@kelta/formula — API Reference

Every symbol exported from @kelta/formula, the formula engine, with its TypeScript signature and doc summary — generated from the package entry point.

Every symbol exported from @kelta/formula, with its TypeScript signature and the first paragraph of its doc comment — generated from kelta-web/packages/formula/src/index.ts. For a guided tour with examples, see @kelta/formula.

37 exports, grouped by kind and sorted by name.

Classes#

FormulaEvaluator#

class FormulaEvaluator {
    constructor(opts?: FormulaEvaluatorOptions);
    registerFunction(fn: FormulaFunction): void;
    parse(expression: string): FormulaAst;
    evaluate(expression: string, fieldValues: Record<string, unknown>): unknown;
    evaluateBoolean(expression: string, fieldValues: Record<string, unknown>): boolean;
    validate(expression: string): void;
    extractFieldRefs(expression: string): string[];
    evict(expression: string): void;
    clearCache(): void;
    cacheSize(): number;
}

FormulaException#

class FormulaException extends Error {
    constructor(message: string, position?: number | undefined);
    readonly position?: number | undefined;
}

FormulaParser#

class FormulaParser {
    parse(expression: string): FormulaAst;
}

Functions#

buildBuiltinMap#

function buildBuiltinMap(extra?: FormulaFunction[]): Map<string, FormulaFunction>;

evaluateAst#

function evaluateAst(node: FormulaAst, context: FormulaContext): unknown;

extractFieldRefs#

function extractFieldRefs(node: FormulaAst, out?: Set<string>): Set<string>;

toBoolean#

function toBoolean(value: unknown): boolean;

toDouble#

function toDouble(value: unknown): number;

Constants#

ABS#

const ABS: FormulaFunction;

ALL_BUILTINS#

const ALL_BUILTINS: FormulaFunction[];

AND_FN#

const AND_FN: FormulaFunction;

BLANKVALUE#

const BLANKVALUE: FormulaFunction;

CONTAINS#

const CONTAINS: FormulaFunction;

DATEDIFF#

const DATEDIFF: FormulaFunction;

IF#

const IF: FormulaFunction;

ISBLANK#

const ISBLANK: FormulaFunction;

LEN#

const LEN: FormulaFunction;

LOWER#

const LOWER: FormulaFunction;

MAX_FN#

const MAX_FN: FormulaFunction;

MIN_FN#

const MIN_FN: FormulaFunction;

NOT_FN#

const NOT_FN: FormulaFunction;

NOW#

const NOW: FormulaFunction;

OR_FN#

const OR_FN: FormulaFunction;

REGEX#

const REGEX: FormulaFunction;

ROUND#

const ROUND: FormulaFunction;

TEXT#

const TEXT: FormulaFunction;

TODAY#

const TODAY: FormulaFunction;

TRIM#

const TRIM: FormulaFunction;

UPPER#

const UPPER: FormulaFunction;

VALUE#

const VALUE: FormulaFunction;

Interfaces#

FormulaEvaluatorOptions#

interface FormulaEvaluatorOptions {
    cacheMaxSize?: number;
    functions?: FormulaFunction[];
}

Type aliases#

BinaryOperator#

type BinaryOperator = "+" | "-" | "*" | "/" | ">" | "<" | ">=" | "<=" | "=" | "==" | "!=" | "<>" | "&&" | "||";

FormulaAst#

type FormulaAst = {
    kind: "literal";
    value: unknown;
} | {
    kind: "fieldRef";
    fieldName: string;
} | {
    kind: "binaryOp";
    operator: BinaryOperator;
    left: FormulaAst;
    right: FormulaAst;
} | {
    kind: "unaryOp";
    operator: UnaryOperator;
    operand: FormulaAst;
} | {
    kind: "functionCall";
    functionName: string;
    arguments: FormulaAst[];
};

FormulaContext#

type FormulaContext = {
    fieldValues: Record<string, unknown>;
    functions: Map<string, FormulaFunction>;
};

FormulaFunction#

type FormulaFunction = {
    name: string;
    execute(args: unknown[], context: FormulaContext): unknown;
};

FormulaValue#

type FormulaValue = string | number | boolean | null | undefined;

UnaryOperator#

type UnaryOperator = "-" | "!";

Edit this page on GitHub