@fw-components/formula-editor 2.0.7-formula-editor.39 → 2.0.7-formula-editor.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,6 +19,14 @@ export class Parser {
|
|
|
19
19
|
return false;
|
|
20
20
|
return !Number.isNaN(Number(value));
|
|
21
21
|
}
|
|
22
|
+
formatFormulaToken(token) {
|
|
23
|
+
for (let existingKey of this.variables.keys()) {
|
|
24
|
+
if (existingKey.toLowerCase() === token.toLowerCase()) {
|
|
25
|
+
return existingKey;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return token;
|
|
29
|
+
}
|
|
22
30
|
parseInput(formula, prevCurPos = null, recommendation = null) {
|
|
23
31
|
const tokens = getFormulaTokens(formula, this.formulaRegex);
|
|
24
32
|
const parentheses = new Stack();
|
|
@@ -38,6 +46,7 @@ export class Parser {
|
|
|
38
46
|
return parseOutput;
|
|
39
47
|
}
|
|
40
48
|
tokens?.forEach((token) => {
|
|
49
|
+
token = this.formatFormulaToken(token);
|
|
41
50
|
let isNumber = this.variables.has(token) || this.isNumber(token);
|
|
42
51
|
const isOperator = this.allowedOperators.has(token);
|
|
43
52
|
const isSpace = token.trim() === "";
|
|
@@ -81,11 +90,11 @@ export class Parser {
|
|
|
81
90
|
* Unknown symbol/variable/word
|
|
82
91
|
*/
|
|
83
92
|
if (!(isNumber || isOperator || isBracket || isSpace)) {
|
|
84
|
-
parseOutput.errorString = `${this.variableType} : ${token} does not exist`;
|
|
93
|
+
parseOutput.errorString = `${this.variableType} : '${token}' does not exist`;
|
|
85
94
|
expectation = Expectation.UNDEFINED;
|
|
86
95
|
}
|
|
87
96
|
else if (this.allowedOperators.has(previousToken) && isOperator) {
|
|
88
|
-
parseOutput.errorString = `
|
|
97
|
+
parseOutput.errorString = `Please use ${this.variableType}${this.allowedNumbers ? " or numbers" : ""} after '${previousToken}'. Pls do not use consecutive two mathametical operators (+ ,- ,* ,/ ,^)`;
|
|
89
98
|
expectation = Expectation.UNDEFINED;
|
|
90
99
|
}
|
|
91
100
|
else if (parentheses.isEmpty() && token === ")") {
|
|
@@ -98,14 +107,14 @@ export class Parser {
|
|
|
98
107
|
*/
|
|
99
108
|
else if (expectation === Expectation.VARIABLE && !isNumber && !isSpace && token != "("
|
|
100
109
|
&& !((unaryOperators.includes(token)) && (!parsedString.trim() || previousToken === "(" || this.allowedOperators.has(previousToken)))) {
|
|
101
|
-
parseOutput.errorString = `
|
|
110
|
+
parseOutput.errorString = `Please use ${this.variableType}${this.allowedNumbers ? " or numbers" : ""} after '${previousToken}'.`;
|
|
102
111
|
expectation = Expectation.UNDEFINED;
|
|
103
112
|
}
|
|
104
113
|
/**
|
|
105
114
|
* Multiple number/variable together without operator
|
|
106
115
|
*/
|
|
107
116
|
else if (expectation === Expectation.OPERATOR && !isOperator && !isSpace && token != ")") {
|
|
108
|
-
parseOutput.errorString = `
|
|
117
|
+
parseOutput.errorString = `Please use mathametical operators (${Array.from(this.allowedOperators).join(", ")}) after ${previousToken}.`;
|
|
109
118
|
expectation = Expectation.UNDEFINED;
|
|
110
119
|
}
|
|
111
120
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fw-components/formula-editor",
|
|
3
|
-
"version": "2.0.7-formula-editor.
|
|
3
|
+
"version": "2.0.7-formula-editor.40",
|
|
4
4
|
"description": "A WYSIWYG type formula editor",
|
|
5
5
|
"main": "dist/formula-editor/src/formula-editor.js",
|
|
6
6
|
"exports": {
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"@types/big.js": "^6.1.6",
|
|
32
32
|
"es-dev-server": "^2.1.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "5bf490d4aae797852b522a53bec12fcbf3d524bd"
|
|
35
35
|
}
|