@judo/idem
Version:
A powerful and expressive query language designed for filtering and manipulating data
29 lines (28 loc) • 1.3 kB
TypeScript
import { ASTNode } from './types/ast';
export interface Self {
[key: string]: any;
}
export interface DateFunctions {
addDays: (date: Date | number, amount: number) => Date;
subDays: (date: Date | number, amount: number) => Date;
parseISO: (argument: string) => Date;
differenceInDays: (dateLeft: Date | number, dateRight: Date | number) => number;
differenceInSeconds: (dateLeft: Date | number, dateRight: Date | number) => number;
}
export interface EvalContext {
self: Self;
dateFunctions: DateFunctions;
}
export type EvalExpr = <T = unknown>(expr: string, ctx?: Pick<EvalContext, 'self'>) => T | undefined;
/**
* Creates a customized evaluation function with specific helper implementations.
* This allows for dependency injection of helper functions, making the expression
* evaluation more flexible and testable.
*
* @param other An object with full implementation of helper functions.
* @returns A new evalExpr-like function that uses the provided helper functions.
*/
export declare function createEvalExpr(other: Omit<EvalContext, 'self'>): EvalExpr;
export declare function evaluate(node: ASTNode, ctx: EvalContext): unknown;
export declare function compare(left: any, right: any): number;
export declare function toBoolean(value: unknown): boolean;