0.1.0 • Published 2 years ago

@wmakeev/vm-sandbox v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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