feat(engine): 🚸 Always evaluate Set variable
This commit is contained in:
@ -20,30 +20,15 @@ export const parseVariables =
|
||||
})
|
||||
}
|
||||
|
||||
export const isMathFormula = (str?: string) =>
|
||||
['*', '/', '+', '-'].some((val) => str && str.includes(val))
|
||||
|
||||
export const evaluateExpression = (str: string) => {
|
||||
const result = replaceCommasWithDots(str)
|
||||
try {
|
||||
const evaluatedNumber = safeEval(result) as number
|
||||
if (countDecimals(evaluatedNumber) > 2) {
|
||||
return evaluatedNumber.toFixed(2)
|
||||
}
|
||||
return evaluatedNumber.toString()
|
||||
const evaluatedResult = safeEval(str)
|
||||
return evaluatedResult.toString()
|
||||
} catch (err) {
|
||||
return result
|
||||
return str
|
||||
}
|
||||
}
|
||||
|
||||
const replaceCommasWithDots = (str: string) =>
|
||||
str.replace(new RegExp(/(\d+)(,)(\d+)/, 'g'), '$1.$3')
|
||||
|
||||
const countDecimals = (value: number) => {
|
||||
if (value % 1 != 0) return value.toString().split('.')[1].length
|
||||
return 0
|
||||
}
|
||||
|
||||
export const parseVariablesInObject = (
|
||||
object: { [key: string]: string | number },
|
||||
variables: Variable[]
|
||||
|
Reference in New Issue
Block a user