{"_id":"@data7expressions/3xpr","name":"@data7expressions/3xpr","dist-tags":{"latest":"5.0.0"},"versions":{"5.0.0":{"name":"@data7expressions/3xpr","version":"5.0.0","description":"expressions","author":{"name":"Flavio Lionel Rita","email":"flaviolrita@proton.me"},"license":"Apache-2.0 License","main":"index.js","types":"index.d.ts","publishConfig":{"access":"public"},"homepage":"https://data7expressions.github.com/wiki/3xpr","bugs":{"url":"https://github.com/data7expressions/wiki/issues"},"scripts":{"test":"npx jest --config jest-unit-config.json"},"dependencies":{"@data7expressions/h3lp":"^5.0.0","@data7expressions/typ3s":"^5.0.0"},"keywords":["expression","expressions","exp","parser","eval","evaluator"],"tags":["expression","expressions","exp","parser","eval","evaluator"],"gitHead":"5bca5aebadf4145a5313a1ddb5427b4cde159c1c","_id":"@data7expressions/3xpr@5.0.0","_nodeVersion":"24.16.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-zYRSgbAgRPQfMSd56E7cXNwRK6MM7nxXZyjzVOSkZhw3UHkmnaog875588jtJ7DfxXE7Uod23cKveYWQVvHH2Q==","shasum":"79b9c2fbac95ef76ec529e15a055f0c3256bfd80","tarball":"https://registry.npmjs.org/@data7expressions/3xpr/-/3xpr-5.0.0.tgz","fileCount":213,"unpackedSize":599424,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIAmX6yQqszfkWQBY6b0NBLnlcn0R2TwfKOhausbPKS1mAiEA+r0ZVnvQ0mip7ALGJT9VdOdEVkZTXHixKNwkm1vO8ho="}]},"_npmUser":{"name":"flaviolrita","email":"flaviolrita@proton.me"},"directories":{},"maintainers":[{"name":"flaviolrita","email":"flaviolrita@proton.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/3xpr_5.0.0_1783073222115_0.3091291143623023"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-03T10:07:01.961Z","5.0.0":"2026-07-03T10:07:02.250Z","modified":"2026-07-03T10:07:02.462Z"},"maintainers":[{"name":"flaviolrita","email":"flaviolrita@proton.me"}],"description":"expressions","homepage":"https://data7expressions.github.com/wiki/3xpr","keywords":["expression","expressions","exp","parser","eval","evaluator"],"author":{"name":"Flavio Lionel Rita","email":"flaviolrita@proton.me"},"bugs":{"url":"https://github.com/data7expressions/wiki/issues"},"license":"Apache-2.0 License","readme":"# 3xpr\n\n>3xpr is an extensible expression evaluator and parser.\n>\n>Besides the operators, functions, variables, objects and arrays that are supported.\n>\n>It 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) <= 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 => 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 => p.offset == 1).sort(p => p.pos.lat).name', context)\n// ['Ceuta','Madrid']\n\nexp.eval('stringify(timezones.first(p => p.name == \"Madrid\").pos)', context)\n// '{\"lat\":40.4165,\"log\":-3.70256}'\n\nexp.eval('timezones.filter(p => p.pos.lat > 30 && p.pos.log > -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=> p.name ==\"Madrid\").pos.lat - timezones.first(p=> p.name ==\"Ceuta\").pos.lat,2)', context)\n// 4.55\n\nexp.eval('timezones.each(p => p.pos={lat:round(p.pos.lat,2),log:round(p.pos.log,2)}).map(p=> 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 < 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 => 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 => 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/@data7expressions/typ3s)\n- [jexp](https://www.npmjs.com/package/@data7expressions/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","readmeFilename":"README.md","_rev":"1-c1fe4cb75dab018a5e6171874c55dee0"}