duktape-eval
A safe eval library based on WebAssembly build of Duktape.
Usage
In node:
const getInstance =
In browser:
API
duktapeEval.getInstance(): Promise<Instance>
Returns a Promise to resolve the module instance.
Instance
Instance#eval(code: string): any
Evaluate JavaScript string in Duktape engine, and return a value.
Instance#newFunction(argnames: string[], body: string): (...any) => any
Create a function like new Function
to be called afterward.
Q&A
What can it runs?
Whatever Duktape can run. Basically ES5 syntax and some ES6, ES7 capabilities.
How can I pass data to it?
JSON.stringify
is your friend.
How can I return data from it?
Just like normal eval
, for example var a={};a.prop=1;a
will return { prop: 1 }
. But keep in mind, only JSON serializable data can be returned.
How big is this?
Script size: 348kB Gzipped size: 154kB