npm.io
0.1.0 • Published 4 years ago

@wmakeev/vm-sandbox

Licence
MIT
Version
0.1.0
Deps
0
Size
4 kB
Vulns
0
Weekly
0

vm-sandbox

npm

JavaScript code sandbox based on node.js vm module. Use for better testing and code isolation.

Inspired by metavm

Install

npm install @wmakeev/vm-sandbox

Using

const src = `
  const { mult, round } = api

  const radius = 12

  const s = round(mult(mult(2, PI), radius))

  s
`

const script = createScript('myScript', src, {
  context: {
    api: {
      mult: (a, b) => a * b,
      round: Math.round
    },
    PI: Math.PI
  }
})

console.log(script.exports) // 75

Keywords