require-cjs-string
v1.0.0
Published
Load commonjs module from string in Node & Browser.
Downloads
9
Maintainers
Readme
require-cjs-string
Dynamic eval commonjs/umd module from string in Node & Browser.
Install
npm install require-cjs-string
Usage
const rcs = require('require-cjs-string')
rcs('module.exports = 1') // => 1
More Examples:
const rcs = require('require-cjs-string')
const { sqrt, square } = rcs(`
exports.sqrt = Math.sqrt;
exports.square = x => x * x;
`)
square(12) // => 144
sqrt(36) // => 6
const fn = rcs(`
module.exports = (x, y) => {
var z = x + y;
return z * z * z;
}
`)
fn(3, 4) // => 343
License
MIT @ Amio