@totvs-agro/core-mobile
Version:
Core Mobile Totvs Agro (Front-End) para utilização dos estilos do T-Faces
45 lines (44 loc) • 1.65 kB
TypeScript
import { FormulaVariable } from './formula-variable';
import { FormulaResponse } from './formula-response';
/**
* Object to execute some formula with given variables.
* @example
const runner = new FormulaRunner('SUM([D],[C])');
runner.addVariable({identifier: 'A', value: 10, formula: null});
runner.addVariable({identifier: 'B', value: 5, formula: null});
runner.addVariable({identifier: 'C', value: null, formula: '[A]+[B]'});
runner.addVariable({identifier: 'D', value: null, formula: '[C] * 2'});
runner.run()
.then(response => console.log(response.result))
*/
export declare class FormulaRunner {
private _resultFormula;
private static VAR_FUNCTION_SEPARATOR;
private _variables;
constructor(_resultFormula: string);
/**
* Add a FormulaVariable to the runner.
* @param variable FormulaVariable
*/
addVariable(variable: FormulaVariable): void;
/**
* Modifies value of variable with the given identifier (only if has only one variable with the identifier)
* @param identifier Identifier of the variable to modify value
* @param value Value to be set
*/
setValue(identifier: string, value: any): void;
/**
* Runs the expression and return the result for the given formula
*/
run(): Promise<FormulaResponse>;
/**
* Translates the formula written by user, to be readed inside de API
* @param formula
*/
private translateFormula;
/**
* This method translates the error object from hot-parser-formula to an string message
* @param error
*/
private translateErrorMessage;
}