@cortex-js/compute-engine 0.25.0 → 0.26.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/compute-engine.esm.js +27153 -25341
- package/dist/compute-engine.js +27124 -25300
- package/dist/compute-engine.min.esm.js +88 -23
- package/dist/compute-engine.min.js +88 -23
- package/dist/math-json.esm.js +42 -196
- package/dist/math-json.js +42 -196
- package/dist/math-json.min.esm.js +42 -196
- package/dist/math-json.min.js +2 -2
- package/dist/types/common/ansi-codes.d.ts +30 -4
- package/dist/types/common/buffer.d.ts +9 -0
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/one-of.d.ts +9 -0
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/common/styled-text.d.ts +28 -0
- package/dist/types/common/suggest.d.ts +1 -0
- package/dist/types/common/syntax-highlighter.d.ts +40 -0
- package/dist/types/common/terminal.d.ts +19 -0
- package/dist/types/common/type/parse.d.ts +4 -0
- package/dist/types/common/type/primitive.d.ts +8 -0
- package/dist/types/common/type/serialize.d.ts +2 -0
- package/dist/types/common/type/subtype.d.ts +6 -0
- package/dist/types/common/type/types.d.ts +249 -0
- package/dist/types/common/type/utils.d.ts +39 -0
- package/dist/types/common/utils.d.ts +2 -1
- package/dist/types/compute-engine/assume.d.ts +13 -13
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +71 -47
- package/dist/types/compute-engine/boxed-expression/apply.d.ts +5 -0
- package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +15 -0
- package/dist/types/compute-engine/boxed-expression/arithmetic-divide.d.ts +12 -0
- package/dist/types/compute-engine/boxed-expression/arithmetic-multiply.d.ts +16 -0
- package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +20 -0
- package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +11 -0
- package/dist/types/compute-engine/boxed-expression/box.d.ts +13 -71
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +31 -13
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +66 -45
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +41 -37
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +13 -9
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +34 -66
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +63 -41
- package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +44 -27
- package/dist/types/compute-engine/boxed-expression/cache.d.ts +6 -0
- package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/compare.d.ts +13 -0
- package/dist/types/compute-engine/boxed-expression/expand.d.ts +20 -0
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/factor.d.ts +7 -6
- package/dist/types/compute-engine/boxed-expression/flatten.d.ts +25 -0
- package/dist/types/compute-engine/boxed-expression/hold.d.ts +9 -0
- package/dist/types/compute-engine/boxed-expression/match.d.ts +2 -4
- package/dist/types/compute-engine/boxed-expression/negate.d.ts +10 -0
- package/dist/types/compute-engine/boxed-expression/numerics.d.ts +5 -39
- package/dist/types/compute-engine/boxed-expression/order.d.ts +26 -14
- package/dist/types/compute-engine/{symbolic → boxed-expression}/polynomials.d.ts +11 -15
- package/dist/types/compute-engine/{symbolic → boxed-expression}/product.d.ts +18 -24
- package/dist/types/compute-engine/boxed-expression/public.d.ts +947 -656
- package/dist/types/compute-engine/boxed-expression/rules.d.ts +129 -0
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/sgn.d.ts +6 -0
- package/dist/types/compute-engine/boxed-expression/simplify.d.ts +6 -0
- package/dist/types/compute-engine/{solve.d.ts → boxed-expression/solve.d.ts} +5 -5
- package/dist/types/compute-engine/{symbolic → boxed-expression}/tensor-fields.d.ts +3 -3
- package/dist/types/compute-engine/boxed-expression/terms.d.ts +10 -0
- package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +10 -0
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +22 -16
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +10 -7
- package/dist/types/compute-engine/collection-utils.d.ts +24 -2
- package/dist/types/compute-engine/compile.d.ts +3 -3
- package/dist/types/compute-engine/compute-engine.d.ts +133 -165
- package/dist/types/compute-engine/cost-function.d.ts +11 -1
- package/dist/types/compute-engine/function-utils.d.ts +5 -5
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +25 -30
- package/dist/types/compute-engine/latex-syntax/public.d.ts +22 -18
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +2 -2
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +5 -8
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +4 -2
- package/dist/types/compute-engine/library/calculus.d.ts +1 -1
- package/dist/types/compute-engine/library/collections.d.ts +24 -1
- package/dist/types/compute-engine/library/complex.d.ts +1 -1
- package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +1 -3
- package/dist/types/compute-engine/library/invisible-operator.d.ts +4 -0
- package/dist/types/compute-engine/library/library.d.ts +2 -4
- package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/library/logic.d.ts +5 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/sets.d.ts +1 -1
- package/dist/types/compute-engine/library/statistics.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +46 -40
- package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +59 -0
- package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +77 -0
- package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +58 -0
- package/dist/types/compute-engine/numeric-value/public.d.ts +110 -0
- package/dist/types/compute-engine/numerics/bigint.d.ts +2 -0
- package/dist/types/compute-engine/numerics/bignum.d.ts +12 -0
- package/dist/types/compute-engine/numerics/expression.d.ts +4 -0
- package/dist/types/compute-engine/numerics/interval.d.ts +12 -0
- package/dist/types/compute-engine/numerics/monte-carlo.d.ts +19 -0
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +4 -14
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +6 -9
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +9 -59
- package/dist/types/compute-engine/numerics/primes.d.ts +3 -3
- package/dist/types/compute-engine/numerics/rationals.d.ts +29 -13
- package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
- package/dist/types/compute-engine/numerics/special-functions.d.ts +28 -0
- package/dist/types/compute-engine/numerics/strings.d.ts +2 -0
- package/dist/types/compute-engine/public.d.ts +8 -4
- package/dist/types/compute-engine/symbolic/derivative.d.ts +2 -2
- package/dist/types/compute-engine/symbolic/distribute.d.ts +5 -0
- package/dist/types/compute-engine/{simplify-rules.d.ts → symbolic/simplify-rules.d.ts} +1 -1
- package/dist/types/compute-engine/{symbolic → tensor}/tensors.d.ts +3 -3
- package/dist/types/compute-engine.d.ts +4 -2
- package/dist/types/math-json/identifiers.d.ts +11 -0
- package/dist/types/math-json/{math-json-format.d.ts → types.d.ts} +4 -9
- package/dist/types/math-json/utils.d.ts +15 -23
- package/dist/types/math-json.d.ts +3 -3
- package/package.json +11 -11
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +0 -48
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +0 -40
- package/dist/types/compute-engine/domain-utils.d.ts +0 -19
- package/dist/types/compute-engine/library/arithmetic-add.d.ts +0 -21
- package/dist/types/compute-engine/library/arithmetic-divide.d.ts +0 -17
- package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +0 -16
- package/dist/types/compute-engine/library/arithmetic-power.d.ts +0 -11
- package/dist/types/compute-engine/library/domains.d.ts +0 -16
- package/dist/types/compute-engine/numerics/terms.d.ts +0 -17
- package/dist/types/compute-engine/rules.d.ts +0 -20
- package/dist/types/compute-engine/symbolic/expand.d.ts +0 -23
- package/dist/types/compute-engine/symbolic/flatten.d.ts +0 -9
- package/dist/types/compute-engine/symbolic/negate.d.ts +0 -11
- package/dist/types/compute-engine/symbolic/utils.d.ts +0 -22
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Compute Engine 0.
|
|
1
|
+
/** Compute Engine 0.26.0 */
|
|
2
2
|
|
|
3
3
|
// src/math-json/utils.ts
|
|
4
4
|
function isSymbolObject(expr) {
|
|
@@ -10,229 +10,79 @@ function isStringObject(expr) {
|
|
|
10
10
|
function isFunctionObject(expr) {
|
|
11
11
|
return expr !== null && typeof expr === "object" && "fn" in expr;
|
|
12
12
|
}
|
|
13
|
-
function isDictionaryObject(expr) {
|
|
14
|
-
return expr !== null && typeof expr === "object" && "dict" in expr;
|
|
15
|
-
}
|
|
16
|
-
var recommendedScriptsRegex;
|
|
17
|
-
function isRecommendedScripts(text) {
|
|
18
|
-
if (!recommendedScriptsRegex) {
|
|
19
|
-
const recommendedScripts = [
|
|
20
|
-
"Zyyy",
|
|
21
|
-
"Zinh",
|
|
22
|
-
"Arab",
|
|
23
|
-
"Armn",
|
|
24
|
-
"Beng",
|
|
25
|
-
"Bopo",
|
|
26
|
-
"Cyrl",
|
|
27
|
-
"Deva",
|
|
28
|
-
"Ethi",
|
|
29
|
-
"Geor",
|
|
30
|
-
"Grek",
|
|
31
|
-
"Gujr",
|
|
32
|
-
"Guru",
|
|
33
|
-
"Hang",
|
|
34
|
-
"Hani",
|
|
35
|
-
"Hebr",
|
|
36
|
-
"Hira",
|
|
37
|
-
"Kana",
|
|
38
|
-
"Knda",
|
|
39
|
-
"Khmr",
|
|
40
|
-
"Laoo",
|
|
41
|
-
"Latn",
|
|
42
|
-
"Mlym",
|
|
43
|
-
"Mymr",
|
|
44
|
-
"Orya",
|
|
45
|
-
"Sinh",
|
|
46
|
-
"Taml",
|
|
47
|
-
"Telu",
|
|
48
|
-
"Thaa",
|
|
49
|
-
"Thai",
|
|
50
|
-
"Tibt"
|
|
51
|
-
];
|
|
52
|
-
const regexPattern = `^[${recommendedScripts.map((x) => `\\p{Script=${x}}`).join("")}]*$`;
|
|
53
|
-
recommendedScriptsRegex = new RegExp(regexPattern, "u");
|
|
54
|
-
}
|
|
55
|
-
return recommendedScriptsRegex.test(text);
|
|
56
|
-
}
|
|
57
|
-
function isValidIdentifier(s) {
|
|
58
|
-
if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s))
|
|
59
|
-
return true;
|
|
60
|
-
if (ONLY_EMOJIS.test(s))
|
|
61
|
-
return true;
|
|
62
|
-
if (!isRecommendedScripts(s))
|
|
63
|
-
return false;
|
|
64
|
-
return /^[\p{XIDS}_]\p{XIDC}*$/u.test(s);
|
|
65
|
-
}
|
|
66
|
-
var VS16 = "\\u{FE0F}";
|
|
67
|
-
var KEYCAP = "\\u{20E3}";
|
|
68
|
-
var ZWJ = "\\u{200D}";
|
|
69
|
-
var FLAG_SEQUENCE = "\\p{RI}\\p{RI}";
|
|
70
|
-
var TAG_MOD = `(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})`;
|
|
71
|
-
var EMOJI_MOD = `(?:\\p{EMod}|${VS16}${KEYCAP}?|${TAG_MOD})`;
|
|
72
|
-
var EMOJI_NOT_IDENTIFIER = `(?:(?=\\P{XIDC})\\p{Emoji})`;
|
|
73
|
-
var ZWJ_ELEMENT = `(?:${EMOJI_NOT_IDENTIFIER}${EMOJI_MOD}*|\\p{Emoji}${EMOJI_MOD}+|${FLAG_SEQUENCE})`;
|
|
74
|
-
var POSSIBLE_EMOJI = `(?:${ZWJ_ELEMENT})(${ZWJ}${ZWJ_ELEMENT})*`;
|
|
75
|
-
var SOME_EMOJI = new RegExp(`(?:${POSSIBLE_EMOJI})+`, "u");
|
|
76
|
-
var ONLY_EMOJIS = new RegExp(`^(?:${POSSIBLE_EMOJI})+$`, "u");
|
|
77
|
-
function validateIdentifier(s) {
|
|
78
|
-
if (typeof s !== "string")
|
|
79
|
-
return "not-a-string";
|
|
80
|
-
if (s === "")
|
|
81
|
-
return "empty-string";
|
|
82
|
-
if (s.normalize() !== s)
|
|
83
|
-
return "expected-nfc";
|
|
84
|
-
if (/[\u200E\u200F\u2066-\u2069\u202A-\u202E]/.test(s))
|
|
85
|
-
return "unexpected-bidi-marker";
|
|
86
|
-
if (ONLY_EMOJIS.test(s))
|
|
87
|
-
return "valid";
|
|
88
|
-
if (/\p{XIDC}/u.test(s) && SOME_EMOJI.test(s))
|
|
89
|
-
return "unexpected-mixed-emoji";
|
|
90
|
-
if (!isRecommendedScripts(s))
|
|
91
|
-
return "unexpected-script";
|
|
92
|
-
if (!isValidIdentifier(s)) {
|
|
93
|
-
if (!isValidIdentifier(s[0]))
|
|
94
|
-
return "invalid-first-char";
|
|
95
|
-
return "invalid-char";
|
|
96
|
-
}
|
|
97
|
-
return "valid";
|
|
98
|
-
}
|
|
99
13
|
function stringValue(expr) {
|
|
100
|
-
if (expr === null || expr === void 0)
|
|
101
|
-
|
|
102
|
-
if (typeof expr
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
return null;
|
|
106
|
-
if (expr.length < 2)
|
|
107
|
-
return null;
|
|
108
|
-
if (expr[0] !== "'" || expr[expr.length - 1] !== "'")
|
|
109
|
-
return null;
|
|
14
|
+
if (expr === null || expr === void 0) return null;
|
|
15
|
+
if (typeof expr === "object" && "str" in expr) return expr.str;
|
|
16
|
+
if (typeof expr !== "string") return null;
|
|
17
|
+
if (expr.length < 2) return null;
|
|
18
|
+
if (expr.at(0) !== "'" || expr.at(-1) !== "'") return null;
|
|
110
19
|
return expr.substring(1, expr.length - 1);
|
|
111
20
|
}
|
|
112
|
-
function
|
|
113
|
-
if (Array.isArray(expr))
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
);
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
return expr[0];
|
|
121
|
-
}
|
|
122
|
-
if (expr === null || expr === void 0)
|
|
123
|
-
return null;
|
|
124
|
-
if (isFunctionObject(expr))
|
|
125
|
-
return expr.fn[0];
|
|
126
|
-
return null;
|
|
21
|
+
function operator(expr) {
|
|
22
|
+
if (Array.isArray(expr)) return expr[0];
|
|
23
|
+
if (expr === null || expr === void 0) return "";
|
|
24
|
+
if (isFunctionObject(expr)) return expr.fn[0];
|
|
25
|
+
return "";
|
|
127
26
|
}
|
|
128
|
-
function
|
|
129
|
-
|
|
130
|
-
|
|
27
|
+
function operands(expr) {
|
|
28
|
+
if (Array.isArray(expr)) return expr.slice(1);
|
|
29
|
+
if (expr !== void 0 && isFunctionObject(expr)) return expr.fn.slice(1);
|
|
30
|
+
return [];
|
|
131
31
|
}
|
|
132
|
-
function
|
|
133
|
-
if (Array.isArray(expr))
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return null;
|
|
137
|
-
if (isFunctionObject(expr))
|
|
138
|
-
return expr.fn.slice(1);
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
function op(expr, n) {
|
|
142
|
-
if (Array.isArray(expr))
|
|
143
|
-
return expr[n] ?? null;
|
|
144
|
-
if (expr === null || expr === void 0)
|
|
145
|
-
return null;
|
|
146
|
-
if (isFunctionObject(expr))
|
|
147
|
-
return expr.fn[n] ?? null;
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
function op1(expr) {
|
|
151
|
-
return op(expr, 1);
|
|
152
|
-
}
|
|
153
|
-
function op2(expr) {
|
|
154
|
-
return op(expr, 2);
|
|
32
|
+
function operand(expr, n) {
|
|
33
|
+
if (Array.isArray(expr)) return expr[n] ?? null;
|
|
34
|
+
if (expr === null || !isFunctionObject(expr)) return null;
|
|
35
|
+
return expr.fn[n] ?? null;
|
|
155
36
|
}
|
|
156
37
|
function nops(expr) {
|
|
157
|
-
if (expr === null || expr === void 0)
|
|
158
|
-
|
|
159
|
-
if (
|
|
160
|
-
return Math.max(0, expr.length - 1);
|
|
161
|
-
if (isFunctionObject(expr))
|
|
162
|
-
return Math.max(0, expr.fn.length - 1);
|
|
38
|
+
if (expr === null || expr === void 0) return 0;
|
|
39
|
+
if (Array.isArray(expr)) return Math.max(0, expr.length - 1);
|
|
40
|
+
if (isFunctionObject(expr)) return Math.max(0, expr.fn.length - 1);
|
|
163
41
|
return 0;
|
|
164
42
|
}
|
|
165
43
|
function symbol(expr) {
|
|
166
44
|
if (typeof expr === "string") {
|
|
167
|
-
if (/^[+-]?[0-9\.]/.test(expr))
|
|
168
|
-
return null;
|
|
45
|
+
if (/^[+-]?[0-9\.]/.test(expr)) return null;
|
|
169
46
|
if (expr.length >= 2 && expr[0] === "'" && expr[expr.length - 1] === "'")
|
|
170
47
|
return null;
|
|
171
48
|
return expr;
|
|
172
49
|
}
|
|
173
|
-
if (expr === null || expr === void 0)
|
|
174
|
-
return null;
|
|
50
|
+
if (expr === null || expr === void 0) return null;
|
|
175
51
|
const s = isSymbolObject(expr) ? expr.sym : expr;
|
|
176
|
-
if (typeof s !== "string")
|
|
177
|
-
return null;
|
|
52
|
+
if (typeof s !== "string") return null;
|
|
178
53
|
return s;
|
|
179
54
|
}
|
|
180
55
|
function keyValuePair(expr) {
|
|
181
|
-
const h =
|
|
56
|
+
const h = operator(expr);
|
|
182
57
|
if (h === "KeyValuePair" || h === "Tuple" || h === "Pair") {
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return [key,
|
|
58
|
+
const [k, v] = operands(expr);
|
|
59
|
+
const key = stringValue(k);
|
|
60
|
+
if (!key) return null;
|
|
61
|
+
return [key, v ?? "Nothing"];
|
|
187
62
|
}
|
|
188
63
|
return null;
|
|
189
64
|
}
|
|
190
65
|
function dictionary(expr) {
|
|
191
|
-
if (expr === null)
|
|
192
|
-
return null;
|
|
193
|
-
if (typeof expr === "object" && "dict" in expr)
|
|
194
|
-
return expr.dict;
|
|
66
|
+
if (expr === null) return null;
|
|
195
67
|
const kv = keyValuePair(expr);
|
|
196
|
-
if (kv)
|
|
197
|
-
|
|
198
|
-
const h = head(expr);
|
|
68
|
+
if (kv) return { [kv[0]]: kv[1] };
|
|
69
|
+
const h = operator(expr);
|
|
199
70
|
if (h === "Dictionary") {
|
|
200
71
|
const result = {};
|
|
72
|
+
const ops = operands(expr);
|
|
201
73
|
for (let i = 1; i < nops(expr); i++) {
|
|
202
|
-
const kv2 = keyValuePair(
|
|
203
|
-
if (kv2)
|
|
204
|
-
result[kv2[0]] = kv2[1];
|
|
74
|
+
const kv2 = keyValuePair(ops[i]);
|
|
75
|
+
if (kv2) result[kv2[0]] = kv2[1];
|
|
205
76
|
}
|
|
206
77
|
return result;
|
|
207
78
|
}
|
|
208
79
|
return null;
|
|
209
80
|
}
|
|
210
|
-
function applyRecursively(expr, fn) {
|
|
211
|
-
const h = head(expr);
|
|
212
|
-
if (h !== null) {
|
|
213
|
-
return [
|
|
214
|
-
fn(h),
|
|
215
|
-
...(ops(expr) ?? []).map(fn)
|
|
216
|
-
];
|
|
217
|
-
}
|
|
218
|
-
const dict = dictionary(expr);
|
|
219
|
-
if (dict !== null) {
|
|
220
|
-
const keys = Object.keys(dict);
|
|
221
|
-
const result = {};
|
|
222
|
-
for (const key of keys)
|
|
223
|
-
result[key] = fn(dict[key]);
|
|
224
|
-
return { dict: result };
|
|
225
|
-
}
|
|
226
|
-
return fn(expr);
|
|
227
|
-
}
|
|
228
81
|
function mapArgs(expr, fn) {
|
|
229
82
|
let args = null;
|
|
230
|
-
if (Array.isArray(expr))
|
|
231
|
-
|
|
232
|
-
if (
|
|
233
|
-
args = expr.fn;
|
|
234
|
-
if (args === null)
|
|
235
|
-
return [];
|
|
83
|
+
if (Array.isArray(expr)) args = expr;
|
|
84
|
+
if (isFunctionObject(expr)) args = expr.fn;
|
|
85
|
+
if (args === null) return [];
|
|
236
86
|
let i = 1;
|
|
237
87
|
const result = [];
|
|
238
88
|
while (i < args.length) {
|
|
@@ -243,20 +93,16 @@ function mapArgs(expr, fn) {
|
|
|
243
93
|
}
|
|
244
94
|
|
|
245
95
|
// src/math-json.ts
|
|
246
|
-
var version = "0.
|
|
96
|
+
var version = "0.26.0";
|
|
247
97
|
export {
|
|
248
|
-
applyRecursively,
|
|
249
98
|
dictionary as getDictionary,
|
|
250
99
|
stringValue as getStringValue,
|
|
251
|
-
head,
|
|
252
|
-
headName,
|
|
253
|
-
isDictionaryObject,
|
|
254
100
|
isFunctionObject,
|
|
255
101
|
isStringObject,
|
|
256
102
|
isSymbolObject,
|
|
257
103
|
mapArgs,
|
|
258
|
-
|
|
259
|
-
|
|
104
|
+
operand,
|
|
105
|
+
operator,
|
|
260
106
|
symbol,
|
|
261
107
|
version
|
|
262
108
|
};
|
package/dist/math-json.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** MathJSON 0.
|
|
1
|
+
/** MathJSON 0.26.0 */
|
|
2
2
|
(function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MathJson = {}));})(this, (function (exports) { 'use strict';
|
|
3
|
-
var MathJson=(()=>{var f=Object.defineProperty;var
|
|
3
|
+
var MathJson=(()=>{var f=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var A=(n,t)=>{for(var e in t)f(n,e,{get:t[e],enumerable:!0})},p=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of S(t))!N.call(n,i)&&i!==e&&f(n,i,{get:()=>t[i],enumerable:!(r=M(t,i))||r.enumerable});return n};var J=n=>p(f({},"__esModule",{value:!0}),n);var O={};A(O,{getDictionary:()=>g,getStringValue:()=>c,isFunctionObject:()=>u,isStringObject:()=>y,isSymbolObject:()=>a,mapArgs:()=>h,operand:()=>E,operator:()=>o,symbol:()=>b,version:()=>I});function a(n){return n!==null&&typeof n=="object"&&"sym"in n}function y(n){return n!==null&&typeof n=="object"&&"str"in n}function u(n){return n!==null&&typeof n=="object"&&"fn"in n}function c(n){return n==null?null:typeof n=="object"&&"str"in n?n.str:typeof n!="string"||n.length<2||n.at(0)!=="'"||n.at(-1)!=="'"?null:n.substring(1,n.length-1)}function o(n){return Array.isArray(n)?n[0]:n==null?"":u(n)?n.fn[0]:""}function m(n){return Array.isArray(n)?n.slice(1):n!==void 0&&u(n)?n.fn.slice(1):[]}function E(n,t){return Array.isArray(n)?n[t]??null:n===null||!u(n)?null:n.fn[t]??null}function j(n){return n==null?0:Array.isArray(n)?Math.max(0,n.length-1):u(n)?Math.max(0,n.fn.length-1):0}function b(n){if(typeof n=="string")return/^[+-]?[0-9\.]/.test(n)||n.length>=2&&n[0]==="'"&&n[n.length-1]==="'"?null:n;if(n==null)return null;let t=a(n)?n.sym:n;return typeof t!="string"?null:t}function d(n){let t=o(n);if(t==="KeyValuePair"||t==="Tuple"||t==="Pair"){let[e,r]=m(n),i=c(e);return i?[i,r??"Nothing"]:null}return null}function g(n){if(n===null)return null;let t=d(n);if(t)return{[t[0]]:t[1]};if(o(n)==="Dictionary"){let r={},i=m(n);for(let l=1;l<j(n);l++){let s=d(i[l]);s&&(r[s[0]]=s[1])}return r}return null}function h(n,t){let e=null;if(Array.isArray(n)&&(e=n),u(n)&&(e=n.fn),e===null)return[];let r=1,i=[];for(;r<e.length;)i.push(t(e[r])),r+=1;return i}var I="0.26.0";return J(O);})();
|
|
4
4
|
Object.assign(exports, MathJson); Object.defineProperty(exports, '__esModule', { value: true });}));
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
/* 0.
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
1
|
+
/* 0.26.0 */
|
|
2
|
+
export declare const DEFAULT_COLOR = "\u001B[39m";
|
|
3
|
+
export declare const DEFAULT_BG = "\u001B[49m";
|
|
4
|
+
export declare const WHITE_BG = "\u001B[47m";
|
|
5
|
+
export declare const BLACK_BG = "\u001B[40m";
|
|
6
|
+
export declare const GREY_BG = "\u001B[100m";
|
|
7
|
+
export declare const GREEN_BG = "\u001B[42m";
|
|
8
|
+
export declare const RED_BG = "\u001B[41m";
|
|
9
|
+
export declare const YELLOW_BG = "\u001B[43m";
|
|
10
|
+
export declare const BLUE_BG = "\u001B[44m";
|
|
11
|
+
export declare const MAGENTA_BG = "\u001B[45m";
|
|
12
|
+
export declare const CYAN_BG = "\u001B[46m";
|
|
13
|
+
export declare const WHITE = "\u001B[37;1m";
|
|
14
|
+
export declare const BLACK = "\u001B[30;1m";
|
|
15
|
+
export declare const GREY = "\u001B[30;1m";
|
|
4
16
|
export declare const GREEN = "\u001B[32;1m";
|
|
5
17
|
export declare const RED = "\u001B[31;1m";
|
|
6
18
|
export declare const YELLOW = "\u001B[33m";
|
|
@@ -12,4 +24,18 @@ export declare const INVERSE_GREEN = "\u001B[102;97m";
|
|
|
12
24
|
export declare const INVERSE_YELLOW = "\u001B[103;97m";
|
|
13
25
|
export declare const INVERSE_BLUE = "\u001B[104;97m";
|
|
14
26
|
export declare const BOLD = "\u001B[1m";
|
|
15
|
-
export declare const
|
|
27
|
+
export declare const BOLD_OFF = "\u001B[22m";
|
|
28
|
+
export declare const DIM = "\u001B[2m";
|
|
29
|
+
export declare const DIM_OFF = "\u001B[22m";
|
|
30
|
+
export declare const ITALIC = "\u001B[3m";
|
|
31
|
+
export declare const ITALIC_OFF = "\u001B[23m";
|
|
32
|
+
export declare const UNDERLINE = "\u001B[4m";
|
|
33
|
+
export declare const UNDERLINE_OFF = "\u001B[24m";
|
|
34
|
+
export declare const BLINK = "\u001B[5m";
|
|
35
|
+
export declare const BLINK_OFF = "\u001B[25m";
|
|
36
|
+
export declare const INVERSE = "\u001B[7m";
|
|
37
|
+
export declare const INVERSE_OFF = "\u001B[27m";
|
|
38
|
+
export declare const HIDDEN = "\u001B[8m";
|
|
39
|
+
export declare const HIDDEN_OFF = "\u001B[28m";
|
|
40
|
+
export declare function ansiFgColor(color: string | number, mode: 'none' | 'basic' | 'full'): number[];
|
|
41
|
+
export declare function ansiBgColor(color: string, mode: 'none' | 'basic' | 'full'): number[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* 0.26.0 */
|
|
2
|
+
infer Head,
|
|
3
|
+
...infer Rem
|
|
4
|
+
] ? MergeTypes<Rem, Res & Head> : Res;
|
|
5
|
+
export type OneOf<TypesArray extends any[], Res = never, AllProperties = MergeTypes<TypesArray>> = TypesArray extends [infer Head, ...infer Rem] ? OneOf<Rem, Res | OnlyFirst<Head, AllProperties>, AllProperties> : Res;
|
|
6
|
+
type OnlyFirst<F, S> = F & {
|
|
7
|
+
[Key in keyof Omit<S, keyof F>]?: never;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* 0.26.0 */
|
|
2
|
+
fg?: string;
|
|
3
|
+
bg?: string;
|
|
4
|
+
weight?: 'bold' | 'normal' | 'thin';
|
|
5
|
+
italic?: boolean;
|
|
6
|
+
mono?: boolean;
|
|
7
|
+
content: string;
|
|
8
|
+
};
|
|
9
|
+
/** A paragraph block has a blank line before and after
|
|
10
|
+
* and is wrapped to the width of the terminal.
|
|
11
|
+
*
|
|
12
|
+
* A 'block' is rendered as is, with no wrapping, but possibly
|
|
13
|
+
* with an indent. Used for code blocks, tables.
|
|
14
|
+
*
|
|
15
|
+
* A `blockquote` is a block with a vertical bar on the left,
|
|
16
|
+
* and is wrapped to the available width.
|
|
17
|
+
*
|
|
18
|
+
* A `note`, `warning` or `error` is an admonition block with a
|
|
19
|
+
* colored background or border (blue, orange or red).
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export type StyledBlock = {
|
|
23
|
+
tag: 'paragraph' | 'block';
|
|
24
|
+
spans: StyledSpan[];
|
|
25
|
+
} | {
|
|
26
|
+
tag: 'blockquote' | 'note' | 'warning' | 'error';
|
|
27
|
+
blocks: StyledBlock[];
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/* 0.26.0 */
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* 0.26.0 */
|
|
2
|
+
import { StyledBlock, StyledSpan } from './styled-text';
|
|
3
|
+
export type CodeTag =
|
|
4
|
+
/** Plain text in default foreground/background color */
|
|
5
|
+
'default'
|
|
6
|
+
/** A literal such as a number, string or regex */
|
|
7
|
+
| 'literal'
|
|
8
|
+
/** A comment */
|
|
9
|
+
| 'comment'
|
|
10
|
+
/** A language keyword: if, while, export */
|
|
11
|
+
| 'keyword'
|
|
12
|
+
/** An operator such as =, >=, +, etc... */
|
|
13
|
+
| 'operator'
|
|
14
|
+
/** A punctuation such as `;`, `,`, `:` */
|
|
15
|
+
| 'punctuation'
|
|
16
|
+
/** An identifier such as "foo" or "bar" */
|
|
17
|
+
| 'identifier'
|
|
18
|
+
/** A type such as `boolean` or `number` */
|
|
19
|
+
| 'type';
|
|
20
|
+
export type CodeSpan = {
|
|
21
|
+
tag: CodeTag;
|
|
22
|
+
content: string;
|
|
23
|
+
};
|
|
24
|
+
export type SyntaxGrammar = {
|
|
25
|
+
comment?: (buf: Buffer) => undefined | CodeSpan;
|
|
26
|
+
number?: (buf: Buffer) => undefined | CodeSpan;
|
|
27
|
+
string?: (buf: Buffer) => undefined | CodeSpan;
|
|
28
|
+
regex?: (buf: Buffer) => undefined | CodeSpan;
|
|
29
|
+
identifier?: (buf: Buffer) => undefined | CodeSpan;
|
|
30
|
+
keyword?: (buf: Buffer) => undefined | CodeSpan;
|
|
31
|
+
};
|
|
32
|
+
export declare function parseCode(text: string, grammar?: SyntaxGrammar, pos?: number): CodeSpan[];
|
|
33
|
+
/** Return a style span of the input code */
|
|
34
|
+
export declare function highlightCodeSpan(code: string, grammar?: SyntaxGrammar): StyledSpan[];
|
|
35
|
+
/** Return a style block of the input code, including a
|
|
36
|
+
* gutter with line numbers and an optional highlighted line
|
|
37
|
+
*/
|
|
38
|
+
export declare function highlightCodeBlock(code: string, lineStart?: number | undefined, markIndicator?: string, grammar?: SyntaxGrammar): StyledBlock;
|
|
39
|
+
export declare function mark(line: StyledSpan[], mark: string): StyledSpan[];
|
|
40
|
+
/** JS sample */
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* 0.26.0 */
|
|
2
|
+
declare abstract class Terminal {
|
|
3
|
+
width: number | undefined;
|
|
4
|
+
indent: number;
|
|
5
|
+
constructor(options?: {
|
|
6
|
+
indent?: number;
|
|
7
|
+
width?: number;
|
|
8
|
+
});
|
|
9
|
+
renderBlock(block: StyledBlock): string;
|
|
10
|
+
abstract renderSpan(span: StyledSpan): string;
|
|
11
|
+
renderSpans(s: StyledSpan[]): string;
|
|
12
|
+
display(s: StyledSpan[] | StyledBlock): void;
|
|
13
|
+
}
|
|
14
|
+
export declare const terminal: Terminal;
|
|
15
|
+
/** Word-wrap a string that contains ANSI escape sequences.
|
|
16
|
+
* ANSI escape sequences do not add to the string length.
|
|
17
|
+
*/
|
|
18
|
+
export declare const wrapAnsiString: (string: string, width: number | undefined) => string[];
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* 0.26.0 */
|
|
2
|
+
export declare const NUMERIC_TYPES: PrimitiveType[];
|
|
3
|
+
export declare const COLLECTION_TYPES: PrimitiveType[];
|
|
4
|
+
export declare const SCALAR_TYPES: PrimitiveType[];
|
|
5
|
+
export declare const VALUE_TYPES: PrimitiveType[];
|
|
6
|
+
export declare const EXPRESSION_TYPES: PrimitiveType[];
|
|
7
|
+
export declare const PRIMITIVE_TYPES: PrimitiveType[];
|
|
8
|
+
export declare function isValidPrimitiveType(s: any): s is PrimitiveType;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/* 0.26.0 */
|
|
2
|
+
/** Return true if lhs is a subtype of rhs */
|
|
3
|
+
export declare function isPrimitiveSubtype(lhs: PrimitiveType, rhs: PrimitiveType): boolean;
|
|
4
|
+
/** Return true if lhs is a subtype of rhs */
|
|
5
|
+
export declare function isSubtype(lhs: Type | TypeString, rhs: Type | TypeString): boolean;
|
|
6
|
+
export declare function isCompatible(lhs: PrimitiveType, rhs: PrimitiveType, compatibility: TypeCompatibility): boolean;
|