@danielsimonjr/mathts-expression 0.10.3 → 0.11.1

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.
Files changed (48) hide show
  1. package/README.md +18 -2
  2. package/dist/compiler/compile.d.ts.map +1 -1
  3. package/dist/evaluator/evaluate.d.ts.map +1 -1
  4. package/dist/index.d.ts +7 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +819 -256
  7. package/dist/limits.d.ts +18 -0
  8. package/dist/limits.d.ts.map +1 -0
  9. package/dist/node/ArrayNode.d.ts.map +1 -1
  10. package/dist/node/AssignmentNode.d.ts.map +1 -1
  11. package/dist/node/ConditionalNode.d.ts +124 -124
  12. package/dist/node/ConditionalNode.d.ts.map +1 -1
  13. package/dist/node/FunctionNode.d.ts.map +1 -1
  14. package/dist/node/IndexNode.d.ts.map +1 -1
  15. package/dist/node/Node.d.ts +15 -0
  16. package/dist/node/Node.d.ts.map +1 -1
  17. package/dist/node/ObjectNode.d.ts.map +1 -1
  18. package/dist/node/OperatorNode.d.ts +2 -2
  19. package/dist/node/OperatorNode.d.ts.map +1 -1
  20. package/dist/node/RangeNode.d.ts +70 -70
  21. package/dist/node/RangeNode.d.ts.map +1 -1
  22. package/dist/node/RelationalNode.d.ts +120 -120
  23. package/dist/node/RelationalNode.d.ts.map +1 -1
  24. package/dist/node/utils/stringSubset.d.ts +9 -2
  25. package/dist/node/utils/stringSubset.d.ts.map +1 -1
  26. package/dist/parse.d.ts.map +1 -1
  27. package/dist/scalar-builder.d.ts +4 -4
  28. package/dist/scalar-enumerate.d.ts +48 -0
  29. package/dist/scalar-enumerate.d.ts.map +1 -0
  30. package/dist/scalar-structure.d.ts +167 -0
  31. package/dist/scalar-structure.d.ts.map +1 -0
  32. package/dist/transform/and.transform.d.ts.map +1 -1
  33. package/dist/transform/bitAnd.transform.d.ts.map +1 -1
  34. package/dist/transform/bitOr.transform.d.ts.map +1 -1
  35. package/dist/transform/cumsum.transform.d.ts.map +1 -1
  36. package/dist/transform/filter.transform.d.ts +4 -4
  37. package/dist/transform/filter.transform.d.ts.map +1 -1
  38. package/dist/transform/forEach.transform.d.ts.map +1 -1
  39. package/dist/transform/mapSlices.transform.d.ts +1 -1
  40. package/dist/transform/mapSlices.transform.d.ts.map +1 -1
  41. package/dist/transform/or.transform.d.ts.map +1 -1
  42. package/dist/transform/utils/dimToZeroBase.d.ts +4 -1
  43. package/dist/transform/utils/dimToZeroBase.d.ts.map +1 -1
  44. package/dist/transform/utils/prepareTransformArgs.d.ts +23 -0
  45. package/dist/transform/utils/prepareTransformArgs.d.ts.map +1 -0
  46. package/dist/transform/utils/shortCircuitBinary.d.ts +21 -0
  47. package/dist/transform/utils/shortCircuitBinary.d.ts.map +1 -0
  48. package/package.json +3 -3
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Structural utilities over {@link ScalarNode}: traversal, metrics, and
3
+ * canonical form with a stable structural key.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import { type LoweredScalarFn, type ScalarNode, type ScalarOperator } from './scalar-builder.js';
8
+ /**
9
+ * Per-node weights for {@link scalarComplexity}.
10
+ *
11
+ * Omitted fields default to 1. A `symbol` record supplies per-name weights; a
12
+ * name that is absent from the record still weighs 1. Weights are summed
13
+ * across the stored tree and then rounded with `Math.round`.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { createScalarBuilder, scalarComplexity } from '@danielsimonjr/mathts-expression';
18
+ * const b = createScalarBuilder();
19
+ * const tree = b.op('+', [b.symbol('y'), b.op('*', [b.symbol('x'), b.symbol('x')])]);
20
+ * scalarComplexity(tree, { symbol: { x: 2 } }); // 7
21
+ * scalarComplexity(b.symbol('constructor')); // 1 (no own key → weight 1)
22
+ * ```
23
+ */
24
+ export interface ScalarComplexityWeights {
25
+ /** Weight of one operator node. Default 1 for every {@link ScalarOperator}. */
26
+ readonly op?: Partial<Record<ScalarOperator, number>>;
27
+ /** Weight of one call node, keyed by the lowered name (`ln` is `log`). Default 1. */
28
+ readonly call?: Partial<Record<LoweredScalarFn, number>>;
29
+ /** Weight of one number node. Default 1. */
30
+ readonly number?: number;
31
+ /** Weight of one symbol node: one number for every name, or a per-name record. Default 1. */
32
+ readonly symbol?: number | Readonly<Record<string, number>>;
33
+ }
34
+ /**
35
+ * Preorder walk. The root is visited first, at `depth` 0, then each child
36
+ * left to right. `depth` here is not {@link scalarDepth}: a leaf visited by
37
+ * this function has depth 0 when it is the root, while `scalarDepth` of any
38
+ * leaf is 1.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { createScalarBuilder, forEachScalar } from '@danielsimonjr/mathts-expression';
43
+ * const b = createScalarBuilder();
44
+ * const tree = b.op('+', [b.symbol('y'), b.op('*', [b.symbol('x'), b.symbol('x')])]);
45
+ * const depths: number[] = [];
46
+ * forEachScalar(tree, (_n, depth) => depths.push(depth));
47
+ * depths.join(','); // '0,1,1,2,2'
48
+ * ```
49
+ */
50
+ export declare function forEachScalar(node: ScalarNode, visit: (n: ScalarNode, depth: number) => void): void;
51
+ /**
52
+ * Post-order immutable map. Children are mapped first. `fn` then receives
53
+ * the node with those children and its return value replaces the node.
54
+ * The replacement is not walked again.
55
+ *
56
+ * When a child result is the same reference and `fn` returns the rebuilt
57
+ * node, the original node reference is kept. The input tree is never mutated,
58
+ * including a deep-frozen input.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import { createScalarBuilder, mapScalar, scalarSize } from '@danielsimonjr/mathts-expression';
63
+ * const b = createScalarBuilder();
64
+ * const tree = b.op('+', [b.symbol('y'), b.op('*', [b.symbol('x'), b.symbol('x')])]);
65
+ * const mapped = mapScalar(tree, (n) =>
66
+ * n.kind === 'symbol' && n.name === 'x' ? { kind: 'number', value: 9 } : n
67
+ * );
68
+ * scalarSize(mapped); // 5 — replacement is not walked again
69
+ * ```
70
+ */
71
+ export declare function mapScalar(node: ScalarNode, fn: (n: ScalarNode) => ScalarNode): ScalarNode;
72
+ /**
73
+ * Number of nodes in the stored tree. An empty `+` is one node.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * import { createScalarBuilder, scalarSize } from '@danielsimonjr/mathts-expression';
78
+ * const b = createScalarBuilder();
79
+ * const tree = b.op('+', [b.symbol('y'), b.op('*', [b.symbol('x'), b.symbol('x')])]);
80
+ * scalarSize(tree); // 5
81
+ * ```
82
+ */
83
+ export declare function scalarSize(node: ScalarNode): number;
84
+ /**
85
+ * Stored-tree depth. A number or symbol is 1. A call is `1 + scalarDepth(arg)`.
86
+ * An operator is `1 + max(child depths)`, or 1 when it has no children.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * import { createScalarBuilder, scalarDepth } from '@danielsimonjr/mathts-expression';
91
+ * const b = createScalarBuilder();
92
+ * const tree = b.op('+', [b.symbol('y'), b.op('*', [b.symbol('x'), b.symbol('x')])]);
93
+ * scalarDepth(tree); // 3
94
+ * ```
95
+ */
96
+ export declare function scalarDepth(node: ScalarNode): number;
97
+ /**
98
+ * Weighted node count of the stored tree. See {@link ScalarComplexityWeights}.
99
+ * The return value is `Math.round` of the sum, so default weights make this
100
+ * equal `scalarSize`. Walks `-` and `/` as stored; it does not rewrite them first.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * import { createScalarBuilder, scalarComplexity } from '@danielsimonjr/mathts-expression';
105
+ * const b = createScalarBuilder();
106
+ * const tree = b.op('+', [b.symbol('y'), b.op('*', [b.symbol('x'), b.symbol('x')])]);
107
+ * scalarComplexity(tree); // 5
108
+ * scalarComplexity(tree, { symbol: { x: 2 } }); // 7
109
+ * ```
110
+ */
111
+ export declare function scalarComplexity(node: ScalarNode, weights?: ScalarComplexityWeights): number;
112
+ /**
113
+ * Sorted unique `symbol` names in the stored tree. Function names and number
114
+ * literals are not included. Sort is UTF-16 code-unit order (`<` on strings).
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import { createScalarBuilder, scalarSymbols } from '@danielsimonjr/mathts-expression';
119
+ * const b = createScalarBuilder();
120
+ * const tree = b.op('+', [b.symbol('y'), b.op('*', [b.symbol('x'), b.symbol('x')])]);
121
+ * scalarSymbols(tree).join(','); // 'x,y'
122
+ * ```
123
+ */
124
+ export declare function scalarSymbols(node: ScalarNode): readonly string[];
125
+ /**
126
+ * Canonical tree. Idempotent: `scalarCanonical(scalarCanonical(n))` is deeply
127
+ * equal to `scalarCanonical(n)`. Does not mutate `n`. The result uses only
128
+ * `number`, `symbol`, `call`, `+`, `*`, and `^`. See the algorithm below.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * import { createScalarBuilder, scalarCanonical, scalarEquals } from '@danielsimonjr/mathts-expression';
133
+ * const b = createScalarBuilder();
134
+ * const aa = b.op('*', [b.symbol('a'), b.symbol('a')]);
135
+ * const aSquared = b.op('^', [b.symbol('a'), b.number(2)]);
136
+ * scalarEquals(aa, aSquared); // true — canonical uses only +, *, ^
137
+ * scalarCanonical(b.op('^', [b.number(2), b.number(3)])); // does not fold 2^3 to 8
138
+ * ```
139
+ */
140
+ export declare function scalarCanonical(node: ScalarNode): ScalarNode;
141
+ /**
142
+ * `JSON.stringify` of {@link scalarCanonical}, with the key order fixed in
143
+ * "Key encoding". Equal keys are the definition of structural equality.
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * import { createScalarBuilder, scalarCanonicalKey } from '@danielsimonjr/mathts-expression';
148
+ * const b = createScalarBuilder();
149
+ * scalarCanonicalKey(b.op('^', [b.number(2), b.number(3)]));
150
+ * // {"k":"^","b":{"k":"n","v":"2"},"e":{"k":"n","v":"3"}}
151
+ * ```
152
+ */
153
+ export declare function scalarCanonicalKey(node: ScalarNode): string;
154
+ /**
155
+ * `scalarCanonicalKey(a) === scalarCanonicalKey(b)`.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * import { createScalarBuilder, scalarEquals } from '@danielsimonjr/mathts-expression';
160
+ * const b = createScalarBuilder();
161
+ * const aa = b.op('*', [b.symbol('a'), b.symbol('a')]);
162
+ * const aSquared = b.op('^', [b.symbol('a'), b.number(2)]);
163
+ * scalarEquals(aa, aSquared); // true
164
+ * ```
165
+ */
166
+ export declare function scalarEquals(a: ScalarNode, b: ScalarNode): boolean;
167
+ //# sourceMappingURL=scalar-structure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalar-structure.d.ts","sourceRoot":"","sources":["../src/scalar-structure.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,cAAc,EACpB,MAAM,qBAAqB,CAAC;AAQ7B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,uBAAuB;IACtC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC;IACtD,qFAAqF;IACrF,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC;IACzD,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,6FAA6F;IAC7F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC7D;AAiCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAC5C,IAAI,CAYN;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,UAAU,GAAG,UAAU,CAiBzF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAMnD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAkBpD;AA8BD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,uBAA4B,GAAG,MAAM,CAMhG;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,MAAM,EAAE,CAQjE;AAiRD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAE5D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAE3D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAElE"}
@@ -1 +1 @@
1
- {"version":3,"file":"and.transform.d.ts","sourceRoot":"","sources":["../../src/transform/and.transform.ts"],"names":[],"mappings":"AAGA,UAAU,IAAI;IACZ,OAAO,IAAI,kBAAkB,CAAC;CAC/B;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,YAAY;IACpB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;CACtC;AAKD,eAAO,MAAM,kBAAkB,gFAkB9B,CAAC"}
1
+ {"version":3,"file":"and.transform.d.ts","sourceRoot":"","sources":["../../src/transform/and.transform.ts"],"names":[],"mappings":"AAGA,UAAU,IAAI;IACZ,OAAO,IAAI,kBAAkB,CAAC;CAC/B;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,YAAY;IACpB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;CACtC;AAKD,eAAO,MAAM,kBAAkB,gFAe9B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"bitAnd.transform.d.ts","sourceRoot":"","sources":["../../src/transform/bitAnd.transform.ts"],"names":[],"mappings":"AAGA,UAAU,IAAI;IACZ,OAAO,IAAI,kBAAkB,CAAC;CAC/B;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;CACzC;AAKD,eAAO,MAAM,qBAAqB,gFAuBjC,CAAC"}
1
+ {"version":3,"file":"bitAnd.transform.d.ts","sourceRoot":"","sources":["../../src/transform/bitAnd.transform.ts"],"names":[],"mappings":"AAGA,UAAU,IAAI;IACZ,OAAO,IAAI,kBAAkB,CAAC;CAC/B;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;CACzC;AAKD,eAAO,MAAM,qBAAqB,gFAqBjC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"bitOr.transform.d.ts","sourceRoot":"","sources":["../../src/transform/bitOr.transform.ts"],"names":[],"mappings":"AAGA,UAAU,IAAI;IACZ,OAAO,IAAI,kBAAkB,CAAC;CAC/B;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,YAAY;IACpB,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;CACxC;AAKD,eAAO,MAAM,oBAAoB,gFA0BhC,CAAC"}
1
+ {"version":3,"file":"bitOr.transform.d.ts","sourceRoot":"","sources":["../../src/transform/bitOr.transform.ts"],"names":[],"mappings":"AAGA,UAAU,IAAI;IACZ,OAAO,IAAI,kBAAkB,CAAC;CAC/B;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,YAAY;IACpB,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;CACxC;AAKD,eAAO,MAAM,oBAAoB,gFAwBhC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"cumsum.transform.d.ts","sourceRoot":"","sources":["../../src/transform/cumsum.transform.ts"],"names":[],"mappings":"AAIA,UAAU,aAAa,CAAC,CAAC,GAAG,OAAO;IACjC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;CACzB;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IACxC,KAAK,EAAE,aAAa,CAAC;CACtB;AAYD,eAAO,MAAM,qBAAqB,sEAyBjC,CAAC"}
1
+ {"version":3,"file":"cumsum.transform.d.ts","sourceRoot":"","sources":["../../src/transform/cumsum.transform.ts"],"names":[],"mappings":"AAIA,UAAU,aAAa,CAAC,CAAC,GAAG,OAAO;IACjC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;CACzB;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IACxC,KAAK,EAAE,aAAa,CAAC;CACtB;AAYD,eAAO,MAAM,qBAAqB,sEAiBjC,CAAC"}
@@ -1,16 +1,16 @@
1
1
  interface TypedFunction<T = unknown> {
2
2
  (...args: unknown[]): T;
3
3
  }
4
+ interface TransformFunction {
5
+ (args: Node[], math: unknown, scope: unknown): unknown;
6
+ rawArgs?: boolean;
7
+ }
4
8
  interface Node {
5
9
  compile(): CompiledExpression;
6
10
  }
7
11
  interface CompiledExpression {
8
12
  evaluate(scope: unknown): unknown;
9
13
  }
10
- interface TransformFunction {
11
- (args: Node[], math: unknown, scope: unknown): unknown;
12
- rawArgs?: boolean;
13
- }
14
14
  interface Dependencies {
15
15
  filter: (...args: unknown[]) => unknown;
16
16
  typed: TypedFunction;
@@ -1 +1 @@
1
- {"version":3,"file":"filter.transform.d.ts","sourceRoot":"","sources":["../../src/transform/filter.transform.ts"],"names":[],"mappings":"AAKA,UAAU,aAAa,CAAC,CAAC,GAAG,OAAO;IACjC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;CACzB;AAED,UAAU,IAAI;IACZ,OAAO,IAAI,kBAAkB,CAAC;CAC/B;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IACxC,KAAK,EAAE,aAAa,CAAC;CACtB;AAKD,eAAO,MAAM,qBAAqB,gFAuDjC,CAAC"}
1
+ {"version":3,"file":"filter.transform.d.ts","sourceRoot":"","sources":["../../src/transform/filter.transform.ts"],"names":[],"mappings":"AAIA,UAAU,aAAa,CAAC,CAAC,GAAG,OAAO;IACjC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;CACzB;AAED,UAAU,iBAAiB;IACzB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,IAAI;IACZ,OAAO,IAAI,kBAAkB,CAAC;CAC/B;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACnC;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IACxC,KAAK,EAAE,aAAa,CAAC;CACtB;AAKD,eAAO,MAAM,qBAAqB,gFA2BjC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"forEach.transform.d.ts","sourceRoot":"","sources":["../../src/transform/forEach.transform.ts"],"names":[],"mappings":"AAKA,UAAU,aAAa,CAAC,CAAC,GAAG,OAAO;IACjC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;CACzB;AAED,UAAU,IAAI;IACZ,OAAO,IAAI,kBAAkB,CAAC;CAC/B;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,YAAY;IACpB,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IACzC,KAAK,EAAE,aAAa,CAAC;CACtB;AAKD,eAAO,MAAM,sBAAsB,gFAoDlC,CAAC"}
1
+ {"version":3,"file":"forEach.transform.d.ts","sourceRoot":"","sources":["../../src/transform/forEach.transform.ts"],"names":[],"mappings":"AAIA,UAAU,aAAa,CAAC,CAAC,GAAG,OAAO;IACjC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;CACzB;AAED,UAAU,IAAI;IACZ,OAAO,IAAI,kBAAkB,CAAC;CAC/B;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,YAAY;IACpB,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IACzC,KAAK,EAAE,aAAa,CAAC;CACtB;AAKD,eAAO,MAAM,sBAAsB,gFAyBlC,CAAC"}
@@ -9,7 +9,7 @@ interface Dependencies {
9
9
  * Attach a transform function to math.mapSlices
10
10
  * Adds a property transform containing the transform function.
11
11
  *
12
- * This transform changed the last `dim` parameter of function mapSlices
12
+ * This transform changes the second `dim` argument of function mapSlices
13
13
  * from one-based to zero based
14
14
  */
15
15
  export declare const createMapSlicesTransform: import("../utils/factory.js").FactoryFunction<Dependencies, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"mapSlices.transform.d.ts","sourceRoot":"","sources":["../../src/transform/mapSlices.transform.ts"],"names":[],"mappings":"AAIA,UAAU,aAAa,CAAC,CAAC,GAAG,OAAO;IACjC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;CACzB;AAED,UAAU,YAAY;IACpB,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IAC3C,KAAK,EAAE,aAAa,CAAC;CACtB;AAKD;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,sEAyBpC,CAAC"}
1
+ {"version":3,"file":"mapSlices.transform.d.ts","sourceRoot":"","sources":["../../src/transform/mapSlices.transform.ts"],"names":[],"mappings":"AAIA,UAAU,aAAa,CAAC,CAAC,GAAG,OAAO;IACjC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;CACzB;AAED,UAAU,YAAY;IACpB,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IAC3C,KAAK,EAAE,aAAa,CAAC;CACtB;AAKD;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,sEAqBpC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"or.transform.d.ts","sourceRoot":"","sources":["../../src/transform/or.transform.ts"],"names":[],"mappings":"AAGA,UAAU,IAAI;IACZ,OAAO,IAAI,kBAAkB,CAAC;CAC/B;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,YAAY;IACpB,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;CACrC;AAKD,eAAO,MAAM,iBAAiB,gFAkB7B,CAAC"}
1
+ {"version":3,"file":"or.transform.d.ts","sourceRoot":"","sources":["../../src/transform/or.transform.ts"],"names":[],"mappings":"AAGA,UAAU,IAAI;IACZ,OAAO,IAAI,kBAAkB,CAAC;CAC/B;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,YAAY;IACpB,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;CACrC;AAKD,eAAO,MAAM,iBAAiB,gFAe7B,CAAC"}
@@ -1,5 +1,8 @@
1
1
  /**
2
- * Change last argument dim from one-based to zero-based.
2
+ * Convert a one-based dimension to zero-based.
3
+ * Numbers are shifted with `- 1`. BigNumbers use `.sub(1)` (MathTS core)
4
+ * and fall back to decimal.js `.minus(1)` when that is the only subtract API.
5
+ * Any other value is returned unchanged.
3
6
  */
4
7
  export declare function dimToZeroBase(dim: unknown): unknown;
5
8
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"dimToZeroBase.d.ts","sourceRoot":"","sources":["../../../src/transform/utils/dimToZeroBase.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAQnD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAEvD"}
1
+ {"version":3,"file":"dimToZeroBase.d.ts","sourceRoot":"","sources":["../../../src/transform/utils/dimToZeroBase.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAgBnD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAEvD"}
@@ -0,0 +1,23 @@
1
+ interface TransformArgNode {
2
+ compile(): {
3
+ evaluate(scope: unknown): unknown;
4
+ };
5
+ }
6
+ export interface PreparedTransformArgs {
7
+ x: unknown;
8
+ callback: unknown;
9
+ callbackArity: number;
10
+ }
11
+ /**
12
+ * Shared tail of filter/forEach transforms: evaluate the collection argument and
13
+ * compile the callback (symbol, function assignment, or inline expression).
14
+ */
15
+ export declare function prepareTransformArrayAndCallback(args: TransformArgNode[], math: Record<string, unknown>, scope: Map<string, unknown>): PreparedTransformArgs;
16
+ /**
17
+ * Shared filter/forEach transform body: arity 0 calls `op()`; arity 1 passes
18
+ * the raw node (not a compiled value) to `op`; otherwise compile the collection
19
+ * and callback via {@link prepareTransformArrayAndCallback}.
20
+ */
21
+ export declare function applyArrayCallbackTransform(args: TransformArgNode[], math: Record<string, unknown>, scope: Map<string, unknown>, op: (...args: unknown[]) => unknown, transformCallback: (callback: unknown, arity: number) => unknown): unknown;
22
+ export {};
23
+ //# sourceMappingURL=prepareTransformArgs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepareTransformArgs.d.ts","sourceRoot":"","sources":["../../../src/transform/utils/prepareTransformArgs.ts"],"names":[],"mappings":"AAGA,UAAU,gBAAgB;IACxB,OAAO,IAAI;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAA;KAAE,CAAC;CAClD;AAMD,MAAM,WAAW,qBAAqB;IACpC,CAAC,EAAE,OAAO,CAAC;IACX,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAgB,gCAAgC,CAC9C,IAAI,EAAE,gBAAgB,EAAE,EACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GAC1B,qBAAqB,CAsBvB;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,gBAAgB,EAAE,EACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3B,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EACnC,iBAAiB,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,GAC/D,OAAO,CAcT"}
@@ -0,0 +1,21 @@
1
+ interface EvalNode {
2
+ compile(): {
3
+ evaluate(scope: unknown): unknown;
4
+ };
5
+ }
6
+ /** Short-circuit decision for the left operand of a binary transform. */
7
+ export type Absorb = {
8
+ readonly take: false;
9
+ } | {
10
+ readonly take: true;
11
+ readonly value: unknown;
12
+ };
13
+ /**
14
+ * Evaluate a lazy binary operator transform: compile/evaluate the left arg
15
+ * with `scope`, optionally return early via `absorb` when the left value is
16
+ * not a collection (so the right arg is never compiled/evaluated), otherwise
17
+ * evaluate the right arg with the same `scope` and call `op`.
18
+ */
19
+ export declare function evalShortCircuitBinary(args: EvalNode[], scope: unknown, op: (left: unknown, right: unknown) => unknown, absorb: (left: unknown) => Absorb): unknown;
20
+ export {};
21
+ //# sourceMappingURL=shortCircuitBinary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shortCircuitBinary.d.ts","sourceRoot":"","sources":["../../../src/transform/utils/shortCircuitBinary.ts"],"names":[],"mappings":"AAEA,UAAU,QAAQ;IAChB,OAAO,IAAI;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAA;KAAE,CAAC;CAClD;AAED,yEAAyE;AACzE,MAAM,MAAM,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAEjG;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,QAAQ,EAAE,EAChB,KAAK,EAAE,OAAO,EACd,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,KAAK,OAAO,EAC9C,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,MAAM,GAChC,OAAO,CAUT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielsimonjr/mathts-expression",
3
- "version": "0.10.3",
3
+ "version": "0.11.1",
4
4
  "description": "Expression parser and evaluator for MathTS",
5
5
  "author": "Daniel Simon Jr.",
6
6
  "license": "MIT",
@@ -42,11 +42,11 @@
42
42
  }
43
43
  },
44
44
  "dependencies": {
45
- "@danielsimonjr/mathts-core": "^0.19.0",
46
- "typed-function": "^4.0.0"
45
+ "@danielsimonjr/mathts-core": "^0.21.0"
47
46
  },
48
47
  "devDependencies": {
49
48
  "@types/node": "^26.4.0",
49
+ "fast-check": "^4.9.0",
50
50
  "tsdown": "^0.23.0",
51
51
  "typescript": "^7.0.2",
52
52
  "vitest": "^5.0.0"