@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
|
+
type GracefulShutdownOptions = {
|
|
2
|
+
onSignal: (signal: NodeJS.Signals) => void | Promise<void>;
|
|
3
|
+
onForce?: () => void;
|
|
4
|
+
forceKillAfterMs?: number;
|
|
5
|
+
coalesceWindowMs?: number;
|
|
6
|
+
exitCode?: (signal: NodeJS.Signals, isGraceful: boolean) => number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Registers handlers for `SIGINT`, `SIGTERM`, and `SIGHUP` that run the given cleanup callback once
|
|
10
|
+
* and then exit, forcing exit if a repeated signal arrives or the cleanup exceeds its timeout.
|
|
11
|
+
*
|
|
12
|
+
* @param options - The shutdown callbacks and timing configuration.
|
|
13
|
+
*/
|
|
14
|
+
declare function installGracefulShutdown(options: GracefulShutdownOptions): void;
|
|
15
|
+
export { installGracefulShutdown, type GracefulShutdownOptions };
|
|
16
|
+
//# sourceMappingURL=install-graceful-shutdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install-graceful-shutdown.d.ts","sourceRoot":"","sources":["../../src/process/install-graceful-shutdown.ts"],"names":[],"mappings":"AAGA,KAAK,uBAAuB,GAAG;IAC3B,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,KAAK,MAAM,CAAC;CACtE,CAAC;AA2FF;;;;;GAKG;AACH,iBAAS,uBAAuB,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAiBvE;AAED,OAAO,EAAE,uBAAuB,EAAE,KAAK,uBAAuB,EAAE,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { error } from "../log/default-logger.js";
|
|
2
|
+
import { exitCodeForSignal } from "./exit-code-for-signal.js";
|
|
3
|
+
const HANDLED_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
4
|
+
const DEFAULT_FORCE_KILL_TIMEOUT_MS = 5000;
|
|
5
|
+
const DEFAULT_COALESCE_WINDOW_MS = 500;
|
|
6
|
+
const clearTimers = (state) => {
|
|
7
|
+
if (state.forceTimer) {
|
|
8
|
+
clearTimeout(state.forceTimer);
|
|
9
|
+
state.forceTimer = null;
|
|
10
|
+
}
|
|
11
|
+
if (state.coalesceTimer) {
|
|
12
|
+
clearTimeout(state.coalesceTimer);
|
|
13
|
+
state.coalesceTimer = null;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const finish = (state, signal, isGraceful) => {
|
|
17
|
+
if (state.exited) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
state.exited = true;
|
|
21
|
+
clearTimers(state);
|
|
22
|
+
const { exitCode } = state.options;
|
|
23
|
+
const defaultCode = isGraceful ? 0 : exitCodeForSignal(signal);
|
|
24
|
+
process.exit(exitCode ? exitCode(signal, isGraceful) : defaultCode);
|
|
25
|
+
};
|
|
26
|
+
const runShutdown = async (state, signal) => {
|
|
27
|
+
try {
|
|
28
|
+
await state.options.onSignal(signal);
|
|
29
|
+
finish(state, signal, true);
|
|
30
|
+
}
|
|
31
|
+
catch (error_) {
|
|
32
|
+
error("graceful shutdown failed", error_);
|
|
33
|
+
finish(state, signal, false);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const beginShutdown = (state, signal) => {
|
|
37
|
+
state.firstSignal = signal;
|
|
38
|
+
if (state.coalesceWindowMs > 0) {
|
|
39
|
+
state.coalescing = true;
|
|
40
|
+
state.coalesceTimer = setTimeout(() => {
|
|
41
|
+
state.coalescing = false;
|
|
42
|
+
}, state.coalesceWindowMs);
|
|
43
|
+
state.coalesceTimer.unref();
|
|
44
|
+
}
|
|
45
|
+
if (state.options.onForce && state.forceKillMs > 0) {
|
|
46
|
+
state.forceTimer = setTimeout(() => {
|
|
47
|
+
state.options.onForce?.();
|
|
48
|
+
finish(state, signal, false);
|
|
49
|
+
}, state.forceKillMs);
|
|
50
|
+
state.forceTimer.unref();
|
|
51
|
+
}
|
|
52
|
+
void runShutdown(state, signal);
|
|
53
|
+
};
|
|
54
|
+
const handle = (state, signal) => {
|
|
55
|
+
if (state.firstSignal === null) {
|
|
56
|
+
beginShutdown(state, signal);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (state.coalescing) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
state.options.onForce?.();
|
|
63
|
+
finish(state, signal, false);
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Registers handlers for `SIGINT`, `SIGTERM`, and `SIGHUP` that run the given cleanup callback once
|
|
67
|
+
* and then exit, forcing exit if a repeated signal arrives or the cleanup exceeds its timeout.
|
|
68
|
+
*
|
|
69
|
+
* @param options - The shutdown callbacks and timing configuration.
|
|
70
|
+
*/
|
|
71
|
+
function installGracefulShutdown(options) {
|
|
72
|
+
const state = {
|
|
73
|
+
options,
|
|
74
|
+
forceKillMs: options.forceKillAfterMs ?? DEFAULT_FORCE_KILL_TIMEOUT_MS,
|
|
75
|
+
coalesceWindowMs: options.coalesceWindowMs ?? DEFAULT_COALESCE_WINDOW_MS,
|
|
76
|
+
firstSignal: null,
|
|
77
|
+
exited: false,
|
|
78
|
+
coalescing: false,
|
|
79
|
+
forceTimer: null,
|
|
80
|
+
coalesceTimer: null,
|
|
81
|
+
};
|
|
82
|
+
for (const sig of HANDLED_SIGNALS) {
|
|
83
|
+
process.on(sig, () => {
|
|
84
|
+
handle(state, sig);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export { installGracefulShutdown };
|
|
89
|
+
//# sourceMappingURL=install-graceful-shutdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install-graceful-shutdown.js","sourceRoot":"","sources":["../../src/process/install-graceful-shutdown.ts"],"names":[],"mappings":"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","sourcesContent":["import { error } from \"../log/default-logger.js\";\nimport { exitCodeForSignal } from \"./exit-code-for-signal.js\";\n\ntype GracefulShutdownOptions = {\n onSignal: (signal: NodeJS.Signals) => void | Promise<void>;\n onForce?: () => void;\n forceKillAfterMs?: number;\n coalesceWindowMs?: number;\n exitCode?: (signal: NodeJS.Signals, isGraceful: boolean) => number;\n};\n\ntype ShutdownState = {\n options: GracefulShutdownOptions;\n forceKillMs: number;\n coalesceWindowMs: number;\n firstSignal: NodeJS.Signals | null;\n exited: boolean;\n coalescing: boolean;\n forceTimer: NodeJS.Timeout | null;\n coalesceTimer: NodeJS.Timeout | null;\n};\n\nconst HANDLED_SIGNALS = [\"SIGINT\", \"SIGTERM\", \"SIGHUP\"] as const satisfies NodeJS.Signals[];\nconst DEFAULT_FORCE_KILL_TIMEOUT_MS = 5000;\nconst DEFAULT_COALESCE_WINDOW_MS = 500;\n\nconst clearTimers = (state: ShutdownState): void => {\n if (state.forceTimer) {\n clearTimeout(state.forceTimer);\n state.forceTimer = null;\n }\n\n if (state.coalesceTimer) {\n clearTimeout(state.coalesceTimer);\n state.coalesceTimer = null;\n }\n};\n\nconst finish = (state: ShutdownState, signal: NodeJS.Signals, isGraceful: boolean): void => {\n if (state.exited) {\n return;\n }\n\n state.exited = true;\n clearTimers(state);\n const { exitCode } = state.options;\n const defaultCode = isGraceful ? 0 : exitCodeForSignal(signal);\n process.exit(exitCode ? exitCode(signal, isGraceful) : defaultCode);\n};\n\nconst runShutdown = async (state: ShutdownState, signal: NodeJS.Signals): Promise<void> => {\n try {\n await state.options.onSignal(signal);\n finish(state, signal, true);\n } catch (error_) {\n error(\"graceful shutdown failed\", error_);\n finish(state, signal, false);\n }\n};\n\nconst beginShutdown = (state: ShutdownState, signal: NodeJS.Signals): void => {\n state.firstSignal = signal;\n\n if (state.coalesceWindowMs > 0) {\n state.coalescing = true;\n\n state.coalesceTimer = setTimeout(() => {\n state.coalescing = false;\n }, state.coalesceWindowMs);\n\n state.coalesceTimer.unref();\n }\n\n if (state.options.onForce && state.forceKillMs > 0) {\n state.forceTimer = setTimeout(() => {\n state.options.onForce?.();\n finish(state, signal, false);\n }, state.forceKillMs);\n\n state.forceTimer.unref();\n }\n\n void runShutdown(state, signal);\n};\n\nconst handle = (state: ShutdownState, signal: NodeJS.Signals): void => {\n if (state.firstSignal === null) {\n beginShutdown(state, signal);\n\n return;\n }\n\n if (state.coalescing) {\n return;\n }\n\n state.options.onForce?.();\n finish(state, signal, false);\n};\n\n/**\n * Registers handlers for `SIGINT`, `SIGTERM`, and `SIGHUP` that run the given cleanup callback once\n * and then exit, forcing exit if a repeated signal arrives or the cleanup exceeds its timeout.\n *\n * @param options - The shutdown callbacks and timing configuration.\n */\nfunction installGracefulShutdown(options: GracefulShutdownOptions): void {\n const state: ShutdownState = {\n options,\n forceKillMs: options.forceKillAfterMs ?? DEFAULT_FORCE_KILL_TIMEOUT_MS,\n coalesceWindowMs: options.coalesceWindowMs ?? DEFAULT_COALESCE_WINDOW_MS,\n firstSignal: null,\n exited: false,\n coalescing: false,\n forceTimer: null,\n coalesceTimer: null,\n };\n\n for (const sig of HANDLED_SIGNALS) {\n process.on(sig, () => {\n handle(state, sig);\n });\n }\n}\n\nexport { installGracefulShutdown, type GracefulShutdownOptions };\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves an executable to an absolute path, searching `PATH` only for a bare command name, so
|
|
3
|
+
* spawning it never re-runs a lookup against a `PATH` that may have changed.
|
|
4
|
+
*
|
|
5
|
+
* @param command - An executable name, or a path to one.
|
|
6
|
+
* @returns The absolute path of the executable.
|
|
7
|
+
* @throws When a bare command name is not found on `PATH`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* resolveExecutable("weston"); // "/usr/bin/weston"
|
|
11
|
+
*/
|
|
12
|
+
declare function resolveExecutable(command: string): string;
|
|
13
|
+
export { resolveExecutable };
|
|
14
|
+
//# sourceMappingURL=resolve-executable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-executable.d.ts","sourceRoot":"","sources":["../../src/process/resolve-executable.ts"],"names":[],"mappings":"AA2BA;;;;;;;;;;GAUG;AACH,iBAAS,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAgBlD;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { accessSync, constants } from "node:fs";
|
|
2
|
+
import { delimiter, isAbsolute, join, resolve } from "node:path";
|
|
3
|
+
const isExecutable = (path) => {
|
|
4
|
+
try {
|
|
5
|
+
accessSync(path, constants.X_OK);
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const findOnPath = (command) => {
|
|
13
|
+
const searchPaths = (process.env.PATH ?? "").split(delimiter).filter((entry) => entry.length > 0);
|
|
14
|
+
for (const directory of searchPaths) {
|
|
15
|
+
const candidate = join(directory, command);
|
|
16
|
+
if (isExecutable(candidate)) {
|
|
17
|
+
return candidate;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Resolves an executable to an absolute path, searching `PATH` only for a bare command name, so
|
|
24
|
+
* spawning it never re-runs a lookup against a `PATH` that may have changed.
|
|
25
|
+
*
|
|
26
|
+
* @param command - An executable name, or a path to one.
|
|
27
|
+
* @returns The absolute path of the executable.
|
|
28
|
+
* @throws When a bare command name is not found on `PATH`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* resolveExecutable("weston"); // "/usr/bin/weston"
|
|
32
|
+
*/
|
|
33
|
+
function resolveExecutable(command) {
|
|
34
|
+
if (isAbsolute(command)) {
|
|
35
|
+
return command;
|
|
36
|
+
}
|
|
37
|
+
if (command.includes("/")) {
|
|
38
|
+
return resolve(command);
|
|
39
|
+
}
|
|
40
|
+
const found = findOnPath(command);
|
|
41
|
+
if (found === undefined) {
|
|
42
|
+
throw new Error(`Cannot find the "${command}" executable on PATH`);
|
|
43
|
+
}
|
|
44
|
+
return found;
|
|
45
|
+
}
|
|
46
|
+
export { resolveExecutable };
|
|
47
|
+
//# sourceMappingURL=resolve-executable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-executable.js","sourceRoot":"","sources":["../../src/process/resolve-executable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEjE,MAAM,YAAY,GAAG,CAAC,IAAY,EAAW,EAAE;IAC3C,IAAI,CAAC;QACD,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QAEjC,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,OAAe,EAAsB,EAAE;IACvD,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAElG,KAAK,MAAM,SAAS,IAAI,WAAW,EAAE,CAAC;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAE3C,IAAI,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC;YAC1B,OAAO,SAAS,CAAC;QACrB,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,SAAS,iBAAiB,CAAC,OAAe;IACtC,IAAI,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACtB,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAElC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,oBAAoB,OAAO,sBAAsB,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import { accessSync, constants } from \"node:fs\";\nimport { delimiter, isAbsolute, join, resolve } from \"node:path\";\n\nconst isExecutable = (path: string): boolean => {\n try {\n accessSync(path, constants.X_OK);\n\n return true;\n } catch {\n return false;\n }\n};\n\nconst findOnPath = (command: string): string | undefined => {\n const searchPaths = (process.env.PATH ?? \"\").split(delimiter).filter((entry) => entry.length > 0);\n\n for (const directory of searchPaths) {\n const candidate = join(directory, command);\n\n if (isExecutable(candidate)) {\n return candidate;\n }\n }\n\n return undefined;\n};\n\n/**\n * Resolves an executable to an absolute path, searching `PATH` only for a bare command name, so\n * spawning it never re-runs a lookup against a `PATH` that may have changed.\n *\n * @param command - An executable name, or a path to one.\n * @returns The absolute path of the executable.\n * @throws When a bare command name is not found on `PATH`.\n *\n * @example\n * resolveExecutable(\"weston\"); // \"/usr/bin/weston\"\n */\nfunction resolveExecutable(command: string): string {\n if (isAbsolute(command)) {\n return command;\n }\n\n if (command.includes(\"/\")) {\n return resolve(command);\n }\n\n const found = findOnPath(command);\n\n if (found === undefined) {\n throw new Error(`Cannot find the \"${command}\" executable on PATH`);\n }\n\n return found;\n}\n\nexport { resolveExecutable };\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterates every item currently in `set`, then clears it. Use it to drain a set of pending work
|
|
3
|
+
* accumulated since the last drain.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The set item type.
|
|
6
|
+
* @param set - The set to drain and clear.
|
|
7
|
+
* @param visit - Called with each item before the set is cleared.
|
|
8
|
+
*/
|
|
9
|
+
declare const drain: <T>(set: Set<T>, visit: (item: T) => void) => void;
|
|
10
|
+
export { drain };
|
|
11
|
+
//# sourceMappingURL=drain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drain.d.ts","sourceRoot":"","sources":["../../src/set/drain.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,QAAA,MAAM,KAAK,GAAI,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,KAAG,IAMzD,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterates every item currently in `set`, then clears it. Use it to drain a set of pending work
|
|
3
|
+
* accumulated since the last drain.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The set item type.
|
|
6
|
+
* @param set - The set to drain and clear.
|
|
7
|
+
* @param visit - Called with each item before the set is cleared.
|
|
8
|
+
*/
|
|
9
|
+
const drain = (set, visit) => {
|
|
10
|
+
for (const item of set) {
|
|
11
|
+
visit(item);
|
|
12
|
+
}
|
|
13
|
+
set.clear();
|
|
14
|
+
};
|
|
15
|
+
export { drain };
|
|
16
|
+
//# sourceMappingURL=drain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drain.js","sourceRoot":"","sources":["../../src/set/drain.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,KAAK,GAAG,CAAI,GAAW,EAAE,KAAwB,EAAQ,EAAE;IAC7D,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE,CAAC;QACrB,KAAK,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAED,GAAG,CAAC,KAAK,EAAE,CAAC;AAChB,CAAC,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC","sourcesContent":["/**\n * Iterates every item currently in `set`, then clears it. Use it to drain a set of pending work\n * accumulated since the last drain.\n *\n * @template T - The set item type.\n * @param set - The set to drain and clear.\n * @param visit - Called with each item before the set is cleared.\n */\nconst drain = <T>(set: Set<T>, visit: (item: T) => void): void => {\n for (const item of set) {\n visit(item);\n }\n\n set.clear();\n};\n\nexport { drain };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/set/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/set/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { drain } from \"./drain.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/source/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/source/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["export { sanitizeIdentifier } from \"./sanitize-identifier.js\";\nexport { sourceStringLiteral } from \"./source-string-literal.js\";\nexport { toCamelIdentifier } from \"./to-camel-identifier.js\";\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the name unchanged, or with a trailing underscore when it collides with a reserved word,
|
|
3
|
+
* so it is safe to emit as a JavaScript identifier.
|
|
4
|
+
*
|
|
5
|
+
* @param name - The candidate identifier.
|
|
6
|
+
* @returns The name, suffixed with `_` when it is a reserved word.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* sanitizeIdentifier("iconName"); // "iconName"
|
|
10
|
+
* sanitizeIdentifier("class"); // "class_"
|
|
11
|
+
*/
|
|
12
|
+
declare function sanitizeIdentifier(name: string): string;
|
|
13
|
+
export { sanitizeIdentifier };
|
|
14
|
+
//# sourceMappingURL=sanitize-identifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize-identifier.d.ts","sourceRoot":"","sources":["../../src/source/sanitize-identifier.ts"],"names":[],"mappings":"AAkDA;;;;;;;;;;GAUG;AACH,iBAAS,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const RESERVED = new Set([
|
|
2
|
+
"arguments",
|
|
3
|
+
"await",
|
|
4
|
+
"break",
|
|
5
|
+
"case",
|
|
6
|
+
"catch",
|
|
7
|
+
"class",
|
|
8
|
+
"const",
|
|
9
|
+
"continue",
|
|
10
|
+
"debugger",
|
|
11
|
+
"default",
|
|
12
|
+
"delete",
|
|
13
|
+
"do",
|
|
14
|
+
"else",
|
|
15
|
+
"enum",
|
|
16
|
+
"eval",
|
|
17
|
+
"export",
|
|
18
|
+
"extends",
|
|
19
|
+
"false",
|
|
20
|
+
"finally",
|
|
21
|
+
"for",
|
|
22
|
+
"function",
|
|
23
|
+
"if",
|
|
24
|
+
"import",
|
|
25
|
+
"in",
|
|
26
|
+
"instanceof",
|
|
27
|
+
"interface",
|
|
28
|
+
"let",
|
|
29
|
+
"new",
|
|
30
|
+
"null",
|
|
31
|
+
"package",
|
|
32
|
+
"private",
|
|
33
|
+
"protected",
|
|
34
|
+
"public",
|
|
35
|
+
"return",
|
|
36
|
+
"static",
|
|
37
|
+
"super",
|
|
38
|
+
"switch",
|
|
39
|
+
"this",
|
|
40
|
+
"throw",
|
|
41
|
+
"true",
|
|
42
|
+
"try",
|
|
43
|
+
"typeof",
|
|
44
|
+
"var",
|
|
45
|
+
"void",
|
|
46
|
+
"while",
|
|
47
|
+
"with",
|
|
48
|
+
"yield",
|
|
49
|
+
]);
|
|
50
|
+
/**
|
|
51
|
+
* Returns the name unchanged, or with a trailing underscore when it collides with a reserved word,
|
|
52
|
+
* so it is safe to emit as a JavaScript identifier.
|
|
53
|
+
*
|
|
54
|
+
* @param name - The candidate identifier.
|
|
55
|
+
* @returns The name, suffixed with `_` when it is a reserved word.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* sanitizeIdentifier("iconName"); // "iconName"
|
|
59
|
+
* sanitizeIdentifier("class"); // "class_"
|
|
60
|
+
*/
|
|
61
|
+
function sanitizeIdentifier(name) {
|
|
62
|
+
return RESERVED.has(name) ? `${name}_` : name;
|
|
63
|
+
}
|
|
64
|
+
export { sanitizeIdentifier };
|
|
65
|
+
//# sourceMappingURL=sanitize-identifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize-identifier.js","sourceRoot":"","sources":["../../src/source/sanitize-identifier.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ,GAAgB,IAAI,GAAG,CAAC;IAClC,WAAW;IACX,OAAO;IACP,OAAO;IACP,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,UAAU;IACV,UAAU;IACV,SAAS;IACT,QAAQ;IACR,IAAI;IACJ,MAAM;IACN,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,OAAO;IACP,SAAS;IACT,KAAK;IACL,UAAU;IACV,IAAI;IACJ,QAAQ;IACR,IAAI;IACJ,YAAY;IACZ,WAAW;IACX,KAAK;IACL,KAAK;IACL,MAAM;IACN,SAAS;IACT,SAAS;IACT,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,MAAM;IACN,OAAO;IACP,MAAM;IACN,KAAK;IACL,QAAQ;IACR,KAAK;IACL,MAAM;IACN,OAAO;IACP,MAAM;IACN,OAAO;CACV,CAAC,CAAC;AAEH;;;;;;;;;;GAUG;AACH,SAAS,kBAAkB,CAAC,IAAY;IACpC,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AAClD,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["const RESERVED: Set<string> = new Set([\n \"arguments\",\n \"await\",\n \"break\",\n \"case\",\n \"catch\",\n \"class\",\n \"const\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"delete\",\n \"do\",\n \"else\",\n \"enum\",\n \"eval\",\n \"export\",\n \"extends\",\n \"false\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"import\",\n \"in\",\n \"instanceof\",\n \"interface\",\n \"let\",\n \"new\",\n \"null\",\n \"package\",\n \"private\",\n \"protected\",\n \"public\",\n \"return\",\n \"static\",\n \"super\",\n \"switch\",\n \"this\",\n \"throw\",\n \"true\",\n \"try\",\n \"typeof\",\n \"var\",\n \"void\",\n \"while\",\n \"with\",\n \"yield\",\n]);\n\n/**\n * Returns the name unchanged, or with a trailing underscore when it collides with a reserved word,\n * so it is safe to emit as a JavaScript identifier.\n *\n * @param name - The candidate identifier.\n * @returns The name, suffixed with `_` when it is a reserved word.\n *\n * @example\n * sanitizeIdentifier(\"iconName\"); // \"iconName\"\n * sanitizeIdentifier(\"class\"); // \"class_\"\n */\nfunction sanitizeIdentifier(name: string): string {\n return RESERVED.has(name) ? `${name}_` : name;\n}\n\nexport { sanitizeIdentifier };\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a string as a JavaScript string literal, additionally escaping characters that are unsafe
|
|
3
|
+
* to embed in generated source (angle brackets and the line and paragraph separators).
|
|
4
|
+
*
|
|
5
|
+
* @param value - The string to encode.
|
|
6
|
+
* @returns The quoted, source-safe string literal.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* sourceStringLiteral("hello"); // '"hello"'
|
|
10
|
+
*/
|
|
11
|
+
declare function sourceStringLiteral(value: string): string;
|
|
12
|
+
export { sourceStringLiteral };
|
|
13
|
+
//# sourceMappingURL=source-string-literal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-string-literal.d.ts","sourceRoot":"","sources":["../../src/source/source-string-literal.ts"],"names":[],"mappings":"AAYA;;;;;;;;;GASG;AACH,iBAAS,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const LINE_SEPARATOR = String.fromCodePoint(0x20_28);
|
|
2
|
+
const PARAGRAPH_SEPARATOR = String.fromCodePoint(0x20_29);
|
|
3
|
+
const SOURCE_ESCAPES = {
|
|
4
|
+
"<": String.raw `\u003C`,
|
|
5
|
+
">": String.raw `\u003E`,
|
|
6
|
+
[LINE_SEPARATOR]: String.raw `\u2028`,
|
|
7
|
+
[PARAGRAPH_SEPARATOR]: String.raw `\u2029`,
|
|
8
|
+
};
|
|
9
|
+
const UNSAFE_SOURCE_CHARS = new RegExp(`[${Object.keys(SOURCE_ESCAPES).join("")}]`, "g");
|
|
10
|
+
/**
|
|
11
|
+
* Encodes a string as a JavaScript string literal, additionally escaping characters that are unsafe
|
|
12
|
+
* to embed in generated source (angle brackets and the line and paragraph separators).
|
|
13
|
+
*
|
|
14
|
+
* @param value - The string to encode.
|
|
15
|
+
* @returns The quoted, source-safe string literal.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* sourceStringLiteral("hello"); // '"hello"'
|
|
19
|
+
*/
|
|
20
|
+
function sourceStringLiteral(value) {
|
|
21
|
+
return JSON.stringify(value).replaceAll(UNSAFE_SOURCE_CHARS, (char) => SOURCE_ESCAPES[char] ?? char);
|
|
22
|
+
}
|
|
23
|
+
export { sourceStringLiteral };
|
|
24
|
+
//# sourceMappingURL=source-string-literal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-string-literal.js","sourceRoot":"","sources":["../../src/source/source-string-literal.ts"],"names":[],"mappings":"AAAA,MAAM,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AACrD,MAAM,mBAAmB,GAAG,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AAE1D,MAAM,cAAc,GAA2B;IAC3C,GAAG,EAAE,MAAM,CAAC,GAAG,CAAA,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC,GAAG,CAAA,QAAQ;IACvB,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,GAAG,CAAA,QAAQ;IACpC,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC,GAAG,CAAA,QAAQ;CAC5C,CAAC;AAEF,MAAM,mBAAmB,GAAG,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAEzF;;;;;;;;;GASG;AACH,SAAS,mBAAmB,CAAC,KAAa;IACtC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,mBAAmB,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;AACzG,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC","sourcesContent":["const LINE_SEPARATOR = String.fromCodePoint(0x20_28);\nconst PARAGRAPH_SEPARATOR = String.fromCodePoint(0x20_29);\n\nconst SOURCE_ESCAPES: Record<string, string> = {\n \"<\": String.raw`\\u003C`,\n \">\": String.raw`\\u003E`,\n [LINE_SEPARATOR]: String.raw`\\u2028`,\n [PARAGRAPH_SEPARATOR]: String.raw`\\u2029`,\n};\n\nconst UNSAFE_SOURCE_CHARS = new RegExp(`[${Object.keys(SOURCE_ESCAPES).join(\"\")}]`, \"g\");\n\n/**\n * Encodes a string as a JavaScript string literal, additionally escaping characters that are unsafe\n * to embed in generated source (angle brackets and the line and paragraph separators).\n *\n * @param value - The string to encode.\n * @returns The quoted, source-safe string literal.\n *\n * @example\n * sourceStringLiteral(\"hello\"); // '\"hello\"'\n */\nfunction sourceStringLiteral(value: string): string {\n return JSON.stringify(value).replaceAll(UNSAFE_SOURCE_CHARS, (char) => SOURCE_ESCAPES[char] ?? char);\n}\n\nexport { sourceStringLiteral };\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a name to camel case and sanitizes it into a valid JavaScript identifier.
|
|
3
|
+
*
|
|
4
|
+
* @param name - The name to convert.
|
|
5
|
+
* @returns The camel-cased, reserved-word-safe identifier.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* toCamelIdentifier("icon_name"); // "iconName"
|
|
9
|
+
* toCamelIdentifier("class"); // "class_"
|
|
10
|
+
*/
|
|
11
|
+
declare function toCamelIdentifier(name: string): string;
|
|
12
|
+
export { toCamelIdentifier };
|
|
13
|
+
//# sourceMappingURL=to-camel-identifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-camel-identifier.d.ts","sourceRoot":"","sources":["../../src/source/to-camel-identifier.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,iBAAS,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { camelCase } from "../string/camel-case.js";
|
|
2
|
+
import { sanitizeIdentifier } from "./sanitize-identifier.js";
|
|
3
|
+
/**
|
|
4
|
+
* Converts a name to camel case and sanitizes it into a valid JavaScript identifier.
|
|
5
|
+
*
|
|
6
|
+
* @param name - The name to convert.
|
|
7
|
+
* @returns The camel-cased, reserved-word-safe identifier.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* toCamelIdentifier("icon_name"); // "iconName"
|
|
11
|
+
* toCamelIdentifier("class"); // "class_"
|
|
12
|
+
*/
|
|
13
|
+
function toCamelIdentifier(name) {
|
|
14
|
+
return sanitizeIdentifier(camelCase(name));
|
|
15
|
+
}
|
|
16
|
+
export { toCamelIdentifier };
|
|
17
|
+
//# sourceMappingURL=to-camel-identifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-camel-identifier.js","sourceRoot":"","sources":["../../src/source/to-camel-identifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D;;;;;;;;;GASG;AACH,SAAS,iBAAiB,CAAC,IAAY;IACnC,OAAO,kBAAkB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import { camelCase } from \"../string/camel-case.js\";\nimport { sanitizeIdentifier } from \"./sanitize-identifier.js\";\n\n/**\n * Converts a name to camel case and sanitizes it into a valid JavaScript identifier.\n *\n * @param name - The name to convert.\n * @returns The camel-cased, reserved-word-safe identifier.\n *\n * @example\n * toCamelIdentifier(\"icon_name\"); // \"iconName\"\n * toCamelIdentifier(\"class\"); // \"class_\"\n */\nfunction toCamelIdentifier(name: string): string {\n return sanitizeIdentifier(camelCase(name));\n}\n\nexport { toCamelIdentifier };\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an underscore- or hyphen-delimited string to camel case.
|
|
3
|
+
*
|
|
4
|
+
* Unlike a general-purpose converter, this splits only on `_` and `-` and keeps the first segment
|
|
5
|
+
* verbatim, so GObject acronyms are preserved (`camelCase("GLArea")` stays `"GLArea"`).
|
|
6
|
+
*
|
|
7
|
+
* @param str - The string to convert.
|
|
8
|
+
* @returns The camel-cased string.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* camelCase("icon_name"); // "iconName"
|
|
12
|
+
* camelCase("start-widget"); // "startWidget"
|
|
13
|
+
* camelCase("Box"); // "Box"
|
|
14
|
+
*/
|
|
15
|
+
declare function camelCase(str: string): string;
|
|
16
|
+
export { camelCase };
|
|
17
|
+
//# sourceMappingURL=camel-case.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camel-case.d.ts","sourceRoot":"","sources":["../../src/string/camel-case.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AACH,iBAAS,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEtC;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { upperFirst } from "./upper-first.js";
|
|
2
|
+
import { mapWordSegments } from "./word-segments.js";
|
|
3
|
+
/**
|
|
4
|
+
* Converts an underscore- or hyphen-delimited string to camel case.
|
|
5
|
+
*
|
|
6
|
+
* Unlike a general-purpose converter, this splits only on `_` and `-` and keeps the first segment
|
|
7
|
+
* verbatim, so GObject acronyms are preserved (`camelCase("GLArea")` stays `"GLArea"`).
|
|
8
|
+
*
|
|
9
|
+
* @param str - The string to convert.
|
|
10
|
+
* @returns The camel-cased string.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* camelCase("icon_name"); // "iconName"
|
|
14
|
+
* camelCase("start-widget"); // "startWidget"
|
|
15
|
+
* camelCase("Box"); // "Box"
|
|
16
|
+
*/
|
|
17
|
+
function camelCase(str) {
|
|
18
|
+
return mapWordSegments(str, (part, index) => (index === 0 ? part : upperFirst(part)));
|
|
19
|
+
}
|
|
20
|
+
export { camelCase };
|
|
21
|
+
//# sourceMappingURL=camel-case.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camel-case.js","sourceRoot":"","sources":["../../src/string/camel-case.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;;;;;;;;GAaG;AACH,SAAS,SAAS,CAAC,GAAW;IAC1B,OAAO,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC1F,CAAC;AAED,OAAO,EAAE,SAAS,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 camel case.\n *\n * Unlike a general-purpose converter, this splits only on `_` and `-` and keeps the first segment\n * verbatim, so GObject acronyms are preserved (`camelCase(\"GLArea\")` stays `\"GLArea\"`).\n *\n * @param str - The string to convert.\n * @returns The camel-cased string.\n *\n * @example\n * camelCase(\"icon_name\"); // \"iconName\"\n * camelCase(\"start-widget\"); // \"startWidget\"\n * camelCase(\"Box\"); // \"Box\"\n */\nfunction camelCase(str: string): string {\n return mapWordSegments(str, (part, index) => (index === 0 ? part : upperFirst(part)));\n}\n\nexport { camelCase };\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { camelCase } from "./camel-case.js";
|
|
2
|
+
export { kebabCase } from "./kebab-case.js";
|
|
3
|
+
export { lowerFirst } from "./lower-first.js";
|
|
4
|
+
export { pascalCase } from "./pascal-case.js";
|
|
5
|
+
export { upperFirst } from "./upper-first.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { camelCase } from "./camel-case.js";
|
|
2
|
+
export { kebabCase } from "./kebab-case.js";
|
|
3
|
+
export { lowerFirst } from "./lower-first.js";
|
|
4
|
+
export { pascalCase } from "./pascal-case.js";
|
|
5
|
+
export { upperFirst } from "./upper-first.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["export { camelCase } from \"./camel-case.js\";\nexport { kebabCase } from \"./kebab-case.js\";\nexport { lowerFirst } from \"./lower-first.js\";\nexport { pascalCase } from \"./pascal-case.js\";\nexport { upperFirst } from \"./upper-first.js\";\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a camelCase or PascalCase string to kebab case by lower-casing uppercase letters and
|
|
3
|
+
* inserting hyphens before interior ones.
|
|
4
|
+
*
|
|
5
|
+
* @param str - The string to convert.
|
|
6
|
+
* @returns The kebab-cased string.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* kebabCase("iconName"); // "icon-name"
|
|
10
|
+
* kebabCase("Title"); // "title"
|
|
11
|
+
*/
|
|
12
|
+
declare function kebabCase(str: string): string;
|
|
13
|
+
export { kebabCase };
|
|
14
|
+
//# sourceMappingURL=kebab-case.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kebab-case.d.ts","sourceRoot":"","sources":["../../src/string/kebab-case.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,iBAAS,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAItC;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a camelCase or PascalCase string to kebab case by lower-casing uppercase letters and
|
|
3
|
+
* inserting hyphens before interior ones.
|
|
4
|
+
*
|
|
5
|
+
* @param str - The string to convert.
|
|
6
|
+
* @returns The kebab-cased string.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* kebabCase("iconName"); // "icon-name"
|
|
10
|
+
* kebabCase("Title"); // "title"
|
|
11
|
+
*/
|
|
12
|
+
function kebabCase(str) {
|
|
13
|
+
return str.replaceAll(/[A-Z]/g, (char, index) => index === 0 ? char.toLowerCase() : `-${char.toLowerCase()}`);
|
|
14
|
+
}
|
|
15
|
+
export { kebabCase };
|
|
16
|
+
//# sourceMappingURL=kebab-case.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kebab-case.js","sourceRoot":"","sources":["../../src/string/kebab-case.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,SAAS,SAAS,CAAC,GAAW;IAC1B,OAAO,GAAG,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,KAAa,EAAE,EAAE,CACpD,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAC9D,CAAC;AACN,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["/**\n * Converts a camelCase or PascalCase string to kebab case by lower-casing uppercase letters and\n * inserting hyphens before interior ones.\n *\n * @param str - The string to convert.\n * @returns The kebab-cased string.\n *\n * @example\n * kebabCase(\"iconName\"); // \"icon-name\"\n * kebabCase(\"Title\"); // \"title\"\n */\nfunction kebabCase(str: string): string {\n return str.replaceAll(/[A-Z]/g, (char, index: number) =>\n index === 0 ? char.toLowerCase() : `-${char.toLowerCase()}`,\n );\n}\n\nexport { kebabCase };\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts the first character of a string to lower case.
|
|
3
|
+
*
|
|
4
|
+
* @param str - The string to transform.
|
|
5
|
+
* @returns The string with its first character lower-cased.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* lowerFirst("Fred"); // "fred"
|
|
9
|
+
* lowerFirst("FRED"); // "fRED"
|
|
10
|
+
*/
|
|
11
|
+
declare function lowerFirst(str: string): string;
|
|
12
|
+
export { lowerFirst };
|
|
13
|
+
//# sourceMappingURL=lower-first.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lower-first.d.ts","sourceRoot":"","sources":["../../src/string/lower-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 lower case.
|
|
3
|
+
*
|
|
4
|
+
* @param str - The string to transform.
|
|
5
|
+
* @returns The string with its first character lower-cased.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* lowerFirst("Fred"); // "fred"
|
|
9
|
+
* lowerFirst("FRED"); // "fRED"
|
|
10
|
+
*/
|
|
11
|
+
function lowerFirst(str) {
|
|
12
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
13
|
+
}
|
|
14
|
+
export { lowerFirst };
|
|
15
|
+
//# sourceMappingURL=lower-first.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lower-first.js","sourceRoot":"","sources":["../../src/string/lower-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 lower case.\n *\n * @param str - The string to transform.\n * @returns The string with its first character lower-cased.\n *\n * @example\n * lowerFirst(\"Fred\"); // \"fred\"\n * lowerFirst(\"FRED\"); // \"fRED\"\n */\nfunction lowerFirst(str: string): string {\n return str.charAt(0).toLowerCase() + str.slice(1);\n}\n\nexport { lowerFirst };\n"]}
|