formulax
Version:
Fast javascript expression parser and compiler.
43 lines (32 loc) • 639 B
JavaScript
const formulax = require('./src')
var source = `$(123).plus(456).minus(10)*2`
const { formula } = formulax.parse(source)
const exec = require('./src/exec2')
function ChainableValue(value, context) {
if(typeof value === 'string') {
if(value.split('-').length === 4) { // uuid
this.value = value
}
}
this.value = value
}
ChainableValue.prototype = {
inRow( id ) {
return this
},
plus(x) {
this.value += x
return this
},
minus(x) {
this.value -= x
return this
},
valueOf() {
return this.value
},
}
const $ = x => new ChainableValue(x)
console.log(exec(formula, {
$,
}))