@oliversalzburg/js-utils 0.6.0 → 0.7.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 (172) hide show
  1. package/package.json +5 -5
  2. package/lib/async/async.d.ts +0 -44
  3. package/lib/async/async.js +0 -76
  4. package/lib/async/async.js.map +0 -1
  5. package/lib/async/async.test.d.ts +0 -1
  6. package/lib/async/async.test.js +0 -26
  7. package/lib/async/async.test.js.map +0 -1
  8. package/lib/core.d.ts +0 -43
  9. package/lib/core.js +0 -2
  10. package/lib/core.js.map +0 -1
  11. package/lib/data/array.d.ts +0 -45
  12. package/lib/data/array.js +0 -70
  13. package/lib/data/array.js.map +0 -1
  14. package/lib/data/nil.d.ts +0 -92
  15. package/lib/data/nil.js +0 -131
  16. package/lib/data/nil.js.map +0 -1
  17. package/lib/data/random.d.ts +0 -111
  18. package/lib/data/random.js +0 -377
  19. package/lib/data/random.js.map +0 -1
  20. package/lib/data/string.d.ts +0 -30
  21. package/lib/data/string.js +0 -52
  22. package/lib/data/string.js.map +0 -1
  23. package/lib/data/tree.d.ts +0 -28
  24. package/lib/data/tree.js +0 -45
  25. package/lib/data/tree.js.map +0 -1
  26. package/lib/device/shake.d.ts +0 -79
  27. package/lib/device/shake.js +0 -135
  28. package/lib/device/shake.js.map +0 -1
  29. package/lib/dom/core.d.ts +0 -21
  30. package/lib/dom/core.js +0 -41
  31. package/lib/dom/core.js.map +0 -1
  32. package/lib/errors/AbstractError.d.ts +0 -29
  33. package/lib/errors/AbstractError.js +0 -59
  34. package/lib/errors/AbstractError.js.map +0 -1
  35. package/lib/errors/InternalError.d.ts +0 -19
  36. package/lib/errors/InternalError.js +0 -38
  37. package/lib/errors/InternalError.js.map +0 -1
  38. package/lib/errors/InvalidArgumentError.d.ts +0 -13
  39. package/lib/errors/InvalidArgumentError.js +0 -22
  40. package/lib/errors/InvalidArgumentError.js.map +0 -1
  41. package/lib/errors/InvalidOperationError.d.ts +0 -13
  42. package/lib/errors/InvalidOperationError.js +0 -22
  43. package/lib/errors/InvalidOperationError.js.map +0 -1
  44. package/lib/errors/NotImplementedError.d.ts +0 -12
  45. package/lib/errors/NotImplementedError.js +0 -21
  46. package/lib/errors/NotImplementedError.js.map +0 -1
  47. package/lib/errors/PermissionViolationError.d.ts +0 -13
  48. package/lib/errors/PermissionViolationError.js +0 -22
  49. package/lib/errors/PermissionViolationError.js.map +0 -1
  50. package/lib/errors/ResourceConflictError.d.ts +0 -12
  51. package/lib/errors/ResourceConflictError.js +0 -21
  52. package/lib/errors/ResourceConflictError.js.map +0 -1
  53. package/lib/errors/UnknownError.d.ts +0 -16
  54. package/lib/errors/UnknownError.js +0 -25
  55. package/lib/errors/UnknownError.js.map +0 -1
  56. package/lib/errors/console.d.ts +0 -7
  57. package/lib/errors/console.js +0 -13
  58. package/lib/errors/console.js.map +0 -1
  59. package/lib/errors/error-serializer.d.ts +0 -45
  60. package/lib/errors/error-serializer.js +0 -71
  61. package/lib/errors/error-serializer.js.map +0 -1
  62. package/lib/errors/error-serializer.test.d.ts +0 -1
  63. package/lib/errors/error-serializer.test.js +0 -109
  64. package/lib/errors/error-serializer.test.js.map +0 -1
  65. package/lib/errors/stream.d.ts +0 -7
  66. package/lib/errors/stream.js +0 -15
  67. package/lib/errors/stream.js.map +0 -1
  68. package/lib/errors/tools.d.ts +0 -10
  69. package/lib/errors/tools.js +0 -13
  70. package/lib/errors/tools.js.map +0 -1
  71. package/lib/events/event.d.ts +0 -9
  72. package/lib/events/event.js +0 -10
  73. package/lib/events/event.js.map +0 -1
  74. package/lib/format/bytes.d.ts +0 -118
  75. package/lib/format/bytes.js +0 -99
  76. package/lib/format/bytes.js.map +0 -1
  77. package/lib/format/bytes.test.d.ts +0 -1
  78. package/lib/format/bytes.test.js +0 -138
  79. package/lib/format/bytes.test.js.map +0 -1
  80. package/lib/format/count.d.ts +0 -14
  81. package/lib/format/count.js +0 -50
  82. package/lib/format/count.js.map +0 -1
  83. package/lib/format/count.test.d.ts +0 -1
  84. package/lib/format/count.test.js +0 -42
  85. package/lib/format/count.test.js.map +0 -1
  86. package/lib/format/milliseconds.d.ts +0 -100
  87. package/lib/format/milliseconds.js +0 -192
  88. package/lib/format/milliseconds.js.map +0 -1
  89. package/lib/format/milliseconds.test.d.ts +0 -1
  90. package/lib/format/milliseconds.test.js +0 -343
  91. package/lib/format/milliseconds.test.js.map +0 -1
  92. package/lib/format/string.d.ts +0 -24
  93. package/lib/format/string.js +0 -30
  94. package/lib/format/string.js.map +0 -1
  95. package/lib/format/string.test.d.ts +0 -1
  96. package/lib/format/string.test.js +0 -17
  97. package/lib/format/string.test.js.map +0 -1
  98. package/lib/graphics/canvas-sandbox-mp.d.ts +0 -258
  99. package/lib/graphics/canvas-sandbox-mp.js +0 -279
  100. package/lib/graphics/canvas-sandbox-mp.js.map +0 -1
  101. package/lib/graphics/canvas-sandbox.d.ts +0 -255
  102. package/lib/graphics/canvas-sandbox.js +0 -361
  103. package/lib/graphics/canvas-sandbox.js.map +0 -1
  104. package/lib/graphics/canvas.d.ts +0 -57
  105. package/lib/graphics/canvas.js +0 -37
  106. package/lib/graphics/canvas.js.map +0 -1
  107. package/lib/graphics/canvas2d-headless.d.ts +0 -85
  108. package/lib/graphics/canvas2d-headless.js +0 -193
  109. package/lib/graphics/canvas2d-headless.js.map +0 -1
  110. package/lib/graphics/canvas2d.d.ts +0 -162
  111. package/lib/graphics/canvas2d.js +0 -328
  112. package/lib/graphics/canvas2d.js.map +0 -1
  113. package/lib/graphics/canvas3d.d.ts +0 -41
  114. package/lib/graphics/canvas3d.js +0 -67
  115. package/lib/graphics/canvas3d.js.map +0 -1
  116. package/lib/graphics/color.d.ts +0 -22
  117. package/lib/graphics/color.js +0 -42
  118. package/lib/graphics/color.js.map +0 -1
  119. package/lib/graphics/core.d.ts +0 -89
  120. package/lib/graphics/core.js +0 -146
  121. package/lib/graphics/core.js.map +0 -1
  122. package/lib/graphics/palette-sampler.d.ts +0 -7
  123. package/lib/graphics/palette-sampler.js +0 -21
  124. package/lib/graphics/palette-sampler.js.map +0 -1
  125. package/lib/graphics/palette.d.ts +0 -120
  126. package/lib/graphics/palette.js +0 -494
  127. package/lib/graphics/palette.js.map +0 -1
  128. package/lib/graphics/palette.test.d.ts +0 -1
  129. package/lib/graphics/palette.test.js +0 -43
  130. package/lib/graphics/palette.test.js.map +0 -1
  131. package/lib/graphics/render-loop.d.ts +0 -80
  132. package/lib/graphics/render-loop.js +0 -120
  133. package/lib/graphics/render-loop.js.map +0 -1
  134. package/lib/graphics/shader.d.ts +0 -56
  135. package/lib/graphics/shader.js +0 -80
  136. package/lib/graphics/shader.js.map +0 -1
  137. package/lib/log/log.d.ts +0 -11
  138. package/lib/log/log.js +0 -2
  139. package/lib/log/log.js.map +0 -1
  140. package/lib/log/report.d.ts +0 -57
  141. package/lib/log/report.js +0 -88
  142. package/lib/log/report.js.map +0 -1
  143. package/lib/math/core.d.ts +0 -85
  144. package/lib/math/core.js +0 -125
  145. package/lib/math/core.js.map +0 -1
  146. package/lib/math/easing.d.ts +0 -204
  147. package/lib/math/easing.js +0 -332
  148. package/lib/math/easing.js.map +0 -1
  149. package/lib/math/euler.d.ts +0 -18
  150. package/lib/math/euler.js +0 -22
  151. package/lib/math/euler.js.map +0 -1
  152. package/lib/math/matrix3.d.ts +0 -217
  153. package/lib/math/matrix3.js +0 -508
  154. package/lib/math/matrix3.js.map +0 -1
  155. package/lib/math/quaternion.d.ts +0 -119
  156. package/lib/math/quaternion.js +0 -270
  157. package/lib/math/quaternion.js.map +0 -1
  158. package/lib/math/transformation.d.ts +0 -26
  159. package/lib/math/transformation.js +0 -31
  160. package/lib/math/transformation.js.map +0 -1
  161. package/lib/math/vector2.d.ts +0 -202
  162. package/lib/math/vector2.js +0 -310
  163. package/lib/math/vector2.js.map +0 -1
  164. package/lib/math/vector3.d.ts +0 -293
  165. package/lib/math/vector3.js +0 -492
  166. package/lib/math/vector3.js.map +0 -1
  167. package/lib/math/vector4.d.ts +0 -182
  168. package/lib/math/vector4.js +0 -302
  169. package/lib/math/vector4.js.map +0 -1
  170. package/lib/measurement/performance.d.ts +0 -13
  171. package/lib/measurement/performance.js +0 -19
  172. package/lib/measurement/performance.js.map +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@oliversalzburg/js-utils",
4
- "version": "0.6.0",
4
+ "version": "0.7.0",
5
5
  "license": "MIT",
6
6
  "author": "Oliver Salzburg <oliver.salzburg@gmail.com>",
7
7
  "repository": {
@@ -25,10 +25,10 @@
25
25
  "postversion": "git push"
26
26
  },
27
27
  "devDependencies": {
28
- "@biomejs/biome": "2.4.4",
29
- "@types/node": "24.10.13",
30
- "@types/web": "0.0.338",
31
- "typescript": "5.9.3"
28
+ "@biomejs/biome": "2.5.9",
29
+ "@types/node": "26.2.0",
30
+ "@types/web": "0.0.354",
31
+ "typescript": "7.0.2"
32
32
  },
33
33
  "engines": {
34
34
  "node": ">=20"
@@ -1,44 +0,0 @@
1
- import { 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<TExecutableReturn | TCoalesce>;
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>;
@@ -1,76 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"async.js","sourceRoot":"","sources":["../../source/async/async.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/D;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAAyB,EAAE,EAAE;IAC/D,OAAO;IACL;;OAEG;IACH,GAAG,IAAoB,EACvB,EAAE;QACF,KAAK,OAAO,CAAC,GAAG,IAAI,CAAC;aAClB,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;aACrB,KAAK,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7C,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAKtC,UAAgF,EAChF,EAAa,EACb,MAAgB,EAChB,EAAE;IACF,IAAI,CAAC;QACH,OAAO,MAAM,UAAU,EAAE,CAAC;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,YAAY,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjE,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,QAAgB,EAAiB,EAAE;IACvD,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC/D,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EACxB,UAAgF,EAChF,UAAU,GAAG,CAAC,EACd,UAAU,GAAG,CAAC,EACc,EAAE;IAC9B,IAAI,CAAC;QACH,OAAO,MAAM,UAAU,EAAE,CAAC;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,GAAG,UAAU,EAAE,CAAC;YACnB,IAAI,CAAC,GAAG,UAAU,EAAE,CAAC;gBACnB,MAAM,KAAK,CAAC,UAAU,CAAC,CAAC;YAC1B,CAAC;YACD,OAAO,KAAK,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,UAAU,CAAC,CAAC;QACrD,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
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
@@ -1 +0,0 @@
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;IACzC,IAAI,QAAQ,GAAG,KAAK,CAAC;IAErB,MAAM,QAAQ,GAAG,mBAAmB,CAAC,KAAK,IAAI,EAAE;QAC9C,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC;QACf,QAAQ,GAAG,IAAI,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,QAAQ,EAAE,CAAC;IAEX,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IAEjB,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;IAC7C,IAAI,QAAQ,GAAG,KAAK,CAAC;IAErB,MAAM,QAAQ,GAAG,mBAAmB,CAAC,KAAK,EAAE,KAA6B,EAAE,OAAe,EAAE,EAAE;QAC5F,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;IAClB,CAAC,CAAC,CAAC;IAEH,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;AACrC,CAAC,CAAC,CAAC"}
package/lib/core.d.ts DELETED
@@ -1,43 +0,0 @@
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 DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=core.js.map
package/lib/core.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"core.js","sourceRoot":"","sources":["../source/core.ts"],"names":[],"mappings":""}
@@ -1,45 +0,0 @@
1
- import { 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>;
package/lib/data/array.js DELETED
@@ -1,70 +0,0 @@
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
- //# sourceMappingURL=array.js.map
@@ -1 +0,0 @@
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;IACjE,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACtD,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;IAC5B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAY,CAAmB,EAAE,CAAmB,EAAE,EAAE;IAC/E,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAY,CAAmB,EAAE,CAAmB,EAAE,EAAE;IAChF,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,KAAqB,EACrB,YAAsC,EACtC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAqB,CAAC;AAE5E;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,QAAQ,CAAC,EAAa,QAA6B,EAAE,KAAa;IACxF,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;YAC3B,MAAM,KAAK,CAAC;YACZ,KAAK,GAAG,EAAE,CAAC;QACb,CAAC;IACH,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACjB,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC"}
package/lib/data/nil.d.ts DELETED
@@ -1,92 +0,0 @@
1
- import { 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;
package/lib/data/nil.js DELETED
@@ -1,131 +0,0 @@
1
- /**
2
- * Check if something is nil.
3
- * Can be used as a typeguard.
4
- * @param subject - The subject that could be nil.
5
- * @typeParam TSubject - The type of the subject.
6
- * @returns `true` if the subject is nil, `false` otherwise.
7
- */
8
- export function isNil(subject) {
9
- return subject === null || subject === undefined;
10
- }
11
- /**
12
- * Check if something is a concrete value of the given type.
13
- * Can be used as a typeguard.
14
- * @param subject - The subject that could be nil.
15
- * @param Prototype - The prototype to check against.
16
- * @typeParam TSubject - The type to check against.
17
- * @returns `true` if the input element matches the given type,
18
- * `false` otherwise.
19
- */
20
- export function is(subject, Prototype) {
21
- return !isNil(subject) && subject instanceof Prototype;
22
- }
23
- /**
24
- * Thrown when an unexpected nil value was encountered.
25
- */
26
- export class UnexpectedNilError extends Error {
27
- /**
28
- * Constructs a new {@linkcode UnexpectedNilError}.
29
- * @param message - The error message.
30
- */
31
- constructor(message = "unexpected nil value") {
32
- super(message);
33
- }
34
- }
35
- /**
36
- * Ensure that the passed subject is not nil; throw otherwise.
37
- * @param subject - A subject that is possibly nil.
38
- * @param errorMessage - An optional error message to throw when the subject is nil.
39
- * @typeParam TSubject - The type of the subject.
40
- * @returns The subject, if it isn't nil.
41
- * @throws {@linkcode UnexpectedNilError} When the subject is nil.
42
- */
43
- export function mustExist(subject, errorMessage) {
44
- if (isNil(subject)) {
45
- throw new UnexpectedNilError(errorMessage);
46
- }
47
- return subject;
48
- }
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 function mustExistAll(subjects, errorMessage) {
58
- for (const subject of subjects) {
59
- if (isNil(subject)) {
60
- throw new UnexpectedNilError(errorMessage);
61
- }
62
- }
63
- return subjects;
64
- }
65
- /**
66
- * Ensure that the passed subject is not nil; throw otherwise.
67
- * @param subject - A subject that is possibly nil.
68
- * @typeParam TSubject - The type of the subject.
69
- * @throws {@linkcode UnexpectedNilError} When the subject is nil.
70
- */
71
- export function assertExists(subject) {
72
- if (isNil(subject)) {
73
- throw new UnexpectedNilError();
74
- }
75
- }
76
- /**
77
- * Ensure that the passed subjects are not nil; throw otherwise.
78
- * @param subjects - Subjects that are possibly nil.
79
- * @typeParam TSubject - The type of a subject.
80
- * @throws {@linkcode UnexpectedNilError} When a subject is nil.
81
- */
82
- export function assertExistsAll(subjects) {
83
- for (const subject of subjects) {
84
- if (isNil(subject)) {
85
- throw new UnexpectedNilError();
86
- }
87
- }
88
- }
89
- /**
90
- * Convert a nilable into a real value, if it is nil.
91
- * @param nilable - The subject to convert to an optional.
92
- * @param to - The value to coalese to.
93
- * @returns The input value, if it wasn't nil, or the value to coalesce to.
94
- */
95
- export function coalesce(nilable, to) {
96
- if (isNil(nilable)) {
97
- return to;
98
- }
99
- return nilable;
100
- }
101
- /**
102
- * Drop all nil values from an array, or replaces them with another value.
103
- * @param nilables - The subject to convert.
104
- * @param to - The value to coalese to.
105
- * @returns An array with where all values are not nil.
106
- */
107
- export function coalesceArray(nilables, to) {
108
- const result = new Array();
109
- for (const nilable of nilables) {
110
- if (!isNil(nilable)) {
111
- result.push(nilable);
112
- }
113
- else if (!isNil(to)) {
114
- result.push(to);
115
- }
116
- }
117
- return result;
118
- }
119
- /**
120
- * Convert a nilable into an optional argument.
121
- * This means `null` is normalized to `undefined`.
122
- * @param nilable - The subject to convert to an optional.
123
- * @returns The value, normalized to `undefined`, if it was nil.
124
- */
125
- export function toOptional(nilable) {
126
- if (isNil(nilable)) {
127
- return undefined;
128
- }
129
- return nilable;
130
- }
131
- //# sourceMappingURL=nil.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nil.js","sourceRoot":"","sources":["../../source/data/nil.ts"],"names":[],"mappings":"AAcA;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAW,OAAwB;IACtD,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,CAAC;AACnD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,EAAE,CAChB,OAAkC,EAClC,SAAkC;IAElC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,YAAY,SAAS,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C;;;OAGG;IACH,YAAY,OAAO,GAAG,sBAAsB;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAW,OAAwB,EAAE,YAAqB;IACjF,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,QAAgC,EAChC,YAAqB;IAErB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YACnB,MAAM,IAAI,kBAAkB,CAAC,YAAY,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,OAAO,QAA2B,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAW,OAAwB;IAC7D,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAgC;IAEhC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YACnB,MAAM,IAAI,kBAAkB,EAAE,CAAC;QACjC,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAI,OAAiB,EAAE,EAAK;IAClD,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACnB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAI,QAAyB,EAAE,EAAa;IACvE,MAAM,MAAM,GAAG,IAAI,KAAK,EAAK,CAAC;IAC9B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;aAAM,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;YACtB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAI,OAAiB;IAC7C,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACnB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}