affinirum 1.2.3 → 1.2.5

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/README.md CHANGED
@@ -183,7 +183,7 @@ Unknown or variant type is declared as **??**.
183
183
  - **object Object.Merge(values: array...)** — Merge multiple objects
184
184
 
185
185
  #### AN
186
- - **string AN.Format(value: string, whitespace: string?)** — Format string as AN
186
+ - **string AN.Format(value: ??, whitespace: string?)** — Format string as AN
187
187
 
188
188
  #### JSON
189
189
  - **string JSON.Format(value: void | boolean | float | string | array | object, whitespace: string?)** — Format as JSON string
@@ -196,8 +196,11 @@ Unknown or variant type is declared as **??**.
196
196
  - **?? ??.Coalesce(otherwise: ??)** — Null coalescence
197
197
  - **boolean ??.Equal(value: ??)** — Equals to
198
198
  - **boolean ??.Unequal(value: ??)** — Not equals to
199
- - **buffer float | integer | string.Encode(encoding: string?)** — Encode value to buffer
200
- - **string boolean | float | integer | buffer | string | array | object.Format(radix: integer?, separator: string?)** — Format value to string
199
+ - **buffer ??.Encode(encoding: string?)** — Encode value to buffer
200
+ - **string ??.Format(formatting: integer? | string?)** — Format value to string
201
+
202
+ #### Aggregable Functions
203
+ - **float | integer | buffer | string | array float | integer | buffer | string | array.Add(values: array...)** — Add or concatenate values
201
204
 
202
205
  #### Array Functions
203
206
  - **?? array.First(condition: function)** — First item satisfying condition
@@ -220,7 +223,6 @@ Unknown or variant type is declared as **??**.
220
223
  - **string Buffer.FormatBuffer(value: buffer)** — Hexadecimal string from buffer
221
224
 
222
225
  #### Enumerable Functions
223
- - **float | integer | buffer | string | array.Add(values: array...)** — Add or concatenate values
224
226
  - **buffer | string | array.Slice(start: integer?, end: integer?)** — Slice section
225
227
  - **buffer | string | array.Splice(start: integer, remove: integer, inject: array...)** — Splice section
226
228
  - **buffer | string | array.Inject(start: integer, inject: array...)** — Inject section
package/dst/Affinirum.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { funcOr, funcAnd, funcNot } from "./constant/Boolean.js";
2
- import { funcAdd } from "./constant/Enumerable.js";
2
+ import { funcAdd } from "./constant/Aggregable.js";
3
3
  import { funcAt, funcHas } from "./constant/Iterable.js";
4
4
  import { funcGreaterThan, funcLessThan, funcGreaterOrEqual, funcLessOrEqual, funcSubtract, funcMultiply, funcDivide, funcRemainder, funcPower, funcNegate } from "./constant/Number.js";
5
5
  import { funcCoalesce, funcEqual, funcNotEqual } from "./constant/Unknown.js";
package/dst/Functions.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { funcAdd } from "./constant/Aggregable.js";
1
2
  import { funcFirst, funcLast, funcFirstIndex, funcLastIndex, funcEvery, funcAny, funcFlatten, funcReverse, funcDerive, funcFilter, funcReduce, funcCompose, funcPrepend, funcAppend } from "./constant/Array.js";
2
3
  import { funcByte } from "./constant/Buffer.js";
3
- import { funcAdd, funcSlice, funcSplice, funcInject } from "./constant/Enumerable.js";
4
+ import { funcSlice, funcSplice, funcInject } from "./constant/Enumerable.js";
4
5
  import { funcLength, funcContains, funcAt, funcHas } from "./constant/Iterable.js";
5
6
  import { funcGreaterThan, funcLessThan, funcGreaterOrEqual, funcLessOrEqual, funcSubtract, funcMultiply, funcDivide, funcRemainder, funcModulo, funcPower, funcRoot, funcNegate, funcCast, funcCastToFloat, funcCastToInteger } from "./constant/Number.js";
6
7
  import { funcEntries, funcKeys, funcValues } from "./constant/Object.js";
@@ -8,6 +9,8 @@ import { funcLike, funcUnlike, funcStartsWith, funcEndsWith, funcChar, funcCharC
8
9
  import { funcYear, funcMonth, funcMonthIndex, funcWeekdayIndex, funcDay, funcHour, funcMinute, funcSecond, funcMillisecond, funcEpochTime, funcDaysSince, funcHoursSince, funcMinutesSince, funcSecondsSince } from "./constant/Timestamp.js";
9
10
  import { funcCoalesce, funcEqual, funcNotEqual, funcEncode, funcFormat } from "./constant/Unknown.js";
10
11
  export const Functions = [
12
+ // Aggregable
13
+ ["Add", funcAdd],
11
14
  // Array
12
15
  ["First", funcFirst],
13
16
  ["Last", funcLast],
@@ -26,7 +29,6 @@ export const Functions = [
26
29
  // Buffer
27
30
  ["Byte", funcByte],
28
31
  // Enumerable
29
- ["Add", funcAdd],
30
32
  ["Slice", funcSlice],
31
33
  ["Splice", funcSplice],
32
34
  ["Inject", funcInject],
@@ -1,6 +1,6 @@
1
1
  import { funcOr, funcAnd, funcNot } from "./constant/Boolean.js";
2
2
  import { parseBuffer } from "./constant/Buffer.js";
3
- import { funcAdd } from "./constant/Enumerable.js";
3
+ import { funcAdd } from "./constant/Aggregable.js";
4
4
  import { isSignSymbol, isTokenStartSymbol, isNumericSymbol, isTokenSymbol, isDateSymbol, isTimeSymbol, isDateTimeSeparatorSymbol, replaceWith } from "./constant/String.js";
5
5
  import { Constant } from "./Constant.js";
6
6
  import { funcGreaterThan, funcLessThan, funcGreaterOrEqual, funcLessOrEqual, funcSubtract, funcMultiply, funcDivide, funcRemainder, funcPower } from "./constant/Number.js";
package/dst/Value.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export type Value = undefined | null | number | boolean | Date | bigint | ArrayBuffer | string | Value[] | {
1
+ export type PrimitiveValue = undefined | null | number | boolean | Date | bigint | ArrayBuffer | string;
2
+ export type Value = PrimitiveValue | Value[] | {
2
3
  [key: string]: Value;
3
4
  } | ((...args: any[]) => Value);
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Affinirum = void 0;
4
4
  const Boolean_js_1 = require("./constant/Boolean.js");
5
- const Enumerable_js_1 = require("./constant/Enumerable.js");
5
+ const Aggregable_js_1 = require("./constant/Aggregable.js");
6
6
  const Iterable_js_1 = require("./constant/Iterable.js");
7
7
  const Number_js_1 = require("./constant/Number.js");
8
8
  const Unknown_js_1 = require("./constant/Unknown.js");
@@ -188,7 +188,7 @@ class Affinirum {
188
188
  }
189
189
  _aggregate(state, scope) {
190
190
  let node = this._product(state, scope);
191
- while (state.operator === Enumerable_js_1.funcAdd || state.operator === Number_js_1.funcSubtract) {
191
+ while (state.operator === Aggregable_js_1.funcAdd || state.operator === Number_js_1.funcSubtract) {
192
192
  const fnode = new ConstantNode_js_1.ConstantNode(state, state.operator);
193
193
  node = new FunctionNode_js_1.FunctionNode(state, fnode, [node, this._product(state.next(), scope)]);
194
194
  }
@@ -205,7 +205,7 @@ class Affinirum {
205
205
  _signum(state, scope) {
206
206
  const frame = state.starts();
207
207
  let negate = false;
208
- while (state.operator === Enumerable_js_1.funcAdd || state.operator === Number_js_1.funcSubtract) {
208
+ while (state.operator === Aggregable_js_1.funcAdd || state.operator === Number_js_1.funcSubtract) {
209
209
  if (state.operator === Number_js_1.funcSubtract) {
210
210
  negate = !negate;
211
211
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Functions = void 0;
4
+ const Aggregable_js_1 = require("./constant/Aggregable.js");
4
5
  const Array_js_1 = require("./constant/Array.js");
5
6
  const Buffer_js_1 = require("./constant/Buffer.js");
6
7
  const Enumerable_js_1 = require("./constant/Enumerable.js");
@@ -11,6 +12,8 @@ const String_js_1 = require("./constant/String.js");
11
12
  const Timestamp_js_1 = require("./constant/Timestamp.js");
12
13
  const Unknown_js_1 = require("./constant/Unknown.js");
13
14
  exports.Functions = [
15
+ // Aggregable
16
+ ["Add", Aggregable_js_1.funcAdd],
14
17
  // Array
15
18
  ["First", Array_js_1.funcFirst],
16
19
  ["Last", Array_js_1.funcLast],
@@ -29,7 +32,6 @@ exports.Functions = [
29
32
  // Buffer
30
33
  ["Byte", Buffer_js_1.funcByte],
31
34
  // Enumerable
32
- ["Add", Enumerable_js_1.funcAdd],
33
35
  ["Slice", Enumerable_js_1.funcSlice],
34
36
  ["Splice", Enumerable_js_1.funcSplice],
35
37
  ["Inject", Enumerable_js_1.funcInject],
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ParserState = void 0;
4
4
  const Boolean_js_1 = require("./constant/Boolean.js");
5
5
  const Buffer_js_1 = require("./constant/Buffer.js");
6
- const Enumerable_js_1 = require("./constant/Enumerable.js");
6
+ const Aggregable_js_1 = require("./constant/Aggregable.js");
7
7
  const String_js_1 = require("./constant/String.js");
8
8
  const Constant_js_1 = require("./Constant.js");
9
9
  const Number_js_1 = require("./constant/Number.js");
@@ -28,7 +28,7 @@ class Assignment {
28
28
  const funcAssignment = new Assignment();
29
29
  const funcOrAssignment = new Assignment(Boolean_js_1.funcOr);
30
30
  const funcAndAssignment = new Assignment(Boolean_js_1.funcAnd);
31
- const funcAddAssignment = new Assignment(Enumerable_js_1.funcAdd);
31
+ const funcAddAssignment = new Assignment(Aggregable_js_1.funcAdd);
32
32
  const funcSubtractAssignment = new Assignment(Number_js_1.funcSubtract);
33
33
  const funcMultiplyAssignment = new Assignment(Number_js_1.funcMultiply);
34
34
  const funcDivideAssignment = new Assignment(Number_js_1.funcDivide);
@@ -351,7 +351,7 @@ class ParserState extends ParserFrame_js_1.ParserFrame {
351
351
  this._fragment = funcAddAssignment;
352
352
  break;
353
353
  default:
354
- this._fragment = Enumerable_js_1.funcAdd;
354
+ this._fragment = Aggregable_js_1.funcAdd;
355
355
  break;
356
356
  }
357
357
  break;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.funcAdd = exports.aggregate = 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 == null || value2 == null) {
9
+ return undefined;
10
+ }
11
+ if (value1 instanceof ArrayBuffer && value2 instanceof ArrayBuffer) {
12
+ return (0, Buffer_js_1.concatBuffers)(value1, value2);
13
+ }
14
+ if (typeof value1 === "string" && typeof value2 === "string") {
15
+ return value1.concat(value2);
16
+ }
17
+ return [value1].flat().concat([value2].flat());
18
+ };
19
+ exports.aggregate = aggregate;
20
+ const add = (value1, value2) => {
21
+ if (typeof value1 === "bigint" && typeof value2 === "bigint") {
22
+ return BigInt.asIntN(64, value1 + value2);
23
+ }
24
+ if ((typeof value1 === "number" || typeof value1 === "bigint") && (typeof value2 === "number" || typeof value2 === "bigint")) {
25
+ return Number(value1) + Number(value2);
26
+ }
27
+ return (0, exports.aggregate)(value1, value2);
28
+ };
29
+ 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])));
@@ -48,7 +48,7 @@ exports.funcDerive = new Constant_js_1.Constant((value, transform) => value?.map
48
48
  exports.funcFilter = new Constant_js_1.Constant((value, predicate) => value?.filter((v, i, a) => predicate(v, BigInt(i), a)), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array, typePredicate]));
49
49
  exports.funcReduce = new Constant_js_1.Constant((value, reducer, initial) => initial != null
50
50
  ? value?.reduce((p, v, i, a) => reducer(p, v, BigInt(i), a), initial)
51
- : value?.reduce((p, v, i, a) => reducer(p, v, BigInt(i), a)), Type_js_1.Type.functionType(Type_js_1.Type.Unknown, [Type_js_1.Type.Array, Type_js_1.Type.functionType(Type_js_1.Type.Unknown, [Type_js_1.Type.Unknown, Type_js_1.Type.Unknown, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalArray])]));
51
+ : value?.reduce((p, v, i, a) => reducer(p, v, BigInt(i), a)), Type_js_1.Type.functionType(Type_js_1.Type.Unknown, [Type_js_1.Type.Array, Type_js_1.Type.functionType(Type_js_1.Type.Unknown, [Type_js_1.Type.Unknown, Type_js_1.Type.Unknown, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalArray]), Type_js_1.Type.Unknown]));
52
52
  exports.funcCompose = new Constant_js_1.Constant((value, callback) => {
53
53
  if (value == null) {
54
54
  return undefined;
@@ -68,7 +68,7 @@ exports.funcAppend = new Constant_js_1.Constant((value, ...items) => {
68
68
  value?.push(items);
69
69
  return value;
70
70
  }, typeVariadicInsert);
71
- const funcJoin = new Constant_js_1.Constant((...values) => values.flat(Infinity).reduce((acc, val) => [...acc, val], []), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array], true));
71
+ const funcJoin = new Constant_js_1.Constant((...values) => values.flat(Infinity), Type_js_1.Type.functionType(Type_js_1.Type.Array, [Type_js_1.Type.Array], true));
72
72
  const funcRange = new Constant_js_1.Constant((value1, value2) => {
73
73
  const min = value1 < value2 ? value1 : value2;
74
74
  const max = value1 > value2 ? value1 : value2;
@@ -72,10 +72,20 @@ const concatBuffers = (value1, value2) => {
72
72
  return bytes.buffer;
73
73
  };
74
74
  exports.concatBuffers = concatBuffers;
75
- const formatBuffer = (value) => {
75
+ const formatBuffer = (value, formatting = "hex") => {
76
76
  if (value == null) {
77
77
  return "";
78
78
  }
79
+ if (formatting === "base64") {
80
+ let binary = "";
81
+ const bytes = new Uint8Array(value);
82
+ const chunkSize = 0x4000;
83
+ for (let i = 0; i < bytes.length; i += chunkSize) {
84
+ const chunk = bytes.subarray(i, i + chunkSize);
85
+ binary += String.fromCharCode(...chunk);
86
+ }
87
+ return btoa(binary);
88
+ }
79
89
  const bytes = new Uint8Array(value);
80
90
  let str = "";
81
91
  for (let i = 0; i < bytes.byteLength; ++i) {
@@ -1,37 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.funcInject = exports.funcSplice = exports.funcSlice = exports.funcAdd = void 0;
3
+ exports.funcInject = exports.funcSplice = exports.funcSlice = void 0;
4
4
  const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
- const Buffer_js_1 = require("./Buffer.js");
7
- const aggregate = (value1, value2) => {
8
- if (value1 == null || value2 == null) {
9
- return undefined;
10
- }
11
- if (value1 instanceof ArrayBuffer && value2 instanceof ArrayBuffer) {
12
- return (0, Buffer_js_1.concatBuffers)(value1, value2);
13
- }
14
- if (typeof value1 === "string" && typeof value2 === "string") {
15
- return value1.concat(value2);
16
- }
17
- return [value1].flat().concat([value2].flat());
18
- };
19
- const add = (value1, value2) => {
20
- if (typeof value1 === "bigint" && typeof value2 === "bigint") {
21
- return BigInt.asIntN(64, value1 + value2);
22
- }
23
- if ((typeof value1 === "number" || typeof value1 === "bigint") && (typeof value2 === "number" || typeof value2 === "bigint")) {
24
- return Number(value1) + Number(value2);
25
- }
26
- return aggregate(value1, value2);
27
- };
28
- 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])));
6
+ const Aggregable_js_1 = require("./Aggregable.js");
29
7
  exports.funcSlice = new Constant_js_1.Constant((value, start = 0n, end) => value == null
30
8
  ? undefined
31
9
  : 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])));
32
10
  exports.funcSplice = new Constant_js_1.Constant((value, start, remove, ...inject) => value == null
33
11
  ? undefined
34
- : 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)));
12
+ : (0, Aggregable_js_1.aggregate)(inject.reduce((acc, val) => (0, Aggregable_js_1.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)));
35
13
  exports.funcInject = new Constant_js_1.Constant((value, start, ...inject) => value == null
36
14
  ? undefined
37
- : 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)));
15
+ : (0, Aggregable_js_1.aggregate)(inject.reduce((acc, val) => (0, Aggregable_js_1.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)));
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.constFloat = exports.formatReal = exports.encodeFloat = void 0;
3
+ exports.constFloat = 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") => {
@@ -46,8 +46,6 @@ const decodeFloat = (value, encoding = "f64", byteOffset) => {
46
46
  default: throw new Error(`${encoding} encoding not supported`);
47
47
  }
48
48
  };
49
- const formatReal = (value, radix) => value.toString(radix) + (Number.isInteger(value) ? ".0" : "");
50
- exports.formatReal = formatReal;
51
49
  const typeNumberOrArray = Type_js_1.Type.union(Type_js_1.Type.Float, Type_js_1.Type.arrayType([Type_js_1.Type.Float]));
52
50
  const typeAggregator = Type_js_1.Type.functionType(Type_js_1.Type.Float, [typeNumberOrArray], true);
53
51
  const typeTransform = Type_js_1.Type.functionType(Type_js_1.Type.Float, [Type_js_1.Type.Float]);
@@ -1,8 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.funcCastToInteger = exports.funcCastToFloat = 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;
3
+ exports.funcCastToInteger = exports.funcCastToFloat = 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 = exports.formatNumber = void 0;
4
4
  const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
+ const formatNumber = (value, formatting) => {
7
+ if (formatting) {
8
+ const nformat = JSON.parse(`{${formatting}}`);
9
+ if (typeof nformat === "object") {
10
+ return new Intl.NumberFormat(undefined, {
11
+ minimumIntegerDigits: nformat?.min_integer_digits,
12
+ minimumFractionDigits: nformat?.min_fraction_digits,
13
+ maximumFractionDigits: nformat?.max_fraction_digits,
14
+ minimumSignificantDigits: nformat?.min_significant_digits,
15
+ maximumSignificantDigits: nformat?.max_significant_digits,
16
+ notation: nformat?.notation,
17
+ }).format(value);
18
+ }
19
+ }
20
+ return typeof value === "number" && Number.isInteger(value)
21
+ ? `${value.toString()}.0`
22
+ : value.toString();
23
+ };
24
+ exports.formatNumber = formatNumber;
6
25
  const castToInteger = (value) => {
7
26
  if (value == null || Number.isNaN(value)) {
8
27
  return 0n;
@@ -168,14 +168,12 @@ const encodeString = (value, encoding = "utf8") => {
168
168
  if (encoding === "utf8") {
169
169
  return new TextEncoder().encode(value).buffer;
170
170
  }
171
- else {
172
- const dv = new DataView(new Uint16Array(value.length).buffer);
173
- const lessOrEqual = encoding.endsWith("le");
174
- for (let i = 0; i < value.length; ++i) {
175
- dv.setUint16(i << 1, value.charCodeAt(i), lessOrEqual);
176
- }
177
- return dv.buffer;
171
+ const dv = new DataView(new Uint16Array(value.length).buffer);
172
+ const lessOrEqual = encoding.endsWith("le");
173
+ for (let i = 0; i < value.length; ++i) {
174
+ dv.setUint16(i << 1, value.charCodeAt(i), lessOrEqual);
178
175
  }
176
+ return dv.buffer;
179
177
  };
180
178
  exports.encodeString = encodeString;
181
179
  const decodeString = (value, encoding = "utf8", byteOffset, byteLength) => {
@@ -14,21 +14,43 @@ const encodeTimestamp = (value, encoding = "int64") => {
14
14
  exports.encodeTimestamp = encodeTimestamp;
15
15
  const decodeTimestamp = (value, encoding = "int64", byteOffset) => value ? new Date(Number(new DataView(value).getBigInt64(byteOffset == null ? 0 : Number(byteOffset), encoding === "int64le"))) : undefined;
16
16
  exports.decodeTimestamp = decodeTimestamp;
17
- const formatTimestamp = (value, radix) => {
17
+ const formatTimestamp = (value, template) => {
18
18
  if (value == null) {
19
19
  return "";
20
20
  }
21
- const str = value.toISOString();
22
- switch (radix) {
23
- case 1: return str.slice(0, 4);
24
- case 2: return str.slice(5, 7);
25
- case 3: return str.slice(8, 10);
26
- case 4: return str.slice(11, 13);
27
- case 5: return str.slice(14, 16);
28
- case 6: return str.slice(17, 19);
29
- case 7: return str.slice(20, 23);
30
- default: return str;
21
+ if (!template || typeof template !== "string") {
22
+ return value.toISOString();
31
23
  }
24
+ const map = template.includes("Z")
25
+ ? {
26
+ YYYY: value.getUTCFullYear(),
27
+ YY: value.getUTCFullYear() % 100,
28
+ MM: value.getUTCMonth() + 1,
29
+ DD: value.getUTCDate(),
30
+ hh: value.getUTCHours(),
31
+ mm: value.getUTCMinutes(),
32
+ ss: value.getUTCSeconds(),
33
+ fff: value.getUTCMilliseconds(),
34
+ }
35
+ : {
36
+ YYYY: value.getFullYear(),
37
+ YY: value.getFullYear() % 100,
38
+ MM: value.getMonth() + 1,
39
+ DD: value.getDate(),
40
+ hh: value.getHours(),
41
+ mm: value.getMinutes(),
42
+ ss: value.getSeconds(),
43
+ fff: value.getMilliseconds(),
44
+ };
45
+ return template.replaceAll("Z", "")
46
+ .replace("YYYY", map.YYYY.toString())
47
+ .replace("YY", map.YY.toString().padStart(2, "0"))
48
+ .replace("MM", map.MM.toString().padStart(2, "0"))
49
+ .replace("DD", map.DD.toString().padStart(2, "0"))
50
+ .replace("hh", map.hh.toString().padStart(2, "0"))
51
+ .replace("mm", map.mm.toString().padStart(2, "0"))
52
+ .replace("ss", map.ss.toString().padStart(2, "0"))
53
+ .replace("fff", map.fff.toString().padStart(3, "0"));
32
54
  };
33
55
  exports.formatTimestamp = formatTimestamp;
34
56
  const parseTimestamp = (value) => {
@@ -5,6 +5,7 @@ const Constant_js_1 = require("../Constant.js");
5
5
  const Type_js_1 = require("../Type.js");
6
6
  const Float_js_1 = require("./Float.js");
7
7
  const Integer_js_1 = require("./Integer.js");
8
+ const Number_js_1 = require("./Number.js");
8
9
  const Buffer_js_1 = require("./Buffer.js");
9
10
  const String_js_1 = require("./String.js");
10
11
  const Timestamp_js_1 = require("./Timestamp.js");
@@ -70,32 +71,36 @@ const encode = (value, encoding) => value == null
70
71
  : Array.isArray(value)
71
72
  ? value.map((i) => (0, exports.encode)(i, encoding)).reduce((acc, val) => (0, Buffer_js_1.concatBuffers)(acc, val))
72
73
  : typeof value === "object"
73
- ? Object.entries(value).map(([k, v]) => (0, Buffer_js_1.concatBuffers)((0, exports.encode)(k, encoding), (0, exports.encode)(v, encoding))).reduce((acc, val) => (0, Buffer_js_1.concatBuffers)(acc, val))
74
+ ? Object.entries(value)
75
+ .map(([k, v]) => (0, Buffer_js_1.concatBuffers)((0, exports.encode)(k, encoding), (0, exports.encode)(v, encoding)))
76
+ .reduce((acc, val) => (0, Buffer_js_1.concatBuffers)(acc, val))
74
77
  : new Uint8Array(0).buffer;
75
78
  exports.encode = encode;
76
- const format = (value, radix, separator = "") => value == null
79
+ const format = (value, formatting) => value == null
77
80
  ? "null"
78
81
  : typeof value === "boolean"
79
82
  ? value.toString()
80
83
  : value instanceof Date
81
- ? (0, Timestamp_js_1.formatTimestamp)(value, radix ? Number(radix) : undefined)
84
+ ? (0, Timestamp_js_1.formatTimestamp)(value, formatting)
82
85
  : typeof value === "number"
83
- ? (0, Float_js_1.formatReal)(value, radix ? Number(radix) : undefined)
86
+ ? (0, Number_js_1.formatNumber)(value, formatting)
84
87
  : typeof value === "bigint"
85
- ? value.toString(radix ? Number(radix) : undefined)
88
+ ? (0, Number_js_1.formatNumber)(value, formatting)
86
89
  : value instanceof ArrayBuffer
87
- ? (0, Buffer_js_1.formatBuffer)(value)
90
+ ? (0, Buffer_js_1.formatBuffer)(value, formatting)
88
91
  : typeof value === "string"
89
92
  ? value
90
93
  : Array.isArray(value)
91
- ? value.map((i) => (0, exports.format)(i, radix)).join(separator)
94
+ ? value.map((i) => (0, exports.format)(i, formatting)).reduce((acc, val) => acc + val)
92
95
  : typeof value === "object"
93
- ? Object.entries(value).map(([k, v]) => `${(0, exports.format)(k)}${radix}${(0, exports.format)(v)}`).join(separator)
96
+ ? Object.entries(value)
97
+ .map(([k, v]) => (0, exports.format)(k, formatting) + (0, exports.format)(v, formatting))
98
+ .reduce((acc, val) => acc + val)
94
99
  : "function";
95
100
  exports.format = format;
96
101
  const typeEquator = Type_js_1.Type.functionType(Type_js_1.Type.Boolean, [Type_js_1.Type.Unknown, Type_js_1.Type.Unknown]);
97
102
  exports.funcCoalesce = new Constant_js_1.Constant((value, valueOtherwise) => value ?? valueOtherwise, Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Unknown, [Type_js_1.Type.Unknown, Type_js_1.Type.Unknown]), Type_js_1.Type.functionType(Type_js_1.Type.OptionalFloat, [Type_js_1.Type.OptionalFloat, Type_js_1.Type.OptionalFloat]), Type_js_1.Type.functionType(Type_js_1.Type.OptionalBoolean, [Type_js_1.Type.OptionalBoolean, Type_js_1.Type.OptionalBoolean]), Type_js_1.Type.functionType(Type_js_1.Type.OptionalTimestamp, [Type_js_1.Type.OptionalTimestamp, Type_js_1.Type.OptionalTimestamp]), Type_js_1.Type.functionType(Type_js_1.Type.OptionalInteger, [Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalInteger]), Type_js_1.Type.functionType(Type_js_1.Type.OptionalBuffer, [Type_js_1.Type.OptionalBuffer, Type_js_1.Type.OptionalBuffer]), Type_js_1.Type.functionType(Type_js_1.Type.OptionalString, [Type_js_1.Type.OptionalString, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.OptionalArray, [Type_js_1.Type.OptionalArray, Type_js_1.Type.OptionalArray]), Type_js_1.Type.functionType(Type_js_1.Type.OptionalObject, [Type_js_1.Type.OptionalObject, Type_js_1.Type.OptionalObject]), Type_js_1.Type.functionType(Type_js_1.Type.OptionalFunction, [Type_js_1.Type.OptionalFunction, Type_js_1.Type.OptionalFunction])));
98
103
  exports.funcEqual = new Constant_js_1.Constant((value1, value2) => (0, exports.equate)(value1, value2), typeEquator);
99
104
  exports.funcNotEqual = new Constant_js_1.Constant((value1, value2) => !(0, exports.equate)(value1, value2), typeEquator);
100
- exports.funcEncode = new Constant_js_1.Constant((value, encoding) => (0, exports.encode)(value, encoding), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Boolean]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Timestamp, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Float, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Integer, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.String, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Array, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Object, Type_js_1.Type.OptionalString])));
101
- exports.funcFormat = new Constant_js_1.Constant((value, radix, separator = "") => (0, exports.format)(value, radix == null ? undefined : Number(radix), separator), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Boolean]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Timestamp, Type_js_1.Type.OptionalInteger]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Float, Type_js_1.Type.OptionalInteger]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Integer, Type_js_1.Type.OptionalInteger]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Buffer]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Array, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Object, Type_js_1.Type.OptionalInteger, Type_js_1.Type.OptionalString])));
105
+ exports.funcEncode = new Constant_js_1.Constant((value, encoding) => (0, exports.encode)(value, encoding), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Boolean]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Timestamp, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Float, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Integer, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Buffer]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.String, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Array, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Object, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.Buffer, [Type_js_1.Type.Function])));
106
+ exports.funcFormat = new Constant_js_1.Constant((value, formatting) => (0, exports.format)(value, formatting), Type_js_1.Type.union(Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Boolean]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Timestamp, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Float, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Integer, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Buffer, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.String]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Array, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Object, Type_js_1.Type.OptionalString]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Function])));
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.constAN = exports.formatAN = void 0;
4
4
  const Constant_js_1 = require("../../Constant.js");
5
5
  const Type_js_1 = require("../../Type.js");
6
- const Float_js_1 = require("../Float.js");
6
+ const Number_js_1 = require("../Number.js");
7
7
  const Buffer_js_1 = require("../Buffer.js");
8
8
  const formatAN = (value, whitespace) => {
9
9
  if (value == null) {
@@ -16,10 +16,10 @@ const formatAN = (value, whitespace) => {
16
16
  return `@${value.toISOString()}`;
17
17
  }
18
18
  if (typeof value === "number") {
19
- return (0, Float_js_1.formatReal)(value);
19
+ return (0, Number_js_1.formatNumber)(value);
20
20
  }
21
21
  if (typeof value === "bigint") {
22
- return value.toString();
22
+ return (0, Number_js_1.formatNumber)(value);
23
23
  }
24
24
  if (value instanceof ArrayBuffer) {
25
25
  return `#${(0, Buffer_js_1.formatBuffer)(value)}`;
@@ -0,0 +1,4 @@
1
+ import { Constant } from "../Constant.js";
2
+ import { Value } from "../Value.js";
3
+ export declare const aggregate: (value1: ArrayBuffer | string | Value[] | null | undefined, value2: ArrayBuffer | string | Value[] | null | undefined) => string | ArrayBuffer | Value[] | undefined;
4
+ export declare const funcAdd: Constant;
@@ -0,0 +1,25 @@
1
+ import { Constant } from "../Constant.js";
2
+ import { Type } from "../Type.js";
3
+ import { concatBuffers } from "./Buffer.js";
4
+ export const aggregate = (value1, value2) => {
5
+ if (value1 == null || value2 == null) {
6
+ return undefined;
7
+ }
8
+ if (value1 instanceof ArrayBuffer && value2 instanceof ArrayBuffer) {
9
+ return 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 value1 === "bigint") && (typeof value2 === "number" || typeof value2 === "bigint")) {
21
+ return Number(value1) + Number(value2);
22
+ }
23
+ return aggregate(value1, value2);
24
+ };
25
+ export const funcAdd = new Constant((value1, value2) => add(value1, value2), Type.union(Type.functionType(Type.Float, [Type.Float, Type.Integer]), Type.functionType(Type.Float, [Type.Integer, Type.Float]), Type.functionType(Type.Integer, [Type.Integer, Type.Integer]), Type.functionType(Type.Buffer, [Type.Buffer, Type.Buffer]), Type.functionType(Type.String, [Type.String, Type.String]), Type.functionType(Type.Array, [Type.Array, Type.Array])));
@@ -45,7 +45,7 @@ export const funcDerive = new Constant((value, transform) => value?.map((v, i, a
45
45
  export const funcFilter = new Constant((value, predicate) => value?.filter((v, i, a) => predicate(v, BigInt(i), a)), Type.functionType(Type.Array, [Type.Array, typePredicate]));
46
46
  export const funcReduce = new Constant((value, reducer, initial) => initial != null
47
47
  ? value?.reduce((p, v, i, a) => reducer(p, v, BigInt(i), a), initial)
48
- : value?.reduce((p, v, i, a) => reducer(p, v, BigInt(i), a)), Type.functionType(Type.Unknown, [Type.Array, Type.functionType(Type.Unknown, [Type.Unknown, Type.Unknown, Type.OptionalInteger, Type.OptionalArray])]));
48
+ : value?.reduce((p, v, i, a) => reducer(p, v, BigInt(i), a)), Type.functionType(Type.Unknown, [Type.Array, Type.functionType(Type.Unknown, [Type.Unknown, Type.Unknown, Type.OptionalInteger, Type.OptionalArray]), Type.Unknown]));
49
49
  export const funcCompose = new Constant((value, callback) => {
50
50
  if (value == null) {
51
51
  return undefined;
@@ -65,7 +65,7 @@ export const funcAppend = new Constant((value, ...items) => {
65
65
  value?.push(items);
66
66
  return value;
67
67
  }, typeVariadicInsert);
68
- const funcJoin = new Constant((...values) => values.flat(Infinity).reduce((acc, val) => [...acc, val], []), Type.functionType(Type.Array, [Type.Array], true));
68
+ const funcJoin = new Constant((...values) => values.flat(Infinity), Type.functionType(Type.Array, [Type.Array], true));
69
69
  const funcRange = new Constant((value1, value2) => {
70
70
  const min = value1 < value2 ? value1 : value2;
71
71
  const max = value1 > value2 ? value1 : value2;
@@ -1,8 +1,9 @@
1
1
  import { Constant } from "../Constant.js";
2
+ export type BufferFormatting = "hex" | "base64";
2
3
  export declare const equateBuffers: (value1: ArrayBuffer, value2: ArrayBuffer) => boolean;
3
4
  export declare const containsBuffer: (value: ArrayBuffer, search: ArrayBuffer, startPos?: number) => boolean;
4
5
  export declare const concatBuffers: (value1: ArrayBuffer, value2: ArrayBuffer) => ArrayBuffer;
5
- export declare const formatBuffer: (value?: ArrayBuffer) => string;
6
+ export declare const formatBuffer: (value?: ArrayBuffer, formatting?: BufferFormatting) => string;
6
7
  export declare const parseBuffer: (value?: string) => ArrayBuffer | undefined;
7
8
  export declare const funcByte: Constant;
8
9
  export declare const constBuffer: {
@@ -66,10 +66,20 @@ export const concatBuffers = (value1, value2) => {
66
66
  bytes.set(new Uint8Array(value2), value1.byteLength);
67
67
  return bytes.buffer;
68
68
  };
69
- export const formatBuffer = (value) => {
69
+ export const formatBuffer = (value, formatting = "hex") => {
70
70
  if (value == null) {
71
71
  return "";
72
72
  }
73
+ if (formatting === "base64") {
74
+ let binary = "";
75
+ const bytes = new Uint8Array(value);
76
+ const chunkSize = 0x4000;
77
+ for (let i = 0; i < bytes.length; i += chunkSize) {
78
+ const chunk = bytes.subarray(i, i + chunkSize);
79
+ binary += String.fromCharCode(...chunk);
80
+ }
81
+ return btoa(binary);
82
+ }
73
83
  const bytes = new Uint8Array(value);
74
84
  let str = "";
75
85
  for (let i = 0; i < bytes.byteLength; ++i) {
@@ -1,5 +1,4 @@
1
1
  import { Constant } from "../Constant.js";
2
- export declare const funcAdd: Constant;
3
2
  export declare const funcSlice: Constant;
4
3
  export declare const funcSplice: Constant;
5
4
  export declare const funcInject: Constant;
@@ -1,28 +1,6 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  import { Type } from "../Type.js";
3
- import { concatBuffers } from "./Buffer.js";
4
- const aggregate = (value1, value2) => {
5
- if (value1 == null || value2 == null) {
6
- return undefined;
7
- }
8
- if (value1 instanceof ArrayBuffer && value2 instanceof ArrayBuffer) {
9
- return 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 value1 === "bigint") && (typeof value2 === "number" || typeof value2 === "bigint")) {
21
- return Number(value1) + Number(value2);
22
- }
23
- return aggregate(value1, value2);
24
- };
25
- export const funcAdd = new Constant((value1, value2) => add(value1, value2), Type.union(Type.functionType(Type.Float, [Type.Float, Type.Integer]), Type.functionType(Type.Float, [Type.Integer, Type.Float]), Type.functionType(Type.Integer, [Type.Integer, Type.Integer]), Type.functionType(Type.Buffer, [Type.Buffer, Type.Buffer]), Type.functionType(Type.String, [Type.String, Type.String]), Type.functionType(Type.Array, [Type.Array, Type.Array])));
3
+ import { aggregate } from "./Aggregable.js";
26
4
  export const funcSlice = new Constant((value, start = 0n, end) => value == null
27
5
  ? undefined
28
6
  : value.slice(Number(start), end == null ? undefined : Number(end)), Type.union(Type.functionType(Type.Buffer, [Type.Buffer, Type.OptionalInteger, Type.OptionalInteger]), Type.functionType(Type.String, [Type.String, Type.OptionalInteger, Type.OptionalInteger]), Type.functionType(Type.Array, [Type.Array, Type.OptionalInteger, Type.OptionalInteger])));
@@ -1,7 +1,6 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  export type FloatEncoding = "f32" | "f32le" | "f64" | "f64le";
3
3
  export declare const encodeFloat: (value?: number, encoding?: FloatEncoding) => ArrayBuffer;
4
- export declare const formatReal: (value: number, radix?: number) => string;
5
4
  export declare const constFloat: {
6
5
  NAN: Constant;
7
6
  PositiveInfinity: Constant;
@@ -42,7 +42,6 @@ const decodeFloat = (value, encoding = "f64", byteOffset) => {
42
42
  default: throw new Error(`${encoding} encoding not supported`);
43
43
  }
44
44
  };
45
- export const formatReal = (value, radix) => value.toString(radix) + (Number.isInteger(value) ? ".0" : "");
46
45
  const typeNumberOrArray = Type.union(Type.Float, Type.arrayType([Type.Float]));
47
46
  const typeAggregator = Type.functionType(Type.Float, [typeNumberOrArray], true);
48
47
  const typeTransform = Type.functionType(Type.Float, [Type.Float]);
@@ -1,4 +1,13 @@
1
1
  import { Constant } from "../Constant.js";
2
+ export interface NumberFormatting {
3
+ min_integer_digits?: number;
4
+ min_fraction_digits?: number;
5
+ max_fraction_digits?: number;
6
+ min_significant_digits?: number;
7
+ max_significant_digits?: number;
8
+ notation?: "standard" | "scientific";
9
+ }
10
+ export declare const formatNumber: (value: bigint | number, formatting?: string) => string;
2
11
  export declare const funcGreaterThan: Constant;
3
12
  export declare const funcLessThan: Constant;
4
13
  export declare const funcGreaterOrEqual: Constant;
@@ -1,5 +1,23 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  import { Type } from "../Type.js";
3
+ export const formatNumber = (value, formatting) => {
4
+ if (formatting) {
5
+ const nformat = JSON.parse(`{${formatting}}`);
6
+ if (typeof nformat === "object") {
7
+ return new Intl.NumberFormat(undefined, {
8
+ minimumIntegerDigits: nformat?.min_integer_digits,
9
+ minimumFractionDigits: nformat?.min_fraction_digits,
10
+ maximumFractionDigits: nformat?.max_fraction_digits,
11
+ minimumSignificantDigits: nformat?.min_significant_digits,
12
+ maximumSignificantDigits: nformat?.max_significant_digits,
13
+ notation: nformat?.notation,
14
+ }).format(value);
15
+ }
16
+ }
17
+ return typeof value === "number" && Number.isInteger(value)
18
+ ? `${value.toString()}.0`
19
+ : value.toString();
20
+ };
3
21
  const castToInteger = (value) => {
4
22
  if (value == null || Number.isNaN(value)) {
5
23
  return 0n;
@@ -149,14 +149,12 @@ export const encodeString = (value, encoding = "utf8") => {
149
149
  if (encoding === "utf8") {
150
150
  return new TextEncoder().encode(value).buffer;
151
151
  }
152
- else {
153
- const dv = new DataView(new Uint16Array(value.length).buffer);
154
- const lessOrEqual = encoding.endsWith("le");
155
- for (let i = 0; i < value.length; ++i) {
156
- dv.setUint16(i << 1, value.charCodeAt(i), lessOrEqual);
157
- }
158
- return dv.buffer;
152
+ const dv = new DataView(new Uint16Array(value.length).buffer);
153
+ const lessOrEqual = encoding.endsWith("le");
154
+ for (let i = 0; i < value.length; ++i) {
155
+ dv.setUint16(i << 1, value.charCodeAt(i), lessOrEqual);
159
156
  }
157
+ return dv.buffer;
160
158
  };
161
159
  const decodeString = (value, encoding = "utf8", byteOffset, byteLength) => {
162
160
  if (value == null) {
@@ -2,7 +2,7 @@ import { Constant } from "../Constant.js";
2
2
  export type TimestampEncoding = "int64" | "int64le";
3
3
  export declare const encodeTimestamp: (value?: Date, encoding?: TimestampEncoding) => ArrayBuffer;
4
4
  export declare const decodeTimestamp: (value?: ArrayBuffer, encoding?: TimestampEncoding, byteOffset?: bigint) => Date | undefined;
5
- export declare const formatTimestamp: (value?: Date, radix?: number) => string;
5
+ export declare const formatTimestamp: (value?: Date, template?: string) => string;
6
6
  export declare const funcYear: Constant;
7
7
  export declare const funcMonth: Constant;
8
8
  export declare const funcMonthIndex: Constant;
@@ -9,21 +9,43 @@ export const encodeTimestamp = (value, encoding = "int64") => {
9
9
  return buf;
10
10
  };
11
11
  export const decodeTimestamp = (value, encoding = "int64", byteOffset) => value ? new Date(Number(new DataView(value).getBigInt64(byteOffset == null ? 0 : Number(byteOffset), encoding === "int64le"))) : undefined;
12
- export const formatTimestamp = (value, radix) => {
12
+ export const formatTimestamp = (value, template) => {
13
13
  if (value == null) {
14
14
  return "";
15
15
  }
16
- const str = value.toISOString();
17
- switch (radix) {
18
- case 1: return str.slice(0, 4);
19
- case 2: return str.slice(5, 7);
20
- case 3: return str.slice(8, 10);
21
- case 4: return str.slice(11, 13);
22
- case 5: return str.slice(14, 16);
23
- case 6: return str.slice(17, 19);
24
- case 7: return str.slice(20, 23);
25
- default: return str;
16
+ if (!template || typeof template !== "string") {
17
+ return value.toISOString();
26
18
  }
19
+ const map = template.includes("Z")
20
+ ? {
21
+ YYYY: value.getUTCFullYear(),
22
+ YY: value.getUTCFullYear() % 100,
23
+ MM: value.getUTCMonth() + 1,
24
+ DD: value.getUTCDate(),
25
+ hh: value.getUTCHours(),
26
+ mm: value.getUTCMinutes(),
27
+ ss: value.getUTCSeconds(),
28
+ fff: value.getUTCMilliseconds(),
29
+ }
30
+ : {
31
+ YYYY: value.getFullYear(),
32
+ YY: value.getFullYear() % 100,
33
+ MM: value.getMonth() + 1,
34
+ DD: value.getDate(),
35
+ hh: value.getHours(),
36
+ mm: value.getMinutes(),
37
+ ss: value.getSeconds(),
38
+ fff: value.getMilliseconds(),
39
+ };
40
+ return template.replaceAll("Z", "")
41
+ .replace("YYYY", map.YYYY.toString())
42
+ .replace("YY", map.YY.toString().padStart(2, "0"))
43
+ .replace("MM", map.MM.toString().padStart(2, "0"))
44
+ .replace("DD", map.DD.toString().padStart(2, "0"))
45
+ .replace("hh", map.hh.toString().padStart(2, "0"))
46
+ .replace("mm", map.mm.toString().padStart(2, "0"))
47
+ .replace("ss", map.ss.toString().padStart(2, "0"))
48
+ .replace("fff", map.fff.toString().padStart(3, "0"));
27
49
  };
28
50
  const parseTimestamp = (value) => {
29
51
  if (value == null) {
@@ -6,7 +6,7 @@ import { StringEncoding } from "./String.js";
6
6
  import { TimestampEncoding } from "./Timestamp.js";
7
7
  export declare const equate: (value1: Value, value2: Value) => boolean;
8
8
  export declare const encode: (value: Value, encoding?: FloatEncoding | IntegerEncoding | TimestampEncoding | StringEncoding) => ArrayBuffer;
9
- export declare const format: (value: Value, radix?: number, separator?: string) => string;
9
+ export declare const format: (value: Value, formatting?: string) => string;
10
10
  export declare const funcCoalesce: Constant;
11
11
  export declare const funcEqual: Constant;
12
12
  export declare const funcNotEqual: Constant;
@@ -1,8 +1,9 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  import { Type } from "../Type.js";
3
- import { encodeFloat, formatReal } from "./Float.js";
3
+ import { encodeFloat } from "./Float.js";
4
4
  import { encodeInteger } from "./Integer.js";
5
- import { concatBuffers, equateBuffers, formatBuffer } from "./Buffer.js";
5
+ import { formatNumber } from "./Number.js";
6
+ import { formatBuffer, concatBuffers, equateBuffers } from "./Buffer.js";
6
7
  import { encodeString } from "./String.js";
7
8
  import { encodeTimestamp, formatTimestamp } from "./Timestamp.js";
8
9
  export const equate = (value1, value2) => {
@@ -66,30 +67,34 @@ export const encode = (value, encoding) => value == null
66
67
  : Array.isArray(value)
67
68
  ? value.map((i) => encode(i, encoding)).reduce((acc, val) => concatBuffers(acc, val))
68
69
  : typeof value === "object"
69
- ? Object.entries(value).map(([k, v]) => concatBuffers(encode(k, encoding), encode(v, encoding))).reduce((acc, val) => concatBuffers(acc, val))
70
+ ? Object.entries(value)
71
+ .map(([k, v]) => concatBuffers(encode(k, encoding), encode(v, encoding)))
72
+ .reduce((acc, val) => concatBuffers(acc, val))
70
73
  : new Uint8Array(0).buffer;
71
- export const format = (value, radix, separator = "") => value == null
74
+ export const format = (value, formatting) => value == null
72
75
  ? "null"
73
76
  : typeof value === "boolean"
74
77
  ? value.toString()
75
78
  : value instanceof Date
76
- ? formatTimestamp(value, radix ? Number(radix) : undefined)
79
+ ? formatTimestamp(value, formatting)
77
80
  : typeof value === "number"
78
- ? formatReal(value, radix ? Number(radix) : undefined)
81
+ ? formatNumber(value, formatting)
79
82
  : typeof value === "bigint"
80
- ? value.toString(radix ? Number(radix) : undefined)
83
+ ? formatNumber(value, formatting)
81
84
  : value instanceof ArrayBuffer
82
- ? formatBuffer(value)
85
+ ? formatBuffer(value, formatting)
83
86
  : typeof value === "string"
84
87
  ? value
85
88
  : Array.isArray(value)
86
- ? value.map((i) => format(i, radix)).join(separator)
89
+ ? value.map((i) => format(i, formatting)).reduce((acc, val) => acc + val)
87
90
  : typeof value === "object"
88
- ? Object.entries(value).map(([k, v]) => `${format(k)}${radix}${format(v)}`).join(separator)
91
+ ? Object.entries(value)
92
+ .map(([k, v]) => format(k, formatting) + format(v, formatting))
93
+ .reduce((acc, val) => acc + val)
89
94
  : "function";
90
95
  const typeEquator = Type.functionType(Type.Boolean, [Type.Unknown, Type.Unknown]);
91
96
  export const funcCoalesce = new Constant((value, valueOtherwise) => value ?? valueOtherwise, Type.union(Type.functionType(Type.Unknown, [Type.Unknown, Type.Unknown]), Type.functionType(Type.OptionalFloat, [Type.OptionalFloat, Type.OptionalFloat]), Type.functionType(Type.OptionalBoolean, [Type.OptionalBoolean, Type.OptionalBoolean]), Type.functionType(Type.OptionalTimestamp, [Type.OptionalTimestamp, Type.OptionalTimestamp]), Type.functionType(Type.OptionalInteger, [Type.OptionalInteger, Type.OptionalInteger]), Type.functionType(Type.OptionalBuffer, [Type.OptionalBuffer, Type.OptionalBuffer]), Type.functionType(Type.OptionalString, [Type.OptionalString, Type.OptionalString]), Type.functionType(Type.OptionalArray, [Type.OptionalArray, Type.OptionalArray]), Type.functionType(Type.OptionalObject, [Type.OptionalObject, Type.OptionalObject]), Type.functionType(Type.OptionalFunction, [Type.OptionalFunction, Type.OptionalFunction])));
92
97
  export const funcEqual = new Constant((value1, value2) => equate(value1, value2), typeEquator);
93
98
  export const funcNotEqual = new Constant((value1, value2) => !equate(value1, value2), typeEquator);
94
- export const funcEncode = new Constant((value, encoding) => encode(value, encoding), Type.union(Type.functionType(Type.Buffer, [Type.Boolean]), Type.functionType(Type.Buffer, [Type.Timestamp, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Float, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Integer, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.String, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Array, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Object, Type.OptionalString])));
95
- export const funcFormat = new Constant((value, radix, separator = "") => format(value, radix == null ? undefined : Number(radix), separator), Type.union(Type.functionType(Type.String, [Type.Boolean]), Type.functionType(Type.String, [Type.Timestamp, Type.OptionalInteger]), Type.functionType(Type.String, [Type.Float, Type.OptionalInteger]), Type.functionType(Type.String, [Type.Integer, Type.OptionalInteger]), Type.functionType(Type.String, [Type.Buffer]), Type.functionType(Type.String, [Type.Array, Type.OptionalInteger, Type.OptionalString]), Type.functionType(Type.String, [Type.Object, Type.OptionalInteger, Type.OptionalString])));
99
+ export const funcEncode = new Constant((value, encoding) => encode(value, encoding), Type.union(Type.functionType(Type.Buffer, [Type.Boolean]), Type.functionType(Type.Buffer, [Type.Timestamp, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Float, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Integer, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Buffer]), Type.functionType(Type.Buffer, [Type.String, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Array, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Object, Type.OptionalString]), Type.functionType(Type.Buffer, [Type.Function])));
100
+ export const funcFormat = new Constant((value, formatting) => format(value, formatting), Type.union(Type.functionType(Type.String, [Type.Boolean]), Type.functionType(Type.String, [Type.Timestamp, Type.OptionalString]), Type.functionType(Type.String, [Type.Float, Type.OptionalString]), Type.functionType(Type.String, [Type.Integer, Type.OptionalString]), Type.functionType(Type.String, [Type.Buffer, Type.OptionalString]), Type.functionType(Type.String, [Type.String]), Type.functionType(Type.String, [Type.Array, Type.OptionalString]), Type.functionType(Type.String, [Type.Object, Type.OptionalString]), Type.functionType(Type.String, [Type.Function])));
@@ -1,6 +1,6 @@
1
1
  import { Constant } from "../../Constant.js";
2
2
  import { Type } from "../../Type.js";
3
- import { formatReal } from "../Float.js";
3
+ import { formatNumber } from "../Number.js";
4
4
  import { formatBuffer } from "../Buffer.js";
5
5
  export const formatAN = (value, whitespace) => {
6
6
  if (value == null) {
@@ -13,10 +13,10 @@ export const formatAN = (value, whitespace) => {
13
13
  return `@${value.toISOString()}`;
14
14
  }
15
15
  if (typeof value === "number") {
16
- return formatReal(value);
16
+ return formatNumber(value);
17
17
  }
18
18
  if (typeof value === "bigint") {
19
- return value.toString();
19
+ return formatNumber(value);
20
20
  }
21
21
  if (value instanceof ArrayBuffer) {
22
22
  return `#${formatBuffer(value)}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "affinirum",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Affinirum Scripting Language",
5
5
  "main": "dst/cjs/index.js",
6
6
  "module": "dst/index.js",
@@ -56,12 +56,12 @@
56
56
  },
57
57
  "dependencies": {},
58
58
  "devDependencies": {
59
- "@types/jasmine": "~5.1.13",
59
+ "@types/jasmine": "~5.1.15",
60
60
  "copyfiles": "~2.4.1",
61
- "eslint": "~9.39.1",
62
- "jasmine": "~5.12.0",
61
+ "eslint": "~9.39.2",
62
+ "jasmine": "~5.13.0",
63
63
  "rimraf": "~6.1.2",
64
64
  "typescript": "~5.9.3",
65
- "typescript-eslint": "~8.48.0"
65
+ "typescript-eslint": "~8.53.0"
66
66
  }
67
67
  }