Fix some issues with Logic

values.hasOwnProperty(term) is needed as the if statement validates to false even if values contains the term  but the value of the term is currently false (yes / no option with default no)
This commit is contained in:
Teifun2 2022-11-12 17:34:20 +01:00 committed by Michael Schramm
parent 011a6baef4
commit 535c660f59

View File

@ -9,7 +9,7 @@ export const useMath = (): ((
) => boolean) => {
return (expression, values) => {
const parser = init(formula, (term: string) => {
if (values[term]) {
if (values.hasOwnProperty(term)) {
return values[term]
}
@ -17,20 +17,6 @@ export const useMath = (): ((
})
try {
let processed = expression
Object.keys(values).forEach((key) => {
const r = new RegExp(key.replace('$', '\\$'), 'ig')
const test = r.test(processed)
if (test) {
processed = processed.replace(r, String(values[key]))
}
})
parser.expressionToValue(expression)
return Boolean(parser.expressionToValue(expression))
} catch (e) {
logger(