@elaraai/east 1.0.84 → 1.0.85

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 (239) hide show
  1. package/dist/src/analyze.d.ts.map +1 -1
  2. package/dist/src/analyze.js +48 -0
  3. package/dist/src/analyze.js.map +1 -1
  4. package/dist/src/ast_to_ir.coerce_to.spec.js +4 -4
  5. package/dist/src/ast_to_ir.coerce_to.spec.js.map +1 -1
  6. package/dist/src/ast_to_ir.d.ts +6 -1
  7. package/dist/src/ast_to_ir.d.ts.map +1 -1
  8. package/dist/src/ast_to_ir.js +20 -7
  9. package/dist/src/ast_to_ir.js.map +1 -1
  10. package/dist/src/builtins.d.ts +1 -1
  11. package/dist/src/builtins.d.ts.map +1 -1
  12. package/dist/src/builtins.js +52 -0
  13. package/dist/src/builtins.js.map +1 -1
  14. package/dist/src/codegen/canonical.d.ts +37 -0
  15. package/dist/src/codegen/canonical.d.ts.map +1 -0
  16. package/dist/src/codegen/canonical.js +208 -0
  17. package/dist/src/codegen/canonical.js.map +1 -0
  18. package/dist/src/codegen/codegen.spec.js +132 -201
  19. package/dist/src/codegen/codegen.spec.js.map +1 -1
  20. package/dist/src/codegen/printer.d.ts.map +1 -1
  21. package/dist/src/codegen/printer.js +142 -24
  22. package/dist/src/codegen/printer.js.map +1 -1
  23. package/dist/src/codegen/spellings.d.ts +4 -1
  24. package/dist/src/codegen/spellings.d.ts.map +1 -1
  25. package/dist/src/codegen/spellings.js +5 -1
  26. package/dist/src/codegen/spellings.js.map +1 -1
  27. package/dist/src/compile/builtins/index.d.ts.map +1 -1
  28. package/dist/src/compile/builtins/index.js +2 -0
  29. package/dist/src/compile/builtins/index.js.map +1 -1
  30. package/dist/src/compile/builtins/primitives.d.ts.map +1 -1
  31. package/dist/src/compile/builtins/primitives.js +2 -1
  32. package/dist/src/compile/builtins/primitives.js.map +1 -1
  33. package/dist/src/compile/builtins/query.d.ts +10 -0
  34. package/dist/src/compile/builtins/query.d.ts.map +1 -0
  35. package/dist/src/compile/builtins/query.js +5 -0
  36. package/dist/src/compile/builtins/query.js.map +1 -0
  37. package/dist/src/expr/block.d.ts.map +1 -1
  38. package/dist/src/expr/block.js +2 -1
  39. package/dist/src/expr/block.js.map +1 -1
  40. package/dist/src/expr/index.d.ts +75 -47
  41. package/dist/src/expr/index.d.ts.map +1 -1
  42. package/dist/src/expr/index.js +31 -0
  43. package/dist/src/expr/index.js.map +1 -1
  44. package/dist/src/expr/libs/datetime.d.ts +20 -20
  45. package/dist/src/expr/libs/datetime.d.ts.map +1 -1
  46. package/dist/src/expr/libs/datetime.js +208 -167
  47. package/dist/src/expr/libs/datetime.js.map +1 -1
  48. package/dist/src/expr/libs/float.d.ts +15 -15
  49. package/dist/src/expr/libs/float.d.ts.map +1 -1
  50. package/dist/src/expr/libs/float.js +298 -267
  51. package/dist/src/expr/libs/float.js.map +1 -1
  52. package/dist/src/expr/libs/integer.d.ts +12 -12
  53. package/dist/src/expr/libs/integer.d.ts.map +1 -1
  54. package/dist/src/expr/libs/integer.js +219 -194
  55. package/dist/src/expr/libs/integer.js.map +1 -1
  56. package/dist/src/expr/libs/lazy.d.ts +28 -0
  57. package/dist/src/expr/libs/lazy.d.ts.map +1 -0
  58. package/dist/src/expr/libs/lazy.js +55 -0
  59. package/dist/src/expr/libs/lazy.js.map +1 -0
  60. package/dist/src/expr/libs/lazy.spec.d.ts +6 -0
  61. package/dist/src/expr/libs/lazy.spec.d.ts.map +1 -0
  62. package/dist/src/expr/libs/lazy.spec.js +102 -0
  63. package/dist/src/expr/libs/lazy.spec.js.map +1 -0
  64. package/dist/src/expr/query.d.ts +60 -0
  65. package/dist/src/expr/query.d.ts.map +1 -0
  66. package/dist/src/expr/query.js +84 -0
  67. package/dist/src/expr/query.js.map +1 -0
  68. package/dist/src/index.d.ts +3 -0
  69. package/dist/src/index.d.ts.map +1 -1
  70. package/dist/src/index.js +3 -0
  71. package/dist/src/index.js.map +1 -1
  72. package/dist/src/internal.d.ts +4 -0
  73. package/dist/src/internal.d.ts.map +1 -1
  74. package/dist/src/internal.js +9 -0
  75. package/dist/src/internal.js.map +1 -1
  76. package/dist/src/location.d.ts +22 -0
  77. package/dist/src/location.d.ts.map +1 -1
  78. package/dist/src/location.js +31 -0
  79. package/dist/src/location.js.map +1 -1
  80. package/dist/src/naming.d.ts +5 -3
  81. package/dist/src/naming.d.ts.map +1 -1
  82. package/dist/src/naming.js.map +1 -1
  83. package/dist/src/portable.spec.d.ts +6 -0
  84. package/dist/src/portable.spec.d.ts.map +1 -0
  85. package/dist/src/portable.spec.js +181 -0
  86. package/dist/src/portable.spec.js.map +1 -0
  87. package/dist/src/query/evaluate.d.ts +98 -0
  88. package/dist/src/query/evaluate.d.ts.map +1 -0
  89. package/dist/src/query/evaluate.js +193 -0
  90. package/dist/src/query/evaluate.js.map +1 -0
  91. package/dist/src/query/index.d.ts +17 -0
  92. package/dist/src/query/index.d.ts.map +1 -0
  93. package/dist/src/query/index.js +17 -0
  94. package/dist/src/query/index.js.map +1 -0
  95. package/dist/src/query/jq/catalog.d.ts +174 -0
  96. package/dist/src/query/jq/catalog.d.ts.map +1 -0
  97. package/dist/src/query/jq/catalog.js +1740 -0
  98. package/dist/src/query/jq/catalog.js.map +1 -0
  99. package/dist/src/query/jq/check.d.ts +210 -0
  100. package/dist/src/query/jq/check.d.ts.map +1 -0
  101. package/dist/src/query/jq/check.js +2261 -0
  102. package/dist/src/query/jq/check.js.map +1 -0
  103. package/dist/src/query/jq/complete.d.ts +89 -0
  104. package/dist/src/query/jq/complete.d.ts.map +1 -0
  105. package/dist/src/query/jq/complete.js +320 -0
  106. package/dist/src/query/jq/complete.js.map +1 -0
  107. package/dist/src/query/jq/describe.d.ts +53 -0
  108. package/dist/src/query/jq/describe.d.ts.map +1 -0
  109. package/dist/src/query/jq/describe.js +149 -0
  110. package/dist/src/query/jq/describe.js.map +1 -0
  111. package/dist/src/query/jq/lex.d.ts +118 -0
  112. package/dist/src/query/jq/lex.d.ts.map +1 -0
  113. package/dist/src/query/jq/lex.js +371 -0
  114. package/dist/src/query/jq/lex.js.map +1 -0
  115. package/dist/src/query/jq/literals.d.ts +49 -0
  116. package/dist/src/query/jq/literals.d.ts.map +1 -0
  117. package/dist/src/query/jq/literals.js +78 -0
  118. package/dist/src/query/jq/literals.js.map +1 -0
  119. package/dist/src/query/jq/messages.d.ts +126 -0
  120. package/dist/src/query/jq/messages.d.ts.map +1 -0
  121. package/dist/src/query/jq/messages.js +172 -0
  122. package/dist/src/query/jq/messages.js.map +1 -0
  123. package/dist/src/query/jq/parse.d.ts +70 -0
  124. package/dist/src/query/jq/parse.d.ts.map +1 -0
  125. package/dist/src/query/jq/parse.js +1013 -0
  126. package/dist/src/query/jq/parse.js.map +1 -0
  127. package/dist/src/query/jq/print.d.ts +59 -0
  128. package/dist/src/query/jq/print.d.ts.map +1 -0
  129. package/dist/src/query/jq/print.js +587 -0
  130. package/dist/src/query/jq/print.js.map +1 -0
  131. package/dist/src/query/jq/shapes.d.ts +345 -0
  132. package/dist/src/query/jq/shapes.d.ts.map +1 -0
  133. package/dist/src/query/jq/shapes.js +584 -0
  134. package/dist/src/query/jq/shapes.js.map +1 -0
  135. package/dist/src/query/jq/spans.d.ts +133 -0
  136. package/dist/src/query/jq/spans.d.ts.map +1 -0
  137. package/dist/src/query/jq/spans.js +195 -0
  138. package/dist/src/query/jq/spans.js.map +1 -0
  139. package/dist/src/query/jq/split.d.ts +334 -0
  140. package/dist/src/query/jq/split.d.ts.map +1 -0
  141. package/dist/src/query/jq/split.js +2108 -0
  142. package/dist/src/query/jq/split.js.map +1 -0
  143. package/dist/src/query/jq/strftime.d.ts +20 -0
  144. package/dist/src/query/jq/strftime.d.ts.map +1 -0
  145. package/dist/src/query/jq/strftime.js +65 -0
  146. package/dist/src/query/jq/strftime.js.map +1 -0
  147. package/dist/src/query/jq/summary.d.ts +139 -0
  148. package/dist/src/query/jq/summary.d.ts.map +1 -0
  149. package/dist/src/query/jq/summary.js +222 -0
  150. package/dist/src/query/jq/summary.js.map +1 -0
  151. package/dist/src/query/jq/translate-builtins.d.ts +21 -0
  152. package/dist/src/query/jq/translate-builtins.d.ts.map +1 -0
  153. package/dist/src/query/jq/translate-builtins.js +1873 -0
  154. package/dist/src/query/jq/translate-builtins.js.map +1 -0
  155. package/dist/src/query/jq/translate.d.ts +627 -0
  156. package/dist/src/query/jq/translate.d.ts.map +1 -0
  157. package/dist/src/query/jq/translate.js +3364 -0
  158. package/dist/src/query/jq/translate.js.map +1 -0
  159. package/dist/src/query/types.d.ts +505 -0
  160. package/dist/src/query/types.d.ts.map +1 -0
  161. package/dist/src/query/types.js +231 -0
  162. package/dist/src/query/types.js.map +1 -0
  163. package/dist/src/runner_exec.d.ts +134 -0
  164. package/dist/src/runner_exec.d.ts.map +1 -0
  165. package/dist/src/runner_exec.js +371 -0
  166. package/dist/src/runner_exec.js.map +1 -0
  167. package/dist/src/runner_exec.spec.d.ts +6 -0
  168. package/dist/src/runner_exec.spec.d.ts.map +1 -0
  169. package/dist/src/runner_exec.spec.js +198 -0
  170. package/dist/src/runner_exec.spec.js.map +1 -0
  171. package/dist/src/runner_io.d.ts +370 -0
  172. package/dist/src/runner_io.d.ts.map +1 -0
  173. package/dist/src/runner_io.js +563 -0
  174. package/dist/src/runner_io.js.map +1 -0
  175. package/dist/src/runner_io.spec.d.ts +6 -0
  176. package/dist/src/runner_io.spec.d.ts.map +1 -0
  177. package/dist/src/runner_io.spec.js +224 -0
  178. package/dist/src/runner_io.spec.js.map +1 -0
  179. package/dist/src/runner_merge.d.ts +95 -0
  180. package/dist/src/runner_merge.d.ts.map +1 -0
  181. package/dist/src/runner_merge.js +238 -0
  182. package/dist/src/runner_merge.js.map +1 -0
  183. package/dist/src/runner_protocol.d.ts +11 -4
  184. package/dist/src/runner_protocol.d.ts.map +1 -1
  185. package/dist/src/runner_protocol.js +11 -4
  186. package/dist/src/runner_protocol.js.map +1 -1
  187. package/dist/src/serialization/beast2/index.d.ts +1 -1
  188. package/dist/src/serialization/beast2/index.d.ts.map +1 -1
  189. package/dist/src/serialization/beast2/index.js.map +1 -1
  190. package/dist/src/serialization/beast2/v5/frames.d.ts +10 -6
  191. package/dist/src/serialization/beast2/v5/frames.d.ts.map +1 -1
  192. package/dist/src/serialization/beast2/v5/frames.js +10 -6
  193. package/dist/src/serialization/beast2/v5/frames.js.map +1 -1
  194. package/dist/src/serialization/beast2/v5/frames.spec.d.ts +6 -0
  195. package/dist/src/serialization/beast2/v5/frames.spec.d.ts.map +1 -0
  196. package/dist/src/serialization/beast2/v5/frames.spec.js +42 -0
  197. package/dist/src/serialization/beast2/v5/frames.spec.js.map +1 -0
  198. package/dist/src/serialization/beast2/v5/index.spec.js +108 -0
  199. package/dist/src/serialization/beast2/v5/index.spec.js.map +1 -1
  200. package/dist/src/serialization/beast2/v5/lazy.d.ts +12 -7
  201. package/dist/src/serialization/beast2/v5/lazy.d.ts.map +1 -1
  202. package/dist/src/serialization/beast2/v5/lazy.js +16 -6
  203. package/dist/src/serialization/beast2/v5/lazy.js.map +1 -1
  204. package/dist/src/serialization/beast2/v5/lazy.spec.js +159 -18
  205. package/dist/src/serialization/beast2/v5/lazy.spec.js.map +1 -1
  206. package/dist/src/serialization/beast2/v5/stream.d.ts +110 -21
  207. package/dist/src/serialization/beast2/v5/stream.d.ts.map +1 -1
  208. package/dist/src/serialization/beast2/v5/stream.js +153 -42
  209. package/dist/src/serialization/beast2/v5/stream.js.map +1 -1
  210. package/dist/src/serialization/beast2/v5/weight.d.ts +36 -0
  211. package/dist/src/serialization/beast2/v5/weight.d.ts.map +1 -0
  212. package/dist/src/serialization/beast2/v5/weight.js +238 -0
  213. package/dist/src/serialization/beast2/v5/weight.js.map +1 -0
  214. package/dist/src/serialization/crc32.d.ts +38 -0
  215. package/dist/src/serialization/crc32.d.ts.map +1 -0
  216. package/dist/src/serialization/crc32.js +70 -0
  217. package/dist/src/serialization/crc32.js.map +1 -0
  218. package/dist/src/serialization/crc32.spec.d.ts +6 -0
  219. package/dist/src/serialization/crc32.spec.d.ts.map +1 -0
  220. package/dist/src/serialization/crc32.spec.js +92 -0
  221. package/dist/src/serialization/crc32.spec.js.map +1 -0
  222. package/dist/src/serialization/east-inferred.spec.js +4 -0
  223. package/dist/src/serialization/east-inferred.spec.js.map +1 -1
  224. package/dist/src/serialization/east.d.ts.map +1 -1
  225. package/dist/src/serialization/east.js +134 -110
  226. package/dist/src/serialization/east.js.map +1 -1
  227. package/dist/src/serialization/east.spec.js +185 -4
  228. package/dist/src/serialization/east.spec.js.map +1 -1
  229. package/dist/src/serialization/east_text.d.ts +25 -0
  230. package/dist/src/serialization/east_text.d.ts.map +1 -0
  231. package/dist/src/serialization/east_text.js +29 -0
  232. package/dist/src/serialization/east_text.js.map +1 -0
  233. package/dist/src/serialization/index.d.ts +1 -1
  234. package/dist/src/serialization/index.d.ts.map +1 -1
  235. package/dist/src/types.d.ts +1 -1
  236. package/dist/src/types.d.ts.map +1 -1
  237. package/dist/src/types.js +7 -6
  238. package/dist/src/types.js.map +1 -1
  239. package/package.json +6 -3
@@ -4,8 +4,9 @@
4
4
  */
5
5
  import { IntegerType, StringType } from "../../types.js";
6
6
  import { Expr } from "../expr.js";
7
+ import { lazyLibrary } from "./lazy.js";
7
8
  /** Standard library functions for integers */
8
- export default {
9
+ export default lazyLibrary({
9
10
  /**
10
11
  * Formats an integer with comma separators for thousands.
11
12
  *
@@ -23,30 +24,32 @@ export default {
23
24
  * compiled(-5432n); // "-5,432"
24
25
  * ```
25
26
  */
26
- printCommaSeperated: Expr.function([IntegerType], StringType, ($, x) => {
27
- const y = $.let(x);
28
- const negative = $.let(false);
29
- $.if(Expr.less(y, 0n), $ => {
30
- $.if(Expr.equal(y, -9223372036854775808n), $ => $.return("-9,223,372,036,854,775,808")); // cannot negate -2^63 as an i64
31
- $.assign(negative, true);
32
- $.assign(y, y.negate());
33
- });
34
- const ret = $.let("");
35
- $.while(Expr.greater(y, 999n), $ => {
36
- const z = $.let(y.remainder(1000n));
37
- $.if(Expr.less(z, 10n), $ => {
38
- $.assign(ret, Expr.str `,00${z}${ret}`);
39
- }).else($ => {
40
- $.if(Expr.less(z, 100n), $ => {
41
- $.assign(ret, Expr.str `,0${z}${ret}`);
27
+ get printCommaSeperated() {
28
+ return Expr.function([IntegerType], StringType, ($, x) => {
29
+ const y = $.let(x);
30
+ const negative = $.let(false);
31
+ $.if(Expr.less(y, 0n), $ => {
32
+ $.if(Expr.equal(y, -9223372036854775808n), $ => $.return("-9,223,372,036,854,775,808")); // cannot negate -2^63 as an i64
33
+ $.assign(negative, true);
34
+ $.assign(y, y.negate());
35
+ });
36
+ const ret = $.let("");
37
+ $.while(Expr.greater(y, 999n), $ => {
38
+ const z = $.let(y.remainder(1000n));
39
+ $.if(Expr.less(z, 10n), $ => {
40
+ $.assign(ret, Expr.str `,00${z}${ret}`);
42
41
  }).else($ => {
43
- $.assign(ret, Expr.str `,${z}${ret}`);
42
+ $.if(Expr.less(z, 100n), $ => {
43
+ $.assign(ret, Expr.str `,0${z}${ret}`);
44
+ }).else($ => {
45
+ $.assign(ret, Expr.str `,${z}${ret}`);
46
+ });
44
47
  });
48
+ $.assign(y, y.divide(1000n));
45
49
  });
46
- $.assign(y, y.divide(1000n));
50
+ $.if(negative, $ => $.return(Expr.str `-${y}${ret}`)).else($ => $.return(Expr.str `${y}${ret}`));
47
51
  });
48
- $.if(negative, $ => $.return(Expr.str `-${y}${ret}`)).else($ => $.return(Expr.str `${y}${ret}`));
49
- }),
52
+ },
50
53
  /**
51
54
  * Formats a float as currency with comma separators and 2 decimal places.
52
55
  *
@@ -65,35 +68,37 @@ export default {
65
68
  * compiled(1000000n); // "$1,000,000"
66
69
  * ```
67
70
  */
68
- printCurrency: Expr.function([IntegerType], StringType, ($, x) => {
69
- // Check for NaN/Infinity
70
- const negative = $.let(Expr.less(x, 0n));
71
- const abs_x = $.let(x.abs());
72
- // Round to cents
73
- const shifted = $.let(abs_x.multiply(100.0).add(0.5));
74
- const cents_total_float = $.let(shifted.subtract(shifted.remainder(1.0)));
75
- const cents_total = $.let(cents_total_float.toInteger());
76
- const dollars = $.let(cents_total.divide(100n));
77
- // Format dollars with commas
78
- const dollars_with_commas = $.let(dollars);
79
- const comma_ret = $.let("");
80
- $.while(Expr.greater(dollars_with_commas, 999n), $ => {
81
- const z = $.let(dollars_with_commas.remainder(1000n));
82
- $.if(Expr.less(z, 10n), $ => {
83
- $.assign(comma_ret, Expr.str `,00${z}${comma_ret}`);
84
- }).else($ => {
85
- $.if(Expr.less(z, 100n), $ => {
86
- $.assign(comma_ret, Expr.str `,0${z}${comma_ret}`);
71
+ get printCurrency() {
72
+ return Expr.function([IntegerType], StringType, ($, x) => {
73
+ // Check for NaN/Infinity
74
+ const negative = $.let(Expr.less(x, 0n));
75
+ const abs_x = $.let(x.abs());
76
+ // Round to cents
77
+ const shifted = $.let(abs_x.multiply(100.0).add(0.5));
78
+ const cents_total_float = $.let(shifted.subtract(shifted.remainder(1.0)));
79
+ const cents_total = $.let(cents_total_float.toInteger());
80
+ const dollars = $.let(cents_total.divide(100n));
81
+ // Format dollars with commas
82
+ const dollars_with_commas = $.let(dollars);
83
+ const comma_ret = $.let("");
84
+ $.while(Expr.greater(dollars_with_commas, 999n), $ => {
85
+ const z = $.let(dollars_with_commas.remainder(1000n));
86
+ $.if(Expr.less(z, 10n), $ => {
87
+ $.assign(comma_ret, Expr.str `,00${z}${comma_ret}`);
87
88
  }).else($ => {
88
- $.assign(comma_ret, Expr.str `,${z}${comma_ret}`);
89
+ $.if(Expr.less(z, 100n), $ => {
90
+ $.assign(comma_ret, Expr.str `,0${z}${comma_ret}`);
91
+ }).else($ => {
92
+ $.assign(comma_ret, Expr.str `,${z}${comma_ret}`);
93
+ });
89
94
  });
95
+ $.assign(dollars_with_commas, dollars_with_commas.divide(1000n));
90
96
  });
91
- $.assign(dollars_with_commas, dollars_with_commas.divide(1000n));
97
+ const dollars_str = $.let(Expr.str `${dollars_with_commas}${comma_ret}`);
98
+ const result = $.let(Expr.str `${dollars_str}`);
99
+ $.return(negative.ifElse(() => Expr.str `-$${result}`, () => Expr.str `$${result}`));
92
100
  });
93
- const dollars_str = $.let(Expr.str `${dollars_with_commas}${comma_ret}`);
94
- const result = $.let(Expr.str `${dollars_str}`);
95
- $.return(negative.ifElse(() => Expr.str `-$${result}`, () => Expr.str `$${result}`));
96
- }),
101
+ },
97
102
  /**
98
103
  * Formats an integer in compact form with business unit suffixes.
99
104
  *
@@ -115,39 +120,41 @@ export default {
115
120
  * compiled(500n); // "500"
116
121
  * ```
117
122
  */
118
- printCompact: Expr.function([IntegerType], StringType, ($, x) => {
119
- const y = $.let(x);
120
- const negative = $.let(false);
121
- $.if(Expr.less(y, 0n), $ => {
122
- $.if(Expr.equal(y, -9223372036854775808n), $ => $.return("-9.22Qi")); // cannot negate -2^63 as an i64
123
- $.assign(negative, true);
124
- $.assign(y, y.negate());
125
- });
126
- $.if(Expr.less(y, 1000n), $ => $.return(negative.ifElse(() => Expr.str `-${y}`, () => Expr.str `${y}`)));
127
- const scale = $.let(1n);
128
- $.while(Expr.greaterEqual(y, 1000000n), $ => {
129
- $.assign(y, y.divide(1000n));
130
- $.assign(scale, scale.add(1n));
131
- });
132
- const suffix = $.let(Expr.equal(scale, 1n).ifElse(() => "K", () => Expr.equal(scale, 2n).ifElse(() => "M", () => Expr.equal(scale, 3n).ifElse(() => "B", () => Expr.equal(scale, 4n).ifElse(() => "T", () => Expr.equal(scale, 5n).ifElse(() => "Q", () => "Qi"))))));
133
- $.if(Expr.greaterEqual(y, 100000n), $ => {
134
- $.if(negative, $ => {
135
- $.return(Expr.str `-${y.divide(1000n)}${suffix}`);
123
+ get printCompact() {
124
+ return Expr.function([IntegerType], StringType, ($, x) => {
125
+ const y = $.let(x);
126
+ const negative = $.let(false);
127
+ $.if(Expr.less(y, 0n), $ => {
128
+ $.if(Expr.equal(y, -9223372036854775808n), $ => $.return("-9.22Qi")); // cannot negate -2^63 as an i64
129
+ $.assign(negative, true);
130
+ $.assign(y, y.negate());
131
+ });
132
+ $.if(Expr.less(y, 1000n), $ => $.return(negative.ifElse(() => Expr.str `-${y}`, () => Expr.str `${y}`)));
133
+ const scale = $.let(1n);
134
+ $.while(Expr.greaterEqual(y, 1000000n), $ => {
135
+ $.assign(y, y.divide(1000n));
136
+ $.assign(scale, scale.add(1n));
137
+ });
138
+ const suffix = $.let(Expr.equal(scale, 1n).ifElse(() => "K", () => Expr.equal(scale, 2n).ifElse(() => "M", () => Expr.equal(scale, 3n).ifElse(() => "B", () => Expr.equal(scale, 4n).ifElse(() => "T", () => Expr.equal(scale, 5n).ifElse(() => "Q", () => "Qi"))))));
139
+ $.if(Expr.greaterEqual(y, 100000n), $ => {
140
+ $.if(negative, $ => {
141
+ $.return(Expr.str `-${y.divide(1000n)}${suffix}`);
142
+ }).else($ => {
143
+ $.return(Expr.str `${y.divide(1000n)}${suffix}`);
144
+ });
145
+ });
146
+ $.if(Expr.greaterEqual(y, 10000n), $ => {
147
+ const part = $.let(y.divide(100n).remainder(10n));
148
+ $.if(negative, $ => $.return(Expr.str `-${y.divide(1000n)}.${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1000n)}.${part}${suffix}`));
149
+ });
150
+ const part = $.let(y.divide(10n).remainder(100n));
151
+ $.if(Expr.greaterEqual(part, 10n), $ => {
152
+ $.if(negative, $ => $.return(Expr.str `-${y.divide(1000n)}.${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1000n)}.${part}${suffix}`));
136
153
  }).else($ => {
137
- $.return(Expr.str `${y.divide(1000n)}${suffix}`);
154
+ $.if(negative, $ => $.return(Expr.str `-${y.divide(1000n)}.0${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1000n)}.0${part}${suffix}`));
138
155
  });
139
156
  });
140
- $.if(Expr.greaterEqual(y, 10000n), $ => {
141
- const part = $.let(y.divide(100n).remainder(10n));
142
- $.if(negative, $ => $.return(Expr.str `-${y.divide(1000n)}.${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1000n)}.${part}${suffix}`));
143
- });
144
- const part = $.let(y.divide(10n).remainder(100n));
145
- $.if(Expr.greaterEqual(part, 10n), $ => {
146
- $.if(negative, $ => $.return(Expr.str `-${y.divide(1000n)}.${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1000n)}.${part}${suffix}`));
147
- }).else($ => {
148
- $.if(negative, $ => $.return(Expr.str `-${y.divide(1000n)}.0${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1000n)}.0${part}${suffix}`));
149
- });
150
- }),
157
+ },
151
158
  /**
152
159
  * Formats an integer in compact form with SI (International System) unit suffixes.
153
160
  *
@@ -169,33 +176,35 @@ export default {
169
176
  * compiled(3140000000n); // "3.14G"
170
177
  * ```
171
178
  */
172
- printCompactSI: Expr.function([IntegerType], StringType, ($, x) => {
173
- const y = $.let(x);
174
- const negative = $.let(false);
175
- $.if(Expr.less(y, 0n), $ => {
176
- $.if(Expr.equal(y, -9223372036854775808n), $ => $.return("-9.22E")); // cannot negate -2^63 as an i64
177
- $.assign(negative, true);
178
- $.assign(y, y.negate());
179
- });
180
- $.if(Expr.less(y, 1000n), $ => $.return(negative.ifElse(() => Expr.str `-${y}`, () => Expr.str `${y}`)));
181
- const scale = $.let(1n);
182
- $.while(Expr.greaterEqual(y, 1000000n), $ => {
183
- $.assign(y, y.divide(1000n));
184
- $.assign(scale, scale.add(1n));
185
- });
186
- const suffix = $.let(Expr.equal(scale, 1n).ifElse(() => "k", () => Expr.equal(scale, 2n).ifElse(() => "M", () => Expr.equal(scale, 3n).ifElse(() => "G", () => Expr.equal(scale, 4n).ifElse(() => "T", () => Expr.equal(scale, 5n).ifElse(() => "P", () => "E"))))));
187
- $.if(Expr.greaterEqual(y, 100000n), $ => $.if(negative, $ => $.return(Expr.str `-${y.divide(1000n)}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1000n)}${suffix}`)));
188
- $.if(Expr.greaterEqual(y, 10000n), $ => {
189
- const part = $.let(y.divide(100n).remainder(10n));
190
- $.if(negative, $ => $.return(Expr.str `-${y.divide(1000n)}.${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1000n)}.${part}${suffix}`));
191
- });
192
- const part = $.let(y.divide(10n).remainder(100n));
193
- $.if(Expr.greaterEqual(part, 10n), $ => {
194
- $.if(negative, $ => $.return(Expr.str `-${y.divide(1000n)}.${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1000n)}.${part}${suffix}`));
195
- }).else($ => {
196
- $.if(negative, $ => $.return(Expr.str `-${y.divide(1000n)}.0${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1000n)}.0${part}${suffix}`));
179
+ get printCompactSI() {
180
+ return Expr.function([IntegerType], StringType, ($, x) => {
181
+ const y = $.let(x);
182
+ const negative = $.let(false);
183
+ $.if(Expr.less(y, 0n), $ => {
184
+ $.if(Expr.equal(y, -9223372036854775808n), $ => $.return("-9.22E")); // cannot negate -2^63 as an i64
185
+ $.assign(negative, true);
186
+ $.assign(y, y.negate());
187
+ });
188
+ $.if(Expr.less(y, 1000n), $ => $.return(negative.ifElse(() => Expr.str `-${y}`, () => Expr.str `${y}`)));
189
+ const scale = $.let(1n);
190
+ $.while(Expr.greaterEqual(y, 1000000n), $ => {
191
+ $.assign(y, y.divide(1000n));
192
+ $.assign(scale, scale.add(1n));
193
+ });
194
+ const suffix = $.let(Expr.equal(scale, 1n).ifElse(() => "k", () => Expr.equal(scale, 2n).ifElse(() => "M", () => Expr.equal(scale, 3n).ifElse(() => "G", () => Expr.equal(scale, 4n).ifElse(() => "T", () => Expr.equal(scale, 5n).ifElse(() => "P", () => "E"))))));
195
+ $.if(Expr.greaterEqual(y, 100000n), $ => $.if(negative, $ => $.return(Expr.str `-${y.divide(1000n)}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1000n)}${suffix}`)));
196
+ $.if(Expr.greaterEqual(y, 10000n), $ => {
197
+ const part = $.let(y.divide(100n).remainder(10n));
198
+ $.if(negative, $ => $.return(Expr.str `-${y.divide(1000n)}.${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1000n)}.${part}${suffix}`));
199
+ });
200
+ const part = $.let(y.divide(10n).remainder(100n));
201
+ $.if(Expr.greaterEqual(part, 10n), $ => {
202
+ $.if(negative, $ => $.return(Expr.str `-${y.divide(1000n)}.${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1000n)}.${part}${suffix}`));
203
+ }).else($ => {
204
+ $.if(negative, $ => $.return(Expr.str `-${y.divide(1000n)}.0${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1000n)}.0${part}${suffix}`));
205
+ });
197
206
  });
198
- }),
207
+ },
199
208
  /**
200
209
  * Formats an integer in compact form with binary computing unit suffixes.
201
210
  *
@@ -217,33 +226,35 @@ export default {
217
226
  * compiled(3221225472n); // "3Gi" (3 GiB)
218
227
  * ```
219
228
  */
220
- printCompactComputing: Expr.function([IntegerType], StringType, ($, x) => {
221
- const y = $.let(x);
222
- const negative = $.let(false);
223
- $.if(Expr.less(y, 0n), $ => {
224
- $.if(Expr.equal(y, -9223372036854775808n), $ => $.return("-7.99Ei")); // cannot negate -2^63 as an i64
225
- $.assign(negative, true);
226
- $.assign(y, y.negate());
227
- });
228
- $.if(Expr.less(y, 1000n), $ => $.return(negative.ifElse(() => Expr.str `-${y}`, () => Expr.str `${y}`)));
229
- const scale = $.let(1n);
230
- $.while(Expr.greaterEqual(y, 1048576n), $ => {
231
- $.assign(y, y.divide(1024n));
232
- $.assign(scale, scale.add(1n));
233
- });
234
- const suffix = $.let(Expr.equal(scale, 1n).ifElse(() => "ki", () => Expr.equal(scale, 2n).ifElse(() => "Mi", () => Expr.equal(scale, 3n).ifElse(() => "Gi", () => Expr.equal(scale, 4n).ifElse(() => "Ti", () => Expr.equal(scale, 5n).ifElse(() => "Pi", () => "Ei"))))));
235
- $.if(Expr.greaterEqual(y, 102400n), $ => $.if(negative, $ => $.return(Expr.str `-${y.divide(1024n)}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1024n)}${suffix}`)));
236
- $.if(Expr.greaterEqual(y, 10240n), $ => {
237
- const part = $.let(y.multiply(10n).divide(1024n).remainder(10n));
238
- $.if(negative, $ => $.return(Expr.str `-${y.divide(1024n)}.${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1024n)}.${part}${suffix}`));
239
- });
240
- const part = $.let(y.multiply(100n).divide(1024n).remainder(100n));
241
- $.if(Expr.greaterEqual(part, 10n), $ => {
242
- $.if(negative, $ => $.return(Expr.str `-${y.divide(1024n)}.${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1024n)}.${part}${suffix}`));
243
- }).else($ => {
244
- $.if(negative, $ => $.return(Expr.str `-${y.divide(1024n)}.0${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1024n)}.0${part}${suffix}`));
229
+ get printCompactComputing() {
230
+ return Expr.function([IntegerType], StringType, ($, x) => {
231
+ const y = $.let(x);
232
+ const negative = $.let(false);
233
+ $.if(Expr.less(y, 0n), $ => {
234
+ $.if(Expr.equal(y, -9223372036854775808n), $ => $.return("-7.99Ei")); // cannot negate -2^63 as an i64
235
+ $.assign(negative, true);
236
+ $.assign(y, y.negate());
237
+ });
238
+ $.if(Expr.less(y, 1000n), $ => $.return(negative.ifElse(() => Expr.str `-${y}`, () => Expr.str `${y}`)));
239
+ const scale = $.let(1n);
240
+ $.while(Expr.greaterEqual(y, 1048576n), $ => {
241
+ $.assign(y, y.divide(1024n));
242
+ $.assign(scale, scale.add(1n));
243
+ });
244
+ const suffix = $.let(Expr.equal(scale, 1n).ifElse(() => "ki", () => Expr.equal(scale, 2n).ifElse(() => "Mi", () => Expr.equal(scale, 3n).ifElse(() => "Gi", () => Expr.equal(scale, 4n).ifElse(() => "Ti", () => Expr.equal(scale, 5n).ifElse(() => "Pi", () => "Ei"))))));
245
+ $.if(Expr.greaterEqual(y, 102400n), $ => $.if(negative, $ => $.return(Expr.str `-${y.divide(1024n)}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1024n)}${suffix}`)));
246
+ $.if(Expr.greaterEqual(y, 10240n), $ => {
247
+ const part = $.let(y.multiply(10n).divide(1024n).remainder(10n));
248
+ $.if(negative, $ => $.return(Expr.str `-${y.divide(1024n)}.${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1024n)}.${part}${suffix}`));
249
+ });
250
+ const part = $.let(y.multiply(100n).divide(1024n).remainder(100n));
251
+ $.if(Expr.greaterEqual(part, 10n), $ => {
252
+ $.if(negative, $ => $.return(Expr.str `-${y.divide(1024n)}.${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1024n)}.${part}${suffix}`));
253
+ }).else($ => {
254
+ $.if(negative, $ => $.return(Expr.str `-${y.divide(1024n)}.0${part}${suffix}`)).else($ => $.return(Expr.str `${y.divide(1024n)}.0${part}${suffix}`));
255
+ });
245
256
  });
246
- }),
257
+ },
247
258
  /**
248
259
  * Formats an integer as an ordinal number.
249
260
  *
@@ -264,20 +275,22 @@ export default {
264
275
  * compiled(112n); // "112th"
265
276
  * ```
266
277
  */
267
- printOrdinal: Expr.function([IntegerType], StringType, ($, x) => {
268
- const abs_x = $.let(x.abs());
269
- const last_digit = $.let(abs_x.remainder(10n));
270
- const last_two_digits = $.let(abs_x.remainder(100n));
271
- // Special cases for 11th, 12th, 13th
272
- $.if(Expr.greaterEqual(last_two_digits, 11n).bitAnd(Expr.lessEqual(last_two_digits, 13n)), $ => {
273
- $.return(Expr.str `${x}th`);
274
- });
275
- $.if(Expr.equal(last_digit, 1n), $ => $.return(Expr.str `${x}st`)).else($ => {
276
- $.if(Expr.equal(last_digit, 2n), $ => $.return(Expr.str `${x}nd`)).else($ => {
277
- $.if(Expr.equal(last_digit, 3n), $ => $.return(Expr.str `${x}rd`)).else($ => $.return(Expr.str `${x}th`));
278
+ get printOrdinal() {
279
+ return Expr.function([IntegerType], StringType, ($, x) => {
280
+ const abs_x = $.let(x.abs());
281
+ const last_digit = $.let(abs_x.remainder(10n));
282
+ const last_two_digits = $.let(abs_x.remainder(100n));
283
+ // Special cases for 11th, 12th, 13th
284
+ $.if(Expr.greaterEqual(last_two_digits, 11n).bitAnd(Expr.lessEqual(last_two_digits, 13n)), $ => {
285
+ $.return(Expr.str `${x}th`);
286
+ });
287
+ $.if(Expr.equal(last_digit, 1n), $ => $.return(Expr.str `${x}st`)).else($ => {
288
+ $.if(Expr.equal(last_digit, 2n), $ => $.return(Expr.str `${x}nd`)).else($ => {
289
+ $.if(Expr.equal(last_digit, 3n), $ => $.return(Expr.str `${x}rd`)).else($ => $.return(Expr.str `${x}th`));
290
+ });
278
291
  });
279
292
  });
280
- }),
293
+ },
281
294
  /**
282
295
  * Counts the number of decimal digits in an integer (excluding the sign).
283
296
  *
@@ -296,10 +309,12 @@ export default {
296
309
  * compiled(1000000n); // 7n
297
310
  * ```
298
311
  */
299
- digitCount: Expr.function([IntegerType], IntegerType, ($, x) => {
300
- $.if(Expr.equal(x, 0n), $ => $.return(1n));
301
- $.return(x.abs().log(10n).add(1n));
302
- }),
312
+ get digitCount() {
313
+ return Expr.function([IntegerType], IntegerType, ($, x) => {
314
+ $.if(Expr.equal(x, 0n), $ => $.return(1n));
315
+ $.return(x.abs().log(10n).add(1n));
316
+ });
317
+ },
303
318
  /**
304
319
  * Rounds an integer to the nearest multiple of a step value.
305
320
  *
@@ -318,22 +333,24 @@ export default {
318
333
  * compiled(-17n, 5n); // -15n
319
334
  * ```
320
335
  */
321
- roundNearest: Expr.function([IntegerType, IntegerType], IntegerType, ($, x, step) => {
322
- // For step = 0, return original value
323
- $.if(Expr.equal(step, 0n), $ => $.return(x));
324
- const abs_step = $.let(step.abs());
325
- const abs_x = $.let(x.abs());
326
- const remainder = $.let(abs_x.remainder(abs_step));
327
- const half_step = $.let(abs_step.divide(2n));
328
- $.if(Expr.equal(remainder, 0n), $ => $.return(x) // Already a multiple
329
- ).else($ => {
330
- const rounded_abs = $.let(Expr.less(remainder, half_step)
331
- .ifElse(() => abs_x.subtract(remainder), // Round down
332
- () => abs_x.add(abs_step.subtract(remainder)) // Round up
333
- ));
334
- $.if(Expr.greaterEqual(x, 0n), $ => $.return(rounded_abs)).else($ => $.return(rounded_abs.negate()));
336
+ get roundNearest() {
337
+ return Expr.function([IntegerType, IntegerType], IntegerType, ($, x, step) => {
338
+ // For step = 0, return original value
339
+ $.if(Expr.equal(step, 0n), $ => $.return(x));
340
+ const abs_step = $.let(step.abs());
341
+ const abs_x = $.let(x.abs());
342
+ const remainder = $.let(abs_x.remainder(abs_step));
343
+ const half_step = $.let(abs_step.divide(2n));
344
+ $.if(Expr.equal(remainder, 0n), $ => $.return(x) // Already a multiple
345
+ ).else($ => {
346
+ const rounded_abs = $.let(Expr.less(remainder, half_step)
347
+ .ifElse(() => abs_x.subtract(remainder), // Round down
348
+ () => abs_x.add(abs_step.subtract(remainder)) // Round up
349
+ ));
350
+ $.if(Expr.greaterEqual(x, 0n), $ => $.return(rounded_abs)).else($ => $.return(rounded_abs.negate()));
351
+ });
335
352
  });
336
- }),
353
+ },
337
354
  /**
338
355
  * Rounds an integer up to the next multiple of a step value (ceiling).
339
356
  *
@@ -352,18 +369,20 @@ export default {
352
369
  * compiled(-17n, 5n); // -15n (towards zero for negatives)
353
370
  * ```
354
371
  */
355
- roundUp: Expr.function([IntegerType, IntegerType], IntegerType, ($, x, step) => {
356
- // For step = 0, return original value
357
- $.if(Expr.equal(step, 0n), $ => $.return(x));
358
- const abs_step = $.let(step.abs());
359
- const remainder = $.let(x.remainder(abs_step));
360
- $.if(Expr.equal(remainder, 0n), $ => $.return(x) // Already a multiple
361
- ).else($ => {
362
- $.if(Expr.greaterEqual(x, 0n), $ => $.return(x.add(abs_step.subtract(remainder))) // Positive: round up
363
- ).else($ => $.return(x.subtract(remainder)) // Negative: round towards zero
364
- );
372
+ get roundUp() {
373
+ return Expr.function([IntegerType, IntegerType], IntegerType, ($, x, step) => {
374
+ // For step = 0, return original value
375
+ $.if(Expr.equal(step, 0n), $ => $.return(x));
376
+ const abs_step = $.let(step.abs());
377
+ const remainder = $.let(x.remainder(abs_step));
378
+ $.if(Expr.equal(remainder, 0n), $ => $.return(x) // Already a multiple
379
+ ).else($ => {
380
+ $.if(Expr.greaterEqual(x, 0n), $ => $.return(x.add(abs_step.subtract(remainder))) // Positive: round up
381
+ ).else($ => $.return(x.subtract(remainder)) // Negative: round towards zero
382
+ );
383
+ });
365
384
  });
366
- }),
385
+ },
367
386
  /**
368
387
  * Rounds an integer down to the previous multiple of a step value (floor).
369
388
  *
@@ -382,18 +401,20 @@ export default {
382
401
  * compiled(-17n, 5n); // -20n (away from zero for negatives)
383
402
  * ```
384
403
  */
385
- roundDown: Expr.function([IntegerType, IntegerType], IntegerType, ($, x, step) => {
386
- // For step = 0, return original value
387
- $.if(Expr.equal(step, 0n), $ => $.return(x));
388
- const abs_step = $.let(step.abs());
389
- const remainder = $.let(x.remainder(abs_step));
390
- $.if(Expr.equal(remainder, 0n), $ => $.return(x) // Already a multiple
391
- ).else($ => {
392
- $.if(Expr.greaterEqual(x, 0n), $ => $.return(x.subtract(remainder)) // Positive: round down
393
- ).else($ => $.return(x.subtract(abs_step.add(remainder))) // Negative: round away from zero
394
- );
404
+ get roundDown() {
405
+ return Expr.function([IntegerType, IntegerType], IntegerType, ($, x, step) => {
406
+ // For step = 0, return original value
407
+ $.if(Expr.equal(step, 0n), $ => $.return(x));
408
+ const abs_step = $.let(step.abs());
409
+ const remainder = $.let(x.remainder(abs_step));
410
+ $.if(Expr.equal(remainder, 0n), $ => $.return(x) // Already a multiple
411
+ ).else($ => {
412
+ $.if(Expr.greaterEqual(x, 0n), $ => $.return(x.subtract(remainder)) // Positive: round down
413
+ ).else($ => $.return(x.subtract(abs_step.add(remainder))) // Negative: round away from zero
414
+ );
415
+ });
395
416
  });
396
- }),
417
+ },
397
418
  /**
398
419
  * Rounds an integer towards zero to the nearest multiple of a step value (truncate).
399
420
  *
@@ -412,15 +433,17 @@ export default {
412
433
  * compiled(3n, 5n); // 0n
413
434
  * ```
414
435
  */
415
- roundTruncate: Expr.function([IntegerType, IntegerType], IntegerType, ($, x, step) => {
416
- // For step = 0, return original value
417
- $.if(Expr.equal(step, 0n), $ => $.return(x));
418
- const abs_step = $.let(step.abs());
419
- const remainder = $.let(x.remainder(abs_step));
420
- $.if(Expr.equal(remainder, 0n), $ => $.return(x) // Already a multiple
421
- ).else($ => $.return(x.subtract(remainder)) // Always subtract remainder (towards zero)
422
- );
423
- }),
436
+ get roundTruncate() {
437
+ return Expr.function([IntegerType, IntegerType], IntegerType, ($, x, step) => {
438
+ // For step = 0, return original value
439
+ $.if(Expr.equal(step, 0n), $ => $.return(x));
440
+ const abs_step = $.let(step.abs());
441
+ const remainder = $.let(x.remainder(abs_step));
442
+ $.if(Expr.equal(remainder, 0n), $ => $.return(x) // Already a multiple
443
+ ).else($ => $.return(x.subtract(remainder)) // Always subtract remainder (towards zero)
444
+ );
445
+ });
446
+ },
424
447
  /**
425
448
  * Formats an integer as a percentage.
426
449
  *
@@ -438,8 +461,10 @@ export default {
438
461
  * compiled(-25n); // "-25%"
439
462
  * ```
440
463
  */
441
- printPercentage: Expr.function([IntegerType], StringType, ($, x) => {
442
- $.return(Expr.str `${x}%`);
443
- }),
444
- };
464
+ get printPercentage() {
465
+ return Expr.function([IntegerType], StringType, ($, x) => {
466
+ $.return(Expr.str `${x}%`);
467
+ });
468
+ },
469
+ });
445
470
  //# sourceMappingURL=integer.js.map