affinirum 1.5.4 → 2.0.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/.cache/arrow-preview-vWvB5K/affinirum-arrow-functions.patch +155 -0
- package/.cache/function-syntax-tests.log +20 -0
- package/README.md +925 -355
- package/dst/Affinirum.d.ts +29 -19
- package/dst/Affinirum.js +399 -334
- package/dst/CallFrame.d.ts +12 -3
- package/dst/CallFrame.js +49 -10
- package/dst/Constant.d.ts +1 -3
- package/dst/Constant.js +3 -8
- package/dst/LexicalScope.d.ts +11 -9
- package/dst/LexicalScope.js +10 -6
- package/dst/ParserSpan.d.ts +11 -0
- package/dst/{ScriptSpan.js → ParserSpan.js} +8 -5
- package/dst/ParserState.d.ts +28 -49
- package/dst/ParserState.js +256 -489
- package/dst/Type.d.ts +34 -17
- package/dst/Type.js +211 -115
- package/dst/TypeParser.d.ts +9 -0
- package/dst/TypeParser.js +127 -0
- package/dst/Value.d.ts +1 -1
- package/dst/Value.js +21 -10
- package/dst/Variable.d.ts +16 -5
- package/dst/Variable.js +32 -7
- package/dst/atom/ArrayAtom.d.ts +10 -10
- package/dst/atom/ArrayAtom.js +62 -55
- package/dst/atom/Atom.d.ts +7 -0
- package/dst/atom/FunctionAtom.d.ts +13 -15
- package/dst/atom/FunctionAtom.js +53 -104
- package/dst/atom/FunctionSignature.d.ts +23 -0
- package/dst/atom/FunctionSignature.js +124 -0
- package/dst/atom/ObjectAtom.d.ts +11 -9
- package/dst/atom/ObjectAtom.js +73 -33
- package/dst/atom/PrimitiveAtom.d.ts +6 -7
- package/dst/atom/PrimitiveAtom.js +7 -10
- package/dst/cjs/Affinirum.d.ts +29 -19
- package/dst/cjs/Affinirum.js +398 -333
- package/dst/cjs/CallFrame.d.ts +12 -3
- package/dst/cjs/CallFrame.js +49 -10
- package/dst/cjs/Constant.d.ts +1 -3
- package/dst/cjs/Constant.js +3 -8
- package/dst/cjs/LexicalScope.d.ts +11 -9
- package/dst/cjs/LexicalScope.js +10 -6
- package/dst/cjs/ParserSpan.d.ts +11 -0
- package/dst/cjs/{ScriptSpan.js → ParserSpan.js} +10 -7
- package/dst/cjs/ParserState.d.ts +28 -49
- package/dst/cjs/ParserState.js +255 -488
- package/dst/cjs/Type.d.ts +34 -17
- package/dst/cjs/Type.js +211 -115
- package/dst/cjs/TypeParser.d.ts +9 -0
- package/dst/cjs/TypeParser.js +131 -0
- package/dst/cjs/Value.d.ts +1 -1
- package/dst/cjs/Value.js +21 -10
- package/dst/cjs/Variable.d.ts +16 -5
- package/dst/cjs/Variable.js +36 -9
- package/dst/cjs/atom/ArrayAtom.d.ts +10 -10
- package/dst/cjs/atom/ArrayAtom.js +62 -55
- package/dst/cjs/atom/Atom.d.ts +7 -0
- package/dst/cjs/atom/FunctionAtom.d.ts +13 -15
- package/dst/cjs/atom/FunctionAtom.js +54 -105
- package/dst/cjs/atom/FunctionSignature.d.ts +23 -0
- package/dst/cjs/atom/FunctionSignature.js +128 -0
- package/dst/cjs/atom/ObjectAtom.d.ts +11 -9
- package/dst/cjs/atom/ObjectAtom.js +73 -33
- package/dst/cjs/atom/PrimitiveAtom.d.ts +6 -7
- package/dst/cjs/atom/PrimitiveAtom.js +7 -10
- package/dst/cjs/dictionary/Constants.d.ts +2 -0
- package/dst/cjs/dictionary/Constants.js +27 -0
- package/dst/cjs/dictionary/Functions.d.ts +2 -0
- package/dst/cjs/{Functions.js → dictionary/Functions.js} +27 -25
- package/dst/cjs/native/Aggregable.js +10 -2
- package/dst/cjs/native/Array.d.ts +2 -3
- package/dst/cjs/native/Array.js +38 -39
- package/dst/cjs/native/Boolean.d.ts +1 -1
- package/dst/cjs/native/Boolean.js +13 -10
- package/dst/cjs/native/Buffer.d.ts +5 -5
- package/dst/cjs/native/Buffer.js +70 -46
- package/dst/cjs/native/Composite.d.ts +5 -0
- package/dst/cjs/native/Composite.js +35 -0
- package/dst/cjs/native/Enumerable.js +20 -8
- package/dst/cjs/native/Float.d.ts +3 -1
- package/dst/cjs/native/Float.js +51 -12
- package/dst/cjs/native/Integer.d.ts +4 -2
- package/dst/cjs/native/Integer.js +60 -25
- package/dst/cjs/native/Iterable.d.ts +0 -2
- package/dst/cjs/native/Iterable.js +9 -28
- package/dst/cjs/native/Number.d.ts +0 -2
- package/dst/cjs/native/Number.js +34 -48
- package/dst/cjs/native/Object.d.ts +1 -1
- package/dst/cjs/native/Object.js +5 -6
- package/dst/cjs/native/String.d.ts +7 -6
- package/dst/cjs/native/String.js +28 -27
- package/dst/cjs/native/Timestamp.d.ts +3 -3
- package/dst/cjs/native/Timestamp.js +34 -36
- package/dst/cjs/native/Unknown.d.ts +3 -3
- package/dst/cjs/native/Unknown.js +48 -17
- package/dst/cjs/native/notation/AN.d.ts +1 -1
- package/dst/cjs/native/notation/AN.js +37 -35
- package/dst/cjs/native/notation/IP.d.ts +1 -1
- package/dst/cjs/native/notation/IP.js +11 -12
- package/dst/cjs/native/notation/JSON.d.ts +1 -1
- package/dst/cjs/native/notation/JSON.js +7 -6
- package/dst/cjs/node/AccessNode.d.ts +24 -0
- package/dst/cjs/node/AccessNode.js +193 -0
- package/dst/cjs/node/ArrayNode.d.ts +7 -4
- package/dst/cjs/node/ArrayNode.js +26 -15
- package/dst/cjs/node/AssignableNode.d.ts +16 -0
- package/dst/cjs/node/AssignableNode.js +18 -0
- package/dst/cjs/node/AssignmentNode.d.ts +20 -0
- package/dst/cjs/node/AssignmentNode.js +66 -0
- package/dst/cjs/node/BlockNode.d.ts +5 -4
- package/dst/cjs/node/BlockNode.js +18 -11
- package/dst/cjs/node/CallNode.d.ts +7 -5
- package/dst/cjs/node/CallNode.js +40 -41
- package/dst/cjs/node/CastNode.d.ts +5 -6
- package/dst/cjs/node/CastNode.js +16 -17
- package/dst/cjs/node/ConstantNode.d.ts +4 -6
- package/dst/cjs/node/ConstantNode.js +9 -17
- package/dst/cjs/node/FinalNode.d.ts +19 -0
- package/dst/cjs/node/FinalNode.js +41 -0
- package/dst/cjs/node/FunctionNode.d.ts +17 -0
- package/dst/cjs/node/FunctionNode.js +51 -0
- package/dst/cjs/node/InvocationNode.d.ts +5 -0
- package/dst/cjs/node/InvocationNode.js +34 -0
- package/dst/cjs/node/JumpNode.d.ts +7 -9
- package/dst/cjs/node/JumpNode.js +12 -19
- package/dst/cjs/node/LoopNode.d.ts +7 -5
- package/dst/cjs/node/LoopNode.js +33 -22
- package/dst/cjs/node/MatchNode.d.ts +17 -0
- package/dst/cjs/node/MatchNode.js +65 -0
- package/dst/cjs/node/Node.d.ts +14 -0
- package/dst/cjs/{Node.js → node/Node.js} +17 -11
- package/dst/cjs/node/ObjectNode.d.ts +7 -4
- package/dst/cjs/node/ObjectNode.js +42 -11
- package/dst/cjs/node/{SwitchNode.d.ts → TernaryNode.d.ts} +6 -6
- package/dst/cjs/node/TernaryNode.js +45 -0
- package/dst/cjs/node/VariableNode.d.ts +10 -6
- package/dst/cjs/node/VariableNode.js +50 -16
- package/dst/dictionary/Constants.d.ts +2 -0
- package/dst/dictionary/Constants.js +24 -0
- package/dst/dictionary/Functions.d.ts +2 -0
- package/dst/{Functions.js → dictionary/Functions.js} +26 -24
- package/dst/native/Aggregable.js +11 -3
- package/dst/native/Array.d.ts +2 -3
- package/dst/native/Array.js +37 -38
- package/dst/native/Boolean.d.ts +1 -1
- package/dst/native/Boolean.js +12 -9
- package/dst/native/Buffer.d.ts +5 -5
- package/dst/native/Buffer.js +66 -42
- package/dst/native/Composite.d.ts +5 -0
- package/dst/native/Composite.js +32 -0
- package/dst/native/Enumerable.js +20 -8
- package/dst/native/Float.d.ts +3 -1
- package/dst/native/Float.js +48 -11
- package/dst/native/Integer.d.ts +4 -2
- package/dst/native/Integer.js +56 -23
- package/dst/native/Iterable.d.ts +0 -2
- package/dst/native/Iterable.js +8 -27
- package/dst/native/Number.d.ts +0 -2
- package/dst/native/Number.js +34 -46
- package/dst/native/Object.d.ts +1 -1
- package/dst/native/Object.js +4 -5
- package/dst/native/String.d.ts +7 -6
- package/dst/native/String.js +24 -24
- package/dst/native/Timestamp.d.ts +3 -3
- package/dst/native/Timestamp.js +31 -33
- package/dst/native/Unknown.d.ts +3 -3
- package/dst/native/Unknown.js +49 -18
- package/dst/native/notation/AN.d.ts +1 -1
- package/dst/native/notation/AN.js +37 -35
- package/dst/native/notation/IP.d.ts +1 -1
- package/dst/native/notation/IP.js +10 -11
- package/dst/native/notation/JSON.d.ts +1 -1
- package/dst/native/notation/JSON.js +6 -5
- package/dst/node/AccessNode.d.ts +24 -0
- package/dst/node/AccessNode.js +189 -0
- package/dst/node/ArrayNode.d.ts +7 -4
- package/dst/node/ArrayNode.js +26 -15
- package/dst/node/AssignableNode.d.ts +16 -0
- package/dst/node/AssignableNode.js +14 -0
- package/dst/node/AssignmentNode.d.ts +20 -0
- package/dst/node/AssignmentNode.js +62 -0
- package/dst/node/BlockNode.d.ts +5 -4
- package/dst/node/BlockNode.js +18 -11
- package/dst/node/CallNode.d.ts +7 -5
- package/dst/node/CallNode.js +40 -41
- package/dst/node/CastNode.d.ts +5 -6
- package/dst/node/CastNode.js +16 -17
- package/dst/node/ConstantNode.d.ts +4 -6
- package/dst/node/ConstantNode.js +9 -17
- package/dst/node/FinalNode.d.ts +19 -0
- package/dst/node/FinalNode.js +37 -0
- package/dst/node/FunctionNode.d.ts +17 -0
- package/dst/node/FunctionNode.js +47 -0
- package/dst/node/InvocationNode.d.ts +5 -0
- package/dst/node/InvocationNode.js +30 -0
- package/dst/node/JumpNode.d.ts +7 -9
- package/dst/node/JumpNode.js +12 -19
- package/dst/node/LoopNode.d.ts +7 -5
- package/dst/node/LoopNode.js +33 -22
- package/dst/node/MatchNode.d.ts +17 -0
- package/dst/node/MatchNode.js +61 -0
- package/dst/node/Node.d.ts +14 -0
- package/dst/node/Node.js +28 -0
- package/dst/node/ObjectNode.d.ts +7 -4
- package/dst/node/ObjectNode.js +42 -11
- package/dst/node/{SwitchNode.d.ts → TernaryNode.d.ts} +6 -6
- package/dst/node/TernaryNode.js +41 -0
- package/dst/node/VariableNode.d.ts +10 -6
- package/dst/node/VariableNode.js +50 -16
- package/package.json +4 -4
- package/dst/Atom.d.ts +0 -7
- package/dst/Constants.d.ts +0 -2
- package/dst/Constants.js +0 -24
- package/dst/Functions.d.ts +0 -2
- package/dst/Jump.d.ts +0 -1
- package/dst/Jump.js +0 -1
- package/dst/JumpException.d.ts +0 -9
- package/dst/JumpException.js +0 -14
- package/dst/Keywords.d.ts +0 -1
- package/dst/Keywords.js +0 -17
- package/dst/Node.d.ts +0 -14
- package/dst/Node.js +0 -22
- package/dst/ScriptSpan.d.ts +0 -10
- package/dst/cjs/Atom.d.ts +0 -7
- package/dst/cjs/Constants.d.ts +0 -2
- package/dst/cjs/Constants.js +0 -27
- package/dst/cjs/Functions.d.ts +0 -2
- package/dst/cjs/Jump.d.ts +0 -1
- package/dst/cjs/Jump.js +0 -2
- package/dst/cjs/JumpException.d.ts +0 -9
- package/dst/cjs/JumpException.js +0 -18
- package/dst/cjs/Keywords.d.ts +0 -1
- package/dst/cjs/Keywords.js +0 -20
- package/dst/cjs/Node.d.ts +0 -14
- package/dst/cjs/ScriptSpan.d.ts +0 -10
- package/dst/cjs/node/SwitchNode.js +0 -49
- package/dst/cjs/node/VariadicNode.d.ts +0 -4
- package/dst/cjs/node/VariadicNode.js +0 -10
- package/dst/node/SwitchNode.js +0 -45
- package/dst/node/VariadicNode.d.ts +0 -4
- package/dst/node/VariadicNode.js +0 -6
- /package/dst/{Atom.js → atom/Atom.js} +0 -0
- /package/dst/cjs/{Atom.js → atom/Atom.js} +0 -0
package/dst/native/Buffer.js
CHANGED
|
@@ -1,36 +1,11 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
|
+
import { isWhiteSpaceSymbol } from "./String.js";
|
|
3
4
|
export const EmptyBuffer = new ArrayBuffer(0);
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
export const parseLiteralBuffer = (value, offset = 0) => {
|
|
9
|
-
const q = value.charCodeAt(offset);
|
|
10
|
-
for (let i = offset + 1, bytes = [], digits = [0, 0], ix = 0; i < value.length; ++i) {
|
|
11
|
-
const code = value.charCodeAt(i);
|
|
12
|
-
if (code === q) {
|
|
13
|
-
if (ix === 1) {
|
|
14
|
-
bytes.push(digits[0]);
|
|
15
|
-
}
|
|
16
|
-
return [new Uint8Array(bytes).buffer, i + 1];
|
|
17
|
-
}
|
|
18
|
-
if (code >= ZERO && code <= NINE) {
|
|
19
|
-
digits[ix++] = code - ZERO;
|
|
20
|
-
}
|
|
21
|
-
else if (code >= UPPER_A && code <= UPPER_F) {
|
|
22
|
-
digits[ix++] = code - UPPER_A + 10;
|
|
23
|
-
}
|
|
24
|
-
else if (code >= LOWER_A && code <= LOWER_F) {
|
|
25
|
-
digits[ix++] = code - LOWER_A + 10;
|
|
26
|
-
}
|
|
27
|
-
if (ix > 1) {
|
|
28
|
-
bytes.push(digits[0] << 4 | digits[1]);
|
|
29
|
-
ix = 0;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
throw new Error(`missing closing buffer quotation mark ${String.fromCharCode(q)}`);
|
|
33
|
-
};
|
|
5
|
+
const codeZero = "0".charCodeAt(0), codeNine = "9".charCodeAt(0);
|
|
6
|
+
const codeUpperA = "A".charCodeAt(0), codeUpperF = "F".charCodeAt(0);
|
|
7
|
+
const coderLowerA = "a".charCodeAt(0), codeLowerF = "f".charCodeAt(0);
|
|
8
|
+
const codeComment = "/".charCodeAt(0), codeNewLine = "\n".charCodeAt(0);
|
|
34
9
|
export const parseBoundedInteger = (input, base, min, max) => {
|
|
35
10
|
if (input.length === 0) {
|
|
36
11
|
throw new Error(`Invalid IP component: ${input}`);
|
|
@@ -39,14 +14,14 @@ export const parseBoundedInteger = (input, base, min, max) => {
|
|
|
39
14
|
for (let i = 0; i < input.length; i++) {
|
|
40
15
|
const code = input.charCodeAt(i);
|
|
41
16
|
let digit;
|
|
42
|
-
if (code >=
|
|
43
|
-
digit = code -
|
|
17
|
+
if (code >= codeZero && code <= codeNine) {
|
|
18
|
+
digit = code - codeZero;
|
|
44
19
|
}
|
|
45
|
-
else if (base === 16 && code >=
|
|
46
|
-
digit = code -
|
|
20
|
+
else if (base === 16 && code >= codeUpperA && code <= codeUpperF) {
|
|
21
|
+
digit = code - codeUpperA + 10;
|
|
47
22
|
}
|
|
48
|
-
else if (base === 16 && code >=
|
|
49
|
-
digit = code -
|
|
23
|
+
else if (base === 16 && code >= coderLowerA && code <= codeLowerF) {
|
|
24
|
+
digit = code - coderLowerA + 10;
|
|
50
25
|
}
|
|
51
26
|
else {
|
|
52
27
|
throw new Error(`Invalid character: ${input.charAt(i)}`);
|
|
@@ -58,7 +33,7 @@ export const parseBoundedInteger = (input, base, min, max) => {
|
|
|
58
33
|
}
|
|
59
34
|
return value;
|
|
60
35
|
};
|
|
61
|
-
export const
|
|
36
|
+
export const equalsBuffers = (value1, value2) => {
|
|
62
37
|
if (value1.byteLength !== value2.byteLength) {
|
|
63
38
|
return false;
|
|
64
39
|
}
|
|
@@ -155,12 +130,61 @@ export const parseBuffer = (value) => {
|
|
|
155
130
|
}
|
|
156
131
|
return bytes.buffer;
|
|
157
132
|
};
|
|
158
|
-
export const
|
|
133
|
+
export const formatLiteralBuffer = (value) => `\`${formatBuffer(value)}\``;
|
|
134
|
+
export const parseLiteralBuffer = (value, offset = 0) => {
|
|
135
|
+
const q = value.charCodeAt(offset);
|
|
136
|
+
for (let i = offset + 1, bytes = [], digits = [0, 0], ix = 0; i < value.length; ++i) {
|
|
137
|
+
const code = value.charCodeAt(i);
|
|
138
|
+
if (code === q) {
|
|
139
|
+
if (ix === 1) {
|
|
140
|
+
bytes.push(digits[0]);
|
|
141
|
+
}
|
|
142
|
+
return [new Uint8Array(bytes).buffer, i + 1];
|
|
143
|
+
}
|
|
144
|
+
if (code >= codeZero && code <= codeNine) {
|
|
145
|
+
digits[ix++] = code - codeZero;
|
|
146
|
+
}
|
|
147
|
+
else if (code >= codeUpperA && code <= codeUpperF) {
|
|
148
|
+
digits[ix++] = code - codeUpperA + 10;
|
|
149
|
+
}
|
|
150
|
+
else if (code >= coderLowerA && code <= codeLowerF) {
|
|
151
|
+
digits[ix++] = code - coderLowerA + 10;
|
|
152
|
+
}
|
|
153
|
+
else if (code === codeComment) {
|
|
154
|
+
if (i === value.indexOf("///", i)) {
|
|
155
|
+
i = value.indexOf("///", i + 3);
|
|
156
|
+
if (i < 0) {
|
|
157
|
+
throw new Error("missing closing comment mark");
|
|
158
|
+
}
|
|
159
|
+
i += 2;
|
|
160
|
+
}
|
|
161
|
+
else if (i === value.indexOf("//", i)) {
|
|
162
|
+
let c = value.charCodeAt(i += 2);
|
|
163
|
+
while (c !== codeNewLine && c !== q && !Number.isNaN(c)) {
|
|
164
|
+
c = value.charCodeAt(++i);
|
|
165
|
+
}
|
|
166
|
+
--i;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
throw new Error("unexpected symbol '/'");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else if (!isWhiteSpaceSymbol(value.charAt(i))) {
|
|
173
|
+
throw new Error(`unexpected symbol '${value.charAt(i)}'`);
|
|
174
|
+
}
|
|
175
|
+
if (ix > 1) {
|
|
176
|
+
bytes.push(digits[0] << 4 | digits[1]);
|
|
177
|
+
ix = 0;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
throw new Error(`missing closing buffer quotation mark ${String.fromCharCode(q)}`);
|
|
181
|
+
};
|
|
182
|
+
export const funcByteAt = new Constant((value, pos) => value == null
|
|
159
183
|
? undefined
|
|
160
|
-
: value.slice(Number(pos), Number(pos) + 1), Type.functionType(Type.OptionalBuffer, [Type.Buffer, Type.Integer]));
|
|
161
|
-
const funcRandomBuffer = new Constant((value) => value == null || value <= 0n ? new Uint8Array(0).buffer : crypto.getRandomValues(new Uint8Array(Number(value))).buffer, Type.functionType(Type.Buffer, [Type.Integer]
|
|
162
|
-
const funcParseBuffer = new Constant((value) => parseBuffer(value), Type.functionType(Type.OptionalBuffer, [Type.OptionalString]));
|
|
163
|
-
export const
|
|
184
|
+
: value.slice(Number(pos), Number(pos) + 1), Type.functionType([[Type.OptionalBuffer, [Type.Buffer, Type.Integer]]]));
|
|
185
|
+
const funcRandomBuffer = new Constant((value) => value == null || value <= 0n ? new Uint8Array(0).buffer : crypto.getRandomValues(new Uint8Array(Number(value))).buffer, Type.functionType([[Type.Buffer, [Type.Integer]]], true));
|
|
186
|
+
const funcParseBuffer = new Constant((value) => parseBuffer(value), Type.functionType([[Type.OptionalBuffer, [Type.OptionalString]]]));
|
|
187
|
+
export const globBuffer = Object.assign(Object.create(null), {
|
|
164
188
|
Random: funcRandomBuffer,
|
|
165
189
|
Parse: funcParseBuffer,
|
|
166
190
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Constant } from "../Constant.js";
|
|
2
|
+
import { Type } from "../Type.js";
|
|
3
|
+
const arrayAt = (value, index) => {
|
|
4
|
+
const ix = index < 0 ? value.length + index : index;
|
|
5
|
+
return ix >= 0 && ix < value.length ? value[ix] : undefined;
|
|
6
|
+
};
|
|
7
|
+
const objectAt = (value, key) => {
|
|
8
|
+
return Object.hasOwn(value, key) ? value[key] : undefined;
|
|
9
|
+
};
|
|
10
|
+
const arrayHas = (value, index) => {
|
|
11
|
+
const ix = index < 0 ? value.length + index : index;
|
|
12
|
+
return ix >= 0 && ix < value.length;
|
|
13
|
+
};
|
|
14
|
+
const objectHas = (value, key) => {
|
|
15
|
+
return Object.hasOwn(value, key);
|
|
16
|
+
};
|
|
17
|
+
export const funcAt = new Constant((value, index) => Array.isArray(value) ? arrayAt(value, Number(index)) : objectAt(value, String(index)), Type.functionType([
|
|
18
|
+
[Type.Any, [Type.Array, Type.Integer]],
|
|
19
|
+
[Type.Any, [Type.Object, Type.String]],
|
|
20
|
+
]));
|
|
21
|
+
export const funcOptionalAt = new Constant((value, index) => value == null ? undefined : Array.isArray(value) ? arrayAt(value, Number(index)) : objectAt(value, String(index)), Type.functionType([
|
|
22
|
+
[Type.Any, [Type.OptionalArray, Type.Integer]],
|
|
23
|
+
[Type.Any, [Type.OptionalObject, Type.String]],
|
|
24
|
+
]));
|
|
25
|
+
export const funcHas = new Constant((value, index) => Array.isArray(value) ? arrayHas(value, Number(index)) : objectHas(value, String(index)), Type.functionType([
|
|
26
|
+
[Type.Boolean, [Type.Array, Type.Integer]],
|
|
27
|
+
[Type.Boolean, [Type.Object, Type.String]],
|
|
28
|
+
]));
|
|
29
|
+
export const funcOptionalHas = new Constant((value, index) => value == null ? undefined : Array.isArray(value) ? arrayHas(value, Number(index)) : objectHas(value, String(index)), Type.functionType([
|
|
30
|
+
[Type.OptionalBoolean, [Type.OptionalArray, Type.Integer]],
|
|
31
|
+
[Type.OptionalBoolean, [Type.OptionalObject, Type.String]],
|
|
32
|
+
]));
|
package/dst/native/Enumerable.js
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
3
|
import { aggregate } from "./Aggregable.js";
|
|
4
|
-
const typeBufferArray = Type.arrayType(
|
|
5
|
-
const typeStringArray = Type.arrayType(
|
|
6
|
-
const typeArrayArray = Type.arrayType(
|
|
4
|
+
const typeBufferArray = Type.arrayType(Type.Buffer);
|
|
5
|
+
const typeStringArray = Type.arrayType(Type.String);
|
|
6
|
+
const typeArrayArray = Type.arrayType(Type.Array);
|
|
7
7
|
export const funcSlice = new Constant((value, start = 0n, end) => value == null
|
|
8
8
|
? undefined
|
|
9
|
-
: value.slice(Number(start), end == null ? undefined : Number(end)), Type.
|
|
10
|
-
|
|
9
|
+
: value.slice(Number(start), end == null ? undefined : Number(end)), Type.functionType([
|
|
10
|
+
[Type.Buffer, [Type.Buffer, Type.OptionalInteger, Type.OptionalInteger]],
|
|
11
|
+
[Type.String, [Type.String, Type.OptionalInteger, Type.OptionalInteger]],
|
|
12
|
+
[Type.Array, [Type.Array, Type.OptionalInteger, Type.OptionalInteger]],
|
|
13
|
+
]));
|
|
14
|
+
export const funcSplice = new Constant((value, start, remove, ...inject) => value == null
|
|
11
15
|
? undefined
|
|
12
|
-
: aggregate(inject.reduce((acc, val) => aggregate(acc, val), value.slice(0, Number(start))), value.slice(Number(start + remove))), Type.
|
|
13
|
-
|
|
16
|
+
: aggregate(inject.reduce((acc, val) => aggregate(acc, val), value.slice(0, Number(start))), value.slice(Number(start + remove))), Type.functionType([
|
|
17
|
+
[Type.Buffer, [Type.Buffer, Type.Integer, Type.Integer, typeBufferArray], true],
|
|
18
|
+
[Type.String, [Type.String, Type.Integer, Type.Integer, typeStringArray], true],
|
|
19
|
+
[Type.Array, [Type.Array, Type.Integer, Type.Integer, typeArrayArray], true],
|
|
20
|
+
]));
|
|
21
|
+
export const funcInject = new Constant((value, start, ...inject) => value == null
|
|
14
22
|
? undefined
|
|
15
|
-
: aggregate(inject.reduce((acc, val) => aggregate(acc, val), value.slice(0, Number(start))), value.slice(Number(start))), Type.
|
|
23
|
+
: aggregate(inject.reduce((acc, val) => aggregate(acc, val), value.slice(0, Number(start))), value.slice(Number(start))), Type.functionType([
|
|
24
|
+
[Type.Buffer, [Type.Buffer, Type.Integer, typeBufferArray], true],
|
|
25
|
+
[Type.String, [Type.String, Type.Integer, typeStringArray], true],
|
|
26
|
+
[Type.Array, [Type.Array, Type.Integer, typeArrayArray], true],
|
|
27
|
+
]));
|
package/dst/native/Float.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
export type FloatEncoding = "f32" | "f32le" | "f64" | "f64le";
|
|
3
3
|
export declare const encodeFloat: (value: number, encoding?: FloatEncoding) => ArrayBuffer;
|
|
4
|
+
export declare const formatFloat: (value: number, formatting?: string) => string;
|
|
5
|
+
export declare const formatLiteralFloat: (value: number) => string;
|
|
4
6
|
export declare const funcFloat: Constant;
|
|
5
|
-
export declare const
|
|
7
|
+
export declare const globFloat: any;
|
package/dst/native/Float.js
CHANGED
|
@@ -51,12 +51,45 @@ const decodeFloat = (value, encoding = "f64", byteOffset) => {
|
|
|
51
51
|
default: throw new Error(`${encoding} encoding not supported`);
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
export const formatFloat = (value, formatting) => {
|
|
55
|
+
if (formatting) {
|
|
56
|
+
const nformat = JSON.parse(`{${formatting}}`);
|
|
57
|
+
if (typeof nformat === "object") {
|
|
58
|
+
return new Intl.NumberFormat(undefined, {
|
|
59
|
+
minimumIntegerDigits: nformat?.min_integer_digits,
|
|
60
|
+
minimumFractionDigits: nformat?.min_fraction_digits,
|
|
61
|
+
maximumFractionDigits: nformat?.max_fraction_digits,
|
|
62
|
+
minimumSignificantDigits: nformat?.min_significant_digits,
|
|
63
|
+
maximumSignificantDigits: nformat?.max_significant_digits,
|
|
64
|
+
notation: nformat?.notation,
|
|
65
|
+
}).format(value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return Number.isInteger(value)
|
|
69
|
+
? `${value.toString()}.0`
|
|
70
|
+
: value.toString();
|
|
71
|
+
};
|
|
72
|
+
export const formatLiteralFloat = (value) => {
|
|
73
|
+
const str = value.toString();
|
|
74
|
+
return Number.isInteger(value) && !str.includes("e")
|
|
75
|
+
? `${str}.0`
|
|
76
|
+
: str;
|
|
77
|
+
};
|
|
78
|
+
const typeAggregator = Type.functionType([[Type.Float, [Type.arrayType(Type.Number)], true]]);
|
|
79
|
+
const typeTransform = Type.functionType([[Type.Float, [Type.Number]]]);
|
|
80
|
+
const funcSum = new Constant((...values) => values.reduce((acc, val) => acc + Number(val), 0), typeAggregator);
|
|
81
|
+
const funcMin = new Constant((...values) => {
|
|
82
|
+
if (values.length === 0) {
|
|
83
|
+
throw new Error("function requires at least one argument");
|
|
84
|
+
}
|
|
85
|
+
return Math.min(Number.POSITIVE_INFINITY, ...values.map((i) => Number(i)));
|
|
86
|
+
}, typeAggregator);
|
|
87
|
+
const funcMax = new Constant((...values) => {
|
|
88
|
+
if (values.length === 0) {
|
|
89
|
+
throw new Error("function requires at least one argument");
|
|
90
|
+
}
|
|
91
|
+
return Math.max(Number.NEGATIVE_INFINITY, ...values.map((i) => Number(i)));
|
|
92
|
+
}, typeAggregator);
|
|
60
93
|
const funcExponent = new Constant((value) => Math.exp(Number(value)), typeTransform);
|
|
61
94
|
const funcLogarithm = new Constant((value) => Math.log(Number(value)), typeTransform);
|
|
62
95
|
const funcAbs = new Constant((value) => Math.abs(Number(value)), typeTransform);
|
|
@@ -64,11 +97,15 @@ const funcCeil = new Constant((value) => Math.ceil(Number(value)), typeTransform
|
|
|
64
97
|
const funcFloor = new Constant((value) => Math.floor(Number(value)), typeTransform);
|
|
65
98
|
const funcRound = new Constant((value) => Math.round(Number(value)), typeTransform);
|
|
66
99
|
const funcTruncate = new Constant((value) => Math.trunc(Number(value)), typeTransform);
|
|
67
|
-
const funcRandomFloat = new Constant((value) => value == null ? undefined : Math.random() * Number(value),
|
|
68
|
-
const funcDecodeFloat = new Constant((value, encoding = "f64", byteOffset) => decodeFloat(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType(Type.OptionalFloat, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger]));
|
|
69
|
-
const funcParseFloat = new Constant((value) => value ? Number.parseFloat(value) : undefined, Type.functionType(Type.OptionalFloat, [Type.OptionalString]));
|
|
70
|
-
export const funcFloat = new Constant((value) => Number(value), Type.
|
|
71
|
-
|
|
100
|
+
const funcRandomFloat = new Constant((value) => value == null ? undefined : Math.random() * Number(value), Type.functionType([[Type.Float, [Type.Number]]], true));
|
|
101
|
+
const funcDecodeFloat = new Constant((value, encoding = "f64", byteOffset) => decodeFloat(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType([[Type.OptionalFloat, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger]]]));
|
|
102
|
+
const funcParseFloat = new Constant((value) => value ? Number.parseFloat(value) : undefined, Type.functionType([[Type.OptionalFloat, [Type.OptionalString]]]));
|
|
103
|
+
export const funcFloat = new Constant((value) => Number(value), Type.functionType([
|
|
104
|
+
[Type.Float, [Type.Boolean]],
|
|
105
|
+
[Type.Float, [Type.Timestamp]],
|
|
106
|
+
[Type.Float, [Type.Integer]],
|
|
107
|
+
]));
|
|
108
|
+
export const globFloat = Object.assign(Object.create(null), {
|
|
72
109
|
NAN: new Constant(Number.NaN),
|
|
73
110
|
PositiveInfinity: new Constant(Number.POSITIVE_INFINITY),
|
|
74
111
|
NegativeInfinity: new Constant(Number.NEGATIVE_INFINITY),
|
package/dst/native/Integer.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
export type IntegerEncoding = "i8" | "i16" | "i16le" | "i32" | "i32le" | "i64" | "i64le" | "n8" | "n16" | "n16le" | "n32" | "n32le";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const int64: (value: bigint) => bigint;
|
|
4
4
|
export declare const createInteger: (value?: number) => bigint | undefined;
|
|
5
5
|
export declare const encodeInteger: (value: bigint, encoding?: IntegerEncoding) => ArrayBuffer;
|
|
6
|
+
export declare const formatInteger: (value: bigint, formatting?: string) => string;
|
|
7
|
+
export declare const formatLiteralInteger: (value: bigint) => string;
|
|
6
8
|
export declare const funcInteger: Constant;
|
|
7
|
-
export declare const
|
|
9
|
+
export declare const globInteger: any;
|
package/dst/native/Integer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
|
-
export const
|
|
3
|
+
export const int64 = (value) => BigInt.asIntN(64, value);
|
|
4
4
|
export const createInteger = (value) => {
|
|
5
5
|
if (value == null || Number.isNaN(value)) {
|
|
6
6
|
return undefined;
|
|
@@ -11,7 +11,7 @@ export const createInteger = (value) => {
|
|
|
11
11
|
if (value === Number.POSITIVE_INFINITY) {
|
|
12
12
|
return 0x7fffffffffffffffn;
|
|
13
13
|
}
|
|
14
|
-
return
|
|
14
|
+
return int64(BigInt(Math.trunc(value)));
|
|
15
15
|
};
|
|
16
16
|
export const encodeInteger = (value, encoding = "i64") => {
|
|
17
17
|
let bits = "";
|
|
@@ -24,34 +24,34 @@ export const encodeInteger = (value, encoding = "i64") => {
|
|
|
24
24
|
const dv = new DataView(new Uint8Array(Number.parseInt(bits) / 8).buffer);
|
|
25
25
|
switch (encoding) {
|
|
26
26
|
case "i8":
|
|
27
|
-
dv.setInt8(0, Number(value));
|
|
27
|
+
dv.setInt8(0, Number(BigInt.asIntN(8, value)));
|
|
28
28
|
break;
|
|
29
29
|
case "i16":
|
|
30
|
-
dv.setInt16(0, Number(value));
|
|
30
|
+
dv.setInt16(0, Number(BigInt.asIntN(16, value)));
|
|
31
31
|
break;
|
|
32
32
|
case "i16le":
|
|
33
|
-
dv.setInt16(0, Number(value), true);
|
|
33
|
+
dv.setInt16(0, Number(BigInt.asIntN(16, value)), true);
|
|
34
34
|
break;
|
|
35
35
|
case "i32":
|
|
36
|
-
dv.setInt32(0, Number(value));
|
|
36
|
+
dv.setInt32(0, Number(BigInt.asIntN(32, value)));
|
|
37
37
|
break;
|
|
38
38
|
case "i32le":
|
|
39
|
-
dv.setInt32(0, Number(value), true);
|
|
39
|
+
dv.setInt32(0, Number(BigInt.asIntN(32, value)), true);
|
|
40
40
|
break;
|
|
41
41
|
case "n8":
|
|
42
|
-
dv.setUint8(0, Number(value));
|
|
42
|
+
dv.setUint8(0, Number(BigInt.asUintN(8, value)));
|
|
43
43
|
break;
|
|
44
44
|
case "n16":
|
|
45
|
-
dv.setUint16(0, Number(value));
|
|
45
|
+
dv.setUint16(0, Number(BigInt.asUintN(16, value)));
|
|
46
46
|
break;
|
|
47
47
|
case "n16le":
|
|
48
|
-
dv.setUint16(0, Number(value), true);
|
|
48
|
+
dv.setUint16(0, Number(BigInt.asUintN(16, value)), true);
|
|
49
49
|
break;
|
|
50
50
|
case "n32":
|
|
51
|
-
dv.setUint32(0, Number(value));
|
|
51
|
+
dv.setUint32(0, Number(BigInt.asUintN(32, value)));
|
|
52
52
|
break;
|
|
53
53
|
case "n32le":
|
|
54
|
-
dv.setUint32(0, Number(value), true);
|
|
54
|
+
dv.setUint32(0, Number(BigInt.asUintN(32, value)), true);
|
|
55
55
|
break;
|
|
56
56
|
case "i64":
|
|
57
57
|
dv.setBigInt64(0, value);
|
|
@@ -112,22 +112,55 @@ const decodeInteger = (value, encoding = "i64", byteOffset) => {
|
|
|
112
112
|
default: throw new Error(`${encoding} encoding not supported`);
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
export const formatInteger = (value, formatting) => {
|
|
116
|
+
const int = int64(value);
|
|
117
|
+
if (formatting) {
|
|
118
|
+
const nformat = JSON.parse(`{${formatting}}`);
|
|
119
|
+
if (typeof nformat === "object") {
|
|
120
|
+
return new Intl.NumberFormat(undefined, {
|
|
121
|
+
minimumIntegerDigits: nformat?.min_integer_digits,
|
|
122
|
+
minimumFractionDigits: nformat?.min_fraction_digits,
|
|
123
|
+
maximumFractionDigits: nformat?.max_fraction_digits,
|
|
124
|
+
minimumSignificantDigits: nformat?.min_significant_digits,
|
|
125
|
+
maximumSignificantDigits: nformat?.max_significant_digits,
|
|
126
|
+
notation: nformat?.notation,
|
|
127
|
+
}).format(int);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return int.toString();
|
|
131
|
+
};
|
|
132
|
+
export const formatLiteralInteger = (value) => {
|
|
133
|
+
return int64(value).toString();
|
|
134
|
+
};
|
|
135
|
+
const typeAggregator = Type.functionType([[Type.Integer, [Type.arrayType(Type.Integer)], true]]);
|
|
136
|
+
const funcSum = new Constant((...values) => int64(values.reduce((acc, val) => acc + val, 0n)), typeAggregator);
|
|
137
|
+
const funcMin = new Constant((...values) => {
|
|
138
|
+
if (values.length === 0) {
|
|
139
|
+
throw new Error("function requires at least one argument");
|
|
140
|
+
}
|
|
141
|
+
return values.reduce((min, val) => val < min ? val : min);
|
|
142
|
+
}, typeAggregator);
|
|
143
|
+
const funcMax = new Constant((...values) => {
|
|
144
|
+
if (values.length === 0) {
|
|
145
|
+
throw new Error("function requires at least one argument");
|
|
146
|
+
}
|
|
147
|
+
return values.reduce((max, val) => val > max ? val : max);
|
|
148
|
+
}, typeAggregator);
|
|
149
|
+
const funcRandomInteger = new Constant((value) => value == null ? undefined : BigInt(Math.floor(Math.random() * Number(value))), Type.functionType([[Type.Integer, [Type.Integer]]], true));
|
|
150
|
+
const funcDecodeInteger = new Constant((value, encoding = "i64", byteOffset) => decodeInteger(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType([[Type.OptionalInteger, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger]]]));
|
|
122
151
|
const funcParseInteger = new Constant((value) => {
|
|
123
152
|
try {
|
|
124
|
-
return value ?
|
|
153
|
+
return value ? int64(BigInt(value)) : undefined;
|
|
125
154
|
}
|
|
126
155
|
catch { }
|
|
127
156
|
return undefined;
|
|
128
|
-
}, Type.functionType(Type.OptionalInteger, [Type.OptionalString]));
|
|
129
|
-
export const funcInteger = new Constant((value) => createInteger(Number(value)) ?? 0n, Type.
|
|
130
|
-
|
|
157
|
+
}, Type.functionType([[Type.OptionalInteger, [Type.OptionalString]]]));
|
|
158
|
+
export const funcInteger = new Constant((value) => createInteger(Number(value)) ?? 0n, Type.functionType([
|
|
159
|
+
[Type.Integer, [Type.Boolean]],
|
|
160
|
+
[Type.Integer, [Type.Timestamp]],
|
|
161
|
+
[Type.Integer, [Type.Float]],
|
|
162
|
+
]));
|
|
163
|
+
export const globInteger = Object.assign(Object.create(null), {
|
|
131
164
|
Sum: funcSum,
|
|
132
165
|
Min: funcMin,
|
|
133
166
|
Max: funcMax,
|
package/dst/native/Iterable.d.ts
CHANGED
package/dst/native/Iterable.js
CHANGED
|
@@ -2,14 +2,13 @@ import { Constant } from "../Constant.js";
|
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
3
|
import { containsBuffer } from "./Buffer.js";
|
|
4
4
|
import { containsString } from "./String.js";
|
|
5
|
-
|
|
6
|
-
export const funcLength = new Constant((value) => boundInteger(BigInt(value == null
|
|
5
|
+
export const funcLength = new Constant((value) => BigInt(value == null
|
|
7
6
|
? 0
|
|
8
7
|
: value instanceof ArrayBuffer
|
|
9
8
|
? value.byteLength
|
|
10
9
|
: typeof value === "string" || Array.isArray(value)
|
|
11
10
|
? value.length
|
|
12
|
-
: Object.keys(value).length)
|
|
11
|
+
: Object.keys(value).length), Type.functionType([[Type.Integer, [Type.OptionalIterable]]]));
|
|
13
12
|
export const funcContains = new Constant((value, search, start, ignoreCaseSpaceEtc) => value == null
|
|
14
13
|
? false
|
|
15
14
|
: value instanceof ArrayBuffer
|
|
@@ -18,27 +17,9 @@ export const funcContains = new Constant((value, search, start, ignoreCaseSpaceE
|
|
|
18
17
|
? containsString(value, search, start == null ? undefined : Number(start), ignoreCaseSpaceEtc)
|
|
19
18
|
: Array.isArray(value)
|
|
20
19
|
? value.includes(search, start == null ? undefined : Number(start))
|
|
21
|
-
: Object.values(value).includes(search), Type.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const num = Number(index);
|
|
28
|
-
const ix = num < 0 ? value.length + num : num;
|
|
29
|
-
return ix >= 0 && ix < value.length ? value[ix] : undefined;
|
|
30
|
-
}
|
|
31
|
-
const key = String(index);
|
|
32
|
-
return Object.hasOwn(value, key) ? value[key] : undefined;
|
|
33
|
-
}, Type.union(Type.functionType(Type.Unknown, [Type.Array, Type.Integer]), Type.functionType(Type.Unknown, [Type.Object, Type.String])));
|
|
34
|
-
export const funcHas = new Constant((value, index) => {
|
|
35
|
-
if (value == null) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
else if (Array.isArray(value)) {
|
|
39
|
-
const num = Number(index);
|
|
40
|
-
const ix = num < 0 ? value.length + num : num;
|
|
41
|
-
return ix >= 0 && ix < value.length;
|
|
42
|
-
}
|
|
43
|
-
return Object.hasOwn(value, String(index));
|
|
44
|
-
}, Type.union(Type.functionType(Type.Boolean, [Type.Array, Type.Integer]), Type.functionType(Type.Boolean, [Type.Object, Type.String])));
|
|
20
|
+
: Object.values(value).includes(search), Type.functionType([
|
|
21
|
+
[Type.Boolean, [Type.Buffer, Type.Buffer, Type.OptionalInteger]],
|
|
22
|
+
[Type.Boolean, [Type.String, Type.String, Type.OptionalInteger, Type.OptionalBoolean]],
|
|
23
|
+
[Type.Boolean, [Type.Array, Type.Any, Type.OptionalInteger]],
|
|
24
|
+
[Type.Boolean, [Type.Object, Type.Any]],
|
|
25
|
+
]));
|
package/dst/native/Number.d.ts
CHANGED
|
@@ -9,9 +9,7 @@ export interface NumberFormatting {
|
|
|
9
9
|
max_significant_digits?: number;
|
|
10
10
|
notation?: "standard" | "scientific";
|
|
11
11
|
}
|
|
12
|
-
export declare const formatLiteralNumber: (value: bigint | number) => string;
|
|
13
12
|
export declare const parseLiteralNumber: (value: string, offset?: number) => readonly [number | bigint, number];
|
|
14
|
-
export declare const formatNumber: (value: bigint | number, formatting?: string) => string;
|
|
15
13
|
export declare const funcGreaterThan: Constant;
|
|
16
14
|
export declare const funcLessThan: Constant;
|
|
17
15
|
export declare const funcGreaterOrEqual: Constant;
|