From 535c660f59647f923a71ce37cfb08b2cf88306c7 Mon Sep 17 00:00:00 2001 From: Teifun2 Date: Sat, 12 Nov 2022 17:34:20 +0100 Subject: [PATCH] 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) --- components/use.math.ts | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/components/use.math.ts b/components/use.math.ts index 2273492..a157f1e 100644 --- a/components/use.math.ts +++ b/components/use.math.ts @@ -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(