Jinter
A tiny JavaScript interpreter written in TypeScript
Install / Use
/learn @LuanRT/JinterREADME
Note: This project was originally developed for use in YouTube.js.
Table of Contents <!-- omit in toc -->
Installation
npm install jintr
Usage
Execute some JavaScript code:
// const Jinter = require('jintr').default;
import { Jinter } from 'jintr';
const code = `
function sayHiTo(person) {
console.log('Hi ' + person + '!');
}
sayHiTo('mom');
`
const jinter = new Jinter();
jinter.evaluate(code);
Inject your own functions, objects, etc:
import { Jinter } from 'jintr';
const jinter = new Jinter();
const code = `
console.log(new SomeClass().a);
console.log('hello'.toArray());
function myFn() {
console.log('[myFn]: Who called me?');
}
myFn();
`;
class SomeClass {
constructor() {
this.a = 'this is a test';
}
}
jinter.defineObject('SomeClass', SomeClass);
// Ex: str.toArray();
jinter.visitor.on('toArray', (node, visitor) => {
if (node.type === 'CallExpression' && node.callee.type === 'MemberExpression') {
const obj = visitor.visitNode(node.callee.object);
return obj.split('');
}
});
// Intercept function calls
jinter.visitor.on('myFn', (node) => {
if (node.type == 'CallExpression')
console.info('myFn was called!');
return '__continue_exec';
});
jinter.evaluate(code);
For more examples see /test and /examples.
API
- Jinter()
evaluate(input: string)
Evaluates the given JavaScript code.
visitor
The node visitor. This is responsible for walking the AST and executing the nodes.
scope
Represents the global scope of the program.
License
Distributed under the MIT License.
<p align="right"> (<a href="#top">back to top</a>) </p>Related Skills
node-connect
339.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.9kCommit, push, and open a PR
