hot-formula-parser is a JavaScript library providing a `Parser` class capable of evaluating Excel and mathematical formulas. It supports a wide range of features including arithmetic, logical, and comparison operations, JavaScript Math constants, string concatenation, relative and absolute cell coordinates, custom variables, and custom functions. The current stable version is 4.0.0, released in 2023, which focuses on enhancing module compatibility for both CommonJS and ECMAScript environments. While major releases are not frequent, the project maintains an active development pace with dependency updates and feature enhancements. Its key differentiators include comprehensive Excel formula support via `@handsontable/formulajs`, robust error handling, and the flexibility to extend with custom logic, making it suitable for spreadsheet-like applications in both Node.js and browser environments.
npm install hot-formula-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing the parser, setting custom variables and functions, and parsing formulas with both custom and built-in logic, including error handling.
Review your formulas and replace usage of the deprecated functions with alternative logic or custom functions where possible. Refer to the `@handsontable/formula.js` documentation for compatible functions.
Thoroughly test existing formulas after upgrading to v3.0.0 or later. Consult the `@handsontable/formula.js` release notes for detailed changes.
For ESM, use `import { Parser } from 'hot-formula-parser';`. For CommonJS, `const { Parser } = require('hot-formula-parser');` is recommended. Ensure your build configuration (e.g., Webpack, Rollup) correctly handles module resolution.No direct fix is required for most users, as this improves security. However, if you have very unusual custom parsing logic that somehow interacted with the library's internal `eval` usage, review its behavior.
Ensure that all custom variables are set using `parser.setVariable(name, value)` and custom functions using `parser.setFunction(name, fn)` before parsing. Check for typos in function or variable names.
Modify the formula to prevent division by zero, or implement checks in your custom functions to handle zero divisors gracefully.
Ensure that the arguments passed to functions match their expected types (e.g., numbers for `SUM`). Validate user input or intermediate calculation results before they are fed into the parser.
Review the formula for syntax errors such as unmatched parentheses, incorrect delimiters, or invalid operator sequences. Use a linter or syntax highlighter for complex formulas if possible.