Socket
Book a DemoInstallSign in
Socket

@fw-components/formula-editor

Package Overview
Dependencies
Maintainers
2
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fw-components/formula-editor - npm Package Compare versions

Comparing version

to
2.1.1-formula-editor-regex-fix.1

29

dist/formula-editor/src/utils/parser.js

@@ -69,3 +69,3 @@ import Big from "big.js";

if (this.allowedOperators.has(token)) {
const updatedTokenString = `${token} ${recommendation} `;
const updatedTokenString = `${token} ${recommendation}`;
parseOutput.formattedString += updatedTokenString;

@@ -79,4 +79,4 @@ currentPosition += updatedTokenString.length;

const updatedTokenLength = recommendation.length - token.length;
parseOutput.newCursorPosition = Math.min(parseOutput.newCursorPosition, formula.length) + updatedTokenLength + 1;
token = recommendation + " ";
parseOutput.newCursorPosition = Math.min(parseOutput.newCursorPosition, formula.length) + updatedTokenLength;
token = recommendation;
recommendation = null;

@@ -95,7 +95,7 @@ }

if (!(isNumber || isOperator || isBracket || isSpace)) {
parseOutput.errorString = `${this.variableType} : '${token}' does not exist`;
parseOutput.errorString = `${this.variableType} : '${token}' doesn't exist.`;
expectation = Expectation.UNDEFINED;
}
else if (this.allowedOperators.has(previousToken) && isOperator) {
parseOutput.errorString = `Please use ${this.variableType}${this.allowedNumbers ? " or numbers" : ""} after '${previousToken}'. Pls do not use consecutive two mathametical operators (+ - * / ^)`;
parseOutput.errorString = `Please don't use mathematical operators (${Array.from(this.allowedOperators).join(" ")}) consecutively.`;
expectation = Expectation.UNDEFINED;

@@ -113,3 +113,3 @@ }

&& !((unaryOperators.includes(token)) && (!parsedString.trim() || previousToken === "(" || this.allowedOperators.has(previousToken)))) {
parseOutput.errorString = `Please use ${this.variableType}${this.allowedNumbers ? " or numbers" : ""} after '${previousToken}'.`;
parseOutput.errorString = `Please use ${this.variableType} ${this.variableType && this.allowedNumbers ? " or " : ''} ${this.allowedNumbers ? "numbers" : ""} after '${previousToken}'.`;
expectation = Expectation.UNDEFINED;

@@ -121,3 +121,3 @@ }

else if (expectation === Expectation.OPERATOR && !isOperator && !isSpace && token != ")") {
parseOutput.errorString = `Please use mathametical operators (${Array.from(this.allowedOperators).join(" ")}) after '${previousToken}'.`;
parseOutput.errorString = `Please use mathematical operators (${Array.from(this.allowedOperators).join(" ")}) after '${previousToken}'.`;
expectation = Expectation.UNDEFINED;

@@ -129,3 +129,3 @@ }

else if (isNumber && previousToken === "/" && (this.variables.get(token) === 0 || Number(token) === 0)) {
parseOutput.errorString = `Division by zero is not possible`;
parseOutput.errorString = `Division by zero is not possible.`;
expectation = Expectation.UNDEFINED;

@@ -137,3 +137,3 @@ }

else if (previousToken === "(" && token === ")") {
parseOutput.errorString = `Pls do not use empty brackets ().`;
parseOutput.errorString = `Please don't use empty brackets ().`;
expectation = Expectation.UNDEFINED;

@@ -163,4 +163,4 @@ }

if (recommendation) {
parseOutput.newCursorPosition = Math.min(parseOutput.newCursorPosition, formula.length) + recommendation.length + 1;
parseOutput.formattedString += recommendation + " ";
parseOutput.newCursorPosition = Math.min(parseOutput.newCursorPosition, formula.length) + recommendation.length;
parseOutput.formattedString += recommendation;
previousToken = recommendation;

@@ -172,3 +172,3 @@ }

if (this.allowedOperators.has(previousToken)) {
parseOutput.errorString = `Pls do not use mathametical operators (${Array.from(this.allowedOperators).join(",")}) at the end.`;
parseOutput.errorString = `Please don't use mathematical operators (${Array.from(this.allowedOperators).join(" ")}) at the end.`;
}

@@ -297,9 +297,5 @@ if (!parentheses.isEmpty()) {

if (!this.allowedOperators.has(frontItem)) {
console.log("frontitem", frontItem);
const [sign, variableKey] = /^[+-]/.test(frontItem) ? [frontItem[0], frontItem.slice(1)] : ["", frontItem];
const operandValue = Number.parseFloat(this.variables.get(variableKey)?.toString() ?? variableKey);
console.log("sign", sign);
console.log("variable", variableKey);
const number = Number.parseFloat(sign + "1") * operandValue;
console.log("number", number);
calcStack.push(Big(number));

@@ -318,3 +314,2 @@ }

case "+":
console.log("+", numA, " ", numB);
calcStack.push(Big(numA).add(Big(numB)));

@@ -321,0 +316,0 @@ break;

{
"name": "@fw-components/formula-editor",
"version": "2.1.1-formula-editor-regex-fix.0",
"version": "2.1.1-formula-editor-regex-fix.1",
"description": "A WYSIWYG type formula editor",

@@ -34,3 +34,3 @@ "main": "dist/formula-editor/src/formula-editor.js",

},
"gitHead": "701ff5ec75328a31286c1fc3c4359d90d16dd288"
"gitHead": "f2e7bb9ad6bb5cc28f19505193aaa0bbc9bb5cf7"
}