with params - JEP demo
by longhao he
HTML
<script src="https://unpkg.com/jep/jep.min.js"></script>
Babel + JSX
/* https://github.com/cnlon/jep */
const jep = new JEP({params: ['$', 'SQUARE_METER']})
const scope = {
radius: 3,
square (n) {
return n * n
},
fixed (numObj, num) {
return numObj.toFixed(num)
},
}
const SQUARE_METER = 'm²'
const source = 'fixed((Math.PI + square(radius)), 2) + SQUARE_METER'
const result = jep.make(source)(scope, SQUARE_METER)
log(result)
// 12.14m²
function log(content) {
content += '<br>'
document.body.innerHTML += content
}