Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jintr

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jintr

A tiny JavaScript interpreter written in TypeScript.

  • 0.4.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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)

Keywords

FAQs

Package last updated on 10 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc