{"_id":"node-eval","_rev":"2856223","name":"node-eval","description":"require or eval modules","dist-tags":{"latest":"2.0.0"},"maintainers":[{"name":"blond","email":"andrewblond@yandex.com"},{"name":"npm:blond","email":""},{"name":"npm:qfox","email":""},{"name":"npm:yeti-or","email":""},{"name":"qfox","email":"zxqfox@gmail.com"}],"time":{"modified":"2022-09-06T16:45:15.000Z","created":"2016-04-27T20:03:07.965Z","2.0.0":"2017-11-12T18:34:50.467Z","1.1.1":"2017-09-19T21:05:36.363Z","1.1.0":"2016-10-21T00:51:29.701Z","1.0.4":"2016-10-15T01:32:42.764Z","1.0.3":"2016-07-13T13:21:44.627Z","1.0.2":"2016-05-16T18:22:31.384Z","1.0.1":"2016-05-10T14:17:00.705Z","1.0.0":"2016-04-27T20:03:07.965Z"},"users":{},"author":{"name":"Vasiliy Loginevskiy","email":"yeti.or@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/nodules/node-eval.git"},"versions":{"2.0.0":{"name":"node-eval","version":"2.0.0","description":"require or eval modules","keywords":["eval","require"],"author":{"name":"Vasiliy Loginevskiy","email":"yeti.or@gmail.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/nodules/node-eval.git"},"main":"index.js","files":["index.js"],"engines":{"node":">= 4"},"scripts":{"pretest":"npm run lint","test":"nyc mocha","lint":"eslint ."},"dependencies":{"path-is-absolute":"1.0.1"},"devDependencies":{"chai":"^4.1.2","eslint":"^4.11.0","eslint-config-pedant":"^1.0.0","mocha":"^4.0.1","nyc":"^11.3.0"},"gitHead":"8f24aa97ab1e6014c0c6775c152c015c32cc7496","bugs":{"url":"https://github.com/nodules/node-eval/issues"},"homepage":"https://github.com/nodules/node-eval#readme","_id":"node-eval@2.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.1","_npmUser":{"name":"blond","email":"mail@blond.im"},"dist":{"shasum":"ae1d1299deb4c0e41352f9528c1af6401661d37f","size":3751,"noattachment":false,"key":"/node-eval/-/node-eval-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-eval/download/node-eval-2.0.0.tgz"},"maintainers":[{"name":"blond","email":"andrewblond@yandex.com"},{"name":"npm:blond","email":""},{"name":"npm:qfox","email":""},{"name":"npm:yeti-or","email":""},{"name":"qfox","email":"zxqfox@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/node-eval-2.0.0.tgz_1510511689378_0.316024964209646"},"directories":{},"publish_time":1510511690467,"_hasShrinkwrap":false,"_cnpm_publish_time":1510511690467,"_cnpmcore_publish_time":"2021-12-16T23:54:09.557Z"},"1.1.1":{"name":"node-eval","version":"1.1.1","description":"require or eval modules","keywords":["eval","require"],"author":{"name":"Vasiliy Loginevskiy","email":"yeti.or@gmail.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/nodules/node-eval.git"},"greenkeeper":{"ignore":["nyc"]},"main":"index.js","engines":{"node":">= 0.10"},"scripts":{"pretest":"npm run lint","test":"npm run specs","specs":"nyc mocha","lint":"jshint . && jscs ."},"dependencies":{"path-is-absolute":"1.0.1"},"devDependencies":{"chai":"^4.1.0","jscs":"^3.0.7","jshint":"^2.9.1","mocha":"^3.5.0","nyc":"10.3.2"},"gitHead":"6275274886ca48aa74cada0b22ad412d8ebff0c0","bugs":{"url":"https://github.com/nodules/node-eval/issues"},"homepage":"https://github.com/nodules/node-eval#readme","_id":"node-eval@1.1.1","_npmVersion":"5.4.2","_nodeVersion":"8.2.1","_npmUser":{"name":"yeti-or","email":"yeti.or@gmail.com"},"dist":{"shasum":"da42edbb16e32bff819db8fd7e33721c24a58284","size":3176,"noattachment":false,"key":"/node-eval/-/node-eval-1.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-eval/download/node-eval-1.1.1.tgz"},"maintainers":[{"name":"blond","email":"andrewblond@yandex.com"},{"name":"npm:blond","email":""},{"name":"npm:qfox","email":""},{"name":"npm:yeti-or","email":""},{"name":"qfox","email":"zxqfox@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/node-eval-1.1.1.tgz_1505855135374_0.265575879951939"},"directories":{},"publish_time":1505855136363,"_hasShrinkwrap":false,"_cnpm_publish_time":1505855136363,"_cnpmcore_publish_time":"2021-12-16T23:54:09.793Z"},"1.1.0":{"name":"node-eval","version":"1.1.0","description":"require or eval modules","keywords":["eval","require"],"author":{"name":"Vasiliy Loginevskiy","email":"yeti.or@gmail.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/nodules/node-eval.git"},"main":"index.js","engines":{"node":">= 0.10"},"scripts":{"pretest":"npm run lint","test":"npm run specs","specs":"nyc mocha","lint":"jshint . && jscs ."},"dependencies":{"path-is-absolute":"1.0.1"},"devDependencies":{"chai":"^3.5.0","jscs":"^2.11.0","jshint":"^2.9.1","mocha":"^3.0.0","nyc":"^8.3.1"},"gitHead":"c0c2e51b7f382255f6a4939dbc8e94c9abb6bd41","bugs":{"url":"https://github.com/nodules/node-eval/issues"},"homepage":"https://github.com/nodules/node-eval#readme","_id":"node-eval@1.1.0","_shasum":"9b7b0bed569baa67300ed018f2cf6890deed2654","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.7.0","_npmUser":{"name":"yeti-or","email":"yeti.or@gmail.com"},"dist":{"shasum":"9b7b0bed569baa67300ed018f2cf6890deed2654","size":3763,"noattachment":false,"key":"/node-eval/-/node-eval-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-eval/download/node-eval-1.1.0.tgz"},"maintainers":[{"name":"blond","email":"andrewblond@yandex.com"},{"name":"npm:blond","email":""},{"name":"npm:qfox","email":""},{"name":"npm:yeti-or","email":""},{"name":"qfox","email":"zxqfox@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/node-eval-1.1.0.tgz_1477011088870_0.09328175778500736"},"directories":{},"publish_time":1477011089701,"_hasShrinkwrap":false,"_cnpm_publish_time":1477011089701,"_cnpmcore_publish_time":"2021-12-16T23:54:10.022Z"},"1.0.4":{"name":"node-eval","version":"1.0.4","description":"require or eval modules","keywords":["eval","require"],"author":{"name":"Vasiliy Loginevskiy","email":"yeti.or@gmail.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/nodules/node-eval.git"},"main":"index.js","scripts":{"pretest":"npm run lint","test":"npm run specs","specs":"nyc mocha","lint":"jshint . && jscs ."},"devDependencies":{"chai":"^3.5.0","jscs":"^2.11.0","jshint":"^2.9.1","mocha":"^3.0.0","nyc":"^8.3.1"},"gitHead":"2d36b41766d29bc6fda4fa8d695921a17d602f02","bugs":{"url":"https://github.com/nodules/node-eval/issues"},"homepage":"https://github.com/nodules/node-eval#readme","_id":"node-eval@1.0.4","_shasum":"4f71ee0403b144c9e94804a57f098013ccce07ac","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.7.0","_npmUser":{"name":"yeti-or","email":"yeti.or@gmail.com"},"dist":{"shasum":"4f71ee0403b144c9e94804a57f098013ccce07ac","size":3696,"noattachment":false,"key":"/node-eval/-/node-eval-1.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-eval/download/node-eval-1.0.4.tgz"},"maintainers":[{"name":"blond","email":"andrewblond@yandex.com"},{"name":"npm:blond","email":""},{"name":"npm:qfox","email":""},{"name":"npm:yeti-or","email":""},{"name":"qfox","email":"zxqfox@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/node-eval-1.0.4.tgz_1476495161166_0.4394166909623891"},"directories":{},"publish_time":1476495162764,"_hasShrinkwrap":false,"_cnpm_publish_time":1476495162764,"_cnpmcore_publish_time":"2021-12-16T23:54:10.251Z"},"1.0.3":{"name":"node-eval","version":"1.0.3","description":"require or eval modules","keywords":["eval","require"],"author":{"name":"Vasiliy Loginevskiy","email":"yeti.or@gmail.com"},"license":"MIT","main":"index.js","scripts":{"test":"npm run lint && npm run specs","specs":"mocha test","lint":"jshint . && jscs .","cover":"istanbul cover _mocha -- test"},"devDependencies":{"chai":"^3.5.0","istanbul":"^0.4.2","jscs":"^2.11.0","jshint":"^2.9.1","mocha":"^2.4.5"},"gitHead":"cc725ee7eedf0f77880e8a34b894da6786b69d8a","_id":"node-eval@1.0.3","_shasum":"37075103dbb93b17aea6e854385a828aa5472ac1","_from":".","_npmVersion":"2.15.8","_nodeVersion":"4.4.7","_npmUser":{"name":"yeti-or","email":"yeti.or@gmail.com"},"dist":{"shasum":"37075103dbb93b17aea6e854385a828aa5472ac1","size":2599,"noattachment":false,"key":"/node-eval/-/node-eval-1.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-eval/download/node-eval-1.0.3.tgz"},"maintainers":[{"name":"blond","email":"andrewblond@yandex.com"},{"name":"npm:blond","email":""},{"name":"npm:qfox","email":""},{"name":"npm:yeti-or","email":""},{"name":"qfox","email":"zxqfox@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/node-eval-1.0.3.tgz_1468416102606_0.13469174318015575"},"directories":{},"publish_time":1468416104627,"_hasShrinkwrap":false,"_cnpm_publish_time":1468416104627,"_cnpmcore_publish_time":"2021-12-16T23:54:10.447Z"},"1.0.2":{"name":"node-eval","version":"1.0.2","description":"require or eval modules","keywords":["eval","require"],"author":{"name":"Vasiliy Loginevskiy","email":"yeti.or@gmail.com"},"license":"MIT","main":"index.js","scripts":{"test":"npm run lint && npm run specs","specs":"mocha test","lint":"jshint . && jscs .","cover":"istanbul cover _mocha -- test"},"devDependencies":{"chai":"^3.5.0","istanbul":"^0.4.2","jscs":"^2.11.0","jshint":"^2.9.1","mocha":"^2.4.5"},"gitHead":"cbfd37a1bc8791b3bc68804a138e7b647aba7ea9","_id":"node-eval@1.0.2","_shasum":"503852842e5f2a4095107eeb7fa0e7448a96a2f0","_from":".","_npmVersion":"3.8.3","_nodeVersion":"5.10.0","_npmUser":{"name":"yeti-or","email":"yeti.or@gmail.com"},"dist":{"shasum":"503852842e5f2a4095107eeb7fa0e7448a96a2f0","size":2569,"noattachment":false,"key":"/node-eval/-/node-eval-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-eval/download/node-eval-1.0.2.tgz"},"maintainers":[{"name":"blond","email":"andrewblond@yandex.com"},{"name":"npm:blond","email":""},{"name":"npm:qfox","email":""},{"name":"npm:yeti-or","email":""},{"name":"qfox","email":"zxqfox@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/node-eval-1.0.2.tgz_1463422949135_0.64510732376948"},"directories":{},"publish_time":1463422951384,"_hasShrinkwrap":false,"_cnpm_publish_time":1463422951384,"_cnpmcore_publish_time":"2021-12-16T23:54:10.661Z"},"1.0.1":{"name":"node-eval","version":"1.0.1","description":"require or eval modules","keywords":["eval","require"],"author":{"name":"Vasiliy Loginevskiy","email":"yeti.or@gmail.com"},"license":"MIT","main":"index.js","scripts":{"test":"npm run lint && npm run specs","specs":"mocha test","lint":"jshint . && jscs .","cover":"istanbul cover _mocha -- test"},"devDependencies":{"chai":"^3.5.0","istanbul":"^0.4.2","jscs":"^2.11.0","jshint":"^2.9.1","mocha":"^2.4.5"},"gitHead":"7e316c0269456e359fd263c6da36243615d9eac9","_id":"node-eval@1.0.1","_shasum":"62866b6c5237ded5ff4f8cbf916bea8d62246130","_from":".","_npmVersion":"2.15.1","_nodeVersion":"4.4.4","_npmUser":{"name":"yeti-or","email":"yeti.or@gmail.com"},"dist":{"shasum":"62866b6c5237ded5ff4f8cbf916bea8d62246130","size":2585,"noattachment":false,"key":"/node-eval/-/node-eval-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-eval/download/node-eval-1.0.1.tgz"},"maintainers":[{"name":"blond","email":"andrewblond@yandex.com"},{"name":"npm:blond","email":""},{"name":"npm:qfox","email":""},{"name":"npm:yeti-or","email":""},{"name":"qfox","email":"zxqfox@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/node-eval-1.0.1.tgz_1462889819444_0.6136254004668444"},"directories":{},"publish_time":1462889820705,"_hasShrinkwrap":false,"_cnpm_publish_time":1462889820705,"_cnpmcore_publish_time":"2021-12-16T23:54:10.847Z"},"1.0.0":{"name":"node-eval","version":"1.0.0","description":"require or eval modules","keywords":["eval","require"],"author":{"name":"Vasiliy Loginevskiy","email":"yeti.or@gmail.com"},"license":"MIT","main":"index.js","scripts":{"test":"npm run lint && npm run specs","specs":"mocha test","lint":"jshint . && jscs .","cover":"istanbul cover _mocha -- test"},"devDependencies":{"chai":"^3.5.0","istanbul":"^0.4.2","jscs":"^2.11.0","jshint":"^2.9.1","mocha":"^2.4.5"},"gitHead":"381f553dccd757faafa61cdce7ab9419014953a4","_id":"node-eval@1.0.0","_shasum":"04aed9665ff74f41ac091d18fa68fd82941ce104","_from":".","_npmVersion":"2.15.1","_nodeVersion":"4.4.3","_npmUser":{"name":"yeti-or","email":"yeti.or@gmail.com"},"dist":{"shasum":"04aed9665ff74f41ac091d18fa68fd82941ce104","size":2570,"noattachment":false,"key":"/node-eval/-/node-eval-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/node-eval/download/node-eval-1.0.0.tgz"},"maintainers":[{"name":"blond","email":"andrewblond@yandex.com"},{"name":"npm:blond","email":""},{"name":"npm:qfox","email":""},{"name":"npm:yeti-or","email":""},{"name":"qfox","email":"zxqfox@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/node-eval-1.0.0.tgz_1461787385779_0.04642236698418856"},"directories":{},"publish_time":1461787387965,"_hasShrinkwrap":false,"_cnpm_publish_time":1461787387965,"_cnpmcore_publish_time":"2021-12-16T23:54:11.052Z"}},"readme":"# node-eval\n\nEval JS-expression, CommonJS modules and JSON with ease.\n\n[![NPM Status][npm-img]][npm]\n[![Travis Status][test-img]][travis]\n[![Coverage Status][coveralls-img]][coveralls]\n[![Dependency Status][david-img]][david]\n\n[npm]:           http://www.npmjs.org/package/node-eval\n[npm-img]:       https://img.shields.io/npm/v/node-eval.svg\n\n[travis]:        https://travis-ci.org/node-eval/node-eval\n[test-img]:      https://img.shields.io/travis/node-eval/node-eval/master.svg?label=tests\n\n[coveralls]:     https://coveralls.io/r/node-eval/node-eval\n[coveralls-img]: https://img.shields.io/coveralls/node-eval/node-eval/master.svg\n\n[david]:         https://david-dm.org/node-eval/node-evalenb/enb\n[david-img]:     https://img.shields.io/david/node-eval/node-eval/master.svg\n\n## Usage\n\n### JS-expression\n\n```js\nconst nodeEval = require('node-eval');\n\nnodeEval('42 * 42'); // 1764\n```\n\n### CommonJS\n\n```js\nconst nodeEval = require('node-eval');\nconst moduleContents =\n`\n    const package = require('./package.json');\n\n    module.exports = {\n        name: package.name\n    };\n`;\n\nnodeEval(moduleContents, './index.js'); // filename need to provide required info to resolve relative paths inside evaluating code\n\n// ➜ { name: 'node-eval' }\n```\n\n### JSON\n\n```js\nconst nodeEval = require('node-eval');\nconst jsonContents = '{ \"name\": \"node-eval\" }';\n\nnodeEval(requireContents, 'my.json'); // filename need to `node-eval` determinate json format by extention\n\n// ➜ { name: 'node-eval' }\n```\n\n## API\n\n### nodeEval(contents[, filename, context])\n\n#### contents\n\nType: `string`\n\nThe JS-expression, CommonJS module contents or JSON contents.\n\n#### filename\n\nType: `string`\n\nThe path to file which contents we execute.\n\nThe `node-eval` determinate format by extension. If filename ends with `.json` extention, its contents will be parsing with `JSON.parse`. If filename ends with `.js`, its contents will be evaluating with [vm](https://nodejs.org/dist/latest/docs/api/vm.html).\n\nBy default expected JS-expression or CommonJS module contents.\n\n```js\nconst nodeEval = require('node-eval');\n\nnodeEval('42 * 42'/* js by default */); // 1764\nnodeEval('42 * 42', 'my.js'); // 1764\nnodeEval('{ \"name\": \"node-eval\" }', 'my.json'); // '{ name: 'node-eval' }'\n```\n\nTo evaluating CommonJS module contents filename is required to resolve relative paths inside evaluating code.\n\n```js\nconst nodeEval = require('node-eval');\nconst moduleContents =\n`\n    const package = require('./package.json'); // to resolve this require need to know the path of current module (./index.js)\n\n    module.exports = {\n        name: package.name\n    };\n`;\n\nnodeEval(moduleContents, './index.js'); // filename need to provide required info to resolve relative paths inside evaluating code\n```\n\nInternally `node-eval` will resolve passed relative paths using the place it's called (like `require` do).\n\nIt may spend additional processor's time on it, so better to pass in absolute path.\n\n```js\nconst fs = require('fs');\nconst nodeEval = require('node-eval');\n\n// For example, current path is \"/repos/project/lib/file.js\".\nconst modulePath = '../files/another.js';\nconst moduleContents = fs.readFileSync(modulePath, 'utf-8');\n\n// '../files/another.js' will be resolved to '/repos/project/files/another.js'\nnodeEval(moduleContents, modulePath);\n```\n\n#### context\n\nType: `Object`\n\nThe object to provide into execute method.\n\nIf `context` is specified, then module contents will be evaluating with `vm.runInNewContext`.\n\nIf `context` is not specified, then module contents will be evaluating with `vm.runInThisContext`.\n\nWith `context` you can provide some like-a-global variables into `node-eval`.\n\n```js\nconst nodeEval = require('node-eval');\n\nconst secretKey = '^___^';\nconst contents = 'module.exports = secretKey;';\n\nnodeEval(content, { secretKey }); // '^___^'\n```\n\n## Related\n\n* [file-eval](https://github.com/node-eval/file-eval)\n\n","_attachments":{},"homepage":"https://github.com/nodules/node-eval#readme","bugs":{"url":"https://github.com/nodules/node-eval/issues"},"license":"MIT"}