@fw-components/formula-editor 2.3.0 → 2.3.2-formula-editor-regex-fix.0

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.
@@ -6,7 +6,7 @@ import { Expectation } from "../types";
6
6
  import { operatorPrecedence, unaryOperators, mathematicalOperators } from "./constants.js";
7
7
  import { getFormulaTokens } from "./get-formula-tokens.js";
8
8
  export class Parser {
9
- constructor(variables, minSuggestionLen, formulaRegex = /[A-Za-z0-9_#@]+|[-+(),*^/\s]/g, allowedNumbers = true, allowedOperators = mathematicalOperators, variableType = "") {
9
+ constructor(variables, minSuggestionLen, formulaRegex = /[A-Za-z0-9_#@.]+|[-+(),*^/\s]/g, allowedNumbers = true, allowedOperators = mathematicalOperators, variableType = "") {
10
10
  this.variables = variables;
11
11
  this.formulaRegex = formulaRegex;
12
12
  this._recommender = new Recommender(Array.from(this.variables.keys()), minSuggestionLen);
@@ -90,11 +90,11 @@ export class Parser {
90
90
  * Unknown symbol/variable/word
91
91
  */
92
92
  if (!(isNumber || isOperator || isBracket || isSpace)) {
93
- parseOutput.errorString = `${this.variableType} : '${token}' does not exist`;
93
+ parseOutput.errorString = `${this.variableType} : '${token}' doesn't exist.`;
94
94
  expectation = Expectation.UNDEFINED;
95
95
  }
96
96
  else if (this.allowedOperators.has(previousToken) && isOperator) {
97
- parseOutput.errorString = `Please use ${this.variableType}${this.allowedNumbers ? " or numbers" : ""} after '${previousToken}'. Pls do not use consecutive two mathametical operators (+ - * / ^)`;
97
+ parseOutput.errorString = `Please don't use mathematical operators (${Array.from(this.allowedOperators).join(" ")}) consecutively.`;
98
98
  expectation = Expectation.UNDEFINED;
99
99
  }
100
100
  else if (parentheses.isEmpty() && token === ")") {
@@ -107,28 +107,28 @@ export class Parser {
107
107
  */
108
108
  else if (expectation === Expectation.VARIABLE && !isNumber && !isSpace && token != "("
109
109
  && !((unaryOperators.includes(token)) && (!parsedString.trim() || previousToken === "(" || this.allowedOperators.has(previousToken)))) {
110
- parseOutput.errorString = `Please use ${this.variableType}${this.allowedNumbers ? " or numbers" : ""} after '${previousToken}'.`;
110
+ parseOutput.errorString = `Please use ${this.variableType} ${this.variableType && this.allowedNumbers ? " or " : ''} ${this.allowedNumbers ? "numbers" : ""} after '${previousToken}'.`;
111
111
  expectation = Expectation.UNDEFINED;
112
112
  }
113
113
  /**
114
114
  * Multiple number/variable together without operator
115
115
  */
116
116
  else if (expectation === Expectation.OPERATOR && !isOperator && !isSpace && token != ")") {
117
- parseOutput.errorString = `Please use mathametical operators (${Array.from(this.allowedOperators).join(" ")}) after '${previousToken}'.`;
117
+ parseOutput.errorString = `Please use mathematical operators (${Array.from(this.allowedOperators).join(" ")}) after '${previousToken}'.`;
118
118
  expectation = Expectation.UNDEFINED;
119
119
  }
120
120
  /**
121
121
  * division by zero
122
122
  */
123
123
  else if (isNumber && previousToken === "/" && (this.variables.get(token) === 0 || Number(token) === 0)) {
124
- parseOutput.errorString = `Division by zero is not possible`;
124
+ parseOutput.errorString = `Division by zero is not possible.`;
125
125
  expectation = Expectation.UNDEFINED;
126
126
  }
127
127
  /**
128
128
  * Empty brackets
129
129
  */
130
130
  else if (previousToken === "(" && token === ")") {
131
- parseOutput.errorString = `Pls do not use empty brackets ().`;
131
+ parseOutput.errorString = `Please don't use empty brackets ().`;
132
132
  expectation = Expectation.UNDEFINED;
133
133
  }
134
134
  }
@@ -161,7 +161,7 @@ export class Parser {
161
161
  parseOutput.recommendations = !parseOutput.errorString?.length ? Array.from(this.variables.keys()) : [];
162
162
  }
163
163
  if (this.allowedOperators.has(previousToken)) {
164
- parseOutput.errorString = `Pls do not use mathametical operators (${Array.from(this.allowedOperators).join(",")}) at the end.`;
164
+ parseOutput.errorString = `Please don't use mathematical operators (${Array.from(this.allowedOperators).join(" ")}) at the end.`;
165
165
  }
166
166
  if (!parentheses.isEmpty()) {
167
167
  parseOutput.errorString = "Unexpected opening bracket. Make sure all closing brackets ')' have matching opening brackets '('.";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fw-components/formula-editor",
3
- "version": "2.3.0",
3
+ "version": "2.3.2-formula-editor-regex-fix.0",
4
4
  "description": "A WYSIWYG type formula editor",
5
5
  "main": "dist/formula-editor/src/formula-editor.js",
6
6
  "exports": {
@@ -19,7 +19,7 @@
19
19
  "prepublishOnly": "npm run build"
20
20
  },
21
21
  "dependencies": {
22
- "@fw-components/styles": "^2.3.0",
22
+ "@fw-components/styles": "^2.3.2-formula-editor-regex-fix.0",
23
23
  "big.js": "^6.2.1",
24
24
  "lit": "^2.1.2",
25
25
  "match-sorter": "^8.0.0",
@@ -31,5 +31,5 @@
31
31
  "@types/big.js": "^6.1.6",
32
32
  "es-dev-server": "^2.1.0"
33
33
  },
34
- "gitHead": "8d6a4d40e1207f2f71368aa140af51d134755508"
34
+ "gitHead": "8fd2867417367489a6b009e1d58a4cdccade3520"
35
35
  }