@danielsimonjr/mathts-expression 0.6.3 → 0.6.5

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.d.ts CHANGED
@@ -70,6 +70,40 @@ declare function isAssociativeWith(nodeA: unknown, nodeB: unknown, parenthesis:
70
70
  */
71
71
  declare function getOperator(fn: string): string | null;
72
72
 
73
+ /**
74
+ * Some of this file's helpers are consolidated onto core (see the re-exports at
75
+ * the bottom): `isFactory`, `assertDependencies`, `isOptionalDependency`,
76
+ * `stripOptionalNotation`, and the plain-data types `LegacyFactory`/`FactoryMeta`/
77
+ * `DependencyName` are byte-for-byte equivalent to
78
+ * `@danielsimonjr/mathts-core/internal`'s copies (proven via a fast-check property
79
+ * harness — see `functions/tests/dedup-bucketB-equivalence.test.ts`) and are
80
+ * re-exported from there.
81
+ *
82
+ * `factory`/`FactoryFunction`/`CreateFunction` remain DELIBERATELY KEPT LOCAL — NOT
83
+ * safe to redirect: `factory()`'s generic `CreateFunction<TDeps extends
84
+ * Record<string, unknown>, ...>` constraint (core's copy) rejects real call sites
85
+ * across this package (and `functions`) whose destructured dependency objects are
86
+ * typed as plain interfaces without an index signature — confirmed empirically:
87
+ * redirecting it broke `tsc --noEmit` with dozens of TS2345 errors. This mirrors the
88
+ * `functions` package's pre-existing `@typescript-eslint/no-explicit-any`
89
+ * workaround comment on its own local `CreateFunction`, which independently
90
+ * documents the exact same constraint mismatch.
91
+ *
92
+ * `sortFactories`/`create` are now ADOPTED from core (Bucket B, commit 2): they
93
+ * don't depend on `factory()`'s generic constraint (they only operate on already-
94
+ * constructed `FactoryFunction`/`LegacyFactory` values), so they aren't blocked by
95
+ * the divergence above. Core's `sortFactories` throws on ANY circular dependency —
96
+ * direct or indirect (see `core/tests/factory-sort.test.ts`) — which is a
97
+ * deliberate fix over this file's FORMER local copy, which only special-cased
98
+ * direct 2-cycles and otherwise silently broke longer cycles via a visited-set
99
+ * guard without throwing (see `functions/tests/dedup-bucketB-equivalence.test.ts`'s
100
+ * former "PROVEN DIVERGENCE" block, now updated to reflect the adoption). Verified
101
+ * this package's real `factory()` call sites are never fed through `sortFactories`/
102
+ * `create` in production (both are otherwise-unused mathjs legacy machinery here —
103
+ * every real node/parse factory is wired by hand with an explicit dependency
104
+ * object, e.g. `expression/tests/helpers/bootstrap.ts`), so there is no live
105
+ * dependency graph that could hit the stricter throw.
106
+ */
73
107
  /**
74
108
  * Type for a factory function that creates instances
75
109
  */
package/dist/index.js CHANGED
@@ -142,9 +142,6 @@ function isBigInt(x) {
142
142
  function isComplex(x) {
143
143
  return !!(x && typeof x === "object" && Object.getPrototypeOf(x).isComplex === true);
144
144
  }
145
- function isFraction(x) {
146
- return !!(x && typeof x === "object" && Object.getPrototypeOf(x).isFraction === true);
147
- }
148
145
  function isUnit(x) {
149
146
  if (!x || typeof x !== "object") return false;
150
147
  const obj = x;
@@ -175,19 +172,6 @@ function isHelp(x) {
175
172
  function isFunction(x) {
176
173
  return typeof x === "function";
177
174
  }
178
- function isObject(x) {
179
- return !!(x && typeof x === "object" && x.constructor === Object && !isComplex(x) && !isFraction(x));
180
- }
181
- function isMap(object) {
182
- if (!object) {
183
- return false;
184
- }
185
- if (object instanceof Map) {
186
- return true;
187
- }
188
- const mapLike = object;
189
- return typeof mapLike.set === "function" && typeof mapLike.get === "function" && typeof mapLike.keys === "function" && typeof mapLike.has === "function";
190
- }
191
175
  function isAccessorNode(x) {
192
176
  if (!x || typeof x !== "object") return false;
193
177
  const obj = x;
@@ -604,24 +588,15 @@ function getOperator(fn) {
604
588
  return null;
605
589
  }
606
590
 
607
- // src/error/MathjsError.ts
608
- var MathjsError = class _MathjsError extends Error {
609
- isMathjsError = true;
610
- /**
611
- * Create a MathjsError
612
- * @param message Error message
613
- */
614
- constructor(message) {
615
- super(message);
616
- this.name = "MathjsError";
617
- const { captureStackTrace } = Error;
618
- if (captureStackTrace) {
619
- captureStackTrace(this, _MathjsError);
620
- }
621
- }
622
- };
623
-
624
591
  // src/utils/factory.ts
592
+ import {
593
+ isFactory,
594
+ assertDependencies,
595
+ isOptionalDependency,
596
+ stripOptionalNotation,
597
+ sortFactories as coreSortFactories,
598
+ create as coreCreate
599
+ } from "@danielsimonjr/mathts-core/internal";
625
600
  function factory(name47, dependencies47, create, meta) {
626
601
  function assertAndCreate(scope) {
627
602
  const deps = pickShallow(scope, dependencies47.map(stripOptionalNotation));
@@ -636,70 +611,15 @@ function factory(name47, dependencies47, create, meta) {
636
611
  }
637
612
  return assertAndCreate;
638
613
  }
639
- function assertDependencies(name47, dependencies47, scope) {
640
- const allDefined = dependencies47.filter((dependency) => !isOptionalDependency(dependency)).every((dependency) => scope[dependency] !== void 0);
641
- if (!allDefined) {
642
- const missingDependencies = dependencies47.filter(
643
- (dependency) => scope[dependency] === void 0
644
- );
645
- throw new MathjsError(
646
- `Cannot create function "${name47}", some dependencies are missing: ${missingDependencies.map((d) => `"${d}"`).join(", ")}.`
647
- );
648
- }
649
- }
650
- function isOptionalDependency(dependency) {
651
- return Boolean(dependency && dependency[0] === "?");
652
- }
653
- function stripOptionalNotation(dependency) {
654
- return dependency && dependency[0] === "?" ? dependency.slice(1) : dependency;
655
- }
656
614
 
657
- // src/error/IndexError.ts
658
- var IndexError = class _IndexError extends RangeError {
659
- index;
660
- min;
661
- max;
662
- isIndexError = true;
663
- /**
664
- * Create an IndexError
665
- *
666
- * Can be called in two ways:
667
- * - IndexError(index, max) - assumes min=0
668
- * - IndexError(index, min, max)
669
- *
670
- * @param index The actual index
671
- * @param min Minimum index (included), or max if only 2 args provided
672
- * @param max Maximum index (excluded)
673
- */
674
- constructor(index, min, max) {
675
- let actualMin;
676
- let actualMax;
677
- if (max === void 0) {
678
- actualMin = 0;
679
- actualMax = min;
680
- } else {
681
- actualMin = min;
682
- actualMax = max;
683
- }
684
- let message;
685
- if (actualMin !== void 0 && index < actualMin) {
686
- message = "Index out of range (" + index + " < " + actualMin + ")";
687
- } else if (actualMax !== void 0 && index >= actualMax) {
688
- message = "Index out of range (" + index + " > " + (actualMax - 1) + ")";
689
- } else {
690
- message = "Index out of range (" + index + ")";
691
- }
692
- super(message);
693
- this.index = index;
694
- this.min = actualMin;
695
- this.max = actualMax;
696
- this.name = "IndexError";
697
- const { captureStackTrace } = Error;
698
- if (captureStackTrace) {
699
- captureStackTrace(this, _IndexError);
700
- }
701
- }
702
- };
615
+ // src/utils/collection.ts
616
+ import {
617
+ containsCollections,
618
+ deepForEach,
619
+ deepMap,
620
+ reduce,
621
+ scatter
622
+ } from "@danielsimonjr/mathts-core/internal";
703
623
 
704
624
  // src/utils/number.ts
705
625
  import {
@@ -730,283 +650,6 @@ import {
730
650
  toPrecision
731
651
  } from "@danielsimonjr/mathts-core/internal";
732
652
 
733
- // src/utils/bignumber/formatter.ts
734
- function formatBigNumberToBase(n, base, size) {
735
- const BigNumberCtor = n.constructor;
736
- const big2 = new BigNumberCtor(2);
737
- let suffix = "";
738
- if (size) {
739
- if (size < 1) {
740
- throw new Error("size must be in greater than 0");
741
- }
742
- if (!isInteger(size)) {
743
- throw new Error("size must be an integer");
744
- }
745
- if (n.greaterThan(big2.pow(size - 1).sub(1)) || n.lessThan(big2.pow(size - 1).mul(-1))) {
746
- throw new Error(`Value must be in range [-2^${size - 1}, 2^${size - 1}-1]`);
747
- }
748
- if (!n.isInteger()) {
749
- throw new Error("Value must be an integer");
750
- }
751
- if (n.lessThan(0)) {
752
- n = n.add(big2.pow(size));
753
- }
754
- suffix = `i${size}`;
755
- }
756
- switch (base) {
757
- case 2:
758
- return `${n.toBinary()}${suffix}`;
759
- case 8:
760
- return `${n.toOctal()}${suffix}`;
761
- case 16:
762
- return `${n.toHexadecimal()}${suffix}`;
763
- default:
764
- throw new Error(`Base ${base} not supported `);
765
- }
766
- }
767
- function format2(value, options) {
768
- if (typeof options === "function") {
769
- return options(value);
770
- }
771
- if (!value.isFinite()) {
772
- return value.isNaN() ? "NaN" : value.gt(0) ? "Infinity" : "-Infinity";
773
- }
774
- const { notation, precision, wordSize } = normalizeFormatOptions(options);
775
- switch (notation) {
776
- case "fixed":
777
- return toFixed2(value, precision);
778
- case "exponential":
779
- return toExponential2(value, precision);
780
- case "engineering":
781
- return toEngineering2(value, precision);
782
- case "bin":
783
- return formatBigNumberToBase(value, 2, wordSize);
784
- case "oct":
785
- return formatBigNumberToBase(value, 8, wordSize);
786
- case "hex":
787
- return formatBigNumberToBase(value, 16, wordSize);
788
- case "auto": {
789
- const optionsObject = typeof options === "object" ? options : void 0;
790
- const lowerExp = _toNumberOrDefault(optionsObject?.lowerExp, -3);
791
- const upperExp = _toNumberOrDefault(optionsObject?.upperExp, 5);
792
- if (value.isZero()) return "0";
793
- let str;
794
- const rounded = value.toSignificantDigits(precision);
795
- const exp = rounded.e;
796
- if (exp >= lowerExp && exp < upperExp) {
797
- str = rounded.toFixed();
798
- } else {
799
- str = toExponential2(value, precision);
800
- }
801
- return str.replace(
802
- /((\.\d*?)(0+))($|e)/,
803
- function(_match, _g1, digits2, _g3, e) {
804
- return digits2 !== "." ? digits2 + e : e;
805
- }
806
- );
807
- }
808
- default:
809
- throw new Error(
810
- 'Unknown notation "' + notation + '". Choose "auto", "exponential", "fixed", "bin", "oct", or "hex.'
811
- );
812
- }
813
- }
814
- function toEngineering2(value, precision) {
815
- const e = value.e;
816
- const newExp = e % 3 === 0 ? e : e < 0 ? e - 3 - e % 3 : e - e % 3;
817
- const valueWithoutExp = value.mul(Math.pow(10, -newExp));
818
- let valueStr = valueWithoutExp.toPrecision(precision);
819
- if (valueStr.includes("e")) {
820
- const BigNumber = value.constructor;
821
- valueStr = new BigNumber(valueStr).toFixed();
822
- }
823
- return valueStr + "e" + (e >= 0 ? "+" : "") + newExp.toString();
824
- }
825
- function toExponential2(value, precision) {
826
- if (precision !== void 0) {
827
- return value.toExponential(precision - 1);
828
- } else {
829
- return value.toExponential();
830
- }
831
- }
832
- function toFixed2(value, precision) {
833
- return value.toFixed(precision);
834
- }
835
- function _toNumberOrDefault(value, defaultValue) {
836
- if (isNumber(value)) {
837
- return value;
838
- } else if (isBigNumber(value)) {
839
- return value.toNumber();
840
- } else {
841
- return defaultValue;
842
- }
843
- }
844
-
845
- // src/utils/string.ts
846
- function format3(value, options) {
847
- const result = _format(value, options);
848
- if (options && typeof options === "object" && "truncate" in options && result.length > options.truncate) {
849
- return result.substring(0, options.truncate - 3) + "...";
850
- }
851
- return result;
852
- }
853
- function _format(value, options) {
854
- if (typeof value === "number") {
855
- return format(value, options);
856
- }
857
- if (isBigNumber(value)) {
858
- return format2(
859
- value,
860
- options
861
- );
862
- }
863
- if (looksLikeFraction(value)) {
864
- const v = value;
865
- const opts = options;
866
- if (!opts || opts.fraction !== "decimal") {
867
- const signedNumerator = typeof v.n === "bigint" ? BigInt(v.s) * v.n : v.s * v.n;
868
- return `${signedNumerator}/${v.d}`;
869
- } else {
870
- return v.toString();
871
- }
872
- }
873
- if (Array.isArray(value)) {
874
- return formatArray(value, options);
875
- }
876
- if (isString(value)) {
877
- return stringify(value);
878
- }
879
- if (typeof value === "function") {
880
- const fn = value;
881
- return fn.syntax ? String(fn.syntax) : "function";
882
- }
883
- if (value && typeof value === "object") {
884
- const v = value;
885
- if (typeof v.format === "function") {
886
- return v.format(options);
887
- } else if (value && v.toString(options) !== {}.toString()) {
888
- return v.toString(options);
889
- } else {
890
- const entries = Object.keys(value).map((key) => {
891
- return stringify(key) + ": " + format3(value[key], options);
892
- });
893
- return "{" + entries.join(", ") + "}";
894
- }
895
- }
896
- return String(value);
897
- }
898
- function stringify(value) {
899
- const text = String(value);
900
- let escaped = "";
901
- let i = 0;
902
- while (i < text.length) {
903
- const c = text.charAt(i);
904
- escaped += c in controlCharacters ? controlCharacters[c] : c;
905
- i++;
906
- }
907
- return '"' + escaped + '"';
908
- }
909
- var controlCharacters = {
910
- '"': '\\"',
911
- "\\": "\\\\",
912
- "\b": "\\b",
913
- "\f": "\\f",
914
- "\n": "\\n",
915
- "\r": "\\r",
916
- " ": "\\t"
917
- };
918
- function escape(value) {
919
- let text = String(value);
920
- text = text.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
921
- return text;
922
- }
923
- function formatArray(array, options) {
924
- if (Array.isArray(array)) {
925
- let str = "[";
926
- const len = array.length;
927
- for (let i = 0; i < len; i++) {
928
- if (i !== 0) {
929
- str += ", ";
930
- }
931
- str += formatArray(array[i], options);
932
- }
933
- str += "]";
934
- return str;
935
- } else {
936
- return format3(array, options);
937
- }
938
- }
939
- function looksLikeFraction(value) {
940
- return !!value && typeof value === "object" && typeof value.s === "bigint" && typeof value.n === "bigint" && typeof value.d === "bigint" || false;
941
- }
942
-
943
- // src/utils/array.ts
944
- function map(array, callback) {
945
- return Array.prototype.map.call(array, callback);
946
- }
947
- function forEach(array, callback) {
948
- Array.prototype.forEach.call(array, callback);
949
- }
950
- function join(array, separator) {
951
- return Array.prototype.join.call(array, separator);
952
- }
953
- function deepMap(array, callback, skipIndex = false) {
954
- if (Array.isArray(array) && array.length === 0) {
955
- return [];
956
- }
957
- if (skipIndex) {
958
- return recursiveMap(array);
959
- }
960
- const index = [];
961
- return recursiveMapWithIndex(array, 0);
962
- function recursiveMapWithIndex(value, depth) {
963
- if (Array.isArray(value)) {
964
- const N = value.length;
965
- const result = Array(N);
966
- for (let i = 0; i < N; i++) {
967
- index[depth] = i;
968
- result[i] = recursiveMapWithIndex(value[i], depth + 1);
969
- }
970
- return result;
971
- } else {
972
- return callback(
973
- value,
974
- index.slice(0, depth),
975
- array
976
- );
977
- }
978
- }
979
- function recursiveMap(value) {
980
- if (Array.isArray(value)) {
981
- const N = value.length;
982
- const result = Array(N);
983
- for (let i = 0; i < N; i++) {
984
- result[i] = recursiveMap(value[i]);
985
- }
986
- return result;
987
- } else {
988
- return callback(value);
989
- }
990
- }
991
- }
992
-
993
- // src/utils/collection.ts
994
- function deepMap2(array, callback, skipZeros) {
995
- if (!skipZeros) {
996
- if (isMatrix(array)) {
997
- return array.map((x) => callback(x), false, true);
998
- } else {
999
- return deepMap(array, callback, true);
1000
- }
1001
- }
1002
- const skipZerosCallback = (x) => x === 0 ? x : callback(x);
1003
- if (isMatrix(array)) {
1004
- return array.map((x) => skipZerosCallback(x), false, true);
1005
- } else {
1006
- return deepMap(array, skipZerosCallback, true);
1007
- }
1008
- }
1009
-
1010
653
  // src/parse.ts
1011
654
  var name = "parse";
1012
655
  var dependencies = [
@@ -1067,7 +710,7 @@ var createParse = /* @__PURE__ */ factory(
1067
710
  });
1068
711
  function parseMultiple(expressions, options = {}) {
1069
712
  const extraNodes = options.nodes !== void 0 ? options.nodes : {};
1070
- return deepMap2(
713
+ return deepMap(
1071
714
  expressions,
1072
715
  function(elem) {
1073
716
  if (typeof elem !== "string") throw new TypeError("String expected");
@@ -1653,11 +1296,11 @@ var createParse = /* @__PURE__ */ factory(
1653
1296
  }
1654
1297
  function parseMultiplyDivideModulus(state) {
1655
1298
  let node;
1656
- let last;
1299
+ let last2;
1657
1300
  let name47;
1658
1301
  let fn;
1659
1302
  node = parseImplicitMultiplication(state);
1660
- last = node;
1303
+ last2 = node;
1661
1304
  const operators = {
1662
1305
  "*": "multiply",
1663
1306
  ".*": "dotMultiply",
@@ -1671,8 +1314,8 @@ var createParse = /* @__PURE__ */ factory(
1671
1314
  name47 = state.token;
1672
1315
  fn = operators[name47];
1673
1316
  getTokenSkipNewline(state);
1674
- last = parseImplicitMultiplication(state);
1675
- node = new OperatorNode(name47, fn, [node, last]);
1317
+ last2 = parseImplicitMultiplication(state);
1318
+ node = new OperatorNode(name47, fn, [node, last2]);
1676
1319
  } else {
1677
1320
  break;
1678
1321
  }
@@ -1681,16 +1324,16 @@ var createParse = /* @__PURE__ */ factory(
1681
1324
  }
1682
1325
  function parseImplicitMultiplication(state) {
1683
1326
  let node;
1684
- let last;
1327
+ let last2;
1685
1328
  node = parseRule2(state);
1686
- last = node;
1329
+ last2 = node;
1687
1330
  while (true) {
1688
- if (state.tokenType === 3 /* SYMBOL */ || state.token === "in" && isConstantNode(node) || state.token === "in" && isOperatorNode(node) && node.fn === "unaryMinus" && isConstantNode(node.args[0]) || state.tokenType === 2 /* NUMBER */ && !isConstantNode(last) && (!isOperatorNode(last) || last.op === "!") || state.token === "(") {
1689
- last = parseRule2(state);
1331
+ if (state.tokenType === 3 /* SYMBOL */ || state.token === "in" && isConstantNode(node) || state.token === "in" && isOperatorNode(node) && node.fn === "unaryMinus" && isConstantNode(node.args[0]) || state.tokenType === 2 /* NUMBER */ && !isConstantNode(last2) && (!isOperatorNode(last2) || last2.op === "!") || state.token === "(") {
1332
+ last2 = parseRule2(state);
1690
1333
  node = new OperatorNode(
1691
1334
  "*",
1692
1335
  "multiply",
1693
- [node, last],
1336
+ [node, last2],
1694
1337
  true
1695
1338
  /* implicit */
1696
1339
  );
@@ -1702,10 +1345,10 @@ var createParse = /* @__PURE__ */ factory(
1702
1345
  }
1703
1346
  function parseRule2(state) {
1704
1347
  let node = parseUnaryPercentage(state);
1705
- let last = node;
1348
+ let last2 = node;
1706
1349
  const tokenStates = [];
1707
1350
  while (true) {
1708
- if (state.token === "/" && rule2Node(last)) {
1351
+ if (state.token === "/" && rule2Node(last2)) {
1709
1352
  tokenStates.push(Object.assign({}, state));
1710
1353
  getTokenSkipNewline(state);
1711
1354
  if (state.tokenType === 2 /* NUMBER */) {
@@ -1714,8 +1357,8 @@ var createParse = /* @__PURE__ */ factory(
1714
1357
  if (state.tokenType === 3 /* SYMBOL */ || state.token === "(" || state.token === "in") {
1715
1358
  Object.assign(state, tokenStates.pop());
1716
1359
  tokenStates.pop();
1717
- last = parseUnaryPercentage(state);
1718
- node = new OperatorNode("/", "divide", [node, last]);
1360
+ last2 = parseUnaryPercentage(state);
1361
+ node = new OperatorNode("/", "divide", [node, last2]);
1719
1362
  } else {
1720
1363
  tokenStates.pop();
1721
1364
  Object.assign(state, tokenStates.pop());
@@ -2114,225 +1757,16 @@ var createParse = /* @__PURE__ */ factory(
2114
1757
  }
2115
1758
  );
2116
1759
 
2117
- // src/utils/customs.ts
2118
- function getSafeProperty(object, prop) {
2119
- if (isSafeProperty(object, prop)) {
2120
- return object[prop];
2121
- }
2122
- if (typeof object[prop] === "function" && isSafeMethod(object, prop)) {
2123
- throw new Error('Cannot access method "' + String(prop) + '" as a property');
2124
- }
2125
- throw new Error('No access to property "' + String(prop) + '"');
2126
- }
2127
- function setSafeProperty(object, prop, value) {
2128
- if (isSafeProperty(object, prop)) {
2129
- object[prop] = value;
2130
- return value;
2131
- }
2132
- throw new Error('No access to property "' + String(prop) + '"');
2133
- }
2134
- function isSafeProperty(object, prop) {
2135
- if (!isPlainObject(object) && !Array.isArray(object)) {
2136
- return false;
2137
- }
2138
- if (hasOwnProperty(safeNativeProperties, prop)) {
2139
- return true;
2140
- }
2141
- if (prop in Object.prototype) {
2142
- return false;
2143
- }
2144
- if (prop in Function.prototype) {
2145
- return false;
2146
- }
2147
- return true;
2148
- }
2149
- function getSafeMethod(object, method) {
2150
- if (!isSafeMethod(object, method)) {
2151
- throw new Error('No access to method "' + String(method) + '"');
2152
- }
2153
- return object[method];
2154
- }
2155
- function isSafeMethod(object, method) {
2156
- if (object === null || object === void 0 || typeof object[method] !== "function") {
2157
- return false;
2158
- }
2159
- if (hasOwnProperty(object, method) && Object.getPrototypeOf && method in Object.getPrototypeOf(object)) {
2160
- return false;
2161
- }
2162
- if (hasOwnProperty(safeNativeMethods, method)) {
2163
- return true;
2164
- }
2165
- if (method in Object.prototype) {
2166
- return false;
2167
- }
2168
- if (method in Function.prototype) {
2169
- return false;
2170
- }
2171
- return true;
2172
- }
2173
- function isPlainObject(object) {
2174
- return typeof object === "object" && !!object && object.constructor === Object;
2175
- }
2176
- var safeNativeProperties = {
2177
- length: true,
2178
- name: true
2179
- };
2180
- var safeNativeMethods = {
2181
- toString: true,
2182
- valueOf: true,
2183
- toLocaleString: true
2184
- };
2185
-
2186
1760
  // src/utils/map.ts
2187
- var ObjectWrappingMap = class {
2188
- wrappedObject;
2189
- [Symbol.toStringTag] = "ObjectWrappingMap";
2190
- constructor(object) {
2191
- this.wrappedObject = object;
2192
- this[Symbol.iterator] = this.entries;
2193
- }
2194
- // @ts-expect-error: Implementation is compatible but TS can't infer it
2195
- keys() {
2196
- return Object.keys(this.wrappedObject).filter((key) => this.has(key)).values();
2197
- }
2198
- get(key) {
2199
- return getSafeProperty(this.wrappedObject, key);
2200
- }
2201
- set(key, value) {
2202
- setSafeProperty(this.wrappedObject, key, value);
2203
- return this;
2204
- }
2205
- has(key) {
2206
- return isSafeProperty(this.wrappedObject, key) && key in this.wrappedObject;
2207
- }
2208
- // @ts-expect-error: Implementation is compatible but TS can't infer it
2209
- entries() {
2210
- return mapIterator(this.keys(), (key) => [key, this.get(key)]);
2211
- }
2212
- // @ts-expect-error: Implementation is compatible but TS can't infer it
2213
- *values() {
2214
- for (const key of this.keys()) {
2215
- yield this.get(key);
2216
- }
2217
- }
2218
- forEach(callback) {
2219
- for (const key of this.keys()) {
2220
- callback(this.get(key), key, this);
2221
- }
2222
- }
2223
- delete(key) {
2224
- if (isSafeProperty(this.wrappedObject, key)) {
2225
- delete this.wrappedObject[key];
2226
- return true;
2227
- }
2228
- return false;
2229
- }
2230
- clear() {
2231
- for (const key of this.keys()) {
2232
- this.delete(key);
2233
- }
2234
- }
2235
- get size() {
2236
- return Object.keys(this.wrappedObject).length;
2237
- }
2238
- };
2239
- var PartitionedMap = class {
2240
- a;
2241
- b;
2242
- bKeys;
2243
- [Symbol.toStringTag] = "PartitionedMap";
2244
- /**
2245
- * @param a - Primary map
2246
- * @param b - Secondary map
2247
- * @param bKeys - Set of keys that should be read/written to map b
2248
- */
2249
- constructor(a, b, bKeys) {
2250
- this.a = a;
2251
- this.b = b;
2252
- this.bKeys = bKeys;
2253
- this[Symbol.iterator] = this.entries;
2254
- }
2255
- get(key) {
2256
- return this.bKeys.has(key) ? this.b.get(key) : this.a.get(key);
2257
- }
2258
- set(key, value) {
2259
- if (this.bKeys.has(key)) {
2260
- this.b.set(key, value);
2261
- } else {
2262
- this.a.set(key, value);
2263
- }
2264
- return this;
2265
- }
2266
- has(key) {
2267
- return this.b.has(key) || this.a.has(key);
2268
- }
2269
- // @ts-expect-error: Implementation is compatible but TS can't infer it
2270
- keys() {
2271
- return (/* @__PURE__ */ new Set([...this.a.keys(), ...this.b.keys()]))[Symbol.iterator]();
2272
- }
2273
- // @ts-expect-error: Implementation is compatible but TS can't infer it
2274
- *values() {
2275
- for (const key of this.keys()) {
2276
- yield this.get(key);
2277
- }
2278
- }
2279
- // @ts-expect-error: Implementation is compatible but TS can't infer it
2280
- entries() {
2281
- return mapIterator(this.keys(), (key) => [key, this.get(key)]);
2282
- }
2283
- forEach(callback) {
2284
- for (const key of this.keys()) {
2285
- callback(this.get(key), key, this);
2286
- }
2287
- }
2288
- delete(key) {
2289
- return this.bKeys.has(key) ? this.b.delete(key) : this.a.delete(key);
2290
- }
2291
- clear() {
2292
- this.a.clear();
2293
- this.b.clear();
2294
- }
2295
- get size() {
2296
- return [...this.keys()].length;
2297
- }
2298
- };
2299
- function mapIterator(it, callback) {
2300
- return {
2301
- next: () => {
2302
- const n = it.next();
2303
- return n.done ? n : {
2304
- value: callback(n.value),
2305
- done: false
2306
- };
2307
- }
2308
- };
2309
- }
2310
- function createEmptyMap() {
2311
- return /* @__PURE__ */ new Map();
2312
- }
2313
- function createMap(mapOrObject) {
2314
- if (!mapOrObject) {
2315
- return createEmptyMap();
2316
- }
2317
- if (isMap(mapOrObject)) {
2318
- return mapOrObject;
2319
- }
2320
- if (isObject(mapOrObject)) {
2321
- return new ObjectWrappingMap(mapOrObject);
2322
- }
2323
- throw new Error("createMap can create maps from objects or Maps");
2324
- }
2325
- function toObject(map2) {
2326
- if (map2 instanceof ObjectWrappingMap) {
2327
- return map2.wrappedObject;
2328
- }
2329
- const object = {};
2330
- for (const key of map2.keys()) {
2331
- const value = map2.get(key);
2332
- setSafeProperty(object, key, value);
2333
- }
2334
- return object;
2335
- }
1761
+ import {
1762
+ ObjectWrappingMap,
1763
+ PartitionedMap,
1764
+ createEmptyMap,
1765
+ createMap,
1766
+ toObject,
1767
+ assignMap,
1768
+ isObjectWrappingMap
1769
+ } from "@danielsimonjr/mathts-core/internal";
2336
1770
 
2337
1771
  // src/Parser.ts
2338
1772
  var name2 = "Parser";
@@ -2445,6 +1879,15 @@ var createParser = /* @__PURE__ */ factory(
2445
1879
  }
2446
1880
  );
2447
1881
 
1882
+ // src/utils/string.ts
1883
+ import {
1884
+ endsWith,
1885
+ formatGeneric,
1886
+ stringify,
1887
+ escape,
1888
+ compareText
1889
+ } from "@danielsimonjr/mathts-core/internal";
1890
+
2448
1891
  // src/Help.ts
2449
1892
  var name4 = "Help";
2450
1893
  var dependencies4 = ["evaluate"];
@@ -2496,7 +1939,7 @@ var createHelpClass = /* @__PURE__ */ factory(
2496
1939
  res = e;
2497
1940
  }
2498
1941
  if (res !== void 0 && !isHelp(res)) {
2499
- desc += " " + format3(res, { precision: 14 }) + "\n";
1942
+ desc += " " + formatGeneric(res, { precision: 14 }) + "\n";
2500
1943
  }
2501
1944
  }
2502
1945
  desc += "\n";
@@ -7267,6 +6710,75 @@ var embeddedDocs = {
7267
6710
  gammainc: gammaincDocs
7268
6711
  };
7269
6712
 
6713
+ // src/utils/customs.ts
6714
+ function getSafeProperty(object, prop) {
6715
+ if (isSafeProperty(object, prop)) {
6716
+ return object[prop];
6717
+ }
6718
+ if (typeof object[prop] === "function" && isSafeMethod(object, prop)) {
6719
+ throw new Error('Cannot access method "' + String(prop) + '" as a property');
6720
+ }
6721
+ throw new Error('No access to property "' + String(prop) + '"');
6722
+ }
6723
+ function setSafeProperty(object, prop, value) {
6724
+ if (isSafeProperty(object, prop)) {
6725
+ object[prop] = value;
6726
+ return value;
6727
+ }
6728
+ throw new Error('No access to property "' + String(prop) + '"');
6729
+ }
6730
+ function isSafeProperty(object, prop) {
6731
+ if (!isPlainObject(object) && !Array.isArray(object)) {
6732
+ return false;
6733
+ }
6734
+ if (hasOwnProperty(safeNativeProperties, prop)) {
6735
+ return true;
6736
+ }
6737
+ if (prop in Object.prototype) {
6738
+ return false;
6739
+ }
6740
+ if (prop in Function.prototype) {
6741
+ return false;
6742
+ }
6743
+ return true;
6744
+ }
6745
+ function getSafeMethod(object, method) {
6746
+ if (!isSafeMethod(object, method)) {
6747
+ throw new Error('No access to method "' + String(method) + '"');
6748
+ }
6749
+ return object[method];
6750
+ }
6751
+ function isSafeMethod(object, method) {
6752
+ if (object === null || object === void 0 || typeof object[method] !== "function") {
6753
+ return false;
6754
+ }
6755
+ if (hasOwnProperty(object, method) && Object.getPrototypeOf && method in Object.getPrototypeOf(object)) {
6756
+ return false;
6757
+ }
6758
+ if (hasOwnProperty(safeNativeMethods, method)) {
6759
+ return true;
6760
+ }
6761
+ if (method in Object.prototype) {
6762
+ return false;
6763
+ }
6764
+ if (method in Function.prototype) {
6765
+ return false;
6766
+ }
6767
+ return true;
6768
+ }
6769
+ function isPlainObject(object) {
6770
+ return typeof object === "object" && !!object && object.constructor === Object;
6771
+ }
6772
+ var safeNativeProperties = {
6773
+ length: true,
6774
+ name: true
6775
+ };
6776
+ var safeNativeMethods = {
6777
+ toString: true,
6778
+ valueOf: true,
6779
+ toLocaleString: true
6780
+ };
6781
+
7270
6782
  // src/compiler/compile.ts
7271
6783
  function compile(node, mathScope) {
7272
6784
  const evalFn = compileNode(node, mathScope, {});
@@ -8336,6 +7848,9 @@ ${nodes.concat(edges).join("\n")}
8336
7848
  { isClass: true, isNode: true }
8337
7849
  );
8338
7850
 
7851
+ // src/error/IndexError.ts
7852
+ import { IndexError, createIndexError } from "@danielsimonjr/mathts-core/internal";
7853
+
8339
7854
  // src/transform/utils/errorTransform.ts
8340
7855
  function errorTransform(err) {
8341
7856
  const e = err;
@@ -8570,6 +8085,41 @@ var createAccessorNode = /* @__PURE__ */ factory(
8570
8085
  { isClass: true, isNode: true }
8571
8086
  );
8572
8087
 
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
+
8573
8123
  // src/node/ArrayNode.ts
8574
8124
  var name7 = "ArrayNode";
8575
8125
  var dependencies7 = ["Node"];
@@ -9868,7 +9418,7 @@ var createConstantNode = /* @__PURE__ */ factory(
9868
9418
  * @return {string} str
9869
9419
  */
9870
9420
  _toString(options) {
9871
- return format3(this.value, options);
9421
+ return formatGeneric(this.value, options);
9872
9422
  }
9873
9423
  /**
9874
9424
  * Get HTML representation
@@ -10193,7 +9743,7 @@ var createFunctionNode = /* @__PURE__ */ factory(
10193
9743
  Node,
10194
9744
  SymbolNode
10195
9745
  }) => {
10196
- const strin = (entity) => format3(entity, { truncate: 78 });
9746
+ const strin = (entity) => formatGeneric(entity, { truncate: 78 });
10197
9747
  function expandTemplate(template, node, options) {
10198
9748
  let latex = "";
10199
9749
  const regex = /\$(?:\{([a-z_][a-z_0-9]*)(?:\[([0-9]+)\])?\}|\$)/gi;
@@ -12449,9 +11999,9 @@ var createColumnTransform = /* @__PURE__ */ factory(
12449
11999
  return typed("column", {
12450
12000
  "...any": function(args) {
12451
12001
  const lastIndex = args.length - 1;
12452
- const last = args[lastIndex];
12453
- if (isNumber(last)) {
12454
- args[lastIndex] = last - 1;
12002
+ const last2 = args[lastIndex];
12003
+ if (isNumber(last2)) {
12004
+ args[lastIndex] = last2 - 1;
12455
12005
  }
12456
12006
  try {
12457
12007
  return column(...args);
@@ -12470,18 +12020,18 @@ var dependencies25 = ["typed", "concat"];
12470
12020
  var createConcatTransform = /* @__PURE__ */ factory(
12471
12021
  name25,
12472
12022
  dependencies25,
12473
- ({ typed, concat }) => {
12023
+ ({ typed, concat: concat2 }) => {
12474
12024
  return typed("concat", {
12475
12025
  "...any": function(args) {
12476
12026
  const lastIndex = args.length - 1;
12477
- const last = args[lastIndex];
12478
- if (isNumber(last)) {
12479
- args[lastIndex] = last - 1;
12480
- } else if (isBigNumber(last)) {
12481
- args[lastIndex] = last.minus(1);
12027
+ const last2 = args[lastIndex];
12028
+ if (isNumber(last2)) {
12029
+ args[lastIndex] = last2 - 1;
12030
+ } else if (isBigNumber(last2)) {
12031
+ args[lastIndex] = last2.minus(1);
12482
12032
  }
12483
12033
  try {
12484
- return concat(...args);
12034
+ return concat2(...args);
12485
12035
  } catch (err) {
12486
12036
  throw errorTransform(err);
12487
12037
  }
@@ -12656,15 +12206,15 @@ var dependencies29 = ["typed", "filter"];
12656
12206
  var createFilterTransform = /* @__PURE__ */ factory(
12657
12207
  name29,
12658
12208
  dependencies29,
12659
- ({ typed, filter }) => {
12209
+ ({ typed, filter: filter2 }) => {
12660
12210
  function filterTransform(args, math, scope) {
12661
12211
  const transformCallback = createTransformCallback({ typed });
12662
12212
  if (args.length === 0) {
12663
- return filter();
12213
+ return filter2();
12664
12214
  }
12665
12215
  let x = args[0];
12666
12216
  if (args.length === 1) {
12667
- return filter(x);
12217
+ return filter2(x);
12668
12218
  }
12669
12219
  const N = args.length - 1;
12670
12220
  let callback = args[N];
@@ -12682,7 +12232,7 @@ var createFilterTransform = /* @__PURE__ */ factory(
12682
12232
  );
12683
12233
  }
12684
12234
  }
12685
- return filter(x, transformCallback(callback, N));
12235
+ return filter2(x, transformCallback(callback, N));
12686
12236
  }
12687
12237
  filterTransform.rawArgs = true;
12688
12238
  function _compileAndEvaluate(arg, scope) {
@@ -12742,7 +12292,7 @@ var dependencies31 = ["Index", "getMatrixDataType"];
12742
12292
  var createIndexTransform = /* @__PURE__ */ factory(
12743
12293
  name31,
12744
12294
  dependencies31,
12745
- ({ Index: Index2, getMatrixDataType }) => {
12295
+ ({ Index, getMatrixDataType }) => {
12746
12296
  return function indexTransform(...args) {
12747
12297
  const transformedArgs = [];
12748
12298
  for (let i = 0, ii = args.length; i < ii; i++) {
@@ -12772,7 +12322,7 @@ var createIndexTransform = /* @__PURE__ */ factory(
12772
12322
  }
12773
12323
  transformedArgs[i] = arg;
12774
12324
  }
12775
- return new Index2(...transformedArgs);
12325
+ return new Index(...transformedArgs);
12776
12326
  };
12777
12327
  },
12778
12328
  { isTransformFunction: true }
@@ -13019,8 +12569,8 @@ var createRangeTransform = /* @__PURE__ */ factory(
13019
12569
  return typed("range", {
13020
12570
  "...any": function(args) {
13021
12571
  const lastIndex = args.length - 1;
13022
- const last = args[lastIndex];
13023
- if (typeof last !== "boolean") {
12572
+ const last2 = args[lastIndex];
12573
+ if (typeof last2 !== "boolean") {
13024
12574
  args.push(true);
13025
12575
  }
13026
12576
  return range(...args);
@@ -13040,9 +12590,9 @@ var createRowTransform = /* @__PURE__ */ factory(
13040
12590
  return typed("row", {
13041
12591
  "...any": function(args) {
13042
12592
  const lastIndex = args.length - 1;
13043
- const last = args[lastIndex];
13044
- if (isNumber(last)) {
13045
- args[lastIndex] = last - 1;
12593
+ const last2 = args[lastIndex];
12594
+ if (isNumber(last2)) {
12595
+ args[lastIndex] = last2 - 1;
13046
12596
  }
13047
12597
  try {
13048
12598
  return row(...args);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielsimonjr/mathts-expression",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
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.9.0",
34
+ "@danielsimonjr/mathts-core": "^0.11.0",
35
35
  "typed-function": "^4.0.0"
36
36
  },
37
37
  "devDependencies": {