@oliversalzburg/js-utils 0.7.0 → 0.8.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 (178) hide show
  1. package/lib/async/async.d.ts +44 -0
  2. package/lib/async/async.js +76 -0
  3. package/lib/async/async.js.map +1 -0
  4. package/lib/async/async.test.d.ts +1 -0
  5. package/lib/async/async.test.js +26 -0
  6. package/lib/async/async.test.js.map +1 -0
  7. package/lib/cli/args.d.ts +9 -0
  8. package/lib/cli/args.js +49 -0
  9. package/lib/cli/args.js.map +1 -0
  10. package/lib/cli/args.test.d.ts +1 -0
  11. package/lib/cli/args.test.js +31 -0
  12. package/lib/cli/args.test.js.map +1 -0
  13. package/lib/core.d.ts +43 -0
  14. package/lib/core.js +2 -0
  15. package/lib/core.js.map +1 -0
  16. package/lib/data/array.d.ts +55 -0
  17. package/lib/data/array.js +90 -0
  18. package/lib/data/array.js.map +1 -0
  19. package/lib/data/nil.d.ts +92 -0
  20. package/lib/data/nil.js +131 -0
  21. package/lib/data/nil.js.map +1 -0
  22. package/lib/data/random.d.ts +111 -0
  23. package/lib/data/random.js +381 -0
  24. package/lib/data/random.js.map +1 -0
  25. package/lib/data/string.d.ts +30 -0
  26. package/lib/data/string.js +53 -0
  27. package/lib/data/string.js.map +1 -0
  28. package/lib/data/tree.d.ts +28 -0
  29. package/lib/data/tree.js +45 -0
  30. package/lib/data/tree.js.map +1 -0
  31. package/lib/device/shake.d.ts +79 -0
  32. package/lib/device/shake.js +135 -0
  33. package/lib/device/shake.js.map +1 -0
  34. package/lib/dom/core.d.ts +21 -0
  35. package/lib/dom/core.js +41 -0
  36. package/lib/dom/core.js.map +1 -0
  37. package/lib/errors/AbstractError.d.ts +29 -0
  38. package/lib/errors/AbstractError.js +59 -0
  39. package/lib/errors/AbstractError.js.map +1 -0
  40. package/lib/errors/InternalError.d.ts +19 -0
  41. package/lib/errors/InternalError.js +38 -0
  42. package/lib/errors/InternalError.js.map +1 -0
  43. package/lib/errors/InvalidArgumentError.d.ts +13 -0
  44. package/lib/errors/InvalidArgumentError.js +22 -0
  45. package/lib/errors/InvalidArgumentError.js.map +1 -0
  46. package/lib/errors/InvalidOperationError.d.ts +13 -0
  47. package/lib/errors/InvalidOperationError.js +22 -0
  48. package/lib/errors/InvalidOperationError.js.map +1 -0
  49. package/lib/errors/NotImplementedError.d.ts +12 -0
  50. package/lib/errors/NotImplementedError.js +21 -0
  51. package/lib/errors/NotImplementedError.js.map +1 -0
  52. package/lib/errors/PermissionViolationError.d.ts +13 -0
  53. package/lib/errors/PermissionViolationError.js +22 -0
  54. package/lib/errors/PermissionViolationError.js.map +1 -0
  55. package/lib/errors/ResourceConflictError.d.ts +12 -0
  56. package/lib/errors/ResourceConflictError.js +21 -0
  57. package/lib/errors/ResourceConflictError.js.map +1 -0
  58. package/lib/errors/UnknownError.d.ts +16 -0
  59. package/lib/errors/UnknownError.js +25 -0
  60. package/lib/errors/UnknownError.js.map +1 -0
  61. package/lib/errors/console.d.ts +7 -0
  62. package/lib/errors/console.js +13 -0
  63. package/lib/errors/console.js.map +1 -0
  64. package/lib/errors/error-serializer.d.ts +45 -0
  65. package/lib/errors/error-serializer.js +74 -0
  66. package/lib/errors/error-serializer.js.map +1 -0
  67. package/lib/errors/error-serializer.test.d.ts +1 -0
  68. package/lib/errors/error-serializer.test.js +109 -0
  69. package/lib/errors/error-serializer.test.js.map +1 -0
  70. package/lib/errors/stream.d.ts +7 -0
  71. package/lib/errors/stream.js +15 -0
  72. package/lib/errors/stream.js.map +1 -0
  73. package/lib/errors/tools.d.ts +10 -0
  74. package/lib/errors/tools.js +13 -0
  75. package/lib/errors/tools.js.map +1 -0
  76. package/lib/events/event.d.ts +9 -0
  77. package/lib/events/event.js +10 -0
  78. package/lib/events/event.js.map +1 -0
  79. package/lib/format/bytes.d.ts +118 -0
  80. package/lib/format/bytes.js +138 -0
  81. package/lib/format/bytes.js.map +1 -0
  82. package/lib/format/bytes.test.d.ts +1 -0
  83. package/lib/format/bytes.test.js +146 -0
  84. package/lib/format/bytes.test.js.map +1 -0
  85. package/lib/format/count.d.ts +14 -0
  86. package/lib/format/count.js +51 -0
  87. package/lib/format/count.js.map +1 -0
  88. package/lib/format/count.test.d.ts +1 -0
  89. package/lib/format/count.test.js +42 -0
  90. package/lib/format/count.test.js.map +1 -0
  91. package/lib/format/milliseconds.d.ts +100 -0
  92. package/lib/format/milliseconds.js +199 -0
  93. package/lib/format/milliseconds.js.map +1 -0
  94. package/lib/format/milliseconds.test.d.ts +1 -0
  95. package/lib/format/milliseconds.test.js +393 -0
  96. package/lib/format/milliseconds.test.js.map +1 -0
  97. package/lib/format/string.d.ts +24 -0
  98. package/lib/format/string.js +32 -0
  99. package/lib/format/string.js.map +1 -0
  100. package/lib/format/string.test.d.ts +1 -0
  101. package/lib/format/string.test.js +17 -0
  102. package/lib/format/string.test.js.map +1 -0
  103. package/lib/graphics/canvas-sandbox-mp.d.ts +258 -0
  104. package/lib/graphics/canvas-sandbox-mp.js +280 -0
  105. package/lib/graphics/canvas-sandbox-mp.js.map +1 -0
  106. package/lib/graphics/canvas-sandbox.d.ts +255 -0
  107. package/lib/graphics/canvas-sandbox.js +358 -0
  108. package/lib/graphics/canvas-sandbox.js.map +1 -0
  109. package/lib/graphics/canvas.d.ts +57 -0
  110. package/lib/graphics/canvas.js +37 -0
  111. package/lib/graphics/canvas.js.map +1 -0
  112. package/lib/graphics/canvas2d-headless.d.ts +85 -0
  113. package/lib/graphics/canvas2d-headless.js +197 -0
  114. package/lib/graphics/canvas2d-headless.js.map +1 -0
  115. package/lib/graphics/canvas2d.d.ts +162 -0
  116. package/lib/graphics/canvas2d.js +332 -0
  117. package/lib/graphics/canvas2d.js.map +1 -0
  118. package/lib/graphics/canvas3d.d.ts +41 -0
  119. package/lib/graphics/canvas3d.js +67 -0
  120. package/lib/graphics/canvas3d.js.map +1 -0
  121. package/lib/graphics/color.d.ts +22 -0
  122. package/lib/graphics/color.js +38 -0
  123. package/lib/graphics/color.js.map +1 -0
  124. package/lib/graphics/core.d.ts +89 -0
  125. package/lib/graphics/core.js +146 -0
  126. package/lib/graphics/core.js.map +1 -0
  127. package/lib/graphics/palette-sampler.d.ts +7 -0
  128. package/lib/graphics/palette-sampler.js +21 -0
  129. package/lib/graphics/palette-sampler.js.map +1 -0
  130. package/lib/graphics/palette.d.ts +120 -0
  131. package/lib/graphics/palette.js +574 -0
  132. package/lib/graphics/palette.js.map +1 -0
  133. package/lib/graphics/palette.test.d.ts +1 -0
  134. package/lib/graphics/palette.test.js +43 -0
  135. package/lib/graphics/palette.test.js.map +1 -0
  136. package/lib/graphics/render-loop.d.ts +76 -0
  137. package/lib/graphics/render-loop.js +114 -0
  138. package/lib/graphics/render-loop.js.map +1 -0
  139. package/lib/graphics/shader.d.ts +56 -0
  140. package/lib/graphics/shader.js +80 -0
  141. package/lib/graphics/shader.js.map +1 -0
  142. package/lib/log/log.d.ts +11 -0
  143. package/lib/log/log.js +2 -0
  144. package/lib/log/log.js.map +1 -0
  145. package/lib/log/report.d.ts +57 -0
  146. package/lib/log/report.js +88 -0
  147. package/lib/log/report.js.map +1 -0
  148. package/lib/math/core.d.ts +85 -0
  149. package/lib/math/core.js +125 -0
  150. package/lib/math/core.js.map +1 -0
  151. package/lib/math/easing.d.ts +204 -0
  152. package/lib/math/easing.js +366 -0
  153. package/lib/math/easing.js.map +1 -0
  154. package/lib/math/euler.d.ts +18 -0
  155. package/lib/math/euler.js +22 -0
  156. package/lib/math/euler.js.map +1 -0
  157. package/lib/math/matrix3.d.ts +227 -0
  158. package/lib/math/matrix3.js +508 -0
  159. package/lib/math/matrix3.js.map +1 -0
  160. package/lib/math/quaternion.d.ts +119 -0
  161. package/lib/math/quaternion.js +270 -0
  162. package/lib/math/quaternion.js.map +1 -0
  163. package/lib/math/transformation.d.ts +26 -0
  164. package/lib/math/transformation.js +31 -0
  165. package/lib/math/transformation.js.map +1 -0
  166. package/lib/math/vector2.d.ts +202 -0
  167. package/lib/math/vector2.js +310 -0
  168. package/lib/math/vector2.js.map +1 -0
  169. package/lib/math/vector3.d.ts +293 -0
  170. package/lib/math/vector3.js +492 -0
  171. package/lib/math/vector3.js.map +1 -0
  172. package/lib/math/vector4.d.ts +182 -0
  173. package/lib/math/vector4.js +302 -0
  174. package/lib/math/vector4.js.map +1 -0
  175. package/lib/measurement/performance.d.ts +13 -0
  176. package/lib/measurement/performance.js +19 -0
  177. package/lib/measurement/performance.js.map +1 -0
  178. package/package.json +5 -7
@@ -0,0 +1,44 @@
1
+ import type { AnyAsyncFunction, AnyFunctionReturning, ConstructorOf } from "../core.js";
2
+ /**
3
+ * Wraps the given asynchronous function in a new function that will ignore any outcome of
4
+ * the context as it resolves.
5
+ *
6
+ * This can be useful when providing asynchonous event handler to `.addEventlistener()`,
7
+ * which only expects synchronous functions.
8
+ * @param context - The asynchronous function to execute.
9
+ * @returns A function returning nothing.
10
+ */
11
+ export declare const prepareAsyncContext: (context: AnyAsyncFunction) => (
12
+ /**
13
+ * The arguments that our new function was called with.
14
+ */
15
+ ...args: Array<unknown>) => void;
16
+ /**
17
+ * Executes an asynchronous function and resolves with an alternative result
18
+ * in case the function failed.
19
+ * @param executable - The asynchronous function to execute.
20
+ * @param to - The result we want to return when the function errors.
21
+ * @param filter - An {@linkcode !Error} subclass. If defined, only errors of
22
+ * this type will be coalesced.
23
+ * @typeParam TExecutableReturn - The return type of the function.
24
+ * @typeParam TCoalesce - The type of the object to coalesce to.
25
+ * @typeParam TFilter - The type of the error filter.
26
+ * @returns Whatever the function resolved to, or the provided replacement,
27
+ * in case the function failed.
28
+ */
29
+ export declare const coalesceOnRejection: <TExecutableReturn, TCoalesce, TFilter extends ConstructorOf<Error>>(executable: AnyFunctionReturning<TExecutableReturn | Promise<TExecutableReturn>>, to: TCoalesce, filter?: TFilter) => Promise<TCoalesce | TExecutableReturn>;
30
+ /**
31
+ * Wait a given period before continuing execution.
32
+ * @param duration - How many milliseconds to wait.
33
+ * @returns Nothing
34
+ */
35
+ export declare const sleep: (duration: number) => Promise<void>;
36
+ /**
37
+ * Executes an asynchronous function and retries the execution if it rejects.
38
+ * @param executable - The asynchronous function to execute.
39
+ * @param retryDelay - The duration to wait after a failed execution.
40
+ * @param retryCount - How often should the execution be retried?
41
+ * @typeParam TExecutableReturn - The return type of the function.
42
+ * @returns Whatever the function resolved to.
43
+ */
44
+ export declare const retry: <TExecutableReturn>(executable: AnyFunctionReturning<TExecutableReturn | Promise<TExecutableReturn>>, retryDelay?: number, retryCount?: number) => Promise<TExecutableReturn>;
@@ -0,0 +1,76 @@
1
+ import { redirectErrorsToConsole } from "../errors/console.js";
2
+ /**
3
+ * Wraps the given asynchronous function in a new function that will ignore any outcome of
4
+ * the context as it resolves.
5
+ *
6
+ * This can be useful when providing asynchonous event handler to `.addEventlistener()`,
7
+ * which only expects synchronous functions.
8
+ * @param context - The asynchronous function to execute.
9
+ * @returns A function returning nothing.
10
+ */
11
+ export const prepareAsyncContext = (context) => {
12
+ return (
13
+ /**
14
+ * The arguments that our new function was called with.
15
+ */
16
+ ...args) => {
17
+ void context(...args)
18
+ .then(() => undefined)
19
+ .catch(redirectErrorsToConsole(console));
20
+ };
21
+ };
22
+ /**
23
+ * Executes an asynchronous function and resolves with an alternative result
24
+ * in case the function failed.
25
+ * @param executable - The asynchronous function to execute.
26
+ * @param to - The result we want to return when the function errors.
27
+ * @param filter - An {@linkcode !Error} subclass. If defined, only errors of
28
+ * this type will be coalesced.
29
+ * @typeParam TExecutableReturn - The return type of the function.
30
+ * @typeParam TCoalesce - The type of the object to coalesce to.
31
+ * @typeParam TFilter - The type of the error filter.
32
+ * @returns Whatever the function resolved to, or the provided replacement,
33
+ * in case the function failed.
34
+ */
35
+ export const coalesceOnRejection = async (executable, to, filter) => {
36
+ try {
37
+ return await executable();
38
+ }
39
+ catch (error) {
40
+ if ((filter !== undefined && error instanceof filter) || !filter) {
41
+ return to;
42
+ }
43
+ throw error;
44
+ }
45
+ };
46
+ /**
47
+ * Wait a given period before continuing execution.
48
+ * @param duration - How many milliseconds to wait.
49
+ * @returns Nothing
50
+ */
51
+ export const sleep = (duration) => {
52
+ return new Promise((resolve) => setTimeout(resolve, duration));
53
+ };
54
+ /**
55
+ * Executes an asynchronous function and retries the execution if it rejects.
56
+ * @param executable - The asynchronous function to execute.
57
+ * @param retryDelay - The duration to wait after a failed execution.
58
+ * @param retryCount - How often should the execution be retried?
59
+ * @typeParam TExecutableReturn - The return type of the function.
60
+ * @returns Whatever the function resolved to.
61
+ */
62
+ export const retry = async (executable, retryDelay = 0, retryCount = 0) => {
63
+ try {
64
+ return await executable();
65
+ }
66
+ catch (error) {
67
+ if (0 < retryCount) {
68
+ if (0 < retryDelay) {
69
+ await sleep(retryDelay);
70
+ }
71
+ return retry(executable, retryDelay, --retryCount);
72
+ }
73
+ throw error;
74
+ }
75
+ };
76
+ //# sourceMappingURL=async.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async.js","sourceRoot":"","sources":["../../source/async/async.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAAyB,EAAE,EAAE;IAChE,OAAO;IACN;;OAEG;IACH,GAAG,IAAoB,EACtB,EAAE;QACH,KAAK,OAAO,CAAC,GAAG,IAAI,CAAC;aACnB,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;aACrB,KAAK,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC;AACH,CAAC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAKvC,UAEC,EACD,EAAa,EACb,MAAgB,EACf,EAAE;IACH,IAAI,CAAC;QACJ,OAAO,MAAM,UAAU,EAAE,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,YAAY,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YAClE,OAAO,EAAE,CAAC;QACX,CAAC;QACD,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,QAAgB,EAAiB,EAAE;IACxD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AAChE,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EACzB,UAEC,EACD,UAAU,GAAG,CAAC,EACd,UAAU,GAAG,CAAC,EACe,EAAE;IAC/B,IAAI,CAAC;QACJ,OAAO,MAAM,UAAU,EAAE,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,CAAC,GAAG,UAAU,EAAE,CAAC;YACpB,IAAI,CAAC,GAAG,UAAU,EAAE,CAAC;gBACpB,MAAM,KAAK,CAAC,UAAU,CAAC,CAAC;YACzB,CAAC;YACD,OAAO,KAAK,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,UAAU,CAAC,CAAC;QACpD,CAAC;QACD,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import assert from "node:assert";
2
+ import { it } from "node:test";
3
+ import { prepareAsyncContext, sleep } from "./async.js";
4
+ it("executes trivial callback", async () => {
5
+ let executed = false;
6
+ const callback = prepareAsyncContext(async () => {
7
+ await sleep(1);
8
+ executed = true;
9
+ });
10
+ callback();
11
+ await sleep(100);
12
+ assert.strictEqual(executed, true);
13
+ });
14
+ it("passes parameters to callback", async () => {
15
+ let executed = false;
16
+ const callback = prepareAsyncContext(async (event, eventId) => {
17
+ assert.strictEqual(event.name, "call");
18
+ assert.strictEqual(eventId, 42);
19
+ await sleep(1);
20
+ executed = true;
21
+ });
22
+ callback({ name: "call" }, 42);
23
+ await sleep(100);
24
+ assert.strictEqual(executed, true);
25
+ });
26
+ //# sourceMappingURL=async.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async.test.js","sourceRoot":"","sources":["../../source/async/async.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExD,EAAE,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;IAC1C,IAAI,QAAQ,GAAG,KAAK,CAAC;IAErB,MAAM,QAAQ,GAAG,mBAAmB,CAAC,KAAK,IAAI,EAAE;QAC/C,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC;QACf,QAAQ,GAAG,IAAI,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,QAAQ,EAAE,CAAC;IAEX,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAEjB,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;IAC9C,IAAI,QAAQ,GAAG,KAAK,CAAC;IAErB,MAAM,QAAQ,GAAG,mBAAmB,CACnC,KAAK,EAAE,KAA6B,EAAE,OAAe,EAAE,EAAE;QACxD,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACvC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAEhC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC;QACf,QAAQ,GAAG,IAAI,CAAC;IACjB,CAAC,CACD,CAAC;IAEF,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;IAE/B,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAEjB,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Parse CLI arguments.
3
+ * @param {Array<string>} argv - Expected to be process.argv
4
+ * @param {boolean} expectUnlabeled - Is the command line expected to have
5
+ * at least one trailing argument that is not labeled?
6
+ */
7
+ export declare const parseArgv: (argv: Array<string>, expectUnlabeled?: boolean) => {
8
+ "": Array<string> | undefined;
9
+ } & Record<string, boolean | string | Array<string>>;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Parse CLI arguments.
3
+ * @param {Array<string>} argv - Expected to be process.argv
4
+ * @param {boolean} expectUnlabeled - Is the command line expected to have
5
+ * at least one trailing argument that is not labeled?
6
+ */
7
+ export const parseArgv = (argv, expectUnlabeled = false) => argv.slice(2).reduce((acc, _, index, array) => {
8
+ let slot;
9
+ let value;
10
+ if (!_.startsWith("--")) {
11
+ if (acc.prev === undefined ||
12
+ (expectUnlabeled && index === array.length - 1)) {
13
+ slot = "";
14
+ }
15
+ else {
16
+ slot = acc.prev;
17
+ acc.prev = undefined;
18
+ }
19
+ value = _;
20
+ }
21
+ else {
22
+ const argument = _.substring(2);
23
+ const parts = argument.match(/^(?<name>[^=]+)=?(?<value>.*)$/);
24
+ if (parts === null || parts.groups === undefined) {
25
+ return acc;
26
+ }
27
+ slot = parts.groups.name ?? parts.groups.value;
28
+ value =
29
+ typeof parts.groups.value === "string" && parts.groups.value !== ""
30
+ ? parts.groups.value
31
+ : true;
32
+ if (parts.groups.value === "") {
33
+ acc.prev = slot;
34
+ }
35
+ }
36
+ const argSlot = acc.args[slot];
37
+ acc.args[slot] =
38
+ Array.isArray(argSlot) && typeof value === "string"
39
+ ? [...argSlot, value]
40
+ : slot === "" && typeof value === "string"
41
+ ? [value]
42
+ : typeof argSlot === "undefined" ||
43
+ typeof argSlot === "boolean" ||
44
+ typeof value === "boolean"
45
+ ? value
46
+ : [...(Array.isArray(argSlot) ? argSlot : [argSlot]), value];
47
+ return acc;
48
+ }, { args: {} }).args;
49
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.js","sourceRoot":"","sources":["../../source/cli/args.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACxB,IAAmB,EACnB,eAAe,GAAG,KAAK,EAItB,EAAE,CACH,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CACnB,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;IACxB,IAAI,IAAY,CAAC;IACjB,IAAI,KAAoB,CAAC;IAEzB,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,IACC,GAAG,CAAC,IAAI,KAAK,SAAS;YACtB,CAAC,eAAe,IAAI,KAAK,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAC9C,CAAC;YACF,IAAI,GAAG,EAAE,CAAC;QACX,CAAC;aAAM,CAAC;YACP,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;YAChB,GAAG,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,CAAC;QACD,KAAK,GAAG,CAAC,CAAC;IACX,CAAC;SAAM,CAAC;QACP,MAAM,QAAQ,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAC/D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAClD,OAAO,GAAG,CAAC;QACZ,CAAC;QAED,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;QAC/C,KAAK;YACJ,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,EAAE;gBAClE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK;gBACpB,CAAC,CAAC,IAAI,CAAC;QACT,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,KAAK,EAAE,EAAE,CAAC;YAC/B,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,CAAC;IACF,CAAC;IAED,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;QACb,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ;YAClD,CAAC,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,CAAC;YACrB,CAAC,CAAC,IAAI,KAAK,EAAE,IAAI,OAAO,KAAK,KAAK,QAAQ;gBACzC,CAAC,CAAC,CAAC,KAAK,CAAC;gBACT,CAAC,CAAC,OAAO,OAAO,KAAK,WAAW;oBAC9B,OAAO,OAAO,KAAK,SAAS;oBAC5B,OAAO,KAAK,KAAK,SAAS;oBAC3B,CAAC,CAAC,KAAK;oBACP,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAEjE,OAAO,GAAG,CAAC;AACZ,CAAC,EACD,EAAE,IAAI,EAAE,EAAE,EAMT,CACD,CAAC,IAAI,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ import assert from "node:assert";
2
+ import { it } from "node:test";
3
+ import { parseArgv } from "./args.js";
4
+ it("parses boolean parameters", () => {
5
+ assert.deepStrictEqual(parseArgv(["node", "script.js", "--yes"]), {
6
+ yes: true,
7
+ });
8
+ assert.deepStrictEqual(parseArgv(["node", "script.js", "--yes", "filename.ext"], true), {
9
+ "": ["filename.ext"],
10
+ yes: true,
11
+ });
12
+ });
13
+ it("parses parameters using '='", () => {
14
+ assert.deepStrictEqual(parseArgv(["node", "script.js", "--yes=true"]), {
15
+ yes: "true",
16
+ });
17
+ assert.deepStrictEqual(parseArgv(["node", "script.js", "--yes=true", "filename.ext"]), {
18
+ "": ["filename.ext"],
19
+ yes: "true",
20
+ });
21
+ });
22
+ it("parses parameters using ' '", () => {
23
+ assert.deepStrictEqual(parseArgv(["node", "script.js", "--yes", "true"]), {
24
+ yes: "true",
25
+ });
26
+ assert.deepStrictEqual(parseArgv(["node", "script.js", "--yes", "true", "filename.ext"]), {
27
+ "": ["filename.ext"],
28
+ yes: "true",
29
+ });
30
+ });
31
+ //# sourceMappingURL=args.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.test.js","sourceRoot":"","sources":["../../source/cli/args.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACpC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,EAAE;QACjE,GAAG,EAAE,IAAI;KACT,CAAC,CAAC;IACH,MAAM,CAAC,eAAe,CACrB,SAAS,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,IAAI,CAAC,EAC/D;QACC,EAAE,EAAE,CAAC,cAAc,CAAC;QACpB,GAAG,EAAE,IAAI;KACT,CACD,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;IACtC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC,EAAE;QACtE,GAAG,EAAE,MAAM;KACX,CAAC,CAAC;IACH,MAAM,CAAC,eAAe,CACrB,SAAS,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC,EAC9D;QACC,EAAE,EAAE,CAAC,cAAc,CAAC;QACpB,GAAG,EAAE,MAAM;KACX,CACD,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;IACtC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,EAAE;QACzE,GAAG,EAAE,MAAM;KACX,CAAC,CAAC;IACH,MAAM,CAAC,eAAe,CACrB,SAAS,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,EACjE;QACC,EAAE,EAAE,CAAC,cAAc,CAAC;QACpB,GAAG,EAAE,MAAM;KACX,CACD,CAAC;AACH,CAAC,CAAC,CAAC"}
package/lib/core.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Describes a function that is a constructor for something.
3
+ * @typeParam TConstructed - The type this is a constructor for.
4
+ */
5
+ export type ConstructorOf<TConstructed> = new (...args: Array<any>) => TConstructed;
6
+ /**
7
+ * Describes any function.
8
+ */
9
+ export type AnyFunction = (...args: Array<any>) => any;
10
+ /**
11
+ * Describes any asynchronous function.
12
+ */
13
+ export type AnyAsyncFunction = (...args: Array<any>) => Promise<any>;
14
+ /**
15
+ * Any constructor
16
+ */
17
+ export type AnyConstructor = new (...args: Array<any>) => any;
18
+ /**
19
+ * Describes a function returning an instance of a given type.
20
+ * @typeParam TReturned - The type of the item returned by the function.
21
+ */
22
+ export type AnyFunctionReturning<TReturned = any> = (...args: Array<any>) => TReturned;
23
+ /**
24
+ * Describes an async function returning an instance of a given type.
25
+ * @typeParam TReturned - The type of the item returned by the function.
26
+ */
27
+ export type AnyAsyncFunctionReturning<TReturned = any> = (...args: Array<any>) => Promise<TReturned>;
28
+ /**
29
+ * Describes a class "mixin", which is a function that returns a dynamically
30
+ * constructed class, based on the passed parameters.
31
+ *
32
+ * **Hint**: Don't use mixins.
33
+ * @typeParam TTarget - The type of the classed this mixin is being
34
+ * mixed in with.
35
+ */
36
+ export type Mixin<TTarget extends AnyFunctionReturning> = InstanceType<ReturnType<TTarget>>;
37
+ /**
38
+ * Recursive definition of a regular JS object, which is a key-value hash
39
+ * of strings to primitives, or another object of the same type.
40
+ */
41
+ export type JsonObject = string | number | boolean | null | Array<JsonObject> | {
42
+ [key: string]: JsonObject;
43
+ };
package/lib/core.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../source/core.ts"],"names":[],"mappings":""}
@@ -0,0 +1,55 @@
1
+ import type { ConstructorOf } from "../core.js";
2
+ /**
3
+ * Places the items in the array in random order.
4
+ * The array is shuffled in-place, no copy is created. The returned array is exactly the passed array.
5
+ * @param array - The array to shuffle.
6
+ * @typeParam TElements - The type of the elements in the array.
7
+ * @returns The passed array in random order.
8
+ */
9
+ export declare const shuffleArray: <TElements>(array: Array<TElements>) => TElements[];
10
+ /**
11
+ * Returns an array that holds all items that appear in both
12
+ * passed arrays.
13
+ * @param a - The first array.
14
+ * @param b - The second array.
15
+ * @typeParam TElements - The type of the elements in the array.
16
+ * @returns A new array which holds the items that appear in
17
+ * both passed arrays.
18
+ */
19
+ export declare const intersect: <TElements>(a: Array<TElements>, b: Array<TElements>) => TElements[];
20
+ /**
21
+ * Returns an array that holds all items that only appear in `a`.
22
+ * @param a - The first array.
23
+ * @param b - The second array.
24
+ * @typeParam TElements - The type of the elements in the array.
25
+ * @returns A new array which holds the items that ony appear in `a`.
26
+ */
27
+ export declare const difference: <TElements>(a: Array<TElements>, b: Array<TElements>) => TElements[];
28
+ /**
29
+ * From an array with unknown contents, retrieve all the elements
30
+ * that are of a certain type and return them as a new array.
31
+ * @param array - The array to filter.
32
+ * @param InstanceType - The type to search for.
33
+ * @typeParam TElements - The type of the elements in the array.
34
+ * @returns A new array with the filtered items.
35
+ */
36
+ export declare const filterType: <TElements>(array: Array<unknown>, InstanceType: ConstructorOf<TElements>) => Array<TElements>;
37
+ /**
38
+ * From an iterable with unknown contents, yield arrays that contain items from
39
+ * the iterable up to a given limit.
40
+ * @param iterable - The iterable to retrieve items from.
41
+ * @param limit - The amount of items in each chunk.
42
+ * @typeParam TElements - The type of the elements in the iterable.
43
+ * @yields Chunks from the provided iterable.
44
+ */
45
+ export declare const chunkify: <TElements>(iterable: Iterable<TElements>, limit: number) => Generator<TElements[], void, unknown>;
46
+ /**
47
+ * Group all elements of the input array, that produce the same identity,
48
+ * into a new array.
49
+ * @param array - The array with the items to group.
50
+ * @param ident - Callback that identifies the group of the element.
51
+ * @typeParam TElements - The type of the elements in the array.
52
+ * @typeParam TGroupKey - The type of the group identifier.
53
+ * @returns A map that correlates the group key to an array of all elements with that group key.
54
+ */
55
+ export declare const groupBy: <TElements, TGroupKey>(array: Array<TElements>, ident: (element: TElements) => TGroupKey) => Map<TGroupKey, Array<TElements>>;
@@ -0,0 +1,90 @@
1
+ import { is } from "./nil.js";
2
+ /**
3
+ * Places the items in the array in random order.
4
+ * The array is shuffled in-place, no copy is created. The returned array is exactly the passed array.
5
+ * @param array - The array to shuffle.
6
+ * @typeParam TElements - The type of the elements in the array.
7
+ * @returns The passed array in random order.
8
+ */
9
+ export const shuffleArray = (array) => {
10
+ for (let index = array.length - 1; index > 0; index--) {
11
+ const targetIndex = Math.trunc(Math.random() * (index + 1));
12
+ const temp = array[index];
13
+ array[index] = array[targetIndex];
14
+ array[targetIndex] = temp;
15
+ }
16
+ return array;
17
+ };
18
+ /**
19
+ * Returns an array that holds all items that appear in both
20
+ * passed arrays.
21
+ * @param a - The first array.
22
+ * @param b - The second array.
23
+ * @typeParam TElements - The type of the elements in the array.
24
+ * @returns A new array which holds the items that appear in
25
+ * both passed arrays.
26
+ */
27
+ export const intersect = (a, b) => {
28
+ return a.filter((x) => b.includes(x));
29
+ };
30
+ /**
31
+ * Returns an array that holds all items that only appear in `a`.
32
+ * @param a - The first array.
33
+ * @param b - The second array.
34
+ * @typeParam TElements - The type of the elements in the array.
35
+ * @returns A new array which holds the items that ony appear in `a`.
36
+ */
37
+ export const difference = (a, b) => {
38
+ return a.filter((x) => !b.includes(x));
39
+ };
40
+ /**
41
+ * From an array with unknown contents, retrieve all the elements
42
+ * that are of a certain type and return them as a new array.
43
+ * @param array - The array to filter.
44
+ * @param InstanceType - The type to search for.
45
+ * @typeParam TElements - The type of the elements in the array.
46
+ * @returns A new array with the filtered items.
47
+ */
48
+ export const filterType = (array, InstanceType) => array.filter((element) => is(element, InstanceType));
49
+ /**
50
+ * From an iterable with unknown contents, yield arrays that contain items from
51
+ * the iterable up to a given limit.
52
+ * @param iterable - The iterable to retrieve items from.
53
+ * @param limit - The amount of items in each chunk.
54
+ * @typeParam TElements - The type of the elements in the iterable.
55
+ * @yields Chunks from the provided iterable.
56
+ */
57
+ export const chunkify = function* (iterable, limit) {
58
+ let chunk = [];
59
+ for (const element of iterable) {
60
+ chunk.push(element);
61
+ if (chunk.length === limit) {
62
+ yield chunk;
63
+ chunk = [];
64
+ }
65
+ }
66
+ if (chunk.length) {
67
+ yield chunk;
68
+ }
69
+ };
70
+ /**
71
+ * Group all elements of the input array, that produce the same identity,
72
+ * into a new array.
73
+ * @param array - The array with the items to group.
74
+ * @param ident - Callback that identifies the group of the element.
75
+ * @typeParam TElements - The type of the elements in the array.
76
+ * @typeParam TGroupKey - The type of the group identifier.
77
+ * @returns A map that correlates the group key to an array of all elements with that group key.
78
+ */
79
+ export const groupBy = (array, ident) => {
80
+ const result = new Map();
81
+ for (const element of array) {
82
+ const id = ident(element);
83
+ if (!result.has(id)) {
84
+ result.set(id, new Array());
85
+ }
86
+ result.get(id)?.push(element);
87
+ }
88
+ return result;
89
+ };
90
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../../source/data/array.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAE9B;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAY,KAAuB,EAAE,EAAE;IAClE,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACvD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1B,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;QAClC,KAAK,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;IAC3B,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACxB,CAAmB,EACnB,CAAmB,EAClB,EAAE;IACH,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACzB,CAAmB,EACnB,CAAmB,EAClB,EAAE;IACH,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACzB,KAAqB,EACrB,YAAsC,EACrC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAqB,CAAC;AAE9E;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,QAAQ,CAAC,EAChC,QAA6B,EAC7B,KAAa;IAEb,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAChC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;YAC5B,MAAM,KAAK,CAAC;YACZ,KAAK,GAAG,EAAE,CAAC;QACZ,CAAC;IACF,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CACtB,KAAuB,EACvB,KAAwC,EACL,EAAE;IACrC,MAAM,MAAM,GAAG,IAAI,GAAG,EAA+B,CAAC;IACtD,KAAK,MAAM,OAAO,IAAI,KAAK,EAAE,CAAC;QAC7B,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YACrB,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,KAAK,EAAa,CAAC,CAAC;QACxC,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC,CAAC"}
@@ -0,0 +1,92 @@
1
+ import type { ConstructorOf } from "../core.js";
2
+ /**
3
+ * When you want to normalize away `null` | `undefined`, or deal
4
+ * with either type through a consistent interface.
5
+ */
6
+ export type Nil = null | undefined;
7
+ /**
8
+ * A type that could be either what you want, or `Nil`.
9
+ * @typeParam T - The type that should be made nillable.
10
+ */
11
+ export type Maybe<T> = T | Nil;
12
+ /**
13
+ * Check if something is nil.
14
+ * Can be used as a typeguard.
15
+ * @param subject - The subject that could be nil.
16
+ * @typeParam TSubject - The type of the subject.
17
+ * @returns `true` if the subject is nil, `false` otherwise.
18
+ */
19
+ export declare function isNil<TSubject>(subject: Maybe<TSubject>): subject is Nil;
20
+ /**
21
+ * Check if something is a concrete value of the given type.
22
+ * Can be used as a typeguard.
23
+ * @param subject - The subject that could be nil.
24
+ * @param Prototype - The prototype to check against.
25
+ * @typeParam TSubject - The type to check against.
26
+ * @returns `true` if the input element matches the given type,
27
+ * `false` otherwise.
28
+ */
29
+ export declare function is<TSubject>(subject: Maybe<TSubject> | unknown, Prototype: ConstructorOf<TSubject>): subject is TSubject;
30
+ /**
31
+ * Thrown when an unexpected nil value was encountered.
32
+ */
33
+ export declare class UnexpectedNilError extends Error {
34
+ /**
35
+ * Constructs a new {@linkcode UnexpectedNilError}.
36
+ * @param message - The error message.
37
+ */
38
+ constructor(message?: string);
39
+ }
40
+ /**
41
+ * Ensure that the passed subject is not nil; throw otherwise.
42
+ * @param subject - A subject that is possibly nil.
43
+ * @param errorMessage - An optional error message to throw when the subject is nil.
44
+ * @typeParam TSubject - The type of the subject.
45
+ * @returns The subject, if it isn't nil.
46
+ * @throws {@linkcode UnexpectedNilError} When the subject is nil.
47
+ */
48
+ export declare function mustExist<TSubject>(subject: Maybe<TSubject>, errorMessage?: string): TSubject;
49
+ /**
50
+ * Ensure that all passed subjects are not nil; throw otherwise.
51
+ * @param subjects - The subjects that are possibly nil.
52
+ * @param errorMessage - An optional error message to throw when a subject is nil.
53
+ * @typeParam TSubject - The type a the subject.
54
+ * @returns The subjects, if they aren't nil.
55
+ * @throws {@linkcode UnexpectedNilError} When a subject is nil.
56
+ */
57
+ export declare function mustExistAll<TSubject>(subjects: Array<Maybe<TSubject>>, errorMessage?: string): Array<TSubject>;
58
+ /**
59
+ * Ensure that the passed subject is not nil; throw otherwise.
60
+ * @param subject - A subject that is possibly nil.
61
+ * @typeParam TSubject - The type of the subject.
62
+ * @throws {@linkcode UnexpectedNilError} When the subject is nil.
63
+ */
64
+ export declare function assertExists<TSubject>(subject: Maybe<TSubject>): asserts subject is TSubject;
65
+ /**
66
+ * Ensure that the passed subjects are not nil; throw otherwise.
67
+ * @param subjects - Subjects that are possibly nil.
68
+ * @typeParam TSubject - The type of a subject.
69
+ * @throws {@linkcode UnexpectedNilError} When a subject is nil.
70
+ */
71
+ export declare function assertExistsAll<TSubject>(subjects: Array<Maybe<TSubject>>): asserts subjects is Array<TSubject>;
72
+ /**
73
+ * Convert a nilable into a real value, if it is nil.
74
+ * @param nilable - The subject to convert to an optional.
75
+ * @param to - The value to coalese to.
76
+ * @returns The input value, if it wasn't nil, or the value to coalesce to.
77
+ */
78
+ export declare function coalesce<T>(nilable: Maybe<T>, to: T): T;
79
+ /**
80
+ * Drop all nil values from an array, or replaces them with another value.
81
+ * @param nilables - The subject to convert.
82
+ * @param to - The value to coalese to.
83
+ * @returns An array with where all values are not nil.
84
+ */
85
+ export declare function coalesceArray<T>(nilables: Array<Maybe<T>>, to?: Maybe<T>): Array<T>;
86
+ /**
87
+ * Convert a nilable into an optional argument.
88
+ * This means `null` is normalized to `undefined`.
89
+ * @param nilable - The subject to convert to an optional.
90
+ * @returns The value, normalized to `undefined`, if it was nil.
91
+ */
92
+ export declare function toOptional<T>(nilable: Maybe<T>): T | undefined;