@0y0/exec

1.0.2 • Public • Published

@0y0/exec · GitHub license npm

exec is a sandbox to execute code and get the return.

Installation

npm install --save @0y0/exec

Usage

const exec = require('@0y0/exec')

1. Run the string type of code wrapped with {{ and }}.

exec('{{`Hi, ${name}`}}', { name: 'JC' })
// 'Hi, JC'

2. Run the object type of code

exec({ value: '{{name}}' }, { name: 'JC' })
// { value: 'JC' }

3. Run the array type of code

exec(['{{name}}'], { name: 'JC' })
// ['JC']

4. Run the array type of code with for/of

exec(
  ['for(item of list)', { value: '{{item.name}}' }],
  { list: [{ name: 'JC' }] }
)
// [{ value: 'JC' }]

5. Run the array type of code with for

exec(
  ['for(i=0;i<list.length;i++)', { value: '{{list[i].name}}' }],
  { list: [{ name: 'JC' }] }
)
// [{ value: 'JC' }]

6. Use global variables

exec.define('add', (a, b) => a + b)
exec('{{add(1,2)}}')
// 3

License

MIT

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @0y0/exec

      Weekly Downloads

      2

      Version

      1.0.2

      License

      MIT

      Unpacked Size

      5.39 kB

      Total Files

      4

      Last publish

      Collaborators

      • shiningjason