array-inline-transform
v1.0.0
Published
Evaluate Node.js module source from a string, buffer, or VM script — like require(), without a file.
Maintainers
Readme
array-inline-transform
Evaluate Node.js module source from a string, buffer, or VM script — the same way require() works, without loading a file.
Uses Node's vm module instead of native eval().
Install
npm install array-inline-transformUsage
var arrayInline = require('array-inline-transform')
var result = arrayInline(content /*, filename, scope, includeGlobals */)| Argument | Type | Description |
|---|---|---|
| content | String | Buffer | vm.Script | Source to evaluate |
| filename | String | Optional name used in stack traces |
| scope | Object | Variables provided to the source |
| includeGlobals | Boolean | Expose Node globals and require (default false) |
Examples
var arrayInline = require('array-inline-transform')
var res = arrayInline('var x = 123; exports.x = x')
// => res === { x: 123 }
res = arrayInline('module.exports = function () { return 123 }')
// => res() === 123
res = arrayInline('module.exports = require("events")', true)
// => res === require('events')
res = arrayInline('exports.x = process', true)
// => res.x === processLicense
MIT. Based on node-eval.
