@ls-stack/utils 3.40.0 → 3.42.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.
Files changed (159) hide show
  1. package/dist/arrayUtils.d.cts +70 -57
  2. package/dist/arrayUtils.d.ts +70 -57
  3. package/dist/assertions.d.cts +128 -117
  4. package/dist/assertions.d.ts +128 -117
  5. package/dist/asyncQueue.cjs +117 -112
  6. package/dist/asyncQueue.d.cts +217 -215
  7. package/dist/asyncQueue.d.ts +217 -215
  8. package/dist/asyncQueue.js +117 -112
  9. package/dist/awaitDebounce.d.cts +26 -23
  10. package/dist/awaitDebounce.d.ts +26 -23
  11. package/dist/cache.cjs +2 -1
  12. package/dist/cache.d.cts +15 -9
  13. package/dist/cache.d.ts +15 -9
  14. package/dist/cache.js +2 -1
  15. package/dist/{chunk-ADM37GSC.js → chunk-7L4KCZJJ.js} +12 -10
  16. package/dist/{chunk-KW55OTUG.js → chunk-B3KFV2MH.js} +2 -2
  17. package/dist/chunk-GMJTLFM6.js +60 -0
  18. package/dist/{chunk-GHAQOUA6.js → chunk-Y45CE75W.js} +22 -1
  19. package/dist/concurrentCalls.d.cts +8 -4
  20. package/dist/concurrentCalls.d.ts +8 -4
  21. package/dist/concurrentCalls.js +1 -1
  22. package/dist/debounce.d.cts +12 -20
  23. package/dist/debounce.d.ts +12 -20
  24. package/dist/dedent.d.cts +31 -31
  25. package/dist/dedent.d.ts +31 -31
  26. package/dist/deepEqual.d.cts +10 -9
  27. package/dist/deepEqual.d.ts +10 -9
  28. package/dist/filterObjectOrArrayKeys.d.cts +44 -19
  29. package/dist/filterObjectOrArrayKeys.d.ts +44 -19
  30. package/dist/getAutoIncrementId.d.cts +25 -23
  31. package/dist/getAutoIncrementId.d.ts +25 -23
  32. package/dist/getCompositeKey.d.cts +2 -1
  33. package/dist/getCompositeKey.d.ts +2 -1
  34. package/dist/getValueStableKey.d.cts +4 -3
  35. package/dist/getValueStableKey.d.ts +4 -3
  36. package/dist/mutationUtils.d.cts +2 -2
  37. package/dist/mutationUtils.d.ts +2 -2
  38. package/dist/objUtils.cjs +51 -2
  39. package/dist/objUtils.d.cts +8 -3
  40. package/dist/objUtils.d.ts +8 -3
  41. package/dist/objUtils.js +11 -3
  42. package/dist/parallelAsyncCalls.cjs +2 -1
  43. package/dist/parallelAsyncCalls.d.cts +5 -4
  44. package/dist/parallelAsyncCalls.d.ts +5 -4
  45. package/dist/parallelAsyncCalls.js +2 -1
  46. package/dist/retryOnError.d.cts +23 -20
  47. package/dist/retryOnError.d.ts +23 -20
  48. package/dist/runShellCmd.d.cts +40 -40
  49. package/dist/runShellCmd.d.ts +40 -40
  50. package/dist/safeJson.d.cts +6 -2
  51. package/dist/safeJson.d.ts +6 -2
  52. package/dist/saferTyping.d.cts +21 -14
  53. package/dist/saferTyping.d.ts +21 -14
  54. package/dist/shallowEqual.d.cts +1 -1
  55. package/dist/shallowEqual.d.ts +1 -1
  56. package/dist/stringUtils.cjs +2 -2
  57. package/dist/stringUtils.d.cts +6 -7
  58. package/dist/stringUtils.d.ts +6 -7
  59. package/dist/stringUtils.js +1 -1
  60. package/dist/testUtils.cjs +11 -9
  61. package/dist/testUtils.d.cts +32 -14
  62. package/dist/testUtils.d.ts +32 -14
  63. package/dist/testUtils.js +4 -3
  64. package/dist/throttle.d.cts +57 -48
  65. package/dist/throttle.d.ts +57 -48
  66. package/dist/timers.d.cts +68 -63
  67. package/dist/timers.d.ts +68 -63
  68. package/dist/tsResult.d.cts +7 -6
  69. package/dist/tsResult.d.ts +7 -6
  70. package/dist/typeGuards.d.cts +65 -64
  71. package/dist/typeGuards.d.ts +65 -64
  72. package/dist/typeUtils.d.cts +18 -4
  73. package/dist/typeUtils.d.ts +18 -4
  74. package/dist/typedStrings.d.cts +68 -57
  75. package/dist/typedStrings.d.ts +68 -57
  76. package/dist/typingFnUtils.cjs +15 -0
  77. package/dist/typingFnUtils.d.cts +34 -7
  78. package/dist/typingFnUtils.d.ts +34 -7
  79. package/dist/typingFnUtils.js +18 -35
  80. package/dist/typingTestUtils.cjs +7 -1
  81. package/dist/typingTestUtils.d.cts +52 -11
  82. package/dist/typingTestUtils.d.ts +52 -11
  83. package/dist/typingTestUtils.js +7 -1
  84. package/dist/typingUtils.d.cts +4 -1
  85. package/dist/typingUtils.d.ts +4 -1
  86. package/dist/yamlStringify.cjs +11 -9
  87. package/dist/yamlStringify.js +2 -2
  88. package/package.json +5 -1
  89. package/docs/README.md +0 -72
  90. package/docs/_media/modules.md +0 -58
  91. package/docs/arrayUtils/-internal-.md +0 -179
  92. package/docs/arrayUtils/README.md +0 -550
  93. package/docs/assertions/-internal-.md +0 -63
  94. package/docs/assertions/README.md +0 -565
  95. package/docs/asyncQueue/-internal-.md +0 -297
  96. package/docs/asyncQueue/README.md +0 -1485
  97. package/docs/awaitDebounce.md +0 -66
  98. package/docs/cache/-internal-.md +0 -168
  99. package/docs/cache/README.md +0 -360
  100. package/docs/castValues.md +0 -47
  101. package/docs/concurrentCalls/-internal-.md +0 -490
  102. package/docs/concurrentCalls/README.md +0 -299
  103. package/docs/consoleFmt.md +0 -115
  104. package/docs/conversions.md +0 -27
  105. package/docs/createThrottleController/-internal-.md +0 -73
  106. package/docs/createThrottleController/README.md +0 -31
  107. package/docs/debounce.md +0 -188
  108. package/docs/dedent/-internal-.md +0 -17
  109. package/docs/dedent/README.md +0 -204
  110. package/docs/deepEqual.md +0 -94
  111. package/docs/enhancedMap.md +0 -358
  112. package/docs/exhaustiveMatch/-internal-.md +0 -39
  113. package/docs/exhaustiveMatch/README.md +0 -146
  114. package/docs/filterObjectOrArrayKeys.md +0 -109
  115. package/docs/getAutoIncrementId.md +0 -93
  116. package/docs/getCompositeKey.md +0 -39
  117. package/docs/getValueStableKey.md +0 -57
  118. package/docs/hash.md +0 -31
  119. package/docs/interpolate/-internal-.md +0 -61
  120. package/docs/interpolate/README.md +0 -62
  121. package/docs/keepPrevIfUnchanged.md +0 -43
  122. package/docs/levenshtein.md +0 -93
  123. package/docs/main.md +0 -21
  124. package/docs/mathUtils.md +0 -137
  125. package/docs/modules.md +0 -58
  126. package/docs/mutationUtils.md +0 -44
  127. package/docs/objUtils.md +0 -237
  128. package/docs/parallelAsyncCalls/-internal-.md +0 -347
  129. package/docs/parallelAsyncCalls/README.md +0 -45
  130. package/docs/promiseUtils/-internal-.md +0 -69
  131. package/docs/promiseUtils/README.md +0 -31
  132. package/docs/retryOnError/-internal-.md +0 -111
  133. package/docs/retryOnError/README.md +0 -168
  134. package/docs/runShellCmd/-internal-.md +0 -111
  135. package/docs/runShellCmd/README.md +0 -201
  136. package/docs/safeJson.md +0 -51
  137. package/docs/saferTyping.md +0 -228
  138. package/docs/serializeXML.md +0 -100
  139. package/docs/shallowEqual.md +0 -33
  140. package/docs/sleep.md +0 -27
  141. package/docs/stringUtils/-internal-.md +0 -17
  142. package/docs/stringUtils/README.md +0 -270
  143. package/docs/testUtils.md +0 -382
  144. package/docs/throttle/-internal-.md +0 -47
  145. package/docs/throttle/README.md +0 -178
  146. package/docs/time.md +0 -274
  147. package/docs/timers.md +0 -256
  148. package/docs/tsResult/-internal-.md +0 -327
  149. package/docs/tsResult/README.md +0 -702
  150. package/docs/typeGuards.md +0 -399
  151. package/docs/typeUtils/-internal-.md +0 -99
  152. package/docs/typeUtils/README.md +0 -195
  153. package/docs/typeUtils.typesTest.md +0 -7
  154. package/docs/typedStrings.md +0 -458
  155. package/docs/typingFnUtils/-internal-.md +0 -43
  156. package/docs/typingFnUtils/README.md +0 -317
  157. package/docs/typingTestUtils.md +0 -172
  158. package/docs/typingUtils.md +0 -135
  159. package/docs/yamlStringify.md +0 -83
@@ -5,177 +5,188 @@ type StrictNonUndefined<T, N = unknown> = undefined extends T ? NotUndefined<T>
5
5
  /**
6
6
  * Ensures a value is not undefined and returns it with the correct type.
7
7
  *
8
- * Throws an error if the value is undefined. Use it instead of `!` operator for better type safety.
8
+ * Throws an error if the value is undefined. Use it instead of `!` operator for
9
+ * better type safety.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const maybeString: string | undefined = getValue();
14
+ * const definiteString = notUndefined(maybeString); // Type: string
15
+ *
16
+ * // With custom error message
17
+ * const value = notUndefined(maybeValue, 'Value must be defined');
18
+ *
19
+ * // With custom error function
20
+ * const value = notUndefined(maybeValue, () => new ValidationError('Required field'));
21
+ * ```;
9
22
  *
10
23
  * @template T - The type of the input value
11
24
  * @param value - The value to check for undefined
12
- * @param error - Error message string or function that returns an Error to throw if value is undefined
25
+ * @param error - Error message string or function that returns an Error to
26
+ * throw if value is undefined
13
27
  * @returns The input value with undefined excluded from its type
14
28
  * @throws {Error} When the value is undefined
15
- *
16
- * @example
17
- * ```typescript
18
- * const maybeString: string | undefined = getValue();
19
- * const definiteString = notUndefined(maybeString); // Type: string
20
- *
21
- * // With custom error message
22
- * const value = notUndefined(maybeValue, 'Value must be defined');
23
- *
24
- * // With custom error function
25
- * const value = notUndefined(maybeValue, () => new ValidationError('Required field'));
26
- * ```
27
29
  */
28
30
  declare function notUndefined<T>(value: T, error?: string | (() => Error)): StrictNonUndefined<T>;
29
31
  type StrictNonNullable<T, N = unknown> = undefined extends T ? NonNullable<T> : null extends T ? NonNullable<T> : N;
30
32
  /**
31
- * Ensures a value is not null or undefined and returns it with the correct type.
33
+ * Ensures a value is not null or undefined and returns it with the correct
34
+ * type.
35
+ *
36
+ * Throws an error if the value is null or undefined. Use it instead of `!`
37
+ * operator for better type safety.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const maybeString: string | null | undefined = getValue();
42
+ * const definiteString = notNullish(maybeString); // Type: string
43
+ *
44
+ * // With custom error message
45
+ * const value = notNullish(maybeValue, 'Value cannot be null or undefined');
32
46
  *
33
- * Throws an error if the value is null or undefined. Use it instead of `!` operator for better type safety.
47
+ * // With custom error function
48
+ * const value = notNullish(maybeValue, () => new ValidationError('Required field'));
49
+ * ```;
34
50
  *
35
51
  * @template T - The type of the input value
36
52
  * @param value - The value to check for null or undefined
37
- * @param error - Error message string or function that returns an Error to throw if value is nullish
53
+ * @param error - Error message string or function that returns an Error to
54
+ * throw if value is nullish
38
55
  * @returns The input value with null and undefined excluded from its type
39
56
  * @throws {Error} When the value is null or undefined
40
- *
41
- * @example
42
- * ```typescript
43
- * const maybeString: string | null | undefined = getValue();
44
- * const definiteString = notNullish(maybeString); // Type: string
45
- *
46
- * // With custom error message
47
- * const value = notNullish(maybeValue, 'Value cannot be null or undefined');
48
- *
49
- * // With custom error function
50
- * const value = notNullish(maybeValue, () => new ValidationError('Required field'));
51
- * ```
52
57
  */
53
58
  declare function notNullish<T>(value: T, error?: string | (() => Error)): StrictNonNullable<T>;
54
59
  /**
55
- * Asserts that a value is not null or undefined using TypeScript's assertion signature.
60
+ * Asserts that a value is not null or undefined using TypeScript's assertion
61
+ * signature.
56
62
  *
57
- * Throws an error if the value is null or undefined. Use it instead of `!` operator for better type safety.
63
+ * Throws an error if the value is null or undefined. Use it instead of `!`
64
+ * operator for better type safety.
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * function processValue(input: string | null | undefined) {
69
+ * assertIsNotNullish(input);
70
+ * // TypeScript now knows input is string
71
+ * console.log(input.toUpperCase());
72
+ * }
73
+ *
74
+ * // With custom error
75
+ * assertIsNotNullish(value, 'Value is required for processing');
76
+ * ```;
58
77
  *
59
78
  * @template T - The type of the input value
60
79
  * @param value - The value to assert is not null or undefined
61
- * @param error - Error message string or function that returns an Error to throw if value is nullish
80
+ * @param error - Error message string or function that returns an Error to
81
+ * throw if value is nullish
62
82
  * @throws {Error} When the value is null or undefined
63
- *
64
- * @example
65
- * ```typescript
66
- * function processValue(input: string | null | undefined) {
67
- * assertIsNotNullish(input);
68
- * // TypeScript now knows input is string
69
- * console.log(input.toUpperCase());
70
- * }
71
- *
72
- * // With custom error
73
- * assertIsNotNullish(value, 'Value is required for processing');
74
- * ```
75
83
  */
76
84
  declare function assertIsNotNullish<T>(value: T, error?: string | (() => Error)): asserts value is StrictNonNullable<T, never>;
77
85
  /**
78
86
  * Asserts that a value is not undefined using TypeScript's assertion signature.
79
87
  *
80
- * Throws an error if the value is undefined. Use it instead of `!` operator for better type safety.
88
+ * Throws an error if the value is undefined. Use it instead of `!` operator for
89
+ * better type safety.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * function processValue(input: string | undefined) {
94
+ * assertIsNotUndefined(input);
95
+ * // TypeScript now knows input is string
96
+ * console.log(input.toUpperCase());
97
+ * }
98
+ *
99
+ * // With custom error
100
+ * assertIsNotUndefined(value, 'Value must be defined');
101
+ * ```;
81
102
  *
82
103
  * @template T - The type of the input value
83
104
  * @param value - The value to assert is not undefined
84
- * @param error - Error message string or function that returns an Error to throw if value is undefined
105
+ * @param error - Error message string or function that returns an Error to
106
+ * throw if value is undefined
85
107
  * @throws {Error} When the value is undefined
86
- *
87
- * @example
88
- * ```typescript
89
- * function processValue(input: string | undefined) {
90
- * assertIsNotUndefined(input);
91
- * // TypeScript now knows input is string
92
- * console.log(input.toUpperCase());
93
- * }
94
- *
95
- * // With custom error
96
- * assertIsNotUndefined(value, 'Value must be defined');
97
- * ```
98
108
  */
99
109
  declare function assertIsNotUndefined<T>(value: T, error?: string | (() => Error)): asserts value is StrictNonUndefined<T, never>;
100
110
  /**
101
111
  * Asserts that a condition is always true, throwing an error if it's falsy.
102
112
  *
103
- * This function is useful for enforcing invariants in your code - conditions that
104
- * should always be true. It uses TypeScript's assertion signature to narrow types
105
- * based on the condition.
113
+ * This function is useful for enforcing invariants in your code - conditions
114
+ * that should always be true. It uses TypeScript's assertion signature to
115
+ * narrow types based on the condition.
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * function divide(a: number, b: number) {
120
+ * invariant(b !== 0, 'Division by zero is not allowed');
121
+ * return a / b;
122
+ * }
123
+ *
124
+ * // Type narrowing example
125
+ * function processUser(user: User | null) {
126
+ * invariant(user, 'User must be logged in');
127
+ * // TypeScript now knows user is User, not null
128
+ * console.log(user.name);
129
+ * }
130
+ *
131
+ * // With custom error function
132
+ * invariant(isValid, () => new ValidationError('Invalid state detected'));
133
+ * ```;
106
134
  *
107
135
  * @param condition - The condition to check (any truthy/falsy value)
108
- * @param error - Error message string or function that returns an Error to throw if condition is falsy
136
+ * @param error - Error message string or function that returns an Error to
137
+ * throw if condition is falsy
109
138
  * @throws {Error} When the condition is falsy
110
- *
111
- * @example
112
- * ```typescript
113
- * function divide(a: number, b: number) {
114
- * invariant(b !== 0, 'Division by zero is not allowed');
115
- * return a / b;
116
- * }
117
- *
118
- * // Type narrowing example
119
- * function processUser(user: User | null) {
120
- * invariant(user, 'User must be logged in');
121
- * // TypeScript now knows user is User, not null
122
- * console.log(user.name);
123
- * }
124
- *
125
- * // With custom error function
126
- * invariant(isValid, () => new ValidationError('Invalid state detected'));
127
- * ```
128
139
  */
129
140
  declare function invariant(condition: any, error?: string | (() => Error)): asserts condition;
130
141
  /**
131
142
  * Ensures exhaustive type checking in switch statements or conditional logic.
132
143
  *
133
- * This function should be used in the default case of switch statements or
134
- * the final else branch of conditional logic to ensure all possible cases
135
- * are handled. It helps catch missing cases at compile time when new union
136
- * members are added.
137
- *
138
- * @template Except - The type that should never be reached
139
- * @param narrowedType - The value that should never exist at runtime
140
- * @returns An Error object (this function should never actually execute)
144
+ * This function should be used in the default case of switch statements or the
145
+ * final else branch of conditional logic to ensure all possible cases are
146
+ * handled. It helps catch missing cases at compile time when new union members
147
+ * are added.
141
148
  *
142
149
  * @example
143
- * ```typescript
144
- * type Status = 'pending' | 'success' | 'error';
145
- *
146
- * function handleStatus(status: Status) {
147
- * switch (status) {
148
- * case 'pending':
149
- * return 'Loading...';
150
- * case 'success':
151
- * return 'Done!';
152
- * case 'error':
153
- * return 'Failed!';
154
- * default:
155
- * throw exhaustiveCheck(status); // TypeScript error if Status gains new members
150
+ * ```typescript
151
+ * type Status = 'pending' | 'success' | 'error';
152
+ *
153
+ * function handleStatus(status: Status) {
154
+ * switch (status) {
155
+ * case 'pending':
156
+ * return 'Loading...';
157
+ * case 'success':
158
+ * return 'Done!';
159
+ * case 'error':
160
+ * return 'Failed!';
161
+ * default:
162
+ * throw exhaustiveCheck(status); // TypeScript error if Status gains new members
163
+ * }
156
164
  * }
157
- * }
158
- *
159
- * // In conditional logic
160
- * function processValue(value: string | number) {
161
- * if (typeof value === 'string') {
162
- * return value.toUpperCase();
163
- * } else if (typeof value === 'number') {
164
- * return value.toString();
165
- * } else {
166
- * throw exhaustiveCheck(value); // Ensures all cases are covered
165
+ *
166
+ * // In conditional logic
167
+ * function processValue(value: string | number) {
168
+ * if (typeof value === 'string') {
169
+ * return value.toUpperCase();
170
+ * } else if (typeof value === 'number') {
171
+ * return value.toString();
172
+ * } else {
173
+ * throw exhaustiveCheck(value); // Ensures all cases are covered
174
+ * }
167
175
  * }
168
- * }
169
- * ```
176
+ * ```;
177
+ *
178
+ * @template Except - The type that should never be reached
179
+ * @param narrowedType - The value that should never exist at runtime
180
+ * @returns An Error object (this function should never actually execute)
170
181
  */
171
182
  declare function exhaustiveCheck<Except = never>(narrowedType: NoInfer<Except>): Error;
172
- /** @deprecated use import from `@ls-stack/typeGuards` instead */
183
+ /** @deprecated Use import from `@ls-stack/typeGuards` instead */
173
184
  declare const isFunction: typeof isFunction$1;
174
- /** @deprecated use import from `@ls-stack/typeGuards` instead */
185
+ /** @deprecated Use import from `@ls-stack/typeGuards` instead */
175
186
  declare const isObject: typeof isObject$1;
176
- /** @deprecated use import from `@ls-stack/typeGuards` instead */
187
+ /** @deprecated Use import from `@ls-stack/typeGuards` instead */
177
188
  declare const isPlainObject: typeof isPlainObject$1;
178
- /** @deprecated use import from `@ls-stack/typeGuards` instead */
189
+ /** @deprecated Use import from `@ls-stack/typeGuards` instead */
179
190
  declare const isPromise: typeof isPromise$1;
180
191
 
181
192
  export { assertIsNotNullish, assertIsNotUndefined, exhaustiveCheck, invariant, isFunction, isObject, isPlainObject, isPromise, notNullish, notUndefined };
@@ -5,177 +5,188 @@ type StrictNonUndefined<T, N = unknown> = undefined extends T ? NotUndefined<T>
5
5
  /**
6
6
  * Ensures a value is not undefined and returns it with the correct type.
7
7
  *
8
- * Throws an error if the value is undefined. Use it instead of `!` operator for better type safety.
8
+ * Throws an error if the value is undefined. Use it instead of `!` operator for
9
+ * better type safety.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const maybeString: string | undefined = getValue();
14
+ * const definiteString = notUndefined(maybeString); // Type: string
15
+ *
16
+ * // With custom error message
17
+ * const value = notUndefined(maybeValue, 'Value must be defined');
18
+ *
19
+ * // With custom error function
20
+ * const value = notUndefined(maybeValue, () => new ValidationError('Required field'));
21
+ * ```;
9
22
  *
10
23
  * @template T - The type of the input value
11
24
  * @param value - The value to check for undefined
12
- * @param error - Error message string or function that returns an Error to throw if value is undefined
25
+ * @param error - Error message string or function that returns an Error to
26
+ * throw if value is undefined
13
27
  * @returns The input value with undefined excluded from its type
14
28
  * @throws {Error} When the value is undefined
15
- *
16
- * @example
17
- * ```typescript
18
- * const maybeString: string | undefined = getValue();
19
- * const definiteString = notUndefined(maybeString); // Type: string
20
- *
21
- * // With custom error message
22
- * const value = notUndefined(maybeValue, 'Value must be defined');
23
- *
24
- * // With custom error function
25
- * const value = notUndefined(maybeValue, () => new ValidationError('Required field'));
26
- * ```
27
29
  */
28
30
  declare function notUndefined<T>(value: T, error?: string | (() => Error)): StrictNonUndefined<T>;
29
31
  type StrictNonNullable<T, N = unknown> = undefined extends T ? NonNullable<T> : null extends T ? NonNullable<T> : N;
30
32
  /**
31
- * Ensures a value is not null or undefined and returns it with the correct type.
33
+ * Ensures a value is not null or undefined and returns it with the correct
34
+ * type.
35
+ *
36
+ * Throws an error if the value is null or undefined. Use it instead of `!`
37
+ * operator for better type safety.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const maybeString: string | null | undefined = getValue();
42
+ * const definiteString = notNullish(maybeString); // Type: string
43
+ *
44
+ * // With custom error message
45
+ * const value = notNullish(maybeValue, 'Value cannot be null or undefined');
32
46
  *
33
- * Throws an error if the value is null or undefined. Use it instead of `!` operator for better type safety.
47
+ * // With custom error function
48
+ * const value = notNullish(maybeValue, () => new ValidationError('Required field'));
49
+ * ```;
34
50
  *
35
51
  * @template T - The type of the input value
36
52
  * @param value - The value to check for null or undefined
37
- * @param error - Error message string or function that returns an Error to throw if value is nullish
53
+ * @param error - Error message string or function that returns an Error to
54
+ * throw if value is nullish
38
55
  * @returns The input value with null and undefined excluded from its type
39
56
  * @throws {Error} When the value is null or undefined
40
- *
41
- * @example
42
- * ```typescript
43
- * const maybeString: string | null | undefined = getValue();
44
- * const definiteString = notNullish(maybeString); // Type: string
45
- *
46
- * // With custom error message
47
- * const value = notNullish(maybeValue, 'Value cannot be null or undefined');
48
- *
49
- * // With custom error function
50
- * const value = notNullish(maybeValue, () => new ValidationError('Required field'));
51
- * ```
52
57
  */
53
58
  declare function notNullish<T>(value: T, error?: string | (() => Error)): StrictNonNullable<T>;
54
59
  /**
55
- * Asserts that a value is not null or undefined using TypeScript's assertion signature.
60
+ * Asserts that a value is not null or undefined using TypeScript's assertion
61
+ * signature.
56
62
  *
57
- * Throws an error if the value is null or undefined. Use it instead of `!` operator for better type safety.
63
+ * Throws an error if the value is null or undefined. Use it instead of `!`
64
+ * operator for better type safety.
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * function processValue(input: string | null | undefined) {
69
+ * assertIsNotNullish(input);
70
+ * // TypeScript now knows input is string
71
+ * console.log(input.toUpperCase());
72
+ * }
73
+ *
74
+ * // With custom error
75
+ * assertIsNotNullish(value, 'Value is required for processing');
76
+ * ```;
58
77
  *
59
78
  * @template T - The type of the input value
60
79
  * @param value - The value to assert is not null or undefined
61
- * @param error - Error message string or function that returns an Error to throw if value is nullish
80
+ * @param error - Error message string or function that returns an Error to
81
+ * throw if value is nullish
62
82
  * @throws {Error} When the value is null or undefined
63
- *
64
- * @example
65
- * ```typescript
66
- * function processValue(input: string | null | undefined) {
67
- * assertIsNotNullish(input);
68
- * // TypeScript now knows input is string
69
- * console.log(input.toUpperCase());
70
- * }
71
- *
72
- * // With custom error
73
- * assertIsNotNullish(value, 'Value is required for processing');
74
- * ```
75
83
  */
76
84
  declare function assertIsNotNullish<T>(value: T, error?: string | (() => Error)): asserts value is StrictNonNullable<T, never>;
77
85
  /**
78
86
  * Asserts that a value is not undefined using TypeScript's assertion signature.
79
87
  *
80
- * Throws an error if the value is undefined. Use it instead of `!` operator for better type safety.
88
+ * Throws an error if the value is undefined. Use it instead of `!` operator for
89
+ * better type safety.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * function processValue(input: string | undefined) {
94
+ * assertIsNotUndefined(input);
95
+ * // TypeScript now knows input is string
96
+ * console.log(input.toUpperCase());
97
+ * }
98
+ *
99
+ * // With custom error
100
+ * assertIsNotUndefined(value, 'Value must be defined');
101
+ * ```;
81
102
  *
82
103
  * @template T - The type of the input value
83
104
  * @param value - The value to assert is not undefined
84
- * @param error - Error message string or function that returns an Error to throw if value is undefined
105
+ * @param error - Error message string or function that returns an Error to
106
+ * throw if value is undefined
85
107
  * @throws {Error} When the value is undefined
86
- *
87
- * @example
88
- * ```typescript
89
- * function processValue(input: string | undefined) {
90
- * assertIsNotUndefined(input);
91
- * // TypeScript now knows input is string
92
- * console.log(input.toUpperCase());
93
- * }
94
- *
95
- * // With custom error
96
- * assertIsNotUndefined(value, 'Value must be defined');
97
- * ```
98
108
  */
99
109
  declare function assertIsNotUndefined<T>(value: T, error?: string | (() => Error)): asserts value is StrictNonUndefined<T, never>;
100
110
  /**
101
111
  * Asserts that a condition is always true, throwing an error if it's falsy.
102
112
  *
103
- * This function is useful for enforcing invariants in your code - conditions that
104
- * should always be true. It uses TypeScript's assertion signature to narrow types
105
- * based on the condition.
113
+ * This function is useful for enforcing invariants in your code - conditions
114
+ * that should always be true. It uses TypeScript's assertion signature to
115
+ * narrow types based on the condition.
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * function divide(a: number, b: number) {
120
+ * invariant(b !== 0, 'Division by zero is not allowed');
121
+ * return a / b;
122
+ * }
123
+ *
124
+ * // Type narrowing example
125
+ * function processUser(user: User | null) {
126
+ * invariant(user, 'User must be logged in');
127
+ * // TypeScript now knows user is User, not null
128
+ * console.log(user.name);
129
+ * }
130
+ *
131
+ * // With custom error function
132
+ * invariant(isValid, () => new ValidationError('Invalid state detected'));
133
+ * ```;
106
134
  *
107
135
  * @param condition - The condition to check (any truthy/falsy value)
108
- * @param error - Error message string or function that returns an Error to throw if condition is falsy
136
+ * @param error - Error message string or function that returns an Error to
137
+ * throw if condition is falsy
109
138
  * @throws {Error} When the condition is falsy
110
- *
111
- * @example
112
- * ```typescript
113
- * function divide(a: number, b: number) {
114
- * invariant(b !== 0, 'Division by zero is not allowed');
115
- * return a / b;
116
- * }
117
- *
118
- * // Type narrowing example
119
- * function processUser(user: User | null) {
120
- * invariant(user, 'User must be logged in');
121
- * // TypeScript now knows user is User, not null
122
- * console.log(user.name);
123
- * }
124
- *
125
- * // With custom error function
126
- * invariant(isValid, () => new ValidationError('Invalid state detected'));
127
- * ```
128
139
  */
129
140
  declare function invariant(condition: any, error?: string | (() => Error)): asserts condition;
130
141
  /**
131
142
  * Ensures exhaustive type checking in switch statements or conditional logic.
132
143
  *
133
- * This function should be used in the default case of switch statements or
134
- * the final else branch of conditional logic to ensure all possible cases
135
- * are handled. It helps catch missing cases at compile time when new union
136
- * members are added.
137
- *
138
- * @template Except - The type that should never be reached
139
- * @param narrowedType - The value that should never exist at runtime
140
- * @returns An Error object (this function should never actually execute)
144
+ * This function should be used in the default case of switch statements or the
145
+ * final else branch of conditional logic to ensure all possible cases are
146
+ * handled. It helps catch missing cases at compile time when new union members
147
+ * are added.
141
148
  *
142
149
  * @example
143
- * ```typescript
144
- * type Status = 'pending' | 'success' | 'error';
145
- *
146
- * function handleStatus(status: Status) {
147
- * switch (status) {
148
- * case 'pending':
149
- * return 'Loading...';
150
- * case 'success':
151
- * return 'Done!';
152
- * case 'error':
153
- * return 'Failed!';
154
- * default:
155
- * throw exhaustiveCheck(status); // TypeScript error if Status gains new members
150
+ * ```typescript
151
+ * type Status = 'pending' | 'success' | 'error';
152
+ *
153
+ * function handleStatus(status: Status) {
154
+ * switch (status) {
155
+ * case 'pending':
156
+ * return 'Loading...';
157
+ * case 'success':
158
+ * return 'Done!';
159
+ * case 'error':
160
+ * return 'Failed!';
161
+ * default:
162
+ * throw exhaustiveCheck(status); // TypeScript error if Status gains new members
163
+ * }
156
164
  * }
157
- * }
158
- *
159
- * // In conditional logic
160
- * function processValue(value: string | number) {
161
- * if (typeof value === 'string') {
162
- * return value.toUpperCase();
163
- * } else if (typeof value === 'number') {
164
- * return value.toString();
165
- * } else {
166
- * throw exhaustiveCheck(value); // Ensures all cases are covered
165
+ *
166
+ * // In conditional logic
167
+ * function processValue(value: string | number) {
168
+ * if (typeof value === 'string') {
169
+ * return value.toUpperCase();
170
+ * } else if (typeof value === 'number') {
171
+ * return value.toString();
172
+ * } else {
173
+ * throw exhaustiveCheck(value); // Ensures all cases are covered
174
+ * }
167
175
  * }
168
- * }
169
- * ```
176
+ * ```;
177
+ *
178
+ * @template Except - The type that should never be reached
179
+ * @param narrowedType - The value that should never exist at runtime
180
+ * @returns An Error object (this function should never actually execute)
170
181
  */
171
182
  declare function exhaustiveCheck<Except = never>(narrowedType: NoInfer<Except>): Error;
172
- /** @deprecated use import from `@ls-stack/typeGuards` instead */
183
+ /** @deprecated Use import from `@ls-stack/typeGuards` instead */
173
184
  declare const isFunction: typeof isFunction$1;
174
- /** @deprecated use import from `@ls-stack/typeGuards` instead */
185
+ /** @deprecated Use import from `@ls-stack/typeGuards` instead */
175
186
  declare const isObject: typeof isObject$1;
176
- /** @deprecated use import from `@ls-stack/typeGuards` instead */
187
+ /** @deprecated Use import from `@ls-stack/typeGuards` instead */
177
188
  declare const isPlainObject: typeof isPlainObject$1;
178
- /** @deprecated use import from `@ls-stack/typeGuards` instead */
189
+ /** @deprecated Use import from `@ls-stack/typeGuards` instead */
179
190
  declare const isPromise: typeof isPromise$1;
180
191
 
181
192
  export { assertIsNotNullish, assertIsNotUndefined, exhaustiveCheck, invariant, isFunction, isObject, isPlainObject, isPromise, notNullish, notUndefined };