{"id":21238693,"url":"https://github.com/shahradelahi/node-eval","last_synced_at":"2025-04-09T21:16:09.323Z","repository":{"id":279460006,"uuid":"890092003","full_name":"shahradelahi/node-eval","owner":"shahradelahi","description":"🔒 Secure Code Evaluation, Simplified.","archived":false,"fork":false,"pushed_at":"2025-04-09T00:13:33.000Z","size":69,"stargazers_count":69,"open_issues_count":6,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T21:16:01.393Z","etag":null,"topics":["eval","neval","nodejs","safe","sandbox"],"latest_commit_sha":null,"homepage":"https://npmjs.com/neval","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shahradelahi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-18T01:00:52.000Z","updated_at":"2025-04-09T12:54:37.000Z","dependencies_parsed_at":"2025-03-13T04:19:29.420Z","dependency_job_id":"c3a513dc-b937-4d22-b45d-0a9b606589fa","html_url":"https://github.com/shahradelahi/node-eval","commit_stats":null,"previous_names":["shahradelahi/node-eval"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fnode-eval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fnode-eval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fnode-eval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Fnode-eval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shahradelahi","download_url":"https://codeload.github.com/shahradelahi/node-eval/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248111973,"owners_count":21049578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eval","neval","nodejs","safe","sandbox"],"created_at":"2024-11-21T00:37:42.577Z","updated_at":"2025-04-09T21:16:09.288Z","avatar_url":"https://github.com/shahradelahi.png","language":"TypeScript","readme":"# node-eval\n\n[![CI](https://github.com/shahradelahi/node-eval/actions/workflows/ci.yml/badge.svg)](https://github.com/shahradelahi/node-eval/actions/workflows/ci.yml)\n[![NPM Version](https://img.shields.io/npm/v/neval.svg)](https://www.npmjs.com/package/neval)\n[![MIT License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](/LICENSE)\n[![Install Size](https://packagephobia.com/badge?p=neval)](https://packagephobia.com/result?p=neval)\n\n_neval_ is a zero-dependency, lightweight utility for securely evaluating code in a sandboxed environment in Node.js.\n\n---\n\n- [Installation](#-installation)\n- [Usage](#-usage)\n- [Documentation](#-documentation)\n- [Contributing](#-contributing)\n- [License](#license)\n\n## 📦 Installation\n\n```bash\nnpm install neval\n```\n\n## 📖 Usage\n\n```typescript\nimport { neval, nevalFile } from 'neval';\n\nconst result = neval('1 + 1');\nconsole.log(result); // 2\n\nconst result2 = await nevalFile('./file.js');\nconsole.log(result2); // Whatever file.js returns\n\nconst result3 = await neval(\n  `\n    async function main() {\n        await sleep(1e3); // The \"sleep\" function will be injected through context\n        return 1 + 1;\n    }\n    main();\n`,\n  {\n    context: {\n      sleep: async (ms: number) =\u003e {\n        return new Promise((resolve) =\u003e setTimeout(resolve, ms));\n      },\n    },\n  }\n);\nconsole.log(result3); // Result after 1 second is 2\n\nconst result4 = await neval(\n  `\n    fetch('https://example.com', { method: 'HEAD' })\n      .then((resp) =\u003e resp.statusText);\n`,\n  {\n    // By default, the \"fetch\" API is not available, you must add it to the context\n    context: { fetch },\n  }\n);\nconsole.log(result4); // OK\n```\n\nImporting `neval/register` will register the `neval` function on the global object and overrides the `eval` function.\n\n```typescript\nimport 'neval/register';\n\nconsole.log(eval('1 + 1')); // 2\n```\n\nWhy is it important to register it globally? The `neval` is sandboxed and much more secure than just using the `eval` function. Read more about [eval](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval).\n\nAre you looking for more examples? Check out the [unit tests](/tests/eval.test.ts).\n\n## 📚 Documentation\n\nFor all configuration options, please see [the API docs](https://www.jsdocs.io/package/neval).\n\n##### API\n\n```typescript\nfunction neval(code: any, options?: EvalOptions): any;\nfunction nevalFile(path: string, options?: EvalOptions): Promise\u003cany\u003e;\nfunction register(): void;\n```\n\n## 🤝 Contributing\n\nWant to contribute? Awesome! To show your support is to star the project, or to raise issues on [GitHub](https://github.com/shahradelahi/node-eval)\n\nThanks again for your support, it is much appreciated! 🙏\n\n## Relevant\n\n- [isolated-vm](https://github.com/laverdet/isolated-vm)\n\n## License\n\n[MIT](/LICENSE) © [Shahrad Elahi](https://github.com/shahradelahi)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshahradelahi%2Fnode-eval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshahradelahi%2Fnode-eval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshahradelahi%2Fnode-eval/lists"}