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/cjs/native/Float.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.globFloat = exports.funcFloat = exports.formatLiteralFloat = exports.formatFloat = exports.encodeFloat = void 0;
|
|
4
4
|
const Constant_js_1 = require("../Constant.js");
|
|
5
5
|
const Type_js_1 = require("../Type.js");
|
|
6
6
|
const encodeFloat = (value, encoding = "f64") => {
|
|
@@ -55,12 +55,47 @@ const decodeFloat = (value, encoding = "f64", byteOffset) => {
|
|
|
55
55
|
default: throw new Error(`${encoding} encoding not supported`);
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
const formatFloat = (value, formatting) => {
|
|
59
|
+
if (formatting) {
|
|
60
|
+
const nformat = JSON.parse(`{${formatting}}`);
|
|
61
|
+
if (typeof nformat === "object") {
|
|
62
|
+
return new Intl.NumberFormat(undefined, {
|
|
63
|
+
minimumIntegerDigits: nformat?.min_integer_digits,
|
|
64
|
+
minimumFractionDigits: nformat?.min_fraction_digits,
|
|
65
|
+
maximumFractionDigits: nformat?.max_fraction_digits,
|
|
66
|
+
minimumSignificantDigits: nformat?.min_significant_digits,
|
|
67
|
+
maximumSignificantDigits: nformat?.max_significant_digits,
|
|
68
|
+
notation: nformat?.notation,
|
|
69
|
+
}).format(value);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return Number.isInteger(value)
|
|
73
|
+
? `${value.toString()}.0`
|
|
74
|
+
: value.toString();
|
|
75
|
+
};
|
|
76
|
+
exports.formatFloat = formatFloat;
|
|
77
|
+
const formatLiteralFloat = (value) => {
|
|
78
|
+
const str = value.toString();
|
|
79
|
+
return Number.isInteger(value) && !str.includes("e")
|
|
80
|
+
? `${str}.0`
|
|
81
|
+
: str;
|
|
82
|
+
};
|
|
83
|
+
exports.formatLiteralFloat = formatLiteralFloat;
|
|
84
|
+
const typeAggregator = Type_js_1.Type.functionType([[Type_js_1.Type.Float, [Type_js_1.Type.arrayType(Type_js_1.Type.Number)], true]]);
|
|
85
|
+
const typeTransform = Type_js_1.Type.functionType([[Type_js_1.Type.Float, [Type_js_1.Type.Number]]]);
|
|
86
|
+
const funcSum = new Constant_js_1.Constant((...values) => values.reduce((acc, val) => acc + Number(val), 0), typeAggregator);
|
|
87
|
+
const funcMin = new Constant_js_1.Constant((...values) => {
|
|
88
|
+
if (values.length === 0) {
|
|
89
|
+
throw new Error("function requires at least one argument");
|
|
90
|
+
}
|
|
91
|
+
return Math.min(Number.POSITIVE_INFINITY, ...values.map((i) => Number(i)));
|
|
92
|
+
}, typeAggregator);
|
|
93
|
+
const funcMax = new Constant_js_1.Constant((...values) => {
|
|
94
|
+
if (values.length === 0) {
|
|
95
|
+
throw new Error("function requires at least one argument");
|
|
96
|
+
}
|
|
97
|
+
return Math.max(Number.NEGATIVE_INFINITY, ...values.map((i) => Number(i)));
|
|
98
|
+
}, typeAggregator);
|
|
64
99
|
const funcExponent = new Constant_js_1.Constant((value) => Math.exp(Number(value)), typeTransform);
|
|
65
100
|
const funcLogarithm = new Constant_js_1.Constant((value) => Math.log(Number(value)), typeTransform);
|
|
66
101
|
const funcAbs = new Constant_js_1.Constant((value) => Math.abs(Number(value)), typeTransform);
|
|
@@ -68,11 +103,15 @@ const funcCeil = new Constant_js_1.Constant((value) => Math.ceil(Number(value)),
|
|
|
68
103
|
const funcFloor = new Constant_js_1.Constant((value) => Math.floor(Number(value)), typeTransform);
|
|
69
104
|
const funcRound = new Constant_js_1.Constant((value) => Math.round(Number(value)), typeTransform);
|
|
70
105
|
const funcTruncate = new Constant_js_1.Constant((value) => Math.trunc(Number(value)), typeTransform);
|
|
71
|
-
const funcRandomFloat = new Constant_js_1.Constant((value) => value == null ? undefined : Math.random() * Number(value),
|
|
72
|
-
const funcDecodeFloat = new Constant_js_1.Constant((value, encoding = "f64", byteOffset) => decodeFloat(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type_js_1.Type.functionType(Type_js_1.Type.OptionalFloat, [Type_js_1.Type.OptionalBuffer, Type_js_1.Type.OptionalString, Type_js_1.Type.OptionalInteger]));
|
|
73
|
-
const funcParseFloat = new Constant_js_1.Constant((value) => value ? Number.parseFloat(value) : undefined, Type_js_1.Type.functionType(Type_js_1.Type.OptionalFloat, [Type_js_1.Type.OptionalString]));
|
|
74
|
-
exports.funcFloat = new Constant_js_1.Constant((value) => Number(value), Type_js_1.Type.
|
|
75
|
-
|
|
106
|
+
const funcRandomFloat = new Constant_js_1.Constant((value) => value == null ? undefined : Math.random() * Number(value), Type_js_1.Type.functionType([[Type_js_1.Type.Float, [Type_js_1.Type.Number]]], true));
|
|
107
|
+
const funcDecodeFloat = new Constant_js_1.Constant((value, encoding = "f64", byteOffset) => decodeFloat(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type_js_1.Type.functionType([[Type_js_1.Type.OptionalFloat, [Type_js_1.Type.OptionalBuffer, Type_js_1.Type.OptionalString, Type_js_1.Type.OptionalInteger]]]));
|
|
108
|
+
const funcParseFloat = new Constant_js_1.Constant((value) => value ? Number.parseFloat(value) : undefined, Type_js_1.Type.functionType([[Type_js_1.Type.OptionalFloat, [Type_js_1.Type.OptionalString]]]));
|
|
109
|
+
exports.funcFloat = new Constant_js_1.Constant((value) => Number(value), Type_js_1.Type.functionType([
|
|
110
|
+
[Type_js_1.Type.Float, [Type_js_1.Type.Boolean]],
|
|
111
|
+
[Type_js_1.Type.Float, [Type_js_1.Type.Timestamp]],
|
|
112
|
+
[Type_js_1.Type.Float, [Type_js_1.Type.Integer]],
|
|
113
|
+
]));
|
|
114
|
+
exports.globFloat = Object.assign(Object.create(null), {
|
|
76
115
|
NAN: new Constant_js_1.Constant(Number.NaN),
|
|
77
116
|
PositiveInfinity: new Constant_js_1.Constant(Number.POSITIVE_INFINITY),
|
|
78
117
|
NegativeInfinity: new Constant_js_1.Constant(Number.NEGATIVE_INFINITY),
|
|
@@ -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;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.globInteger = exports.funcInteger = exports.formatLiteralInteger = exports.formatInteger = exports.encodeInteger = exports.createInteger = exports.int64 = void 0;
|
|
4
4
|
const Constant_js_1 = require("../Constant.js");
|
|
5
5
|
const Type_js_1 = require("../Type.js");
|
|
6
|
-
const
|
|
7
|
-
exports.
|
|
6
|
+
const int64 = (value) => BigInt.asIntN(64, value);
|
|
7
|
+
exports.int64 = int64;
|
|
8
8
|
const createInteger = (value) => {
|
|
9
9
|
if (value == null || Number.isNaN(value)) {
|
|
10
10
|
return undefined;
|
|
@@ -15,7 +15,7 @@ const createInteger = (value) => {
|
|
|
15
15
|
if (value === Number.POSITIVE_INFINITY) {
|
|
16
16
|
return 0x7fffffffffffffffn;
|
|
17
17
|
}
|
|
18
|
-
return (0, exports.
|
|
18
|
+
return (0, exports.int64)(BigInt(Math.trunc(value)));
|
|
19
19
|
};
|
|
20
20
|
exports.createInteger = createInteger;
|
|
21
21
|
const encodeInteger = (value, encoding = "i64") => {
|
|
@@ -29,34 +29,34 @@ const encodeInteger = (value, encoding = "i64") => {
|
|
|
29
29
|
const dv = new DataView(new Uint8Array(Number.parseInt(bits) / 8).buffer);
|
|
30
30
|
switch (encoding) {
|
|
31
31
|
case "i8":
|
|
32
|
-
dv.setInt8(0, Number(value));
|
|
32
|
+
dv.setInt8(0, Number(BigInt.asIntN(8, value)));
|
|
33
33
|
break;
|
|
34
34
|
case "i16":
|
|
35
|
-
dv.setInt16(0, Number(value));
|
|
35
|
+
dv.setInt16(0, Number(BigInt.asIntN(16, value)));
|
|
36
36
|
break;
|
|
37
37
|
case "i16le":
|
|
38
|
-
dv.setInt16(0, Number(value), true);
|
|
38
|
+
dv.setInt16(0, Number(BigInt.asIntN(16, value)), true);
|
|
39
39
|
break;
|
|
40
40
|
case "i32":
|
|
41
|
-
dv.setInt32(0, Number(value));
|
|
41
|
+
dv.setInt32(0, Number(BigInt.asIntN(32, value)));
|
|
42
42
|
break;
|
|
43
43
|
case "i32le":
|
|
44
|
-
dv.setInt32(0, Number(value), true);
|
|
44
|
+
dv.setInt32(0, Number(BigInt.asIntN(32, value)), true);
|
|
45
45
|
break;
|
|
46
46
|
case "n8":
|
|
47
|
-
dv.setUint8(0, Number(value));
|
|
47
|
+
dv.setUint8(0, Number(BigInt.asUintN(8, value)));
|
|
48
48
|
break;
|
|
49
49
|
case "n16":
|
|
50
|
-
dv.setUint16(0, Number(value));
|
|
50
|
+
dv.setUint16(0, Number(BigInt.asUintN(16, value)));
|
|
51
51
|
break;
|
|
52
52
|
case "n16le":
|
|
53
|
-
dv.setUint16(0, Number(value), true);
|
|
53
|
+
dv.setUint16(0, Number(BigInt.asUintN(16, value)), true);
|
|
54
54
|
break;
|
|
55
55
|
case "n32":
|
|
56
|
-
dv.setUint32(0, Number(value));
|
|
56
|
+
dv.setUint32(0, Number(BigInt.asUintN(32, value)));
|
|
57
57
|
break;
|
|
58
58
|
case "n32le":
|
|
59
|
-
dv.setUint32(0, Number(value), true);
|
|
59
|
+
dv.setUint32(0, Number(BigInt.asUintN(32, value)), true);
|
|
60
60
|
break;
|
|
61
61
|
case "i64":
|
|
62
62
|
dv.setBigInt64(0, value);
|
|
@@ -118,22 +118,57 @@ const decodeInteger = (value, encoding = "i64", byteOffset) => {
|
|
|
118
118
|
default: throw new Error(`${encoding} encoding not supported`);
|
|
119
119
|
}
|
|
120
120
|
};
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
const formatInteger = (value, formatting) => {
|
|
122
|
+
const int = (0, exports.int64)(value);
|
|
123
|
+
if (formatting) {
|
|
124
|
+
const nformat = JSON.parse(`{${formatting}}`);
|
|
125
|
+
if (typeof nformat === "object") {
|
|
126
|
+
return new Intl.NumberFormat(undefined, {
|
|
127
|
+
minimumIntegerDigits: nformat?.min_integer_digits,
|
|
128
|
+
minimumFractionDigits: nformat?.min_fraction_digits,
|
|
129
|
+
maximumFractionDigits: nformat?.max_fraction_digits,
|
|
130
|
+
minimumSignificantDigits: nformat?.min_significant_digits,
|
|
131
|
+
maximumSignificantDigits: nformat?.max_significant_digits,
|
|
132
|
+
notation: nformat?.notation,
|
|
133
|
+
}).format(int);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return int.toString();
|
|
137
|
+
};
|
|
138
|
+
exports.formatInteger = formatInteger;
|
|
139
|
+
const formatLiteralInteger = (value) => {
|
|
140
|
+
return (0, exports.int64)(value).toString();
|
|
141
|
+
};
|
|
142
|
+
exports.formatLiteralInteger = formatLiteralInteger;
|
|
143
|
+
const typeAggregator = Type_js_1.Type.functionType([[Type_js_1.Type.Integer, [Type_js_1.Type.arrayType(Type_js_1.Type.Integer)], true]]);
|
|
144
|
+
const funcSum = new Constant_js_1.Constant((...values) => (0, exports.int64)(values.reduce((acc, val) => acc + val, 0n)), typeAggregator);
|
|
145
|
+
const funcMin = new Constant_js_1.Constant((...values) => {
|
|
146
|
+
if (values.length === 0) {
|
|
147
|
+
throw new Error("function requires at least one argument");
|
|
148
|
+
}
|
|
149
|
+
return values.reduce((min, val) => val < min ? val : min);
|
|
150
|
+
}, typeAggregator);
|
|
151
|
+
const funcMax = new Constant_js_1.Constant((...values) => {
|
|
152
|
+
if (values.length === 0) {
|
|
153
|
+
throw new Error("function requires at least one argument");
|
|
154
|
+
}
|
|
155
|
+
return values.reduce((max, val) => val > max ? val : max);
|
|
156
|
+
}, typeAggregator);
|
|
157
|
+
const funcRandomInteger = new Constant_js_1.Constant((value) => value == null ? undefined : BigInt(Math.floor(Math.random() * Number(value))), Type_js_1.Type.functionType([[Type_js_1.Type.Integer, [Type_js_1.Type.Integer]]], true));
|
|
158
|
+
const funcDecodeInteger = new Constant_js_1.Constant((value, encoding = "i64", byteOffset) => decodeInteger(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type_js_1.Type.functionType([[Type_js_1.Type.OptionalInteger, [Type_js_1.Type.OptionalBuffer, Type_js_1.Type.OptionalString, Type_js_1.Type.OptionalInteger]]]));
|
|
128
159
|
const funcParseInteger = new Constant_js_1.Constant((value) => {
|
|
129
160
|
try {
|
|
130
|
-
return value ? (0, exports.
|
|
161
|
+
return value ? (0, exports.int64)(BigInt(value)) : undefined;
|
|
131
162
|
}
|
|
132
163
|
catch { }
|
|
133
164
|
return undefined;
|
|
134
|
-
}, Type_js_1.Type.functionType(Type_js_1.Type.OptionalInteger, [Type_js_1.Type.OptionalString]));
|
|
135
|
-
exports.funcInteger = new Constant_js_1.Constant((value) => (0, exports.createInteger)(Number(value)) ?? 0n, Type_js_1.Type.
|
|
136
|
-
|
|
165
|
+
}, Type_js_1.Type.functionType([[Type_js_1.Type.OptionalInteger, [Type_js_1.Type.OptionalString]]]));
|
|
166
|
+
exports.funcInteger = new Constant_js_1.Constant((value) => (0, exports.createInteger)(Number(value)) ?? 0n, Type_js_1.Type.functionType([
|
|
167
|
+
[Type_js_1.Type.Integer, [Type_js_1.Type.Boolean]],
|
|
168
|
+
[Type_js_1.Type.Integer, [Type_js_1.Type.Timestamp]],
|
|
169
|
+
[Type_js_1.Type.Integer, [Type_js_1.Type.Float]],
|
|
170
|
+
]));
|
|
171
|
+
exports.globInteger = Object.assign(Object.create(null), {
|
|
137
172
|
Sum: funcSum,
|
|
138
173
|
Min: funcMin,
|
|
139
174
|
Max: funcMax,
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.funcContains = exports.funcLength = void 0;
|
|
4
4
|
const Constant_js_1 = require("../Constant.js");
|
|
5
5
|
const Type_js_1 = require("../Type.js");
|
|
6
6
|
const Buffer_js_1 = require("./Buffer.js");
|
|
7
7
|
const String_js_1 = require("./String.js");
|
|
8
|
-
|
|
9
|
-
exports.funcLength = new Constant_js_1.Constant((value) => (0, Integer_js_1.boundInteger)(BigInt(value == null
|
|
8
|
+
exports.funcLength = new Constant_js_1.Constant((value) => BigInt(value == null
|
|
10
9
|
? 0
|
|
11
10
|
: value instanceof ArrayBuffer
|
|
12
11
|
? value.byteLength
|
|
13
12
|
: typeof value === "string" || Array.isArray(value)
|
|
14
13
|
? value.length
|
|
15
|
-
: Object.keys(value).length)
|
|
14
|
+
: Object.keys(value).length), Type_js_1.Type.functionType([[Type_js_1.Type.Integer, [Type_js_1.Type.OptionalIterable]]]));
|
|
16
15
|
exports.funcContains = new Constant_js_1.Constant((value, search, start, ignoreCaseSpaceEtc) => value == null
|
|
17
16
|
? false
|
|
18
17
|
: value instanceof ArrayBuffer
|
|
@@ -21,27 +20,9 @@ exports.funcContains = new Constant_js_1.Constant((value, search, start, ignoreC
|
|
|
21
20
|
? (0, String_js_1.containsString)(value, search, start == null ? undefined : Number(start), ignoreCaseSpaceEtc)
|
|
22
21
|
: Array.isArray(value)
|
|
23
22
|
? value.includes(search, start == null ? undefined : Number(start))
|
|
24
|
-
: Object.values(value).includes(search), Type_js_1.Type.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const num = Number(index);
|
|
31
|
-
const ix = num < 0 ? value.length + num : num;
|
|
32
|
-
return ix >= 0 && ix < value.length ? value[ix] : undefined;
|
|
33
|
-
}
|
|
34
|
-
const key = String(index);
|
|
35
|
-
return Object.hasOwn(value, key) ? value[key] : undefined;
|
|
36
|
-
}, Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Unknown, [Type_js_1.Type.Array, Type_js_1.Type.Integer]), Type_js_1.Type.functionType(Type_js_1.Type.Unknown, [Type_js_1.Type.Object, Type_js_1.Type.String])));
|
|
37
|
-
exports.funcHas = new Constant_js_1.Constant((value, index) => {
|
|
38
|
-
if (value == null) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
else if (Array.isArray(value)) {
|
|
42
|
-
const num = Number(index);
|
|
43
|
-
const ix = num < 0 ? value.length + num : num;
|
|
44
|
-
return ix >= 0 && ix < value.length;
|
|
45
|
-
}
|
|
46
|
-
return Object.hasOwn(value, String(index));
|
|
47
|
-
}, Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Array, Type_js_1.Type.Integer]), Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Object, Type_js_1.Type.String])));
|
|
23
|
+
: Object.values(value).includes(search), Type_js_1.Type.functionType([
|
|
24
|
+
[Type_js_1.Type.Boolean, [Type_js_1.Type.Buffer, Type_js_1.Type.Buffer, Type_js_1.Type.OptionalInteger]],
|
|
25
|
+
[Type_js_1.Type.Boolean, [Type_js_1.Type.String, Type_js_1.Type.String, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalBoolean]],
|
|
26
|
+
[Type_js_1.Type.Boolean, [Type_js_1.Type.Array, Type_js_1.Type.Any, Type_js_1.Type.OptionalInteger]],
|
|
27
|
+
[Type_js_1.Type.Boolean, [Type_js_1.Type.Object, Type_js_1.Type.Any]],
|
|
28
|
+
]));
|
|
@@ -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;
|
package/dst/cjs/native/Number.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.funcNegate = exports.funcRoot = exports.funcPower = exports.funcModulo = exports.funcRemainder = exports.funcDivide = exports.funcMultiply = exports.funcSubtract = exports.funcLessOrEqual = exports.funcGreaterOrEqual = exports.funcLessThan = exports.funcGreaterThan = exports.
|
|
3
|
+
exports.funcNegate = exports.funcRoot = exports.funcPower = exports.funcModulo = exports.funcRemainder = exports.funcDivide = exports.funcMultiply = exports.funcSubtract = exports.funcLessOrEqual = exports.funcGreaterOrEqual = exports.funcLessThan = exports.funcGreaterThan = exports.parseLiteralNumber = exports.isNumericSymbol = exports.isSignSymbol = void 0;
|
|
4
4
|
const Constant_js_1 = require("../Constant.js");
|
|
5
5
|
const Type_js_1 = require("../Type.js");
|
|
6
6
|
const Integer_js_1 = require("./Integer.js");
|
|
@@ -8,13 +8,6 @@ const isSignSymbol = (c) => c === "+" || c === "-";
|
|
|
8
8
|
exports.isSignSymbol = isSignSymbol;
|
|
9
9
|
const isNumericSymbol = (c) => c >= "0" && c <= "9";
|
|
10
10
|
exports.isNumericSymbol = isNumericSymbol;
|
|
11
|
-
const formatLiteralNumber = (value) => {
|
|
12
|
-
const str = value.toString();
|
|
13
|
-
return typeof value === "number" && Number.isInteger(value) && !str.includes("e")
|
|
14
|
-
? `${str}.0`
|
|
15
|
-
: str;
|
|
16
|
-
};
|
|
17
|
-
exports.formatLiteralNumber = formatLiteralNumber;
|
|
18
11
|
const parseLiteralNumber = (value, offset = 0) => {
|
|
19
12
|
let i = offset;
|
|
20
13
|
let integer = true;
|
|
@@ -36,8 +29,8 @@ const parseLiteralNumber = (value, offset = 0) => {
|
|
|
36
29
|
}
|
|
37
30
|
if (value.charAt(i) === "e") {
|
|
38
31
|
++i;
|
|
39
|
-
if ((0, exports.isNumericSymbol)(value.charAt(i))
|
|
40
|
-
|
|
32
|
+
if ((0, exports.isNumericSymbol)(value.charAt(i)) ||
|
|
33
|
+
(0, exports.isSignSymbol)(value.charAt(i))) {
|
|
41
34
|
++i;
|
|
42
35
|
while ((0, exports.isNumericSymbol)(value.charAt(i))) {
|
|
43
36
|
++i;
|
|
@@ -46,71 +39,55 @@ const parseLiteralNumber = (value, offset = 0) => {
|
|
|
46
39
|
integer = false;
|
|
47
40
|
}
|
|
48
41
|
const str = value.slice(offset, i);
|
|
49
|
-
return [integer ? (0, Integer_js_1.
|
|
42
|
+
return [integer ? (0, Integer_js_1.int64)(BigInt(str)) : parseFloat(str), i];
|
|
50
43
|
};
|
|
51
44
|
exports.parseLiteralNumber = parseLiteralNumber;
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
maximumFractionDigits: nformat?.max_fraction_digits,
|
|
60
|
-
minimumSignificantDigits: nformat?.min_significant_digits,
|
|
61
|
-
maximumSignificantDigits: nformat?.max_significant_digits,
|
|
62
|
-
notation: nformat?.notation,
|
|
63
|
-
}).format(value);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return typeof value === "number" && Number.isInteger(value)
|
|
67
|
-
? `${value.toString()}.0`
|
|
68
|
-
: value.toString();
|
|
69
|
-
};
|
|
70
|
-
exports.formatNumber = formatNumber;
|
|
71
|
-
const typeComparator = Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Number, Type_js_1.Type.Number]);
|
|
72
|
-
const typeOperator = Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float, Type_js_1.Type.Float]), Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float, Type_js_1.Type.Integer]), Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Integer, Type_js_1.Type.Float]), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Integer, Type_js_1.Type.Integer]));
|
|
45
|
+
const typeComparator = Type_js_1.Type.functionType([[Type_js_1.Type.Boolean, [Type_js_1.Type.Number, Type_js_1.Type.Number]]]);
|
|
46
|
+
const typeOperator = Type_js_1.Type.functionType([
|
|
47
|
+
[Type_js_1.Type.Integer, [Type_js_1.Type.Integer, Type_js_1.Type.Integer]],
|
|
48
|
+
[Type_js_1.Type.Float, [Type_js_1.Type.Float, Type_js_1.Type.Number]],
|
|
49
|
+
[Type_js_1.Type.Float, [Type_js_1.Type.Number, Type_js_1.Type.Float]],
|
|
50
|
+
[Type_js_1.Type.Number, [Type_js_1.Type.Number, Type_js_1.Type.Number]],
|
|
51
|
+
]);
|
|
73
52
|
exports.funcGreaterThan = new Constant_js_1.Constant((value1, value2) => value1 > value2, typeComparator);
|
|
74
53
|
exports.funcLessThan = new Constant_js_1.Constant((value1, value2) => value1 < value2, typeComparator);
|
|
75
54
|
exports.funcGreaterOrEqual = new Constant_js_1.Constant((value1, value2) => value1 >= value2, typeComparator);
|
|
76
55
|
exports.funcLessOrEqual = new Constant_js_1.Constant((value1, value2) => value1 <= value2, typeComparator);
|
|
77
56
|
exports.funcSubtract = new Constant_js_1.Constant((value, subtrahend) => typeof value === "bigint" && typeof subtrahend === "bigint"
|
|
78
|
-
? (0, Integer_js_1.
|
|
57
|
+
? (0, Integer_js_1.int64)(value - subtrahend)
|
|
79
58
|
: Number(value) - Number(subtrahend), typeOperator);
|
|
80
59
|
exports.funcMultiply = new Constant_js_1.Constant((value1, value2) => typeof value1 === "bigint" && typeof value2 === "bigint"
|
|
81
|
-
? (0, Integer_js_1.
|
|
60
|
+
? (0, Integer_js_1.int64)(value1 * value2)
|
|
82
61
|
: Number(value1) * Number(value2), typeOperator);
|
|
83
62
|
exports.funcDivide = new Constant_js_1.Constant((value, divisor) => typeof value === "bigint" && typeof divisor === "bigint"
|
|
84
|
-
? (0, Integer_js_1.
|
|
63
|
+
? (0, Integer_js_1.int64)(value / divisor)
|
|
85
64
|
: Number(value) / Number(divisor), typeOperator);
|
|
86
65
|
exports.funcRemainder = new Constant_js_1.Constant((value, divisor) => typeof value === "bigint" && typeof divisor === "bigint"
|
|
87
|
-
?
|
|
66
|
+
? value % divisor
|
|
88
67
|
: Number(value) % Number(divisor), typeOperator);
|
|
89
68
|
exports.funcModulo = new Constant_js_1.Constant((value, divisor) => typeof value === "bigint" && typeof divisor === "bigint"
|
|
90
|
-
? (
|
|
69
|
+
? (value % divisor + divisor) % divisor
|
|
91
70
|
: (Number(value) % Number(divisor) + Number(divisor)) % Number(divisor), typeOperator);
|
|
92
71
|
exports.funcPower = new Constant_js_1.Constant((value, exponent) => typeof value === "bigint" && typeof exponent === "bigint"
|
|
93
|
-
? (0, Integer_js_1.
|
|
72
|
+
? (0, Integer_js_1.int64)(value ** exponent)
|
|
94
73
|
: Number(value) ** Number(exponent), typeOperator);
|
|
95
74
|
exports.funcRoot = new Constant_js_1.Constant((value, exponent) => {
|
|
96
75
|
if (exponent <= 0) {
|
|
97
76
|
return undefined;
|
|
98
77
|
}
|
|
99
78
|
if (typeof value === "bigint" && typeof exponent === "bigint") {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const negative = v < 0n;
|
|
103
|
-
if (negative && e % 2n === 0n) {
|
|
79
|
+
const negative = value < 0n;
|
|
80
|
+
if (negative && exponent % 2n === 0n) {
|
|
104
81
|
return undefined;
|
|
105
82
|
}
|
|
106
|
-
const magnitude = negative ? -
|
|
107
|
-
if (magnitude <= 1n ||
|
|
108
|
-
return
|
|
83
|
+
const magnitude = negative ? -value : value;
|
|
84
|
+
if (magnitude <= 1n || exponent === 1n) {
|
|
85
|
+
return value;
|
|
109
86
|
}
|
|
110
87
|
let low = 0n, high = magnitude, result = 0n;
|
|
111
88
|
while (low <= high) {
|
|
112
89
|
const mid = low + high >> 1n;
|
|
113
|
-
const midPow = mid **
|
|
90
|
+
const midPow = mid ** exponent;
|
|
114
91
|
if (midPow === magnitude) {
|
|
115
92
|
return negative ? -mid : mid;
|
|
116
93
|
}
|
|
@@ -132,5 +109,14 @@ exports.funcRoot = new Constant_js_1.Constant((value, exponent) => {
|
|
|
132
109
|
return (v < 0 || Object.is(v, -0)) && odd
|
|
133
110
|
? -Math.pow(-v, 1 / e)
|
|
134
111
|
: Math.pow(v, 1 / e);
|
|
135
|
-
},
|
|
136
|
-
|
|
112
|
+
}, Type_js_1.Type.functionType([
|
|
113
|
+
[Type_js_1.Type.OptionalInteger, [Type_js_1.Type.Integer, Type_js_1.Type.Integer]],
|
|
114
|
+
[Type_js_1.Type.OptionalFloat, [Type_js_1.Type.Float, Type_js_1.Type.Number]],
|
|
115
|
+
[Type_js_1.Type.OptionalFloat, [Type_js_1.Type.Number, Type_js_1.Type.Float]],
|
|
116
|
+
[Type_js_1.Type.OptionalNumber, [Type_js_1.Type.Number, Type_js_1.Type.Number]],
|
|
117
|
+
]));
|
|
118
|
+
exports.funcNegate = new Constant_js_1.Constant((value) => value == null ? undefined : typeof value === "number" ? -value : (0, Integer_js_1.int64)(-value), Type_js_1.Type.functionType([
|
|
119
|
+
[Type_js_1.Type.Float, [Type_js_1.Type.Float]],
|
|
120
|
+
[Type_js_1.Type.Integer, [Type_js_1.Type.Integer]],
|
|
121
|
+
[Type_js_1.Type.Number, [Type_js_1.Type.Number]],
|
|
122
|
+
]));
|
package/dst/cjs/native/Object.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.globObject = exports.funcValues = exports.funcKeys = exports.funcEntries = void 0;
|
|
4
4
|
const Constant_js_1 = require("../Constant.js");
|
|
5
5
|
const Type_js_1 = require("../Type.js");
|
|
6
|
-
const typeAccessor = Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Object]);
|
|
7
|
-
const typeObjectOrArray = Type_js_1.Type.union(Type_js_1.Type.Object, Type_js_1.Type.arrayType([Type_js_1.Type.Object]));
|
|
6
|
+
const typeAccessor = Type_js_1.Type.functionType([[Type_js_1.Type.Array, [Type_js_1.Type.Object]]]);
|
|
8
7
|
exports.funcEntries = new Constant_js_1.Constant((value) => value ? Object.entries(value) : undefined, typeAccessor);
|
|
9
|
-
exports.funcKeys = new Constant_js_1.Constant((value) => value ? Object.keys(value) : undefined, Type_js_1.Type.functionType(Type_js_1.Type.arrayType(
|
|
8
|
+
exports.funcKeys = new Constant_js_1.Constant((value) => value ? Object.keys(value) : undefined, Type_js_1.Type.functionType([[Type_js_1.Type.arrayType(Type_js_1.Type.String), [Type_js_1.Type.Object]]]));
|
|
10
9
|
exports.funcValues = new Constant_js_1.Constant((value) => value ? Object.values(value) : undefined, typeAccessor);
|
|
11
|
-
const funcMerge = new Constant_js_1.Constant((values) => values.
|
|
12
|
-
exports.
|
|
10
|
+
const funcMerge = new Constant_js_1.Constant((...values) => values.reduce((acc, val) => Object.assign(acc, val), Object.create(null)), Type_js_1.Type.functionType([[Type_js_1.Type.Object, [Type_js_1.Type.arrayType(Type_js_1.Type.Object)], true]]));
|
|
11
|
+
exports.globObject = Object.assign(Object.create(null), {
|
|
13
12
|
Merge: funcMerge,
|
|
14
13
|
});
|
|
@@ -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/cjs/native/String.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.globString = exports.funcReplaceWith = exports.funcSplit = exports.funcUpperCase = exports.funcLowerCase = exports.funcTrimEnd = exports.funcTrimStart = exports.funcTrim = exports.funcCharCodeAt = exports.funcCharAt = exports.funcEndsWith = exports.funcStartsWith = exports.funcNotLike = exports.funcLike = exports.encodeString = exports.endsWithString = exports.startsWithString = exports.containsString = exports.equateStrings = exports.replaceWith = exports.parseLiteralString = exports.formatLiteralString = exports.isWhiteSpaceSymbol = exports.isHexadecimalSymbol = exports.isIdentifierSymbol = exports.isIdentifierStartSymbol = exports.isAlphanumericSymbol = void 0;
|
|
4
4
|
const Constant_js_1 = require("../Constant.js");
|
|
5
5
|
const Type_js_1 = require("../Type.js");
|
|
6
6
|
const Integer_js_1 = require("./Integer.js");
|
|
7
|
-
const isAlphanumericSymbol = (c) => c >= "a" && c <= "z" || c >= "0" && c <= "9";
|
|
7
|
+
const isAlphanumericSymbol = (c) => c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c >= "0" && c <= "9";
|
|
8
8
|
exports.isAlphanumericSymbol = isAlphanumericSymbol;
|
|
9
|
-
const
|
|
10
|
-
exports.
|
|
11
|
-
const
|
|
12
|
-
exports.
|
|
9
|
+
const isIdentifierStartSymbol = (c) => c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c === "_" || c === "$";
|
|
10
|
+
exports.isIdentifierStartSymbol = isIdentifierStartSymbol;
|
|
11
|
+
const isIdentifierSymbol = (c) => (0, exports.isIdentifierStartSymbol)(c) || c >= "0" && c <= "9";
|
|
12
|
+
exports.isIdentifierSymbol = isIdentifierSymbol;
|
|
13
13
|
const isHexadecimalSymbol = (c) => c >= "0" && c <= "9" || c >= "a" && c <= "f" || c >= "A" && c <= "F";
|
|
14
14
|
exports.isHexadecimalSymbol = isHexadecimalSymbol;
|
|
15
|
+
const isWhiteSpaceSymbol = (c) => c === " " || c === "\t" || c === "\n" || c === "\r" || c === "\v" || c === "\f";
|
|
16
|
+
exports.isWhiteSpaceSymbol = isWhiteSpaceSymbol;
|
|
15
17
|
const formatLiteralString = (value) => {
|
|
16
18
|
let str = "\"";
|
|
17
19
|
for (let i = 0; i < value.length; ++i) {
|
|
@@ -306,36 +308,35 @@ const decodeString = (value, encoding = "utf8", byteOffset, byteLength) => {
|
|
|
306
308
|
}
|
|
307
309
|
return str;
|
|
308
310
|
};
|
|
309
|
-
const typeStringEquator = Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.String, Type_js_1.Type.String]);
|
|
310
|
-
const typeStringComparator = Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.String, Type_js_1.Type.String, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalBoolean]);
|
|
311
|
-
const typeStringMutator = Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.String]);
|
|
312
|
-
const typeStringOrArray = Type_js_1.Type.union(Type_js_1.Type.String, Type_js_1.Type.arrayType([Type_js_1.Type.String]));
|
|
311
|
+
const typeStringEquator = Type_js_1.Type.functionType([[Type_js_1.Type.Boolean, [Type_js_1.Type.String, Type_js_1.Type.String]]]);
|
|
312
|
+
const typeStringComparator = Type_js_1.Type.functionType([[Type_js_1.Type.Boolean, [Type_js_1.Type.String, Type_js_1.Type.String, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalBoolean]]]);
|
|
313
|
+
const typeStringMutator = Type_js_1.Type.functionType([[Type_js_1.Type.String, [Type_js_1.Type.String]]]);
|
|
313
314
|
exports.funcLike = new Constant_js_1.Constant((value1, value2) => (0, exports.equateStrings)(value1, value2, true), typeStringEquator);
|
|
314
|
-
exports.
|
|
315
|
+
exports.funcNotLike = new Constant_js_1.Constant((value1, value2) => !(0, exports.equateStrings)(value1, value2, true), typeStringEquator);
|
|
315
316
|
exports.funcStartsWith = new Constant_js_1.Constant((value, search, start, ignoreCaseSpaceEtc) => (0, exports.startsWithString)(value, search, start == null ? undefined : Number(start), ignoreCaseSpaceEtc), typeStringComparator);
|
|
316
317
|
exports.funcEndsWith = new Constant_js_1.Constant((value, search, end, ignoreCaseSpaceEtc) => (0, exports.endsWithString)(value, search, end == null ? undefined : Number(end), ignoreCaseSpaceEtc), typeStringComparator);
|
|
317
|
-
exports.
|
|
318
|
+
exports.funcCharAt = new Constant_js_1.Constant((value, pos) => value == null
|
|
318
319
|
? undefined
|
|
319
|
-
: value.charAt(pos < 0 ? value.length + Number(pos) : Number(pos)), Type_js_1.Type.functionType(Type_js_1.Type.OptionalString, [Type_js_1.Type.String, Type_js_1.Type.Integer]));
|
|
320
|
-
exports.
|
|
320
|
+
: value.charAt(pos < 0 ? value.length + Number(pos) : Number(pos)), Type_js_1.Type.functionType([[Type_js_1.Type.OptionalString, [Type_js_1.Type.String, Type_js_1.Type.Integer]]]));
|
|
321
|
+
exports.funcCharCodeAt = new Constant_js_1.Constant((value, pos) => value == null
|
|
321
322
|
? undefined
|
|
322
|
-
: (0, Integer_js_1.createInteger)(value.charCodeAt(pos < 0 ? value.length + Number(pos) : Number(pos))), Type_js_1.Type.functionType(Type_js_1.Type.OptionalInteger, [Type_js_1.Type.String, Type_js_1.Type.Integer]));
|
|
323
|
+
: (0, Integer_js_1.createInteger)(value.charCodeAt(pos < 0 ? value.length + Number(pos) : Number(pos))), Type_js_1.Type.functionType([[Type_js_1.Type.OptionalInteger, [Type_js_1.Type.String, Type_js_1.Type.Integer]]]));
|
|
323
324
|
exports.funcTrim = new Constant_js_1.Constant((value) => value?.trim(), typeStringMutator);
|
|
324
325
|
exports.funcTrimStart = new Constant_js_1.Constant((value) => value?.trimStart(), typeStringMutator);
|
|
325
326
|
exports.funcTrimEnd = new Constant_js_1.Constant((value) => value?.trimEnd(), typeStringMutator);
|
|
326
327
|
exports.funcLowerCase = new Constant_js_1.Constant((value) => value?.toLowerCase(), typeStringMutator);
|
|
327
328
|
exports.funcUpperCase = new Constant_js_1.Constant((value) => value?.toUpperCase(), typeStringMutator);
|
|
328
|
-
exports.funcSplit = new Constant_js_1.Constant((value, separator = " ") => value?.split(separator) ?? [], Type_js_1.Type.functionType(Type_js_1.Type.arrayType(
|
|
329
|
-
exports.funcReplaceWith = new Constant_js_1.Constant((value, replacement, search) => (0, exports.replaceWith)(value, replacement, ...search
|
|
330
|
-
const
|
|
331
|
-
if (
|
|
329
|
+
exports.funcSplit = new Constant_js_1.Constant((value, separator = " ") => value?.split(separator) ?? [], Type_js_1.Type.functionType([[Type_js_1.Type.arrayType(Type_js_1.Type.String), [Type_js_1.Type.String, Type_js_1.Type.OptionalString]]]));
|
|
330
|
+
exports.funcReplaceWith = new Constant_js_1.Constant((value, replacement, ...search) => (0, exports.replaceWith)(value, replacement, ...search), Type_js_1.Type.functionType([[Type_js_1.Type.String, [Type_js_1.Type.String, Type_js_1.Type.String, Type_js_1.Type.arrayType(Type_js_1.Type.String)], true]]));
|
|
331
|
+
const funcAlphanumeric = new Constant_js_1.Constant((value) => {
|
|
332
|
+
if (value == null) {
|
|
332
333
|
return undefined;
|
|
333
334
|
}
|
|
334
|
-
const str = value.toLowerCase();
|
|
335
335
|
let result = "";
|
|
336
|
-
for (let i = 0; i <
|
|
337
|
-
|
|
338
|
-
|
|
336
|
+
for (let i = 0; i < value.length; ++i) {
|
|
337
|
+
const c = value[i];
|
|
338
|
+
if ((0, exports.isAlphanumericSymbol)(c)) {
|
|
339
|
+
result += c.toLowerCase();
|
|
339
340
|
}
|
|
340
341
|
}
|
|
341
342
|
return result;
|
|
@@ -347,10 +348,10 @@ const funcRandomString = new Constant_js_1.Constant((value) => {
|
|
|
347
348
|
str += Math.random().toString(36).slice(2);
|
|
348
349
|
}
|
|
349
350
|
return str.slice(0, length);
|
|
350
|
-
}, Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Integer]
|
|
351
|
-
const funcDecodeString = new Constant_js_1.Constant((value, encoding = "utf8", byteOffset, byteLength) => decodeString(value, encoding, byteOffset == null ? undefined : Number(byteOffset), byteLength == null ? undefined : Number(byteLength)), Type_js_1.Type.functionType(Type_js_1.Type.OptionalString, [Type_js_1.Type.OptionalBuffer, Type_js_1.Type.OptionalString, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalInteger]));
|
|
352
|
-
exports.
|
|
353
|
-
|
|
351
|
+
}, Type_js_1.Type.functionType([[Type_js_1.Type.String, [Type_js_1.Type.Integer]]], true));
|
|
352
|
+
const funcDecodeString = new Constant_js_1.Constant((value, encoding = "utf8", byteOffset, byteLength) => decodeString(value, encoding, byteOffset == null ? undefined : Number(byteOffset), byteLength == null ? undefined : Number(byteLength)), Type_js_1.Type.functionType([[Type_js_1.Type.OptionalString, [Type_js_1.Type.OptionalBuffer, Type_js_1.Type.OptionalString, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalInteger]]]));
|
|
353
|
+
exports.globString = Object.assign(Object.create(null), {
|
|
354
|
+
Alphanumeric: funcAlphanumeric,
|
|
354
355
|
Random: funcRandomString,
|
|
355
356
|
Decode: funcDecodeString,
|
|
356
357
|
});
|