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/Number.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
|
-
import {
|
|
3
|
+
import { int64 } from "./Integer.js";
|
|
4
4
|
export const isSignSymbol = (c) => c === "+" || c === "-";
|
|
5
5
|
export const isNumericSymbol = (c) => c >= "0" && c <= "9";
|
|
6
|
-
export const formatLiteralNumber = (value) => {
|
|
7
|
-
const str = value.toString();
|
|
8
|
-
return typeof value === "number" && Number.isInteger(value) && !str.includes("e")
|
|
9
|
-
? `${str}.0`
|
|
10
|
-
: str;
|
|
11
|
-
};
|
|
12
6
|
export const parseLiteralNumber = (value, offset = 0) => {
|
|
13
7
|
let i = offset;
|
|
14
8
|
let integer = true;
|
|
@@ -30,8 +24,8 @@ export const parseLiteralNumber = (value, offset = 0) => {
|
|
|
30
24
|
}
|
|
31
25
|
if (value.charAt(i) === "e") {
|
|
32
26
|
++i;
|
|
33
|
-
if (isNumericSymbol(value.charAt(i))
|
|
34
|
-
|
|
27
|
+
if (isNumericSymbol(value.charAt(i)) ||
|
|
28
|
+
isSignSymbol(value.charAt(i))) {
|
|
35
29
|
++i;
|
|
36
30
|
while (isNumericSymbol(value.charAt(i))) {
|
|
37
31
|
++i;
|
|
@@ -40,69 +34,54 @@ export const parseLiteralNumber = (value, offset = 0) => {
|
|
|
40
34
|
integer = false;
|
|
41
35
|
}
|
|
42
36
|
const str = value.slice(offset, i);
|
|
43
|
-
return [integer ?
|
|
44
|
-
};
|
|
45
|
-
export const formatNumber = (value, formatting) => {
|
|
46
|
-
if (formatting) {
|
|
47
|
-
const nformat = JSON.parse(`{${formatting}}`);
|
|
48
|
-
if (typeof nformat === "object") {
|
|
49
|
-
return new Intl.NumberFormat(undefined, {
|
|
50
|
-
minimumIntegerDigits: nformat?.min_integer_digits,
|
|
51
|
-
minimumFractionDigits: nformat?.min_fraction_digits,
|
|
52
|
-
maximumFractionDigits: nformat?.max_fraction_digits,
|
|
53
|
-
minimumSignificantDigits: nformat?.min_significant_digits,
|
|
54
|
-
maximumSignificantDigits: nformat?.max_significant_digits,
|
|
55
|
-
notation: nformat?.notation,
|
|
56
|
-
}).format(value);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return typeof value === "number" && Number.isInteger(value)
|
|
60
|
-
? `${value.toString()}.0`
|
|
61
|
-
: value.toString();
|
|
37
|
+
return [integer ? int64(BigInt(str)) : parseFloat(str), i];
|
|
62
38
|
};
|
|
63
|
-
const typeComparator = Type.functionType(Type.Boolean, [Type.Number, Type.Number]);
|
|
64
|
-
const typeOperator = Type.
|
|
39
|
+
const typeComparator = Type.functionType([[Type.Boolean, [Type.Number, Type.Number]]]);
|
|
40
|
+
const typeOperator = Type.functionType([
|
|
41
|
+
[Type.Integer, [Type.Integer, Type.Integer]],
|
|
42
|
+
[Type.Float, [Type.Float, Type.Number]],
|
|
43
|
+
[Type.Float, [Type.Number, Type.Float]],
|
|
44
|
+
[Type.Number, [Type.Number, Type.Number]],
|
|
45
|
+
]);
|
|
65
46
|
export const funcGreaterThan = new Constant((value1, value2) => value1 > value2, typeComparator);
|
|
66
47
|
export const funcLessThan = new Constant((value1, value2) => value1 < value2, typeComparator);
|
|
67
48
|
export const funcGreaterOrEqual = new Constant((value1, value2) => value1 >= value2, typeComparator);
|
|
68
49
|
export const funcLessOrEqual = new Constant((value1, value2) => value1 <= value2, typeComparator);
|
|
69
50
|
export const funcSubtract = new Constant((value, subtrahend) => typeof value === "bigint" && typeof subtrahend === "bigint"
|
|
70
|
-
?
|
|
51
|
+
? int64(value - subtrahend)
|
|
71
52
|
: Number(value) - Number(subtrahend), typeOperator);
|
|
72
53
|
export const funcMultiply = new Constant((value1, value2) => typeof value1 === "bigint" && typeof value2 === "bigint"
|
|
73
|
-
?
|
|
54
|
+
? int64(value1 * value2)
|
|
74
55
|
: Number(value1) * Number(value2), typeOperator);
|
|
75
56
|
export const funcDivide = new Constant((value, divisor) => typeof value === "bigint" && typeof divisor === "bigint"
|
|
76
|
-
?
|
|
57
|
+
? int64(value / divisor)
|
|
77
58
|
: Number(value) / Number(divisor), typeOperator);
|
|
78
59
|
export const funcRemainder = new Constant((value, divisor) => typeof value === "bigint" && typeof divisor === "bigint"
|
|
79
|
-
?
|
|
60
|
+
? value % divisor
|
|
80
61
|
: Number(value) % Number(divisor), typeOperator);
|
|
81
62
|
export const funcModulo = new Constant((value, divisor) => typeof value === "bigint" && typeof divisor === "bigint"
|
|
82
|
-
?
|
|
63
|
+
? (value % divisor + divisor) % divisor
|
|
83
64
|
: (Number(value) % Number(divisor) + Number(divisor)) % Number(divisor), typeOperator);
|
|
84
65
|
export const funcPower = new Constant((value, exponent) => typeof value === "bigint" && typeof exponent === "bigint"
|
|
85
|
-
?
|
|
66
|
+
? int64(value ** exponent)
|
|
86
67
|
: Number(value) ** Number(exponent), typeOperator);
|
|
87
68
|
export const funcRoot = new Constant((value, exponent) => {
|
|
88
69
|
if (exponent <= 0) {
|
|
89
70
|
return undefined;
|
|
90
71
|
}
|
|
91
72
|
if (typeof value === "bigint" && typeof exponent === "bigint") {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
const negative = v < 0n;
|
|
95
|
-
if (negative && e % 2n === 0n) {
|
|
73
|
+
const negative = value < 0n;
|
|
74
|
+
if (negative && exponent % 2n === 0n) {
|
|
96
75
|
return undefined;
|
|
97
76
|
}
|
|
98
|
-
const magnitude = negative ? -
|
|
99
|
-
if (magnitude <= 1n ||
|
|
100
|
-
return
|
|
77
|
+
const magnitude = negative ? -value : value;
|
|
78
|
+
if (magnitude <= 1n || exponent === 1n) {
|
|
79
|
+
return value;
|
|
101
80
|
}
|
|
102
81
|
let low = 0n, high = magnitude, result = 0n;
|
|
103
82
|
while (low <= high) {
|
|
104
83
|
const mid = low + high >> 1n;
|
|
105
|
-
const midPow = mid **
|
|
84
|
+
const midPow = mid ** exponent;
|
|
106
85
|
if (midPow === magnitude) {
|
|
107
86
|
return negative ? -mid : mid;
|
|
108
87
|
}
|
|
@@ -124,5 +103,14 @@ export const funcRoot = new Constant((value, exponent) => {
|
|
|
124
103
|
return (v < 0 || Object.is(v, -0)) && odd
|
|
125
104
|
? -Math.pow(-v, 1 / e)
|
|
126
105
|
: Math.pow(v, 1 / e);
|
|
127
|
-
},
|
|
128
|
-
|
|
106
|
+
}, Type.functionType([
|
|
107
|
+
[Type.OptionalInteger, [Type.Integer, Type.Integer]],
|
|
108
|
+
[Type.OptionalFloat, [Type.Float, Type.Number]],
|
|
109
|
+
[Type.OptionalFloat, [Type.Number, Type.Float]],
|
|
110
|
+
[Type.OptionalNumber, [Type.Number, Type.Number]],
|
|
111
|
+
]));
|
|
112
|
+
export const funcNegate = new Constant((value) => value == null ? undefined : typeof value === "number" ? -value : int64(-value), Type.functionType([
|
|
113
|
+
[Type.Float, [Type.Float]],
|
|
114
|
+
[Type.Integer, [Type.Integer]],
|
|
115
|
+
[Type.Number, [Type.Number]],
|
|
116
|
+
]));
|
package/dst/native/Object.d.ts
CHANGED
package/dst/native/Object.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
|
-
const typeAccessor = Type.functionType(Type.Array, [Type.Object]);
|
|
4
|
-
const typeObjectOrArray = Type.union(Type.Object, Type.arrayType([Type.Object]));
|
|
3
|
+
const typeAccessor = Type.functionType([[Type.Array, [Type.Object]]]);
|
|
5
4
|
export const funcEntries = new Constant((value) => value ? Object.entries(value) : undefined, typeAccessor);
|
|
6
|
-
export const funcKeys = new Constant((value) => value ? Object.keys(value) : undefined, Type.functionType(Type.arrayType(
|
|
5
|
+
export const funcKeys = new Constant((value) => value ? Object.keys(value) : undefined, Type.functionType([[Type.arrayType(Type.String), [Type.Object]]]));
|
|
7
6
|
export const funcValues = new Constant((value) => value ? Object.values(value) : undefined, typeAccessor);
|
|
8
|
-
const funcMerge = new Constant((values) => values.
|
|
9
|
-
export const
|
|
7
|
+
const funcMerge = new Constant((...values) => values.reduce((acc, val) => Object.assign(acc, val), Object.create(null)), Type.functionType([[Type.Object, [Type.arrayType(Type.Object)], true]]));
|
|
8
|
+
export const globObject = Object.assign(Object.create(null), {
|
|
10
9
|
Merge: funcMerge,
|
|
11
10
|
});
|
package/dst/native/String.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
export type StringEncoding = "utf8" | "sbcs" | "ucs2" | "ucs2le";
|
|
3
3
|
export declare const isAlphanumericSymbol: (c: string) => boolean;
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
4
|
+
export declare const isIdentifierStartSymbol: (c: string) => boolean;
|
|
5
|
+
export declare const isIdentifierSymbol: (c: string) => boolean;
|
|
6
6
|
export declare const isHexadecimalSymbol: (c: string) => boolean;
|
|
7
|
+
export declare const isWhiteSpaceSymbol: (c: string) => c is "\t" | "\n" | "\r" | "\f" | "\v" | " ";
|
|
7
8
|
export declare const formatLiteralString: (value: string) => string;
|
|
8
9
|
export declare const parseLiteralString: (value: string, offset?: number) => readonly [string, number];
|
|
9
10
|
export declare const replaceWith: (value?: string, replacement?: string, ...search: string[]) => string | undefined;
|
|
@@ -13,11 +14,11 @@ export declare const startsWithString: (value?: string, search?: string, startPo
|
|
|
13
14
|
export declare const endsWithString: (value?: string, search?: string, endPos?: number, ignoreCaseSpaceEtc?: boolean) => boolean;
|
|
14
15
|
export declare const encodeString: (value: string, encoding?: StringEncoding) => ArrayBuffer;
|
|
15
16
|
export declare const funcLike: Constant;
|
|
16
|
-
export declare const
|
|
17
|
+
export declare const funcNotLike: Constant;
|
|
17
18
|
export declare const funcStartsWith: Constant;
|
|
18
19
|
export declare const funcEndsWith: Constant;
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const
|
|
20
|
+
export declare const funcCharAt: Constant;
|
|
21
|
+
export declare const funcCharCodeAt: Constant;
|
|
21
22
|
export declare const funcTrim: Constant;
|
|
22
23
|
export declare const funcTrimStart: Constant;
|
|
23
24
|
export declare const funcTrimEnd: Constant;
|
|
@@ -25,4 +26,4 @@ export declare const funcLowerCase: Constant;
|
|
|
25
26
|
export declare const funcUpperCase: Constant;
|
|
26
27
|
export declare const funcSplit: Constant;
|
|
27
28
|
export declare const funcReplaceWith: Constant;
|
|
28
|
-
export declare const
|
|
29
|
+
export declare const globString: any;
|
package/dst/native/String.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
3
|
import { createInteger } from "./Integer.js";
|
|
4
|
-
export const isAlphanumericSymbol = (c) => c >= "a" && c <= "z" || c >= "0" && c <= "9";
|
|
5
|
-
export const
|
|
6
|
-
export const
|
|
4
|
+
export const isAlphanumericSymbol = (c) => c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c >= "0" && c <= "9";
|
|
5
|
+
export const isIdentifierStartSymbol = (c) => c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c === "_" || c === "$";
|
|
6
|
+
export const isIdentifierSymbol = (c) => isIdentifierStartSymbol(c) || c >= "0" && c <= "9";
|
|
7
7
|
export const isHexadecimalSymbol = (c) => c >= "0" && c <= "9" || c >= "a" && c <= "f" || c >= "A" && c <= "F";
|
|
8
|
+
export const isWhiteSpaceSymbol = (c) => c === " " || c === "\t" || c === "\n" || c === "\r" || c === "\v" || c === "\f";
|
|
8
9
|
export const formatLiteralString = (value) => {
|
|
9
10
|
let str = "\"";
|
|
10
11
|
for (let i = 0; i < value.length; ++i) {
|
|
@@ -291,36 +292,35 @@ const decodeString = (value, encoding = "utf8", byteOffset, byteLength) => {
|
|
|
291
292
|
}
|
|
292
293
|
return str;
|
|
293
294
|
};
|
|
294
|
-
const typeStringEquator = Type.functionType(Type.Boolean, [Type.String, Type.String]);
|
|
295
|
-
const typeStringComparator = Type.functionType(Type.Boolean, [Type.String, Type.String, Type.OptionalInteger, Type.OptionalBoolean]);
|
|
296
|
-
const typeStringMutator = Type.functionType(Type.String, [Type.String]);
|
|
297
|
-
const typeStringOrArray = Type.union(Type.String, Type.arrayType([Type.String]));
|
|
295
|
+
const typeStringEquator = Type.functionType([[Type.Boolean, [Type.String, Type.String]]]);
|
|
296
|
+
const typeStringComparator = Type.functionType([[Type.Boolean, [Type.String, Type.String, Type.OptionalInteger, Type.OptionalBoolean]]]);
|
|
297
|
+
const typeStringMutator = Type.functionType([[Type.String, [Type.String]]]);
|
|
298
298
|
export const funcLike = new Constant((value1, value2) => equateStrings(value1, value2, true), typeStringEquator);
|
|
299
|
-
export const
|
|
299
|
+
export const funcNotLike = new Constant((value1, value2) => !equateStrings(value1, value2, true), typeStringEquator);
|
|
300
300
|
export const funcStartsWith = new Constant((value, search, start, ignoreCaseSpaceEtc) => startsWithString(value, search, start == null ? undefined : Number(start), ignoreCaseSpaceEtc), typeStringComparator);
|
|
301
301
|
export const funcEndsWith = new Constant((value, search, end, ignoreCaseSpaceEtc) => endsWithString(value, search, end == null ? undefined : Number(end), ignoreCaseSpaceEtc), typeStringComparator);
|
|
302
|
-
export const
|
|
302
|
+
export const funcCharAt = new Constant((value, pos) => value == null
|
|
303
303
|
? undefined
|
|
304
|
-
: value.charAt(pos < 0 ? value.length + Number(pos) : Number(pos)), Type.functionType(Type.OptionalString, [Type.String, Type.Integer]));
|
|
305
|
-
export const
|
|
304
|
+
: value.charAt(pos < 0 ? value.length + Number(pos) : Number(pos)), Type.functionType([[Type.OptionalString, [Type.String, Type.Integer]]]));
|
|
305
|
+
export const funcCharCodeAt = new Constant((value, pos) => value == null
|
|
306
306
|
? undefined
|
|
307
|
-
: createInteger(value.charCodeAt(pos < 0 ? value.length + Number(pos) : Number(pos))), Type.functionType(Type.OptionalInteger, [Type.String, Type.Integer]));
|
|
307
|
+
: createInteger(value.charCodeAt(pos < 0 ? value.length + Number(pos) : Number(pos))), Type.functionType([[Type.OptionalInteger, [Type.String, Type.Integer]]]));
|
|
308
308
|
export const funcTrim = new Constant((value) => value?.trim(), typeStringMutator);
|
|
309
309
|
export const funcTrimStart = new Constant((value) => value?.trimStart(), typeStringMutator);
|
|
310
310
|
export const funcTrimEnd = new Constant((value) => value?.trimEnd(), typeStringMutator);
|
|
311
311
|
export const funcLowerCase = new Constant((value) => value?.toLowerCase(), typeStringMutator);
|
|
312
312
|
export const funcUpperCase = new Constant((value) => value?.toUpperCase(), typeStringMutator);
|
|
313
|
-
export const funcSplit = new Constant((value, separator = " ") => value?.split(separator) ?? [], Type.functionType(Type.arrayType(
|
|
314
|
-
export const funcReplaceWith = new Constant((value, replacement, search) => replaceWith(value, replacement, ...search
|
|
315
|
-
const
|
|
316
|
-
if (
|
|
313
|
+
export const funcSplit = new Constant((value, separator = " ") => value?.split(separator) ?? [], Type.functionType([[Type.arrayType(Type.String), [Type.String, Type.OptionalString]]]));
|
|
314
|
+
export const funcReplaceWith = new Constant((value, replacement, ...search) => replaceWith(value, replacement, ...search), Type.functionType([[Type.String, [Type.String, Type.String, Type.arrayType(Type.String)], true]]));
|
|
315
|
+
const funcAlphanumeric = new Constant((value) => {
|
|
316
|
+
if (value == null) {
|
|
317
317
|
return undefined;
|
|
318
318
|
}
|
|
319
|
-
const str = value.toLowerCase();
|
|
320
319
|
let result = "";
|
|
321
|
-
for (let i = 0; i <
|
|
322
|
-
|
|
323
|
-
|
|
320
|
+
for (let i = 0; i < value.length; ++i) {
|
|
321
|
+
const c = value[i];
|
|
322
|
+
if (isAlphanumericSymbol(c)) {
|
|
323
|
+
result += c.toLowerCase();
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
326
|
return result;
|
|
@@ -332,10 +332,10 @@ const funcRandomString = new Constant((value) => {
|
|
|
332
332
|
str += Math.random().toString(36).slice(2);
|
|
333
333
|
}
|
|
334
334
|
return str.slice(0, length);
|
|
335
|
-
}, Type.functionType(Type.String, [Type.Integer]
|
|
336
|
-
const funcDecodeString = new Constant((value, encoding = "utf8", byteOffset, byteLength) => decodeString(value, encoding, byteOffset == null ? undefined : Number(byteOffset), byteLength == null ? undefined : Number(byteLength)), Type.functionType(Type.OptionalString, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger, Type.OptionalInteger]));
|
|
337
|
-
export const
|
|
338
|
-
|
|
335
|
+
}, Type.functionType([[Type.String, [Type.Integer]]], true));
|
|
336
|
+
const funcDecodeString = new Constant((value, encoding = "utf8", byteOffset, byteLength) => decodeString(value, encoding, byteOffset == null ? undefined : Number(byteOffset), byteLength == null ? undefined : Number(byteLength)), Type.functionType([[Type.OptionalString, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger, Type.OptionalInteger]]]));
|
|
337
|
+
export const globString = Object.assign(Object.create(null), {
|
|
338
|
+
Alphanumeric: funcAlphanumeric,
|
|
339
339
|
Random: funcRandomString,
|
|
340
340
|
Decode: funcDecodeString,
|
|
341
341
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
export type TimestampEncoding = "i32" | "i32le" | "i64" | "i64le";
|
|
3
|
-
export declare const formatLiteralTimestamp: (value: Date) => string;
|
|
4
|
-
export declare const parseLiteralTimestamp: (value: string, offset?: number) => readonly [Date, number];
|
|
5
3
|
export declare const encodeTimestamp: (value: Date, encoding?: TimestampEncoding) => ArrayBuffer;
|
|
6
4
|
export declare const decodeTimestamp: (value?: ArrayBuffer, encoding?: TimestampEncoding, byteOffset?: number) => Date | undefined;
|
|
7
5
|
export declare const formatTimestamp: (value: Date, template?: string) => string;
|
|
6
|
+
export declare const formatLiteralTimestamp: (value: Date) => string;
|
|
7
|
+
export declare const parseLiteralTimestamp: (value: string, offset?: number) => readonly [Date, number];
|
|
8
8
|
export declare const funcYear: Constant;
|
|
9
9
|
export declare const funcMonth: Constant;
|
|
10
10
|
export declare const funcMonthIndex: Constant;
|
|
@@ -19,4 +19,4 @@ export declare const funcDaysSince: Constant;
|
|
|
19
19
|
export declare const funcHoursSince: Constant;
|
|
20
20
|
export declare const funcMinutesSince: Constant;
|
|
21
21
|
export declare const funcSecondsSince: Constant;
|
|
22
|
-
export declare const
|
|
22
|
+
export declare const globTimestamp: any;
|
package/dst/native/Timestamp.js
CHANGED
|
@@ -1,39 +1,14 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
|
-
import { boundInteger } from "./Integer.js";
|
|
4
3
|
import { isNumericSymbol } from "./Number.js";
|
|
5
4
|
const minuteMilliseconds = 60000;
|
|
6
|
-
const typeTimestampPart = Type.functionType(Type.Integer, [Type.Timestamp, Type.OptionalBoolean]);
|
|
7
|
-
const typeTimestampSince = Type.functionType(Type.Float, [Type.Timestamp, Type.Timestamp]);
|
|
5
|
+
const typeTimestampPart = Type.functionType([[Type.Integer, [Type.Timestamp, Type.OptionalBoolean]]]);
|
|
6
|
+
const typeTimestampSince = Type.functionType([[Type.Float, [Type.Timestamp, Type.Timestamp]]]);
|
|
8
7
|
const isDateSeparatorSymbol = (c) => c === "-";
|
|
9
8
|
const isTimeSeparatorSymbol = (c) => c === ":";
|
|
10
9
|
const isDateTimeSeparatorSymbol = (c) => c === "T" || c === " " || c === "@";
|
|
11
10
|
const isDateSymbol = (c) => isNumericSymbol(c) || isDateSeparatorSymbol(c);
|
|
12
11
|
const isTimeSymbol = (c) => isNumericSymbol(c) || isTimeSeparatorSymbol(c);
|
|
13
|
-
export const formatLiteralTimestamp = (value) => `@${formatTimestamp(value)}`;
|
|
14
|
-
export const parseLiteralTimestamp = (value, offset = 0) => {
|
|
15
|
-
let i = offset + 1;
|
|
16
|
-
while (isDateSymbol(value.charAt(i))) {
|
|
17
|
-
++i;
|
|
18
|
-
}
|
|
19
|
-
if (isDateTimeSeparatorSymbol(value.charAt(i))) {
|
|
20
|
-
++i;
|
|
21
|
-
while (isTimeSymbol(value.charAt(i))) {
|
|
22
|
-
++i;
|
|
23
|
-
}
|
|
24
|
-
if (value.charAt(i) === "."
|
|
25
|
-
&& isNumericSymbol(value.charAt(i + 1))) {
|
|
26
|
-
++i;
|
|
27
|
-
while (isNumericSymbol(value.charAt(i))) {
|
|
28
|
-
++i;
|
|
29
|
-
}
|
|
30
|
-
if (value.charAt(i) === "Z") {
|
|
31
|
-
++i;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return [new Date(value.slice(offset + 1, i)), i];
|
|
36
|
-
};
|
|
37
12
|
export const encodeTimestamp = (value, encoding = "i64") => {
|
|
38
13
|
const littleEndian = encoding.endsWith("le");
|
|
39
14
|
switch (encoding) {
|
|
@@ -121,7 +96,30 @@ const parseTimestamp = (value) => {
|
|
|
121
96
|
const date = new Date(value);
|
|
122
97
|
return isNaN(date.getTime()) ? undefined : date;
|
|
123
98
|
};
|
|
124
|
-
const
|
|
99
|
+
export const formatLiteralTimestamp = (value) => `@${formatTimestamp(value)}`;
|
|
100
|
+
export const parseLiteralTimestamp = (value, offset = 0) => {
|
|
101
|
+
let i = offset + 1;
|
|
102
|
+
while (isDateSymbol(value.charAt(i))) {
|
|
103
|
+
++i;
|
|
104
|
+
}
|
|
105
|
+
if (isDateTimeSeparatorSymbol(value.charAt(i))) {
|
|
106
|
+
++i;
|
|
107
|
+
while (isTimeSymbol(value.charAt(i))) {
|
|
108
|
+
++i;
|
|
109
|
+
}
|
|
110
|
+
if (value.charAt(i) === "." && isNumericSymbol(value.charAt(i + 1))) {
|
|
111
|
+
++i;
|
|
112
|
+
while (isNumericSymbol(value.charAt(i))) {
|
|
113
|
+
++i;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (value.charAt(i) === "Z") {
|
|
117
|
+
++i;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return [new Date(value.slice(offset + 1, i)), i];
|
|
121
|
+
};
|
|
122
|
+
const funcNow = new Constant(() => new Date(), Type.functionType([[Type.Timestamp, []]], true));
|
|
125
123
|
export const funcYear = new Constant((value, utc = false) => value ? BigInt(utc ? value.getUTCFullYear() : value.getFullYear()) : undefined, typeTimestampPart);
|
|
126
124
|
export const funcMonth = new Constant((value, utc = false) => value ? BigInt(1 + (utc ? value.getUTCMonth() : value.getMonth())) : undefined, typeTimestampPart);
|
|
127
125
|
export const funcMonthIndex = new Constant((value, utc = false) => value ? BigInt(utc ? value.getUTCMonth() : value.getMonth()) : undefined, typeTimestampPart);
|
|
@@ -131,7 +129,7 @@ export const funcHour = new Constant((value, utc = false) => value ? BigInt(utc
|
|
|
131
129
|
export const funcMinute = new Constant((value, utc = false) => value ? BigInt(utc ? value.getUTCMinutes() : value.getMinutes()) : undefined, typeTimestampPart);
|
|
132
130
|
export const funcSecond = new Constant((value, utc = false) => value ? BigInt(utc ? value.getUTCSeconds() : value.getSeconds()) : undefined, typeTimestampPart);
|
|
133
131
|
export const funcMillisecond = new Constant((value, utc = false) => value ? BigInt(utc ? value.getUTCMilliseconds() : value.getMilliseconds()) : undefined, typeTimestampPart);
|
|
134
|
-
export const funcEpochTime = new Constant((value, epoch = new Date(0)) => value ?
|
|
132
|
+
export const funcEpochTime = new Constant((value, epoch = new Date(0)) => value ? BigInt(value.getTime() - epoch.getTime()) : undefined, Type.functionType([[Type.Integer, [Type.Timestamp, Type.OptionalTimestamp]]]));
|
|
135
133
|
export const funcDaysSince = new Constant((value1, value2) => (value1?.getTime() - value2?.getTime()) / 86400000.0, typeTimestampSince);
|
|
136
134
|
export const funcHoursSince = new Constant((value1, value2) => (value1?.getTime() - value2?.getTime()) / 3600000.0, typeTimestampSince);
|
|
137
135
|
export const funcMinutesSince = new Constant((value1, value2) => (value1?.getTime() - value2?.getTime()) / 60000.0, typeTimestampSince);
|
|
@@ -139,10 +137,10 @@ export const funcSecondsSince = new Constant((value1, value2) => (value1?.getTim
|
|
|
139
137
|
const funcEpochTimestamp = new Constant((value, epoch = new Date(0)) => {
|
|
140
138
|
const ts = new Date(Number(value ?? 0) + epoch?.getTime());
|
|
141
139
|
return Number.isNaN(ts.getTime()) ? undefined : ts;
|
|
142
|
-
}, Type.functionType(Type.Timestamp, [Type.Number, Type.OptionalTimestamp]));
|
|
143
|
-
const funcDecodeTimestamp = new Constant((value, encoding = "i64", byteOffset) => decodeTimestamp(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType(Type.OptionalTimestamp, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger]));
|
|
144
|
-
const funcParseTimestamp = new Constant((value) => parseTimestamp(value), Type.functionType(Type.OptionalTimestamp, [Type.OptionalString]));
|
|
145
|
-
export const
|
|
140
|
+
}, Type.functionType([[Type.Timestamp, [Type.Number, Type.OptionalTimestamp]]]));
|
|
141
|
+
const funcDecodeTimestamp = new Constant((value, encoding = "i64", byteOffset) => decodeTimestamp(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType([[Type.OptionalTimestamp, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger]]]));
|
|
142
|
+
const funcParseTimestamp = new Constant((value) => parseTimestamp(value), Type.functionType([[Type.OptionalTimestamp, [Type.OptionalString]]]));
|
|
143
|
+
export const globTimestamp = Object.assign(Object.create(null), {
|
|
146
144
|
Now: funcNow,
|
|
147
145
|
Epoch: funcEpochTimestamp,
|
|
148
146
|
Decode: funcDecodeTimestamp,
|
package/dst/native/Unknown.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ import { FloatEncoding } from "./Float.js";
|
|
|
4
4
|
import { IntegerEncoding } from "./Integer.js";
|
|
5
5
|
import { StringEncoding } from "./String.js";
|
|
6
6
|
import { TimestampEncoding } from "./Timestamp.js";
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const equals: (value1: Value, value2: Value, pairs?: WeakMap<object, WeakSet<object>>) => boolean;
|
|
8
8
|
export declare const encode: (value: Value, encoding?: FloatEncoding | IntegerEncoding | TimestampEncoding | StringEncoding) => ArrayBuffer;
|
|
9
9
|
export declare const format: (value: Value, formatting?: string) => string;
|
|
10
10
|
export declare const funcCoalesce: Constant;
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
11
|
+
export declare const funcEquals: Constant;
|
|
12
|
+
export declare const funcNotEquals: Constant;
|
|
13
13
|
export declare const funcEncode: Constant;
|
|
14
14
|
export declare const funcFormat: Constant;
|
package/dst/native/Unknown.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Constant } from "../Constant.js";
|
|
2
2
|
import { Type } from "../Type.js";
|
|
3
|
-
import { formatBuffer, concatBuffers,
|
|
4
|
-
import { encodeFloat } from "./Float.js";
|
|
5
|
-
import { encodeInteger } from "./Integer.js";
|
|
6
|
-
import { formatNumber } from "./Number.js";
|
|
3
|
+
import { formatBuffer, concatBuffers, equalsBuffers, EmptyBuffer } from "./Buffer.js";
|
|
4
|
+
import { encodeFloat, formatFloat } from "./Float.js";
|
|
5
|
+
import { encodeInteger, formatInteger } from "./Integer.js";
|
|
7
6
|
import { encodeString } from "./String.js";
|
|
8
7
|
import { encodeTimestamp, formatTimestamp } from "./Timestamp.js";
|
|
9
|
-
export const
|
|
8
|
+
export const equals = (value1, value2, pairs) => {
|
|
10
9
|
if (value1 == null || value2 == null) {
|
|
11
10
|
return value1 == value2;
|
|
12
11
|
}
|
|
@@ -22,7 +21,10 @@ export const equate = (value1, value2) => {
|
|
|
22
21
|
if (typeof value1 === "number") {
|
|
23
22
|
return isNaN(value1) && isNaN(value2) ? true : value1 === value2;
|
|
24
23
|
}
|
|
25
|
-
if (typeof value1 === "
|
|
24
|
+
if (typeof value1 === "bigint") {
|
|
25
|
+
return value1 === value2;
|
|
26
|
+
}
|
|
27
|
+
if (typeof value1 === "boolean" || typeof value1 === "string" || typeof value1 === "function") {
|
|
26
28
|
return value1 === value2;
|
|
27
29
|
}
|
|
28
30
|
if (value1 instanceof Date && value2 instanceof Date) {
|
|
@@ -32,15 +34,25 @@ export const equate = (value1, value2) => {
|
|
|
32
34
|
return false;
|
|
33
35
|
}
|
|
34
36
|
if (value1 instanceof ArrayBuffer && value2 instanceof ArrayBuffer) {
|
|
35
|
-
return
|
|
37
|
+
return equalsBuffers(value1, value2);
|
|
36
38
|
}
|
|
37
39
|
if (value1 instanceof ArrayBuffer || value2 instanceof ArrayBuffer) {
|
|
38
40
|
return false;
|
|
39
41
|
}
|
|
42
|
+
pairs ??= new WeakMap();
|
|
43
|
+
let matches = pairs.get(value1);
|
|
44
|
+
if (matches?.has(value2)) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
if (!matches) {
|
|
48
|
+
matches = new WeakSet();
|
|
49
|
+
pairs.set(value1, matches);
|
|
50
|
+
}
|
|
51
|
+
matches.add(value2);
|
|
40
52
|
if (Array.isArray(value1) && Array.isArray(value2)) {
|
|
41
53
|
if (value1.length === value2.length) {
|
|
42
54
|
for (let i = 0; i < value1.length; ++i) {
|
|
43
|
-
if (!
|
|
55
|
+
if (!equals(value1[i], value2[i], pairs)) {
|
|
44
56
|
return false;
|
|
45
57
|
}
|
|
46
58
|
}
|
|
@@ -51,9 +63,9 @@ export const equate = (value1, value2) => {
|
|
|
51
63
|
if (Array.isArray(value1) || Array.isArray(value2)) {
|
|
52
64
|
return false;
|
|
53
65
|
}
|
|
54
|
-
const props = new Set([...Object.
|
|
66
|
+
const props = new Set([...Object.keys(value1), ...Object.keys(value2)]);
|
|
55
67
|
for (const prop of props) {
|
|
56
|
-
if (!
|
|
68
|
+
if (!equals(value1[prop], value2[prop], pairs)) {
|
|
57
69
|
return false;
|
|
58
70
|
}
|
|
59
71
|
}
|
|
@@ -87,9 +99,9 @@ export const format = (value, formatting) => value == null
|
|
|
87
99
|
: value instanceof Date
|
|
88
100
|
? formatTimestamp(value, formatting)
|
|
89
101
|
: typeof value === "number"
|
|
90
|
-
?
|
|
102
|
+
? formatFloat(value, formatting)
|
|
91
103
|
: typeof value === "bigint"
|
|
92
|
-
?
|
|
104
|
+
? formatInteger(value, formatting)
|
|
93
105
|
: value instanceof ArrayBuffer
|
|
94
106
|
? formatBuffer(value, formatting)
|
|
95
107
|
: typeof value === "string"
|
|
@@ -101,9 +113,28 @@ export const format = (value, formatting) => value == null
|
|
|
101
113
|
.map(([k, v]) => format(k, formatting) + format(v, formatting))
|
|
102
114
|
.reduce((acc, val) => acc + val, "")
|
|
103
115
|
: "";
|
|
104
|
-
const typeEquator = Type.functionType(Type.Boolean, [Type.
|
|
105
|
-
export const funcCoalesce = new Constant((value, valueOtherwise) => value ?? valueOtherwise, Type.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
116
|
+
const typeEquator = Type.functionType([[Type.Boolean, [Type.Any, Type.Any]]]);
|
|
117
|
+
export const funcCoalesce = new Constant((value, valueOtherwise) => value ?? valueOtherwise, Type.functionType([
|
|
118
|
+
[Type.Any, [Type.Any, Type.Any]],
|
|
119
|
+
[Type.OptionalFloat, [Type.OptionalFloat, Type.OptionalFloat]],
|
|
120
|
+
[Type.OptionalBoolean, [Type.OptionalBoolean, Type.OptionalBoolean]],
|
|
121
|
+
[Type.OptionalTimestamp, [Type.OptionalTimestamp, Type.OptionalTimestamp]],
|
|
122
|
+
[Type.OptionalInteger, [Type.OptionalInteger, Type.OptionalInteger]],
|
|
123
|
+
[Type.OptionalBuffer, [Type.OptionalBuffer, Type.OptionalBuffer]],
|
|
124
|
+
[Type.OptionalString, [Type.OptionalString, Type.OptionalString]],
|
|
125
|
+
[Type.OptionalArray, [Type.OptionalArray, Type.OptionalArray]],
|
|
126
|
+
[Type.OptionalObject, [Type.OptionalObject, Type.OptionalObject]],
|
|
127
|
+
[Type.OptionalFunction, [Type.OptionalFunction, Type.OptionalFunction]],
|
|
128
|
+
]));
|
|
129
|
+
export const funcEquals = new Constant((value1, value2) => equals(value1, value2), typeEquator);
|
|
130
|
+
export const funcNotEquals = new Constant((value1, value2) => !equals(value1, value2), typeEquator);
|
|
131
|
+
const typeWithEncoding = Type.union(Type.Null, Type.Timestamp, Type.Number, Type.String, Type.Composite);
|
|
132
|
+
const typeWithFormatting = Type.union(Type.Null, Type.Timestamp, Type.Number, Type.Buffer, Type.Composite);
|
|
133
|
+
export const funcEncode = new Constant((value, encoding) => encode(value, encoding), Type.functionType([
|
|
134
|
+
[Type.Buffer, [Type.Any]],
|
|
135
|
+
[Type.Buffer, [typeWithEncoding, Type.OptionalString]],
|
|
136
|
+
]));
|
|
137
|
+
export const funcFormat = new Constant((value, formatting) => format(value, formatting), Type.functionType([
|
|
138
|
+
[Type.String, [Type.Any]],
|
|
139
|
+
[Type.String, [typeWithFormatting, Type.OptionalString]],
|
|
140
|
+
]));
|