affinirum 1.2.4 → 1.2.7

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
@@ -196,9 +196,12 @@ 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
199
+ - **buffer ??.Encode(encoding: string?)** — Encode value to buffer
200
200
  - **string ??.Format(formatting: integer? | string?)** — Format value to string
201
201
 
202
+ #### Aggregable Functions
203
+ - **float | integer | buffer | string | array float | integer | buffer | string | array.Add(values: array...)** — Add or concatenate values
204
+
202
205
  #### Array Functions
203
206
  - **?? array.First(condition: function)** — First item satisfying condition
204
207
  - **?? array.Last(condition: function)** — Last 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
@@ -54,6 +54,13 @@ export declare class Affinirum {
54
54
  @returns Calculated value.
55
55
  */
56
56
  evaluate(values?: Record<string, Value>): Value;
57
+ /**
58
+ Produces string in Affinirum Notation.
59
+ @param value Value to format.
60
+ @param whitespace Optional white space characters for readability.
61
+ @returns String formatted in Affinirum Notation.
62
+ */
63
+ static format(value: Value, whitespace?: string): string;
57
64
  protected _list(state: ParserState, scope: StaticScope): Node;
58
65
  protected _unit(state: ParserState, scope: StaticScope): Node;
59
66
  protected _coalescence(state: ParserState, scope: StaticScope): Node;
package/dst/Affinirum.js CHANGED
@@ -1,5 +1,6 @@
1
+ import { formatAN } from "./constant/notation/AN.js";
1
2
  import { funcOr, funcAnd, funcNot } from "./constant/Boolean.js";
2
- import { funcAdd } from "./constant/Enumerable.js";
3
+ import { funcAdd } from "./constant/Aggregable.js";
3
4
  import { funcAt, funcHas } from "./constant/Iterable.js";
4
5
  import { funcGreaterThan, funcLessThan, funcGreaterOrEqual, funcLessOrEqual, funcSubtract, funcMultiply, funcDivide, funcRemainder, funcPower, funcNegate } from "./constant/Number.js";
5
6
  import { funcCoalesce, funcEqual, funcNotEqual } from "./constant/Unknown.js";
@@ -117,6 +118,15 @@ export class Affinirum {
117
118
  throw e;
118
119
  }
119
120
  }
121
+ /**
122
+ Produces string in Affinirum Notation.
123
+ @param value Value to format.
124
+ @param whitespace Optional white space characters for readability.
125
+ @returns String formatted in Affinirum Notation.
126
+ */
127
+ static format(value, whitespace) {
128
+ return formatAN(value, whitespace);
129
+ }
120
130
  _list(state, scope) {
121
131
  const frame = state.starts();
122
132
  const subnodes = [];
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,5 +1,4 @@
1
1
  export type PrimitiveValue = undefined | null | number | boolean | Date | bigint | ArrayBuffer | string;
2
- export type DataValue = PrimitiveValue | Value[] | {
2
+ export type Value = PrimitiveValue | Value[] | {
3
3
  [key: string]: Value;
4
- };
5
- export type Value = DataValue | ((...args: any[]) => Value);
4
+ } | ((...args: any[]) => Value);
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Affinirum = void 0;
4
+ const AN_js_1 = require("./constant/notation/AN.js");
4
5
  const Boolean_js_1 = require("./constant/Boolean.js");
5
- const Enumerable_js_1 = require("./constant/Enumerable.js");
6
+ const Aggregable_js_1 = require("./constant/Aggregable.js");
6
7
  const Iterable_js_1 = require("./constant/Iterable.js");
7
8
  const Number_js_1 = require("./constant/Number.js");
8
9
  const Unknown_js_1 = require("./constant/Unknown.js");
@@ -120,6 +121,15 @@ class Affinirum {
120
121
  throw e;
121
122
  }
122
123
  }
124
+ /**
125
+ Produces string in Affinirum Notation.
126
+ @param value Value to format.
127
+ @param whitespace Optional white space characters for readability.
128
+ @returns String formatted in Affinirum Notation.
129
+ */
130
+ static format(value, whitespace) {
131
+ return (0, AN_js_1.formatAN)(value, whitespace);
132
+ }
123
133
  _list(state, scope) {
124
134
  const frame = state.starts();
125
135
  const subnodes = [];
@@ -188,7 +198,7 @@ class Affinirum {
188
198
  }
189
199
  _aggregate(state, scope) {
190
200
  let node = this._product(state, scope);
191
- while (state.operator === Enumerable_js_1.funcAdd || state.operator === Number_js_1.funcSubtract) {
201
+ while (state.operator === Aggregable_js_1.funcAdd || state.operator === Number_js_1.funcSubtract) {
192
202
  const fnode = new ConstantNode_js_1.ConstantNode(state, state.operator);
193
203
  node = new FunctionNode_js_1.FunctionNode(state, fnode, [node, this._product(state.next(), scope)]);
194
204
  }
@@ -205,7 +215,7 @@ class Affinirum {
205
215
  _signum(state, scope) {
206
216
  const frame = state.starts();
207
217
  let negate = false;
208
- while (state.operator === Enumerable_js_1.funcAdd || state.operator === Number_js_1.funcSubtract) {
218
+ while (state.operator === Aggregable_js_1.funcAdd || state.operator === Number_js_1.funcSubtract) {
209
219
  if (state.operator === Number_js_1.funcSubtract) {
210
220
  negate = !negate;
211
221
  }
@@ -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])));
@@ -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) => {
@@ -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,7 +71,9 @@ 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
79
  const format = (value, formatting) => value == null
@@ -78,24 +81,26 @@ const format = (value, formatting) => value == null
78
81
  : typeof value === "boolean"
79
82
  ? value.toString()
80
83
  : value instanceof Date
81
- ? (0, Timestamp_js_1.formatTimestamp)(value, String(formatting))
84
+ ? (0, Timestamp_js_1.formatTimestamp)(value, formatting)
82
85
  : typeof value === "number"
83
- ? (0, Float_js_1.formatReal)(value, formatting ? Number(formatting) : undefined)
86
+ ? (0, Number_js_1.formatNumber)(value, formatting)
84
87
  : typeof value === "bigint"
85
- ? value.toString(formatting ? Number(formatting) : 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
- ? "array"
94
+ ? value.map((i) => (0, exports.format)(i, formatting)).reduce((acc, val) => acc + val)
92
95
  : typeof value === "object"
93
- ? "object"
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, formatting) => (0, exports.format)(value, formatting == null ? undefined : typeof formatting === 'string' ? formatting : Number(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.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.functionType(Type_js_1.Type.String, [Type_js_1.Type.Object]), Type_js_1.Type.functionType(Type_js_1.Type.String, [Type_js_1.Type.Function])));
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)}`;
@@ -33,8 +33,8 @@ const formatAN = (value, whitespace) => {
33
33
  return `[${lines.join(",")}${suffix}]`;
34
34
  }
35
35
  if (typeof value === "object") {
36
- const [prefix, suffix] = whitespace ? ["\n" + whitespace, "\n"] : ["", ""];
37
- const lines = Object.entries(value).map(([k, v]) => `${prefix}"${k}":${(0, exports.formatAN)(v, whitespace).split("\n").join(prefix)}`);
36
+ const [prefix, suffix, separator] = whitespace ? ["\n" + whitespace, "\n", ": "] : ["", "", ":"];
37
+ const lines = Object.entries(value).map(([k, v]) => `${prefix}"${k}"${separator}${(0, exports.formatAN)(v, whitespace).split("\n").join(prefix)}`);
38
38
  return `[${lines.join(",")}${suffix}]`;
39
39
  }
40
40
  return "function";
@@ -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])));
@@ -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) {
@@ -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, formatting?: number | 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
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, String(formatting))
79
+ ? formatTimestamp(value, formatting)
77
80
  : typeof value === "number"
78
- ? formatReal(value, formatting ? Number(formatting) : undefined)
81
+ ? formatNumber(value, formatting)
79
82
  : typeof value === "bigint"
80
- ? value.toString(formatting ? Number(formatting) : 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
- ? "array"
89
+ ? value.map((i) => format(i, formatting)).reduce((acc, val) => acc + val)
87
90
  : typeof value === "object"
88
- ? "object"
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, formatting) => format(value, formatting == null ? undefined : typeof formatting === 'string' ? formatting : Number(formatting)), Type.union(Type.functionType(Type.String, [Type.Boolean]), Type.functionType(Type.String, [Type.Timestamp, Type.OptionalString]), 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.functionType(Type.String, [Type.Object]), Type.functionType(Type.String, [Type.Function])));
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)}`;
@@ -30,8 +30,8 @@ export const formatAN = (value, whitespace) => {
30
30
  return `[${lines.join(",")}${suffix}]`;
31
31
  }
32
32
  if (typeof value === "object") {
33
- const [prefix, suffix] = whitespace ? ["\n" + whitespace, "\n"] : ["", ""];
34
- const lines = Object.entries(value).map(([k, v]) => `${prefix}"${k}":${formatAN(v, whitespace).split("\n").join(prefix)}`);
33
+ const [prefix, suffix, separator] = whitespace ? ["\n" + whitespace, "\n", ": "] : ["", "", ":"];
34
+ const lines = Object.entries(value).map(([k, v]) => `${prefix}"${k}"${separator}${formatAN(v, whitespace).split("\n").join(prefix)}`);
35
35
  return `[${lines.join(",")}${suffix}]`;
36
36
  }
37
37
  return "function";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "affinirum",
3
- "version": "1.2.4",
3
+ "version": "1.2.7",
4
4
  "description": "Affinirum Scripting Language",
5
5
  "main": "dst/cjs/index.js",
6
6
  "module": "dst/index.js",