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.

  • 3.0.1
  • 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

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

Table of Contents

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

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.

(back to top)

Keywords

FAQs

Package last updated on 28 Oct 2024

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