affinirum 1.5.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/.cache/arrow-preview-vWvB5K/affinirum-arrow-functions.patch +155 -0
  2. package/.cache/function-syntax-tests.log +20 -0
  3. package/README.md +925 -355
  4. package/dst/Affinirum.d.ts +29 -19
  5. package/dst/Affinirum.js +399 -334
  6. package/dst/CallFrame.d.ts +12 -3
  7. package/dst/CallFrame.js +49 -10
  8. package/dst/Constant.d.ts +1 -3
  9. package/dst/Constant.js +3 -8
  10. package/dst/LexicalScope.d.ts +11 -9
  11. package/dst/LexicalScope.js +10 -6
  12. package/dst/ParserSpan.d.ts +11 -0
  13. package/dst/{ScriptSpan.js → ParserSpan.js} +8 -5
  14. package/dst/ParserState.d.ts +28 -49
  15. package/dst/ParserState.js +256 -489
  16. package/dst/Type.d.ts +34 -17
  17. package/dst/Type.js +211 -115
  18. package/dst/TypeParser.d.ts +9 -0
  19. package/dst/TypeParser.js +127 -0
  20. package/dst/Value.d.ts +1 -1
  21. package/dst/Value.js +21 -10
  22. package/dst/Variable.d.ts +16 -5
  23. package/dst/Variable.js +32 -7
  24. package/dst/atom/ArrayAtom.d.ts +10 -10
  25. package/dst/atom/ArrayAtom.js +62 -55
  26. package/dst/atom/Atom.d.ts +7 -0
  27. package/dst/atom/FunctionAtom.d.ts +13 -15
  28. package/dst/atom/FunctionAtom.js +53 -104
  29. package/dst/atom/FunctionSignature.d.ts +23 -0
  30. package/dst/atom/FunctionSignature.js +124 -0
  31. package/dst/atom/ObjectAtom.d.ts +11 -9
  32. package/dst/atom/ObjectAtom.js +73 -33
  33. package/dst/atom/PrimitiveAtom.d.ts +6 -7
  34. package/dst/atom/PrimitiveAtom.js +7 -10
  35. package/dst/cjs/Affinirum.d.ts +29 -19
  36. package/dst/cjs/Affinirum.js +398 -333
  37. package/dst/cjs/CallFrame.d.ts +12 -3
  38. package/dst/cjs/CallFrame.js +49 -10
  39. package/dst/cjs/Constant.d.ts +1 -3
  40. package/dst/cjs/Constant.js +3 -8
  41. package/dst/cjs/LexicalScope.d.ts +11 -9
  42. package/dst/cjs/LexicalScope.js +10 -6
  43. package/dst/cjs/ParserSpan.d.ts +11 -0
  44. package/dst/cjs/{ScriptSpan.js → ParserSpan.js} +10 -7
  45. package/dst/cjs/ParserState.d.ts +28 -49
  46. package/dst/cjs/ParserState.js +255 -488
  47. package/dst/cjs/Type.d.ts +34 -17
  48. package/dst/cjs/Type.js +211 -115
  49. package/dst/cjs/TypeParser.d.ts +9 -0
  50. package/dst/cjs/TypeParser.js +131 -0
  51. package/dst/cjs/Value.d.ts +1 -1
  52. package/dst/cjs/Value.js +21 -10
  53. package/dst/cjs/Variable.d.ts +16 -5
  54. package/dst/cjs/Variable.js +36 -9
  55. package/dst/cjs/atom/ArrayAtom.d.ts +10 -10
  56. package/dst/cjs/atom/ArrayAtom.js +62 -55
  57. package/dst/cjs/atom/Atom.d.ts +7 -0
  58. package/dst/cjs/atom/FunctionAtom.d.ts +13 -15
  59. package/dst/cjs/atom/FunctionAtom.js +54 -105
  60. package/dst/cjs/atom/FunctionSignature.d.ts +23 -0
  61. package/dst/cjs/atom/FunctionSignature.js +128 -0
  62. package/dst/cjs/atom/ObjectAtom.d.ts +11 -9
  63. package/dst/cjs/atom/ObjectAtom.js +73 -33
  64. package/dst/cjs/atom/PrimitiveAtom.d.ts +6 -7
  65. package/dst/cjs/atom/PrimitiveAtom.js +7 -10
  66. package/dst/cjs/dictionary/Constants.d.ts +2 -0
  67. package/dst/cjs/dictionary/Constants.js +27 -0
  68. package/dst/cjs/dictionary/Functions.d.ts +2 -0
  69. package/dst/cjs/{Functions.js → dictionary/Functions.js} +27 -25
  70. package/dst/cjs/native/Aggregable.js +10 -2
  71. package/dst/cjs/native/Array.d.ts +2 -3
  72. package/dst/cjs/native/Array.js +38 -39
  73. package/dst/cjs/native/Boolean.d.ts +1 -1
  74. package/dst/cjs/native/Boolean.js +13 -10
  75. package/dst/cjs/native/Buffer.d.ts +5 -5
  76. package/dst/cjs/native/Buffer.js +70 -46
  77. package/dst/cjs/native/Composite.d.ts +5 -0
  78. package/dst/cjs/native/Composite.js +35 -0
  79. package/dst/cjs/native/Enumerable.js +20 -8
  80. package/dst/cjs/native/Float.d.ts +3 -1
  81. package/dst/cjs/native/Float.js +51 -12
  82. package/dst/cjs/native/Integer.d.ts +4 -2
  83. package/dst/cjs/native/Integer.js +60 -25
  84. package/dst/cjs/native/Iterable.d.ts +0 -2
  85. package/dst/cjs/native/Iterable.js +9 -28
  86. package/dst/cjs/native/Number.d.ts +0 -2
  87. package/dst/cjs/native/Number.js +34 -48
  88. package/dst/cjs/native/Object.d.ts +1 -1
  89. package/dst/cjs/native/Object.js +5 -6
  90. package/dst/cjs/native/String.d.ts +7 -6
  91. package/dst/cjs/native/String.js +28 -27
  92. package/dst/cjs/native/Timestamp.d.ts +3 -3
  93. package/dst/cjs/native/Timestamp.js +34 -36
  94. package/dst/cjs/native/Unknown.d.ts +3 -3
  95. package/dst/cjs/native/Unknown.js +48 -17
  96. package/dst/cjs/native/notation/AN.d.ts +1 -1
  97. package/dst/cjs/native/notation/AN.js +37 -35
  98. package/dst/cjs/native/notation/IP.d.ts +1 -1
  99. package/dst/cjs/native/notation/IP.js +11 -12
  100. package/dst/cjs/native/notation/JSON.d.ts +1 -1
  101. package/dst/cjs/native/notation/JSON.js +7 -6
  102. package/dst/cjs/node/AccessNode.d.ts +24 -0
  103. package/dst/cjs/node/AccessNode.js +193 -0
  104. package/dst/cjs/node/ArrayNode.d.ts +7 -4
  105. package/dst/cjs/node/ArrayNode.js +26 -15
  106. package/dst/cjs/node/AssignableNode.d.ts +16 -0
  107. package/dst/cjs/node/AssignableNode.js +18 -0
  108. package/dst/cjs/node/AssignmentNode.d.ts +20 -0
  109. package/dst/cjs/node/AssignmentNode.js +66 -0
  110. package/dst/cjs/node/BlockNode.d.ts +5 -4
  111. package/dst/cjs/node/BlockNode.js +18 -11
  112. package/dst/cjs/node/CallNode.d.ts +7 -5
  113. package/dst/cjs/node/CallNode.js +40 -41
  114. package/dst/cjs/node/CastNode.d.ts +5 -6
  115. package/dst/cjs/node/CastNode.js +16 -17
  116. package/dst/cjs/node/ConstantNode.d.ts +4 -6
  117. package/dst/cjs/node/ConstantNode.js +9 -17
  118. package/dst/cjs/node/FinalNode.d.ts +19 -0
  119. package/dst/cjs/node/FinalNode.js +41 -0
  120. package/dst/cjs/node/FunctionNode.d.ts +17 -0
  121. package/dst/cjs/node/FunctionNode.js +51 -0
  122. package/dst/cjs/node/InvocationNode.d.ts +5 -0
  123. package/dst/cjs/node/InvocationNode.js +34 -0
  124. package/dst/cjs/node/JumpNode.d.ts +7 -9
  125. package/dst/cjs/node/JumpNode.js +12 -19
  126. package/dst/cjs/node/LoopNode.d.ts +7 -5
  127. package/dst/cjs/node/LoopNode.js +33 -22
  128. package/dst/cjs/node/MatchNode.d.ts +17 -0
  129. package/dst/cjs/node/MatchNode.js +65 -0
  130. package/dst/cjs/node/Node.d.ts +14 -0
  131. package/dst/cjs/{Node.js → node/Node.js} +17 -11
  132. package/dst/cjs/node/ObjectNode.d.ts +7 -4
  133. package/dst/cjs/node/ObjectNode.js +42 -11
  134. package/dst/cjs/node/{SwitchNode.d.ts → TernaryNode.d.ts} +6 -6
  135. package/dst/cjs/node/TernaryNode.js +45 -0
  136. package/dst/cjs/node/VariableNode.d.ts +10 -6
  137. package/dst/cjs/node/VariableNode.js +50 -16
  138. package/dst/dictionary/Constants.d.ts +2 -0
  139. package/dst/dictionary/Constants.js +24 -0
  140. package/dst/dictionary/Functions.d.ts +2 -0
  141. package/dst/{Functions.js → dictionary/Functions.js} +26 -24
  142. package/dst/native/Aggregable.js +11 -3
  143. package/dst/native/Array.d.ts +2 -3
  144. package/dst/native/Array.js +37 -38
  145. package/dst/native/Boolean.d.ts +1 -1
  146. package/dst/native/Boolean.js +12 -9
  147. package/dst/native/Buffer.d.ts +5 -5
  148. package/dst/native/Buffer.js +66 -42
  149. package/dst/native/Composite.d.ts +5 -0
  150. package/dst/native/Composite.js +32 -0
  151. package/dst/native/Enumerable.js +20 -8
  152. package/dst/native/Float.d.ts +3 -1
  153. package/dst/native/Float.js +48 -11
  154. package/dst/native/Integer.d.ts +4 -2
  155. package/dst/native/Integer.js +56 -23
  156. package/dst/native/Iterable.d.ts +0 -2
  157. package/dst/native/Iterable.js +8 -27
  158. package/dst/native/Number.d.ts +0 -2
  159. package/dst/native/Number.js +34 -46
  160. package/dst/native/Object.d.ts +1 -1
  161. package/dst/native/Object.js +4 -5
  162. package/dst/native/String.d.ts +7 -6
  163. package/dst/native/String.js +24 -24
  164. package/dst/native/Timestamp.d.ts +3 -3
  165. package/dst/native/Timestamp.js +31 -33
  166. package/dst/native/Unknown.d.ts +3 -3
  167. package/dst/native/Unknown.js +49 -18
  168. package/dst/native/notation/AN.d.ts +1 -1
  169. package/dst/native/notation/AN.js +37 -35
  170. package/dst/native/notation/IP.d.ts +1 -1
  171. package/dst/native/notation/IP.js +10 -11
  172. package/dst/native/notation/JSON.d.ts +1 -1
  173. package/dst/native/notation/JSON.js +6 -5
  174. package/dst/node/AccessNode.d.ts +24 -0
  175. package/dst/node/AccessNode.js +189 -0
  176. package/dst/node/ArrayNode.d.ts +7 -4
  177. package/dst/node/ArrayNode.js +26 -15
  178. package/dst/node/AssignableNode.d.ts +16 -0
  179. package/dst/node/AssignableNode.js +14 -0
  180. package/dst/node/AssignmentNode.d.ts +20 -0
  181. package/dst/node/AssignmentNode.js +62 -0
  182. package/dst/node/BlockNode.d.ts +5 -4
  183. package/dst/node/BlockNode.js +18 -11
  184. package/dst/node/CallNode.d.ts +7 -5
  185. package/dst/node/CallNode.js +40 -41
  186. package/dst/node/CastNode.d.ts +5 -6
  187. package/dst/node/CastNode.js +16 -17
  188. package/dst/node/ConstantNode.d.ts +4 -6
  189. package/dst/node/ConstantNode.js +9 -17
  190. package/dst/node/FinalNode.d.ts +19 -0
  191. package/dst/node/FinalNode.js +37 -0
  192. package/dst/node/FunctionNode.d.ts +17 -0
  193. package/dst/node/FunctionNode.js +47 -0
  194. package/dst/node/InvocationNode.d.ts +5 -0
  195. package/dst/node/InvocationNode.js +30 -0
  196. package/dst/node/JumpNode.d.ts +7 -9
  197. package/dst/node/JumpNode.js +12 -19
  198. package/dst/node/LoopNode.d.ts +7 -5
  199. package/dst/node/LoopNode.js +33 -22
  200. package/dst/node/MatchNode.d.ts +17 -0
  201. package/dst/node/MatchNode.js +61 -0
  202. package/dst/node/Node.d.ts +14 -0
  203. package/dst/node/Node.js +28 -0
  204. package/dst/node/ObjectNode.d.ts +7 -4
  205. package/dst/node/ObjectNode.js +42 -11
  206. package/dst/node/{SwitchNode.d.ts → TernaryNode.d.ts} +6 -6
  207. package/dst/node/TernaryNode.js +41 -0
  208. package/dst/node/VariableNode.d.ts +10 -6
  209. package/dst/node/VariableNode.js +50 -16
  210. package/package.json +4 -4
  211. package/dst/Atom.d.ts +0 -7
  212. package/dst/Constants.d.ts +0 -2
  213. package/dst/Constants.js +0 -24
  214. package/dst/Functions.d.ts +0 -2
  215. package/dst/Jump.d.ts +0 -1
  216. package/dst/Jump.js +0 -1
  217. package/dst/JumpException.d.ts +0 -9
  218. package/dst/JumpException.js +0 -14
  219. package/dst/Keywords.d.ts +0 -1
  220. package/dst/Keywords.js +0 -17
  221. package/dst/Node.d.ts +0 -14
  222. package/dst/Node.js +0 -22
  223. package/dst/ScriptSpan.d.ts +0 -10
  224. package/dst/cjs/Atom.d.ts +0 -7
  225. package/dst/cjs/Constants.d.ts +0 -2
  226. package/dst/cjs/Constants.js +0 -27
  227. package/dst/cjs/Functions.d.ts +0 -2
  228. package/dst/cjs/Jump.d.ts +0 -1
  229. package/dst/cjs/Jump.js +0 -2
  230. package/dst/cjs/JumpException.d.ts +0 -9
  231. package/dst/cjs/JumpException.js +0 -18
  232. package/dst/cjs/Keywords.d.ts +0 -1
  233. package/dst/cjs/Keywords.js +0 -20
  234. package/dst/cjs/Node.d.ts +0 -14
  235. package/dst/cjs/ScriptSpan.d.ts +0 -10
  236. package/dst/cjs/node/SwitchNode.js +0 -49
  237. package/dst/cjs/node/VariadicNode.d.ts +0 -4
  238. package/dst/cjs/node/VariadicNode.js +0 -10
  239. package/dst/node/SwitchNode.js +0 -45
  240. package/dst/node/VariadicNode.d.ts +0 -4
  241. package/dst/node/VariadicNode.js +0 -6
  242. /package/dst/{Atom.js → atom/Atom.js} +0 -0
  243. /package/dst/cjs/{Atom.js → atom/Atom.js} +0 -0
@@ -1,36 +1,11 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  import { Type } from "../Type.js";
3
+ import { isWhiteSpaceSymbol } from "./String.js";
3
4
  export const EmptyBuffer = new ArrayBuffer(0);
4
- const ZERO = "0".charCodeAt(0), NINE = "9".charCodeAt(0);
5
- const UPPER_A = "A".charCodeAt(0), UPPER_F = "F".charCodeAt(0);
6
- const LOWER_A = "a".charCodeAt(0), LOWER_F = "f".charCodeAt(0);
7
- export const formatLiteralBuffer = (value) => `\`${formatBuffer(value)}\``;
8
- export const parseLiteralBuffer = (value, offset = 0) => {
9
- const q = value.charCodeAt(offset);
10
- for (let i = offset + 1, bytes = [], digits = [0, 0], ix = 0; i < value.length; ++i) {
11
- const code = value.charCodeAt(i);
12
- if (code === q) {
13
- if (ix === 1) {
14
- bytes.push(digits[0]);
15
- }
16
- return [new Uint8Array(bytes).buffer, i + 1];
17
- }
18
- if (code >= ZERO && code <= NINE) {
19
- digits[ix++] = code - ZERO;
20
- }
21
- else if (code >= UPPER_A && code <= UPPER_F) {
22
- digits[ix++] = code - UPPER_A + 10;
23
- }
24
- else if (code >= LOWER_A && code <= LOWER_F) {
25
- digits[ix++] = code - LOWER_A + 10;
26
- }
27
- if (ix > 1) {
28
- bytes.push(digits[0] << 4 | digits[1]);
29
- ix = 0;
30
- }
31
- }
32
- throw new Error(`missing closing buffer quotation mark ${String.fromCharCode(q)}`);
33
- };
5
+ const codeZero = "0".charCodeAt(0), codeNine = "9".charCodeAt(0);
6
+ const codeUpperA = "A".charCodeAt(0), codeUpperF = "F".charCodeAt(0);
7
+ const coderLowerA = "a".charCodeAt(0), codeLowerF = "f".charCodeAt(0);
8
+ const codeComment = "/".charCodeAt(0), codeNewLine = "\n".charCodeAt(0);
34
9
  export const parseBoundedInteger = (input, base, min, max) => {
35
10
  if (input.length === 0) {
36
11
  throw new Error(`Invalid IP component: ${input}`);
@@ -39,14 +14,14 @@ export const parseBoundedInteger = (input, base, min, max) => {
39
14
  for (let i = 0; i < input.length; i++) {
40
15
  const code = input.charCodeAt(i);
41
16
  let digit;
42
- if (code >= ZERO && code <= NINE) {
43
- digit = code - ZERO;
17
+ if (code >= codeZero && code <= codeNine) {
18
+ digit = code - codeZero;
44
19
  }
45
- else if (base === 16 && code >= UPPER_A && code <= UPPER_F) {
46
- digit = code - UPPER_A + 10;
20
+ else if (base === 16 && code >= codeUpperA && code <= codeUpperF) {
21
+ digit = code - codeUpperA + 10;
47
22
  }
48
- else if (base === 16 && code >= LOWER_A && code <= LOWER_F) {
49
- digit = code - LOWER_A + 10;
23
+ else if (base === 16 && code >= coderLowerA && code <= codeLowerF) {
24
+ digit = code - coderLowerA + 10;
50
25
  }
51
26
  else {
52
27
  throw new Error(`Invalid character: ${input.charAt(i)}`);
@@ -58,7 +33,7 @@ export const parseBoundedInteger = (input, base, min, max) => {
58
33
  }
59
34
  return value;
60
35
  };
61
- export const equateBuffers = (value1, value2) => {
36
+ export const equalsBuffers = (value1, value2) => {
62
37
  if (value1.byteLength !== value2.byteLength) {
63
38
  return false;
64
39
  }
@@ -155,12 +130,61 @@ export const parseBuffer = (value) => {
155
130
  }
156
131
  return bytes.buffer;
157
132
  };
158
- export const funcByte = new Constant((value, pos) => value == null
133
+ export const formatLiteralBuffer = (value) => `\`${formatBuffer(value)}\``;
134
+ export const parseLiteralBuffer = (value, offset = 0) => {
135
+ const q = value.charCodeAt(offset);
136
+ for (let i = offset + 1, bytes = [], digits = [0, 0], ix = 0; i < value.length; ++i) {
137
+ const code = value.charCodeAt(i);
138
+ if (code === q) {
139
+ if (ix === 1) {
140
+ bytes.push(digits[0]);
141
+ }
142
+ return [new Uint8Array(bytes).buffer, i + 1];
143
+ }
144
+ if (code >= codeZero && code <= codeNine) {
145
+ digits[ix++] = code - codeZero;
146
+ }
147
+ else if (code >= codeUpperA && code <= codeUpperF) {
148
+ digits[ix++] = code - codeUpperA + 10;
149
+ }
150
+ else if (code >= coderLowerA && code <= codeLowerF) {
151
+ digits[ix++] = code - coderLowerA + 10;
152
+ }
153
+ else if (code === codeComment) {
154
+ if (i === value.indexOf("///", i)) {
155
+ i = value.indexOf("///", i + 3);
156
+ if (i < 0) {
157
+ throw new Error("missing closing comment mark");
158
+ }
159
+ i += 2;
160
+ }
161
+ else if (i === value.indexOf("//", i)) {
162
+ let c = value.charCodeAt(i += 2);
163
+ while (c !== codeNewLine && c !== q && !Number.isNaN(c)) {
164
+ c = value.charCodeAt(++i);
165
+ }
166
+ --i;
167
+ }
168
+ else {
169
+ throw new Error("unexpected symbol '/'");
170
+ }
171
+ }
172
+ else if (!isWhiteSpaceSymbol(value.charAt(i))) {
173
+ throw new Error(`unexpected symbol '${value.charAt(i)}'`);
174
+ }
175
+ if (ix > 1) {
176
+ bytes.push(digits[0] << 4 | digits[1]);
177
+ ix = 0;
178
+ }
179
+ }
180
+ throw new Error(`missing closing buffer quotation mark ${String.fromCharCode(q)}`);
181
+ };
182
+ export const funcByteAt = new Constant((value, pos) => value == null
159
183
  ? undefined
160
- : value.slice(Number(pos), Number(pos) + 1), Type.functionType(Type.OptionalBuffer, [Type.Buffer, Type.Integer]));
161
- const funcRandomBuffer = new Constant((value) => value == null || value <= 0n ? new Uint8Array(0).buffer : crypto.getRandomValues(new Uint8Array(Number(value))).buffer, Type.functionType(Type.Buffer, [Type.Integer]), false);
162
- const funcParseBuffer = new Constant((value) => parseBuffer(value), Type.functionType(Type.OptionalBuffer, [Type.OptionalString]));
163
- export const constBuffer = Object.assign(Object.create(null), {
184
+ : value.slice(Number(pos), Number(pos) + 1), Type.functionType([[Type.OptionalBuffer, [Type.Buffer, Type.Integer]]]));
185
+ const funcRandomBuffer = new Constant((value) => value == null || value <= 0n ? new Uint8Array(0).buffer : crypto.getRandomValues(new Uint8Array(Number(value))).buffer, Type.functionType([[Type.Buffer, [Type.Integer]]], true));
186
+ const funcParseBuffer = new Constant((value) => parseBuffer(value), Type.functionType([[Type.OptionalBuffer, [Type.OptionalString]]]));
187
+ export const globBuffer = Object.assign(Object.create(null), {
164
188
  Random: funcRandomBuffer,
165
189
  Parse: funcParseBuffer,
166
190
  });
@@ -0,0 +1,5 @@
1
+ import { Constant } from "../Constant.js";
2
+ export declare const funcAt: Constant;
3
+ export declare const funcOptionalAt: Constant;
4
+ export declare const funcHas: Constant;
5
+ export declare const funcOptionalHas: Constant;
@@ -0,0 +1,32 @@
1
+ import { Constant } from "../Constant.js";
2
+ import { Type } from "../Type.js";
3
+ const arrayAt = (value, index) => {
4
+ const ix = index < 0 ? value.length + index : index;
5
+ return ix >= 0 && ix < value.length ? value[ix] : undefined;
6
+ };
7
+ const objectAt = (value, key) => {
8
+ return Object.hasOwn(value, key) ? value[key] : undefined;
9
+ };
10
+ const arrayHas = (value, index) => {
11
+ const ix = index < 0 ? value.length + index : index;
12
+ return ix >= 0 && ix < value.length;
13
+ };
14
+ const objectHas = (value, key) => {
15
+ return Object.hasOwn(value, key);
16
+ };
17
+ export const funcAt = new Constant((value, index) => Array.isArray(value) ? arrayAt(value, Number(index)) : objectAt(value, String(index)), Type.functionType([
18
+ [Type.Any, [Type.Array, Type.Integer]],
19
+ [Type.Any, [Type.Object, Type.String]],
20
+ ]));
21
+ export const funcOptionalAt = new Constant((value, index) => value == null ? undefined : Array.isArray(value) ? arrayAt(value, Number(index)) : objectAt(value, String(index)), Type.functionType([
22
+ [Type.Any, [Type.OptionalArray, Type.Integer]],
23
+ [Type.Any, [Type.OptionalObject, Type.String]],
24
+ ]));
25
+ export const funcHas = new Constant((value, index) => Array.isArray(value) ? arrayHas(value, Number(index)) : objectHas(value, String(index)), Type.functionType([
26
+ [Type.Boolean, [Type.Array, Type.Integer]],
27
+ [Type.Boolean, [Type.Object, Type.String]],
28
+ ]));
29
+ export const funcOptionalHas = new Constant((value, index) => value == null ? undefined : Array.isArray(value) ? arrayHas(value, Number(index)) : objectHas(value, String(index)), Type.functionType([
30
+ [Type.OptionalBoolean, [Type.OptionalArray, Type.Integer]],
31
+ [Type.OptionalBoolean, [Type.OptionalObject, Type.String]],
32
+ ]));
@@ -1,15 +1,27 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  import { Type } from "../Type.js";
3
3
  import { aggregate } from "./Aggregable.js";
4
- const typeBufferArray = Type.arrayType([Type.Buffer]);
5
- const typeStringArray = Type.arrayType([Type.String]);
6
- const typeArrayArray = Type.arrayType([Type.Array]);
4
+ const typeBufferArray = Type.arrayType(Type.Buffer);
5
+ const typeStringArray = Type.arrayType(Type.String);
6
+ const typeArrayArray = Type.arrayType(Type.Array);
7
7
  export const funcSlice = new Constant((value, start = 0n, end) => value == null
8
8
  ? undefined
9
- : 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])));
10
- export const funcSplice = new Constant((value, start, remove, inject) => value == null
9
+ : value.slice(Number(start), end == null ? undefined : Number(end)), Type.functionType([
10
+ [Type.Buffer, [Type.Buffer, Type.OptionalInteger, Type.OptionalInteger]],
11
+ [Type.String, [Type.String, Type.OptionalInteger, Type.OptionalInteger]],
12
+ [Type.Array, [Type.Array, Type.OptionalInteger, Type.OptionalInteger]],
13
+ ]));
14
+ export const funcSplice = new Constant((value, start, remove, ...inject) => value == null
11
15
  ? undefined
12
- : aggregate(inject.reduce((acc, val) => aggregate(acc, val), value.slice(0, Number(start))), value.slice(Number(start + remove))), Type.union(Type.functionType(Type.Buffer, [Type.Buffer, Type.Integer, Type.Integer, typeBufferArray], true), Type.functionType(Type.String, [Type.String, Type.Integer, Type.Integer, typeStringArray], true), Type.functionType(Type.Array, [Type.Array, Type.Integer, Type.Integer, typeArrayArray], true)));
13
- export const funcInject = new Constant((value, start, inject) => value == null
16
+ : aggregate(inject.reduce((acc, val) => aggregate(acc, val), value.slice(0, Number(start))), value.slice(Number(start + remove))), Type.functionType([
17
+ [Type.Buffer, [Type.Buffer, Type.Integer, Type.Integer, typeBufferArray], true],
18
+ [Type.String, [Type.String, Type.Integer, Type.Integer, typeStringArray], true],
19
+ [Type.Array, [Type.Array, Type.Integer, Type.Integer, typeArrayArray], true],
20
+ ]));
21
+ export const funcInject = new Constant((value, start, ...inject) => value == null
14
22
  ? undefined
15
- : aggregate(inject.reduce((acc, val) => aggregate(acc, val), value.slice(0, Number(start))), value.slice(Number(start))), Type.union(Type.functionType(Type.Buffer, [Type.Buffer, Type.Integer, typeBufferArray], true), Type.functionType(Type.String, [Type.String, Type.Integer, typeStringArray], true), Type.functionType(Type.Array, [Type.Array, Type.Integer, typeArrayArray], true)));
23
+ : aggregate(inject.reduce((acc, val) => aggregate(acc, val), value.slice(0, Number(start))), value.slice(Number(start))), Type.functionType([
24
+ [Type.Buffer, [Type.Buffer, Type.Integer, typeBufferArray], true],
25
+ [Type.String, [Type.String, Type.Integer, typeStringArray], true],
26
+ [Type.Array, [Type.Array, Type.Integer, typeArrayArray], true],
27
+ ]));
@@ -1,5 +1,7 @@
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 formatFloat: (value: number, formatting?: string) => string;
5
+ export declare const formatLiteralFloat: (value: number) => string;
4
6
  export declare const funcFloat: Constant;
5
- export declare const constFloat: any;
7
+ export declare const globFloat: any;
@@ -51,12 +51,45 @@ const decodeFloat = (value, encoding = "f64", byteOffset) => {
51
51
  default: throw new Error(`${encoding} encoding not supported`);
52
52
  }
53
53
  };
54
- const typeNumberOrArray = Type.union(Type.Number, Type.arrayType([Type.Number]));
55
- const typeAggregator = Type.functionType(Type.Float, [Type.arrayType([typeNumberOrArray])], true);
56
- const typeTransform = Type.functionType(Type.Float, [Type.Number]);
57
- const funcSum = new Constant((values) => values.flat().reduce((acc, val) => acc + Number(val), 0), typeAggregator);
58
- const funcMin = new Constant((values) => Math.min(Number.POSITIVE_INFINITY, ...values.flat().map((i) => Number(i))), typeAggregator);
59
- const funcMax = new Constant((values) => Math.max(Number.NEGATIVE_INFINITY, ...values.flat().map((i) => Number(i))), typeAggregator);
54
+ export const formatFloat = (value, formatting) => {
55
+ if (formatting) {
56
+ const nformat = JSON.parse(`{${formatting}}`);
57
+ if (typeof nformat === "object") {
58
+ return new Intl.NumberFormat(undefined, {
59
+ minimumIntegerDigits: nformat?.min_integer_digits,
60
+ minimumFractionDigits: nformat?.min_fraction_digits,
61
+ maximumFractionDigits: nformat?.max_fraction_digits,
62
+ minimumSignificantDigits: nformat?.min_significant_digits,
63
+ maximumSignificantDigits: nformat?.max_significant_digits,
64
+ notation: nformat?.notation,
65
+ }).format(value);
66
+ }
67
+ }
68
+ return Number.isInteger(value)
69
+ ? `${value.toString()}.0`
70
+ : value.toString();
71
+ };
72
+ export const formatLiteralFloat = (value) => {
73
+ const str = value.toString();
74
+ return Number.isInteger(value) && !str.includes("e")
75
+ ? `${str}.0`
76
+ : str;
77
+ };
78
+ const typeAggregator = Type.functionType([[Type.Float, [Type.arrayType(Type.Number)], true]]);
79
+ const typeTransform = Type.functionType([[Type.Float, [Type.Number]]]);
80
+ const funcSum = new Constant((...values) => values.reduce((acc, val) => acc + Number(val), 0), typeAggregator);
81
+ const funcMin = new Constant((...values) => {
82
+ if (values.length === 0) {
83
+ throw new Error("function requires at least one argument");
84
+ }
85
+ return Math.min(Number.POSITIVE_INFINITY, ...values.map((i) => Number(i)));
86
+ }, typeAggregator);
87
+ const funcMax = new Constant((...values) => {
88
+ if (values.length === 0) {
89
+ throw new Error("function requires at least one argument");
90
+ }
91
+ return Math.max(Number.NEGATIVE_INFINITY, ...values.map((i) => Number(i)));
92
+ }, typeAggregator);
60
93
  const funcExponent = new Constant((value) => Math.exp(Number(value)), typeTransform);
61
94
  const funcLogarithm = new Constant((value) => Math.log(Number(value)), typeTransform);
62
95
  const funcAbs = new Constant((value) => Math.abs(Number(value)), typeTransform);
@@ -64,11 +97,15 @@ const funcCeil = new Constant((value) => Math.ceil(Number(value)), typeTransform
64
97
  const funcFloor = new Constant((value) => Math.floor(Number(value)), typeTransform);
65
98
  const funcRound = new Constant((value) => Math.round(Number(value)), typeTransform);
66
99
  const funcTruncate = new Constant((value) => Math.trunc(Number(value)), typeTransform);
67
- const funcRandomFloat = new Constant((value) => value == null ? undefined : Math.random() * Number(value), typeTransform, false);
68
- const funcDecodeFloat = new Constant((value, encoding = "f64", byteOffset) => decodeFloat(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType(Type.OptionalFloat, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger]));
69
- const funcParseFloat = new Constant((value) => value ? Number.parseFloat(value) : undefined, Type.functionType(Type.OptionalFloat, [Type.OptionalString]));
70
- export const funcFloat = new Constant((value) => Number(value), Type.union(Type.functionType(Type.Float, [Type.Boolean]), Type.functionType(Type.Float, [Type.Timestamp]), Type.functionType(Type.Float, [Type.Integer])));
71
- export const constFloat = Object.assign(Object.create(null), {
100
+ const funcRandomFloat = new Constant((value) => value == null ? undefined : Math.random() * Number(value), Type.functionType([[Type.Float, [Type.Number]]], true));
101
+ const funcDecodeFloat = new Constant((value, encoding = "f64", byteOffset) => decodeFloat(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType([[Type.OptionalFloat, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger]]]));
102
+ const funcParseFloat = new Constant((value) => value ? Number.parseFloat(value) : undefined, Type.functionType([[Type.OptionalFloat, [Type.OptionalString]]]));
103
+ export const funcFloat = new Constant((value) => Number(value), Type.functionType([
104
+ [Type.Float, [Type.Boolean]],
105
+ [Type.Float, [Type.Timestamp]],
106
+ [Type.Float, [Type.Integer]],
107
+ ]));
108
+ export const globFloat = Object.assign(Object.create(null), {
72
109
  NAN: new Constant(Number.NaN),
73
110
  PositiveInfinity: new Constant(Number.POSITIVE_INFINITY),
74
111
  NegativeInfinity: new Constant(Number.NEGATIVE_INFINITY),
@@ -1,7 +1,9 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  export type IntegerEncoding = "i8" | "i16" | "i16le" | "i32" | "i32le" | "i64" | "i64le" | "n8" | "n16" | "n16le" | "n32" | "n32le";
3
- export declare const boundInteger: (value: bigint) => bigint;
3
+ export declare const int64: (value: bigint) => bigint;
4
4
  export declare const createInteger: (value?: number) => bigint | undefined;
5
5
  export declare const encodeInteger: (value: bigint, encoding?: IntegerEncoding) => ArrayBuffer;
6
+ export declare const formatInteger: (value: bigint, formatting?: string) => string;
7
+ export declare const formatLiteralInteger: (value: bigint) => string;
6
8
  export declare const funcInteger: Constant;
7
- export declare const constInteger: any;
9
+ export declare const globInteger: any;
@@ -1,6 +1,6 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  import { Type } from "../Type.js";
3
- export const boundInteger = (value) => BigInt.asIntN(64, value);
3
+ export const int64 = (value) => BigInt.asIntN(64, value);
4
4
  export const createInteger = (value) => {
5
5
  if (value == null || Number.isNaN(value)) {
6
6
  return undefined;
@@ -11,7 +11,7 @@ export const createInteger = (value) => {
11
11
  if (value === Number.POSITIVE_INFINITY) {
12
12
  return 0x7fffffffffffffffn;
13
13
  }
14
- return boundInteger(BigInt(Math.trunc(value)));
14
+ return int64(BigInt(Math.trunc(value)));
15
15
  };
16
16
  export const encodeInteger = (value, encoding = "i64") => {
17
17
  let bits = "";
@@ -24,34 +24,34 @@ export const encodeInteger = (value, encoding = "i64") => {
24
24
  const dv = new DataView(new Uint8Array(Number.parseInt(bits) / 8).buffer);
25
25
  switch (encoding) {
26
26
  case "i8":
27
- dv.setInt8(0, Number(value));
27
+ dv.setInt8(0, Number(BigInt.asIntN(8, value)));
28
28
  break;
29
29
  case "i16":
30
- dv.setInt16(0, Number(value));
30
+ dv.setInt16(0, Number(BigInt.asIntN(16, value)));
31
31
  break;
32
32
  case "i16le":
33
- dv.setInt16(0, Number(value), true);
33
+ dv.setInt16(0, Number(BigInt.asIntN(16, value)), true);
34
34
  break;
35
35
  case "i32":
36
- dv.setInt32(0, Number(value));
36
+ dv.setInt32(0, Number(BigInt.asIntN(32, value)));
37
37
  break;
38
38
  case "i32le":
39
- dv.setInt32(0, Number(value), true);
39
+ dv.setInt32(0, Number(BigInt.asIntN(32, value)), true);
40
40
  break;
41
41
  case "n8":
42
- dv.setUint8(0, Number(value));
42
+ dv.setUint8(0, Number(BigInt.asUintN(8, value)));
43
43
  break;
44
44
  case "n16":
45
- dv.setUint16(0, Number(value));
45
+ dv.setUint16(0, Number(BigInt.asUintN(16, value)));
46
46
  break;
47
47
  case "n16le":
48
- dv.setUint16(0, Number(value), true);
48
+ dv.setUint16(0, Number(BigInt.asUintN(16, value)), true);
49
49
  break;
50
50
  case "n32":
51
- dv.setUint32(0, Number(value));
51
+ dv.setUint32(0, Number(BigInt.asUintN(32, value)));
52
52
  break;
53
53
  case "n32le":
54
- dv.setUint32(0, Number(value), true);
54
+ dv.setUint32(0, Number(BigInt.asUintN(32, value)), true);
55
55
  break;
56
56
  case "i64":
57
57
  dv.setBigInt64(0, value);
@@ -112,22 +112,55 @@ const decodeInteger = (value, encoding = "i64", byteOffset) => {
112
112
  default: throw new Error(`${encoding} encoding not supported`);
113
113
  }
114
114
  };
115
- const typeIntegerOrArray = Type.union(Type.Integer, Type.arrayType([Type.Integer]));
116
- const typeAggregator = Type.functionType(Type.Integer, [Type.arrayType([typeIntegerOrArray])], true);
117
- const funcSum = new Constant((values) => boundInteger(values.flat().reduce((acc, val) => acc + val, 0n)), typeAggregator);
118
- const funcMin = new Constant((values) => boundInteger(values.flat().reduce((min, val) => val < min ? val : min)), typeAggregator);
119
- const funcMax = new Constant((values) => boundInteger(values.flat().reduce((max, val) => val > max ? val : max)), typeAggregator);
120
- const funcRandomInteger = new Constant((value) => value == null ? undefined : boundInteger(BigInt(Math.floor(Math.random() * Number(value)))), Type.functionType(Type.Integer, [Type.Integer]), false);
121
- const funcDecodeInteger = new Constant((value, encoding = "i64", byteOffset) => decodeInteger(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType(Type.OptionalInteger, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger]));
115
+ export const formatInteger = (value, formatting) => {
116
+ const int = int64(value);
117
+ if (formatting) {
118
+ const nformat = JSON.parse(`{${formatting}}`);
119
+ if (typeof nformat === "object") {
120
+ return new Intl.NumberFormat(undefined, {
121
+ minimumIntegerDigits: nformat?.min_integer_digits,
122
+ minimumFractionDigits: nformat?.min_fraction_digits,
123
+ maximumFractionDigits: nformat?.max_fraction_digits,
124
+ minimumSignificantDigits: nformat?.min_significant_digits,
125
+ maximumSignificantDigits: nformat?.max_significant_digits,
126
+ notation: nformat?.notation,
127
+ }).format(int);
128
+ }
129
+ }
130
+ return int.toString();
131
+ };
132
+ export const formatLiteralInteger = (value) => {
133
+ return int64(value).toString();
134
+ };
135
+ const typeAggregator = Type.functionType([[Type.Integer, [Type.arrayType(Type.Integer)], true]]);
136
+ const funcSum = new Constant((...values) => int64(values.reduce((acc, val) => acc + val, 0n)), typeAggregator);
137
+ const funcMin = new Constant((...values) => {
138
+ if (values.length === 0) {
139
+ throw new Error("function requires at least one argument");
140
+ }
141
+ return values.reduce((min, val) => val < min ? val : min);
142
+ }, typeAggregator);
143
+ const funcMax = new Constant((...values) => {
144
+ if (values.length === 0) {
145
+ throw new Error("function requires at least one argument");
146
+ }
147
+ return values.reduce((max, val) => val > max ? val : max);
148
+ }, typeAggregator);
149
+ const funcRandomInteger = new Constant((value) => value == null ? undefined : BigInt(Math.floor(Math.random() * Number(value))), Type.functionType([[Type.Integer, [Type.Integer]]], true));
150
+ const funcDecodeInteger = new Constant((value, encoding = "i64", byteOffset) => decodeInteger(value, encoding, byteOffset == null ? undefined : Number(byteOffset)), Type.functionType([[Type.OptionalInteger, [Type.OptionalBuffer, Type.OptionalString, Type.OptionalInteger]]]));
122
151
  const funcParseInteger = new Constant((value) => {
123
152
  try {
124
- return value ? boundInteger(BigInt(value)) : undefined;
153
+ return value ? int64(BigInt(value)) : undefined;
125
154
  }
126
155
  catch { }
127
156
  return undefined;
128
- }, Type.functionType(Type.OptionalInteger, [Type.OptionalString]));
129
- export const funcInteger = new Constant((value) => createInteger(Number(value)) ?? 0n, Type.union(Type.functionType(Type.Integer, [Type.Boolean]), Type.functionType(Type.Integer, [Type.Timestamp]), Type.functionType(Type.Integer, [Type.Float])));
130
- export const constInteger = Object.assign(Object.create(null), {
157
+ }, Type.functionType([[Type.OptionalInteger, [Type.OptionalString]]]));
158
+ export const funcInteger = new Constant((value) => createInteger(Number(value)) ?? 0n, Type.functionType([
159
+ [Type.Integer, [Type.Boolean]],
160
+ [Type.Integer, [Type.Timestamp]],
161
+ [Type.Integer, [Type.Float]],
162
+ ]));
163
+ export const globInteger = Object.assign(Object.create(null), {
131
164
  Sum: funcSum,
132
165
  Min: funcMin,
133
166
  Max: funcMax,
@@ -1,5 +1,3 @@
1
1
  import { Constant } from "../Constant.js";
2
2
  export declare const funcLength: Constant;
3
3
  export declare const funcContains: Constant;
4
- export declare const funcAt: Constant;
5
- export declare const funcHas: Constant;
@@ -2,14 +2,13 @@ import { Constant } from "../Constant.js";
2
2
  import { Type } from "../Type.js";
3
3
  import { containsBuffer } from "./Buffer.js";
4
4
  import { containsString } from "./String.js";
5
- import { boundInteger } from "./Integer.js";
6
- export const funcLength = new Constant((value) => boundInteger(BigInt(value == null
5
+ export const funcLength = new Constant((value) => BigInt(value == null
7
6
  ? 0
8
7
  : value instanceof ArrayBuffer
9
8
  ? value.byteLength
10
9
  : typeof value === "string" || Array.isArray(value)
11
10
  ? value.length
12
- : Object.keys(value).length)), Type.functionType(Type.Integer, [Type.Iterable]));
11
+ : Object.keys(value).length), Type.functionType([[Type.Integer, [Type.OptionalIterable]]]));
13
12
  export const funcContains = new Constant((value, search, start, ignoreCaseSpaceEtc) => value == null
14
13
  ? false
15
14
  : value instanceof ArrayBuffer
@@ -18,27 +17,9 @@ export const funcContains = new Constant((value, search, start, ignoreCaseSpaceE
18
17
  ? containsString(value, search, start == null ? undefined : Number(start), ignoreCaseSpaceEtc)
19
18
  : Array.isArray(value)
20
19
  ? value.includes(search, start == null ? undefined : Number(start))
21
- : Object.values(value).includes(search), Type.union(Type.functionType(Type.Boolean, [Type.Buffer, Type.Buffer, Type.OptionalInteger]), Type.functionType(Type.Boolean, [Type.String, Type.String, Type.OptionalInteger, Type.OptionalBoolean]), Type.functionType(Type.Boolean, [Type.Array, Type.Unknown, Type.OptionalInteger]), Type.functionType(Type.Boolean, [Type.Object, Type.Unknown])));
22
- export const funcAt = new Constant((value, index) => {
23
- if (value == null) {
24
- return undefined;
25
- }
26
- else if (Array.isArray(value)) {
27
- const num = Number(index);
28
- const ix = num < 0 ? value.length + num : num;
29
- return ix >= 0 && ix < value.length ? value[ix] : undefined;
30
- }
31
- const key = String(index);
32
- return Object.hasOwn(value, key) ? value[key] : undefined;
33
- }, Type.union(Type.functionType(Type.Unknown, [Type.Array, Type.Integer]), Type.functionType(Type.Unknown, [Type.Object, Type.String])));
34
- export const funcHas = new Constant((value, index) => {
35
- if (value == null) {
36
- return false;
37
- }
38
- else if (Array.isArray(value)) {
39
- const num = Number(index);
40
- const ix = num < 0 ? value.length + num : num;
41
- return ix >= 0 && ix < value.length;
42
- }
43
- return Object.hasOwn(value, String(index));
44
- }, Type.union(Type.functionType(Type.Boolean, [Type.Array, Type.Integer]), Type.functionType(Type.Boolean, [Type.Object, Type.String])));
20
+ : Object.values(value).includes(search), Type.functionType([
21
+ [Type.Boolean, [Type.Buffer, Type.Buffer, Type.OptionalInteger]],
22
+ [Type.Boolean, [Type.String, Type.String, Type.OptionalInteger, Type.OptionalBoolean]],
23
+ [Type.Boolean, [Type.Array, Type.Any, Type.OptionalInteger]],
24
+ [Type.Boolean, [Type.Object, Type.Any]],
25
+ ]));
@@ -9,9 +9,7 @@ export interface NumberFormatting {
9
9
  max_significant_digits?: number;
10
10
  notation?: "standard" | "scientific";
11
11
  }
12
- export declare const formatLiteralNumber: (value: bigint | number) => string;
13
12
  export declare const parseLiteralNumber: (value: string, offset?: number) => readonly [number | bigint, number];
14
- export declare const formatNumber: (value: bigint | number, formatting?: string) => string;
15
13
  export declare const funcGreaterThan: Constant;
16
14
  export declare const funcLessThan: Constant;
17
15
  export declare const funcGreaterOrEqual: Constant;