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.1.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19K
decreased by-8.64%
Maintainers
1
Weekly downloads
 
Created
Source

Jinter

A tiny JavaScript interpreter written in TypeScript

Tests Say thanks

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);
});

// Ex: str.toArray();
jinter.visitor.on('toArray', (node: any, visitor: Visitor) => {
  const obj = visitor.visitNode(node.callee.object);
  return obj.split('');      
});

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

jinter.interpret();

More examples are available in the test & examples folders.

License

Distributed under the MIT License.

(back to top)

Footnotes

  1. This project was originally developed for use in YouTube.js.

Keywords

FAQs

Package last updated on 20 Aug 2022

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