3.2.1 • Published 5 months ago

jintr v3.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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.

3.2.1

5 months ago

3.2.0

7 months ago

3.1.0

7 months ago

3.0.2

9 months ago

3.0.1

9 months ago

3.0.0

9 months ago

1.2.0

11 months ago

2.1.1

11 months ago

2.1.0

11 months ago

2.0.0

1 year ago

1.1.0

2 years ago

1.0.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.9

3 years ago

0.3.1

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago