@danielsimonjr/mathts-expression 0.6.7 → 0.7.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.
- package/dist/index.js +118 -73
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -164,6 +164,11 @@ function isRange(x) {
|
|
|
164
164
|
const obj = x;
|
|
165
165
|
return obj.constructor?.prototype?.isRange === true;
|
|
166
166
|
}
|
|
167
|
+
function isIndex(x) {
|
|
168
|
+
if (!x || typeof x !== "object") return false;
|
|
169
|
+
const obj = x;
|
|
170
|
+
return obj.constructor?.prototype?.isIndex === true;
|
|
171
|
+
}
|
|
167
172
|
function isHelp(x) {
|
|
168
173
|
if (!x || typeof x !== "object") return false;
|
|
169
174
|
const obj = x;
|
|
@@ -756,7 +761,8 @@ var createParse = /* @__PURE__ */ factory(
|
|
|
756
761
|
">=": true,
|
|
757
762
|
"<<": true,
|
|
758
763
|
">>": true,
|
|
759
|
-
">>>": true
|
|
764
|
+
">>>": true,
|
|
765
|
+
".": true
|
|
760
766
|
};
|
|
761
767
|
const NAMED_DELIMITERS = {
|
|
762
768
|
mod: true,
|
|
@@ -851,25 +857,28 @@ var createParse = /* @__PURE__ */ factory(
|
|
|
851
857
|
const c1 = currentCharacter(state);
|
|
852
858
|
const c2 = currentString(state, 2);
|
|
853
859
|
const c3 = currentString(state, 3);
|
|
860
|
+
let delim = "";
|
|
854
861
|
if (c3.length === 3 && DELIMITERS[c3]) {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
862
|
+
delim = c3;
|
|
863
|
+
} else if (c2.length === 2 && DELIMITERS[c2]) {
|
|
864
|
+
delim = c2;
|
|
865
|
+
} else if (DELIMITERS[c1]) {
|
|
866
|
+
delim = c1;
|
|
867
|
+
}
|
|
868
|
+
if (delim) {
|
|
869
|
+
if (delim.endsWith(".") && parse.isDigit(state.expression.charAt(state.index + delim.length))) {
|
|
870
|
+
delim = delim.slice(0, -1);
|
|
871
|
+
if (delim.length > 0 && !DELIMITERS[delim]) {
|
|
872
|
+
delim = "";
|
|
873
|
+
}
|
|
874
|
+
}
|
|
868
875
|
}
|
|
869
|
-
if (
|
|
876
|
+
if (delim) {
|
|
870
877
|
state.tokenType = 1 /* DELIMITER */;
|
|
871
|
-
state.token =
|
|
872
|
-
|
|
878
|
+
state.token = delim;
|
|
879
|
+
for (let i = 0; i < delim.length; i++) {
|
|
880
|
+
next(state);
|
|
881
|
+
}
|
|
873
882
|
return;
|
|
874
883
|
}
|
|
875
884
|
if (parse.isDigitDot(c1)) {
|
|
@@ -904,10 +913,6 @@ var createParse = /* @__PURE__ */ factory(
|
|
|
904
913
|
if (currentCharacter(state) === ".") {
|
|
905
914
|
state.token += currentCharacter(state);
|
|
906
915
|
next(state);
|
|
907
|
-
if (!parse.isDigit(currentCharacter(state))) {
|
|
908
|
-
state.tokenType = 1 /* DELIMITER */;
|
|
909
|
-
return;
|
|
910
|
-
}
|
|
911
916
|
} else {
|
|
912
917
|
while (parse.isDigit(currentCharacter(state))) {
|
|
913
918
|
state.token += currentCharacter(state);
|
|
@@ -1023,26 +1028,29 @@ var createParse = /* @__PURE__ */ factory(
|
|
|
1023
1028
|
function parseBlock(state) {
|
|
1024
1029
|
let node;
|
|
1025
1030
|
const blocks = [];
|
|
1026
|
-
let
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
if (state.
|
|
1030
|
-
node.comment = state.comment;
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
while (state.token === "\n" || state.token === ";") {
|
|
1034
|
-
if (blocks.length === 0 && node) {
|
|
1035
|
-
visible = state.token !== ";";
|
|
1036
|
-
blocks.push({ node, visible });
|
|
1037
|
-
}
|
|
1038
|
-
getToken(state);
|
|
1039
|
-
if (state.token !== "\n" && state.token !== ";" && state.token !== "") {
|
|
1031
|
+
let hasSeparators = false;
|
|
1032
|
+
let nodePushed = true;
|
|
1033
|
+
while (state.token !== "") {
|
|
1034
|
+
if (state.token !== "\n" && state.token !== ";") {
|
|
1040
1035
|
node = parseAssignment(state);
|
|
1036
|
+
nodePushed = false;
|
|
1041
1037
|
if (state.comment) {
|
|
1042
1038
|
node.comment = state.comment;
|
|
1043
1039
|
}
|
|
1044
|
-
|
|
1045
|
-
|
|
1040
|
+
}
|
|
1041
|
+
if (state.token === "\n" || state.token === ";") {
|
|
1042
|
+
hasSeparators = true;
|
|
1043
|
+
if (node && !nodePushed) {
|
|
1044
|
+
blocks.push({ node, visible: state.token !== ";" });
|
|
1045
|
+
nodePushed = true;
|
|
1046
|
+
}
|
|
1047
|
+
getToken(state);
|
|
1048
|
+
} else {
|
|
1049
|
+
if (node && hasSeparators && !nodePushed) {
|
|
1050
|
+
blocks.push({ node, visible: state.token !== ";" });
|
|
1051
|
+
nodePushed = true;
|
|
1052
|
+
}
|
|
1053
|
+
break;
|
|
1046
1054
|
}
|
|
1047
1055
|
}
|
|
1048
1056
|
if (blocks.length > 0) {
|
|
@@ -1787,9 +1795,15 @@ var createParserClass = /* @__PURE__ */ factory(
|
|
|
1787
1795
|
Parser.prototype.type = "Parser";
|
|
1788
1796
|
Parser.prototype.isParser = true;
|
|
1789
1797
|
Parser.prototype.evaluate = function(expr) {
|
|
1798
|
+
if (typeof expr !== "string" && !Array.isArray(expr)) {
|
|
1799
|
+
throw new TypeError('String or string array expected for parameter "expr"');
|
|
1800
|
+
}
|
|
1790
1801
|
return evaluate(expr, this.scope);
|
|
1791
1802
|
};
|
|
1792
1803
|
Parser.prototype.get = function(name47) {
|
|
1804
|
+
if (typeof name47 !== "string") {
|
|
1805
|
+
throw new TypeError('String expected for parameter "name"');
|
|
1806
|
+
}
|
|
1793
1807
|
return this.scope.has(name47) ? this.scope.get(name47) : void 0;
|
|
1794
1808
|
};
|
|
1795
1809
|
Parser.prototype.getAll = function() {
|
|
@@ -7860,6 +7874,72 @@ function errorTransform(err) {
|
|
|
7860
7874
|
return err;
|
|
7861
7875
|
}
|
|
7862
7876
|
|
|
7877
|
+
// src/utils/array.ts
|
|
7878
|
+
import {
|
|
7879
|
+
arraySize,
|
|
7880
|
+
validate,
|
|
7881
|
+
validateIndexSourceSize,
|
|
7882
|
+
validateIndex,
|
|
7883
|
+
isEmptyIndex,
|
|
7884
|
+
resize,
|
|
7885
|
+
reshape,
|
|
7886
|
+
processSizesWildcard,
|
|
7887
|
+
squeeze,
|
|
7888
|
+
unsqueeze,
|
|
7889
|
+
flatten,
|
|
7890
|
+
map,
|
|
7891
|
+
forEach,
|
|
7892
|
+
filter,
|
|
7893
|
+
filterRegExp,
|
|
7894
|
+
join,
|
|
7895
|
+
identify,
|
|
7896
|
+
generalize,
|
|
7897
|
+
getArrayDataType,
|
|
7898
|
+
last,
|
|
7899
|
+
initial,
|
|
7900
|
+
concat,
|
|
7901
|
+
broadcastSizes,
|
|
7902
|
+
checkBroadcastingRules,
|
|
7903
|
+
broadcastTo,
|
|
7904
|
+
broadcastArrays,
|
|
7905
|
+
stretch,
|
|
7906
|
+
getArrayElement,
|
|
7907
|
+
deepMapArray,
|
|
7908
|
+
deepForEachArray,
|
|
7909
|
+
cloneArray
|
|
7910
|
+
} from "@danielsimonjr/mathts-core/internal";
|
|
7911
|
+
|
|
7912
|
+
// src/error/DimensionError.ts
|
|
7913
|
+
import { DimensionError } from "@danielsimonjr/mathts-core/internal";
|
|
7914
|
+
|
|
7915
|
+
// src/node/utils/stringSubset.ts
|
|
7916
|
+
function getStringSubset(str, index) {
|
|
7917
|
+
if (!isIndex(index)) {
|
|
7918
|
+
throw new TypeError("Index expected");
|
|
7919
|
+
}
|
|
7920
|
+
if (isEmptyIndex(index)) {
|
|
7921
|
+
return "";
|
|
7922
|
+
}
|
|
7923
|
+
validateIndexSourceSize(Array.from(str), index);
|
|
7924
|
+
if (index.size().length !== 1) {
|
|
7925
|
+
throw new DimensionError(index.size().length, 1);
|
|
7926
|
+
}
|
|
7927
|
+
const strLen = str.length;
|
|
7928
|
+
validateIndex(index.min()[0], strLen);
|
|
7929
|
+
validateIndex(index.max()[0], strLen);
|
|
7930
|
+
const range = index.dimension(0);
|
|
7931
|
+
let substr = "";
|
|
7932
|
+
function callback(v) {
|
|
7933
|
+
substr += str.charAt(v);
|
|
7934
|
+
}
|
|
7935
|
+
if (Number.isInteger(range)) {
|
|
7936
|
+
callback(range);
|
|
7937
|
+
} else {
|
|
7938
|
+
range.forEach(callback);
|
|
7939
|
+
}
|
|
7940
|
+
return substr;
|
|
7941
|
+
}
|
|
7942
|
+
|
|
7863
7943
|
// src/node/utils/access.ts
|
|
7864
7944
|
function accessFactory({ subset }) {
|
|
7865
7945
|
return function access(object, index) {
|
|
@@ -7869,7 +7949,7 @@ function accessFactory({ subset }) {
|
|
|
7869
7949
|
} else if (object && typeof object.subset === "function") {
|
|
7870
7950
|
return object.subset(index);
|
|
7871
7951
|
} else if (typeof object === "string") {
|
|
7872
|
-
return
|
|
7952
|
+
return getStringSubset(object, index);
|
|
7873
7953
|
} else if (typeof object === "object") {
|
|
7874
7954
|
if (!index.isObjectProperty()) {
|
|
7875
7955
|
throw new TypeError("Cannot apply a numeric index as object property");
|
|
@@ -8085,41 +8165,6 @@ var createAccessorNode = /* @__PURE__ */ factory(
|
|
|
8085
8165
|
{ isClass: true, isNode: true }
|
|
8086
8166
|
);
|
|
8087
8167
|
|
|
8088
|
-
// src/utils/array.ts
|
|
8089
|
-
import {
|
|
8090
|
-
arraySize,
|
|
8091
|
-
validate,
|
|
8092
|
-
validateIndexSourceSize,
|
|
8093
|
-
validateIndex,
|
|
8094
|
-
isEmptyIndex,
|
|
8095
|
-
resize,
|
|
8096
|
-
reshape,
|
|
8097
|
-
processSizesWildcard,
|
|
8098
|
-
squeeze,
|
|
8099
|
-
unsqueeze,
|
|
8100
|
-
flatten,
|
|
8101
|
-
map,
|
|
8102
|
-
forEach,
|
|
8103
|
-
filter,
|
|
8104
|
-
filterRegExp,
|
|
8105
|
-
join,
|
|
8106
|
-
identify,
|
|
8107
|
-
generalize,
|
|
8108
|
-
getArrayDataType,
|
|
8109
|
-
last,
|
|
8110
|
-
initial,
|
|
8111
|
-
concat,
|
|
8112
|
-
broadcastSizes,
|
|
8113
|
-
checkBroadcastingRules,
|
|
8114
|
-
broadcastTo,
|
|
8115
|
-
broadcastArrays,
|
|
8116
|
-
stretch,
|
|
8117
|
-
getArrayElement,
|
|
8118
|
-
deepMapArray,
|
|
8119
|
-
deepForEachArray,
|
|
8120
|
-
cloneArray
|
|
8121
|
-
} from "@danielsimonjr/mathts-core/internal";
|
|
8122
|
-
|
|
8123
8168
|
// src/node/ArrayNode.ts
|
|
8124
8169
|
var name7 = "ArrayNode";
|
|
8125
8170
|
var dependencies7 = ["Node"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielsimonjr/mathts-expression",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Expression parser and evaluator for MathTS",
|
|
5
5
|
"author": "Daniel Simon Jr.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"build:prod": "tsup src/index.ts --format esm --dts --clean --minify --treeshake"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@danielsimonjr/mathts-core": "^0.
|
|
34
|
+
"@danielsimonjr/mathts-core": "^0.14.0",
|
|
35
35
|
"typed-function": "^4.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"repository": {
|
|
47
47
|
"type": "git",
|
|
48
|
-
"url": "git+https://github.com/danielsimonjr/
|
|
48
|
+
"url": "git+https://github.com/danielsimonjr/MathTS.git",
|
|
49
49
|
"directory": "expression"
|
|
50
50
|
},
|
|
51
51
|
"keywords": [
|