@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 @@
1
+ {"version":3,"file":"InvalidOperationError.js","sourceRoot":"","sources":["../../source/errors/InvalidOperationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;GAGG;AACH,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IACvD;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAAM,GAAG,GAAG;QACxC,KAAK,CAAC,0BAA0B,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAEnD,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QAEpC,IAAI,OAAO,KAAK,CAAC,iBAAiB,KAAK,WAAW,EAAE,CAAC;YACpD,qEAAqE;YACrE,yEAAyE;YACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;QACtD,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,12 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * Used when a called method actually hasn't been implemented yet (whoops).
4
+ */
5
+ export declare class NotImplementedError extends AbstractError {
6
+ /**
7
+ * Constructs a new {@linkcode NotImplementedError}.
8
+ * @param message - The main error message.
9
+ * @param status - The HTTP status code to return.
10
+ */
11
+ constructor(message?: string, status?: number);
12
+ }
@@ -0,0 +1,21 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * Used when a called method actually hasn't been implemented yet (whoops).
4
+ */
5
+ export class NotImplementedError extends AbstractError {
6
+ /**
7
+ * Constructs a new {@linkcode NotImplementedError}.
8
+ * @param message - The main error message.
9
+ * @param status - The HTTP status code to return.
10
+ */
11
+ constructor(message = "Not implemented.", status = 501) {
12
+ super("ERR_OS_NOT_IMPLEMENTED", message, status);
13
+ this.name = "NotImplementedError";
14
+ if (typeof Error.captureStackTrace !== "undefined") {
15
+ // Capture a new stacktrace, otherwise it will include our base-class
16
+ // constructor instead of the code location we're actually interested in.
17
+ Error.captureStackTrace(this, NotImplementedError);
18
+ }
19
+ }
20
+ }
21
+ //# sourceMappingURL=NotImplementedError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotImplementedError.js","sourceRoot":"","sources":["../../source/errors/NotImplementedError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,aAAa;IACrD;;;;OAIG;IACH,YAAY,OAAO,GAAG,kBAAkB,EAAE,MAAM,GAAG,GAAG;QACrD,KAAK,CAAC,wBAAwB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAEjD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAElC,IAAI,OAAO,KAAK,CAAC,iBAAiB,KAAK,WAAW,EAAE,CAAC;YACpD,qEAAqE;YACrE,yEAAyE;YACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;QACpD,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,13 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * An error used when access to a resource was requested, but the required
4
+ * permissions were not available.
5
+ */
6
+ export declare class PermissionViolationError extends AbstractError {
7
+ /**
8
+ * Constructs a new {@linkcode PermissionViolationError}.
9
+ * @param message - The main error message.
10
+ * @param status - The HTTP status code to return.
11
+ */
12
+ constructor(message: string, status?: number);
13
+ }
@@ -0,0 +1,22 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * An error used when access to a resource was requested, but the required
4
+ * permissions were not available.
5
+ */
6
+ export class PermissionViolationError extends AbstractError {
7
+ /**
8
+ * Constructs a new {@linkcode PermissionViolationError}.
9
+ * @param message - The main error message.
10
+ * @param status - The HTTP status code to return.
11
+ */
12
+ constructor(message, status = 403) {
13
+ super("ERR_OS_PERMISSION_VIOLATION", message, status);
14
+ this.name = "PermissionViolationError";
15
+ if (typeof Error.captureStackTrace !== "undefined") {
16
+ // Capture a new stacktrace, otherwise it will include our base-class
17
+ // constructor instead of the code location we're actually interested in.
18
+ Error.captureStackTrace(this, PermissionViolationError);
19
+ }
20
+ }
21
+ }
22
+ //# sourceMappingURL=PermissionViolationError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PermissionViolationError.js","sourceRoot":"","sources":["../../source/errors/PermissionViolationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;GAGG;AACH,MAAM,OAAO,wBAAyB,SAAQ,aAAa;IAC1D;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAAM,GAAG,GAAG;QACxC,KAAK,CAAC,6BAA6B,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAEtD,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QAEvC,IAAI,OAAO,KAAK,CAAC,iBAAiB,KAAK,WAAW,EAAE,CAAC;YACpD,qEAAqE;YACrE,yEAAyE;YACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,wBAAwB,CAAC,CAAC;QACzD,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,12 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * Used when a resource conflict was detected.
4
+ */
5
+ export declare class ResourceConflictError extends AbstractError {
6
+ /**
7
+ * Constructs a new {@linkcode ResourceConflictError}.
8
+ * @param message - The main error message.
9
+ * @param status - The HTTP status code to return.
10
+ */
11
+ constructor(message: string, status?: number);
12
+ }
@@ -0,0 +1,21 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * Used when a resource conflict was detected.
4
+ */
5
+ export class ResourceConflictError extends AbstractError {
6
+ /**
7
+ * Constructs a new {@linkcode ResourceConflictError}.
8
+ * @param message - The main error message.
9
+ * @param status - The HTTP status code to return.
10
+ */
11
+ constructor(message, status = 409) {
12
+ super("ERR_OS_RESOURCE_CONFLICT", message, status);
13
+ this.name = "ResourceConflictError";
14
+ if (typeof Error.captureStackTrace !== "undefined") {
15
+ // Capture a new stacktrace, otherwise it will include our base-class
16
+ // constructor instead of the code location we're actually interested in.
17
+ Error.captureStackTrace(this, ResourceConflictError);
18
+ }
19
+ }
20
+ }
21
+ //# sourceMappingURL=ResourceConflictError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResourceConflictError.js","sourceRoot":"","sources":["../../source/errors/ResourceConflictError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IACvD;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAAM,GAAG,GAAG;QACxC,KAAK,CAAC,0BAA0B,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAEnD,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QAEpC,IAAI,OAAO,KAAK,CAAC,iBAAiB,KAAK,WAAW,EAAE,CAAC;YACpD,qEAAqE;YACrE,yEAAyE;YACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;QACtD,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,16 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * Used when an unknown, non-{@linkcode !Error}-like object was caught and converted into a
4
+ * real {@linkcode !Error} instance.
5
+ * Like when you catch a `throw "boom"`, we will convert the caught `"boom"`
6
+ * into an {@linkcode UnknownError}.
7
+ * To enrich an {@linkcode !Error}-like object that was caught, use the {@linkcode InternalError}.
8
+ */
9
+ export declare class UnknownError extends AbstractError {
10
+ /**
11
+ * Constructs a new {@linkcode UnknownError}.
12
+ * @param message - The main error message.
13
+ * @param status - The HTTP status code to return.
14
+ */
15
+ constructor(message: string, status?: number);
16
+ }
@@ -0,0 +1,25 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * Used when an unknown, non-{@linkcode !Error}-like object was caught and converted into a
4
+ * real {@linkcode !Error} instance.
5
+ * Like when you catch a `throw "boom"`, we will convert the caught `"boom"`
6
+ * into an {@linkcode UnknownError}.
7
+ * To enrich an {@linkcode !Error}-like object that was caught, use the {@linkcode InternalError}.
8
+ */
9
+ export class UnknownError extends AbstractError {
10
+ /**
11
+ * Constructs a new {@linkcode UnknownError}.
12
+ * @param message - The main error message.
13
+ * @param status - The HTTP status code to return.
14
+ */
15
+ constructor(message, status = 500) {
16
+ super("ERR_OS_UNKNOWN", message, status);
17
+ this.name = "UnknownError";
18
+ if (typeof Error.captureStackTrace !== "undefined") {
19
+ // Capture a new stacktrace, otherwise it will include our base-class
20
+ // constructor instead of the code location we're actually interested in.
21
+ Error.captureStackTrace(this, UnknownError);
22
+ }
23
+ }
24
+ }
25
+ //# sourceMappingURL=UnknownError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UnknownError.js","sourceRoot":"","sources":["../../source/errors/UnknownError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,OAAO,YAAa,SAAQ,aAAa;IAC9C;;;;OAIG;IACH,YAAY,OAAe,EAAE,MAAM,GAAG,GAAG;QACxC,KAAK,CAAC,gBAAgB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAEzC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAE3B,IAAI,OAAO,KAAK,CAAC,iBAAiB,KAAK,WAAW,EAAE,CAAC;YACpD,qEAAqE;YACrE,yEAAyE;YACzE,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAC7C,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns a function that will receive errors (or anything else that was `throw`n)
3
+ * and prints it to a {@linkcode !console}.
4
+ * @param console - The console to print errors to.
5
+ * @returns A function that will print errors to the console.
6
+ */
7
+ export declare const redirectErrorsToConsole: (console: Console) => ((error: unknown) => void);
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Returns a function that will receive errors (or anything else that was `throw`n)
3
+ * and prints it to a {@linkcode !console}.
4
+ * @param console - The console to print errors to.
5
+ * @returns A function that will print errors to the console.
6
+ */
7
+ export const redirectErrorsToConsole = (console) => {
8
+ const printErrorsToConsole = (error) => {
9
+ console.error(error);
10
+ };
11
+ return printErrorsToConsole;
12
+ };
13
+ //# sourceMappingURL=console.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.js","sourceRoot":"","sources":["../../source/errors/console.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACtC,OAAgB,EACa,EAAE;IAC/B,MAAM,oBAAoB,GAAG,CAAC,KAAc,EAAQ,EAAE;QACrD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC,CAAC;IACF,OAAO,oBAAoB,CAAC;AAC7B,CAAC,CAAC"}
@@ -0,0 +1,45 @@
1
+ import { AbstractError } from "./AbstractError.js";
2
+ /**
3
+ * The shape of an {@linkcode !Error} instance, after it has been serialized into a simple hash.
4
+ */
5
+ export type SerializedError = Record<string, Record<string, string> | string | undefined>;
6
+ /**
7
+ * Determine if the given unknown subject is an {@linkcode !Error} instance.
8
+ * @param subject - The object to inspect.
9
+ * @returns `true` if the subject is an {@linkcode !Error}, `false` otherwise.
10
+ */
11
+ export declare const isError: (subject: unknown) => subject is Error;
12
+ /**
13
+ * Returns an {@linkcode AbstractError} that best represents the passed subject.
14
+ * If the passed subject is already an {@linkcode AbstractError}, it is returned as-is.
15
+ * Otherwise, it will be converted into an appropriate error type.
16
+ * @param subject - The subject to inspect
17
+ * @returns An {@linkcode AbstractError} instance.
18
+ */
19
+ export declare const unknownToError: (subject: unknown) => AbstractError;
20
+ /**
21
+ * Serializes an error into a string.
22
+ * @param error - The error to stringify.
23
+ * @returns A string representing the error.
24
+ */
25
+ export declare const errorToString: (error: Error & {
26
+ toString?: () => string;
27
+ }) => string;
28
+ /**
29
+ * Serializes an error into a JSON string.
30
+ * @param error - The error to stringify.
31
+ * @returns A JSON string representing the error.
32
+ */
33
+ export declare const errorToJSON: (error: Error) => string;
34
+ /**
35
+ * Converts an error into a regular hash.
36
+ * @param error - The error to convert.
37
+ * @returns A new object that contains all the properties of the error.
38
+ */
39
+ export declare const errorToRecord: (error: Error) => Record<string, unknown>;
40
+ /**
41
+ * Serializes an error into a simpler shape.
42
+ * @param error - The error to serialize.
43
+ * @returns A simple representation of the error.
44
+ */
45
+ export declare const errorToSimpleSerializable: (error: AbstractError) => SerializedError;
@@ -0,0 +1,74 @@
1
+ import { isNil } from "../data/nil.js";
2
+ import { AbstractError } from "./AbstractError.js";
3
+ import { InternalError } from "./InternalError.js";
4
+ import { UnknownError } from "./UnknownError.js";
5
+ /**
6
+ * Determine if the given unknown subject is an {@linkcode !Error} instance.
7
+ * @param subject - The object to inspect.
8
+ * @returns `true` if the subject is an {@linkcode !Error}, `false` otherwise.
9
+ */
10
+ export const isError = (subject) => {
11
+ return (subject instanceof Error ||
12
+ Object.prototype.toString.call(subject) === "[object Error]");
13
+ };
14
+ /**
15
+ * Returns an {@linkcode AbstractError} that best represents the passed subject.
16
+ * If the passed subject is already an {@linkcode AbstractError}, it is returned as-is.
17
+ * Otherwise, it will be converted into an appropriate error type.
18
+ * @param subject - The subject to inspect
19
+ * @returns An {@linkcode AbstractError} instance.
20
+ */
21
+ export const unknownToError = (subject) => {
22
+ if (AbstractError.isAbstractError(subject)) {
23
+ return subject;
24
+ }
25
+ if (isError(subject)) {
26
+ return InternalError.fromError(subject);
27
+ }
28
+ return new UnknownError(String(subject));
29
+ };
30
+ /**
31
+ * Serializes an error into a string.
32
+ * @param error - The error to stringify.
33
+ * @returns A string representing the error.
34
+ */
35
+ export const errorToString = (error) => {
36
+ return isNil(error.toString)
37
+ ? Object.prototype.toString.call(error)
38
+ : error.toString();
39
+ };
40
+ /**
41
+ * Serializes an error into a JSON string.
42
+ * @param error - The error to stringify.
43
+ * @returns A JSON string representing the error.
44
+ */
45
+ export const errorToJSON = (error) => {
46
+ return JSON.stringify(error, Object.getOwnPropertyNames(error));
47
+ };
48
+ /**
49
+ * Converts an error into a regular hash.
50
+ * @param error - The error to convert.
51
+ * @returns A new object that contains all the properties of the error.
52
+ */
53
+ export const errorToRecord = (error) => {
54
+ const record = {};
55
+ for (const propertyName of Object.getOwnPropertyNames(error)) {
56
+ record[propertyName] = error[propertyName];
57
+ }
58
+ return record;
59
+ };
60
+ /**
61
+ * Serializes an error into a simpler shape.
62
+ * @param error - The error to serialize.
63
+ * @returns A simple representation of the error.
64
+ */
65
+ export const errorToSimpleSerializable = (error) => {
66
+ const serialized = {
67
+ code: error.code,
68
+ message: error.message,
69
+ name: error.name,
70
+ stack: error.stack,
71
+ };
72
+ return serialized;
73
+ };
74
+ //# sourceMappingURL=error-serializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-serializer.js","sourceRoot":"","sources":["../../source/errors/error-serializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUjD;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAgB,EAAoB,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AAC,YAAkC,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACxC,KAAoB,EACF,EAAE;IACpB,MAAM,UAAU,GAAoB;QACnC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,KAAK,CAAC,KAAK;KAClB,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,109 @@
1
+ import assert from "node:assert";
2
+ import { it } from "node:test";
3
+ import { errorToJSON, errorToRecord, errorToSimpleSerializable, isError, unknownToError, } from "./error-serializer.js";
4
+ import { InternalError } from "./InternalError.js";
5
+ import { InvalidArgumentError } from "./InvalidArgumentError.js";
6
+ function generateDefaultError() {
7
+ try {
8
+ throw new Error("oops");
9
+ }
10
+ catch (error) {
11
+ return error;
12
+ }
13
+ }
14
+ it("unknown to Error: AbstractError", () => {
15
+ const subjectError = new InvalidArgumentError("oops");
16
+ const serialized = unknownToError(subjectError);
17
+ assert.strictEqual(serialized.code, "ERR_OS_INVALID_ARGUMENT");
18
+ assert.strictEqual(serialized.message, "oops");
19
+ assert.strictEqual(serialized.name, "InvalidArgumentError");
20
+ assert.strictEqual(typeof serialized.stack, "string");
21
+ });
22
+ it("unknown to Error: Error", () => {
23
+ const subjectError = new Error("oops");
24
+ const serialized = unknownToError(subjectError);
25
+ assert.strictEqual(serialized.code, "ERR_OS_INTERNAL");
26
+ assert.strictEqual(serialized.message, "oops");
27
+ assert.strictEqual(serialized.name, "InternalError");
28
+ assert.strictEqual(typeof serialized.stack, "string");
29
+ });
30
+ it("unknown to Error: string", () => {
31
+ const subjectError = "oops";
32
+ const serialized = unknownToError(subjectError);
33
+ assert.strictEqual(serialized.code, "ERR_OS_UNKNOWN");
34
+ assert.strictEqual(serialized.message, "oops");
35
+ assert.strictEqual(serialized.name, "UnknownError");
36
+ assert.strictEqual(typeof serialized.stack, "string");
37
+ });
38
+ it("unknown to Error: null", () => {
39
+ const subjectError = null;
40
+ const serialized = unknownToError(subjectError);
41
+ assert.strictEqual(serialized.code, "ERR_OS_UNKNOWN");
42
+ assert.strictEqual(serialized.message, "null");
43
+ assert.strictEqual(serialized.name, "UnknownError");
44
+ assert.strictEqual(typeof serialized.stack, "string");
45
+ });
46
+ it("serializes an error to JSON", () => {
47
+ const subjectError = new Error("oops");
48
+ const plain = JSON.stringify(subjectError);
49
+ const serialized = errorToJSON(subjectError);
50
+ // We assert.strictEqual more properties to have been serialized into the string.
51
+ assert.notStrictEqual(serialized, plain);
52
+ assert.strictEqual(plain.length < serialized.length, true);
53
+ });
54
+ it("serializes an error to a record: Error", () => {
55
+ const subjectError = new Error("oops");
56
+ const serialized = errorToRecord(subjectError);
57
+ assert.strictEqual(isError(subjectError), true);
58
+ assert.strictEqual(isError(serialized), false);
59
+ assert.strictEqual(serialized.message, "oops");
60
+ assert.strictEqual(typeof serialized.stack, "string");
61
+ });
62
+ it("serializes an error to a record: Default Error", () => {
63
+ const subjectError = generateDefaultError();
64
+ const serialized = errorToRecord(subjectError);
65
+ assert.strictEqual(isError(subjectError), true);
66
+ assert.strictEqual(isError(serialized), false);
67
+ assert.strictEqual(serialized.code, undefined);
68
+ assert.strictEqual(serialized.message, "oops");
69
+ assert.strictEqual(serialized.name, undefined);
70
+ assert.strictEqual(typeof serialized.stack, "string");
71
+ });
72
+ it("serializes an error to a record: Node Error", async () => {
73
+ let error;
74
+ try {
75
+ assert(false, "oops");
76
+ }
77
+ catch (thrownError) {
78
+ error = thrownError;
79
+ }
80
+ const subjectError = error;
81
+ const serialized = errorToRecord(subjectError);
82
+ assert.strictEqual(isError(subjectError), true);
83
+ assert.strictEqual(isError(serialized), false);
84
+ assert.strictEqual(serialized.code, "ERR_ASSERTION");
85
+ assert.strictEqual(serialized.message, "oops");
86
+ assert.strictEqual(serialized.name, "AssertionError");
87
+ assert.strictEqual(typeof serialized.stack, "string");
88
+ });
89
+ it("serializes an error to a simple object for persistence: Error", () => {
90
+ const subjectError = InternalError.fromError(new Error("oops"));
91
+ const serialized = errorToSimpleSerializable(subjectError);
92
+ assert.strictEqual(isError(subjectError), true);
93
+ assert.strictEqual(isError(serialized), false);
94
+ assert.strictEqual(serialized.code, "ERR_OS_INTERNAL");
95
+ assert.strictEqual(serialized.message, "oops");
96
+ assert.strictEqual(serialized.name, "InternalError");
97
+ assert.strictEqual(typeof serialized.stack, "string");
98
+ });
99
+ it("serializes an error to a simple object for persistence: Node Error", () => {
100
+ const subjectError = InternalError.fromError(generateDefaultError());
101
+ const serialized = errorToSimpleSerializable(subjectError);
102
+ assert.strictEqual(isError(subjectError), true);
103
+ assert.strictEqual(isError(serialized), false);
104
+ assert.strictEqual(serialized.code, "ERR_OS_INTERNAL");
105
+ assert.strictEqual(serialized.message, "oops");
106
+ assert.strictEqual(serialized.name, "InternalError");
107
+ assert.strictEqual(typeof serialized.stack, "string");
108
+ });
109
+ //# sourceMappingURL=error-serializer.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-serializer.test.js","sourceRoot":"","sources":["../../source/errors/error-serializer.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAC/B,OAAO,EACN,WAAW,EACX,aAAa,EACb,yBAAyB,EACzB,OAAO,EACP,cAAc,GACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,SAAS,oBAAoB;IAC5B,IAAI,CAAC;QACJ,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IAAC,OAAO,KAAK,EAAE,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CAAC,CAAC;AACvD,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,oEAAoE,EAAE,GAAG,EAAE;IAC7E,MAAM,YAAY,GAAG,aAAa,CAAC,SAAS,CAAC,oBAAoB,EAAE,CAAC,CAAC;IACrE,MAAM,UAAU,GAAG,yBAAyB,CAAC,YAAY,CAAC,CAAC;IAC3D,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,CAAC;IAChD,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,CAAC;IAE/C,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;IACvD,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC/C,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IACrD,MAAM,CAAC,WAAW,CAAC,OAAO,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns a function that will receive errors (or anything else that was `throw`n)
3
+ * and prints it to a {@linkcode NodeJS.WriteStream}.
4
+ * @param stream - The stream to print errors to.
5
+ * @returns A function that will print errors to the stream.
6
+ */
7
+ export declare const redirectErrorsToStream: (stream: NodeJS.WriteStream) => ((error: unknown) => void);
@@ -0,0 +1,15 @@
1
+ import { errorToString, unknownToError } from "./error-serializer.js";
2
+ /**
3
+ * Returns a function that will receive errors (or anything else that was `throw`n)
4
+ * and prints it to a {@linkcode NodeJS.WriteStream}.
5
+ * @param stream - The stream to print errors to.
6
+ * @returns A function that will print errors to the stream.
7
+ */
8
+ export const redirectErrorsToStream = (stream) => {
9
+ const printErrorsToStream = (unknownError) => {
10
+ const error = unknownToError(unknownError);
11
+ stream.write(`${errorToString(error)}\n`);
12
+ };
13
+ return printErrorsToStream;
14
+ };
15
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../source/errors/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACrC,MAA0B,EACG,EAAE;IAC/B,MAAM,mBAAmB,GAAG,CAAC,YAAqB,EAAQ,EAAE;QAC3D,MAAM,KAAK,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;QAC3C,MAAM,CAAC,KAAK,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC,CAAC;IACF,OAAO,mBAAmB,CAAC;AAC5B,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * General error-related tooling that fits no other module.
3
+ * @module
4
+ */
5
+ /**
6
+ * Throws the provided error.
7
+ * @param error - The error that will be thrown.
8
+ * @throws The provided error.
9
+ */
10
+ export declare const rethrow: (error: unknown) => never;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * General error-related tooling that fits no other module.
3
+ * @module
4
+ */
5
+ /**
6
+ * Throws the provided error.
7
+ * @param error - The error that will be thrown.
8
+ * @throws The provided error.
9
+ */
10
+ export const rethrow = (error) => {
11
+ throw error;
12
+ };
13
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../source/errors/tools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAc,EAAE,EAAE;IACzC,MAAM,KAAK,CAAC;AACb,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Creates a {@linkcode !CustomEvent} instance with the given arguments.
3
+ * @param type - The name of the type of the event.
4
+ * @param detail - The event details.
5
+ * @returns The requested event object.
6
+ */
7
+ export declare const createEvent: <TEventType extends string, TDetail>(type: TEventType, detail: TDetail) => CustomEvent<TDetail> & {
8
+ type: TEventType;
9
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Creates a {@linkcode !CustomEvent} instance with the given arguments.
3
+ * @param type - The name of the type of the event.
4
+ * @param detail - The event details.
5
+ * @returns The requested event object.
6
+ */
7
+ export const createEvent = (type, detail) => {
8
+ return new CustomEvent(type, { detail });
9
+ };
10
+ //# sourceMappingURL=event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.js","sourceRoot":"","sources":["../../source/events/event.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAC1B,IAAgB,EAChB,MAAe,EAC+B,EAAE;IAChD,OAAO,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAEtC,CAAC;AACH,CAAC,CAAC"}