Skip to content

Commit

Permalink
fix(util): arithmetic logic
Browse files Browse the repository at this point in the history
  • Loading branch information
narekhovhannisyan committed Oct 18, 2024
1 parent 1dc38b2 commit 93826da
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/utils/arithmetic-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ export const getParameterFromArithmeticExpression = (
*/
export const evaluateArithmeticOutput = (
outputParameter: string,
calculatedResult: number
output: PluginParams
) => {
const checkedOutputParameter =
getParameterFromArithmeticExpression(outputParameter);
const isValidExpression = isValidArithmeticExpression(outputParameter);
const calculatedResult = output[outputParameter]

if (
typeof outputParameter === 'string' &&
Expand All @@ -74,15 +75,22 @@ export const evaluateArithmeticOutput = (
.replace(/['"]/g, '');

const result = evaluateExpression(transformedOutputParameter);
delete output[outputParameter]

return {[checkedOutputParameter]: result};
return {
...output,
[checkedOutputParameter]: result
};
} else if (outputParameter !== checkedOutputParameter) {
throw new WrongArithmeticExpressionError(
`The output parameter \`${outputParameter}\` contains an invalid arithmetic expression. It should start with \`=\` and include the symbols \`*\`, \`+\`, \`-\` and \`/\`.`
);
}

return {[outputParameter]: calculatedResult};
return {
...output,
[outputParameter]: calculatedResult
};
};

/**
Expand Down

0 comments on commit 93826da

Please sign in to comment.