@ls-stack/utils 3.39.0 → 3.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrayUtils.d.cts +70 -57
- package/dist/arrayUtils.d.ts +70 -57
- package/dist/assertions.d.cts +128 -117
- package/dist/assertions.d.ts +128 -117
- package/dist/asyncQueue.cjs +117 -112
- package/dist/asyncQueue.d.cts +217 -215
- package/dist/asyncQueue.d.ts +217 -215
- package/dist/asyncQueue.js +117 -112
- package/dist/awaitDebounce.d.cts +26 -23
- package/dist/awaitDebounce.d.ts +26 -23
- package/dist/cache.cjs +2 -1
- package/dist/cache.d.cts +15 -9
- package/dist/cache.d.ts +15 -9
- package/dist/cache.js +2 -1
- package/dist/{chunk-GHAQOUA6.js → chunk-23KPGKDT.js} +22 -1
- package/dist/{chunk-ADM37GSC.js → chunk-7L4KCZJJ.js} +12 -10
- package/dist/{chunk-KW55OTUG.js → chunk-B3KFV2MH.js} +2 -2
- package/dist/chunk-DTE2QMWE.js +48 -0
- package/dist/concurrentCalls.d.cts +8 -4
- package/dist/concurrentCalls.d.ts +8 -4
- package/dist/concurrentCalls.js +1 -1
- package/dist/consoleFmt.cjs +1 -0
- package/dist/consoleFmt.d.cts +6 -0
- package/dist/consoleFmt.d.ts +6 -0
- package/dist/consoleFmt.js +1 -0
- package/dist/debounce.d.cts +12 -20
- package/dist/debounce.d.ts +12 -20
- package/dist/dedent.d.cts +31 -31
- package/dist/dedent.d.ts +31 -31
- package/dist/deepEqual.d.cts +10 -9
- package/dist/deepEqual.d.ts +10 -9
- package/dist/filterObjectOrArrayKeys.d.cts +44 -19
- package/dist/filterObjectOrArrayKeys.d.ts +44 -19
- package/dist/getAutoIncrementId.d.cts +25 -23
- package/dist/getAutoIncrementId.d.ts +25 -23
- package/dist/getCompositeKey.d.cts +2 -1
- package/dist/getCompositeKey.d.ts +2 -1
- package/dist/getValueStableKey.d.cts +4 -3
- package/dist/getValueStableKey.d.ts +4 -3
- package/dist/mutationUtils.d.cts +2 -2
- package/dist/mutationUtils.d.ts +2 -2
- package/dist/objUtils.cjs +51 -2
- package/dist/objUtils.d.cts +8 -3
- package/dist/objUtils.d.ts +8 -3
- package/dist/objUtils.js +11 -3
- package/dist/parallelAsyncCalls.cjs +2 -1
- package/dist/parallelAsyncCalls.d.cts +5 -4
- package/dist/parallelAsyncCalls.d.ts +5 -4
- package/dist/parallelAsyncCalls.js +2 -1
- package/dist/retryOnError.d.cts +23 -20
- package/dist/retryOnError.d.ts +23 -20
- package/dist/runShellCmd.d.cts +40 -40
- package/dist/runShellCmd.d.ts +40 -40
- package/dist/safeJson.d.cts +6 -2
- package/dist/safeJson.d.ts +6 -2
- package/dist/saferTyping.d.cts +21 -14
- package/dist/saferTyping.d.ts +21 -14
- package/dist/shallowEqual.d.cts +1 -1
- package/dist/shallowEqual.d.ts +1 -1
- package/dist/stringUtils.cjs +2 -2
- package/dist/stringUtils.d.cts +6 -7
- package/dist/stringUtils.d.ts +6 -7
- package/dist/stringUtils.js +1 -1
- package/dist/testUtils.cjs +11 -9
- package/dist/testUtils.d.cts +32 -14
- package/dist/testUtils.d.ts +32 -14
- package/dist/testUtils.js +4 -3
- package/dist/throttle.d.cts +57 -48
- package/dist/throttle.d.ts +57 -48
- package/dist/timers.d.cts +68 -63
- package/dist/timers.d.ts +68 -63
- package/dist/tsResult.d.cts +7 -6
- package/dist/tsResult.d.ts +7 -6
- package/dist/typeGuards.d.cts +65 -64
- package/dist/typeGuards.d.ts +65 -64
- package/dist/typeUtils.d.cts +18 -4
- package/dist/typeUtils.d.ts +18 -4
- package/dist/typedStrings.d.cts +68 -57
- package/dist/typedStrings.d.ts +68 -57
- package/dist/typingFnUtils.d.cts +12 -6
- package/dist/typingFnUtils.d.ts +12 -6
- package/dist/typingFnUtils.js +12 -35
- package/dist/typingTestUtils.cjs +7 -1
- package/dist/typingTestUtils.d.cts +52 -11
- package/dist/typingTestUtils.d.ts +52 -11
- package/dist/typingTestUtils.js +7 -1
- package/dist/typingUtils.d.cts +4 -1
- package/dist/typingUtils.d.ts +4 -1
- package/dist/yamlStringify.cjs +11 -9
- package/dist/yamlStringify.js +2 -2
- package/package.json +6 -2
- package/docs/README.md +0 -72
- package/docs/_media/modules.md +0 -58
- package/docs/arrayUtils/-internal-.md +0 -179
- package/docs/arrayUtils/README.md +0 -550
- package/docs/assertions/-internal-.md +0 -63
- package/docs/assertions/README.md +0 -565
- package/docs/asyncQueue/-internal-.md +0 -297
- package/docs/asyncQueue/README.md +0 -1485
- package/docs/awaitDebounce.md +0 -66
- package/docs/cache/-internal-.md +0 -168
- package/docs/cache/README.md +0 -360
- package/docs/castValues.md +0 -47
- package/docs/concurrentCalls/-internal-.md +0 -490
- package/docs/concurrentCalls/README.md +0 -299
- package/docs/consoleFmt.md +0 -91
- package/docs/conversions.md +0 -27
- package/docs/createThrottleController/-internal-.md +0 -73
- package/docs/createThrottleController/README.md +0 -31
- package/docs/debounce.md +0 -188
- package/docs/dedent/-internal-.md +0 -17
- package/docs/dedent/README.md +0 -204
- package/docs/deepEqual.md +0 -94
- package/docs/enhancedMap.md +0 -358
- package/docs/exhaustiveMatch/-internal-.md +0 -39
- package/docs/exhaustiveMatch/README.md +0 -146
- package/docs/filterObjectOrArrayKeys.md +0 -109
- package/docs/getAutoIncrementId.md +0 -93
- package/docs/getCompositeKey.md +0 -39
- package/docs/getValueStableKey.md +0 -57
- package/docs/hash.md +0 -31
- package/docs/interpolate/-internal-.md +0 -61
- package/docs/interpolate/README.md +0 -62
- package/docs/keepPrevIfUnchanged.md +0 -43
- package/docs/levenshtein.md +0 -93
- package/docs/main.md +0 -21
- package/docs/mathUtils.md +0 -137
- package/docs/modules.md +0 -58
- package/docs/mutationUtils.md +0 -44
- package/docs/objUtils.md +0 -237
- package/docs/parallelAsyncCalls/-internal-.md +0 -347
- package/docs/parallelAsyncCalls/README.md +0 -45
- package/docs/promiseUtils/-internal-.md +0 -69
- package/docs/promiseUtils/README.md +0 -31
- package/docs/retryOnError/-internal-.md +0 -111
- package/docs/retryOnError/README.md +0 -168
- package/docs/runShellCmd/-internal-.md +0 -111
- package/docs/runShellCmd/README.md +0 -201
- package/docs/safeJson.md +0 -51
- package/docs/saferTyping.md +0 -228
- package/docs/serializeXML.md +0 -100
- package/docs/shallowEqual.md +0 -33
- package/docs/sleep.md +0 -27
- package/docs/stringUtils/-internal-.md +0 -17
- package/docs/stringUtils/README.md +0 -270
- package/docs/testUtils.md +0 -382
- package/docs/throttle/-internal-.md +0 -47
- package/docs/throttle/README.md +0 -178
- package/docs/time.md +0 -274
- package/docs/timers.md +0 -256
- package/docs/tsResult/-internal-.md +0 -327
- package/docs/tsResult/README.md +0 -702
- package/docs/typeGuards.md +0 -399
- package/docs/typeUtils/-internal-.md +0 -99
- package/docs/typeUtils/README.md +0 -195
- package/docs/typeUtils.typesTest.md +0 -7
- package/docs/typedStrings.md +0 -458
- package/docs/typingFnUtils/-internal-.md +0 -43
- package/docs/typingFnUtils/README.md +0 -317
- package/docs/typingTestUtils.md +0 -172
- package/docs/typingUtils.md +0 -135
- package/docs/yamlStringify.md +0 -83
package/dist/timers.d.ts
CHANGED
|
@@ -2,69 +2,70 @@ type CleanupTimer = () => void;
|
|
|
2
2
|
/**
|
|
3
3
|
* Creates a timeout with automatic cleanup capability.
|
|
4
4
|
*
|
|
5
|
-
* Returns a cleanup function that can be called to cancel the timeout.
|
|
6
|
-
*
|
|
5
|
+
* Returns a cleanup function that can be called to cancel the timeout. The
|
|
6
|
+
* cleanup function is idempotent - calling it multiple times is safe.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const cleanup = createTimeout(1000, () => {
|
|
11
|
+
* console.log('Timeout completed');
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* // Cancel the timeout before it completes
|
|
15
|
+
* cleanup();
|
|
16
|
+
* ```;
|
|
7
17
|
*
|
|
8
18
|
* @param ms - The timeout duration in milliseconds
|
|
9
19
|
* @param callback - The function to execute when the timeout completes
|
|
10
20
|
* @returns A cleanup function that cancels the timeout when called
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const cleanup = createTimeout(1000, () => {
|
|
15
|
-
* console.log('Timeout completed');
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
18
|
-
* // Cancel the timeout before it completes
|
|
19
|
-
* cleanup();
|
|
20
|
-
* ```
|
|
21
21
|
*/
|
|
22
22
|
declare function createTimeout(ms: number, callback: () => void): CleanupTimer;
|
|
23
23
|
/**
|
|
24
24
|
* Creates an interval with automatic cleanup capability.
|
|
25
25
|
*
|
|
26
|
-
* Returns a cleanup function that can be called to cancel the interval.
|
|
27
|
-
*
|
|
26
|
+
* Returns a cleanup function that can be called to cancel the interval. The
|
|
27
|
+
* cleanup function is idempotent - calling it multiple times is safe.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const cleanup = createInterval(1000, () => {
|
|
32
|
+
* console.log('Interval tick');
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // Stop the interval
|
|
36
|
+
* cleanup();
|
|
37
|
+
* ```;
|
|
28
38
|
*
|
|
29
39
|
* @param ms - The interval duration in milliseconds
|
|
30
40
|
* @param callback - The function to execute on each interval tick
|
|
31
41
|
* @returns A cleanup function that cancels the interval when called
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* const cleanup = createInterval(1000, () => {
|
|
36
|
-
* console.log('Interval tick');
|
|
37
|
-
* });
|
|
38
|
-
*
|
|
39
|
-
* // Stop the interval
|
|
40
|
-
* cleanup();
|
|
41
|
-
* ```
|
|
42
42
|
*/
|
|
43
43
|
declare function createInterval(ms: number, callback: () => void): CleanupTimer;
|
|
44
44
|
/**
|
|
45
45
|
* Creates a timeout that prevents concurrent executions.
|
|
46
46
|
*
|
|
47
|
-
* Each call to the `call` function will cancel any previous pending timeout
|
|
48
|
-
*
|
|
49
|
-
*
|
|
47
|
+
* Each call to the `call` function will cancel any previous pending timeout and
|
|
48
|
+
* start a new one. This is useful for debouncing or ensuring only the last call
|
|
49
|
+
* executes after a delay.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const { call, clean } = createDebouncedTimeout(1000, () => {
|
|
54
|
+
* console.log('Only the last call executes');
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* call(); // This will be cancelled
|
|
58
|
+
* call(); // This will be cancelled
|
|
59
|
+
* call(); // Only this one will execute after 1000ms
|
|
60
|
+
*
|
|
61
|
+
* // Or cancel all pending timeouts
|
|
62
|
+
* clean();
|
|
63
|
+
* ```;
|
|
50
64
|
*
|
|
51
65
|
* @param ms - The timeout duration in milliseconds
|
|
52
66
|
* @param callback - The function to execute when the timeout completes
|
|
53
|
-
* @returns An object with `call` to trigger the timeout and `clean` to cancel
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```typescript
|
|
57
|
-
* const { call, clean } = createDebouncedTimeout(1000, () => {
|
|
58
|
-
* console.log('Only the last call executes');
|
|
59
|
-
* });
|
|
60
|
-
*
|
|
61
|
-
* call(); // This will be cancelled
|
|
62
|
-
* call(); // This will be cancelled
|
|
63
|
-
* call(); // Only this one will execute after 1000ms
|
|
64
|
-
*
|
|
65
|
-
* // Or cancel all pending timeouts
|
|
66
|
-
* clean();
|
|
67
|
-
* ```
|
|
67
|
+
* @returns An object with `call` to trigger the timeout and `clean` to cancel
|
|
68
|
+
* it
|
|
68
69
|
*/
|
|
69
70
|
declare function createDebouncedTimeout(ms: number, callback: () => void): {
|
|
70
71
|
call: () => void;
|
|
@@ -73,32 +74,36 @@ declare function createDebouncedTimeout(ms: number, callback: () => void): {
|
|
|
73
74
|
/**
|
|
74
75
|
* Creates a timeout that waits for a condition to become true.
|
|
75
76
|
*
|
|
76
|
-
* Polls the condition function at regular intervals until it returns a truthy
|
|
77
|
-
* then calls the callback with that value. If the condition doesn't
|
|
78
|
-
* within the maximum wait time, the timeout expires without calling
|
|
77
|
+
* Polls the condition function at regular intervals until it returns a truthy
|
|
78
|
+
* value, then calls the callback with that value. If the condition doesn't
|
|
79
|
+
* become true within the maximum wait time, the timeout expires without calling
|
|
80
|
+
* the callback.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const cleanup = createWaitUntil({
|
|
85
|
+
* condition: () => document.getElementById('myElement'),
|
|
86
|
+
* maxWaitMs: 5000,
|
|
87
|
+
* callback: (element) => {
|
|
88
|
+
* console.log('Element found:', element);
|
|
89
|
+
* },
|
|
90
|
+
* checkIntervalMs: 50
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* // Cancel the condition check
|
|
94
|
+
* cleanup();
|
|
95
|
+
* ```;
|
|
79
96
|
*
|
|
80
97
|
* @template T - The type of value returned by the condition function when true
|
|
81
98
|
* @param options - Configuration options
|
|
82
|
-
* @param options.condition - Function that returns false or a truthy value when
|
|
83
|
-
*
|
|
99
|
+
* @param options.condition - Function that returns false or a truthy value when
|
|
100
|
+
* the condition is met
|
|
101
|
+
* @param options.maxWaitMs - Maximum time to wait for the condition in
|
|
102
|
+
* milliseconds
|
|
84
103
|
* @param options.callback - Function to call when the condition becomes true
|
|
85
|
-
* @param options.checkIntervalMs - How often to check the condition in
|
|
104
|
+
* @param options.checkIntervalMs - How often to check the condition in
|
|
105
|
+
* milliseconds (default: 20)
|
|
86
106
|
* @returns A cleanup function that cancels the condition timeout
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* const cleanup = createWaitUntil({
|
|
91
|
-
* condition: () => document.getElementById('myElement'),
|
|
92
|
-
* maxWaitMs: 5000,
|
|
93
|
-
* callback: (element) => {
|
|
94
|
-
* console.log('Element found:', element);
|
|
95
|
-
* },
|
|
96
|
-
* checkIntervalMs: 50
|
|
97
|
-
* });
|
|
98
|
-
*
|
|
99
|
-
* // Cancel the condition check
|
|
100
|
-
* cleanup();
|
|
101
|
-
* ```
|
|
102
107
|
*/
|
|
103
108
|
declare function createWaitUntil<T extends NonNullable<unknown>>({ condition, maxWaitMs, callback, checkIntervalMs, }: {
|
|
104
109
|
condition: () => false | T;
|
package/dist/tsResult.d.cts
CHANGED
|
@@ -37,18 +37,19 @@ type ResultMethodsKeys = keyof ResultMethods<any, any>;
|
|
|
37
37
|
/** @deprecated Use `t-result` library instead. */
|
|
38
38
|
declare function ok(): Ok<void>;
|
|
39
39
|
/**
|
|
40
|
-
* @param value
|
|
41
40
|
* @deprecated Use `t-result` library instead.
|
|
41
|
+
* @param value
|
|
42
42
|
*/
|
|
43
43
|
declare function ok<T>(value: T): Ok<T>;
|
|
44
44
|
/**
|
|
45
|
-
* @param error
|
|
46
45
|
* @deprecated Use `t-result` library instead.
|
|
46
|
+
* @param error
|
|
47
47
|
*/
|
|
48
48
|
declare function err<E extends ResultValidErrors>(error: E): Err<E>;
|
|
49
49
|
declare function unknownToResultError(error: unknown): Err<Error>;
|
|
50
50
|
/**
|
|
51
51
|
* Unwraps a promise result
|
|
52
|
+
*
|
|
52
53
|
* @param result
|
|
53
54
|
*/
|
|
54
55
|
declare function asyncUnwrap<T>(result: Promise<Result<T, ResultValidErrors>>): Promise<T>;
|
|
@@ -72,26 +73,26 @@ declare const Result: {
|
|
|
72
73
|
getOkErr: typeof getOkErr;
|
|
73
74
|
};
|
|
74
75
|
/**
|
|
76
|
+
* @deprecated Use `t-result` library instead.
|
|
75
77
|
* @param fn
|
|
76
78
|
* @param errorNormalizer
|
|
77
|
-
* @deprecated Use `t-result` library instead.
|
|
78
79
|
*/
|
|
79
80
|
declare function resultify<T, E extends ResultValidErrors = Error>(fn: () => T extends Promise<any> ? never : T, errorNormalizer?: (err: unknown) => E): Result<T, E>;
|
|
80
81
|
/**
|
|
82
|
+
* @deprecated Use `t-result` library instead.
|
|
81
83
|
* @param fn
|
|
82
84
|
* @param errorNormalizer
|
|
83
|
-
* @deprecated Use `t-result` library instead.
|
|
84
85
|
*/
|
|
85
86
|
declare function resultify<T, E extends ResultValidErrors = Error>(fn: () => Promise<T>, errorNormalizer?: (err: unknown) => E): Promise<Result<Awaited<T>, E>>;
|
|
86
87
|
/**
|
|
88
|
+
* @deprecated Use `t-result` library instead.
|
|
87
89
|
* @param fn
|
|
88
90
|
* @param errorNormalizer
|
|
89
|
-
* @deprecated Use `t-result` library instead.
|
|
90
91
|
*/
|
|
91
92
|
declare function resultify<T, E extends ResultValidErrors = Error>(fn: Promise<T>, errorNormalizer?: (err: unknown) => E): Promise<Result<T, E>>;
|
|
92
93
|
/**
|
|
93
|
-
* @param error
|
|
94
94
|
* @deprecated Use `t-result` library instead.
|
|
95
|
+
* @param error
|
|
95
96
|
*/
|
|
96
97
|
declare function unknownToError(error: unknown): Error;
|
|
97
98
|
/** @deprecated Use `t-result` library instead. */
|
package/dist/tsResult.d.ts
CHANGED
|
@@ -37,18 +37,19 @@ type ResultMethodsKeys = keyof ResultMethods<any, any>;
|
|
|
37
37
|
/** @deprecated Use `t-result` library instead. */
|
|
38
38
|
declare function ok(): Ok<void>;
|
|
39
39
|
/**
|
|
40
|
-
* @param value
|
|
41
40
|
* @deprecated Use `t-result` library instead.
|
|
41
|
+
* @param value
|
|
42
42
|
*/
|
|
43
43
|
declare function ok<T>(value: T): Ok<T>;
|
|
44
44
|
/**
|
|
45
|
-
* @param error
|
|
46
45
|
* @deprecated Use `t-result` library instead.
|
|
46
|
+
* @param error
|
|
47
47
|
*/
|
|
48
48
|
declare function err<E extends ResultValidErrors>(error: E): Err<E>;
|
|
49
49
|
declare function unknownToResultError(error: unknown): Err<Error>;
|
|
50
50
|
/**
|
|
51
51
|
* Unwraps a promise result
|
|
52
|
+
*
|
|
52
53
|
* @param result
|
|
53
54
|
*/
|
|
54
55
|
declare function asyncUnwrap<T>(result: Promise<Result<T, ResultValidErrors>>): Promise<T>;
|
|
@@ -72,26 +73,26 @@ declare const Result: {
|
|
|
72
73
|
getOkErr: typeof getOkErr;
|
|
73
74
|
};
|
|
74
75
|
/**
|
|
76
|
+
* @deprecated Use `t-result` library instead.
|
|
75
77
|
* @param fn
|
|
76
78
|
* @param errorNormalizer
|
|
77
|
-
* @deprecated Use `t-result` library instead.
|
|
78
79
|
*/
|
|
79
80
|
declare function resultify<T, E extends ResultValidErrors = Error>(fn: () => T extends Promise<any> ? never : T, errorNormalizer?: (err: unknown) => E): Result<T, E>;
|
|
80
81
|
/**
|
|
82
|
+
* @deprecated Use `t-result` library instead.
|
|
81
83
|
* @param fn
|
|
82
84
|
* @param errorNormalizer
|
|
83
|
-
* @deprecated Use `t-result` library instead.
|
|
84
85
|
*/
|
|
85
86
|
declare function resultify<T, E extends ResultValidErrors = Error>(fn: () => Promise<T>, errorNormalizer?: (err: unknown) => E): Promise<Result<Awaited<T>, E>>;
|
|
86
87
|
/**
|
|
88
|
+
* @deprecated Use `t-result` library instead.
|
|
87
89
|
* @param fn
|
|
88
90
|
* @param errorNormalizer
|
|
89
|
-
* @deprecated Use `t-result` library instead.
|
|
90
91
|
*/
|
|
91
92
|
declare function resultify<T, E extends ResultValidErrors = Error>(fn: Promise<T>, errorNormalizer?: (err: unknown) => E): Promise<Result<T, E>>;
|
|
92
93
|
/**
|
|
93
|
-
* @param error
|
|
94
94
|
* @deprecated Use `t-result` library instead.
|
|
95
|
+
* @param error
|
|
95
96
|
*/
|
|
96
97
|
declare function unknownToError(error: unknown): Error;
|
|
97
98
|
/** @deprecated Use `t-result` library instead. */
|
package/dist/typeGuards.d.cts
CHANGED
|
@@ -4,98 +4,99 @@
|
|
|
4
4
|
* Returns true if the value is an object that is not null and not an array.
|
|
5
5
|
* This is useful for distinguishing between objects and other types.
|
|
6
6
|
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* if (isObject(value)) {
|
|
10
|
+
* // TypeScript knows value is Record<string, unknown>
|
|
11
|
+
* console.log(value.someProperty);
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* isObject({}); // true
|
|
15
|
+
* isObject({ a: 1 }); // true
|
|
16
|
+
* isObject(null); // false
|
|
17
|
+
* isObject([]); // false
|
|
18
|
+
* isObject('string'); // false
|
|
19
|
+
* ```;
|
|
20
|
+
*
|
|
7
21
|
* @param value - The value to check
|
|
8
22
|
* @returns True if the value is a plain object, false otherwise
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* if (isObject(value)) {
|
|
13
|
-
* // TypeScript knows value is Record<string, unknown>
|
|
14
|
-
* console.log(value.someProperty);
|
|
15
|
-
* }
|
|
16
|
-
*
|
|
17
|
-
* isObject({}); // true
|
|
18
|
-
* isObject({ a: 1 }); // true
|
|
19
|
-
* isObject(null); // false
|
|
20
|
-
* isObject([]); // false
|
|
21
|
-
* isObject('string'); // false
|
|
22
|
-
* ```
|
|
23
23
|
*/
|
|
24
24
|
declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
25
25
|
/**
|
|
26
26
|
* Type guard to check if a value is a function.
|
|
27
27
|
*
|
|
28
|
-
* Returns true if the value is a function of any kind (regular function,
|
|
29
|
-
*
|
|
28
|
+
* Returns true if the value is a function of any kind (regular function, arrow
|
|
29
|
+
* function, method, constructor, etc.).
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* if (isFunction(value)) {
|
|
34
|
+
* // TypeScript knows value is (...args: any[]) => any
|
|
35
|
+
* const result = value();
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* isFunction(() => {}); // true
|
|
39
|
+
* isFunction(function() {}); // true
|
|
40
|
+
* isFunction(Math.max); // true
|
|
41
|
+
* isFunction('string'); // false
|
|
42
|
+
* isFunction({}); // false
|
|
43
|
+
* ```;
|
|
30
44
|
*
|
|
31
45
|
* @param value - The value to check
|
|
32
46
|
* @returns True if the value is a function, false otherwise
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* if (isFunction(value)) {
|
|
37
|
-
* // TypeScript knows value is (...args: any[]) => any
|
|
38
|
-
* const result = value();
|
|
39
|
-
* }
|
|
40
|
-
*
|
|
41
|
-
* isFunction(() => {}); // true
|
|
42
|
-
* isFunction(function() {}); // true
|
|
43
|
-
* isFunction(Math.max); // true
|
|
44
|
-
* isFunction('string'); // false
|
|
45
|
-
* isFunction({}); // false
|
|
46
|
-
* ```
|
|
47
47
|
*/
|
|
48
48
|
declare function isFunction(value: unknown): value is (...args: any[]) => any;
|
|
49
49
|
/**
|
|
50
50
|
* Type guard to check if a value is a Promise or thenable object.
|
|
51
51
|
*
|
|
52
|
-
* Returns true if the value is an object with a `then` method that is a
|
|
53
|
-
* This covers both native Promises and thenable objects that
|
|
54
|
-
* Promise interface.
|
|
52
|
+
* Returns true if the value is an object with a `then` method that is a
|
|
53
|
+
* function. This covers both native Promises and thenable objects that
|
|
54
|
+
* implement the Promise interface.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* if (isPromise(value)) {
|
|
59
|
+
* // TypeScript knows value is Promise<unknown>
|
|
60
|
+
* const result = await value;
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
* isPromise(Promise.resolve()); // true
|
|
64
|
+
* isPromise(new Promise(() => {})); // true
|
|
65
|
+
* isPromise({ then: () => {} }); // true
|
|
66
|
+
* isPromise({ then: 'not a function' }); // false
|
|
67
|
+
* isPromise('string'); // false
|
|
68
|
+
* ```;
|
|
55
69
|
*
|
|
56
70
|
* @param value - The value to check
|
|
57
71
|
* @returns True if the value is a Promise or thenable, false otherwise
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* if (isPromise(value)) {
|
|
62
|
-
* // TypeScript knows value is Promise<unknown>
|
|
63
|
-
* const result = await value;
|
|
64
|
-
* }
|
|
65
|
-
*
|
|
66
|
-
* isPromise(Promise.resolve()); // true
|
|
67
|
-
* isPromise(new Promise(() => {})); // true
|
|
68
|
-
* isPromise({ then: () => {} }); // true
|
|
69
|
-
* isPromise({ then: 'not a function' }); // false
|
|
70
|
-
* isPromise('string'); // false
|
|
71
|
-
* ```
|
|
72
72
|
*/
|
|
73
73
|
declare function isPromise(value: unknown): value is Promise<unknown>;
|
|
74
74
|
/**
|
|
75
|
-
* Type guard to check if a value is a plain object (created by Object literal
|
|
75
|
+
* Type guard to check if a value is a plain object (created by Object literal
|
|
76
|
+
* or Object constructor).
|
|
76
77
|
*
|
|
77
78
|
* Returns true if the value is a plain object - an object created by the Object
|
|
78
79
|
* constructor or object literal syntax. This excludes instances of classes,
|
|
79
80
|
* built-in objects like Date, RegExp, etc.
|
|
80
81
|
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* if (isPlainObject(value)) {
|
|
85
|
+
* // TypeScript knows value is Record<string, unknown>
|
|
86
|
+
* console.log(Object.keys(value));
|
|
87
|
+
* }
|
|
88
|
+
*
|
|
89
|
+
* isPlainObject({}); // true
|
|
90
|
+
* isPlainObject({ a: 1 }); // true
|
|
91
|
+
* isPlainObject(Object.create(null)); // true
|
|
92
|
+
* isPlainObject(new Date()); // false
|
|
93
|
+
* isPlainObject(/regex/); // false
|
|
94
|
+
* isPlainObject(new MyClass()); // false
|
|
95
|
+
* isPlainObject([]); // false
|
|
96
|
+
* ```;
|
|
97
|
+
*
|
|
81
98
|
* @param value - The value to check
|
|
82
99
|
* @returns True if the value is a plain object, false otherwise
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```typescript
|
|
86
|
-
* if (isPlainObject(value)) {
|
|
87
|
-
* // TypeScript knows value is Record<string, unknown>
|
|
88
|
-
* console.log(Object.keys(value));
|
|
89
|
-
* }
|
|
90
|
-
*
|
|
91
|
-
* isPlainObject({}); // true
|
|
92
|
-
* isPlainObject({ a: 1 }); // true
|
|
93
|
-
* isPlainObject(Object.create(null)); // true
|
|
94
|
-
* isPlainObject(new Date()); // false
|
|
95
|
-
* isPlainObject(/regex/); // false
|
|
96
|
-
* isPlainObject(new MyClass()); // false
|
|
97
|
-
* isPlainObject([]); // false
|
|
98
|
-
* ```
|
|
99
100
|
*/
|
|
100
101
|
declare function isPlainObject(value: any): value is Record<string, unknown>;
|
|
101
102
|
type NonEmptyArray<T> = [T, ...T[]];
|
package/dist/typeGuards.d.ts
CHANGED
|
@@ -4,98 +4,99 @@
|
|
|
4
4
|
* Returns true if the value is an object that is not null and not an array.
|
|
5
5
|
* This is useful for distinguishing between objects and other types.
|
|
6
6
|
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* if (isObject(value)) {
|
|
10
|
+
* // TypeScript knows value is Record<string, unknown>
|
|
11
|
+
* console.log(value.someProperty);
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* isObject({}); // true
|
|
15
|
+
* isObject({ a: 1 }); // true
|
|
16
|
+
* isObject(null); // false
|
|
17
|
+
* isObject([]); // false
|
|
18
|
+
* isObject('string'); // false
|
|
19
|
+
* ```;
|
|
20
|
+
*
|
|
7
21
|
* @param value - The value to check
|
|
8
22
|
* @returns True if the value is a plain object, false otherwise
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* if (isObject(value)) {
|
|
13
|
-
* // TypeScript knows value is Record<string, unknown>
|
|
14
|
-
* console.log(value.someProperty);
|
|
15
|
-
* }
|
|
16
|
-
*
|
|
17
|
-
* isObject({}); // true
|
|
18
|
-
* isObject({ a: 1 }); // true
|
|
19
|
-
* isObject(null); // false
|
|
20
|
-
* isObject([]); // false
|
|
21
|
-
* isObject('string'); // false
|
|
22
|
-
* ```
|
|
23
23
|
*/
|
|
24
24
|
declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
25
25
|
/**
|
|
26
26
|
* Type guard to check if a value is a function.
|
|
27
27
|
*
|
|
28
|
-
* Returns true if the value is a function of any kind (regular function,
|
|
29
|
-
*
|
|
28
|
+
* Returns true if the value is a function of any kind (regular function, arrow
|
|
29
|
+
* function, method, constructor, etc.).
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* if (isFunction(value)) {
|
|
34
|
+
* // TypeScript knows value is (...args: any[]) => any
|
|
35
|
+
* const result = value();
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* isFunction(() => {}); // true
|
|
39
|
+
* isFunction(function() {}); // true
|
|
40
|
+
* isFunction(Math.max); // true
|
|
41
|
+
* isFunction('string'); // false
|
|
42
|
+
* isFunction({}); // false
|
|
43
|
+
* ```;
|
|
30
44
|
*
|
|
31
45
|
* @param value - The value to check
|
|
32
46
|
* @returns True if the value is a function, false otherwise
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* if (isFunction(value)) {
|
|
37
|
-
* // TypeScript knows value is (...args: any[]) => any
|
|
38
|
-
* const result = value();
|
|
39
|
-
* }
|
|
40
|
-
*
|
|
41
|
-
* isFunction(() => {}); // true
|
|
42
|
-
* isFunction(function() {}); // true
|
|
43
|
-
* isFunction(Math.max); // true
|
|
44
|
-
* isFunction('string'); // false
|
|
45
|
-
* isFunction({}); // false
|
|
46
|
-
* ```
|
|
47
47
|
*/
|
|
48
48
|
declare function isFunction(value: unknown): value is (...args: any[]) => any;
|
|
49
49
|
/**
|
|
50
50
|
* Type guard to check if a value is a Promise or thenable object.
|
|
51
51
|
*
|
|
52
|
-
* Returns true if the value is an object with a `then` method that is a
|
|
53
|
-
* This covers both native Promises and thenable objects that
|
|
54
|
-
* Promise interface.
|
|
52
|
+
* Returns true if the value is an object with a `then` method that is a
|
|
53
|
+
* function. This covers both native Promises and thenable objects that
|
|
54
|
+
* implement the Promise interface.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* if (isPromise(value)) {
|
|
59
|
+
* // TypeScript knows value is Promise<unknown>
|
|
60
|
+
* const result = await value;
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
* isPromise(Promise.resolve()); // true
|
|
64
|
+
* isPromise(new Promise(() => {})); // true
|
|
65
|
+
* isPromise({ then: () => {} }); // true
|
|
66
|
+
* isPromise({ then: 'not a function' }); // false
|
|
67
|
+
* isPromise('string'); // false
|
|
68
|
+
* ```;
|
|
55
69
|
*
|
|
56
70
|
* @param value - The value to check
|
|
57
71
|
* @returns True if the value is a Promise or thenable, false otherwise
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* if (isPromise(value)) {
|
|
62
|
-
* // TypeScript knows value is Promise<unknown>
|
|
63
|
-
* const result = await value;
|
|
64
|
-
* }
|
|
65
|
-
*
|
|
66
|
-
* isPromise(Promise.resolve()); // true
|
|
67
|
-
* isPromise(new Promise(() => {})); // true
|
|
68
|
-
* isPromise({ then: () => {} }); // true
|
|
69
|
-
* isPromise({ then: 'not a function' }); // false
|
|
70
|
-
* isPromise('string'); // false
|
|
71
|
-
* ```
|
|
72
72
|
*/
|
|
73
73
|
declare function isPromise(value: unknown): value is Promise<unknown>;
|
|
74
74
|
/**
|
|
75
|
-
* Type guard to check if a value is a plain object (created by Object literal
|
|
75
|
+
* Type guard to check if a value is a plain object (created by Object literal
|
|
76
|
+
* or Object constructor).
|
|
76
77
|
*
|
|
77
78
|
* Returns true if the value is a plain object - an object created by the Object
|
|
78
79
|
* constructor or object literal syntax. This excludes instances of classes,
|
|
79
80
|
* built-in objects like Date, RegExp, etc.
|
|
80
81
|
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* if (isPlainObject(value)) {
|
|
85
|
+
* // TypeScript knows value is Record<string, unknown>
|
|
86
|
+
* console.log(Object.keys(value));
|
|
87
|
+
* }
|
|
88
|
+
*
|
|
89
|
+
* isPlainObject({}); // true
|
|
90
|
+
* isPlainObject({ a: 1 }); // true
|
|
91
|
+
* isPlainObject(Object.create(null)); // true
|
|
92
|
+
* isPlainObject(new Date()); // false
|
|
93
|
+
* isPlainObject(/regex/); // false
|
|
94
|
+
* isPlainObject(new MyClass()); // false
|
|
95
|
+
* isPlainObject([]); // false
|
|
96
|
+
* ```;
|
|
97
|
+
*
|
|
81
98
|
* @param value - The value to check
|
|
82
99
|
* @returns True if the value is a plain object, false otherwise
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```typescript
|
|
86
|
-
* if (isPlainObject(value)) {
|
|
87
|
-
* // TypeScript knows value is Record<string, unknown>
|
|
88
|
-
* console.log(Object.keys(value));
|
|
89
|
-
* }
|
|
90
|
-
*
|
|
91
|
-
* isPlainObject({}); // true
|
|
92
|
-
* isPlainObject({ a: 1 }); // true
|
|
93
|
-
* isPlainObject(Object.create(null)); // true
|
|
94
|
-
* isPlainObject(new Date()); // false
|
|
95
|
-
* isPlainObject(/regex/); // false
|
|
96
|
-
* isPlainObject(new MyClass()); // false
|
|
97
|
-
* isPlainObject([]); // false
|
|
98
|
-
* ```
|
|
99
100
|
*/
|
|
100
101
|
declare function isPlainObject(value: any): value is Record<string, unknown>;
|
|
101
102
|
type NonEmptyArray<T> = [T, ...T[]];
|
package/dist/typeUtils.d.cts
CHANGED
|
@@ -4,6 +4,10 @@ type PartialRecord<K extends keyof any, T> = {
|
|
|
4
4
|
type NonPartial<T> = {
|
|
5
5
|
[K in keyof Required<T>]: T[K];
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `ObjKeysWithValuesOfType` from `@ls-stack/utils/typeUtils`
|
|
9
|
+
* instead
|
|
10
|
+
*/
|
|
7
11
|
type ObjKeysWithValuesOfType<Obj extends Record<PropertyKey, unknown>, ValueType> = {
|
|
8
12
|
[K in keyof Obj]: Obj[K] extends ValueType ? K : never;
|
|
9
13
|
}[keyof Obj];
|
|
@@ -26,12 +30,14 @@ type DeepReplaceValueImpl<T, ReplaceType, NewType, SkipPaths extends string | un
|
|
|
26
30
|
[K in keyof T]: DeepReplaceValueImpl<T[K], ReplaceType, NewType, SkipPaths, SkipType, BuildPath<Path, K>>;
|
|
27
31
|
} : T;
|
|
28
32
|
/**
|
|
29
|
-
* Replaces all values that extends `ReplaceType` with `NewType` in a deeply
|
|
33
|
+
* Replaces all values that extends `ReplaceType` with `NewType` in a deeply
|
|
34
|
+
* nested object or array.
|
|
30
35
|
*
|
|
31
36
|
* @template T - The object or array to replace values in.
|
|
32
37
|
* @template ReplaceType - The type to replace.
|
|
33
38
|
* @template NewType - The new type to replace with.
|
|
34
|
-
* @template SkipPaths - The paths to skip in transverse. e.g. 'a.b.c' |
|
|
39
|
+
* @template SkipPaths - The paths to skip in transverse. e.g. 'a.b.c' |
|
|
40
|
+
* 'array[*].b'
|
|
35
41
|
* @template SkipTypes - The types to skip in transverse and replace.
|
|
36
42
|
*/
|
|
37
43
|
type DeepReplaceValue<T, ReplaceType, NewType, SkipPaths extends string | undefined = undefined, SkipTypes = DefaultSkipTransverseDeepReplace> = DeepReplaceValueImpl<T, ReplaceType, NewType, SkipPaths, SkipTypes>;
|
|
@@ -39,8 +45,16 @@ type KeysWithUndefinedValues<T extends Record<string, unknown>> = {
|
|
|
39
45
|
[K in keyof T]: undefined extends T[K] ? K : never;
|
|
40
46
|
}[keyof T];
|
|
41
47
|
/**
|
|
42
|
-
* Marks all possible undefined values as partial at the root level of the
|
|
48
|
+
* Marks all possible undefined values as partial at the root level of the
|
|
49
|
+
* object.
|
|
43
50
|
*/
|
|
44
51
|
type PartialPossiblyUndefinedValues<T extends Record<string, unknown>> = Prettify<Partial<Pick<T, KeysWithUndefinedValues<T>>> & Omit<T, KeysWithUndefinedValues<T>>>;
|
|
52
|
+
type PickUndefinedKeys<T> = {
|
|
53
|
+
[K in keyof T]: undefined extends T[K] ? K : never;
|
|
54
|
+
}[keyof T];
|
|
55
|
+
type PickRequiredKeys<T> = {
|
|
56
|
+
[K in keyof T]: undefined extends T[K] ? never : K;
|
|
57
|
+
}[keyof T];
|
|
58
|
+
type MakeUndefinedKeysOptional<T> = Prettify<Partial<Pick<T, PickUndefinedKeys<T>>> & Pick<T, PickRequiredKeys<T>>>;
|
|
45
59
|
|
|
46
|
-
export type { DeepPrettify, DeepReplaceValue, DefaultSkipTransverseDeepReplace, IsAny, NonPartial, ObjKeysWithValuesOfType, PartialPossiblyUndefinedValues, PartialRecord, Prettify };
|
|
60
|
+
export type { DeepPrettify, DeepReplaceValue, DefaultSkipTransverseDeepReplace, IsAny, MakeUndefinedKeysOptional, NonPartial, ObjKeysWithValuesOfType, PartialPossiblyUndefinedValues, PartialRecord, Prettify };
|