{"id":25582,"library":"filtrex","title":"Filtrex","description":"A JavaScript expression compiler that safely evaluates end-user-defined filter expressions by compiling them into sandboxed JavaScript functions. Current stable version is 3.1.0, with regular maintenance releases. Key differentiators: simple spreadsheet-like syntax, no eval, no loops or recursion (predictable), supports custom data and functions, ships TypeScript types, and is fast due to compiled output. Follows semver, breaking changes in v3 include stricter property access and boolean preservation.","status":"active","version":"3.1.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/cshaa/filtrex","tags":["javascript","typescript"],"install":[{"cmd":"npm install filtrex","lang":"bash","label":"npm"},{"cmd":"yarn add filtrex","lang":"bash","label":"yarn"},{"cmd":"pnpm add filtrex","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export not available; use named import since v1.","wrong":"import filtrex from 'filtrex'","symbol":"compileExpression","correct":"import { compileExpression } from 'filtrex'"},{"note":"CommonJS require must destructure the named export.","wrong":"const filtrex = require('filtrex')","symbol":"compileExpression (CommonJS)","correct":"const { compileExpression } = require('filtrex')"},{"note":"Types are included; FiltrexExpression is the type of the compiled function.","wrong":"","symbol":"TypeScript types","correct":"import type { FiltrexExpression } from 'filtrex'"}],"quickstart":{"code":"import { compileExpression } from 'filtrex';\n\n// Compile user-provided filter expression\nconst expr = compileExpression(`category == \"meal\" and (calories * weight > 2000.0 or subcategory in (\"cake\", \"pie\"))`);\n\n// Execute on data\nconst data = {\n  category: 'meal',\n  calories: 500,\n  weight: 5,\n  subcategory: 'cake'\n};\n\nconsole.log(expr(data)); // true\n\n// With custom functions\nconst expr2 = compileExpression(`x > 10`, { customFunctions: { double: (n) => n * 2 } });\nconsole.log(expr2({ x: 15 })); // true","lang":"typescript","description":"Compile and execute a filter expression with data and custom functions."},"warnings":[{"fix":"Update expressions to only access properties present in the data object, or add a check before passing data.","message":"Property access on non-existent data properties now throws an error instead of returning undefined.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Review expressions that relied on numeric coercion of booleans, e.g., `(a > 5) + (b < 3)` will now throw an error instead of summing numbers.","message":"Logical operations now return proper booleans (true/false) instead of 1/0.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Add parentheses to ensure intended order: `(2 ** 3) ** 2` if right-to-left not desired.","message":"Exponentiation operator precedence corrected; `2 ** 3 ** 2` is now `2 ** (3 ** 2)` = 512 instead of `(2 ** 3) ** 2` = 64.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"If negative results are needed, use custom function with Math.abs or adjust logic.","message":"Modulo operator now always returns a positive result (like JavaScript's % but with sign of divisor).","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Escape backslashes in all string literals used in expressions.","message":"Backslash must be escaped in string literals: `\"\\\\\"` for a single backslash.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Update links and references to point to new repo.","message":"Old GitHub repository URL `github.com/m93a/filtrex` is deprecated; use `github.com/cshaa/filtrex`.","severity":"deprecated","affected_versions":">=3.1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure all properties accessed in the expression exist in the data object, or use optional chaining via custom functions.","cause":"Expression references a property not present in the data object (breaking change in v3).","error":"Error: Cannot access property 'xxx' of undefined"},{"fix":"Use logical operators (and, or, not) instead of arithmetic on booleans.","cause":"Expression returns a number or string where a boolean is expected (e.g., using + on booleans).","error":"TypeError: Expression returned ... instead of boolean"},{"fix":"Escape backslashes: use '\\\\' for a backslash, or wrap string in double quotes and use literal newline.","cause":"String literal contains unescaped backslash or invalid escape sequence (e.g., '\\n' instead of literal newline).","error":"SyntaxError: Unexpected token '}'"},{"fix":"Register the function via the customFunctions option in compileExpression's second argument.","cause":"Expression calls a function not defined in the customFunctions option.","error":"Error: Unknown function 'foo'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}