@lacspace/formula
A safe spreadsheet formula engine — parse and evaluate Excel-style formulas over rows and columns with no eval, no new Function and no dependencies. 110+ functions: SUM/AVERAGE/SUMIFS/COUNTIFS, IF/IFS/SWITCH, text, dates (EDATE, EOMONTH, DATEDIF, NETWORKDAYS), VLOOKUP-style LOOKUP/XLOOKUP/MATCH/INDEX, wildcard criteria, TEXT formats. Every function ships reference metadata for docs and autocomplete; validate as the user types with check(). The engine behind LUMIFORM in Lacspace's ERPs.
npm i @lacspace/formulaUsage
import { compile, computeColumn, check } from "@lacspace/formula";
const rows = [
{ item: "Shirt", qty: 2, rate: 850, cost: 600 },
{ item: "Jacket", qty: 1, rate: 2400, cost: 1900 },
{ item: "Scarf", qty: 5, rate: 450, cost: 300 },
];
// one formula, evaluated down a whole table
computeColumn("=qty * rate", rows); // [1700, 2400, 2250]
computeColumn("=(rate - cost) / rate * 100", rows); // margins per row
computeColumn("=rate / SUM(rate) * 100", rows); // bare names read the row, SUM(rate) reads the column
// compile once, run anywhere — no eval, ever
const margin = compile("=IF(rate = 0, 0, (rate - cost) / rate * 100)");
margin({ field: (n) => rows[0][n], column: (n) => rows.map((r) => r[n]) });
// validate as the user types
check("=1+2 3"); // { ok: false, error: 'Unexpected "3"', position: 4 }Exports 12
compileruncheckreferencescomputeColumntableScoperegisterFunctiondescribeFunctionFUNCTIONSFUNCTION_NAMESFUNCTION_DOCSAGGREGATESKeywords
formulaformula-engineformula-parserexcel-formulaspreadsheet-formulasumifvlookupexpression-evaluatorno-evalhyperformula-alternativezero-dependency