@gtkx/utils 1.0.0-rc.1 → 1.0.0-rc.2
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/dist/array/index-before-or-end.d.ts +15 -0
- package/dist/array/index-before-or-end.d.ts.map +1 -0
- package/dist/array/index-before-or-end.js +21 -0
- package/dist/array/index-before-or-end.js.map +1 -0
- package/dist/array/index.d.ts +6 -0
- package/dist/array/index.d.ts.map +1 -0
- package/dist/array/index.js +6 -0
- package/dist/array/index.js.map +1 -0
- package/dist/array/remove.d.ts +14 -0
- package/dist/array/remove.d.ts.map +1 -0
- package/dist/array/remove.js +19 -0
- package/dist/array/remove.js.map +1 -0
- package/dist/array/sort-strings-by.d.ts +15 -0
- package/dist/array/sort-strings-by.d.ts.map +1 -0
- package/dist/array/sort-strings-by.js +17 -0
- package/dist/array/sort-strings-by.js.map +1 -0
- package/dist/array/sort-strings.d.ts +12 -0
- package/dist/array/sort-strings.d.ts.map +1 -0
- package/dist/array/sort-strings.js +14 -0
- package/dist/array/sort-strings.js.map +1 -0
- package/dist/array/uniq-by.d.ts +18 -0
- package/dist/array/uniq-by.d.ts.map +1 -0
- package/dist/array/uniq-by.js +29 -0
- package/dist/array/uniq-by.js.map +1 -0
- package/dist/class/any-class.d.ts +8 -0
- package/dist/class/any-class.d.ts.map +1 -0
- package/dist/class/any-class.js +2 -0
- package/dist/class/any-class.js.map +1 -0
- package/dist/class/get-parent-class.d.ts +10 -0
- package/dist/class/get-parent-class.d.ts.map +1 -0
- package/dist/class/get-parent-class.js +12 -0
- package/dist/class/get-parent-class.js.map +1 -0
- package/dist/class/index.d.ts +4 -0
- package/dist/class/index.d.ts.map +1 -0
- package/dist/class/index.js +3 -0
- package/dist/class/index.js.map +1 -0
- package/dist/class/walk-class-chain.d.ts +13 -0
- package/dist/class/walk-class-chain.d.ts.map +1 -0
- package/dist/class/walk-class-chain.js +23 -0
- package/dist/class/walk-class-chain.js.map +1 -0
- package/dist/error/error-like.d.ts +6 -0
- package/dist/error/error-like.d.ts.map +1 -0
- package/dist/error/error-like.js +15 -0
- package/dist/error/error-like.js.map +1 -0
- package/dist/error/error-message.d.ts +13 -0
- package/dist/error/error-message.d.ts.map +1 -0
- package/dist/error/error-message.js +16 -0
- package/dist/error/error-message.js.map +1 -0
- package/dist/error/format-child-process-error.d.ts +12 -0
- package/dist/error/format-child-process-error.d.ts.map +1 -0
- package/dist/error/format-child-process-error.js +21 -0
- package/dist/error/format-child-process-error.js.map +1 -0
- package/dist/error/index.d.ts +4 -0
- package/dist/error/index.d.ts.map +1 -0
- package/dist/error/index.js +4 -0
- package/dist/error/index.js.map +1 -0
- package/dist/error/normalize-error.d.ts +13 -0
- package/dist/error/normalize-error.d.ts.map +1 -0
- package/dist/error/normalize-error.js +20 -0
- package/dist/error/normalize-error.js.map +1 -0
- package/dist/function/call-method.d.ts +3 -0
- package/dist/function/call-method.d.ts.map +1 -0
- package/dist/function/call-method.js +19 -0
- package/dist/function/call-method.js.map +1 -0
- package/dist/function/index.d.ts +2 -0
- package/dist/function/index.d.ts.map +1 -0
- package/dist/function/index.js +2 -0
- package/dist/function/index.js.map +1 -0
- package/dist/index.d.ts +13 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -9
- package/dist/index.js.map +1 -1
- package/dist/log/create-logger.d.ts +15 -0
- package/dist/log/create-logger.d.ts.map +1 -0
- package/dist/log/create-logger.js +17 -0
- package/dist/log/create-logger.js.map +1 -0
- package/dist/log/default-logger.d.ts +36 -0
- package/dist/log/default-logger.d.ts.map +1 -0
- package/dist/log/default-logger.js +44 -0
- package/dist/log/default-logger.js.map +1 -0
- package/dist/log/index.d.ts +4 -0
- package/dist/log/index.d.ts.map +1 -0
- package/dist/log/index.js +4 -0
- package/dist/log/index.js.map +1 -0
- package/dist/log/logger.d.ts +64 -0
- package/dist/log/logger.d.ts.map +1 -0
- package/dist/log/logger.js +100 -0
- package/dist/log/logger.js.map +1 -0
- package/dist/map/get-or-insert.d.ts +23 -0
- package/dist/map/get-or-insert.d.ts.map +1 -0
- package/dist/map/get-or-insert.js +25 -0
- package/dist/map/get-or-insert.js.map +1 -0
- package/dist/map/index.d.ts +2 -0
- package/dist/map/index.d.ts.map +1 -0
- package/dist/map/index.js +2 -0
- package/dist/map/index.js.map +1 -0
- package/dist/object/index.d.ts +4 -0
- package/dist/object/index.d.ts.map +1 -0
- package/dist/object/index.js +4 -0
- package/dist/object/index.js.map +1 -0
- package/dist/object/omit.d.ts +15 -0
- package/dist/object/omit.d.ts.map +1 -0
- package/dist/object/omit.js +24 -0
- package/dist/object/omit.js.map +1 -0
- package/dist/object/pick-by.d.ts +15 -0
- package/dist/object/pick-by.d.ts.map +1 -0
- package/dist/object/pick-by.js +24 -0
- package/dist/object/pick-by.js.map +1 -0
- package/dist/object/structured-clone.d.ts +19 -0
- package/dist/object/structured-clone.d.ts.map +1 -0
- package/dist/object/structured-clone.js +28 -0
- package/dist/object/structured-clone.js.map +1 -0
- package/dist/predicate/are-object-keys-equal.d.ts +3 -0
- package/dist/predicate/are-object-keys-equal.d.ts.map +1 -0
- package/dist/predicate/are-object-keys-equal.js +9 -0
- package/dist/predicate/are-object-keys-equal.js.map +1 -0
- package/dist/predicate/index.d.ts +7 -0
- package/dist/predicate/index.d.ts.map +1 -0
- package/dist/predicate/index.js +7 -0
- package/dist/predicate/index.js.map +1 -0
- package/dist/predicate/is-deep-equal.d.ts +3 -0
- package/dist/predicate/is-deep-equal.d.ts.map +1 -0
- package/dist/predicate/is-deep-equal.js +35 -0
- package/dist/predicate/is-deep-equal.js.map +1 -0
- package/dist/predicate/is-plain-object.d.ts +17 -0
- package/dist/predicate/is-plain-object.d.ts.map +1 -0
- package/dist/predicate/is-plain-object.js +23 -0
- package/dist/predicate/is-plain-object.js.map +1 -0
- package/dist/predicate/is-record.d.ts +14 -0
- package/dist/predicate/is-record.d.ts.map +1 -0
- package/dist/predicate/is-record.js +16 -0
- package/dist/predicate/is-record.js.map +1 -0
- package/dist/predicate/is-same-array-by.d.ts +15 -0
- package/dist/predicate/is-same-array-by.d.ts.map +1 -0
- package/dist/predicate/is-same-array-by.js +20 -0
- package/dist/predicate/is-same-array-by.js.map +1 -0
- package/dist/predicate/is-same-array.d.ts +15 -0
- package/dist/predicate/is-same-array.d.ts.map +1 -0
- package/dist/predicate/is-same-array.js +18 -0
- package/dist/predicate/is-same-array.js.map +1 -0
- package/dist/predicate/is-shallow-equal.d.ts +3 -0
- package/dist/predicate/is-shallow-equal.d.ts.map +1 -0
- package/dist/predicate/is-shallow-equal.js +28 -0
- package/dist/predicate/is-shallow-equal.js.map +1 -0
- package/dist/process/exit-code-for-signal.d.ts +14 -0
- package/dist/process/exit-code-for-signal.d.ts.map +1 -0
- package/dist/process/exit-code-for-signal.js +19 -0
- package/dist/process/exit-code-for-signal.js.map +1 -0
- package/dist/process/index.d.ts +4 -0
- package/dist/process/index.d.ts.map +1 -0
- package/dist/process/index.js +4 -0
- package/dist/process/index.js.map +1 -0
- package/dist/process/install-graceful-shutdown.d.ts +16 -0
- package/dist/process/install-graceful-shutdown.d.ts.map +1 -0
- package/dist/{graceful-shutdown.js → process/install-graceful-shutdown.js} +28 -28
- package/dist/process/install-graceful-shutdown.js.map +1 -0
- package/dist/process/resolve-executable.d.ts +14 -0
- package/dist/process/resolve-executable.d.ts.map +1 -0
- package/dist/process/resolve-executable.js +47 -0
- package/dist/process/resolve-executable.js.map +1 -0
- package/dist/set/drain.d.ts +11 -0
- package/dist/set/drain.d.ts.map +1 -0
- package/dist/set/drain.js +16 -0
- package/dist/set/drain.js.map +1 -0
- package/dist/set/index.d.ts +2 -0
- package/dist/set/index.d.ts.map +1 -0
- package/dist/set/index.js +2 -0
- package/dist/set/index.js.map +1 -0
- package/dist/source/index.d.ts +4 -0
- package/dist/source/index.d.ts.map +1 -0
- package/dist/source/index.js +4 -0
- package/dist/source/index.js.map +1 -0
- package/dist/source/sanitize-identifier.d.ts +14 -0
- package/dist/source/sanitize-identifier.d.ts.map +1 -0
- package/dist/source/sanitize-identifier.js +65 -0
- package/dist/source/sanitize-identifier.js.map +1 -0
- package/dist/source/source-string-literal.d.ts +13 -0
- package/dist/source/source-string-literal.d.ts.map +1 -0
- package/dist/source/source-string-literal.js +24 -0
- package/dist/source/source-string-literal.js.map +1 -0
- package/dist/source/to-camel-identifier.d.ts +13 -0
- package/dist/source/to-camel-identifier.d.ts.map +1 -0
- package/dist/source/to-camel-identifier.js +17 -0
- package/dist/source/to-camel-identifier.js.map +1 -0
- package/dist/string/camel-case.d.ts +17 -0
- package/dist/string/camel-case.d.ts.map +1 -0
- package/dist/string/camel-case.js +21 -0
- package/dist/string/camel-case.js.map +1 -0
- package/dist/string/index.d.ts +6 -0
- package/dist/string/index.d.ts.map +1 -0
- package/dist/string/index.js +6 -0
- package/dist/string/index.js.map +1 -0
- package/dist/string/kebab-case.d.ts +14 -0
- package/dist/string/kebab-case.d.ts.map +1 -0
- package/dist/string/kebab-case.js +16 -0
- package/dist/string/kebab-case.js.map +1 -0
- package/dist/string/lower-first.d.ts +13 -0
- package/dist/string/lower-first.d.ts.map +1 -0
- package/dist/string/lower-first.js +15 -0
- package/dist/string/lower-first.js.map +1 -0
- package/dist/string/pascal-case.d.ts +16 -0
- package/dist/string/pascal-case.d.ts.map +1 -0
- package/dist/string/pascal-case.js +20 -0
- package/dist/string/pascal-case.js.map +1 -0
- package/dist/string/upper-first.d.ts +13 -0
- package/dist/string/upper-first.d.ts.map +1 -0
- package/dist/string/upper-first.js +15 -0
- package/dist/string/upper-first.js.map +1 -0
- package/dist/string/word-segments.d.ts +3 -0
- package/dist/string/word-segments.d.ts.map +1 -0
- package/dist/string/word-segments.js +12 -0
- package/dist/string/word-segments.js.map +1 -0
- package/dist/util/index.d.ts +2 -0
- package/dist/util/index.d.ts.map +1 -0
- package/dist/util/index.js +2 -0
- package/dist/util/index.js.map +1 -0
- package/dist/util/package-version.d.ts +12 -0
- package/dist/util/package-version.d.ts.map +1 -0
- package/dist/util/package-version.js +15 -0
- package/dist/util/package-version.js.map +1 -0
- package/package.json +1 -3
- package/src/array/index-before-or-end.ts +27 -0
- package/src/array/index.ts +5 -0
- package/src/array/remove.ts +20 -0
- package/src/array/sort-strings-by.ts +17 -0
- package/src/array/sort-strings.ts +14 -0
- package/src/array/uniq-by.ts +33 -0
- package/src/class/any-class.ts +10 -0
- package/src/class/get-parent-class.ts +15 -0
- package/src/class/index.ts +3 -0
- package/src/class/walk-class-chain.ts +29 -0
- package/src/error/error-like.ts +19 -0
- package/src/error/error-message.ts +17 -0
- package/src/error/format-child-process-error.ts +24 -0
- package/src/error/index.ts +3 -0
- package/src/error/normalize-error.ts +22 -0
- package/src/function/call-method.ts +22 -0
- package/src/function/index.ts +1 -0
- package/src/index.ts +13 -19
- package/src/log/create-logger.ts +18 -0
- package/src/log/default-logger.ts +49 -0
- package/src/log/index.ts +3 -0
- package/src/log/logger.ts +142 -0
- package/src/map/get-or-insert.ts +33 -0
- package/src/map/index.ts +1 -0
- package/src/object/index.ts +3 -0
- package/src/object/omit.ts +26 -0
- package/src/object/pick-by.ts +30 -0
- package/src/object/structured-clone.ts +31 -0
- package/src/predicate/are-object-keys-equal.ts +15 -0
- package/src/predicate/index.ts +6 -0
- package/src/predicate/is-deep-equal.ts +41 -0
- package/src/predicate/is-plain-object.ts +25 -0
- package/src/predicate/is-record.ts +16 -0
- package/src/predicate/is-same-array-by.ts +21 -0
- package/src/predicate/is-same-array.ts +19 -0
- package/src/predicate/is-shallow-equal.ts +32 -0
- package/src/process/exit-code-for-signal.ts +20 -0
- package/src/process/index.ts +3 -0
- package/src/{graceful-shutdown.ts → process/install-graceful-shutdown.ts} +48 -36
- package/src/process/resolve-executable.ts +57 -0
- package/src/set/drain.ts +17 -0
- package/src/set/index.ts +1 -0
- package/src/source/index.ts +3 -0
- package/src/source/sanitize-identifier.ts +66 -0
- package/src/source/source-string-literal.ts +27 -0
- package/src/source/to-camel-identifier.ts +18 -0
- package/src/string/camel-case.ts +22 -0
- package/src/string/index.ts +5 -0
- package/src/string/kebab-case.ts +18 -0
- package/src/string/lower-first.ts +15 -0
- package/src/string/pascal-case.ts +21 -0
- package/src/string/upper-first.ts +15 -0
- package/src/string/word-segments.ts +15 -0
- package/src/util/index.ts +1 -0
- package/src/util/package-version.ts +16 -0
- package/dist/class.d.ts +0 -22
- package/dist/class.d.ts.map +0 -1
- package/dist/class.js +0 -28
- package/dist/class.js.map +0 -1
- package/dist/collection.d.ts +0 -30
- package/dist/collection.d.ts.map +0 -1
- package/dist/collection.js +0 -64
- package/dist/collection.js.map +0 -1
- package/dist/error.d.ts +0 -21
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js +0 -40
- package/dist/error.js.map +0 -1
- package/dist/graceful-shutdown.d.ts +0 -22
- package/dist/graceful-shutdown.d.ts.map +0 -1
- package/dist/graceful-shutdown.js.map +0 -1
- package/dist/log.d.ts +0 -103
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -129
- package/dist/log.js.map +0 -1
- package/dist/package-version.d.ts +0 -7
- package/dist/package-version.d.ts.map +0 -1
- package/dist/package-version.js +0 -8
- package/dist/package-version.js.map +0 -1
- package/dist/reflect.d.ts +0 -11
- package/dist/reflect.d.ts.map +0 -1
- package/dist/reflect.js +0 -14
- package/dist/reflect.js.map +0 -1
- package/dist/source.d.ts +0 -21
- package/dist/source.d.ts.map +0 -1
- package/dist/source.js +0 -78
- package/dist/source.js.map +0 -1
- package/dist/string.d.ts +0 -32
- package/dist/string.d.ts.map +0 -1
- package/dist/string.js +0 -43
- package/dist/string.js.map +0 -1
- package/src/class.ts +0 -36
- package/src/collection.ts +0 -65
- package/src/error.ts +0 -42
- package/src/log.ts +0 -164
- package/src/package-version.ts +0 -9
- package/src/reflect.ts +0 -13
- package/src/source.ts +0 -84
- package/src/string.ts +0 -46
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a camelCase or PascalCase string to kebab case by lower-casing uppercase letters and
|
|
3
|
+
* inserting hyphens before interior ones.
|
|
4
|
+
*
|
|
5
|
+
* @param str - The string to convert.
|
|
6
|
+
* @returns The kebab-cased string.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* kebabCase("iconName"); // "icon-name"
|
|
10
|
+
* kebabCase("Title"); // "title"
|
|
11
|
+
*/
|
|
12
|
+
function kebabCase(str: string): string {
|
|
13
|
+
return str.replaceAll(/[A-Z]/g, (char, index: number) =>
|
|
14
|
+
index === 0 ? char.toLowerCase() : `-${char.toLowerCase()}`,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { kebabCase };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the first character of a string to lower case.
|
|
3
|
+
*
|
|
4
|
+
* @param str - The string to transform.
|
|
5
|
+
* @returns The string with its first character lower-cased.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* lowerFirst("Fred"); // "fred"
|
|
9
|
+
* lowerFirst("FRED"); // "fRED"
|
|
10
|
+
*/
|
|
11
|
+
function lowerFirst(str: string): string {
|
|
12
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { lowerFirst };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { upperFirst } from "./upper-first.js";
|
|
2
|
+
import { mapWordSegments } from "./word-segments.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts an underscore- or hyphen-delimited string to Pascal case.
|
|
6
|
+
*
|
|
7
|
+
* Splits only on `_` and `-` and capitalizes each segment's first character, so GObject acronyms
|
|
8
|
+
* are preserved (`pascalCase("GLArea")` stays `"GLArea"`).
|
|
9
|
+
*
|
|
10
|
+
* @param str - The string to convert.
|
|
11
|
+
* @returns The Pascal-cased string.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* pascalCase("icon_name"); // "IconName"
|
|
15
|
+
* pascalCase("scrolled-window"); // "ScrolledWindow"
|
|
16
|
+
*/
|
|
17
|
+
function pascalCase(str: string): string {
|
|
18
|
+
return mapWordSegments(str, upperFirst);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { pascalCase };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the first character of a string to upper case.
|
|
3
|
+
*
|
|
4
|
+
* @param str - The string to transform.
|
|
5
|
+
* @returns The string with its first character upper-cased.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* upperFirst("fred"); // "Fred"
|
|
9
|
+
* upperFirst("Fred"); // "Fred"
|
|
10
|
+
*/
|
|
11
|
+
function upperFirst(str: string): string {
|
|
12
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { upperFirst };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function splitWords(input: string): string[] {
|
|
2
|
+
return input.split(/[_-]/g).filter((part) => part.length > 0);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function mapWordSegments(input: string, mapSegment: (part: string, index: number) => string): string {
|
|
6
|
+
const parts = splitWords(input);
|
|
7
|
+
|
|
8
|
+
if (parts.length === 0) {
|
|
9
|
+
return input;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return parts.map((part, index) => mapSegment(part, index)).join("");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { mapWordSegments };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { packageVersion } from "./package-version.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reads the `version` field from the `package.json` next to the calling module.
|
|
5
|
+
*
|
|
6
|
+
* @param importMetaUrl - The caller's `import.meta.url`, used to resolve the sibling `package.json`.
|
|
7
|
+
* @returns The package's version string.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* packageVersion(import.meta.url); // "1.2.3"
|
|
11
|
+
*/
|
|
12
|
+
function packageVersion(importMetaUrl: string): string {
|
|
13
|
+
return (createRequire(importMetaUrl)("../package.json") as { version: string }).version;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { packageVersion };
|
package/dist/class.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A constructor value of any (possibly abstract) class producing instances of `T`.
|
|
3
|
-
*/
|
|
4
|
-
export type AnyClass<T extends object = object> = (abstract new (...args: never[]) => T) & {
|
|
5
|
-
prototype: T;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Returns the direct superclass of `cls`, or `null` when it has no class ancestor.
|
|
9
|
-
*
|
|
10
|
-
* @param cls The class whose prototype parent to inspect.
|
|
11
|
-
*/
|
|
12
|
-
export declare function getParentClass(cls: AnyClass): AnyClass | null;
|
|
13
|
-
/**
|
|
14
|
-
* Walks the class chain from `cls` up through its ancestors, calling `visit` on each and
|
|
15
|
-
* returning the first result that is not `undefined`.
|
|
16
|
-
*
|
|
17
|
-
* @param cls The class to start from, or `null` to visit nothing.
|
|
18
|
-
* @param visit Called with each class in the chain; a defined return value stops the walk.
|
|
19
|
-
* @returns The first defined result from `visit`, or `undefined` if none was produced.
|
|
20
|
-
*/
|
|
21
|
-
export declare function walkClassChain<T>(cls: AnyClass | null, visit: (ancestor: AnyClass) => T | undefined): T | undefined;
|
|
22
|
-
//# sourceMappingURL=class.d.ts.map
|
package/dist/class.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"class.d.ts","sourceRoot":"","sources":["../src/class.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,MACvD,GAAG,IAAI,EAAE,KAAK,EAAE,KACf,CAAC,CAAC,GAAG;IACN,SAAS,EAAE,CAAC,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,QAAQ,GAAG,QAAQ,GAAG,IAAI,CAG7D;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,QAAQ,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,CAAC,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS,CAQnH"}
|
package/dist/class.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the direct superclass of `cls`, or `null` when it has no class ancestor.
|
|
3
|
-
*
|
|
4
|
-
* @param cls The class whose prototype parent to inspect.
|
|
5
|
-
*/
|
|
6
|
-
export function getParentClass(cls) {
|
|
7
|
-
const parent = Object.getPrototypeOf(cls);
|
|
8
|
-
return typeof parent === "function" && parent !== Function.prototype ? parent : null;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Walks the class chain from `cls` up through its ancestors, calling `visit` on each and
|
|
12
|
-
* returning the first result that is not `undefined`.
|
|
13
|
-
*
|
|
14
|
-
* @param cls The class to start from, or `null` to visit nothing.
|
|
15
|
-
* @param visit Called with each class in the chain; a defined return value stops the walk.
|
|
16
|
-
* @returns The first defined result from `visit`, or `undefined` if none was produced.
|
|
17
|
-
*/
|
|
18
|
-
export function walkClassChain(cls, visit) {
|
|
19
|
-
let current = cls;
|
|
20
|
-
while (current !== null) {
|
|
21
|
-
const result = visit(current);
|
|
22
|
-
if (result !== undefined)
|
|
23
|
-
return result;
|
|
24
|
-
current = getParentClass(current);
|
|
25
|
-
}
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=class.js.map
|
package/dist/class.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"class.js","sourceRoot":"","sources":["../src/class.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,GAAa;IACxC,MAAM,MAAM,GAAY,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IACnD,OAAO,OAAO,MAAM,KAAK,UAAU,IAAI,MAAM,KAAK,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAE,MAAmB,CAAC,CAAC,CAAC,IAAI,CAAC;AACvG,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAI,GAAoB,EAAE,KAA4C;IAChG,IAAI,OAAO,GAAG,GAAG,CAAC;IAClB,OAAO,OAAO,KAAK,IAAI,EAAE,CAAC;QACtB,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,MAAM,CAAC;QACxC,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC","sourcesContent":["/**\n * A constructor value of any (possibly abstract) class producing instances of `T`.\n */\nexport type AnyClass<T extends object = object> = (abstract new (\n ...args: never[]\n) => T) & {\n prototype: T;\n};\n\n/**\n * Returns the direct superclass of `cls`, or `null` when it has no class ancestor.\n *\n * @param cls The class whose prototype parent to inspect.\n */\nexport function getParentClass(cls: AnyClass): AnyClass | null {\n const parent: unknown = Object.getPrototypeOf(cls);\n return typeof parent === \"function\" && parent !== Function.prototype ? (parent as AnyClass) : null;\n}\n\n/**\n * Walks the class chain from `cls` up through its ancestors, calling `visit` on each and\n * returning the first result that is not `undefined`.\n *\n * @param cls The class to start from, or `null` to visit nothing.\n * @param visit Called with each class in the chain; a defined return value stops the walk.\n * @returns The first defined result from `visit`, or `undefined` if none was produced.\n */\nexport function walkClassChain<T>(cls: AnyClass | null, visit: (ancestor: AnyClass) => T | undefined): T | undefined {\n let current = cls;\n while (current !== null) {\n const result = visit(current);\n if (result !== undefined) return result;\n current = getParentClass(current);\n }\n return undefined;\n}\n"]}
|
package/dist/collection.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the items with duplicates removed, keeping the first item for each distinct key.
|
|
3
|
-
*
|
|
4
|
-
* @param items The items to deduplicate.
|
|
5
|
-
* @param key Computes the identity string used to detect duplicates.
|
|
6
|
-
*/
|
|
7
|
-
export declare const uniqBy: <T>(items: T[], key: (item: T) => string) => T[];
|
|
8
|
-
export declare const isSameArray: <T>(a: T[], b: T[]) => boolean;
|
|
9
|
-
/**
|
|
10
|
-
* Returns a new array of the given strings sorted with locale-aware comparison.
|
|
11
|
-
*
|
|
12
|
-
* @param values The strings to sort.
|
|
13
|
-
*/
|
|
14
|
-
export declare const sortStrings: (values: Iterable<string>) => string[];
|
|
15
|
-
/**
|
|
16
|
-
* Returns a new array of the given items sorted by a locale-aware comparison of their keys.
|
|
17
|
-
*
|
|
18
|
-
* @param items The items to sort.
|
|
19
|
-
* @param key Computes the string to sort each item by.
|
|
20
|
-
*/
|
|
21
|
-
export declare const sortStringsBy: <T>(items: Iterable<T>, key: (item: T) => string) => T[];
|
|
22
|
-
/**
|
|
23
|
-
* Determines whether two records have the same keys and strictly equal values.
|
|
24
|
-
*
|
|
25
|
-
* @param a The first record, or `undefined`.
|
|
26
|
-
* @param b The second record, or `undefined`.
|
|
27
|
-
* @returns `true` when both are the same reference, or both are defined with identical own keys and values.
|
|
28
|
-
*/
|
|
29
|
-
export declare const isShallowEqual: <T extends Record<string, unknown>>(a?: T, b?: T) => boolean;
|
|
30
|
-
//# sourceMappingURL=collection.d.ts.map
|
package/dist/collection.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,KAAG,CAAC,EAUjE,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,KAAG,OAM/C,CAAC;AAIF;;;;GAIG;AACH,eAAO,MAAM,WAAW,WAAY,QAAQ,CAAC,MAAM,CAAC,KAAG,MAAM,EAAsC,CAAC;AAEpG;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,KAAG,CAAC,EACpB,CAAC;AAE9D;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAG,OAahF,CAAC"}
|
package/dist/collection.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the items with duplicates removed, keeping the first item for each distinct key.
|
|
3
|
-
*
|
|
4
|
-
* @param items The items to deduplicate.
|
|
5
|
-
* @param key Computes the identity string used to detect duplicates.
|
|
6
|
-
*/
|
|
7
|
-
export const uniqBy = (items, key) => {
|
|
8
|
-
const seen = new Set();
|
|
9
|
-
const result = [];
|
|
10
|
-
for (const item of items) {
|
|
11
|
-
const identity = key(item);
|
|
12
|
-
if (seen.has(identity))
|
|
13
|
-
continue;
|
|
14
|
-
seen.add(identity);
|
|
15
|
-
result.push(item);
|
|
16
|
-
}
|
|
17
|
-
return result;
|
|
18
|
-
};
|
|
19
|
-
export const isSameArray = (a, b) => {
|
|
20
|
-
if (a.length !== b.length)
|
|
21
|
-
return false;
|
|
22
|
-
for (let index = 0; index < a.length; index++) {
|
|
23
|
-
if (a[index] !== b[index])
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
};
|
|
28
|
-
const compareStrings = (a, b) => a.localeCompare(b);
|
|
29
|
-
/**
|
|
30
|
-
* Returns a new array of the given strings sorted with locale-aware comparison.
|
|
31
|
-
*
|
|
32
|
-
* @param values The strings to sort.
|
|
33
|
-
*/
|
|
34
|
-
export const sortStrings = (values) => [...values].sort(compareStrings);
|
|
35
|
-
/**
|
|
36
|
-
* Returns a new array of the given items sorted by a locale-aware comparison of their keys.
|
|
37
|
-
*
|
|
38
|
-
* @param items The items to sort.
|
|
39
|
-
* @param key Computes the string to sort each item by.
|
|
40
|
-
*/
|
|
41
|
-
export const sortStringsBy = (items, key) => [...items].sort((a, b) => compareStrings(key(a), key(b)));
|
|
42
|
-
/**
|
|
43
|
-
* Determines whether two records have the same keys and strictly equal values.
|
|
44
|
-
*
|
|
45
|
-
* @param a The first record, or `undefined`.
|
|
46
|
-
* @param b The second record, or `undefined`.
|
|
47
|
-
* @returns `true` when both are the same reference, or both are defined with identical own keys and values.
|
|
48
|
-
*/
|
|
49
|
-
export const isShallowEqual = (a, b) => {
|
|
50
|
-
if (a === b)
|
|
51
|
-
return true;
|
|
52
|
-
if (!a || !b)
|
|
53
|
-
return false;
|
|
54
|
-
const keysA = Object.keys(a);
|
|
55
|
-
const keysB = Object.keys(b);
|
|
56
|
-
if (keysA.length !== keysB.length)
|
|
57
|
-
return false;
|
|
58
|
-
for (const key of keysA) {
|
|
59
|
-
if (a[key] !== b[key])
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
return true;
|
|
63
|
-
};
|
|
64
|
-
//# sourceMappingURL=collection.js.map
|
package/dist/collection.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collection.js","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAI,KAAU,EAAE,GAAwB,EAAO,EAAE;IACnE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,MAAM,GAAQ,EAAE,CAAC;IACvB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAG,GA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AK,EAAW,EAAE;IACvF,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAE3B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7B,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAEhD,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;IACxC,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC","sourcesContent":["/**\n * Returns the items with duplicates removed, keeping the first item for each distinct key.\n *\n * @param items The items to deduplicate.\n * @param key Computes the identity string used to detect duplicates.\n */\nexport const uniqBy = <T>(items: T[], key: (item: T) => string): T[] => {\n const seen = new Set<string>();\n const result: T[] = [];\n for (const item of items) {\n const identity = key(item);\n if (seen.has(identity)) continue;\n seen.add(identity);\n result.push(item);\n }\n return result;\n};\n\nexport const isSameArray = <T>(a: T[], b: T[]): boolean => {\n if (a.length !== b.length) return false;\n for (let index = 0; index < a.length; index++) {\n if (a[index] !== b[index]) return false;\n }\n return true;\n};\n\nconst compareStrings = (a: string, b: string): number => a.localeCompare(b);\n\n/**\n * Returns a new array of the given strings sorted with locale-aware comparison.\n *\n * @param values The strings to sort.\n */\nexport const sortStrings = (values: Iterable<string>): string[] => [...values].sort(compareStrings);\n\n/**\n * Returns a new array of the given items sorted by a locale-aware comparison of their keys.\n *\n * @param items The items to sort.\n * @param key Computes the string to sort each item by.\n */\nexport const sortStringsBy = <T>(items: Iterable<T>, key: (item: T) => string): T[] =>\n [...items].sort((a, b) => compareStrings(key(a), key(b)));\n\n/**\n * Determines whether two records have the same keys and strictly equal values.\n *\n * @param a The first record, or `undefined`.\n * @param b The second record, or `undefined`.\n * @returns `true` when both are the same reference, or both are defined with identical own keys and values.\n */\nexport const isShallowEqual = <T extends Record<string, unknown>>(a?: T, b?: T): boolean => {\n if (a === b) return true;\n if (!a || !b) return false;\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (a[key] !== b[key]) return false;\n }\n\n return true;\n};\n"]}
|
package/dist/error.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts a human-readable message from an unknown thrown value, falling back to its string form.
|
|
3
|
-
*
|
|
4
|
-
* @param error The caught value to describe.
|
|
5
|
-
*/
|
|
6
|
-
export declare const errorMessage: (error: unknown) => string;
|
|
7
|
-
/**
|
|
8
|
-
* Coerces an unknown thrown value into an `Error`, reusing it if it already is one and otherwise
|
|
9
|
-
* wrapping its message while copying any error-like own properties.
|
|
10
|
-
*
|
|
11
|
-
* @param error The caught value to normalize.
|
|
12
|
-
*/
|
|
13
|
-
export declare const normalizeError: (error: unknown) => Error;
|
|
14
|
-
/**
|
|
15
|
-
* Combines the `stderr` and `stdout` fields of a failed child-process error into a single trimmed string.
|
|
16
|
-
*
|
|
17
|
-
* @param error The child-process error to read output from.
|
|
18
|
-
* @returns The joined output, or `undefined` when neither stream carried any text.
|
|
19
|
-
*/
|
|
20
|
-
export declare const formatChildProcessError: (error: unknown) => string | undefined;
|
|
21
|
-
//# sourceMappingURL=error.d.ts.map
|
package/dist/error.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,MACgC,CAAC;AAE/E;;;;;GAKG;AACH,eAAO,MAAM,cAAc,UAAW,OAAO,KAAG,KAG/C,CAAC;AAQF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,UAAW,OAAO,KAAG,MAAM,GAAG,SAKjE,CAAC"}
|
package/dist/error.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const isObject = (value) => typeof value === "object" && value !== null;
|
|
2
|
-
const isErrorLike = (value) => isObject(value) && "message" in value && typeof value.message === "string";
|
|
3
|
-
/**
|
|
4
|
-
* Extracts a human-readable message from an unknown thrown value, falling back to its string form.
|
|
5
|
-
*
|
|
6
|
-
* @param error The caught value to describe.
|
|
7
|
-
*/
|
|
8
|
-
export const errorMessage = (error) => Error.isError(error) || isErrorLike(error) ? error.message : String(error);
|
|
9
|
-
/**
|
|
10
|
-
* Coerces an unknown thrown value into an `Error`, reusing it if it already is one and otherwise
|
|
11
|
-
* wrapping its message while copying any error-like own properties.
|
|
12
|
-
*
|
|
13
|
-
* @param error The caught value to normalize.
|
|
14
|
-
*/
|
|
15
|
-
export const normalizeError = (error) => {
|
|
16
|
-
if (Error.isError(error))
|
|
17
|
-
return error;
|
|
18
|
-
return Object.assign(new Error(errorMessage(error)), isErrorLike(error) ? error : {});
|
|
19
|
-
};
|
|
20
|
-
const readStream = (value) => {
|
|
21
|
-
if (typeof value === "string")
|
|
22
|
-
return value;
|
|
23
|
-
if (value instanceof Uint8Array || Buffer.isBuffer(value))
|
|
24
|
-
return value.toString();
|
|
25
|
-
return "";
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Combines the `stderr` and `stdout` fields of a failed child-process error into a single trimmed string.
|
|
29
|
-
*
|
|
30
|
-
* @param error The child-process error to read output from.
|
|
31
|
-
* @returns The joined output, or `undefined` when neither stream carried any text.
|
|
32
|
-
*/
|
|
33
|
-
export const formatChildProcessError = (error) => {
|
|
34
|
-
if (!isObject(error))
|
|
35
|
-
return undefined;
|
|
36
|
-
const { stderr, stdout } = error;
|
|
37
|
-
const details = [readStream(stderr), readStream(stdout)].filter(Boolean).join("\n").trim();
|
|
38
|
-
return details.length > 0 ? details : undefined;
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=error.js.map
|
package/dist/error.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AAEnH,MAAM,WAAW,GAAG,CAAC,KAAc,EAAgC,EAAE,CACjE,QAAQ,CAAC,KAAK,CAAC,IAAI,SAAS,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CAAC;AAE/E;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAc,EAAU,EAAE,CACnD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAc,EAAS,EAAE;IACpD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC1F,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,KAAc,EAAU,EAAE;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,KAAK,YAAY,UAAU,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IACnF,OAAO,EAAE,CAAC;AACd,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAc,EAAsB,EAAE;IAC1E,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACvC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACjC,MAAM,OAAO,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;IAC3F,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AACpD,CAAC,CAAC","sourcesContent":["const isObject = (value: unknown): value is Record<string, unknown> => typeof value === \"object\" && value !== null;\n\nconst isErrorLike = (value: unknown): value is { message: string } =>\n isObject(value) && \"message\" in value && typeof value.message === \"string\";\n\n/**\n * Extracts a human-readable message from an unknown thrown value, falling back to its string form.\n *\n * @param error The caught value to describe.\n */\nexport const errorMessage = (error: unknown): string =>\n Error.isError(error) || isErrorLike(error) ? error.message : String(error);\n\n/**\n * Coerces an unknown thrown value into an `Error`, reusing it if it already is one and otherwise\n * wrapping its message while copying any error-like own properties.\n *\n * @param error The caught value to normalize.\n */\nexport const normalizeError = (error: unknown): Error => {\n if (Error.isError(error)) return error;\n return Object.assign(new Error(errorMessage(error)), isErrorLike(error) ? error : {});\n};\n\nconst readStream = (value: unknown): string => {\n if (typeof value === \"string\") return value;\n if (value instanceof Uint8Array || Buffer.isBuffer(value)) return value.toString();\n return \"\";\n};\n\n/**\n * Combines the `stderr` and `stdout` fields of a failed child-process error into a single trimmed string.\n *\n * @param error The child-process error to read output from.\n * @returns The joined output, or `undefined` when neither stream carried any text.\n */\nexport const formatChildProcessError = (error: unknown): string | undefined => {\n if (!isObject(error)) return undefined;\n const { stderr, stdout } = error;\n const details = [readStream(stderr), readStream(stdout)].filter(Boolean).join(\"\\n\").trim();\n return details.length > 0 ? details : undefined;\n};\n"]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Maps a terminating signal to its conventional process exit code (130 for `SIGINT`, 143 otherwise),
|
|
3
|
-
* or 0 when no signal is given.
|
|
4
|
-
*
|
|
5
|
-
* @param signal The signal that triggered termination, or `null`.
|
|
6
|
-
*/
|
|
7
|
-
export declare const exitCodeForSignal: (signal: NodeJS.Signals | null) => number;
|
|
8
|
-
export type GracefulShutdownOptions = {
|
|
9
|
-
onSignal: (signal: NodeJS.Signals) => void | Promise<void>;
|
|
10
|
-
onForce?: () => void;
|
|
11
|
-
forceKillAfterMs?: number;
|
|
12
|
-
coalesceWindowMs?: number;
|
|
13
|
-
exitCode?: (signal: NodeJS.Signals, graceful: boolean) => number;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Registers handlers for `SIGINT`, `SIGTERM`, and `SIGHUP` that run the given cleanup callback once
|
|
17
|
-
* and then exit, forcing exit if a repeated signal arrives or the cleanup exceeds its timeout.
|
|
18
|
-
*
|
|
19
|
-
* @param options The shutdown callbacks and timing configuration.
|
|
20
|
-
*/
|
|
21
|
-
export declare const installGracefulShutdown: (options: GracefulShutdownOptions) => void;
|
|
22
|
-
//# sourceMappingURL=graceful-shutdown.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"graceful-shutdown.d.ts","sourceRoot":"","sources":["../src/graceful-shutdown.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,WAAY,MAAM,CAAC,OAAO,GAAG,IAAI,KAAG,MAGjE,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IAClC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO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K,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QAChC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IAC9C,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { error } from \"./log.js\";\n\nconst HANDLED_SIGNALS = [\"SIGINT\", \"SIGTERM\", \"SIGHUP\"] as const satisfies NodeJS.Signals[];\nconst DEFAULT_FORCE_KILL_TIMEOUT_MS = 5000;\nconst DEFAULT_COALESCE_WINDOW_MS = 500;\n\n/**\n * Maps a terminating signal to its conventional process exit code (130 for `SIGINT`, 143 otherwise),\n * or 0 when no signal is given.\n *\n * @param signal The signal that triggered termination, or `null`.\n */\nexport const exitCodeForSignal = (signal: NodeJS.Signals | null): number => {\n if (!signal) return 0;\n return signal === \"SIGINT\" ? 130 : 143;\n};\n\nexport type GracefulShutdownOptions = {\n onSignal: (signal: NodeJS.Signals) => void | Promise<void>;\n onForce?: () => void;\n forceKillAfterMs?: number;\n coalesceWindowMs?: number;\n exitCode?: (signal: NodeJS.Signals, graceful: boolean) => number;\n};\n\ntype ShutdownState = {\n options: GracefulShutdownOptions;\n forceKillMs: number;\n coalesceWindowMs: number;\n firstSignal: NodeJS.Signals | null;\n exited: boolean;\n coalescing: boolean;\n forceTimer: NodeJS.Timeout | null;\n coalesceTimer: NodeJS.Timeout | null;\n};\n\nconst clearTimers = (state: ShutdownState): void => {\n if (state.forceTimer) {\n clearTimeout(state.forceTimer);\n state.forceTimer = null;\n }\n if (state.coalesceTimer) {\n clearTimeout(state.coalesceTimer);\n state.coalesceTimer = null;\n }\n};\n\nconst finish = (state: ShutdownState, signal: NodeJS.Signals, graceful: boolean): void => {\n if (state.exited) return;\n state.exited = true;\n clearTimers(state);\n const { exitCode } = state.options;\n const code = exitCode ? exitCode(signal, graceful) : graceful ? 0 : exitCodeForSignal(signal);\n process.exit(code);\n};\n\nconst beginShutdown = (state: ShutdownState, signal: NodeJS.Signals): void => {\n state.firstSignal = signal;\n if (state.coalesceWindowMs > 0) {\n state.coalescing = true;\n state.coalesceTimer = setTimeout(() => {\n state.coalescing = false;\n }, state.coalesceWindowMs);\n state.coalesceTimer.unref();\n }\n if (state.options.onForce && state.forceKillMs > 0) {\n state.forceTimer = setTimeout(() => {\n state.options.onForce?.();\n finish(state, signal, false);\n }, state.forceKillMs);\n state.forceTimer.unref();\n }\n Promise.resolve()\n .then(() => state.options.onSignal(signal))\n .then(\n () => finish(state, signal, true),\n (reason: unknown) => {\n error(\"graceful shutdown failed\", reason);\n finish(state, signal, false);\n },\n );\n};\n\nconst handle = (state: ShutdownState, signal: NodeJS.Signals): void => {\n if (state.firstSignal === null) {\n beginShutdown(state, signal);\n return;\n }\n if (state.coalescing) return;\n state.options.onForce?.();\n finish(state, signal, false);\n};\n\n/**\n * Registers handlers for `SIGINT`, `SIGTERM`, and `SIGHUP` that run the given cleanup callback once\n * and then exit, forcing exit if a repeated signal arrives or the cleanup exceeds its timeout.\n *\n * @param options The shutdown callbacks and timing configuration.\n */\nexport const installGracefulShutdown = (options: GracefulShutdownOptions): void => {\n const state: ShutdownState = {\n options,\n forceKillMs: options.forceKillAfterMs ?? DEFAULT_FORCE_KILL_TIMEOUT_MS,\n coalesceWindowMs: options.coalesceWindowMs ?? DEFAULT_COALESCE_WINDOW_MS,\n firstSignal: null,\n exited: false,\n coalescing: false,\n forceTimer: null,\n coalesceTimer: null,\n };\n for (const sig of HANDLED_SIGNALS) {\n process.on(sig, () => handle(state, sig));\n }\n};\n"]}
|
package/dist/log.d.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal writable-stream shape a {@link Logger} writes formatted lines to.
|
|
3
|
-
*/
|
|
4
|
-
export type OutputStream = {
|
|
5
|
-
write(chunk: string): unknown;
|
|
6
|
-
/** Whether the stream is a terminal, used to decide if colored output is emitted. */
|
|
7
|
-
isTTY?: boolean | undefined;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Options for constructing a {@link Logger}.
|
|
11
|
-
*/
|
|
12
|
-
export type LoggerOptions = {
|
|
13
|
-
/** Namespace appended to the log prefix and matched against debug configuration. */
|
|
14
|
-
namespace?: string | undefined;
|
|
15
|
-
/** Stream to write log lines to; defaults to `process.stderr`. */
|
|
16
|
-
stream?: OutputStream | undefined;
|
|
17
|
-
/** Forces debug output on or off; when omitted it is resolved from `--debug` and `GTKX_DEBUG`. */
|
|
18
|
-
debugEnabled?: boolean | undefined;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Writes prefixed, optionally colored log lines to an output stream, with debug lines gated by
|
|
22
|
-
* command-line and environment configuration.
|
|
23
|
-
*/
|
|
24
|
-
export declare class Logger {
|
|
25
|
-
private stream;
|
|
26
|
-
private prefix;
|
|
27
|
-
private debugEnabled;
|
|
28
|
-
private colors;
|
|
29
|
-
/**
|
|
30
|
-
* @param options Namespace, target stream, and debug configuration for the logger.
|
|
31
|
-
*/
|
|
32
|
-
constructor(options?: LoggerOptions);
|
|
33
|
-
private write;
|
|
34
|
-
/**
|
|
35
|
-
* Writes an informational line.
|
|
36
|
-
*
|
|
37
|
-
* @param message The message text.
|
|
38
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
39
|
-
*/
|
|
40
|
-
info(message: string, ...rest: unknown[]): void;
|
|
41
|
-
/**
|
|
42
|
-
* Writes a line marked as a warning.
|
|
43
|
-
*
|
|
44
|
-
* @param message The message text.
|
|
45
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
46
|
-
*/
|
|
47
|
-
warn(message: string, ...rest: unknown[]): void;
|
|
48
|
-
/**
|
|
49
|
-
* Writes a line marked as an error.
|
|
50
|
-
*
|
|
51
|
-
* @param message The message text.
|
|
52
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
53
|
-
*/
|
|
54
|
-
error(message: string, ...rest: unknown[]): void;
|
|
55
|
-
/**
|
|
56
|
-
* Writes a line only when debug output is enabled for this logger.
|
|
57
|
-
*
|
|
58
|
-
* @param message The message text.
|
|
59
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
60
|
-
*/
|
|
61
|
-
debug(message: string, ...rest: unknown[]): void;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Creates a {@link Logger} scoped to the given namespace.
|
|
65
|
-
*
|
|
66
|
-
* @param namespace Namespace added to the log prefix and matched against debug configuration.
|
|
67
|
-
* @param options Further logger options excluding the namespace.
|
|
68
|
-
*/
|
|
69
|
-
export declare const createLogger: (namespace: string, options?: Omit<LoggerOptions, "namespace">) => Logger;
|
|
70
|
-
/**
|
|
71
|
-
* The default namespace-less {@link Logger} backing the module-level {@link info}, {@link warn},
|
|
72
|
-
* {@link error}, and {@link debug} functions.
|
|
73
|
-
*/
|
|
74
|
-
export declare const logger: Logger;
|
|
75
|
-
/**
|
|
76
|
-
* Writes an informational line through the shared {@link logger}.
|
|
77
|
-
*
|
|
78
|
-
* @param message The message text.
|
|
79
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
80
|
-
*/
|
|
81
|
-
export declare const info: (message: string, ...rest: unknown[]) => void;
|
|
82
|
-
/**
|
|
83
|
-
* Writes a warning line through the shared {@link logger}.
|
|
84
|
-
*
|
|
85
|
-
* @param message The message text.
|
|
86
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
87
|
-
*/
|
|
88
|
-
export declare const warn: (message: string, ...rest: unknown[]) => void;
|
|
89
|
-
/**
|
|
90
|
-
* Writes an error line through the shared {@link logger}.
|
|
91
|
-
*
|
|
92
|
-
* @param message The message text.
|
|
93
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
94
|
-
*/
|
|
95
|
-
export declare const error: (message: string, ...rest: unknown[]) => void;
|
|
96
|
-
/**
|
|
97
|
-
* Writes a debug line through the shared {@link logger} when debug output is enabled.
|
|
98
|
-
*
|
|
99
|
-
* @param message The message text.
|
|
100
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
101
|
-
*/
|
|
102
|
-
export declare const debug: (message: string, ...rest: unknown[]) => void;
|
|
103
|
-
//# sourceMappingURL=log.d.ts.map
|
package/dist/log.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACvB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAC9B,qFAAqF;IACrF,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC/B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IACxB,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,kEAAkE;IAClE,MAAM,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;IAClC,kGAAkG;IAClG,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACtC,CAAC;AA0BF;;;GAGG;AACH,qBAAa,MAAM;IACf,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,MAAM,CAAS;IAEvB;;OAEG;IACH,YAAY,OAAO,GAAE,aAAkB,EAKtC;IAED,OAAO,CAAC,KAAK;IAKb;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAE9C;IAED;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAE9C;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAE/C;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAG/C;CACJ;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,cAAe,MAAM,YAAW,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,KAAQ,MACxD,CAAC;AAE1C;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,MAAqB,CAAC;AAE3C;;;;;GAKG;AACH,eAAO,MAAM,IAAI,YAAa,MAAM,WAAW,OAAO,EAAE,KAAG,IAAqC,CAAC;AAEjG;;;;;GAKG;AACH,eAAO,MAAM,IAAI,YAAa,MAAM,WAAW,OAAO,EAAE,KAAG,IAAqC,CAAC;AAEjG;;;;;GAKG;AACH,eAAO,MAAM,KAAK,YAAa,MAAM,WAAW,OAAO,EAAE,KAAG,IAAsC,CAAC;AAEnG;;;;;GAKG;AACH,eAAO,MAAM,KAAK,YAAa,MAAM,WAAW,OAAO,EAAE,KAAG,IAAsC,CAAC"}
|
package/dist/log.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import pc from "picocolors";
|
|
2
|
-
const BASE_PREFIX = "[gtkx]";
|
|
3
|
-
const colorsFor = (stream) => pc.createColors(pc.isColorSupported && stream.isTTY === true);
|
|
4
|
-
const formatValue = (value) => {
|
|
5
|
-
if (typeof value === "string")
|
|
6
|
-
return value;
|
|
7
|
-
if (value instanceof Error)
|
|
8
|
-
return value.stack ?? value.message;
|
|
9
|
-
try {
|
|
10
|
-
return JSON.stringify(value);
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
return String(value);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const resolveDebugEnabled = (namespace, argv, env) => {
|
|
17
|
-
if (argv.includes("--debug"))
|
|
18
|
-
return true;
|
|
19
|
-
const spec = env.GTKX_DEBUG;
|
|
20
|
-
if (!spec)
|
|
21
|
-
return false;
|
|
22
|
-
const names = spec.split(/[\s,]+/).filter((name) => name.length > 0);
|
|
23
|
-
if (names.includes("1") || names.includes("*"))
|
|
24
|
-
return true;
|
|
25
|
-
return namespace !== undefined && names.includes(namespace);
|
|
26
|
-
};
|
|
27
|
-
const prefixFor = (namespace) => namespace === undefined ? BASE_PREFIX : `[gtkx:${namespace}]`;
|
|
28
|
-
/**
|
|
29
|
-
* Writes prefixed, optionally colored log lines to an output stream, with debug lines gated by
|
|
30
|
-
* command-line and environment configuration.
|
|
31
|
-
*/
|
|
32
|
-
export class Logger {
|
|
33
|
-
stream;
|
|
34
|
-
prefix;
|
|
35
|
-
debugEnabled;
|
|
36
|
-
colors;
|
|
37
|
-
/**
|
|
38
|
-
* @param options Namespace, target stream, and debug configuration for the logger.
|
|
39
|
-
*/
|
|
40
|
-
constructor(options = {}) {
|
|
41
|
-
this.stream = options.stream ?? process.stderr;
|
|
42
|
-
this.prefix = prefixFor(options.namespace);
|
|
43
|
-
this.debugEnabled = options.debugEnabled ?? resolveDebugEnabled(options.namespace, process.argv, process.env);
|
|
44
|
-
this.colors = colorsFor(this.stream);
|
|
45
|
-
}
|
|
46
|
-
write(message, rest) {
|
|
47
|
-
const suffix = rest.length === 0 ? "" : ` ${rest.map(formatValue).join(" ")}`;
|
|
48
|
-
this.stream.write(`${this.prefix} ${message}${suffix}\n`);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Writes an informational line.
|
|
52
|
-
*
|
|
53
|
-
* @param message The message text.
|
|
54
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
55
|
-
*/
|
|
56
|
-
info(message, ...rest) {
|
|
57
|
-
this.write(message, rest);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Writes a line marked as a warning.
|
|
61
|
-
*
|
|
62
|
-
* @param message The message text.
|
|
63
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
64
|
-
*/
|
|
65
|
-
warn(message, ...rest) {
|
|
66
|
-
this.write(`${this.colors.yellow("warn")} ${message}`, rest);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Writes a line marked as an error.
|
|
70
|
-
*
|
|
71
|
-
* @param message The message text.
|
|
72
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
73
|
-
*/
|
|
74
|
-
error(message, ...rest) {
|
|
75
|
-
this.write(`${this.colors.red("error")} ${message}`, rest);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Writes a line only when debug output is enabled for this logger.
|
|
79
|
-
*
|
|
80
|
-
* @param message The message text.
|
|
81
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
82
|
-
*/
|
|
83
|
-
debug(message, ...rest) {
|
|
84
|
-
if (!this.debugEnabled)
|
|
85
|
-
return;
|
|
86
|
-
this.write(message, rest);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Creates a {@link Logger} scoped to the given namespace.
|
|
91
|
-
*
|
|
92
|
-
* @param namespace Namespace added to the log prefix and matched against debug configuration.
|
|
93
|
-
* @param options Further logger options excluding the namespace.
|
|
94
|
-
*/
|
|
95
|
-
export const createLogger = (namespace, options = {}) => new Logger({ ...options, namespace });
|
|
96
|
-
/**
|
|
97
|
-
* The default namespace-less {@link Logger} backing the module-level {@link info}, {@link warn},
|
|
98
|
-
* {@link error}, and {@link debug} functions.
|
|
99
|
-
*/
|
|
100
|
-
export const logger = new Logger();
|
|
101
|
-
/**
|
|
102
|
-
* Writes an informational line through the shared {@link logger}.
|
|
103
|
-
*
|
|
104
|
-
* @param message The message text.
|
|
105
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
106
|
-
*/
|
|
107
|
-
export const info = (message, ...rest) => logger.info(message, ...rest);
|
|
108
|
-
/**
|
|
109
|
-
* Writes a warning line through the shared {@link logger}.
|
|
110
|
-
*
|
|
111
|
-
* @param message The message text.
|
|
112
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
113
|
-
*/
|
|
114
|
-
export const warn = (message, ...rest) => logger.warn(message, ...rest);
|
|
115
|
-
/**
|
|
116
|
-
* Writes an error line through the shared {@link logger}.
|
|
117
|
-
*
|
|
118
|
-
* @param message The message text.
|
|
119
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
120
|
-
*/
|
|
121
|
-
export const error = (message, ...rest) => logger.error(message, ...rest);
|
|
122
|
-
/**
|
|
123
|
-
* Writes a debug line through the shared {@link logger} when debug output is enabled.
|
|
124
|
-
*
|
|
125
|
-
* @param message The message text.
|
|
126
|
-
* @param rest Extra values appended after the message, formatted for display.
|
|
127
|
-
*/
|
|
128
|
-
export const debug = (message, ...rest) => logger.debug(message, ...rest);
|
|
129
|
-
//# sourceMappingURL=log.js.map
|