@holzchopf/es
v1.0.0
Published
ECMAScript eval, execute ECMAScript string
Readme
ES
eval() but
- isolated from global object
- customizable API
- able to be prepared once, executed multiple times
Examples
Basic arithmetics
es('1+1') // returns 2Isolation:
let a = 2
es('a + 1') // throws EsError: a is not definedCustom API:
let a = 2
es('a + 1', { customAPIs: { a } }) // returns 3Prepared statements:
let a = 0
const prepared = new ES('a + 1', { args: { a } })
a = 2
prepared.execute({ args: { a }}) // returns 3
a = 3
prepared.execute({ args: { a }}) // returns 4