JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 33583
  • Score
    100M100P100Q134654F
  • License MIT

A tiny JavaScript interpreter written in TypeScript.

Package Exports

  • jintr
  • jintr/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jintr) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Jinter

A tiny JavaScript interpreter written in TypeScript

Tests Say thanks

Note: This project was originally developed for use in YouTube.js.

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(code);
jinter.interpret();

Inject your own functions and variables into the interpreter:

// ...

jinter.visitor.on('println', (node, visitor) => {
  if (node.type === 'CallExpression' && node.callee.type === 'MemberExpression') {
    const args = node.arguments.map((arg) => visitor.visitNode(arg));
    return console.log(...args);
  }
});

// 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('');    
  }  
});

// Or you can just intercept access to specific nodes;
jinter.visitor.on('myFn', (node, visitor) => {
  console.info('MyFn node just got accessed:', node);
  return 'proceed'; // tells the interpreter to continue execution 
});

jinter.interpret();

For more examples see /test and /examples.

License

Distributed under the MIT License.

(back to top)