affinirum 1.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/LICENSE +661 -0
- package/README.md +301 -0
- package/dst/Affinirum.d.ts +73 -0
- package/dst/Affinirum.js +536 -0
- package/dst/Constant.d.ts +15 -0
- package/dst/Constant.js +26 -0
- package/dst/Constants.d.ts +2 -0
- package/dst/Constants.js +22 -0
- package/dst/Functions.d.ts +2 -0
- package/dst/Functions.js +85 -0
- package/dst/Keywords.d.ts +1 -0
- package/dst/Keywords.js +17 -0
- package/dst/Node.d.ts +13 -0
- package/dst/Node.js +22 -0
- package/dst/ParserFrame.d.ts +13 -0
- package/dst/ParserFrame.js +80 -0
- package/dst/ParserState.d.ts +54 -0
- package/dst/ParserState.js +562 -0
- package/dst/StaticScope.d.ts +13 -0
- package/dst/StaticScope.js +44 -0
- package/dst/Type.d.ts +72 -0
- package/dst/Type.js +196 -0
- package/dst/Value.d.ts +3 -0
- package/dst/Value.js +1 -0
- package/dst/Variable.d.ts +13 -0
- package/dst/Variable.js +25 -0
- package/dst/atom/ArrayAtom.d.ts +11 -0
- package/dst/atom/ArrayAtom.js +38 -0
- package/dst/atom/FunctionAtom.d.ts +17 -0
- package/dst/atom/FunctionAtom.js +54 -0
- package/dst/atom/ObjectAtom.d.ts +11 -0
- package/dst/atom/ObjectAtom.js +44 -0
- package/dst/atom/PrimitiveAtom.d.ts +8 -0
- package/dst/atom/PrimitiveAtom.js +26 -0
- package/dst/cjs/Affinirum.js +540 -0
- package/dst/cjs/Constant.js +30 -0
- package/dst/cjs/Constants.js +25 -0
- package/dst/cjs/Functions.js +88 -0
- package/dst/cjs/Keywords.js +20 -0
- package/dst/cjs/Node.js +26 -0
- package/dst/cjs/ParserFrame.js +84 -0
- package/dst/cjs/ParserState.js +566 -0
- package/dst/cjs/StaticScope.js +48 -0
- package/dst/cjs/Type.js +200 -0
- package/dst/cjs/Value.js +2 -0
- package/dst/cjs/Variable.js +29 -0
- package/dst/cjs/atom/ArrayAtom.js +42 -0
- package/dst/cjs/atom/FunctionAtom.js +58 -0
- package/dst/cjs/atom/ObjectAtom.js +48 -0
- package/dst/cjs/atom/PrimitiveAtom.js +30 -0
- package/dst/cjs/constant/Array.js +93 -0
- package/dst/cjs/constant/Boolean.js +25 -0
- package/dst/cjs/constant/Buffer.js +68 -0
- package/dst/cjs/constant/Enumerable.js +34 -0
- package/dst/cjs/constant/Float.js +85 -0
- package/dst/cjs/constant/Integer.js +104 -0
- package/dst/cjs/constant/Iterable.js +24 -0
- package/dst/cjs/constant/Number.js +59 -0
- package/dst/cjs/constant/Object.js +13 -0
- package/dst/cjs/constant/String.js +197 -0
- package/dst/cjs/constant/Timestamp.js +56 -0
- package/dst/cjs/constant/Unknown.js +101 -0
- package/dst/cjs/constant/notation/AN.js +46 -0
- package/dst/cjs/constant/notation/JSON.js +14 -0
- package/dst/cjs/index.js +19 -0
- package/dst/cjs/node/ArrayNode.js +34 -0
- package/dst/cjs/node/BlockNode.js +33 -0
- package/dst/cjs/node/CallNode.js +54 -0
- package/dst/cjs/node/ConstantNode.js +33 -0
- package/dst/cjs/node/LoopNode.js +34 -0
- package/dst/cjs/node/ObjectNode.js +42 -0
- package/dst/cjs/node/SwitchNode.js +45 -0
- package/dst/cjs/node/VariableNode.js +30 -0
- package/dst/cjs/package.json +3 -0
- package/dst/constant/Array.d.ts +22 -0
- package/dst/constant/Array.js +90 -0
- package/dst/constant/Boolean.d.ts +11 -0
- package/dst/constant/Boolean.js +22 -0
- package/dst/constant/Buffer.d.ts +10 -0
- package/dst/constant/Buffer.js +61 -0
- package/dst/constant/Enumerable.d.ts +5 -0
- package/dst/constant/Enumerable.js +31 -0
- package/dst/constant/Float.d.ts +22 -0
- package/dst/constant/Float.js +80 -0
- package/dst/constant/Integer.d.ts +10 -0
- package/dst/constant/Integer.js +100 -0
- package/dst/constant/Iterable.d.ts +3 -0
- package/dst/constant/Iterable.js +21 -0
- package/dst/constant/Number.d.ts +14 -0
- package/dst/constant/Number.js +56 -0
- package/dst/constant/Object.d.ts +7 -0
- package/dst/constant/Object.js +10 -0
- package/dst/constant/String.d.ts +34 -0
- package/dst/constant/String.js +179 -0
- package/dst/constant/Timestamp.d.ts +20 -0
- package/dst/constant/Timestamp.js +50 -0
- package/dst/constant/Unknown.d.ts +10 -0
- package/dst/constant/Unknown.js +95 -0
- package/dst/constant/notation/AN.d.ts +6 -0
- package/dst/constant/notation/AN.js +42 -0
- package/dst/constant/notation/JSON.d.ts +7 -0
- package/dst/constant/notation/JSON.js +10 -0
- package/dst/index.d.ts +3 -0
- package/dst/index.js +3 -0
- package/dst/node/ArrayNode.d.ts +12 -0
- package/dst/node/ArrayNode.js +30 -0
- package/dst/node/BlockNode.d.ts +12 -0
- package/dst/node/BlockNode.js +29 -0
- package/dst/node/CallNode.d.ts +14 -0
- package/dst/node/CallNode.js +50 -0
- package/dst/node/ConstantNode.d.ts +15 -0
- package/dst/node/ConstantNode.js +29 -0
- package/dst/node/LoopNode.d.ts +13 -0
- package/dst/node/LoopNode.js +30 -0
- package/dst/node/ObjectNode.d.ts +13 -0
- package/dst/node/ObjectNode.js +38 -0
- package/dst/node/SwitchNode.d.ts +14 -0
- package/dst/node/SwitchNode.js +41 -0
- package/dst/node/VariableNode.d.ts +14 -0
- package/dst/node/VariableNode.js +26 -0
- package/package.json +67 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.funcInject = exports.funcSplice = exports.funcSlice = exports.funcAdd = void 0;
|
|
4
|
+
const Constant_js_1 = require("../Constant.js");
|
|
5
|
+
const Type_js_1 = require("../Type.js");
|
|
6
|
+
const Buffer_js_1 = require("./Buffer.js");
|
|
7
|
+
const aggregate = (value1, value2) => {
|
|
8
|
+
if (value1 instanceof ArrayBuffer && value2 instanceof ArrayBuffer) {
|
|
9
|
+
return (0, Buffer_js_1.concatBuffers)(value1, value2);
|
|
10
|
+
}
|
|
11
|
+
if (typeof value1 === 'string' && typeof value2 === 'string') {
|
|
12
|
+
return value1.concat(value2);
|
|
13
|
+
}
|
|
14
|
+
return [value1].flat().concat([value2].flat());
|
|
15
|
+
};
|
|
16
|
+
const add = (value1, value2) => {
|
|
17
|
+
if (typeof value1 === 'bigint' && typeof value2 === 'bigint') {
|
|
18
|
+
return BigInt.asIntN(64, value1 + value2);
|
|
19
|
+
}
|
|
20
|
+
if (typeof value1 === 'number' || typeof value2 === 'number') {
|
|
21
|
+
return Number(value1) + Number(value2);
|
|
22
|
+
}
|
|
23
|
+
return aggregate(value1, value2);
|
|
24
|
+
};
|
|
25
|
+
exports.funcAdd = new Constant_js_1.Constant((value1, value2) => add(value1, value2), Type_js_1.Type.union(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]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Buffer, Type_js_1.Type.Buffer]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.String, Type_js_1.Type.String]), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, Type_js_1.Type.Array])));
|
|
26
|
+
exports.funcSlice = new Constant_js_1.Constant((value, start = 0n, end) => value == null
|
|
27
|
+
? undefined
|
|
28
|
+
: value.slice(Number(start), end == null ? undefined : Number(end)), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Buffer, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalInteger]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.String, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalInteger]), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalInteger])));
|
|
29
|
+
exports.funcSplice = new Constant_js_1.Constant((value, start, remove, ...inject) => value == null
|
|
30
|
+
? undefined
|
|
31
|
+
: aggregate(inject.reduce((acc, val) => aggregate(acc, val), value.slice(0, Number(start))), value.slice(Number(start + remove))), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Buffer, Type_js_1.Type.Integer, Type_js_1.Type.Integer, Type_js_1.Type.Enumerable], true), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.String, Type_js_1.Type.Integer, Type_js_1.Type.Integer, Type_js_1.Type.Enumerable], true), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, Type_js_1.Type.Integer, Type_js_1.Type.Integer, Type_js_1.Type.Enumerable], true)));
|
|
32
|
+
exports.funcInject = new Constant_js_1.Constant((value, start, ...inject) => value == null
|
|
33
|
+
? undefined
|
|
34
|
+
: aggregate(inject.reduce((acc, val) => aggregate(acc, val), value.slice(0, Number(start))), value.slice(Number(start))), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Buffer, Type_js_1.Type.Integer, Type_js_1.Type.Enumerable], true), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.String, Type_js_1.Type.Integer, Type_js_1.Type.Enumerable], true), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, Type_js_1.Type.Integer, Type_js_1.Type.Enumerable], true)));
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constFloat = exports.formatFloat = exports.encodeFloat = void 0;
|
|
4
|
+
const Constant_js_1 = require("../Constant.js");
|
|
5
|
+
const Type_js_1 = require("../Type.js");
|
|
6
|
+
const encodeFloat = (value, encoding = 'float64') => {
|
|
7
|
+
if (value == null) {
|
|
8
|
+
return new Uint8Array(0).buffer;
|
|
9
|
+
}
|
|
10
|
+
let bits = '';
|
|
11
|
+
for (let i = 0; i < encoding.length; ++i) {
|
|
12
|
+
const c = encoding[i];
|
|
13
|
+
if (c >= '0' && c <= '9') {
|
|
14
|
+
bits += c;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const dv = new DataView(new Uint8Array(Number.parseInt(bits) / 8).buffer);
|
|
18
|
+
switch (encoding) {
|
|
19
|
+
case 'float32':
|
|
20
|
+
dv.setFloat32(0, value);
|
|
21
|
+
break;
|
|
22
|
+
case 'float32le':
|
|
23
|
+
dv.setFloat32(0, value, true);
|
|
24
|
+
break;
|
|
25
|
+
case 'float64':
|
|
26
|
+
dv.setFloat64(0, value);
|
|
27
|
+
break;
|
|
28
|
+
case 'float64le':
|
|
29
|
+
dv.setFloat64(0, value, true);
|
|
30
|
+
break;
|
|
31
|
+
default: throw new Error(`${encoding} encoding not supported`);
|
|
32
|
+
}
|
|
33
|
+
return dv.buffer;
|
|
34
|
+
};
|
|
35
|
+
exports.encodeFloat = encodeFloat;
|
|
36
|
+
const decodeFloat = (value, encoding = 'float64', byteOffset) => {
|
|
37
|
+
if (value == null) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const dv = new DataView(value, byteOffset);
|
|
41
|
+
switch (encoding) {
|
|
42
|
+
case 'float32': return dv.getFloat32(0);
|
|
43
|
+
case 'float32le': return dv.getFloat32(0, true);
|
|
44
|
+
case 'float64': return dv.getFloat64(0);
|
|
45
|
+
case 'float64le': return dv.getFloat64(0, true);
|
|
46
|
+
default: throw new Error(`${encoding} encoding not supported`);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const formatFloat = (value, radix) => value.toString(radix) + (Number.isInteger(value) ? '.0' : '');
|
|
50
|
+
exports.formatFloat = formatFloat;
|
|
51
|
+
const typeNumberOrArray = Type_js_1.Type.union(Type_js_1.Type.Float, Type_js_1.Type.arrayType([Type_js_1.Type.Float]));
|
|
52
|
+
const typeAggregator = Type_js_1.Type.functionType(Type_js_1.Type.Float, [typeNumberOrArray], true);
|
|
53
|
+
const typeNumberTransform = Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float]);
|
|
54
|
+
const funcSum = new Constant_js_1.Constant((...values) => values.flat().reduce((acc, val) => acc + val, 0), typeAggregator);
|
|
55
|
+
const funcMin = new Constant_js_1.Constant((...values) => Math.min(Number.POSITIVE_INFINITY, ...values.flat()), typeAggregator);
|
|
56
|
+
const funcMax = new Constant_js_1.Constant((...values) => Math.max(Number.NEGATIVE_INFINITY, ...values.flat()), typeAggregator);
|
|
57
|
+
const funcExponent = new Constant_js_1.Constant((value) => Math.exp(value), typeNumberTransform);
|
|
58
|
+
const funcLogarithm = new Constant_js_1.Constant((value) => Math.log(value), typeNumberTransform);
|
|
59
|
+
const funcAbs = new Constant_js_1.Constant((value) => Math.abs(value), typeNumberTransform);
|
|
60
|
+
const funcCeil = new Constant_js_1.Constant((value) => Math.ceil(value), typeNumberTransform);
|
|
61
|
+
const funcFloor = new Constant_js_1.Constant((value) => Math.floor(value), typeNumberTransform);
|
|
62
|
+
const funcRound = new Constant_js_1.Constant((value) => Math.round(value), typeNumberTransform);
|
|
63
|
+
const funcTruncate = new Constant_js_1.Constant((value) => Math.trunc(value), typeNumberTransform);
|
|
64
|
+
const funcRandomFloat = new Constant_js_1.Constant((value) => value == null ? undefined : Math.random() * value, Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float]), false);
|
|
65
|
+
const funcDecodeFloat = new Constant_js_1.Constant((value, encoding = 'float64', byteOffset) => decodeFloat(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type_js_1.Type.functionType(Type_js_1.Type.OptionalFloat, [Type_js_1.Type.Buffer, Type_js_1.Type.OptionalString, Type_js_1.Type.OptionalInteger]));
|
|
66
|
+
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.String]));
|
|
67
|
+
exports.constFloat = {
|
|
68
|
+
NAN: new Constant_js_1.Constant(Number.NaN),
|
|
69
|
+
PositiveInfinity: new Constant_js_1.Constant(Number.POSITIVE_INFINITY),
|
|
70
|
+
NegativeInfinity: new Constant_js_1.Constant(Number.NEGATIVE_INFINITY),
|
|
71
|
+
Epsilon: new Constant_js_1.Constant(Number.EPSILON),
|
|
72
|
+
Sum: funcSum,
|
|
73
|
+
Min: funcMin,
|
|
74
|
+
Max: funcMax,
|
|
75
|
+
Exponent: funcExponent,
|
|
76
|
+
Logarithm: funcLogarithm,
|
|
77
|
+
Abs: funcAbs,
|
|
78
|
+
Ceil: funcCeil,
|
|
79
|
+
Floor: funcFloor,
|
|
80
|
+
Round: funcRound,
|
|
81
|
+
Truncate: funcTruncate,
|
|
82
|
+
Random: funcRandomFloat,
|
|
83
|
+
Decode: funcDecodeFloat,
|
|
84
|
+
Parse: funcParseFloat,
|
|
85
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constInteger = exports.encodeInteger = void 0;
|
|
4
|
+
const Constant_js_1 = require("../Constant.js");
|
|
5
|
+
const Type_js_1 = require("../Type.js");
|
|
6
|
+
const encodeInteger = (value, encoding = 'int64') => {
|
|
7
|
+
if (value == null) {
|
|
8
|
+
return new Uint8Array(0).buffer;
|
|
9
|
+
}
|
|
10
|
+
let bits = '';
|
|
11
|
+
for (let i = 0; i < encoding.length; ++i) {
|
|
12
|
+
const c = encoding[i];
|
|
13
|
+
if (c >= '0' && c <= '9') {
|
|
14
|
+
bits += c;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const dv = new DataView(new Uint8Array(Number.parseInt(bits) / 8).buffer);
|
|
18
|
+
switch (encoding) {
|
|
19
|
+
case 'int8':
|
|
20
|
+
dv.setInt8(0, Number(value));
|
|
21
|
+
break;
|
|
22
|
+
case 'int16':
|
|
23
|
+
dv.setInt16(0, Number(value));
|
|
24
|
+
break;
|
|
25
|
+
case 'int16le':
|
|
26
|
+
dv.setInt16(0, Number(value), true);
|
|
27
|
+
break;
|
|
28
|
+
case 'int32':
|
|
29
|
+
dv.setInt32(0, Number(value));
|
|
30
|
+
break;
|
|
31
|
+
case 'int32le':
|
|
32
|
+
dv.setInt32(0, Number(value), true);
|
|
33
|
+
break;
|
|
34
|
+
case 'uint8':
|
|
35
|
+
dv.setUint8(0, Number(value));
|
|
36
|
+
break;
|
|
37
|
+
case 'uint16':
|
|
38
|
+
dv.setUint16(0, Number(value));
|
|
39
|
+
break;
|
|
40
|
+
case 'uint16le':
|
|
41
|
+
dv.setUint16(0, Number(value), true);
|
|
42
|
+
break;
|
|
43
|
+
case 'uint32':
|
|
44
|
+
dv.setUint32(0, Number(value));
|
|
45
|
+
break;
|
|
46
|
+
case 'uint32le':
|
|
47
|
+
dv.setUint32(0, Number(value), true);
|
|
48
|
+
break;
|
|
49
|
+
case 'int64':
|
|
50
|
+
dv.setBigInt64(0, value);
|
|
51
|
+
break;
|
|
52
|
+
case 'int64le':
|
|
53
|
+
dv.setBigInt64(0, value, true);
|
|
54
|
+
break;
|
|
55
|
+
case 'uint64':
|
|
56
|
+
dv.setBigUint64(0, value);
|
|
57
|
+
break;
|
|
58
|
+
case 'uint64le':
|
|
59
|
+
dv.setBigUint64(0, value, true);
|
|
60
|
+
break;
|
|
61
|
+
default: throw new Error(`${encoding} encoding not supported`);
|
|
62
|
+
}
|
|
63
|
+
return dv.buffer;
|
|
64
|
+
};
|
|
65
|
+
exports.encodeInteger = encodeInteger;
|
|
66
|
+
const decodeInteger = (value, encoding = 'int64', byteOffset) => {
|
|
67
|
+
if (value == null) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
const dv = new DataView(value, byteOffset == null ? undefined : Number(byteOffset));
|
|
71
|
+
switch (encoding) {
|
|
72
|
+
case 'int8': return BigInt(dv.getInt8(0));
|
|
73
|
+
case 'int16': return BigInt(dv.getInt16(0));
|
|
74
|
+
case 'int16le': return BigInt(dv.getInt16(0, true));
|
|
75
|
+
case 'int32': return BigInt(dv.getInt32(0));
|
|
76
|
+
case 'int32le': return BigInt(dv.getInt32(0, true));
|
|
77
|
+
case 'int64': return dv.getBigInt64(0);
|
|
78
|
+
case 'int64le': return dv.getBigInt64(0, true);
|
|
79
|
+
case 'uint8': return BigInt(dv.getUint8(0));
|
|
80
|
+
case 'uint16': return BigInt(dv.getUint16(0));
|
|
81
|
+
case 'uint16le': return BigInt(dv.getUint16(0, true));
|
|
82
|
+
case 'uint32': return BigInt(dv.getUint32(0));
|
|
83
|
+
case 'uint32le': return BigInt(dv.getUint32(0, true));
|
|
84
|
+
case 'uint64': return dv.getBigUint64(0);
|
|
85
|
+
case 'uint64le': return dv.getBigUint64(0, true);
|
|
86
|
+
default: throw new Error(`${encoding} encoding not supported`);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const typeIntegerOrArray = Type_js_1.Type.union(Type_js_1.Type.Integer, Type_js_1.Type.arrayType([Type_js_1.Type.Integer]));
|
|
90
|
+
const typeAggregator = Type_js_1.Type.functionType(Type_js_1.Type.Integer, [typeIntegerOrArray], true);
|
|
91
|
+
const funcSum = new Constant_js_1.Constant((...values) => BigInt.asIntN(64, values.flat().reduce((acc, val) => acc + val, 0n)), typeAggregator);
|
|
92
|
+
const funcMin = new Constant_js_1.Constant((...values) => BigInt.asIntN(64, values.flat().reduce((min, val) => val < min ? val : min)), typeAggregator);
|
|
93
|
+
const funcMax = new Constant_js_1.Constant((...values) => BigInt.asIntN(64, values.flat().reduce((max, val) => val > max ? val : max)), typeAggregator);
|
|
94
|
+
const funcRandomInteger = new Constant_js_1.Constant((value) => value == null ? undefined : BigInt.asIntN(64, BigInt(Math.floor(Math.random() * Number(value)))), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Integer]), false);
|
|
95
|
+
const funcDecodeInteger = new Constant_js_1.Constant((value, encoding = 'int64', byteOffset) => decodeInteger(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type_js_1.Type.functionType(Type_js_1.Type.OptionalInteger, [Type_js_1.Type.Buffer, Type_js_1.Type.OptionalString, Type_js_1.Type.OptionalInteger]));
|
|
96
|
+
const funcParseInteger = new Constant_js_1.Constant((value) => value ? BigInt.asIntN(64, BigInt(value)) : undefined, Type_js_1.Type.functionType(Type_js_1.Type.OptionalInteger, [Type_js_1.Type.String]));
|
|
97
|
+
exports.constInteger = {
|
|
98
|
+
Sum: funcSum,
|
|
99
|
+
Min: funcMin,
|
|
100
|
+
Max: funcMax,
|
|
101
|
+
Random: funcRandomInteger,
|
|
102
|
+
Decode: funcDecodeInteger,
|
|
103
|
+
Parse: funcParseInteger,
|
|
104
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.funcAt = exports.funcLength = void 0;
|
|
4
|
+
const Constant_js_1 = require("../Constant.js");
|
|
5
|
+
const Type_js_1 = require("../Type.js");
|
|
6
|
+
exports.funcLength = new Constant_js_1.Constant((value) => BigInt.asIntN(64, BigInt(value == null
|
|
7
|
+
? 0
|
|
8
|
+
: value instanceof ArrayBuffer
|
|
9
|
+
? value.byteLength
|
|
10
|
+
: typeof value === 'string' || Array.isArray(value)
|
|
11
|
+
? value.length
|
|
12
|
+
: Object.keys(value).length)), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Iterable]));
|
|
13
|
+
exports.funcAt = new Constant_js_1.Constant((value, index) => {
|
|
14
|
+
if (value == null) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
else if (Array.isArray(value)) {
|
|
18
|
+
const ix = Number(index);
|
|
19
|
+
return value[ix < 0 ? value.length + ix : ix];
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return value[String(index)];
|
|
23
|
+
}
|
|
24
|
+
}, 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])));
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.funcCast = exports.funcNegate = exports.funcRoot = exports.funcPower = exports.funcModulo = exports.funcRemainder = exports.funcDivide = exports.funcMultiply = exports.funcSubtract = exports.funcLessOrEqual = exports.funcGreaterOrEqual = exports.funcLessThan = exports.funcGreaterThan = void 0;
|
|
4
|
+
const Constant_js_1 = require("../Constant.js");
|
|
5
|
+
const Type_js_1 = require("../Type.js");
|
|
6
|
+
const typeComparator = Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Number, Type_js_1.Type.Number]);
|
|
7
|
+
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.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]));
|
|
8
|
+
exports.funcGreaterThan = new Constant_js_1.Constant((value1, value2) => value1 > value2, typeComparator);
|
|
9
|
+
exports.funcLessThan = new Constant_js_1.Constant((value1, value2) => value1 < value2, typeComparator);
|
|
10
|
+
exports.funcGreaterOrEqual = new Constant_js_1.Constant((value1, value2) => value1 >= value2, typeComparator);
|
|
11
|
+
exports.funcLessOrEqual = new Constant_js_1.Constant((value1, value2) => value1 <= value2, typeComparator);
|
|
12
|
+
exports.funcSubtract = new Constant_js_1.Constant((value, subtrahend) => typeof value === 'bigint' && typeof subtrahend === 'bigint'
|
|
13
|
+
? BigInt.asIntN(64, value - subtrahend)
|
|
14
|
+
: Number(value) - Number(subtrahend), typeOperator);
|
|
15
|
+
exports.funcMultiply = new Constant_js_1.Constant((value1, value2) => typeof value1 === 'bigint' && typeof value2 === 'bigint'
|
|
16
|
+
? BigInt.asIntN(64, value1 * value2)
|
|
17
|
+
: Number(value1) * Number(value2), typeOperator);
|
|
18
|
+
exports.funcDivide = new Constant_js_1.Constant((value, divisor) => typeof value === 'bigint' && typeof divisor === 'bigint'
|
|
19
|
+
? BigInt.asIntN(64, value / divisor)
|
|
20
|
+
: Number(value) / Number(divisor), typeOperator);
|
|
21
|
+
exports.funcRemainder = new Constant_js_1.Constant((value, divisor) => typeof value === 'bigint' && typeof divisor === 'bigint'
|
|
22
|
+
? BigInt.asIntN(64, value % divisor)
|
|
23
|
+
: Number(value) % Number(divisor), typeOperator);
|
|
24
|
+
exports.funcModulo = new Constant_js_1.Constant((value, divisor) => typeof value === 'bigint' && typeof divisor === 'bigint'
|
|
25
|
+
? BigInt.asIntN(64, (value % divisor + divisor) % divisor)
|
|
26
|
+
: (Number(value) % Number(divisor) + Number(divisor)) % Number(divisor), typeOperator);
|
|
27
|
+
exports.funcPower = new Constant_js_1.Constant((value, exponent) => typeof value === 'bigint' && typeof exponent === 'bigint'
|
|
28
|
+
? BigInt.asIntN(64, value ** BigInt(exponent))
|
|
29
|
+
: Number(value) ** Number(exponent), typeOperator);
|
|
30
|
+
exports.funcRoot = new Constant_js_1.Constant((value, exponent) => {
|
|
31
|
+
if (typeof value === 'bigint' && typeof exponent === 'bigint') {
|
|
32
|
+
const e = BigInt(exponent);
|
|
33
|
+
if (value < 0n && e % 2n === 0n) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
if (value < 2n || e === 1n) {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
let low = 0n, high = value, result = 0n;
|
|
40
|
+
while (low <= high) {
|
|
41
|
+
const mid = low + high >> 1n;
|
|
42
|
+
const midPow = mid ** e;
|
|
43
|
+
if (midPow === value) {
|
|
44
|
+
return mid;
|
|
45
|
+
}
|
|
46
|
+
else if (midPow < value) {
|
|
47
|
+
result = mid;
|
|
48
|
+
low = mid + 1n;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
high = mid - 1n;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return BigInt.asIntN(64, result);
|
|
55
|
+
}
|
|
56
|
+
return Math.pow(Number(value), 1 / Number(exponent));
|
|
57
|
+
}, typeOperator);
|
|
58
|
+
exports.funcNegate = new Constant_js_1.Constant((value) => typeof value === 'number' ? -value : BigInt.asIntN(64, -value), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float]), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Integer])));
|
|
59
|
+
exports.funcCast = new Constant_js_1.Constant((value) => typeof value === 'number' ? BigInt.asIntN(64, BigInt(Math.trunc(value))) : Number(value), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Integer]), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Float])));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constObject = exports.funcValues = exports.funcKeys = exports.funcEntries = void 0;
|
|
4
|
+
const Constant_js_1 = require("../Constant.js");
|
|
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
|
+
exports.funcEntries = new Constant_js_1.Constant((value) => Object.entries(value), typeAccessor);
|
|
8
|
+
exports.funcKeys = new Constant_js_1.Constant((value) => Object.keys(value), Type_js_1.Type.functionType(Type_js_1.Type.arrayType([Type_js_1.Type.String]), [Type_js_1.Type.Object]));
|
|
9
|
+
exports.funcValues = new Constant_js_1.Constant((value) => Object.values(value), typeAccessor);
|
|
10
|
+
const funcMerge = new Constant_js_1.Constant((...values) => values.flat().reduce((acc, val) => Object.assign(acc, val), {}), Type_js_1.Type.functionType(Type_js_1.Type.Object, [Type_js_1.Type.union(Type_js_1.Type.arrayType([Type_js_1.Type.Object]), Type_js_1.Type.Object)], true));
|
|
11
|
+
exports.constObject = {
|
|
12
|
+
Merge: funcMerge,
|
|
13
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constString = exports.funcSplit = exports.funcUpperCase = exports.funcLowerCase = exports.funcTrimEnd = exports.funcTrimStart = exports.funcTrim = exports.funcCharCode = exports.funcChar = exports.funcEndsWith = exports.funcStartsWith = exports.funcContains = exports.funcUnlike = exports.funcLike = exports.encodeString = exports.endsWithString = exports.startsWithString = exports.containsString = exports.equateStrings = exports.isCaseSpaceEtc = exports.isQuotation = exports.isHexadecimal = exports.isDateTimeSeparator = exports.isTimeSymbol = exports.isDateSymbol = exports.isAlphanumeric = exports.isNumeric = exports.isAlpha = exports.isSign = void 0;
|
|
4
|
+
const Constant_js_1 = require("../Constant.js");
|
|
5
|
+
const Type_js_1 = require("../Type.js");
|
|
6
|
+
const isSign = (c) => c === '+' || c === '-';
|
|
7
|
+
exports.isSign = isSign;
|
|
8
|
+
const isAlpha = (c) => c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c === '_';
|
|
9
|
+
exports.isAlpha = isAlpha;
|
|
10
|
+
const isNumeric = (c) => c >= '0' && c <= '9';
|
|
11
|
+
exports.isNumeric = isNumeric;
|
|
12
|
+
const isAlphanumeric = (c) => (0, exports.isAlpha)(c) || (0, exports.isNumeric)(c);
|
|
13
|
+
exports.isAlphanumeric = isAlphanumeric;
|
|
14
|
+
const isDateSymbol = (c) => (0, exports.isNumeric)(c) || c === '-';
|
|
15
|
+
exports.isDateSymbol = isDateSymbol;
|
|
16
|
+
const isTimeSymbol = (c) => (0, exports.isNumeric)(c) || c === ':';
|
|
17
|
+
exports.isTimeSymbol = isTimeSymbol;
|
|
18
|
+
const isDateTimeSeparator = (c) => c === 'T' || c === ' ' || c === '@';
|
|
19
|
+
exports.isDateTimeSeparator = isDateTimeSeparator;
|
|
20
|
+
const isHexadecimal = (c) => (0, exports.isNumeric)(c) || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F';
|
|
21
|
+
exports.isHexadecimal = isHexadecimal;
|
|
22
|
+
const isQuotation = (c) => c === '\'' || c === '"' || c === '`';
|
|
23
|
+
exports.isQuotation = isQuotation;
|
|
24
|
+
const isCaseSpaceEtc = (c) => (c < 'a' || c > 'z') && (c < '0' || c > '9');
|
|
25
|
+
exports.isCaseSpaceEtc = isCaseSpaceEtc;
|
|
26
|
+
const equateStrings = (value1, value2, ignoreCaseSpaceEtc) => {
|
|
27
|
+
if (!ignoreCaseSpaceEtc) {
|
|
28
|
+
return value1 === value2;
|
|
29
|
+
}
|
|
30
|
+
const str1 = value1.toLowerCase();
|
|
31
|
+
const str2 = value2.toLowerCase();
|
|
32
|
+
for (let i1 = 0, i2 = 0; i1 < str1.length && i2 < str2.length; ++i1, ++i2) {
|
|
33
|
+
while ((0, exports.isCaseSpaceEtc)(str1[i1]) && i1 < str1.length) {
|
|
34
|
+
++i1;
|
|
35
|
+
}
|
|
36
|
+
while ((0, exports.isCaseSpaceEtc)(str2[i2]) && i2 < str2.length) {
|
|
37
|
+
++i2;
|
|
38
|
+
}
|
|
39
|
+
if (str1[i1] != str2[i2]) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
};
|
|
45
|
+
exports.equateStrings = equateStrings;
|
|
46
|
+
const containsString = (value, search, startPos, ignoreCaseSpaceEtc) => {
|
|
47
|
+
if (!ignoreCaseSpaceEtc) {
|
|
48
|
+
return value.includes(search, startPos);
|
|
49
|
+
}
|
|
50
|
+
const valueStr = value.toLowerCase();
|
|
51
|
+
const searchStr = search.toLowerCase();
|
|
52
|
+
if (valueStr.length < searchStr.length) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
const pos = startPos == null ? 0 : startPos < 0 ? value.length + startPos : startPos;
|
|
56
|
+
for (let i1 = pos, i2 = 0; i1 < valueStr.length && i2 < searchStr.length; ++i1, ++i2) {
|
|
57
|
+
while ((0, exports.isCaseSpaceEtc)(valueStr[i1]) && i1 < valueStr.length) {
|
|
58
|
+
++i1;
|
|
59
|
+
}
|
|
60
|
+
while ((0, exports.isCaseSpaceEtc)(searchStr[i2]) && i2 < searchStr.length) {
|
|
61
|
+
++i2;
|
|
62
|
+
}
|
|
63
|
+
while (valueStr[i1] != searchStr[i2] && i1 < valueStr.length) {
|
|
64
|
+
++i1;
|
|
65
|
+
}
|
|
66
|
+
if (valueStr[i1] != searchStr[i2] && i2 < searchStr.length) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
};
|
|
72
|
+
exports.containsString = containsString;
|
|
73
|
+
const startsWithString = (value, search, startPos, ignoreCaseSpaceEtc) => {
|
|
74
|
+
if (!ignoreCaseSpaceEtc) {
|
|
75
|
+
return value.startsWith(search, startPos);
|
|
76
|
+
}
|
|
77
|
+
const valueStr = value.toLowerCase();
|
|
78
|
+
const searchStr = search.toLowerCase();
|
|
79
|
+
if (valueStr.length < searchStr.length) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
const pos = startPos == null ? 0 : startPos < 0 ? value.length + startPos : startPos;
|
|
83
|
+
for (let i1 = pos, i2 = 0; i1 < valueStr.length && i2 < searchStr.length; ++i1, ++i2) {
|
|
84
|
+
while ((0, exports.isCaseSpaceEtc)(valueStr[i1]) && i1 < valueStr.length) {
|
|
85
|
+
++i1;
|
|
86
|
+
}
|
|
87
|
+
while ((0, exports.isCaseSpaceEtc)(searchStr[i2]) && i2 < searchStr.length) {
|
|
88
|
+
++i2;
|
|
89
|
+
}
|
|
90
|
+
if (valueStr[i1] != searchStr[i2] && i2 < searchStr.length) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
};
|
|
96
|
+
exports.startsWithString = startsWithString;
|
|
97
|
+
const endsWithString = (value, search, endPos, ignoreCaseSpaceEtc) => {
|
|
98
|
+
if (!ignoreCaseSpaceEtc) {
|
|
99
|
+
return value.endsWith(search, endPos);
|
|
100
|
+
}
|
|
101
|
+
const valueStr = value.toLowerCase();
|
|
102
|
+
const searchStr = search.toLowerCase();
|
|
103
|
+
if (valueStr.length < searchStr.length) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
const pos = endPos == null ? valueStr.length : endPos < 0 ? value.length + endPos : endPos;
|
|
107
|
+
for (let i1 = pos - 1, i2 = searchStr.length - 1; i1 > -1 && i2 > -1; --i1, --i2) {
|
|
108
|
+
while ((0, exports.isCaseSpaceEtc)(valueStr[i1]) && i1 > -1) {
|
|
109
|
+
--i1;
|
|
110
|
+
}
|
|
111
|
+
while ((0, exports.isCaseSpaceEtc)(searchStr[i2]) && i2 > -1) {
|
|
112
|
+
--i2;
|
|
113
|
+
}
|
|
114
|
+
if (valueStr[i1] != searchStr[i2] && i2 > -1) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
};
|
|
120
|
+
exports.endsWithString = endsWithString;
|
|
121
|
+
const encodeString = (value, encoding = 'utf8') => {
|
|
122
|
+
if (value == null) {
|
|
123
|
+
return new Uint8Array(0).buffer;
|
|
124
|
+
}
|
|
125
|
+
if (encoding === 'utf8') {
|
|
126
|
+
return new TextEncoder().encode(value).buffer;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
const dv = new DataView(new Uint16Array(value.length).buffer);
|
|
130
|
+
const lessOrEqual = encoding.endsWith('le');
|
|
131
|
+
for (let i = 0; i < value.length; ++i) {
|
|
132
|
+
dv.setUint16(i << 1, value.charCodeAt(i), lessOrEqual);
|
|
133
|
+
}
|
|
134
|
+
return dv.buffer;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
exports.encodeString = encodeString;
|
|
138
|
+
const decodeString = (value, encoding = 'utf8', byteOffset, byteLength) => {
|
|
139
|
+
if (value == null) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
if (encoding === 'utf8') {
|
|
143
|
+
return new TextDecoder().decode(new DataView(value, byteOffset, byteLength));
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
const dv = new DataView(value, byteOffset, byteLength);
|
|
147
|
+
const lessOrEqual = encoding.endsWith('le');
|
|
148
|
+
let str = '';
|
|
149
|
+
for (let i = 0; i < dv.byteLength; i += 2) {
|
|
150
|
+
str += String.fromCharCode(dv.getUint16(i, lessOrEqual));
|
|
151
|
+
}
|
|
152
|
+
return str;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const typeStringEquator = Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.String, Type_js_1.Type.String]);
|
|
156
|
+
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]);
|
|
157
|
+
const typeStringMutator = Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.String]);
|
|
158
|
+
exports.funcLike = new Constant_js_1.Constant((value1, value2) => (0, exports.equateStrings)(value1, value2, true), typeStringEquator);
|
|
159
|
+
exports.funcUnlike = new Constant_js_1.Constant((value1, value2) => !(0, exports.equateStrings)(value1, value2, true), typeStringEquator);
|
|
160
|
+
exports.funcContains = new Constant_js_1.Constant((value, search, start, ignoreCaseSpaceEtc) => (0, exports.containsString)(value, search, start == null ? undefined : Number(start), ignoreCaseSpaceEtc), typeStringComparator);
|
|
161
|
+
exports.funcStartsWith = new Constant_js_1.Constant((value, search, start, ignoreCaseSpaceEtc) => (0, exports.startsWithString)(value, search, start == null ? undefined : Number(start), ignoreCaseSpaceEtc), typeStringComparator);
|
|
162
|
+
exports.funcEndsWith = new Constant_js_1.Constant((value, search, end, ignoreCaseSpaceEtc) => (0, exports.endsWithString)(value, search, end == null ? undefined : Number(end), ignoreCaseSpaceEtc), typeStringComparator);
|
|
163
|
+
exports.funcChar = new Constant_js_1.Constant((value, pos) => value == null
|
|
164
|
+
? undefined
|
|
165
|
+
: 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]));
|
|
166
|
+
exports.funcCharCode = new Constant_js_1.Constant((value, pos) => value == null
|
|
167
|
+
? undefined
|
|
168
|
+
: 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.Float]));
|
|
169
|
+
exports.funcTrim = new Constant_js_1.Constant((value) => value.trim(), typeStringMutator);
|
|
170
|
+
exports.funcTrimStart = new Constant_js_1.Constant((value) => value.trimStart(), typeStringMutator);
|
|
171
|
+
exports.funcTrimEnd = new Constant_js_1.Constant((value) => value.trimEnd(), typeStringMutator);
|
|
172
|
+
exports.funcLowerCase = new Constant_js_1.Constant((value) => value.toLowerCase(), typeStringMutator);
|
|
173
|
+
exports.funcUpperCase = new Constant_js_1.Constant((value) => value.toUpperCase(), typeStringMutator);
|
|
174
|
+
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]));
|
|
175
|
+
const funcAlphanum = new Constant_js_1.Constant((value) => {
|
|
176
|
+
const lowerCase = value.toLowerCase();
|
|
177
|
+
let result = '';
|
|
178
|
+
for (let i = 0; i < lowerCase.length; ++i) {
|
|
179
|
+
if (!(0, exports.isCaseSpaceEtc)(value[i])) {
|
|
180
|
+
result += value[i];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
}, typeStringMutator);
|
|
185
|
+
const funcRandomString = new Constant_js_1.Constant((value) => {
|
|
186
|
+
let str = '';
|
|
187
|
+
while (str.length < value) {
|
|
188
|
+
str += Math.random().toString(36).slice(2);
|
|
189
|
+
}
|
|
190
|
+
return str.slice(0, Number(value));
|
|
191
|
+
}, Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Integer]), false);
|
|
192
|
+
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.Buffer, Type_js_1.Type.OptionalString, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalInteger]));
|
|
193
|
+
exports.constString = {
|
|
194
|
+
Alphanum: funcAlphanum,
|
|
195
|
+
Random: funcRandomString,
|
|
196
|
+
Decode: funcDecodeString,
|
|
197
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constTimestamp = exports.funcEpochTime = exports.funcMillisecond = exports.funcSecond = exports.funcMinute = exports.funcHour = exports.funcDay = exports.funcWeekdayIndex = exports.funcMonthIndex = exports.funcMonth = exports.funcYear = exports.formatTimestamp = exports.decodeTimestamp = exports.encodeTimestamp = void 0;
|
|
4
|
+
const Constant_js_1 = require("../Constant.js");
|
|
5
|
+
const Type_js_1 = require("../Type.js");
|
|
6
|
+
const typeTimestampPart = Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Timestamp, Type_js_1.Type.OptionalBoolean]);
|
|
7
|
+
const encodeTimestamp = (value, encoding = 'int64') => {
|
|
8
|
+
const buf = new ArrayBuffer(8);
|
|
9
|
+
const dv = new DataView(buf);
|
|
10
|
+
dv.setBigInt64(0, BigInt(value.getTime()), encoding === 'int64le');
|
|
11
|
+
return buf;
|
|
12
|
+
};
|
|
13
|
+
exports.encodeTimestamp = encodeTimestamp;
|
|
14
|
+
const decodeTimestamp = (value, encoding = 'int64', byteOffset) => new Date(Number(new DataView(value).getBigInt64(byteOffset == null ? 0 : Number(byteOffset), encoding === 'int64le')));
|
|
15
|
+
exports.decodeTimestamp = decodeTimestamp;
|
|
16
|
+
const formatTimestamp = (value, radix) => {
|
|
17
|
+
const str = value.toISOString();
|
|
18
|
+
switch (radix) {
|
|
19
|
+
case 1: return str.slice(0, 4);
|
|
20
|
+
case 2: return str.slice(5, 7);
|
|
21
|
+
case 3: return str.slice(8, 10);
|
|
22
|
+
case 4: return str.slice(11, 13);
|
|
23
|
+
case 5: return str.slice(14, 16);
|
|
24
|
+
case 6: return str.slice(17, 19);
|
|
25
|
+
case 7: return str.slice(20, 23);
|
|
26
|
+
default: return str;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.formatTimestamp = formatTimestamp;
|
|
30
|
+
const parseTimestamp = (value) => {
|
|
31
|
+
if (value == null) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const date = new Date(value);
|
|
35
|
+
return isNaN(date.getTime()) ? undefined : date;
|
|
36
|
+
};
|
|
37
|
+
const funcNow = new Constant_js_1.Constant(() => new Date(), Type_js_1.Type.functionType(Type_js_1.Type.Timestamp, []), false);
|
|
38
|
+
exports.funcYear = new Constant_js_1.Constant((value, utc = false) => BigInt(utc ? value.getUTCFullYear() : value.getFullYear()), typeTimestampPart);
|
|
39
|
+
exports.funcMonth = new Constant_js_1.Constant((value, utc = false) => BigInt(1 + (utc ? value.getUTCMonth() : value.getMonth())), typeTimestampPart);
|
|
40
|
+
exports.funcMonthIndex = new Constant_js_1.Constant((value, utc = false) => BigInt(utc ? value.getUTCMonth() : value.getMonth()), typeTimestampPart);
|
|
41
|
+
exports.funcWeekdayIndex = new Constant_js_1.Constant((value, utc = false) => BigInt(utc ? value.getUTCDay() : value.getDay()), typeTimestampPart);
|
|
42
|
+
exports.funcDay = new Constant_js_1.Constant((value, utc = false) => BigInt(utc ? value.getUTCDate() : value.getDate()), typeTimestampPart);
|
|
43
|
+
exports.funcHour = new Constant_js_1.Constant((value, utc = false) => BigInt(utc ? value.getUTCHours() : value.getHours()), typeTimestampPart);
|
|
44
|
+
exports.funcMinute = new Constant_js_1.Constant((value, utc = false) => BigInt(utc ? value.getUTCMinutes() : value.getMinutes()), typeTimestampPart);
|
|
45
|
+
exports.funcSecond = new Constant_js_1.Constant((value, utc = false) => BigInt(utc ? value.getUTCSeconds() : value.getSeconds()), typeTimestampPart);
|
|
46
|
+
exports.funcMillisecond = new Constant_js_1.Constant((value, utc = false) => BigInt(utc ? value.getUTCMilliseconds() : value.getMilliseconds()), typeTimestampPart);
|
|
47
|
+
exports.funcEpochTime = new Constant_js_1.Constant((value, epoch = new Date(0)) => BigInt.asIntN(64, BigInt(value.getTime() - epoch.getTime())), Type_js_1.Type.functionType(Type_js_1.Type.Integer, [Type_js_1.Type.Timestamp, Type_js_1.Type.OptionalTimestamp]));
|
|
48
|
+
const funcEpochTimestamp = new Constant_js_1.Constant((value, epoch = new Date(0)) => new Date(Number(value) + epoch.getTime()), Type_js_1.Type.functionType(Type_js_1.Type.Timestamp, [Type_js_1.Type.Number, Type_js_1.Type.OptionalTimestamp]));
|
|
49
|
+
const funcDecodeTimestamp = new Constant_js_1.Constant((value, encoding = 'int64', byteOffset) => (0, exports.decodeTimestamp)(value, encoding, byteOffset), Type_js_1.Type.functionType(Type_js_1.Type.OptionalTimestamp, [Type_js_1.Type.Buffer, Type_js_1.Type.OptionalString, Type_js_1.Type.OptionalInteger]));
|
|
50
|
+
const funcParseTimestamp = new Constant_js_1.Constant((value) => parseTimestamp(value), Type_js_1.Type.functionType(Type_js_1.Type.OptionalTimestamp, [Type_js_1.Type.String]));
|
|
51
|
+
exports.constTimestamp = {
|
|
52
|
+
Now: funcNow,
|
|
53
|
+
Epoch: funcEpochTimestamp,
|
|
54
|
+
Decode: funcDecodeTimestamp,
|
|
55
|
+
Parse: funcParseTimestamp,
|
|
56
|
+
};
|