@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 @@
|
|
|
1
|
+
{"version":3,"file":"error-message.js","sourceRoot":"","sources":["../../src/error/error-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;;;;;;;;GASG;AACH,SAAS,YAAY,CAAC,KAAc;IAChC,OAAO,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;AACtF,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { isErrorLike } from \"./error-like.js\";\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 * @returns The value's message when it has one, otherwise its string form.\n *\n * @example\n * errorMessage(new Error(\"boom\")); // \"boom\"\n * errorMessage(42); // \"42\"\n */\nfunction errorMessage(error: unknown): string {\n return Error.isError(error) || isErrorLike(error) ? error.message : String(error);\n}\n\nexport { errorMessage };\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Combines the `stderr` and `stdout` of a failed child-process error into a single trimmed string.
|
|
3
|
+
*
|
|
4
|
+
* @param error - The child-process error to read output from.
|
|
5
|
+
* @returns The joined output, or `undefined` when neither stream carried any text.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* formatChildProcessError({ stderr: "boom" }); // "boom"
|
|
9
|
+
*/
|
|
10
|
+
declare function formatChildProcessError(error: unknown): string | undefined;
|
|
11
|
+
export { formatChildProcessError };
|
|
12
|
+
//# sourceMappingURL=format-child-process-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-child-process-error.d.ts","sourceRoot":"","sources":["../../src/error/format-child-process-error.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,iBAAS,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CASnE;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isRecord } from "../predicate/is-record.js";
|
|
2
|
+
import { readStream } from "./error-like.js";
|
|
3
|
+
/**
|
|
4
|
+
* Combines the `stderr` and `stdout` of a failed child-process error into a single trimmed string.
|
|
5
|
+
*
|
|
6
|
+
* @param error - The child-process error to read output from.
|
|
7
|
+
* @returns The joined output, or `undefined` when neither stream carried any text.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* formatChildProcessError({ stderr: "boom" }); // "boom"
|
|
11
|
+
*/
|
|
12
|
+
function formatChildProcessError(error) {
|
|
13
|
+
if (!isRecord(error)) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const { stderr, stdout } = error;
|
|
17
|
+
const details = [readStream(stderr), readStream(stdout)].filter(Boolean).join("\n").trim();
|
|
18
|
+
return details.length > 0 ? details : undefined;
|
|
19
|
+
}
|
|
20
|
+
export { formatChildProcessError };
|
|
21
|
+
//# sourceMappingURL=format-child-process-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-child-process-error.js","sourceRoot":"","sources":["../../src/error/format-child-process-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;;GAQG;AACH,SAAS,uBAAuB,CAAC,KAAc;IAC3C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACnB,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,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;IAE3F,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AACpD,CAAC;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAC","sourcesContent":["import { isRecord } from \"../predicate/is-record.js\";\nimport { readStream } from \"./error-like.js\";\n\n/**\n * Combines the `stderr` and `stdout` 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 *\n * @example\n * formatChildProcessError({ stderr: \"boom\" }); // \"boom\"\n */\nfunction formatChildProcessError(error: unknown): string | undefined {\n if (!isRecord(error)) {\n return undefined;\n }\n\n const { stderr, stdout } = error;\n const details = [readStream(stderr), readStream(stdout)].filter(Boolean).join(\"\\n\").trim();\n\n return details.length > 0 ? details : undefined;\n}\n\nexport { formatChildProcessError };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export { errorMessage } from \"./error-message.js\";\nexport { formatChildProcessError } from \"./format-child-process-error.js\";\nexport { normalizeError } from \"./normalize-error.js\";\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coerces an unknown thrown value into an `Error`, reusing it when it already is one and otherwise
|
|
3
|
+
* wrapping its message while copying any error-like own properties.
|
|
4
|
+
*
|
|
5
|
+
* @param error - The caught value to normalize.
|
|
6
|
+
* @returns The value itself when it is an `Error`, otherwise a new `Error` carrying its message.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* normalizeError("boom"); // Error: boom
|
|
10
|
+
*/
|
|
11
|
+
declare function normalizeError(error: unknown): Error;
|
|
12
|
+
export { normalizeError };
|
|
13
|
+
//# sourceMappingURL=normalize-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-error.d.ts","sourceRoot":"","sources":["../../src/error/normalize-error.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,iBAAS,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAM7C;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isErrorLike } from "./error-like.js";
|
|
2
|
+
import { errorMessage } from "./error-message.js";
|
|
3
|
+
/**
|
|
4
|
+
* Coerces an unknown thrown value into an `Error`, reusing it when it already is one and otherwise
|
|
5
|
+
* wrapping its message while copying any error-like own properties.
|
|
6
|
+
*
|
|
7
|
+
* @param error - The caught value to normalize.
|
|
8
|
+
* @returns The value itself when it is an `Error`, otherwise a new `Error` carrying its message.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* normalizeError("boom"); // Error: boom
|
|
12
|
+
*/
|
|
13
|
+
function normalizeError(error) {
|
|
14
|
+
if (Error.isError(error)) {
|
|
15
|
+
return error;
|
|
16
|
+
}
|
|
17
|
+
return Object.assign(new Error(errorMessage(error)), isErrorLike(error) ? error : {});
|
|
18
|
+
}
|
|
19
|
+
export { normalizeError };
|
|
20
|
+
//# sourceMappingURL=normalize-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-error.js","sourceRoot":"","sources":["../../src/error/normalize-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;;;;;;;GASG;AACH,SAAS,cAAc,CAAC,KAAc;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,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;AAED,OAAO,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import { isErrorLike } from \"./error-like.js\";\nimport { errorMessage } from \"./error-message.js\";\n\n/**\n * Coerces an unknown thrown value into an `Error`, reusing it when 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 * @returns The value itself when it is an `Error`, otherwise a new `Error` carrying its message.\n *\n * @example\n * normalizeError(\"boom\"); // Error: boom\n */\nfunction normalizeError(error: unknown): Error {\n if (Error.isError(error)) {\n return error;\n }\n\n return Object.assign(new Error(errorMessage(error)), isErrorLike(error) ? error : {});\n}\n\nexport { normalizeError };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-method.d.ts","sourceRoot":"","sources":["../../src/function/call-method.ts"],"names":[],"mappings":"AAeA,iBAAS,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAI5E;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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) => typeof value === "function";
|
|
14
|
+
function callMethod(target, method, args) {
|
|
15
|
+
const fn = Reflect.get(target, method);
|
|
16
|
+
return isCallable(fn) ? Reflect.apply(fn, target, args) : undefined;
|
|
17
|
+
}
|
|
18
|
+
export { callMethod };
|
|
19
|
+
//# sourceMappingURL=call-method.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-method.js","sourceRoot":"","sources":["../../src/function/call-method.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,GAAG,CAAC,KAAc,EAA0D,EAAE,CAC1F,OAAO,KAAK,KAAK,UAAU,CAAC;AAEhC,SAAS,UAAU,CAAC,MAAc,EAAE,MAAc,EAAE,IAAe;IAC/D,MAAM,EAAE,GAAY,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEhD,OAAO,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACxE,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["/**\n * Calls the named method on `target` with the given arguments, returning `undefined` when the\n * property is missing or not callable.\n *\n * @param target - The object to read the method from and bind as `this`.\n * @param method - The name of the method to look up.\n * @param args - The arguments passed to the method.\n * @returns The method's return value, or `undefined` when it is not a function.\n *\n * @example\n * callMethod(console, \"log\", [\"hi\"]); // logs \"hi\"; returns undefined\n */\nconst isCallable = (value: unknown): value is (this: object, ...args: unknown[]) => unknown =>\n typeof value === \"function\";\n\nfunction callMethod(target: object, method: string, args: unknown[]): unknown {\n const fn: unknown = Reflect.get(target, method);\n\n return isCallable(fn) ? Reflect.apply(fn, target, args) : undefined;\n}\n\nexport { callMethod };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/function/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/function/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["export { callMethod } from \"./call-method.js\";\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
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";
|
|
7
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
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";
|
|
6
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC","sourcesContent":["export * from \"./array/index.js\";\nexport * from \"./class/index.js\";\nexport * from \"./error/index.js\";\nexport * from \"./function/index.js\";\nexport * from \"./log/index.js\";\nexport * from \"./map/index.js\";\nexport * from \"./object/index.js\";\nexport * from \"./predicate/index.js\";\nexport * from \"./process/index.js\";\nexport * from \"./set/index.js\";\nexport * from \"./source/index.js\";\nexport * from \"./string/index.js\";\nexport * from \"./util/index.js\";\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Logger, type LoggerOptions } from "./logger.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a {@link Logger} scoped to the given namespace.
|
|
4
|
+
*
|
|
5
|
+
* @param namespace - Namespace added to the log prefix and matched against debug configuration.
|
|
6
|
+
* @param options - Further logger options, excluding the namespace.
|
|
7
|
+
* @returns A new namespaced logger.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const log = createLogger("react");
|
|
11
|
+
* log.info("mounted");
|
|
12
|
+
*/
|
|
13
|
+
declare function createLogger(namespace: string, options?: Omit<LoggerOptions, "namespace">): Logger;
|
|
14
|
+
export { createLogger };
|
|
15
|
+
//# sourceMappingURL=create-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-logger.d.ts","sourceRoot":"","sources":["../../src/log/create-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,iBAAS,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,aAAa,EAAE,WAAW,CAAM,GAAG,MAAM,CAE/F;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Logger } from "./logger.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a {@link Logger} scoped to the given namespace.
|
|
4
|
+
*
|
|
5
|
+
* @param namespace - Namespace added to the log prefix and matched against debug configuration.
|
|
6
|
+
* @param options - Further logger options, excluding the namespace.
|
|
7
|
+
* @returns A new namespaced logger.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const log = createLogger("react");
|
|
11
|
+
* log.info("mounted");
|
|
12
|
+
*/
|
|
13
|
+
function createLogger(namespace, options = {}) {
|
|
14
|
+
return new Logger({ ...options, namespace });
|
|
15
|
+
}
|
|
16
|
+
export { createLogger };
|
|
17
|
+
//# sourceMappingURL=create-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-logger.js","sourceRoot":"","sources":["../../src/log/create-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAsB,MAAM,aAAa,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,SAAS,YAAY,CAAC,SAAiB,EAAE,UAA4C,EAAE;IACnF,OAAO,IAAI,MAAM,CAAC,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;AACjD,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { Logger, type LoggerOptions } from \"./logger.js\";\n\n/**\n * Creates a {@link Logger} scoped to the given namespace.\n *\n * @param namespace - Namespace added to the log prefix and matched against debug configuration.\n * @param options - Further logger options, excluding the namespace.\n * @returns A new namespaced logger.\n *\n * @example\n * const log = createLogger(\"react\");\n * log.info(\"mounted\");\n */\nfunction createLogger(namespace: string, options: Omit<LoggerOptions, \"namespace\"> = {}): Logger {\n return new Logger({ ...options, namespace });\n}\n\nexport { createLogger };\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Logger } from "./logger.js";
|
|
2
|
+
/**
|
|
3
|
+
* The default namespace-less {@link Logger} backing the module-level {@link info}, {@link warn},
|
|
4
|
+
* {@link error}, and {@link debug} functions.
|
|
5
|
+
*/
|
|
6
|
+
declare const logger: Logger;
|
|
7
|
+
/**
|
|
8
|
+
* Writes an informational line through the shared {@link logger}.
|
|
9
|
+
*
|
|
10
|
+
* @param message - The message text.
|
|
11
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
12
|
+
*/
|
|
13
|
+
declare function info(message: string, ...rest: unknown[]): void;
|
|
14
|
+
/**
|
|
15
|
+
* Writes a warning line through the shared {@link logger}.
|
|
16
|
+
*
|
|
17
|
+
* @param message - The message text.
|
|
18
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
19
|
+
*/
|
|
20
|
+
declare function warn(message: string, ...rest: unknown[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Writes an error line through the shared {@link logger}.
|
|
23
|
+
*
|
|
24
|
+
* @param message - The message text.
|
|
25
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
26
|
+
*/
|
|
27
|
+
declare function error(message: string, ...rest: unknown[]): void;
|
|
28
|
+
/**
|
|
29
|
+
* Writes a debug line through the shared {@link logger} when debug output is enabled.
|
|
30
|
+
*
|
|
31
|
+
* @param message - The message text.
|
|
32
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
33
|
+
*/
|
|
34
|
+
declare function debug(message: string, ...rest: unknown[]): void;
|
|
35
|
+
export { logger, info, warn, error, debug };
|
|
36
|
+
//# sourceMappingURL=default-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-logger.d.ts","sourceRoot":"","sources":["../../src/log/default-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;GAGG;AACH,QAAA,MAAM,MAAM,EAAE,MAAqB,CAAC;AAEpC;;;;;GAKG;AACH,iBAAS,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAEvD;AAED;;;;;GAKG;AACH,iBAAS,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAEvD;AAED;;;;;GAKG;AACH,iBAAS,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAExD;AAED;;;;;GAKG;AACH,iBAAS,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAExD;AAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Logger } from "./logger.js";
|
|
2
|
+
/**
|
|
3
|
+
* The default namespace-less {@link Logger} backing the module-level {@link info}, {@link warn},
|
|
4
|
+
* {@link error}, and {@link debug} functions.
|
|
5
|
+
*/
|
|
6
|
+
const logger = new Logger();
|
|
7
|
+
/**
|
|
8
|
+
* Writes an informational line through the shared {@link logger}.
|
|
9
|
+
*
|
|
10
|
+
* @param message - The message text.
|
|
11
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
12
|
+
*/
|
|
13
|
+
function info(message, ...rest) {
|
|
14
|
+
logger.info(message, ...rest);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Writes a warning line through the shared {@link logger}.
|
|
18
|
+
*
|
|
19
|
+
* @param message - The message text.
|
|
20
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
21
|
+
*/
|
|
22
|
+
function warn(message, ...rest) {
|
|
23
|
+
logger.warn(message, ...rest);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Writes an error line through the shared {@link logger}.
|
|
27
|
+
*
|
|
28
|
+
* @param message - The message text.
|
|
29
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
30
|
+
*/
|
|
31
|
+
function error(message, ...rest) {
|
|
32
|
+
logger.error(message, ...rest);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Writes a debug line through the shared {@link logger} when debug output is enabled.
|
|
36
|
+
*
|
|
37
|
+
* @param message - The message text.
|
|
38
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
39
|
+
*/
|
|
40
|
+
function debug(message, ...rest) {
|
|
41
|
+
logger.debug(message, ...rest);
|
|
42
|
+
}
|
|
43
|
+
export { logger, info, warn, error, debug };
|
|
44
|
+
//# sourceMappingURL=default-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-logger.js","sourceRoot":"","sources":["../../src/log/default-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;GAGG;AACH,MAAM,MAAM,GAAW,IAAI,MAAM,EAAE,CAAC;AAEpC;;;;;GAKG;AACH,SAAS,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;IAC7C,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;AAClC,CAAC;AAED;;;;;GAKG;AACH,SAAS,IAAI,CAAC,OAAe,EAAE,GAAG,IAAe;IAC7C,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;AAClC,CAAC;AAED;;;;;GAKG;AACH,SAAS,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;IAC9C,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;AACnC,CAAC;AAED;;;;;GAKG;AACH,SAAS,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;IAC9C,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;AACnC,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC","sourcesContent":["import { Logger } from \"./logger.js\";\n\n/**\n * The default namespace-less {@link Logger} backing the module-level {@link info}, {@link warn},\n * {@link error}, and {@link debug} functions.\n */\nconst logger: Logger = new Logger();\n\n/**\n * Writes an informational line through the shared {@link logger}.\n *\n * @param message - The message text.\n * @param rest - Extra values appended after the message, formatted for display.\n */\nfunction info(message: string, ...rest: unknown[]): void {\n logger.info(message, ...rest);\n}\n\n/**\n * Writes a warning line through the shared {@link logger}.\n *\n * @param message - The message text.\n * @param rest - Extra values appended after the message, formatted for display.\n */\nfunction warn(message: string, ...rest: unknown[]): void {\n logger.warn(message, ...rest);\n}\n\n/**\n * Writes an error line through the shared {@link logger}.\n *\n * @param message - The message text.\n * @param rest - Extra values appended after the message, formatted for display.\n */\nfunction error(message: string, ...rest: unknown[]): void {\n logger.error(message, ...rest);\n}\n\n/**\n * Writes a debug line through the shared {@link logger} when debug output is enabled.\n *\n * @param message - The message text.\n * @param rest - Extra values appended after the message, formatted for display.\n */\nfunction debug(message: string, ...rest: unknown[]): void {\n logger.debug(message, ...rest);\n}\n\nexport { logger, info, warn, error, debug };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/log/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/log/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,MAAM,EAAyC,MAAM,aAAa,CAAC","sourcesContent":["export { createLogger } from \"./create-logger.js\";\nexport { debug, error, info, logger, warn } from \"./default-logger.js\";\nexport { Logger, type LoggerOptions, type OutputStream } from \"./logger.js\";\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal writable-stream shape a {@link Logger} writes formatted lines to.
|
|
3
|
+
*/
|
|
4
|
+
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
|
+
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
|
+
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
|
+
export { Logger, type OutputStream, type LoggerOptions };
|
|
64
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/log/logger.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,KAAK,YAAY,GAAG;IAChB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAC9B,qFAAqF;IACrF,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC/B,CAAC;AAEF;;GAEG;AACH,KAAK,aAAa,GAAG;IACjB,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;AAgDF;;;GAGG;AACH,cAAM,MAAM;IACR,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,MAAM,CAAS;IAEvB;;OAEG;gBACS,OAAO,GAAE,aAAkB;IAOvC,OAAO,CAAC,KAAK;IAKb;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI/C;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI/C;;;;;OAKG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIhD;;;;;OAKG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;CAOnD;AAED,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
const BASE_PREFIX = "[gtkx]";
|
|
3
|
+
function getColors(stream) {
|
|
4
|
+
return pc.createColors(pc.isColorSupported && stream.isTTY === true);
|
|
5
|
+
}
|
|
6
|
+
function formatValue(value) {
|
|
7
|
+
if (typeof value === "string") {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
if (value instanceof Error) {
|
|
11
|
+
return value.stack ?? value.message;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
return JSON.stringify(value);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return String(value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function isDebugEnabled(namespace, argv, env) {
|
|
21
|
+
if (argv.includes("--debug")) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const spec = env.GTKX_DEBUG;
|
|
25
|
+
if (!spec) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const names = new Set(spec.split(/[\s,]+/).filter((name) => name.length > 0));
|
|
29
|
+
if (names.has("1") || names.has("*")) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return namespace !== undefined && names.has(namespace);
|
|
33
|
+
}
|
|
34
|
+
function getPrefix(namespace) {
|
|
35
|
+
return namespace === undefined ? BASE_PREFIX : `[gtkx:${namespace}]`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Writes prefixed, optionally colored log lines to an output stream, with debug lines gated by
|
|
39
|
+
* command-line and environment configuration.
|
|
40
|
+
*/
|
|
41
|
+
class Logger {
|
|
42
|
+
stream;
|
|
43
|
+
prefix;
|
|
44
|
+
debugEnabled;
|
|
45
|
+
colors;
|
|
46
|
+
/**
|
|
47
|
+
* @param options - Namespace, target stream, and debug configuration for the logger.
|
|
48
|
+
*/
|
|
49
|
+
constructor(options = {}) {
|
|
50
|
+
this.stream = options.stream ?? process.stderr;
|
|
51
|
+
this.prefix = getPrefix(options.namespace);
|
|
52
|
+
this.debugEnabled = options.debugEnabled ?? isDebugEnabled(options.namespace, process.argv, process.env);
|
|
53
|
+
this.colors = getColors(this.stream);
|
|
54
|
+
}
|
|
55
|
+
write(message, rest) {
|
|
56
|
+
const suffix = rest.length === 0 ? "" : ` ${rest.map((value) => formatValue(value)).join(" ")}`;
|
|
57
|
+
this.stream.write(`${this.prefix} ${message}${suffix}\n`);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Writes an informational line.
|
|
61
|
+
*
|
|
62
|
+
* @param message - The message text.
|
|
63
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
64
|
+
*/
|
|
65
|
+
info(message, ...rest) {
|
|
66
|
+
this.write(message, rest);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Writes a line marked as a warning.
|
|
70
|
+
*
|
|
71
|
+
* @param message - The message text.
|
|
72
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
73
|
+
*/
|
|
74
|
+
warn(message, ...rest) {
|
|
75
|
+
this.write(`${this.colors.yellow("warn")} ${message}`, rest);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Writes a line marked as an error.
|
|
79
|
+
*
|
|
80
|
+
* @param message - The message text.
|
|
81
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
82
|
+
*/
|
|
83
|
+
error(message, ...rest) {
|
|
84
|
+
this.write(`${this.colors.red("error")} ${message}`, rest);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Writes a line only when debug output is enabled for this logger.
|
|
88
|
+
*
|
|
89
|
+
* @param message - The message text.
|
|
90
|
+
* @param rest - Extra values appended after the message, formatted for display.
|
|
91
|
+
*/
|
|
92
|
+
debug(message, ...rest) {
|
|
93
|
+
if (!this.debugEnabled) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
this.write(message, rest);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export { Logger };
|
|
100
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/log/logger.ts"],"names":[],"mappings":"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","sourcesContent":["import pc from \"picocolors\";\n\ntype Colors = ReturnType<typeof pc.createColors>;\n\n/**\n * Minimal writable-stream shape a {@link Logger} writes formatted lines to.\n */\ntype OutputStream = {\n write(chunk: string): unknown;\n /** Whether the stream is a terminal, used to decide if colored output is emitted. */\n isTTY?: boolean | undefined;\n};\n\n/**\n * Options for constructing a {@link Logger}.\n */\ntype LoggerOptions = {\n /** Namespace appended to the log prefix and matched against debug configuration. */\n namespace?: string | undefined;\n /** Stream to write log lines to; defaults to `process.stderr`. */\n stream?: OutputStream | undefined;\n /** Forces debug output on or off; when omitted it is resolved from `--debug` and `GTKX_DEBUG`. */\n debugEnabled?: boolean | undefined;\n};\n\nconst BASE_PREFIX = \"[gtkx]\";\n\nfunction getColors(stream: OutputStream): Colors {\n return pc.createColors(pc.isColorSupported && stream.isTTY === true);\n}\n\nfunction formatValue(value: unknown): string {\n if (typeof value === \"string\") {\n return value;\n }\n\n if (value instanceof Error) {\n return value.stack ?? value.message;\n }\n\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n}\n\nfunction isDebugEnabled(namespace: string | undefined, argv: string[], env: NodeJS.ProcessEnv): boolean {\n if (argv.includes(\"--debug\")) {\n return true;\n }\n\n const spec = env.GTKX_DEBUG;\n\n if (!spec) {\n return false;\n }\n\n const names = new Set(spec.split(/[\\s,]+/).filter((name) => name.length > 0));\n\n if (names.has(\"1\") || names.has(\"*\")) {\n return true;\n }\n\n return namespace !== undefined && names.has(namespace);\n}\n\nfunction getPrefix(namespace: string | undefined): string {\n return namespace === undefined ? BASE_PREFIX : `[gtkx:${namespace}]`;\n}\n\n/**\n * Writes prefixed, optionally colored log lines to an output stream, with debug lines gated by\n * command-line and environment configuration.\n */\nclass Logger {\n private stream: OutputStream;\n private prefix: string;\n private debugEnabled: boolean;\n private colors: Colors;\n\n /**\n * @param options - Namespace, target stream, and debug configuration for the logger.\n */\n constructor(options: LoggerOptions = {}) {\n this.stream = options.stream ?? process.stderr;\n this.prefix = getPrefix(options.namespace);\n this.debugEnabled = options.debugEnabled ?? isDebugEnabled(options.namespace, process.argv, process.env);\n this.colors = getColors(this.stream);\n }\n\n private write(message: string, rest: unknown[]): void {\n const suffix = rest.length === 0 ? \"\" : ` ${rest.map((value) => formatValue(value)).join(\" \")}`;\n this.stream.write(`${this.prefix} ${message}${suffix}\\n`);\n }\n\n /**\n * Writes an informational line.\n *\n * @param message - The message text.\n * @param rest - Extra values appended after the message, formatted for display.\n */\n info(message: string, ...rest: unknown[]): void {\n this.write(message, rest);\n }\n\n /**\n * Writes a line marked as a warning.\n *\n * @param message - The message text.\n * @param rest - Extra values appended after the message, formatted for display.\n */\n warn(message: string, ...rest: unknown[]): void {\n this.write(`${this.colors.yellow(\"warn\")} ${message}`, rest);\n }\n\n /**\n * Writes a line marked as an error.\n *\n * @param message - The message text.\n * @param rest - Extra values appended after the message, formatted for display.\n */\n error(message: string, ...rest: unknown[]): void {\n this.write(`${this.colors.red(\"error\")} ${message}`, rest);\n }\n\n /**\n * Writes a line only when debug output is enabled for this logger.\n *\n * @param message - The message text.\n * @param rest - Extra values appended after the message, formatted for display.\n */\n debug(message: string, ...rest: unknown[]): void {\n if (!this.debugEnabled) {\n return;\n }\n\n this.write(message, rest);\n }\n}\n\nexport { Logger, type OutputStream, type LoggerOptions };\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type GetSet<K, V> = {
|
|
2
|
+
get(key: K): V | undefined;
|
|
3
|
+
set(key: K, value: V): unknown;
|
|
4
|
+
has(key: K): boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Returns the value stored under `key`, or inserts and returns the value produced by `factory` when
|
|
8
|
+
* the key is absent. Works with both `Map` and `WeakMap`, and caches a computed `undefined` value.
|
|
9
|
+
*
|
|
10
|
+
* @template K - The key type.
|
|
11
|
+
* @template V - The value type.
|
|
12
|
+
* @param map - The `Map` or `WeakMap` to read from and populate.
|
|
13
|
+
* @param key - The key to look up.
|
|
14
|
+
* @param factory - Produces the value to insert when `key` is absent; called at most once.
|
|
15
|
+
* @returns The existing or newly-inserted value.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const counts = new Map<string, number[]>();
|
|
19
|
+
* getOrInsert(counts, "a", () => []).push(1); // counts is Map { "a" => [1] }
|
|
20
|
+
*/
|
|
21
|
+
declare function getOrInsert<K, V>(map: GetSet<K, V>, key: K, factory: (key: K) => V): V;
|
|
22
|
+
export { getOrInsert, type GetSet };
|
|
23
|
+
//# sourceMappingURL=get-or-insert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-or-insert.d.ts","sourceRoot":"","sources":["../../src/map/get-or-insert.ts"],"names":[],"mappings":"AAAA,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI;IAChB,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAC3B,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC;IAC/B,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,iBAAS,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAS/E;AAED,OAAO,EAAE,WAAW,EAAE,KAAK,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the value stored under `key`, or inserts and returns the value produced by `factory` when
|
|
3
|
+
* the key is absent. Works with both `Map` and `WeakMap`, and caches a computed `undefined` value.
|
|
4
|
+
*
|
|
5
|
+
* @template K - The key type.
|
|
6
|
+
* @template V - The value type.
|
|
7
|
+
* @param map - The `Map` or `WeakMap` to read from and populate.
|
|
8
|
+
* @param key - The key to look up.
|
|
9
|
+
* @param factory - Produces the value to insert when `key` is absent; called at most once.
|
|
10
|
+
* @returns The existing or newly-inserted value.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const counts = new Map<string, number[]>();
|
|
14
|
+
* getOrInsert(counts, "a", () => []).push(1); // counts is Map { "a" => [1] }
|
|
15
|
+
*/
|
|
16
|
+
function getOrInsert(map, key, factory) {
|
|
17
|
+
if (map.has(key)) {
|
|
18
|
+
return map.get(key);
|
|
19
|
+
}
|
|
20
|
+
const value = factory(key);
|
|
21
|
+
map.set(key, value);
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
export { getOrInsert };
|
|
25
|
+
//# sourceMappingURL=get-or-insert.js.map
|