{"id":18939875,"url":"https://github.com/abdullah2993/expression-parser","last_synced_at":"2025-07-31T12:07:56.940Z","repository":{"id":44557007,"uuid":"393637012","full_name":"abdullah2993/expression-parser","owner":"abdullah2993","description":"An expression evaluator written in typescript with the goal to support SQL like WHERE clauses.","archived":false,"fork":false,"pushed_at":"2023-11-07T13:33:29.000Z","size":511,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-23T13:51:00.647Z","etag":null,"topics":["expression","expression-evaluator","filters","parser","whereclause"],"latest_commit_sha":null,"homepage":"","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/abdullah2993.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,"zenodo":null}},"created_at":"2021-08-07T09:21:05.000Z","updated_at":"2025-02-20T09:11:40.000Z","dependencies_parsed_at":"2023-10-13T13:17:33.395Z","dependency_job_id":"45eaf23f-a9ea-4c0b-bc91-70483fbe4aa2","html_url":"https://github.com/abdullah2993/expression-parser","commit_stats":{"total_commits":25,"total_committers":1,"mean_commits":25.0,"dds":0.0,"last_synced_commit":"c1f24d8eaedc62d76cc6f2ac734b3dd714283484"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/abdullah2993/expression-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abdullah2993%2Fexpression-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abdullah2993%2Fexpression-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abdullah2993%2Fexpression-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abdullah2993%2Fexpression-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abdullah2993","download_url":"https://codeload.github.com/abdullah2993/expression-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abdullah2993%2Fexpression-parser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268036050,"owners_count":24185143,"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","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-evaluator","filters","parser","whereclause"],"created_at":"2024-11-08T12:19:15.657Z","updated_at":"2025-07-31T12:07:56.887Z","avatar_url":"https://github.com/abdullah2993.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# expression-parser [![Build](https://github.com/abdullah2993/expression-parser/actions/workflows/build.yaml/badge.svg)](https://github.com/abdullah2993/expression-parser/actions/workflows/build.yaml)\n\nAn expression evaluator written in typescript with the goal to support `SQL` like `WHERE` clauses.\n\n## Installation\n\n```\nnpm install --save @abdullah2993/expression-parser\n```\n\n## Supported Operations and Functions\n\n### Arithmetics\n\n- `+`\n- `-`\n- `*`\n- `/`\n\n### Comparison\n\n- `=`\n- `\u003c\u003e`\n- `\u003e`\n- `\u003e=`\n- `\u003c=`\n\n### Logical\n\n- `and`\n- `or`\n\n### SQL\n\n- `IS NULL`\n- `IS NOT NULL`\n- `BETWEEN [NUMBER] AND [NUMBER]`\n- `CASE WHEN expression THEN expression [WHEN expression] [ELSE expression] END`\n\n### Functions\n\nCurrently only function that is evaluated is the `LENGTH(variable)` function but supports function calls at the parser level so it is fairly easy to add more `SQL` functions.\n\n## Examples\n\n```js\n\n/** Basic Math **/\nevaluate('1+2'));\n// 3\nevaluate('10 + 2 * 6'));\n// 22\nevaluate('100 * 2 + 12'));\n// 212\nevaluate('100 * ( 2 + 12 )'));\n// 1400\nevaluate('100 * ( 2 + 12 ) / 14'));\n// 100\n\n\n/** Basic Math With Variable Substitution**/\n\nconst context = {\n  a: 1, b: 2, c: 10, d: 6, e: 100, f: 12, g: 14,\n};\n\nevaluateObject('a+b', context));\n// 3\nevaluateObject('c + b * d', context));\n// 22\nevaluateObject('e * b + f', context));\n// 212\nevaluateObject('e * ( b + f )', context));\n// 1400\nevaluateObject('e * ( b + f ) / g', context));\n// 100\n\n/** Other Operations **/\nconst val: any = { a: null };\nevaluateObject('a is not null and length(a) between 4 and 10', val);\n// false\nconst val = { a: '123' };\nevaluateObject('a is not null and length(a) between 4 and 10', val);\n// false\nconst val = { a: '1234' };\nevaluateObject('a is not null and length(a) between 4 and 10', val);\n// true\nconst val = { a: '1234567890' };\nevaluateObject('a is not null and length(a) between 4 and 10', val);\n// true\nconst val = { a: '12345678901' };\nevaluateObject('a is not null and length(a) between 4 and 10', val);\n// false\nconst val: any = { a: 1, b: 1 };\nevaluateObject('a is not null and b is not null', val);\n// true\nevaluateObject('a is not null and b is null', val);\n// false\nconst val = { a: 1, b: null };\nevaluateObject('a is not null and b is null', val);\n// true\nconst val = { a: 1, b: 1 };\nevaluateObject('a=b', val));\n// true\nevaluateObject('a\u003eb', val));\n// false\nevaluateObject('a\u003cb', val));\n// false\nconst val = { a: 1, b: 2 };\nevaluateObject('a=b', val);\n// false\nevaluateObject('a\u003eb', val);\n// false\nevaluateObject('a\u003cb', val);\n// true\n\nconst val = { a: 1, b: 3 };\nevaluateObject('case when a \u003e 1 then true else false end', val);\n// false\nconst val = { a: 2, b: 3 };\nevaluateObject('case when a \u003e 1 then true else false end', val);\n// true\nval = { a: 2, b: 3 };\nevaluateObject('case when a = 1 then 1 when a = 2 then 1 else false end', val);\n// 1\nevaluateObject('case when a = 1 then 1 when a = 2 then 2 else 3 end', val);\n// 2\nevaluateObject('case when a = 1 then 1 when a = 3 then 3 else 2 end', val);\n// 2\nconst rule = `case\n                when light = 'Green' then 'Go'\n                when light = 'Yellow' then 'Should Stop'\n                when light = 'Red' then 'Stop'\n                else 'Invalid State' end`;\nval = { light: 'Yellow' };\nevaluateObject(rule, val))\n// 'Should Stop'\nval = { light: 'Green' };\nevaluateObject(rule, val))\n// 'Go'\nval = { light: 'Red' };\nevaluateObject(rule, val))\n// 'Stop'\nval = { light: 'Blue' };\nevaluateObject(rule, val))\n// 'Invalid State'\n\n```\n\n## Sample AST\n\n```json\n//Expression: a is not null and length(a) between 4 and 10\n{\n  \"operator\": \"and\",\n  \"left\": {\n    \"operator\": \"\u003c\u003e\",\n    \"left\": {\n      \"name\": \"a\",\n      \"type\": \"IdentifierExpression\"\n    },\n    \"right\": {\n      \"value\": null,\n      \"type\": \"ValueExpression\"\n    },\n    \"type\": \"BinaryExpression\"\n  },\n  \"right\": {\n    \"operator\": \"and\",\n    \"left\": {\n      \"operator\": \"\u003e=\",\n      \"left\": {\n        \"name\": \"length\",\n        \"args\": [\n          {\n            \"name\": \"a\",\n            \"type\": \"IdentifierExpression\"\n          }\n        ],\n        \"type\": \"FunctionCallExpression\"\n      },\n      \"right\": {\n        \"value\": 4,\n        \"type\": \"ValueExpression\"\n      },\n      \"type\": \"BinaryExpression\"\n    },\n    \"right\": {\n      \"operator\": \"\u003c=\",\n      \"left\": {\n        \"name\": \"length\",\n        \"args\": [\n          {\n            \"name\": \"a\",\n            \"type\": \"IdentifierExpression\"\n          }\n        ],\n        \"type\": \"FunctionCallExpression\"\n      },\n      \"right\": {\n        \"value\": 10,\n        \"type\": \"ValueExpression\"\n      },\n      \"type\": \"BinaryExpression\"\n    },\n    \"type\": \"BinaryExpression\"\n  },\n  \"type\": \"BinaryExpression\"\n}\n```\n\n## Test Coverage\n\n```\n13 specs, 0 failures\nFinished in 0.069 seconds\nRandomized with seed 62175 (jasmine --random=true --seed=62175)\n--------------|---------|----------|---------|---------|-----------------------------------\nFile          | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s\n--------------|---------|----------|---------|---------|-----------------------------------\nAll files     |   93.24 |    83.33 |   92.73 |   93.19 |\n ast.ts       |   89.66 |      100 |      90 |      90 | 16-18\n evaluator.ts |      85 |    69.23 |     100 |   84.21 | 14,18,27,47-49,64\n lexer.ts     |   99.04 |       98 |     100 |   99.03 | 86\n parser.ts    |   89.89 |       70 |   89.47 |   89.41 | 83,91,103,121,133,137,144,181,184\n token.ts     |   97.06 |      100 |      75 |   96.97 | 44\n--------------|---------|----------|---------|---------|-----------------------------------\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabdullah2993%2Fexpression-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabdullah2993%2Fexpression-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabdullah2993%2Fexpression-parser/lists"}