UNPKG

yarn-spinner-runner-ts

Version:

TypeScript parser, compiler, and runtime for Yarn Spinner 3.x with React adapter [NPM package](https://www.npmjs.com/package/yarn-spinner-runner-ts)

56 lines (55 loc) 1.94 kB
/** * Safe expression evaluator for Yarn Spinner conditions. * Supports variables, functions, comparisons, and logical operators. */ export declare class ExpressionEvaluator { private variables; private functions; private enums; private smartVariables; constructor(variables?: Record<string, unknown>, functions?: Record<string, (...args: unknown[]) => unknown>, enums?: Record<string, string[]>); /** * Evaluate a condition expression and return a boolean result. * Supports: variables, literals (numbers, strings, booleans), comparisons, logical ops, function calls. */ evaluate(expr: string): boolean; /** * Evaluate an expression that can return any value (not just boolean). */ evaluateExpression(expr: string): unknown; private preprocess; private evaluateFunctionCall; private parseArguments; private containsComparison; private looksLikeFunctionCall; private containsArithmetic; private evaluateArithmetic; private evaluateComparison; private evaluateLogical; private resolveValue; /** * Resolve shorthand enum (.CaseName) when setting a variable with known enum type */ resolveEnumValue(expr: string, enumName?: string): string; /** * Get enum type for a variable (if it was declared with enum type) */ getEnumTypeForVariable(varName: string): string | undefined; private deepEquals; /** * Update variables. Can be used to mutate state during dialogue. */ setVariable(name: string, value: unknown): void; /** * Register a smart variable (variable with expression that recalculates on access). */ setSmartVariable(name: string, expression: string): void; /** * Check if a variable is a smart variable. */ isSmartVariable(name: string): boolean; /** * Get variable value. */ getVariable(name: string): unknown; }