UNPKG

@grnsft/if-core

Version:

If core utilities.

48 lines (47 loc) 2.57 kB
import { PluginParams, ArithmeticParameters } from '../types'; /** * Extracts a parameter from an arithmetic expression. */ export declare const getParameterFromArithmeticExpression: (arithmeticParameter: string) => any; /** * Evaluates an arithmetic expression provided as a string and returns the result. * The function first checks if the `outputParameter` contains an assignment ('=') and extracts the parameter * from the expression. If found, the expression is transformed by replacing the assignment and the parameter * with the `calculatedResult`, and then evaluated using `eval`. The result is returned as an object. * If no assignment is found, the function returns the original `outputParameter` with the `calculatedResult`. */ export declare const evaluateArithmeticOutput: (outputParameter: string, output: PluginParams) => PluginParams; /** * Evaluates and updates the input by replacing its properties * with the results of arithmetic expressions. */ export declare const evaluateInput: (input: PluginParams) => PluginParams; /** * Evaluates and updates the config by replacing its properties * with the results of arithmetic expressions. */ export declare const evaluateConfig: (options: ArithmeticParameters) => any; /** * Checks if the provided parameter is a valid arithmetic expression. * The function uses a regular expression to validate arithmetic expressions * that consist of numbers, alphanumeric strings, or quoted strings, * separated by arithmetic operators (+, -, *, /). The expression can contain * whitespace and support basic arithmetic operations. */ export declare const isValidArithmeticExpression: (parameter: string) => boolean; /** * Evaluates a simple arithmetic expression if the input is a valid expression. * It checks if the input string follows a pattern for simple arithmetic * operations (numbers with operators like *, /, +, -) between them. */ export declare const evaluateSimpleArithmeticExpression: (parameter: string) => any; /** * Validates whether a given value is a valid arithmetic expression. * * If the value is a string, it first removes any equal signs and checks if it * is a valid arithmetic expression using the `isValidArithmeticExpression` helper. * If valid, it attempts to evaluate the expression and ensures the result is numeric. * In case of an invalid format, it calls `validateExpressionFormat`. * The function returns true if the value is valid or numeric. */ export declare const validateArithmeticExpression: (parameterName: string, value: any, type?: any) => any;