@oliversalzburg/js-utils 0.7.0 → 0.7.1
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.
- package/lib/async/async.d.ts +44 -0
- package/lib/async/async.js +76 -0
- package/lib/async/async.js.map +1 -0
- package/lib/async/async.test.d.ts +1 -0
- package/lib/async/async.test.js +26 -0
- package/lib/async/async.test.js.map +1 -0
- package/lib/core.d.ts +43 -0
- package/lib/core.js +2 -0
- package/lib/core.js.map +1 -0
- package/lib/data/array.d.ts +55 -0
- package/lib/data/array.js +90 -0
- package/lib/data/array.js.map +1 -0
- package/lib/data/nil.d.ts +92 -0
- package/lib/data/nil.js +131 -0
- package/lib/data/nil.js.map +1 -0
- package/lib/data/random.d.ts +111 -0
- package/lib/data/random.js +381 -0
- package/lib/data/random.js.map +1 -0
- package/lib/data/string.d.ts +30 -0
- package/lib/data/string.js +53 -0
- package/lib/data/string.js.map +1 -0
- package/lib/data/tree.d.ts +28 -0
- package/lib/data/tree.js +45 -0
- package/lib/data/tree.js.map +1 -0
- package/lib/device/shake.d.ts +79 -0
- package/lib/device/shake.js +135 -0
- package/lib/device/shake.js.map +1 -0
- package/lib/dom/core.d.ts +21 -0
- package/lib/dom/core.js +41 -0
- package/lib/dom/core.js.map +1 -0
- package/lib/errors/AbstractError.d.ts +29 -0
- package/lib/errors/AbstractError.js +59 -0
- package/lib/errors/AbstractError.js.map +1 -0
- package/lib/errors/InternalError.d.ts +19 -0
- package/lib/errors/InternalError.js +38 -0
- package/lib/errors/InternalError.js.map +1 -0
- package/lib/errors/InvalidArgumentError.d.ts +13 -0
- package/lib/errors/InvalidArgumentError.js +22 -0
- package/lib/errors/InvalidArgumentError.js.map +1 -0
- package/lib/errors/InvalidOperationError.d.ts +13 -0
- package/lib/errors/InvalidOperationError.js +22 -0
- package/lib/errors/InvalidOperationError.js.map +1 -0
- package/lib/errors/NotImplementedError.d.ts +12 -0
- package/lib/errors/NotImplementedError.js +21 -0
- package/lib/errors/NotImplementedError.js.map +1 -0
- package/lib/errors/PermissionViolationError.d.ts +13 -0
- package/lib/errors/PermissionViolationError.js +22 -0
- package/lib/errors/PermissionViolationError.js.map +1 -0
- package/lib/errors/ResourceConflictError.d.ts +12 -0
- package/lib/errors/ResourceConflictError.js +21 -0
- package/lib/errors/ResourceConflictError.js.map +1 -0
- package/lib/errors/UnknownError.d.ts +16 -0
- package/lib/errors/UnknownError.js +25 -0
- package/lib/errors/UnknownError.js.map +1 -0
- package/lib/errors/console.d.ts +7 -0
- package/lib/errors/console.js +13 -0
- package/lib/errors/console.js.map +1 -0
- package/lib/errors/error-serializer.d.ts +45 -0
- package/lib/errors/error-serializer.js +74 -0
- package/lib/errors/error-serializer.js.map +1 -0
- package/lib/errors/error-serializer.test.d.ts +1 -0
- package/lib/errors/error-serializer.test.js +109 -0
- package/lib/errors/error-serializer.test.js.map +1 -0
- package/lib/errors/stream.d.ts +7 -0
- package/lib/errors/stream.js +15 -0
- package/lib/errors/stream.js.map +1 -0
- package/lib/errors/tools.d.ts +10 -0
- package/lib/errors/tools.js +13 -0
- package/lib/errors/tools.js.map +1 -0
- package/lib/events/event.d.ts +9 -0
- package/lib/events/event.js +10 -0
- package/lib/events/event.js.map +1 -0
- package/lib/format/bytes.d.ts +118 -0
- package/lib/format/bytes.js +138 -0
- package/lib/format/bytes.js.map +1 -0
- package/lib/format/bytes.test.d.ts +1 -0
- package/lib/format/bytes.test.js +146 -0
- package/lib/format/bytes.test.js.map +1 -0
- package/lib/format/count.d.ts +14 -0
- package/lib/format/count.js +51 -0
- package/lib/format/count.js.map +1 -0
- package/lib/format/count.test.d.ts +1 -0
- package/lib/format/count.test.js +42 -0
- package/lib/format/count.test.js.map +1 -0
- package/lib/format/milliseconds.d.ts +100 -0
- package/lib/format/milliseconds.js +199 -0
- package/lib/format/milliseconds.js.map +1 -0
- package/lib/format/milliseconds.test.d.ts +1 -0
- package/lib/format/milliseconds.test.js +393 -0
- package/lib/format/milliseconds.test.js.map +1 -0
- package/lib/format/string.d.ts +24 -0
- package/lib/format/string.js +32 -0
- package/lib/format/string.js.map +1 -0
- package/lib/format/string.test.d.ts +1 -0
- package/lib/format/string.test.js +17 -0
- package/lib/format/string.test.js.map +1 -0
- package/lib/graphics/canvas-sandbox-mp.d.ts +258 -0
- package/lib/graphics/canvas-sandbox-mp.js +280 -0
- package/lib/graphics/canvas-sandbox-mp.js.map +1 -0
- package/lib/graphics/canvas-sandbox.d.ts +255 -0
- package/lib/graphics/canvas-sandbox.js +358 -0
- package/lib/graphics/canvas-sandbox.js.map +1 -0
- package/lib/graphics/canvas.d.ts +57 -0
- package/lib/graphics/canvas.js +37 -0
- package/lib/graphics/canvas.js.map +1 -0
- package/lib/graphics/canvas2d-headless.d.ts +85 -0
- package/lib/graphics/canvas2d-headless.js +197 -0
- package/lib/graphics/canvas2d-headless.js.map +1 -0
- package/lib/graphics/canvas2d.d.ts +162 -0
- package/lib/graphics/canvas2d.js +332 -0
- package/lib/graphics/canvas2d.js.map +1 -0
- package/lib/graphics/canvas3d.d.ts +41 -0
- package/lib/graphics/canvas3d.js +67 -0
- package/lib/graphics/canvas3d.js.map +1 -0
- package/lib/graphics/color.d.ts +22 -0
- package/lib/graphics/color.js +38 -0
- package/lib/graphics/color.js.map +1 -0
- package/lib/graphics/core.d.ts +89 -0
- package/lib/graphics/core.js +146 -0
- package/lib/graphics/core.js.map +1 -0
- package/lib/graphics/palette-sampler.d.ts +7 -0
- package/lib/graphics/palette-sampler.js +21 -0
- package/lib/graphics/palette-sampler.js.map +1 -0
- package/lib/graphics/palette.d.ts +120 -0
- package/lib/graphics/palette.js +574 -0
- package/lib/graphics/palette.js.map +1 -0
- package/lib/graphics/palette.test.d.ts +1 -0
- package/lib/graphics/palette.test.js +43 -0
- package/lib/graphics/palette.test.js.map +1 -0
- package/lib/graphics/render-loop.d.ts +76 -0
- package/lib/graphics/render-loop.js +114 -0
- package/lib/graphics/render-loop.js.map +1 -0
- package/lib/graphics/shader.d.ts +56 -0
- package/lib/graphics/shader.js +80 -0
- package/lib/graphics/shader.js.map +1 -0
- package/lib/log/log.d.ts +11 -0
- package/lib/log/log.js +2 -0
- package/lib/log/log.js.map +1 -0
- package/lib/log/report.d.ts +57 -0
- package/lib/log/report.js +88 -0
- package/lib/log/report.js.map +1 -0
- package/lib/math/core.d.ts +85 -0
- package/lib/math/core.js +125 -0
- package/lib/math/core.js.map +1 -0
- package/lib/math/easing.d.ts +204 -0
- package/lib/math/easing.js +366 -0
- package/lib/math/easing.js.map +1 -0
- package/lib/math/euler.d.ts +18 -0
- package/lib/math/euler.js +22 -0
- package/lib/math/euler.js.map +1 -0
- package/lib/math/matrix3.d.ts +227 -0
- package/lib/math/matrix3.js +508 -0
- package/lib/math/matrix3.js.map +1 -0
- package/lib/math/quaternion.d.ts +119 -0
- package/lib/math/quaternion.js +270 -0
- package/lib/math/quaternion.js.map +1 -0
- package/lib/math/transformation.d.ts +26 -0
- package/lib/math/transformation.js +31 -0
- package/lib/math/transformation.js.map +1 -0
- package/lib/math/vector2.d.ts +202 -0
- package/lib/math/vector2.js +310 -0
- package/lib/math/vector2.js.map +1 -0
- package/lib/math/vector3.d.ts +293 -0
- package/lib/math/vector3.js +492 -0
- package/lib/math/vector3.js.map +1 -0
- package/lib/math/vector4.d.ts +182 -0
- package/lib/math/vector4.js +302 -0
- package/lib/math/vector4.js.map +1 -0
- package/lib/measurement/performance.d.ts +13 -0
- package/lib/measurement/performance.js +19 -0
- package/lib/measurement/performance.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +3 -5
|
@@ -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,EAAE;IAC7D,OAAO,CACN,OAAO,YAAY,KAAK;QACxB,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,gBAAgB,CAC5D,CAAC;AACH,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAgB,EAAiB,EAAE;IACjE,IAAI,aAAa,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5C,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACtB,OAAO,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC5B,KAA0C,EACjC,EAAE;IACX,OAAO,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC3B,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;QACvC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;AACrB,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAY,EAAU,EAAE;IACnD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC;AACjE,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAY,EAA2B,EAAE;IACtE,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9D,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,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,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M,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;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"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was derived from https://github.com/sindresorhus/pretty-bytes/tree/71d686a4cefb314c13b57107de5add5789753900.
|
|
3
|
+
* It is available under the MIT license.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Options for the `formatBytes` function.
|
|
7
|
+
*/
|
|
8
|
+
export interface FormatBytesOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Include plus sign for positive numbers. If the difference is exactly zero a space character will be prepended instead for better alignment.
|
|
11
|
+
*/
|
|
12
|
+
signed?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* - If `false`: Output won't be localized.
|
|
15
|
+
* - If `true`: Localize the output using the system/browser locale.
|
|
16
|
+
* - If `string`: Expects a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …)
|
|
17
|
+
* - If `string[]`: Expects a list of [BCP 47 language tags](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …)
|
|
18
|
+
*/
|
|
19
|
+
locale?: boolean | string | ReadonlyArray<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Format the number as [bits](https://en.wikipedia.org/wiki/Bit) instead of [bytes](https://en.wikipedia.org/wiki/Byte). This can be useful when, for example, referring to [bit rate](https://en.wikipedia.org/wiki/Bit_rate).
|
|
22
|
+
* @example
|
|
23
|
+
* ```
|
|
24
|
+
* import formatBytes from '@oliversalzburg/js-utils/format/bytes.js';
|
|
25
|
+
*
|
|
26
|
+
* formatBytes(1337, {bits: true});
|
|
27
|
+
* //=> '1.34 kbit'
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
bits?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Format the number using the [Binary Prefix](https://en.wikipedia.org/wiki/Binary_prefix) instead of the [SI Prefix](https://en.wikipedia.org/wiki/SI_prefix). This can be useful for presenting memory amounts. However, this should not be used for presenting file sizes.
|
|
33
|
+
* @example
|
|
34
|
+
* ```
|
|
35
|
+
* import formatBytes from '@oliversalzburg/js-utils/format/bytes.js';
|
|
36
|
+
*
|
|
37
|
+
* formatBytes(1000, {binary: true});
|
|
38
|
+
* //=> '1000 bit'
|
|
39
|
+
*
|
|
40
|
+
* formatBytes(1024, {binary: true});
|
|
41
|
+
* //=> '1 kiB'
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
binary?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The minimum number of fraction digits to display.
|
|
47
|
+
*
|
|
48
|
+
* If neither `minimumFractionDigits` or `maximumFractionDigits` are set, the default behavior is to round to 3 significant digits.
|
|
49
|
+
* @example
|
|
50
|
+
* ```
|
|
51
|
+
* import formatBytes from '@oliversalzburg/js-utils/format/bytes.js';
|
|
52
|
+
*
|
|
53
|
+
* // Show the number with at least 3 fractional digits
|
|
54
|
+
* formatBytes(1900, {minimumFractionDigits: 3});
|
|
55
|
+
* //=> '1.900 kB'
|
|
56
|
+
*
|
|
57
|
+
* formatBytes(1900);
|
|
58
|
+
* //=> '1.9 kB'
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
minimumFractionDigits?: number;
|
|
62
|
+
/**
|
|
63
|
+
* The maximum number of fraction digits to display.
|
|
64
|
+
*
|
|
65
|
+
* If neither `minimumFractionDigits` or `maximumFractionDigits` are set, the default behavior is to round to 3 significant digits.
|
|
66
|
+
* @example
|
|
67
|
+
* ```
|
|
68
|
+
* import formatBytes from '@oliversalzburg/js-utils/format/bytes.js';
|
|
69
|
+
*
|
|
70
|
+
* // Show the number with at most 1 fractional digit
|
|
71
|
+
* formatBytes(1920, {maximumFractionDigits: 1});
|
|
72
|
+
* //=> '1.9 kB'
|
|
73
|
+
*
|
|
74
|
+
* formatBytes(1920);
|
|
75
|
+
* //=> '1.92 kB'
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
maximumFractionDigits?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Put a space between the number and unit.
|
|
81
|
+
* @example
|
|
82
|
+
* ```
|
|
83
|
+
* import formatBytes from '@oliversalzburg/js-utils/format/bytes.js';
|
|
84
|
+
*
|
|
85
|
+
* formatBytes(1920, {space: false});
|
|
86
|
+
* //=> '1.9kB'
|
|
87
|
+
*
|
|
88
|
+
* formatBytes(1920);
|
|
89
|
+
* //=> '1.92 kB'
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
space?: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Convert bytes to a human readable string: `1337` → `1.34 kB`.
|
|
96
|
+
* @param number - The number to format.
|
|
97
|
+
* @param options - The options for formatting the number.
|
|
98
|
+
* @returns The formatted string.
|
|
99
|
+
* @example
|
|
100
|
+
* ```
|
|
101
|
+
* import formatBytes from '@oliversalzburg/js-utils/format/bytes.js';
|
|
102
|
+
*
|
|
103
|
+
* formatBytes(1337);
|
|
104
|
+
* //=> '1.34 kB'
|
|
105
|
+
*
|
|
106
|
+
* formatBytes(100);
|
|
107
|
+
* //=> '100 B'
|
|
108
|
+
*
|
|
109
|
+
* // Display file size differences
|
|
110
|
+
* formatBytes(42, {signed: true});
|
|
111
|
+
* //=> '+42 B'
|
|
112
|
+
*
|
|
113
|
+
* // Localized output using German locale
|
|
114
|
+
* formatBytes(1337, {locale: 'de'});
|
|
115
|
+
* //=> '1,34 kB'
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare const formatBytes: (number: number, options?: Readonly<FormatBytesOptions>) => string;
|