{"id":22650669,"url":"https://github.com/data7expressions/3xpr","last_synced_at":"2025-04-12T03:13:35.843Z","repository":{"id":40565224,"uuid":"439569096","full_name":"data7expressions/3xpr","owner":"data7expressions","description":"3xpr is an extensible expression evaluator and parser. Besides the operators, functions, variables, objects and arrays that are supported; it is possible to extend it with your own functions, operators, etc","archived":false,"fork":false,"pushed_at":"2024-09-02T13:59:11.000Z","size":2894,"stargazers_count":2,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T03:13:29.931Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/data7expressions.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-12-18T08:52:40.000Z","updated_at":"2024-06-08T00:54:01.000Z","dependencies_parsed_at":"2024-01-16T12:20:12.683Z","dependency_job_id":"eee39b77-9ee1-4754-b9f7-a867b6549730","html_url":"https://github.com/data7expressions/3xpr","commit_stats":null,"previous_names":["flaviolionelrita/js-expressions","expr-solver/3xpr","data7expressions/3xpr"],"tags_count":96,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2F3xpr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2F3xpr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2F3xpr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/data7expressions%2F3xpr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/data7expressions","download_url":"https://codeload.github.com/data7expressions/3xpr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248510003,"owners_count":21116130,"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-12-09T08:36:35.429Z","updated_at":"2025-04-12T03:13:35.819Z","avatar_url":"https://github.com/data7expressions.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 3xpr\n\n\u003e3xpr is an extensible expression evaluator and parser.\n\u003e\n\u003eBesides the operators, functions, variables, objects and arrays that are supported.\n\u003e\n\u003eIt is possible to extend it with your own functions, operators, etc\n\n## Features\n\n- Constants, enums, number, string, datetime, variables, objects and array\n- [Arithmetic](https://github.com/data7expressions/3xpr/wiki/Arithmetic)\n, [assignment](https://github.com/data7expressions/3xpr/wiki/Assignment)\n, [comparison](https://github.com/data7expressions/3xpr/wiki/Comparison)\n, [logical](https://github.com/data7expressions/3xpr/wiki/Logical)\nand [bitwise](https://github.com/data7expressions/3xpr/wiki/Bitwise) operators\n- [Number](https://github.com/data7expressions/3xpr/wiki/Numeric)\n, [string](https://github.com/data7expressions/3xpr/wiki/String)\n,\t[datetime](https://github.com/data7expressions/3xpr/wiki/DateTime)\n, [array](https://github.com/data7expressions/3xpr/wiki/Array)\nand [nullable functions](https://github.com/data7expressions/3xpr/wiki/Nullable)\n- [Conversion functions](https://github.com/data7expressions/3xpr/wiki/Conversion)\n- [Arrow functions](https://github.com/data7expressions/3xpr/wiki/Arrow)\n- [Group functions](https://github.com/data7expressions/3xpr/wiki/Group) (distinct, first, last, min, max, sum and avg)\n- [Sets functions](https://github.com/data7expressions/3xpr/wiki/Sets) (union, intersection, difference and symmetric difference)\n- [Control flows](https://github.com/data7expressions/3xpr/wiki/Flows) flows\n- Environment variables\n- [Extend](https://github.com/data7expressions/3xpr/wiki/Extend)\n- [Metadata](https://github.com/data7expressions/3xpr/wiki/Metadata)\n\n## Quick start\n\n```javascript\nimport { expressions as exp } from '3xpr'\n\nconst context = {\nname: 'Spain',\nregion: 'Europe',\nphoneCode: '34',\ntimezones: [\n\t{ name: 'Madrid', offset: 1, pos: { lat: 40.4165, log: -3.70256 } },\n\t{ name: 'Ceuta', offset: 1, pos: { lat: 35.8883, log: -5.3162 } },\n\t{ name: 'Canary', offset: 0, pos: { lat: 28.1248, log: -15.43 } }\n\t]\n}\n\nconst result = exp.eval('5*(7+9)==(5*7+5*9)')\nconsole.log(result)\n// Output: true\n\n// use context\nexp.eval('toNumber(phoneCode) \u003c= 30', context)\n// false\n\n// template\nexp.eval('`${name} belongs to ${region}`', context)\n// 'Spain belongs to Europe'\n\nexp.eval('timezones.filter(p =\u003e substring(p.name,0,1)==\"C\")', context)\n// ['{\"name\":\"Ceuta\",\"offset\":1,\"pos\":{\"lat\":35.8883,\"log\":-5.3162}}'\n// ,'{\"name\":\"Canary\",\"offset\":0,\"pos\":{\"lat\":28.1248,\"log\":-15.43}}']\n\nexp.eval('timezones.filter(p =\u003e p.offset == 1).sort(p =\u003e p.pos.lat).name', context)\n// ['Ceuta','Madrid']\n\nexp.eval('stringify(timezones.first(p =\u003e p.name == \"Madrid\").pos)', context)\n// '{\"lat\":40.4165,\"log\":-3.70256}'\n\nexp.eval('timezones.filter(p =\u003e p.pos.lat \u003e 30 \u0026\u0026 p.pos.log \u003e -4).pos.lat', context)\n// [40.4165]\n\nexp.eval('sort(timezones.name)', context)\n// ['Canary','Ceuta','Madrid']\n\nexp.eval('timezones[0].name', context)\n// 'Madrid'\n\nexp.eval('round(timezones.first(p=\u003e p.name ==\"Madrid\").pos.lat - timezones.first(p=\u003e p.name ==\"Ceuta\").pos.lat,2)', context)\n// 4.55\n\nexp.eval('timezones.each(p =\u003e p.pos={lat:round(p.pos.lat,2),log:round(p.pos.log,2)}).map(p=\u003e stringify(p))', context)\n// ['{\"name\":\"Madrid\",\"offset\":1,\"pos\":{\"lat\":40.4,\"log\":-3.7}}'\n// ,'{\"name\":\"Ceuta\",\"offset\":1,\"pos\":{\"lat\":35.9,\"log\":-5.3}}'\n// ,'{\"name\":\"Canary\",\"offset\":0,\"pos\":{\"lat\":28.1,\"log\":-15.45}}']\n\nexp.eval(`\nlist = [1, 2, 3, 4, 5, 6, 7, 8, 9];\ntotal = 0;\nfor (i = 0; i \u003c list.length(); i += 1) {\n\ttotal += list[i];\n}\n`, context)\nconsole.log(context.total)\n// 45\n\nexp.eval(`\nwhile (p=timezones.pop()) {\n\tconsole(p);\n}\n`, context)\n// outputs:\n//         {\"name\":\"Canary\",\"offset\":0,\"pos\":{\"lat\":28.1,\"log\":-15.45}}\n//         {\"name\":\"Ceuta\",\"offset\":1,\"pos\":{\"lat\":35.9,\"log\":-5.3}}\n//         {\"name\":\"Madrid\",\"offset\":1,\"pos\":{\"lat\":40.4,\"log\":-3.7}}\n```\n\n## Extend\n\nYou can extend the library by adding enums, constants, formats, operators, and functions.\nTo do this, use the following functions:\n\n- **AddConstant**: Adds a constant to the library.\n- **AddEnum**: Adds an enumeration to the library.\n- **AddFormat**: Adds a format to the library.\n- **AddOperator**: Adds an operator to the library.\n- **AddFunction**: Adds a function to the library.\n\n### Example\n\n```typescript\nimport { expressions as exp } from '3xpr'\nconst CryptoJS = require('crypto-js')\n\nexp.addFunction(\n\t'encrypt(value:string):string',\n\t(value: string, key:string):string =\u003e CryptoJS.AES.encrypt(value, key).toString(),\n\t{ description: 'Encrypt a string' }\n)\nexp.addFunction(\n\t'decrypt(value:string):string', \n\t(value: string, key:string):string =\u003e CryptoJS.AES.decrypt(value, key).toString(CryptoJS.enc.Utf8),\n\t{ description: 'Decrypt a string' }\n)\n```\n\n## Related projects\n\n- [typ3s](https://www.npmjs.com/package/typ3s)\n- [jexp](https://www.npmjs.com/package/jexp)\n- [lambdaorm](https://www.npmjs.com/package/lambdaorm)\n\n## Documentation\n\nFull documentation is available in the [Wiki](https://github.com/data7expressions/3xpr/wiki).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdata7expressions%2F3xpr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdata7expressions%2F3xpr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdata7expressions%2F3xpr/lists"}