Jinter
A tiny JavaScript interpreter written in TypeScript
Note: This project is experimental and not all JavaScript features are implemented! 1
Usage
Execute some JavaScript code:
import Jinter from 'jintr';
const code = `
function sayHiTo(person) {
console.log('Hi ' + person + '!');
}
sayHiTo('mom');
`
const jinter = new Jinter(code);
jinter.interpret();
Inject your own functions and variables into the interpreter;
jinter.visitor.on('println', (node: any, visitor: Visitor) => {
const args = node.arguments.map((arg: any) => visitor.visitNode(arg));
return console.log(...args);
});
jinter.visitor.on('toArray', (node: any, visitor: Visitor) => {
const obj = visitor.visitNode(node.callee.object);
return obj.split('');
});
jinter.visitor.on('myFn', (node: any, visitor: Visitor) => {
console.info('MyFn node just got accessed:', node);
return 'proceed';
});
jinter.interpret();
More examples are available in the test
& examples
folders.
License
Distributed under the MIT License.
(back to top)