{"id":21158147,"url":"https://github.com/node-casbin/expression-eval","last_synced_at":"2025-07-09T12:33:43.562Z","repository":{"id":259245892,"uuid":"875438156","full_name":"node-casbin/expression-eval","owner":"node-casbin","description":"JavaScript expression parsing and evaluation, maintained by Casbin team. A hard fork from the unmaintained: https://github.com/donmccurdy/expression-eval","archived":false,"fork":false,"pushed_at":"2024-11-19T15:20:58.000Z","size":567,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-19T16:29:26.365Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/casbin/node-casbin","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/node-casbin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-10-20T01:20:18.000Z","updated_at":"2024-11-19T15:22:53.000Z","dependencies_parsed_at":"2024-10-23T21:12:34.718Z","dependency_job_id":"e3b3440f-b62c-4047-a7b2-04d57cce8e66","html_url":"https://github.com/node-casbin/expression-eval","commit_stats":null,"previous_names":["node-casbin/expression-eval"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-casbin%2Fexpression-eval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-casbin%2Fexpression-eval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-casbin%2Fexpression-eval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-casbin%2Fexpression-eval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/node-casbin","download_url":"https://codeload.github.com/node-casbin/expression-eval/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225550863,"owners_count":17487191,"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":[],"created_at":"2024-11-20T12:16:16.889Z","updated_at":"2024-11-20T12:16:17.498Z","avatar_url":"https://github.com/node-casbin.png","language":"TypeScript","readme":"# expression-eval\n\n[![NPM version][npm-image]][npm-url]\n[![NPM download][download-image]][download-url]\n[![ci](https://github.com/node-casbin/expression-eval/actions/workflows/ci.yml/badge.svg)](https://github.com/node-casbin/expression-eval/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/github/node-casbin/expression-eval/badge.svg?branch=master)](https://coveralls.io/github/node-casbin/expression-eval?branch=master)\n[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord\u0026label=discord\u0026color=5865F2)](https://discord.gg/S5UjpzGZjN)\n\n[npm-image]: https://img.shields.io/npm/v/@casbin/expression-eval.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@casbin/expression-eval\n[download-image]: https://img.shields.io/npm/dm/@casbin/expression-eval.svg?style=flat-square\n[download-url]: https://npmjs.org/package/@casbin/expression-eval\n\nJavaScript expression parsing and evaluation.\n\nPowered by [jsep](https://github.com/soney/jsep).\n\n## Installation\n\nInstall:\n\n```\nnpm install --save @casbin/expression-eval\n```\n\nImport:\n\n```js\n// ES6\nimport { parse, eval } from '@casbin/expression-eval';\n// CommonJS\nconst { parse, eval } = require('@casbin/expression-eval');\n// UMD / standalone script\nconst { parse, eval } = window['@casbin/expression-eval'];\n```\n\n## API\n\n### Parsing\n\n```javascript\nimport { parse } from '@casbin/expression-eval';\nconst ast = parse('1 + foo');\n```\n\nThe result of the parse is an AST (abstract syntax tree), like:\n\n```json\n{\n  \"type\": \"BinaryExpression\",\n  \"operator\": \"+\",\n  \"left\": {\n    \"type\": \"Literal\",\n    \"value\": 1,\n    \"raw\": \"1\"\n  },\n  \"right\": {\n    \"type\": \"Identifier\",\n    \"name\": \"foo\"\n  }\n}\n```\n\n### Evaluation\n\n```javascript\nimport { parse, eval } from '@casbin/expression-eval';\nconst ast = parse('a + b / c'); // abstract syntax tree (AST)\nconst value = eval(ast, {a: 2, b: 2, c: 5}); // 2.4\n```\n\nAlternatively, use `evalAsync` for asynchronous evaluation.\n\n### Compilation\n\n```javascript\nimport { compile } from '@casbin/expression-eval';\nconst fn = compile('foo.bar + 10');\nfn({foo: {bar: 'baz'}}); // 'baz10'\n```\n\nAlternatively, use `compileAsync` for asynchronous compilation.\n\n## Security\n\nAlthough this package does [avoid the use of `eval()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#Do_not_ever_use_eval!), it _cannot guarantee that user-provided expressions, or user-provided inputs to evaluation, will not modify the state or behavior of your application_. This library does not attempt to provide a secure sandbox for evaluation. Evaluation of arbitrary user inputs (expressions or values) may lead to unsafe behavior. If your project requires a secure sandbox, consider alternatives such as [vm2](https://www.npmjs.com/package/vm2).\n\n## License\n\nApache 2.0 License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-casbin%2Fexpression-eval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnode-casbin%2Fexpression-eval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-casbin%2Fexpression-eval/lists"}