Registry / productivity / formulex

formulex

JSON →
library0.0.60jsnpmunverified

Formulex is a lightweight, extensible library (v0.0.60, pre-1.0, rapid releases) that parses user-defined formulas (e.g., `{Field 1} + {Field 2} * 2`) into SQL expressions or executable JavaScript functions, with built-in AST support. It targets low-code platforms, dashboards, and dynamic logic engines. Key differentiators: built-in type casting for `dropdown`/`checkboxes` fields with id↔name mapping via CTE, minimal dependencies (only luxon for dates), and support for custom field mappings. Note: requires Node.js >= 22.11 < 23; work-in-progress, expect breaking changes.

npm install formulex
INSTALL
IMPORT
SIG · FORMULEX
F
formulex
productivityjavascriptv0.0.60
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Parser
✓ import { Parser } from 'formulex'
✗ const Parser = require('formulex')
ESM-only; CommonJS require() will not work as the package does not export a default. TypeScript types included.

Parses a formula using Parser, generates SQL and JS, then evaluates JS with variable values.

import { Parser } from 'formulex'; const fields = [ { id: '1', name: 'Field 1', type: 'number' }, { id: '2', name: 'Field 2', type: 'number' }, ]; const expression = '{Field_1} + {Field_2} * 2'; const parser = new Parser(expression, fields); const sql = parser.toSqlWithVariables(); // => (field_1 + (field_2 * 2)) const jsFormula = parser.toJs(); // => VARIABLES["1"] + (VARIABLES["2"] * 2) const result = parser.runJs(jsFormula, { 1: 10, 2: 5 }); // => 20 console.log({ sql, jsFormula, result });
Debug
Known issues
gotchaField names in formulas use underscores instead of spaces (e.g., {Field_1} not {Field 1}).
fix
Replace spaces with underscores in field name references within formulas.
affects: >=0.0.0
breakingNode.js version requirement: >= 22.11 < 23. May fail on older or newer Node versions.
fix
Ensure Node.js version satisfies range (e.g., use nvm to switch to v22.11+).
affects: >=0.0.0
breakingESM-only package; no CommonJS support. Using require() will throw an error.
fix
Use ES import syntax: import { Parser } from 'formulex';
affects: >=0.0.0
deprecatedAPI may change without notice as package is pre-1.0 and marked as work-in-progress.
fix
Pin to specific version and test updates thoroughly.
affects: >=0.0.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Using import in a CommonJS environment or Node < 22.11.
fix
Add "type": "module" in package.json or use .mjs extension, and ensure Node >= 22.11.
TypeError: formulex_1.Parser is not a constructor
Likely using require('formulex') which does not export default.
fix
Use import { Parser } from 'formulex' instead of require.
Upgrade
Version history
0.0.60latest on npm
Audit
Dependencies
luxonrequiredDate handling for field types like date
Agent activity
31 hits · last 30 days
node
28
OpenAI (training)
1
Resources
formulex — npm install formulex · libregistry