{"id":19795873,"url":"https://github.com/korbinzhao/aexpr","last_synced_at":"2025-12-30T15:06:52.294Z","repository":{"id":38264055,"uuid":"491827158","full_name":"korbinzhao/aexpr","owner":"korbinzhao","description":"A safe javascript expression interpreter, support operators / context accessing / property accessing / lodash functions.","archived":false,"fork":false,"pushed_at":"2022-10-28T09:47:17.000Z","size":53,"stargazers_count":20,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-28T12:16:47.671Z","etag":null,"topics":["expression","expression-interpreter","expressionengine","interpreter","javascript","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/korbinzhao.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-13T08:56:24.000Z","updated_at":"2024-10-16T07:21:27.000Z","dependencies_parsed_at":"2022-08-31T16:21:49.758Z","dependency_job_id":null,"html_url":"https://github.com/korbinzhao/aexpr","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korbinzhao%2Faexpr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korbinzhao%2Faexpr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korbinzhao%2Faexpr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/korbinzhao%2Faexpr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/korbinzhao","download_url":"https://codeload.github.com/korbinzhao/aexpr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224231335,"owners_count":17277401,"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":["expression","expression-interpreter","expressionengine","interpreter","javascript","nodejs"],"created_at":"2024-11-12T07:17:39.625Z","updated_at":"2025-12-11T21:07:30.823Z","avatar_url":"https://github.com/korbinzhao.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Aexpr\n\nAexpr is safe javascript expression interpreter, support operators / context accessing / property accessing / lodash functions.\n\n# Support\n* Data type: number/boolean/string/object/array\n* Operators: \n    * Mathematical operators: + - * / \n    * Logic operators: \u0026\u0026 || \u003e \u003e= \u003c \u003c= === !== \n    * Tenary operator: a ? b : c\n* Context access\n* Property access\n* Functions: \n    * Support all [Lodash](https://lodash.com/docs/4.17.15) functions, but prohibit function type input params to avoid prototype access\n\n# Advantage\n* Security assurance\n    * Sandbox isolation to avoid prototype accessing using AST\n    * Avoid memory leak by prohibit statements like 'while'\n* [Lodash](https://lodash.com/docs/4.17.15) functions support\n\n# Usage\n```\nconst interpret = require('aexpr');\n\n// invoke the function\n// interpret(codeStr: string, context?: object);\n\n// calculate\ninterpret('1 + 2 / 4 * 6');\ninterpret('1 + 2 / (4 * 6)');\n\n// compare\ninterpret('1 \u003e 2');\ninterpret('1 \u003c 2');\ninterpret('1 \u003c= 2');\ninterpret('2 \u003c= 2');\ninterpret('2 === 2');\n\n// logic\ninterpret('1 \u0026\u0026 2');\ninterpret('1 || 0');\n\n// context accessing \u0026\u0026 property accessing\ninterpret('a + b / c.d.e', { a: 2, b: 3, c: { d: { e: 5 } } });\n\n// lodash functions\ninterpret(`_.has(obj, 'a.b')`, { obj: { a: { b: 1, c: 2 } } });\ninterpret('_.indexOf(arr, 1)', { arr: [1, 2, 3, 4] });\n\nconst arr = [\n    { 'user': 'barney', 'active': false },\n    { 'user': 'fred', 'active': false },\n    { 'user': 'pebbles', 'active': true }\n];\n\n// not support function type input params to avoid prototype access\nexpect(interpret.bind(null, `_.findIndex(users, function(o) { return o.user == 'barney'; })`)).toThrow('Parse error');\n// support ordinary input params\nexpect(interpret(`_.findIndex(users, { 'user': 'fred', 'active': false })`, {users: arr})).toBe(1);\n\n```\n\n# license\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkorbinzhao%2Faexpr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkorbinzhao%2Faexpr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkorbinzhao%2Faexpr/lists"}