run-my-code
v1.0.0
Published
Execute javascript code from a string based on new function.
Downloads
2
Maintainers
Readme
run-my-code
Execute javascript code from a string based on new function, inspired by zx.
Install
$ npm install --save run-my-code
Usage
Tagged Template:
const $ = require('run-my-code');
const obj = { foo: 'foo' };
const arr = [1, 2];
console.log($`return 1 + 1`); // 2
console.log($`return ${obj}`); // { foo: 'foo' }
console.log($`return ${arr}.map((n) => n * 2)`); // [2, 4]
Normal Function:
const $ = require('run-my-code');
console.log($('return 1 + 1')); // 2
With Context:
console.log($({ a: 1, b: 2 })(`return a + b`)); // 3
console.log($({ a: 1, b: 2 })`return a + b`); // 3