@fw-components/formula-editor 2.0.7-formula-editor.39 → 2.0.7-formula-editor.41

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.
@@ -1,4 +1,4 @@
1
- export const mathematicalOperators = new Set(["^", "+", "-", "*", "/"]);
1
+ export const mathematicalOperators = new Set(["+", "-", "*", "/", "^"]);
2
2
  export const unaryOperators = ["+", "-"];
3
3
  export const operatorPrecedence = {
4
4
  "^": 3,
@@ -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 = `Use ${this.variableType}${this.allowedNumbers ? " or numbers" : ""} after ${previousToken}. Pls do not use consecutive two mathametical operators (+,-,*,/,^)`;
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 = `Use ${this.variableType}${this.allowedNumbers ? " or numbers" : ""} after ${previousToken}.`;
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 = `Use mathametical operators (${Array.from(this.allowedOperators).join(",")}) after ${previousToken}.`;
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.39",
3
+ "version": "2.0.7-formula-editor.41",
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": "a3fb82b15d40e80873eaefdc8ab5b1d0ae13096c"
34
+ "gitHead": "c53252d71f716dfcaf8a1c1e7637f09edb715b3f"
35
35
  }