@dative-gpi/foundation-shared-components 1.0.154 → 1.0.155
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.
- package/package.json +4 -4
- package/utils/operations.ts +42 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dative-gpi/foundation-shared-components",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.155",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dative-gpi/foundation-shared-domain": "1.0.
|
|
14
|
-
"@dative-gpi/foundation-shared-services": "1.0.
|
|
13
|
+
"@dative-gpi/foundation-shared-domain": "1.0.155",
|
|
14
|
+
"@dative-gpi/foundation-shared-services": "1.0.155"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"@dative-gpi/bones-ui": "^1.0.0",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"sass": "1.71.1",
|
|
36
36
|
"sass-loader": "13.3.2"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "1cec447dda0a3f4af92ee9e6457134a5b4cf64e1"
|
|
39
39
|
}
|
package/utils/operations.ts
CHANGED
|
@@ -1,7 +1,42 @@
|
|
|
1
1
|
const MinusOperator = "-";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Splits an expression by operators while keeping unary minus signs.
|
|
5
|
+
*/
|
|
6
|
+
const splitByOperators = (expression: string): string[] => {
|
|
7
|
+
const tokens: string[] = [];
|
|
8
|
+
let current = '';
|
|
9
|
+
let expectOperand = true;
|
|
10
|
+
|
|
11
|
+
for (let i = 0; i < expression.length; i++) {
|
|
12
|
+
const char = expression[i];
|
|
13
|
+
if ('+-*/'.includes(char)) {
|
|
14
|
+
const isUnaryMinus = char === '-' && expectOperand;
|
|
15
|
+
if (isUnaryMinus) {
|
|
16
|
+
current += char;
|
|
17
|
+
expectOperand = true;
|
|
18
|
+
} else {
|
|
19
|
+
if (expectOperand) {
|
|
20
|
+
// 2 consecutive operators or operator at the start
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
if (current !== '') {
|
|
24
|
+
tokens.push(current);
|
|
25
|
+
current = '';
|
|
26
|
+
}
|
|
27
|
+
tokens.push(char);
|
|
28
|
+
expectOperand = true;
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
current += char;
|
|
32
|
+
expectOperand = false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (current !== '') {
|
|
36
|
+
tokens.push(current);
|
|
37
|
+
}
|
|
38
|
+
return tokens;
|
|
39
|
+
};
|
|
5
40
|
|
|
6
41
|
// Matches a nested block of parenthesis
|
|
7
42
|
const parenthesisRegex = new RegExp(/\([^)(]+\)/gm);
|
|
@@ -14,7 +49,11 @@ const validateBlock = (block: string, operands: string[] = [], variables: string
|
|
|
14
49
|
block = block.replaceAll("(", "").replaceAll(")", "");
|
|
15
50
|
|
|
16
51
|
// Split block on operators (Leave negative signs)
|
|
17
|
-
const
|
|
52
|
+
const tokens = splitByOperators(block);
|
|
53
|
+
if (tokens.length === 0) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const components = tokens.filter(token => !'+-*/'.includes(token));
|
|
18
57
|
|
|
19
58
|
// Check if each bit is a valid operand
|
|
20
59
|
for (let i = 0; i < components.length; i++) {
|