{"_id":"any-eval","_rev":"5-bf4f6d079a71a4f7a62134c6cf157013","name":"any-eval","description":"Super handy eval of anything","dist-tags":{"latest":"1.0.0"},"versions":{"0.0.0":{"name":"any-eval","version":"0.0.0","description":"Super handy eval of anything","license":"MIT","repository":{"type":"git","url":"git+https://github.com/node-eval/any-eval.git"},"author":{"name":"Andrew Abramov","email":"mail@blond.im","url":"github.com/blond"},"keywords":["eval","JS-expression","CommonJS","JSON","JSON5"],"main":"index.js","files":["index.js"],"engines":{"node":">= 4"},"dependencies":{"json5":"0.5.1","node-eval":"2.0.0"},"devDependencies":{"chai":"^4.1.2","eslint":"^4.11.0","eslint-config-pedant":"^1.0.0","mocha":"^4.0.1","nyc":"^11.3.0","proxyquire":"^1.8.0","sinon":"^4.1.2","sinon-chai":"^2.14.0"},"scripts":{"pretest":"npm run lint","test":"npm run cover","test:unit":"mocha test/**{,/*}.test.js","cover":"nyc npm run test:unit","lint":"eslint ."},"gitHead":"53ccb5fa7e014e9ce67a9232171d5f35a314ae1a","bugs":{"url":"https://github.com/node-eval/any-eval/issues"},"homepage":"https://github.com/node-eval/any-eval#readme","_id":"any-eval@0.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.1","_npmUser":{"name":"blond","email":"mail@blond.im"},"dist":{"integrity":"sha512-QLYk2KPc3O7UvQq1GDp4m23iQJPK0wgE8B6PLzP/BwMPyhADMlhwm2qDL2jPJRFJ04waIofuQNLKDed4RRO1hw==","shasum":"8493bb92a09058f3285f0d78a9f6ce4cb989e70b","tarball":"https://registry.npmjs.org/any-eval/-/any-eval-0.0.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE2nbtZ7H8sCkHc5GSdkP8UHyv/XQh+lRy2d6IJMnpeeAiEAtu7nBAc2EC43rx3G3ZyQll1938FmAq2k7R5RLQWVFX4="}]},"maintainers":[{"name":"blond","email":"mail@blond.im"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/any-eval-0.0.0.tgz_1510518528263_0.2657204151619226"},"directories":{}},"1.0.0":{"name":"any-eval","version":"1.0.0","description":"Super handy eval of anything","license":"MIT","repository":{"type":"git","url":"git+https://github.com/node-eval/any-eval.git"},"author":{"name":"Andrew Abramov","email":"mail@blond.im","url":"github.com/blond"},"keywords":["eval","JS-expression","CommonJS","JSON","JSON5"],"main":"index.js","files":["index.js"],"engines":{"node":">= 4"},"dependencies":{"json5":"0.5.1","node-eval":"2.0.0"},"devDependencies":{"chai":"^4.1.2","eslint":"^4.11.0","eslint-config-pedant":"^1.0.0","mocha":"^4.0.1","nyc":"^11.3.0","proxyquire":"^1.8.0","sinon":"^4.1.2","sinon-chai":"^2.14.0"},"scripts":{"pretest":"npm run lint","test":"npm run cover","test:unit":"mocha test/**{,/*}.test.js","cover":"nyc npm run test:unit","lint":"eslint ."},"gitHead":"3564fc26bdc34c0b8fae07592c3573a8c9d1f8a1","bugs":{"url":"https://github.com/node-eval/any-eval/issues"},"homepage":"https://github.com/node-eval/any-eval#readme","_id":"any-eval@1.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.1","_npmUser":{"name":"blond","email":"mail@blond.im"},"dist":{"integrity":"sha512-/hyPOi/e2pRtglbfHH34Vad8dDmc8OQFtBzDB5nC/Ux93OoNOC6kjr+t1bdUZ7WTro/l8pGrzZM+hUJs75NkyQ==","shasum":"26d185b09d6f83e631a688bd43cec7b8abeb07ed","tarball":"https://registry.npmjs.org/any-eval/-/any-eval-1.0.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHc2zsEy0huqcWr96v60zvkFDv2S7xlurQT9/Q3Q+3olAiAI6f0U0qO9f2R6ptetIBlslkSiY/QsXtvkES1gBwgs0g=="}]},"maintainers":[{"name":"blond","email":"mail@blond.im"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/any-eval-1.0.0.tgz_1510518789408_0.0815859807189554"},"directories":{}}},"readme":"# any-eval\n\nSuper handy eval of anything.\n\nSupports JS-expression, CommonJS module contents and JSON/JSON5.\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/any-eval\n[npm-img]:       https://img.shields.io/npm/v/any-eval.svg\n\n[travis]:        https://travis-ci.org/node-eval/any-eval\n[test-img]:      https://img.shields.io/travis/node-eval/any-eval/master.svg?label=tests\n\n[coveralls]:     https://coveralls.io/r/node-eval/any-eval\n[coveralls-img]: https://img.shields.io/coveralls/node-eval/any-eval/master.svg\n\n[david]:         https://david-dm.org/node-eval/any-eval\n[david-img]:     https://img.shields.io/david/node-eval/any-eval/master.svg\n\n## Install\n\n```\n$ npm install --save any-eval\n```\n\n## Usage\n\n### JS-expression\n\n```js\nconst anyEval = require('any-eval');\n\nanyEval('42 * 42'); // 1764\n```\n\n### CommonJS\n\n```js\nconst anyEval = require('any-eval');\nconst moduleContents =\n`\n    const package = require('./package.json');\n\n    module.exports = {\n        name: package.name\n    };\n`;\n\nanyEval(moduleContents, './index.js'); // filename need to provide required info to resolve relative paths inside evaluating code\n\n// ➜ { name: 'any-eval' }\n```\n\n### JSON\n\n```js\nconst anyEval = require('any-eval');\nconst jsonContents = '{ \"name\": \"any-eval\" }';\n\nanyEval(jsonContents, 'my.json'); // filename need to `any-eval` determinate json format by extention\n\n// ➜ { name: 'any-eval' }\n```\n\n### JSON5\n\n```js\nconst anyEval = require('any-eval');\nconst jsonContents = \"{ name: 'any-eval' }\";\n\nanyEval(jsonContents, 'my.json5'); // filename need to `any-eval` determinate json format by extention\n\n// ➜ { name: 'any-eval' }\n```\n\n## API\n\n### anyEval(contents[, filename, context])\n\n#### contents\n\nType: `string`\n\nThe JS-expression, CommonJS module contents or JSON/JSON5 contents.\n\n#### filename\n\nType: `string`\n\nThe path to file which contents we execute.\n\nThe `any-eval` determinate format by extension. If filename ends with `.js`, its contents will be evaluating with [vm](https://nodejs.org/dist/latest/docs/api/vm.html). If filename ends with `.json`, its contents will be parsing with `JSON.parse`. If filename ends with `.json5`, its contents will be parsing with [json5](https://github.com/json5/json5). \n\nBy default expected JS-expression or CommonJS module contents.\n\n```js\nconst anyEval = require('any-eval');\n\nanyEval('42 * 42'/* js by default */); // 1764\nanyEval('42 * 42', 'my.js'); // 1764\nanyEval('{ \"name\": \"any-eval\" }', 'my.json'); // '{ name: 'any-eval' }'\nanyEval(\"{ name: 'any-eval' }\", 'my.json5');  // '{ name: 'any-eval' }'\n```\n\nTo evaluating CommonJS module contents filename is required to resolve relative paths inside evaluating code.\n\n```js\nconst anyEval = require('any-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\nanyEval(moduleContents, './index.js'); // filename need to provide required info to resolve relative paths inside evaluating code\n```\n\nInternally `any-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 anyEval = require('any-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'\nanyEval(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 `any-eval`.\n\n```js\nconst anyEval = require('any-eval');\n\nconst secretKey = '^___^';\nconst contents = 'module.exports = secretKey;';\n\nanyEval(content, { secretKey }); // '^___^'\n```\n\n## Related\n\n* [node-eval](https://github.com/node-eval/node-eval) — eval Node.js contents only (JS-expression, CommonJS modules and JSON).\n* [node-file-eval](https://github.com/node-eval/node-file-eval) — read node.js file and eval it with [node-eval](https://github.com/node-eval/node-eval).\n* [file-eval](https://github.com/node-eval/file-eval) — read any file and eval it with [any-eval](https://github.com/node-eval/any-eval).\n","maintainers":[{"email":"yeti.or@gmail.com","name":"yeti-or"},{"email":"zxqfox@gmail.com","name":"qfox"},{"email":"mail@blond.im","name":"blond"}],"time":{"modified":"2022-04-11T14:26:52.959Z","created":"2017-11-12T20:28:49.125Z","0.0.0":"2017-11-12T20:28:49.125Z","1.0.0":"2017-11-12T20:33:10.549Z"},"homepage":"https://github.com/node-eval/any-eval#readme","keywords":["eval","JS-expression","CommonJS","JSON","JSON5"],"repository":{"type":"git","url":"git+https://github.com/node-eval/any-eval.git"},"author":{"name":"Andrew Abramov","email":"mail@blond.im","url":"github.com/blond"},"bugs":{"url":"https://github.com/node-eval/any-eval/issues"},"license":"MIT","readmeFilename":"README.md","users":{"laomu":true}}