@gtkx/utils 0.21.0 → 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/README.md +173 -0
- 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 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -5
- 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/process/install-graceful-shutdown.js +89 -0
- 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 +18 -7
- 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 -10
- 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/process/install-graceful-shutdown.ts +126 -0
- 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 -16
- package/dist/class.d.ts.map +0 -1
- package/dist/class.js +0 -2
- package/dist/class.js.map +0 -1
- package/dist/collection.d.ts +0 -58
- package/dist/collection.d.ts.map +0 -1
- package/dist/collection.js +0 -98
- package/dist/collection.js.map +0 -1
- package/dist/error.d.ts +0 -13
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js +0 -13
- package/dist/error.js.map +0 -1
- package/dist/graceful-shutdown.d.ts +0 -70
- package/dist/graceful-shutdown.d.ts.map +0 -1
- package/dist/graceful-shutdown.js +0 -94
- package/dist/graceful-shutdown.js.map +0 -1
- package/dist/source.d.ts +0 -34
- package/dist/source.d.ts.map +0 -1
- package/dist/source.js +0 -99
- package/dist/source.js.map +0 -1
- package/dist/string.d.ts +0 -59
- package/dist/string.d.ts.map +0 -1
- package/dist/string.js +0 -73
- package/dist/string.js.map +0 -1
- package/src/class.ts +0 -17
- package/src/collection.ts +0 -103
- package/src/error.ts +0 -12
- package/src/graceful-shutdown.ts +0 -141
- package/src/source.ts +0 -103
- package/src/string.ts +0 -74
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an underscore- or hyphen-delimited string to Pascal case.
|
|
3
|
+
*
|
|
4
|
+
* Splits only on `_` and `-` and capitalizes each segment's first character, so GObject acronyms
|
|
5
|
+
* are preserved (`pascalCase("GLArea")` stays `"GLArea"`).
|
|
6
|
+
*
|
|
7
|
+
* @param str - The string to convert.
|
|
8
|
+
* @returns The Pascal-cased string.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* pascalCase("icon_name"); // "IconName"
|
|
12
|
+
* pascalCase("scrolled-window"); // "ScrolledWindow"
|
|
13
|
+
*/
|
|
14
|
+
declare function pascalCase(str: string): string;
|
|
15
|
+
export { pascalCase };
|
|
16
|
+
//# sourceMappingURL=pascal-case.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pascal-case.d.ts","sourceRoot":"","sources":["../../src/string/pascal-case.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AACH,iBAAS,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { upperFirst } from "./upper-first.js";
|
|
2
|
+
import { mapWordSegments } from "./word-segments.js";
|
|
3
|
+
/**
|
|
4
|
+
* Converts an underscore- or hyphen-delimited string to Pascal case.
|
|
5
|
+
*
|
|
6
|
+
* Splits only on `_` and `-` and capitalizes each segment's first character, so GObject acronyms
|
|
7
|
+
* are preserved (`pascalCase("GLArea")` stays `"GLArea"`).
|
|
8
|
+
*
|
|
9
|
+
* @param str - The string to convert.
|
|
10
|
+
* @returns The Pascal-cased string.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* pascalCase("icon_name"); // "IconName"
|
|
14
|
+
* pascalCase("scrolled-window"); // "ScrolledWindow"
|
|
15
|
+
*/
|
|
16
|
+
function pascalCase(str) {
|
|
17
|
+
return mapWordSegments(str, upperFirst);
|
|
18
|
+
}
|
|
19
|
+
export { pascalCase };
|
|
20
|
+
//# sourceMappingURL=pascal-case.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pascal-case.js","sourceRoot":"","sources":["../../src/string/pascal-case.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,SAAS,UAAU,CAAC,GAAW;IAC3B,OAAO,eAAe,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;AAC5C,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["import { upperFirst } from \"./upper-first.js\";\nimport { mapWordSegments } from \"./word-segments.js\";\n\n/**\n * Converts an underscore- or hyphen-delimited string to Pascal case.\n *\n * Splits only on `_` and `-` and capitalizes each segment's first character, so GObject acronyms\n * are preserved (`pascalCase(\"GLArea\")` stays `\"GLArea\"`).\n *\n * @param str - The string to convert.\n * @returns The Pascal-cased string.\n *\n * @example\n * pascalCase(\"icon_name\"); // \"IconName\"\n * pascalCase(\"scrolled-window\"); // \"ScrolledWindow\"\n */\nfunction pascalCase(str: string): string {\n return mapWordSegments(str, upperFirst);\n}\n\nexport { pascalCase };\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
declare function upperFirst(str: string): string;
|
|
12
|
+
export { upperFirst };
|
|
13
|
+
//# sourceMappingURL=upper-first.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upper-first.d.ts","sourceRoot":"","sources":["../../src/string/upper-first.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,iBAAS,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -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) {
|
|
12
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
13
|
+
}
|
|
14
|
+
export { upperFirst };
|
|
15
|
+
//# sourceMappingURL=upper-first.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upper-first.js","sourceRoot":"","sources":["../../src/string/upper-first.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,SAAS,UAAU,CAAC,GAAW;IAC3B,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["/**\n * Converts the first character of a string to upper case.\n *\n * @param str - The string to transform.\n * @returns The string with its first character upper-cased.\n *\n * @example\n * upperFirst(\"fred\"); // \"Fred\"\n * upperFirst(\"Fred\"); // \"Fred\"\n */\nfunction upperFirst(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\nexport { upperFirst };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"word-segments.d.ts","sourceRoot":"","sources":["../../src/string/word-segments.ts"],"names":[],"mappings":"AAIA,iBAAS,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAQnG;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function splitWords(input) {
|
|
2
|
+
return input.split(/[_-]/g).filter((part) => part.length > 0);
|
|
3
|
+
}
|
|
4
|
+
function mapWordSegments(input, mapSegment) {
|
|
5
|
+
const parts = splitWords(input);
|
|
6
|
+
if (parts.length === 0) {
|
|
7
|
+
return input;
|
|
8
|
+
}
|
|
9
|
+
return parts.map((part, index) => mapSegment(part, index)).join("");
|
|
10
|
+
}
|
|
11
|
+
export { mapWordSegments };
|
|
12
|
+
//# sourceMappingURL=word-segments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"word-segments.js","sourceRoot":"","sources":["../../src/string/word-segments.ts"],"names":[],"mappings":"AAAA,SAAS,UAAU,CAAC,KAAa;IAC7B,OAAO,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,eAAe,CAAC,KAAa,EAAE,UAAmD;IACvF,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAEhC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxE,CAAC;AAED,OAAO,EAAE,eAAe,EAAE,CAAC","sourcesContent":["function splitWords(input: string): string[] {\n return input.split(/[_-]/g).filter((part) => part.length > 0);\n}\n\nfunction mapWordSegments(input: string, mapSegment: (part: string, index: number) => string): string {\n const parts = splitWords(input);\n\n if (parts.length === 0) {\n return input;\n }\n\n return parts.map((part, index) => mapSegment(part, index)).join(\"\");\n}\n\nexport { mapWordSegments };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export { packageVersion } from \"./package-version.js\";\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the `version` field from the `package.json` next to the calling module.
|
|
3
|
+
*
|
|
4
|
+
* @param importMetaUrl - The caller's `import.meta.url`, used to resolve the sibling `package.json`.
|
|
5
|
+
* @returns The package's version string.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* packageVersion(import.meta.url); // "1.2.3"
|
|
9
|
+
*/
|
|
10
|
+
declare function packageVersion(importMetaUrl: string): string;
|
|
11
|
+
export { packageVersion };
|
|
12
|
+
//# sourceMappingURL=package-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-version.d.ts","sourceRoot":"","sources":["../../src/util/package-version.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,iBAAS,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
/**
|
|
3
|
+
* Reads the `version` field from the `package.json` next to the calling module.
|
|
4
|
+
*
|
|
5
|
+
* @param importMetaUrl - The caller's `import.meta.url`, used to resolve the sibling `package.json`.
|
|
6
|
+
* @returns The package's version string.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* packageVersion(import.meta.url); // "1.2.3"
|
|
10
|
+
*/
|
|
11
|
+
function packageVersion(importMetaUrl) {
|
|
12
|
+
return createRequire(importMetaUrl)("../package.json").version;
|
|
13
|
+
}
|
|
14
|
+
export { packageVersion };
|
|
15
|
+
//# sourceMappingURL=package-version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-version.js","sourceRoot":"","sources":["../../src/util/package-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;;GAQG;AACH,SAAS,cAAc,CAAC,aAAqB;IACzC,OAAQ,aAAa,CAAC,aAAa,CAAC,CAAC,iBAAiB,CAAyB,CAAC,OAAO,CAAC;AAC5F,CAAC;AAED,OAAO,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import { createRequire } from \"node:module\";\n\n/**\n * Reads the `version` field from the `package.json` next to the calling module.\n *\n * @param importMetaUrl - The caller's `import.meta.url`, used to resolve the sibling `package.json`.\n * @returns The package's version string.\n *\n * @example\n * packageVersion(import.meta.url); // \"1.2.3\"\n */\nfunction packageVersion(importMetaUrl: string): string {\n return (createRequire(importMetaUrl)(\"../package.json\") as { version: string }).version;\n}\n\nexport { packageVersion };\n"]}
|
package/package.json
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/utils",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Cross-package utilities shared by GTKX
|
|
3
|
+
"version": "1.0.0-rc.2",
|
|
4
|
+
"description": "Cross-package utilities shared by the GTKX packages and toolchain: logging, error formatting, string and class helpers",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"gtkx",
|
|
7
|
+
"gtk",
|
|
8
|
+
"gtk4",
|
|
9
|
+
"utils",
|
|
10
|
+
"linux",
|
|
11
|
+
"desktop"
|
|
12
|
+
],
|
|
5
13
|
"homepage": "https://gtkx.dev",
|
|
6
14
|
"bugs": {
|
|
7
15
|
"url": "https://github.com/gtkx-org/gtkx/issues"
|
|
8
16
|
},
|
|
9
17
|
"repository": {
|
|
10
18
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/gtkx-org/gtkx.git",
|
|
19
|
+
"url": "git+https://github.com/gtkx-org/gtkx.git",
|
|
12
20
|
"directory": "packages/utils"
|
|
13
21
|
},
|
|
14
22
|
"license": "MPL-2.0",
|
|
@@ -17,7 +25,6 @@
|
|
|
17
25
|
"exports": {
|
|
18
26
|
"./package.json": "./package.json",
|
|
19
27
|
".": {
|
|
20
|
-
"source": "./src/index.ts",
|
|
21
28
|
"types": "./dist/index.d.ts",
|
|
22
29
|
"default": "./dist/index.js"
|
|
23
30
|
}
|
|
@@ -27,9 +34,13 @@
|
|
|
27
34
|
"dist",
|
|
28
35
|
"src"
|
|
29
36
|
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"picocolors": "^1.1.1"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=24"
|
|
42
|
+
},
|
|
30
43
|
"scripts": {
|
|
31
|
-
"
|
|
32
|
-
"test": "vitest run",
|
|
33
|
-
"typecheck": "tsc -b --emitDeclarationOnly"
|
|
44
|
+
"release": "tsx ../../scripts/release-package.ts"
|
|
34
45
|
}
|
|
35
46
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the index of the first item matching `before`, or `list.length` when `before` is `null` or
|
|
3
|
+
* nothing matches. Use it to resolve where a new item should be inserted so it lands before the
|
|
4
|
+
* referenced one, defaulting to the end.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The list item type.
|
|
7
|
+
* @template B - The reference value type.
|
|
8
|
+
* @param list - The list to search.
|
|
9
|
+
* @param before - The item to insert before, or `null` to target the end.
|
|
10
|
+
* @param isMatch - Called with each item and the non-null `before`; return `true` on a match.
|
|
11
|
+
* @returns The matched index, or `list.length`.
|
|
12
|
+
*/
|
|
13
|
+
const indexBeforeOrEnd = <T, B>(
|
|
14
|
+
list: T[],
|
|
15
|
+
before: B | null,
|
|
16
|
+
isMatch: (item: T, before: B) => boolean,
|
|
17
|
+
): number => {
|
|
18
|
+
if (before === null) {
|
|
19
|
+
return list.length;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const index = list.findIndex((item) => isMatch(item, before));
|
|
23
|
+
|
|
24
|
+
return index === -1 ? list.length : index;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { indexBeforeOrEnd };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes the first strictly-equal (`===`) occurrence of `value` from `arr` in place.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of the array elements.
|
|
5
|
+
* @param arr - The array to mutate.
|
|
6
|
+
* @param value - The value to remove.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const items = ["a", "b", "c"];
|
|
10
|
+
* remove(items, "b"); // items is now ["a", "c"]
|
|
11
|
+
*/
|
|
12
|
+
function remove<T>(arr: T[], value: T): void {
|
|
13
|
+
const index = arr.indexOf(value);
|
|
14
|
+
|
|
15
|
+
if (index !== -1) {
|
|
16
|
+
arr.splice(index, 1);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { remove };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the items sorted by a string key using locale-aware comparison.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of items being sorted.
|
|
5
|
+
* @param items - The items to sort.
|
|
6
|
+
* @param key - Maps an item to the string its order is decided by.
|
|
7
|
+
* @returns A new array of the items in ascending locale order of their keys.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* sortStringsBy([{ name: "b" }, { name: "a" }], (item) => item.name);
|
|
11
|
+
* // [{ name: "a" }, { name: "b" }]
|
|
12
|
+
*/
|
|
13
|
+
function sortStringsBy<T>(items: Iterable<T>, key: (item: T) => string): T[] {
|
|
14
|
+
return [...items].toSorted((a, b) => key(a).localeCompare(key(b)));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { sortStringsBy };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the values sorted as strings using locale-aware comparison.
|
|
3
|
+
*
|
|
4
|
+
* @param values - The strings to sort.
|
|
5
|
+
* @returns A new array of the values in ascending locale order.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* sortStrings(["b", "a", "c"]); // ["a", "b", "c"]
|
|
9
|
+
*/
|
|
10
|
+
function sortStrings(values: Iterable<string>): string[] {
|
|
11
|
+
return [...values].toSorted((a, b) => a.localeCompare(b));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { sortStrings };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a new array of the unique elements of `arr`, keyed by the value the `mapper` returns.
|
|
3
|
+
*
|
|
4
|
+
* When two elements map to the same key the first occurrence is kept and later ones discarded,
|
|
5
|
+
* preserving first-seen order.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of elements in the array.
|
|
8
|
+
* @param arr - The array to deduplicate.
|
|
9
|
+
* @param mapper - Maps an element to the key its uniqueness is decided by.
|
|
10
|
+
* @returns A new array containing only the first element seen for each distinct key.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* uniqBy([2.1, 1.2, 2.3], Math.floor); // [2.1, 1.2]
|
|
14
|
+
* uniqBy([{ id: "a" }, { id: "a" }, { id: "b" }], (item) => item.id); // [{ id: "a" }, { id: "b" }]
|
|
15
|
+
*/
|
|
16
|
+
function uniqBy<T>(arr: T[], mapper: (item: T, index: number, array: T[]) => unknown): T[] {
|
|
17
|
+
const seen: Map<unknown, T> = new Map();
|
|
18
|
+
let index = 0;
|
|
19
|
+
|
|
20
|
+
for (const item of arr) {
|
|
21
|
+
const key = mapper(item, index, arr);
|
|
22
|
+
|
|
23
|
+
if (!seen.has(key)) {
|
|
24
|
+
seen.set(key, item);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
index++;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return seen.values().toArray();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { uniqBy };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AnyClass } from "./any-class.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the direct superclass of `cls`, or `null` when it has no class ancestor.
|
|
5
|
+
*
|
|
6
|
+
* @param cls - The class whose prototype parent to inspect.
|
|
7
|
+
* @returns The parent class, or `null` when there is none.
|
|
8
|
+
*/
|
|
9
|
+
function getParentClass(cls: AnyClass): AnyClass | null {
|
|
10
|
+
const parent: unknown = Object.getPrototypeOf(cls);
|
|
11
|
+
|
|
12
|
+
return typeof parent === "function" && parent !== Function.prototype ? (parent as AnyClass) : null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { getParentClass };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AnyClass } from "./any-class.js";
|
|
2
|
+
import { getParentClass } from "./get-parent-class.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Walks the class chain from `cls` up through its ancestors, calling `visit` on each and returning
|
|
6
|
+
* the first result that is not `undefined`.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The type produced by the visitor.
|
|
9
|
+
* @param cls - The class to start from, or `null` to visit nothing.
|
|
10
|
+
* @param visit - Called with each class in the chain; a defined return value stops the walk.
|
|
11
|
+
* @returns The first defined result from `visit`, or `undefined` when none was produced.
|
|
12
|
+
*/
|
|
13
|
+
function walkClassChain<T>(cls: AnyClass | null, visit: (ancestor: AnyClass) => T | undefined): T | undefined {
|
|
14
|
+
let current = cls;
|
|
15
|
+
|
|
16
|
+
while (current !== null) {
|
|
17
|
+
const result = visit(current);
|
|
18
|
+
|
|
19
|
+
if (result !== undefined) {
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
current = getParentClass(current);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { walkClassChain };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isRecord } from "../predicate/is-record.js";
|
|
2
|
+
|
|
3
|
+
function isErrorLike(value: unknown): value is { message: string } {
|
|
4
|
+
return isRecord(value) && "message" in value && typeof value.message === "string";
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function readStream(value: unknown): string {
|
|
8
|
+
if (typeof value === "string") {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (value instanceof Uint8Array || Buffer.isBuffer(value)) {
|
|
13
|
+
return value.toString();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { isErrorLike, readStream };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isErrorLike } from "./error-like.js";
|
|
2
|
+
|
|
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
|
+
* @returns The value's message when it has one, otherwise its string form.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* errorMessage(new Error("boom")); // "boom"
|
|
11
|
+
* errorMessage(42); // "42"
|
|
12
|
+
*/
|
|
13
|
+
function errorMessage(error: unknown): string {
|
|
14
|
+
return Error.isError(error) || isErrorLike(error) ? error.message : String(error);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { errorMessage };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isRecord } from "../predicate/is-record.js";
|
|
2
|
+
import { readStream } from "./error-like.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Combines the `stderr` and `stdout` of a failed child-process error into a single trimmed string.
|
|
6
|
+
*
|
|
7
|
+
* @param error - The child-process error to read output from.
|
|
8
|
+
* @returns The joined output, or `undefined` when neither stream carried any text.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* formatChildProcessError({ stderr: "boom" }); // "boom"
|
|
12
|
+
*/
|
|
13
|
+
function formatChildProcessError(error: unknown): string | undefined {
|
|
14
|
+
if (!isRecord(error)) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const { stderr, stdout } = error;
|
|
19
|
+
const details = [readStream(stderr), readStream(stdout)].filter(Boolean).join("\n").trim();
|
|
20
|
+
|
|
21
|
+
return details.length > 0 ? details : undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { formatChildProcessError };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isErrorLike } from "./error-like.js";
|
|
2
|
+
import { errorMessage } from "./error-message.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Coerces an unknown thrown value into an `Error`, reusing it when it already is one and otherwise
|
|
6
|
+
* wrapping its message while copying any error-like own properties.
|
|
7
|
+
*
|
|
8
|
+
* @param error - The caught value to normalize.
|
|
9
|
+
* @returns The value itself when it is an `Error`, otherwise a new `Error` carrying its message.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* normalizeError("boom"); // Error: boom
|
|
13
|
+
*/
|
|
14
|
+
function normalizeError(error: unknown): Error {
|
|
15
|
+
if (Error.isError(error)) {
|
|
16
|
+
return error;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return Object.assign(new Error(errorMessage(error)), isErrorLike(error) ? error : {});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { normalizeError };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls the named method on `target` with the given arguments, returning `undefined` when the
|
|
3
|
+
* property is missing or not callable.
|
|
4
|
+
*
|
|
5
|
+
* @param target - The object to read the method from and bind as `this`.
|
|
6
|
+
* @param method - The name of the method to look up.
|
|
7
|
+
* @param args - The arguments passed to the method.
|
|
8
|
+
* @returns The method's return value, or `undefined` when it is not a function.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* callMethod(console, "log", ["hi"]); // logs "hi"; returns undefined
|
|
12
|
+
*/
|
|
13
|
+
const isCallable = (value: unknown): value is (this: object, ...args: unknown[]) => unknown =>
|
|
14
|
+
typeof value === "function";
|
|
15
|
+
|
|
16
|
+
function callMethod(target: object, method: string, args: unknown[]): unknown {
|
|
17
|
+
const fn: unknown = Reflect.get(target, method);
|
|
18
|
+
|
|
19
|
+
return isCallable(fn) ? Reflect.apply(fn, target, args) : undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { callMethod };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { callMethod } from "./call-method.js";
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
export
|
|
1
|
+
export * from "./array/index.js";
|
|
2
|
+
export * from "./class/index.js";
|
|
3
|
+
export * from "./error/index.js";
|
|
4
|
+
export * from "./function/index.js";
|
|
5
|
+
export * from "./log/index.js";
|
|
6
|
+
export * from "./map/index.js";
|
|
7
|
+
export * from "./object/index.js";
|
|
8
|
+
export * from "./predicate/index.js";
|
|
9
|
+
export * from "./process/index.js";
|
|
10
|
+
export * from "./set/index.js";
|
|
11
|
+
export * from "./source/index.js";
|
|
12
|
+
export * from "./string/index.js";
|
|
13
|
+
export * from "./util/index.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Logger, type LoggerOptions } from "./logger.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a {@link Logger} scoped to the given namespace.
|
|
5
|
+
*
|
|
6
|
+
* @param namespace - Namespace added to the log prefix and matched against debug configuration.
|
|
7
|
+
* @param options - Further logger options, excluding the namespace.
|
|
8
|
+
* @returns A new namespaced logger.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const log = createLogger("react");
|
|
12
|
+
* log.info("mounted");
|
|
13
|
+
*/
|
|
14
|
+
function createLogger(namespace: string, options: Omit<LoggerOptions, "namespace"> = {}): Logger {
|
|
15
|
+
return new Logger({ ...options, namespace });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { createLogger };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Logger } from "./logger.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The default namespace-less {@link Logger} backing the module-level {@link info}, {@link warn},
|
|
5
|
+
* {@link error}, and {@link debug} functions.
|
|
6
|
+
*/
|
|
7
|
+
const logger: Logger = new Logger();
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Writes an informational line through the shared {@link logger}.
|
|
11
|
+
*
|
|
12
|
+
* @param message - The message text.
|
|
13
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
14
|
+
*/
|
|
15
|
+
function info(message: string, ...rest: unknown[]): void {
|
|
16
|
+
logger.info(message, ...rest);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Writes a warning line through the shared {@link logger}.
|
|
21
|
+
*
|
|
22
|
+
* @param message - The message text.
|
|
23
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
24
|
+
*/
|
|
25
|
+
function warn(message: string, ...rest: unknown[]): void {
|
|
26
|
+
logger.warn(message, ...rest);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Writes an error line through the shared {@link logger}.
|
|
31
|
+
*
|
|
32
|
+
* @param message - The message text.
|
|
33
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
34
|
+
*/
|
|
35
|
+
function error(message: string, ...rest: unknown[]): void {
|
|
36
|
+
logger.error(message, ...rest);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Writes a debug line through the shared {@link logger} when debug output is enabled.
|
|
41
|
+
*
|
|
42
|
+
* @param message - The message text.
|
|
43
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
44
|
+
*/
|
|
45
|
+
function debug(message: string, ...rest: unknown[]): void {
|
|
46
|
+
logger.debug(message, ...rest);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { logger, info, warn, error, debug };
|
package/src/log/index.ts
ADDED