full-utils 3.0.7 → 3.0.8

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/index.d.cts CHANGED
@@ -1,174 +1,5 @@
1
- /**
2
- * Parse a human-typed string of function-like arguments into a normalized array of JS values.
3
- *
4
- * @summary
5
- * Splits by **top-level commas** (ignoring commas that appear inside quotes, parentheses,
6
- * brackets, or braces) and **coerces** each token to a sensible JavaScript type:
7
- * `null`, `undefined`, booleans, numbers (including `Infinity`/`-Infinity`), strings
8
- * (with quote stripping and unescaping), and JSON objects/arrays. Tokens that look like
9
- * a macro or call marker (start with `$` and end with `)`) are returned **as is**.
10
- *
11
- * @remarks
12
- * ### How parsing works
13
- * 1. **Input normalization**
14
- * - Non-string inputs are returned as a single-element array `[value]`.
15
- * - Leading/trailing whitespace is trimmed.
16
- * - If the entire string is wrapped in square brackets (`[...]`), the brackets are
17
- * removed (so the function accepts both `a,b,c` and `[a, b, c]`).
18
- * - Empty input (after trimming or after removing `[...]`) yields `[]`.
19
- *
20
- * 2. **Tokenization by top-level commas**
21
- * - The string is scanned left-to-right.
22
- * - The parser tracks nesting **depth** for `()`, `[]`, `{}` and whether it is
23
- * currently **inside quotes**. A comma only splits tokens at **depth 0** and
24
- * **outside quotes**.
25
- *
26
- * 3. **Per-token coercion (in this order)**
27
- * - **Macro / call marker**: If a token starts with `$`, contains `(`, and ends
28
- * with `)`, it is returned unchanged (e.g., `"$env(PATH)"`).
29
- * - **Literals**: `null` → `null`, `undefined` → `undefined`.
30
- * - **Booleans**: Using {@link isStrBool} + {@link boolNormalize} (e.g., `"true"`,
31
- * `"False"`, `"yes"`, `"0"` depending on your implementation).
32
- * - **Numbers**: Using {@link numNormalize}. If the result is finite, it is returned.
33
- * Explicit `"Infinity"` and `"-Infinity"` are also supported.
34
- * - **Quoted strings**: `'text'` or `"text"` → inner text with escapes processed
35
- * (`\\` → `\`, `\'` → `'`, `\"` → `"`).
36
- * - **JSON**: If token begins with `{` and ends with `}`, or begins with `[` and
37
- * ends with `]`, the function attempts `jsonDecode`. On failure, the raw string
38
- * is returned.
39
- * - **Fallback**: Raw token as string.
40
- *
41
- * ### Escaping inside quotes
42
- * - Backslash escaping is supported while inside quotes:
43
- * - `\\` for a literal backslash
44
- * - `\"` inside double quotes
45
- * - `\'` inside single quotes
46
- *
47
- * ### Non-throwing behavior
48
- * - The function aims to be **robust** and **non-throwing**. Invalid JSON will be
49
- * returned as a plain string rather than crashing.
50
- *
51
- * ### Security considerations
52
- * - The parser **does not** evaluate code; it only returns strings or parsed values.
53
- * If you plan to execute anything returned (e.g., tokens starting with `$...`),
54
- * do so in a sandbox with explicit allow-lists.
55
- *
56
- * ### Limitations
57
- * - Numerical parsing relies on {@link numNormalize}. Extremely large or high-precision
58
- * decimals may still be subject to JavaScript `number` precision limits unless your
59
- * `numNormalize` converts to a safer representation.
60
- * - Only basic backslash escapes are handled in quoted strings (no `\uXXXX` decoding here).
61
- * - Whitespace outside quotes is trimmed from each token; internal whitespace is preserved.
62
- *
63
- * @example
64
- * // Basic values
65
- * arrFuncArgs('1, true, "hello"'); // => [1, true, "hello"]
66
- *
67
- * @example
68
- * // Bracket-wrapped list
69
- * arrFuncArgs('[1, 2, 3]'); // => [1, 2, 3]
70
- *
71
- * @example
72
- * // Nested structures and quoting
73
- * arrFuncArgs('{"a":1,"b":[2,3]}, "te,xt", (x,y)'); // => [ {a:1,b:[2,3]}, "te,xt", "(x,y)" ]
74
- *
75
- * @example
76
- * // Booleans, null/undefined, and Infinity
77
- * arrFuncArgs('yes, NO, null, undefined, Infinity, -Infinity');
78
- * // => [true, false, null, undefined, Infinity, -Infinity]
79
- *
80
- * @example
81
- * // Macro-like token (returned as-is)
82
- * arrFuncArgs('$env(PATH)'); // => ["$env(PATH)"]
83
- *
84
- * @example
85
- * // Escapes inside quotes
86
- * arrFuncArgs('"He said: \\"Hi\\"", \'It\\\'s ok\', "\\\\path"');
87
- * // => ['He said: "Hi"', "It's ok", "\\path"]
88
- *
89
- * @example
90
- * // Empty and whitespace inputs
91
- * arrFuncArgs(' '); // => []
92
- * arrFuncArgs('[]'); // => []
93
- * arrFuncArgs('[ ]'); // => []
94
- * arrFuncArgs(' [ a , b ] '); // => ["a", "b"]
95
- *
96
- * @param value - Raw string containing comma-separated arguments.
97
- * If `value` is **not** a string, the function returns `[value]` unchanged.
98
- *
99
- * @returns An array of coerced values (`unknown[]`). Each item is one parsed token.
100
- *
101
- * @see isStrBool
102
- * @see boolNormalize
103
- * @see numNormalize
104
- * @see jsonDecode
105
- *
106
- * @public
107
- * @since 2.0.0
108
- */
109
1
  declare function arrFuncArgs(value: string): unknown[];
110
2
 
111
- /**
112
- * Splits an input array into smaller subarrays (portions) of a given fixed size.
113
- *
114
- * @summary
115
- * Returns an array of chunks, where each chunk contains at most `portionLength` elements.
116
- * The final chunk may contain fewer elements if the input array length is not evenly divisible
117
- * by `portionLength`.
118
- *
119
- * @typeParam T - Type of the elements in the input array.
120
- *
121
- * @param arr - The source array to be split. It can be any readonly array (or tuple).
122
- * @param portionLength - The desired size of each portion. Must be a **positive integer**.
123
- *
124
- * @returns A new two-dimensional array (`T[][]`), where each inner array is one portion.
125
- * If `portionLength` is not a positive integer, an empty array is returned.
126
- *
127
- * @remarks
128
- * - This function is **non-mutating**: the original array is never modified.
129
- * - If `portionLength` exceeds the array length, the result will be a single chunk
130
- * containing the entire array.
131
- * - If the input array is empty, the result is an empty array.
132
- * - Uses `Array.prototype.slice()` internally, so the returned chunks are **shallow copies**.
133
- *
134
- * ### Performance
135
- * - Time complexity: **O(n)** — each element is visited exactly once.
136
- * - Space complexity: **O(n)** — proportional to the total number of elements copied.
137
- * - For extremely large arrays (millions of elements), prefer a streaming approach
138
- * if memory is a concern.
139
- *
140
- * ### Edge cases
141
- * - `portionLength <= 0` → returns `[]`.
142
- * - `portionLength` is not an integer (e.g. `2.5`, `NaN`) → returns `[]`.
143
- * - `arr.length === 0` → returns `[]`.
144
- * - Works correctly with frozen arrays and readonly tuples.
145
- *
146
- * @example
147
- * // Split an array into groups of 3
148
- * arrSplitBatches([1, 2, 3, 4, 5, 6, 7], 3);
149
- * // => [[1, 2, 3], [4, 5, 6], [7]]
150
- *
151
- * @example
152
- * // Portion length larger than array
153
- * arrSplitBatches(['a', 'b'], 5);
154
- * // => [['a', 'b']]
155
- *
156
- * @example
157
- * // Non-integer or invalid sizes
158
- * arrSplitBatches([1, 2, 3], 0); // => []
159
- * arrSplitBatches([1, 2, 3], -2); // => []
160
- * arrSplitBatches([1, 2, 3], NaN); // => []
161
- *
162
- * @example
163
- * // Works with readonly arrays
164
- * const input = [10, 20, 30, 40] as const;
165
- * const result = arrSplitBatches(input, 2);
166
- * // result: [[10, 20], [30, 40]]
167
- *
168
- * @category Array
169
- * @public
170
- * @since 2.0.0
171
- */
172
3
  declare function arrSplitBatches<T>(arr: readonly T[], portionLength: number): T[][];
173
4
 
174
5
  type AnyObj = Record<string, any>;
@@ -182,237 +13,12 @@ interface UniqueDeepOptions<T = unknown> {
182
13
  }
183
14
  declare function arrUniqueDeep<T>(input: T, opts?: UniqueDeepOptions<unknown>): T;
184
15
 
185
- /**
186
- * Converts any given value into a normalized boolean (`true` / `false`).
187
- *
188
- * @summary
189
- * Performs **loose coercion** of different input types into a `boolean`
190
- * following predictable rules for numbers, strings, and actual boolean values.
191
- * Non-recognized values always return `false`.
192
- *
193
- * @param value - Any unknown input that should be interpreted as a boolean.
194
- *
195
- * @returns The normalized boolean result (`true` or `false`).
196
- *
197
- * @remarks
198
- * This function is designed to **gracefully handle** a wide variety of input forms —
199
- * including primitive values, numeric types, and user-typed strings (like `"yes"`, `"no"`, `"on"`, `"off"`).
200
- *
201
- * ### Conversion Rules (in order of precedence)
202
- * 1. **Native booleans** → returned as-is.
203
- * - `true` → `true`
204
- * - `false` → `false`
205
- *
206
- * 2. **Positive numbers** → interpreted as `true`.
207
- * - `isNumP(value)` check passes (typically `> 0`).
208
- * - Examples: `1`, `42`, `3.14` → `true`
209
- *
210
- * 3. **Zero or negative numbers** → interpreted as `false`.
211
- * - `isNumNZ(value)` check passes (typically `<= 0`).
212
- * - Examples: `0`, `-1` → `false`
213
- *
214
- * 4. **Truthy strings** → `"true"`, `"1"`, `"yes"`, `"on"` (case-insensitive)
215
- * - `"TrUe"` → `true`
216
- * - `" YES "` → `true`
217
- *
218
- * 5. **Falsy strings** → `"false"`, `"0"`, `"no"`, `"off"` (case-insensitive)
219
- * - `"False"` → `false`
220
- * - `" off "` → `false`
221
- *
222
- * 6. **Everything else** → `false`
223
- * - `null`, `undefined`, `NaN`, empty string, symbols, objects, arrays, etc.
224
- *
225
- * ### String Handling
226
- * - Strings are **trimmed** and **lower-cased** before comparison.
227
- * - Case and whitespace are ignored.
228
- * - Empty strings (`""`) return `false`.
229
- *
230
- * ### Error Safety
231
- * - The function **never throws**.
232
- * - Non-primitive or unexpected types are handled safely and result in `false`.
233
- *
234
- * ### Performance
235
- * - Time complexity: **O(1)**.
236
- * - Space complexity: **O(1)**.
237
- *
238
- * ### Examples
239
- *
240
- * @example
241
- * // Native booleans
242
- * boolNormalize(true); // => true
243
- * boolNormalize(false); // => false
244
- *
245
- * @example
246
- * // Numeric values
247
- * boolNormalize(1); // => true
248
- * boolNormalize(0); // => false
249
- * boolNormalize(-5); // => false
250
- *
251
- * @example
252
- * // String values
253
- * boolNormalize('yes'); // => true
254
- * boolNormalize('No'); // => false
255
- * boolNormalize('TRUE'); // => true
256
- * boolNormalize('false'); // => false
257
- * boolNormalize('on'); // => true
258
- * boolNormalize('off'); // => false
259
- *
260
- * @example
261
- * // Mixed and invalid inputs
262
- * boolNormalize(null); // => false
263
- * boolNormalize(undefined); // => false
264
- * boolNormalize([]); // => false
265
- * boolNormalize({}); // => false
266
- * boolNormalize('maybe'); // => false
267
- *
268
- * @see isBool
269
- * @see isNumP
270
- * @see isNumNZ
271
- * @see isStrFilled
272
- *
273
- * @category Conversion
274
- * @public
275
- * @since 2.0.0
276
- */
277
16
  declare function boolNormalize(value: unknown): boolean;
278
17
 
279
- /**
280
- * Waits asynchronously for the specified amount of time.
281
- *
282
- * @summary
283
- * A tiny promise-based delay utility that resolves after `timeout` milliseconds.
284
- * It wraps `setTimeout` in a `Promise`, making it convenient to use with
285
- * `async/await` or as part of larger promise chains.
286
- *
287
- * @param timeout - The delay duration in **milliseconds** before the promise resolves.
288
- * @defaultValue 0
289
- *
290
- * @returns A `Promise<void | true>` that settles after the given delay.
291
- *
292
- * @example
293
- * // Basic usage: pause for ~500 ms
294
- * await wait(500);
295
- * console.log('Half a second later…');
296
- *
297
- * @example
298
- * // Measure elapsed time
299
- * const started = Date.now();
300
- * await wait(1200);
301
- * const elapsed = Date.now() - started; // ~= 1200ms (subject to timer clamping and scheduling)
302
- *
303
- * @example
304
- * // Use inside a retry/backoff loop
305
- * for (let attempt = 1; attempt <= 5; attempt++) {
306
- * try {
307
- * await doWork();
308
- * break;
309
- * } catch (err) {
310
- * // exponential backoff between attempts
311
- * await wait(2 ** attempt * 100);
312
- * }
313
- * }
314
- *
315
- * @example
316
- * // Parallel delays (resolve when the longest finishes)
317
- * await Promise.all([wait(100), wait(250), wait(50)]);
318
- *
319
- * @remarks
320
- * - **Timing accuracy:** JavaScript timers are **best-effort** and may be delayed
321
- * by event-loop load, CPU throttling, tab being backgrounded, or platform-specific
322
- * clamping. Treat `timeout` as a *minimum* delay, not an exact scheduler.
323
- * - **Negative or non-finite values:** Passing `<= 0`, `NaN`, or a non-finite value
324
- * effectively behaves like `0` and resolves on a future macrotask tick.
325
- * - **Cancellation:** This helper **does not support cancellation**. If you need to
326
- * abort a wait, consider a variant that accepts an `AbortSignal` and clears the
327
- * timer when aborted.
328
- * - **Event loop semantics:** `setTimeout(0)` schedules a **macrotask**; it does not
329
- * run synchronously. Code after `await wait(0)` will execute on a subsequent turn
330
- * of the event loop.
331
- *
332
- * Notes:
333
- * - Suitable for throttling UI interactions, pacing network retries, and writing
334
- * deterministic tests (with caution re: flakiness).
335
- * - Keep delays small in performance-critical code paths; prefer debouncing or
336
- * requestAnimationFrame for UI-animation pacing when appropriate.
337
- *
338
- * Complexity:
339
- * - Time: **O(1)** (scheduling a single timer)
340
- * - Space: **O(1)** (a promise and a timer reference)
341
- *
342
- * Performance:
343
- * - The function allocates a single promise and a timer handle.
344
- * - Timer resolution is platform dependent; Node.js and browsers may clamp very
345
- * small delays to a minimum threshold under load.
346
- *
347
- * Security:
348
- * - No I/O, side effects, or data exposure. Purely schedules a future resolution.
349
- *
350
- * <b>Returns remarks</b>:
351
- * The internal promise resolves with the value `true`, but callers typically
352
- * use `await wait(...)` and ignore the value. If you need a strictly `void`
353
- * result, you can cast or ignore the resolution value.
354
- *
355
- * @category Utilities • Timing
356
- * @since 1.0.0
357
- * @see {@link https://developer.mozilla.org/docs/Web/API/setTimeout MDN: setTimeout}
358
- */
359
18
  declare function wait(timeout?: number): Promise<void>;
360
19
 
361
20
  declare function env(k: any): string | undefined;
362
21
 
363
- /**
364
- * Represents a human-readable breakdown of a time duration
365
- * into its fundamental components — **days**, **hours**, **minutes**, and **seconds**.
366
- *
367
- * @remarks
368
- * This interface is used by time utility functions such as
369
- * {@link dateSecParts} and {@link datePartsSec} to represent durations
370
- * in a normalized structure that is easy to read, format, or serialize.
371
- *
372
- * Each field is an **integer number** representing the whole count of that unit.
373
- * None of the fields are fractional, and they are expected to follow
374
- * these conventional bounds when generated by {@link dateSecParts}:
375
- *
376
- * ```
377
- * days ≥ 0
378
- * hours ∈ [0, 23]
379
- * minutes ∈ [0, 59]
380
- * seconds ∈ [0, 59]
381
- * ```
382
- *
383
- * However, when constructing manually, these constraints are **not enforced**
384
- * by TypeScript — it is up to the user or calling function to maintain validity.
385
- *
386
- * @example
387
- * ```ts
388
- * // Example 1: Typical decomposition
389
- * const t: TimeParts = { days: 1, hours: 2, minutes: 30, seconds: 45 };
390
- *
391
- * // Example 2: Used with utility converters
392
- * const total = datePartsSec(t); // -> 95445
393
- * const back = dateSecParts(total); // -> same structure again
394
- * ```
395
- *
396
- * @example
397
- * ```ts
398
- * // Example 3: Display formatting
399
- * const p: TimeParts = { days: 0, hours: 5, minutes: 3, seconds: 9 };
400
- * console.log(`${p.hours}h ${p.minutes}m ${p.seconds}s`);
401
- * // -> "5h 3m 9s"
402
- * ```
403
- *
404
- * @property days - Whole number of days (24-hour periods).
405
- * @property hours - Whole number of hours in the remaining day (0–23 typical).
406
- * @property minutes - Whole number of minutes (0–59 typical).
407
- * @property seconds - Whole number of seconds (0–59 typical).
408
- *
409
- * @see {@link dateSecParts} — converts total seconds into this structure.
410
- * @see {@link datePartsSec} — converts this structure back into total seconds.
411
- *
412
- * @public
413
- * @category Date & Time
414
- * @since 2.0.0
415
- */
416
22
  interface TimeParts {
417
23
  days: number;
418
24
  hours: number;
@@ -420,2845 +26,94 @@ interface TimeParts {
420
26
  seconds: number;
421
27
  }
422
28
 
423
- /**
424
- * Floors a given {@link Date} object down to the nearest time interval in minutes.
425
- *
426
- * @remarks
427
- * This utility function is commonly used for time bucketing, grouping logs, or
428
- * aligning timestamps to fixed intervals (e.g. 5-minute or 15-minute marks).
429
- *
430
- * It takes an arbitrary `Date` and returns a **new** `Date` instance (it does not
431
- * mutate the input) where:
432
- *
433
- * - The `minutes` value is floored down to the nearest multiple of `everyMinutes`.
434
- * - `seconds` and `milliseconds` are reset to `0`.
435
- * - The hour and day remain unchanged.
436
- *
437
- * The step is automatically clamped to the range **1 – 60 minutes** to prevent
438
- * invalid or nonsensical values.
439
- *
440
- * The function allocates a single new `Date` object.
441
- * It is safe for high-frequency use in real-time systems and event batching.
442
- *
443
- * @param everyMinutes - The step interval (in minutes) used for rounding down.
444
- * Must be a positive finite number.
445
- * Values below 1 are treated as 1, values above 60 as 60.
446
- *
447
- * @param date - The input date to be floored.
448
- * Defaults to the current time (`new Date()`).
449
- *
450
- * @returns A **new** `Date` instance, representing the same hour as the input,
451
- * but with minutes rounded down to the nearest `everyMinutes` multiple.
452
- *
453
- * @example
454
- * ```ts
455
- * // Example 1: Floor to the nearest 15-minute mark
456
- * const d = new Date('2025-10-18T10:43:27');
457
- * dateFloorMin(15, d);
458
- * // -> 2025-10-18T10:30:00.000Z
459
- * ```
460
- *
461
- * @example
462
- * ```ts
463
- * // Example 2: Using default date (current time)
464
- * const nowFloored = dateFloorMin(10);
465
- * // -> e.g. 2025-10-18T09:20:00.000Z
466
- * ```
467
- *
468
- * @example
469
- * ```ts
470
- * // Example 3: Clamp behavior
471
- * dateFloorMin(-5, new Date()); // treated as 1 minute
472
- * dateFloorMin(999, new Date()); // treated as 60 minutes
473
- * ```
474
- *
475
- * @throws Never throws — invalid step values are automatically normalized.
476
- *
477
- * @see {@link Date#setMinutes} for the underlying mutation logic.
478
- * @see {@link Date#getMinutes} for how minutes are extracted from a Date.
479
- *
480
- * @public
481
- * @category Date & Time
482
- * @since 2.0.0
483
- */
484
29
  declare function dateFloorMin(everyMinutes?: number, date?: Date): Date;
485
30
 
486
- /**
487
- * Formats a {@link Date} object into a human-readable timestamp string
488
- * using the pattern `"YYYY-MM-DD HH:mm:ss"`.
489
- *
490
- * @remarks
491
- * This function is a simple and locale-independent date formatter that always
492
- * outputs a **24-hour clock** timestamp with leading zeros for all numeric parts.
493
- *
494
- * It does **not** depend on the user's locale or time zone settings beyond what
495
- * is stored in the provided `Date` object. If you pass a `Date` constructed
496
- * from UTC or local time, the formatted output will reflect that same basis.
497
- *
498
- * Each date/time component (month, day, hours, minutes, seconds) is padded to
499
- * two digits using {@link String.padStart}, ensuring consistent width such as
500
- * `2025-03-07 09:04:02`.
501
- *
502
- * - The format is fixed-width and consistent — ideal for logs, filenames,
503
- * and database-friendly timestamps.
504
- * - The output is **not ISO 8601** (which uses a `'T'` separator and optional
505
- * timezone offset).
506
- * Example: ISO → `"2025-10-18T10:43:27Z"`
507
- * This function → `"2025-10-18 10:43:27"`.
508
- *
509
- * @param date - The date to format. Defaults to the **current system time**
510
- * (`new Date()`).
511
- *
512
- * @returns A formatted timestamp string in `"YYYY-MM-DD HH:mm:ss"` form.
513
- *
514
- * @example
515
- * ```ts
516
- * // Example 1: Specific date
517
- * const d = new Date('2025-10-18T10:43:27Z');
518
- * dateStr(d);
519
- * // -> "2025-10-18 10:43:27"
520
- * ```
521
- *
522
- * @example
523
- * ```ts
524
- * // Example 2: Default (current) date
525
- * dateStr();
526
- * // -> e.g. "2025-10-18 12:07:55"
527
- * ```
528
- *
529
- * @example
530
- * ```ts
531
- * // Example 3: Padding behavior
532
- * const d = new Date('2025-03-07T09:04:02');
533
- * dateStr(d);
534
- * // -> "2025-03-07 09:04:02"
535
- * ```
536
- *
537
- * @throws Never throws.
538
- *
539
- * @see {@link Date} for JavaScript’s native date-handling API.
540
- * @see {@link Intl.DateTimeFormat} for locale-aware formatting if needed.
541
- *
542
- * @public
543
- * @category Date & Time
544
- * @since 2.0.0
545
- */
546
31
  declare function dateStr(date?: Date): string;
547
32
 
548
- /**
549
- * Converts a partial {@link TimeParts} structure (days, hours, minutes, seconds)
550
- * into a total number of **seconds**.
551
- *
552
- * @remarks
553
- * This helper provides a simple way to normalize human-readable time components
554
- * into a single scalar duration in seconds.
555
- * It can be useful for:
556
- * - time-based arithmetic (e.g., adding offsets to timestamps),
557
- * - scheduling or delay computation,
558
- * - serializing durations into numeric fields (e.g., databases or APIs).
559
- *
560
- * All fields (`days`, `hours`, `minutes`, `seconds`) are **optional**; any missing
561
- * value defaults to `0`. The calculation uses fixed conversion factors:
562
- *
563
- * - 1 day = 86 400 seconds
564
- * - 1 hour = 3 600 seconds
565
- * - 1 minute = 60 seconds
566
- *
567
- * - Fractional or negative numbers are accepted and processed arithmetically.
568
- * Example: `{ minutes: 1.5 }` → `90`; `{ hours: -1 }` → `-3600`.
569
- * - The function performs no validation; it assumes numeric input.
570
- * TypeScript typing (`number`) ensures intended usage.
571
- *
572
- * @param parts - A partial object containing any subset of time fields.
573
- * Missing values default to zero.
574
- *
575
- * @returns The total number of seconds represented by the provided time parts.
576
- *
577
- * @example
578
- * ```ts
579
- * // Example 1: Simple conversion
580
- * datePartsSec({ hours: 1, minutes: 30 }); // -> 5400
581
- *
582
- * // Example 2: Full time span
583
- * datePartsSec({ days: 2, hours: 3, minutes: 5, seconds: 10 });
584
- * // -> 183910
585
- *
586
- * // Example 3: Partial / missing fields
587
- * datePartsSec({}); // -> 0
588
- * datePartsSec({ minutes: 5 }); // -> 300
589
- * ```
590
- *
591
- * @throws Never throws.
592
- *
593
- * @see {@link dateSecParts} — the inverse operation that expands seconds back into components.
594
- *
595
- * @public
596
- * @category Date & Time
597
- * @since 2.0.0
598
- */
599
33
  declare function datePartsSec(parts: TimeParts): number;
600
34
 
601
- /**
602
- * Decomposes a total number of seconds into discrete time components:
603
- * **days**, **hours**, **minutes**, and **seconds**.
604
- *
605
- * @remarks
606
- * This is the inverse operation of {@link datePartsSec}.
607
- * It converts a flat duration (in seconds) into a more human-readable structure
608
- * suitable for display, logging, or formatting.
609
- *
610
- * The function performs integer division using {@link Math.floor} for each component
611
- * and ensures that the result satisfies:
612
- *
613
- * ```
614
- * 0 <= hours < 24
615
- * 0 <= minutes < 60
616
- * 0 <= seconds < 60
617
- * ```
618
- *
619
- * Any fractional part of the input (e.g., `12.75`) is truncated (floored) to the
620
- * nearest lower whole second.
621
- * Negative or non-finite inputs are considered invalid and will throw an error.
622
- *
623
- * - Uses only a few arithmetic operations and is **O(1)**.
624
- * - Safe for real-time conversions or high-frequency usage (e.g., monitoring dashboards).
625
- *
626
- * @param total - Total duration in seconds.
627
- * Must be a **finite, non-negative number**.
628
- *
629
- * @returns A {@link TimeParts} object with integer fields:
630
- * - `days`
631
- * - `hours`
632
- * - `minutes`
633
- * - `seconds`
634
- *
635
- * @example
636
- * ```ts
637
- * // Example 1: Basic conversion
638
- * dateSecParts(3661);
639
- * // -> { days: 0, hours: 1, minutes: 1, seconds: 1 }
640
- * ```
641
- *
642
- * @example
643
- * ```ts
644
- * // Example 2: Multi-day value
645
- * dateSecParts(90061);
646
- * // -> { days: 1, hours: 1, minutes: 1, seconds: 1 }
647
- * ```
648
- *
649
- * @example
650
- * ```ts
651
- * // Example 3: Invalid input
652
- * dateSecParts(-10); // throws Error("Invalid total seconds")
653
- * dateSecParts(NaN); // throws Error("Invalid total seconds")
654
- * ```
655
- *
656
- * @throws {Error}
657
- * Thrown when `total` is not a finite, non-negative number.
658
- *
659
- * @see {@link datePartsSec} — the complementary function that aggregates components into seconds.
660
- * @see {@link TimeParts} — the return type describing the breakdown of time.
661
- *
662
- * @public
663
- * @category Date & Time
664
- * @since 2.0.0
665
- */
666
35
  declare function dateSecParts(total: number): TimeParts;
667
36
 
668
- /**
669
- * Converts a dotted-decimal IPv4 address string (e.g. `"192.168.0.1"`)
670
- * into its **32-bit unsigned integer** representation.
671
- *
672
- * @remarks
673
- * This function performs a strict validation of the IPv4 address and encodes
674
- * each of its four octets into a 32-bit number using **big-endian (network byte order)**.
675
- *
676
- * The resulting number is in the range `0..4_294_967_295` (`0xFFFFFFFF`),
677
- * where:
678
- *
679
- * - `"0.0.0.0"` → `0`
680
- * - `"255.255.255.255"` → `4294967295`
681
- *
682
- * This representation is particularly useful for:
683
- * - performing numeric range comparisons (e.g., IP ranges, CIDR checks);
684
- * - storing IPv4 values compactly in binary structures or databases;
685
- * - bitwise operations such as masking and subnet arithmetic.
686
- *
687
- * - The conversion uses a {@link DataView} and explicit byte writes
688
- * to guarantee consistent big-endian behavior across platforms.
689
- * - The output number is safe for 32-bit unsigned arithmetic via `>>> 0`.
690
- * - If you need the inverse operation, see {@link numToIpAddr}.
691
- *
692
- * @param ip - The IPv4 address in dotted-quad string form.
693
- *
694
- * @returns A 32-bit **unsigned integer** representing the given IPv4 address.
695
- *
696
- * @example
697
- * ```ts
698
- * // Example 1: Simple conversion
699
- * ipStrNum("192.168.0.1");
700
- * // -> 3232235521
701
- *
702
- * // Example 2: Edge values
703
- * ipStrNum("0.0.0.0"); // -> 0
704
- * ipStrNum("255.255.255.255"); // -> 4294967295
705
- * ```
706
- *
707
- * @example
708
- * ```ts
709
- * // Example 3: Invalid input
710
- * ipStrNum("192.168.1"); // throws Error("Invalid IPv4 address")
711
- * ipStrNum("256.0.0.1"); // throws Error("Invalid IPv4 address")
712
- * ipStrNum("abc.def.ghi.jkl"); // throws Error("Invalid IPv4 address")
713
- * ```
714
- *
715
- * @throws {Error}
716
- * Thrown when:
717
- * - The input does not contain exactly four parts separated by dots.
718
- * - Any octet is not an integer between 0 and 255 inclusive.
719
- *
720
- * @see {@link numToIpAddr} — converts a 32-bit integer back to an IPv4 string.
721
- * @see {@link parseIPv4} — similar numeric parser using bitwise operations.
722
- *
723
- * @public
724
- * @category Network & IP
725
- * @since 2.0.0
726
- */
727
37
  declare function ipStrNum(ip: string): number;
728
38
 
729
- /**
730
- * Converts a 32-bit unsigned integer (numeric IPv4 representation)
731
- * back into its dotted-decimal string form (e.g. `"192.168.0.1"`).
732
- *
733
- * @remarks
734
- * This is the inverse of {@link ipStrNum}.
735
- * It interprets the input number as a **big-endian (network-byte-order)**
736
- * IPv4 value, extracting each of the four octets and joining them into
737
- * the standard dotted-quad notation.
738
- *
739
- * If the input is not a valid finite number (checked via {@link isNumP}),
740
- * an empty string `""` is returned instead of throwing an exception.
741
- *
742
- * The resulting string always consists of **exactly four decimal octets**
743
- * separated by dots, with each octet in the range `0–255`.
744
- *
745
- * - Internally uses {@link DataView} to ensure consistent big-endian behavior
746
- * across all platforms.
747
- * - The output format is always normalized (no leading zeros, no spaces).
748
- * - For the forward direction (string → number), see {@link ipStrNum}.
749
- *
750
- * @param num - The 32-bit unsigned integer representing an IPv4 address.
751
- *
752
- * @returns A dotted-decimal IPv4 string (e.g. `"10.0.0.1"`),
753
- * or an empty string if the input is invalid.
754
- *
755
- * @example
756
- * ```ts
757
- * // Example 1: Basic conversion
758
- * ipNumStr(3232235521);
759
- * // -> "192.168.0.1"
760
- *
761
- * // Example 2: Edge values
762
- * ipNumStr(0); // -> "0.0.0.0"
763
- * ipNumStr(4294967295); // -> "255.255.255.255"
764
- * ```
765
- *
766
- * @example
767
- * ```ts
768
- * // Example 3: Invalid inputs
769
- * ipNumStr(NaN); // -> ""
770
- * ipNumStr(Infinity); // -> ""
771
- * ipNumStr(-5); // -> ""
772
- * ```
773
- *
774
- * @throws Never throws; invalid inputs simply return an empty string.
775
- *
776
- * @see {@link ipStrNum} — converts dotted IPv4 strings to numeric form.
777
- * @see {@link parseIPv4} — alternative parser using bitwise arithmetic.
778
- *
779
- * @public
780
- * @category Network & IP
781
- * @since 2.0.0
782
- */
783
39
  declare function ipNumStr(num: number): string;
784
40
 
785
- /**
786
- * Configuration options that define password validation rules.
787
- *
788
- * This interface allows you to specify various constraints
789
- * that determine whether a given password is considered valid.
790
- *
791
- * @example
792
- * ```ts
793
- * const options: PasswordOptions = {
794
- * minLength: 8,
795
- * maxLength: 32,
796
- * requireUppercase: true,
797
- * requireLowercase: true,
798
- * requireDigit: true,
799
- * requireSpecial: true,
800
- * };
801
- * ```
802
- *
803
- * @remarks
804
- * You can use these options to build password validation functions,
805
- * enforce strong password policies, or configure authentication modules.
806
- *
807
- * @since 2.0.0
808
- */
809
41
  interface PasswordOptions {
810
- /**
811
- * Minimum allowed number of characters in the password.
812
- *
813
- * @defaultValue `0`
814
- * @example
815
- * ```ts
816
- * { minLength: 8 } // password must contain at least 8 characters
817
- * ```
818
- */
819
42
  minLength?: number;
820
- /**
821
- * Maximum allowed number of characters in the password.
822
- *
823
- * @defaultValue `Infinity`
824
- * @example
825
- * ```ts
826
- * { maxLength: 32 } // password cannot exceed 32 characters
827
- * ```
828
- */
829
43
  maxLength?: number;
830
- /**
831
- * Whether the password must contain at least one uppercase Latin letter (A–Z).
832
- *
833
- * @defaultValue `false`
834
- * @example
835
- * ```ts
836
- * { requireUppercase: true } // 'Password1' - OK 'password1' - BAD
837
- * ```
838
- */
839
44
  requireUppercase?: boolean;
840
- /**
841
- * Whether the password must contain at least one lowercase Latin letter (a–z).
842
- *
843
- * @defaultValue `false`
844
- * @example
845
- * ```ts
846
- * { requireLowercase: true } // 'PASSWORD1' - BAD 'Password1' - OK
847
- * ```
848
- */
849
45
  requireLowercase?: boolean;
850
- /**
851
- * Whether the password must include at least one numeric digit (0–9).
852
- *
853
- * @defaultValue `false`
854
- * @example
855
- * ```ts
856
- * { requireDigit: true } // 'Password' - BAD 'Password1' - OK
857
- * ```
858
- */
859
46
  requireDigit?: boolean;
860
- /**
861
- * Whether the password must include at least one special character
862
- * (such as `!@#$%^&*()-_=+[]{};:'",.<>/?`).
863
- *
864
- * @defaultValue `false`
865
- * @example
866
- * ```ts
867
- * { requireSpecial: true } // 'Password1' - BAD 'Password1!' - OK
868
- * ```
869
- */
870
47
  requireSpecial?: boolean;
871
48
  }
872
49
 
873
- /**
874
- * Checks whether a given value is an array.
875
- *
876
- * @summary
877
- * A strongly typed wrapper around {@link Array.isArray}, with an enhanced TypeScript
878
- * type guard that asserts the value as a **readonly non-empty array** (`readonly [T, ...T[]]`).
879
- *
880
- * @typeParam T - The expected element type of the array (defaults to `unknown`).
881
- *
882
- * @param value - Any value to test.
883
- *
884
- * @returns `true` if the value is an array (of any kind), otherwise `false`.
885
- * The return type acts as a **type guard**, allowing TypeScript to infer that
886
- * `value` is a readonly array of `T` when the function returns `true`.
887
- *
888
- * @remarks
889
- * - Internally uses the native {@link Array.isArray} method.
890
- * - Works correctly across realms (e.g., iframes, worker contexts, etc.).
891
- * - The type guard ensures `value` is a **readonly non-empty array**, not just an empty list.
892
- * This provides safer downstream access patterns when empty arrays are not expected.
893
- * - If you need to allow empty arrays, consider changing the type to `readonly T[]`.
894
- *
895
- * ### Performance
896
- * - Time complexity: **O(1)** — constant time native check.
897
- * - Space complexity: **O(1)**.
898
- *
899
- * ### Common pitfalls
900
- * - `isArr([])` → `true`, even though the static type is `readonly [T, ...T[]]`.
901
- * TypeScript does not validate runtime emptiness; you should still check `value.length`.
902
- * - `isArr('abc')` → `false`
903
- * - `isArr({ length: 3 })` → `false`
904
- *
905
- * ### Examples
906
- *
907
- * @example
908
- * // Basic usage
909
- * isArr([1, 2, 3]); // => true
910
- * isArr('hello'); // => false
911
- * isArr({}); // => false
912
- *
913
- * @example
914
- * // With type inference
915
- * const val: unknown = [10, 20];
916
- * if (isArr<number>(val)) {
917
- * // TypeScript now knows val: readonly [number, ...number[]]
918
- * console.log(val[0]); // OK
919
- * }
920
- *
921
- * @example
922
- * // With mixed content
923
- * isArr([true, 'text', 123]); // => true
924
- *
925
- * @see Array.isArray
926
- *
927
- * @category Type Guards
928
- * @public
929
- * @since 2.0.0
930
- */
931
50
  declare function isArr<T = unknown>(value: unknown): value is readonly [T, ...T[]];
932
51
 
933
- /**
934
- * Checks whether a value is a **non-empty array**.
935
- *
936
- * @summary
937
- * A strongly-typed type guard that returns `true` only if the input value is an array
938
- * (via {@link isArr}) and contains at least one element (`length > 0`).
939
- *
940
- * Useful for narrowing unknown data to a **readonly non-empty tuple type**
941
- * (`readonly [T, ...T[]]`), which gives TypeScript safer access guarantees.
942
- *
943
- * @typeParam T - Expected element type of the array (defaults to `unknown`).
944
- *
945
- * @param value - Any value to test.
946
- *
947
- * @returns `true` if `value` is an array with at least one element; otherwise `false`.
948
- *
949
- * @remarks
950
- * ### Type narrowing
951
- * When this function returns `true`, TypeScript automatically infers that:
952
- * ```ts
953
- * value is readonly [T, ...T[]]
954
- * ```
955
- *
956
- * That means inside the `if` block, you can safely access `value[0]`
957
- * without additional checks.
958
- *
959
- * ### Behavior
960
- * - Delegates the array check to {@link isArr}.
961
- * - Works with both mutable (`T[]`) and readonly arrays (`readonly T[]`).
962
- * - Does **not** mutate or clone the array.
963
- * - Returns `false` for:
964
- * - Non-array values (`null`, `undefined`, `object`, `string`, etc.).
965
- * - Empty arrays (`[]`).
966
- *
967
- * ### Performance
968
- * - Time complexity: **O(1)** (constant time check).
969
- * - Space complexity: **O(1)**.
970
- *
971
- * ### Examples
972
- *
973
- * @example
974
- * // Basic usage
975
- * isArrFilled([1, 2, 3]); // => true
976
- * isArrFilled([]); // => false
977
- *
978
- * @example
979
- * // With type inference
980
- * const maybeNumbers: unknown = [10, 20];
981
- * if (isArrFilled<number>(maybeNumbers)) {
982
- * // value is now typed as: readonly [number, ...number[]]
983
- * console.log(maybeNumbers[0]); // OK
984
- * }
985
- *
986
- * @example
987
- * // Non-array values
988
- * isArrFilled('abc'); // => false
989
- * isArrFilled(null); // => false
990
- * isArrFilled(undefined); // => false
991
- * isArrFilled({ length: 2 }); // => false
992
- *
993
- * @see isArr
994
- *
995
- * @category Type Guards
996
- * @public
997
- * @since 2.0.0
998
- */
999
52
  declare function isArrFilled<T = unknown>(value: unknown): value is readonly [T, ...T[]];
1000
53
 
1001
- /**
1002
- * Checks whether a given value is a boolean (`true` or `false`).
1003
- *
1004
- * @summary
1005
- * A strict type guard that returns `true` only if `value` is of type `"boolean"`.
1006
- *
1007
- * This helps safely narrow unknown or mixed-type values in TypeScript code,
1008
- * especially when working with dynamic data sources, JSON, or user input.
1009
- *
1010
- * @param value - Any value to check.
1011
- *
1012
- * @returns `true` if the value is strictly a boolean, otherwise `false`.
1013
- *
1014
- * @remarks
1015
- * - Uses the built-in `typeof` operator (`typeof value === "boolean"`).
1016
- * - Does **not** coerce values — only primitive `true` or `false` are accepted.
1017
- * - Returns `false` for Boolean objects created via `new Boolean()`, because those
1018
- * are of type `"object"`, not `"boolean"`.
1019
- * - Designed as a **type guard**, so when it returns `true`, TypeScript will infer:
1020
- * ```ts
1021
- * value is boolean
1022
- * ```
1023
- *
1024
- * ### Performance
1025
- * - Time complexity: **O(1)** (constant).
1026
- * - Space complexity: **O(1)**.
1027
- *
1028
- * ### Examples
1029
- *
1030
- * @example
1031
- * // Basic usage
1032
- * isBool(true); // => true
1033
- * isBool(false); // => true
1034
- * isBool(0); // => false
1035
- * isBool('true'); // => false
1036
- *
1037
- * @example
1038
- * // With type narrowing
1039
- * const val: unknown = Math.random() > 0.5 ? true : 'yes';
1040
- * if (isBool(val)) {
1041
- * // TypeScript now knows val: boolean
1042
- * console.log(val ? 'OK' : 'NO');
1043
- * }
1044
- *
1045
- * @example
1046
- * // Boolean object is not accepted
1047
- * isBool(new Boolean(true)); // => false
1048
- *
1049
- * @category Type Guards
1050
- * @public
1051
- * @since 2.0.0
1052
- */
1053
54
  declare function isBool(value: unknown): value is boolean;
1054
55
 
1055
56
  declare function isBoolOrBoolTree(value: unknown): boolean;
1056
57
 
1057
- /**
1058
- * Checks whether a value represents a **valid JavaScript date**.
1059
- *
1060
- * @summary
1061
- * Returns `true` if the given value is either:
1062
- * - an actual `Date` instance with a valid timestamp, or
1063
- * - a string or number that can be successfully parsed by the JavaScript `Date` constructor.
1064
- *
1065
- * Returns `false` for invalid dates (`Invalid Date`), empty strings, `NaN`, or non-date types.
1066
- *
1067
- * @param value - Any value to test (can be a `Date`, string, number, or other type).
1068
- *
1069
- * @returns `true` if the value can be interpreted as a valid date, otherwise `false`.
1070
- *
1071
- * @remarks
1072
- * ### Validation logic
1073
- * 1. **If `value` is a `Date` instance:**
1074
- * Checks `!Number.isNaN(value.getTime())` — ensures it’s a real date, not an invalid one.
1075
- * ```ts
1076
- * isDate(new Date('invalid')); // false
1077
- * ```
1078
- *
1079
- * 2. **If `value` is a string or number:**
1080
- * Attempts to construct a new `Date(value)`.
1081
- * Returns `true` only if the resulting date’s timestamp is finite (not `NaN`).
1082
- *
1083
- * 3. **Otherwise:**
1084
- * Returns `false`.
1085
- *
1086
- * ### What counts as "valid"
1087
- * - OK: `"2024-12-31"`, `"2024-12-31T23:59:59Z"`, `1728000000000`, `new Date()`
1088
- * - BAD: `"abc"`, `NaN`, `{}`, `null`, `undefined`, `new Date('invalid')`
1089
- *
1090
- * ### Type safety
1091
- * - This is **not** a strict type guard (it doesn’t narrow to `Date`),
1092
- * but you can pair it with a cast when `true`:
1093
- * ```ts
1094
- * if (isDate(v)) {
1095
- * const d = new Date(v); // guaranteed valid
1096
- * }
1097
- * ```
1098
- *
1099
- * ### Performance
1100
- * - Time complexity: **O(1)**
1101
- * (`Date` construction and timestamp check are constant-time operations).
1102
- * - Space complexity: **O(1)**.
1103
- *
1104
- * ### Examples
1105
- *
1106
- * @example
1107
- * // Valid Date instances
1108
- * isDate(new Date()); // => true
1109
- * isDate(new Date('2024-05-01')); // => true
1110
- *
1111
- * @example
1112
- * // From strings or timestamps
1113
- * isDate('2025-01-01T00:00:00Z'); // => true
1114
- * isDate(1700000000000); // => true
1115
- * isDate('not-a-date'); // => false
1116
- *
1117
- * @example
1118
- * // Invalid cases
1119
- * isDate({}); // => false
1120
- * isDate([]); // => false
1121
- * isDate(''); // => false
1122
- * isDate(new Date('invalid')); // => false
1123
- *
1124
- * @see isStr
1125
- * @see isNum
1126
- * @see Date
1127
- *
1128
- * @category Type Guards
1129
- * @public
1130
- * @since 2.0.0
1131
- */
1132
58
  declare function isDate(value: unknown): boolean;
1133
59
 
1134
- /**
1135
- * Checks whether a given value is a **valid email address**.
1136
- *
1137
- * @summary
1138
- * Validates that the input is a non-empty string and matches a simplified but
1139
- * practical email pattern according to RFC 5322-compatible syntax rules.
1140
- *
1141
- * @param value - Any value to test (string or unknown).
1142
- *
1143
- * @returns `true` if the value is a non-empty string that looks like a valid email,
1144
- * otherwise `false`.
1145
- *
1146
- * @remarks
1147
- * ### Validation process
1148
- * 1. Ensures the input is a **non-empty string** via {@link isStrFilled}.
1149
- * 2. Tests the value against a precompiled **regular expression**:
1150
- * ```
1151
- * /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+
1152
- * @[a-zA-Z0-9]
1153
- * (?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?
1154
- * (?:\.[a-zA-Z]{2,})+$/
1155
- * ```
1156
- * This allows standard ASCII characters in the local part and enforces:
1157
- * - at least one `@` separator
1158
- * - valid domain and subdomain segments
1159
- * - a top-level domain of at least two letters.
1160
- *
1161
- * ### Behavior notes
1162
- * - Returns `false` for empty strings, `null`, `undefined`, or non-string inputs.
1163
- * - Does **not** perform DNS or MX record validation — only syntactic matching.
1164
- * - Intended for lightweight client-side or structural checks.
1165
- * - If you need full compliance with RFC 6531 (Unicode / IDN), normalize the address first.
1166
- *
1167
- * ### Performance
1168
- * - Time complexity: **O(n)** — proportional to input length.
1169
- * - Space complexity: **O(1)**.
1170
- * - The compiled regex is cached and reused for efficiency.
1171
- *
1172
- * ### Examples
1173
- *
1174
- * @example
1175
- * // Valid emails
1176
- * isEmail('user@example.com'); // => true
1177
- * isEmail('john.doe+alias@mail.co.uk'); // => true
1178
- *
1179
- * @example
1180
- * // Invalid formats
1181
- * isEmail(''); // => false
1182
- * isEmail('user@'); // => false
1183
- * isEmail('@example.com'); // => false
1184
- * isEmail('user@@example.com'); // => false
1185
- * isEmail('user example@domain.com'); // => false
1186
- *
1187
- * @example
1188
- * // Non-string inputs
1189
- * isEmail(null); // => false
1190
- * isEmail(undefined); // => false
1191
- * isEmail(12345); // => false
1192
- *
1193
- * @see isStrFilled
1194
- *
1195
- * @category Validation
1196
- * @public
1197
- * @since 2.0.0
1198
- */
1199
60
  declare function isEmail(value: unknown): value is string;
1200
61
 
1201
- /**
1202
- * Checks whether a value **exists** — i.e. is neither `null` nor `undefined`.
1203
- *
1204
- * @summary
1205
- * A minimal and strongly typed utility that acts as a **type guard**
1206
- * to filter out `null` and `undefined` values in TypeScript.
1207
- * It is especially useful in array filters and conditional checks
1208
- * where you need to ensure a value is "present".
1209
- *
1210
- * @typeParam T - The original type of the tested value.
1211
- *
1212
- * @param value - Any value that may be `null` or `undefined`.
1213
- *
1214
- * @returns `true` if `value` is not `null` and not `undefined`, otherwise `false`.
1215
- *
1216
- * @remarks
1217
- * ### Type narrowing
1218
- * When this function returns `true`, TypeScript automatically infers:
1219
- * ```ts
1220
- * value is T
1221
- * ```
1222
- *
1223
- * That means inside the `if` block (or after using `Array.filter(isExists)`),
1224
- * the compiler knows the value cannot be `null` or `undefined`.
1225
- *
1226
- * ### Behavior
1227
- * - Returns `false` for `null` and `undefined`.
1228
- * - Returns `true` for any other type — including `false`, `0`, `''`, `NaN`, empty arrays, etc.
1229
- * - The check is **strict** (`!==`) — no type coercion occurs.
1230
- *
1231
- * ### Typical use cases
1232
- * - Filtering arrays that may contain `null` or `undefined`.
1233
- * - Guarding optional values before access.
1234
- * - Simplifying type-safe checks in functional chains.
1235
- *
1236
- * ### Performance
1237
- * - Time complexity: **O(1)**
1238
- * - Space complexity: **O(1)**
1239
- *
1240
- * ### Examples
1241
- *
1242
- * @example
1243
- * // Basic checks
1244
- * isExists(null); // => false
1245
- * isExists(undefined); // => false
1246
- * isExists(0); // => true
1247
- * isExists(''); // => true
1248
- * isExists(false); // => true
1249
- *
1250
- * @example
1251
- * // With TypeScript narrowing
1252
- * const val: string | null | undefined = getValue();
1253
- * if (isExists(val)) {
1254
- * // val is now guaranteed to be a string
1255
- * console.log(val.toUpperCase());
1256
- * }
1257
- *
1258
- * @example
1259
- * // Filtering nullable arrays
1260
- * const arr = [1, null, 2, undefined, 3];
1261
- * const clean = arr.filter(isExists);
1262
- * // clean: number[] => [1, 2, 3]
1263
- *
1264
- * @category Type Guards
1265
- * @public
1266
- * @since 2.0.0
1267
- */
1268
62
  declare function isExists<T>(value: T | null | undefined): value is T;
1269
63
 
1270
- /**
1271
- * Checks whether a given value is a **function**.
1272
- *
1273
- * @summary
1274
- * A strict type guard that returns `true` only if `value` is a callable function.
1275
- * It works with regular functions, arrow functions, async functions, class constructors,
1276
- * and built-in functions like `setTimeout`.
1277
- *
1278
- * @typeParam T - The expected function type to narrow to (defaults to the base `Function` type).
1279
- *
1280
- * @param value - Any value to check.
1281
- *
1282
- * @returns `true` if the value is of type `"function"`, otherwise `false`.
1283
- *
1284
- * @remarks
1285
- * ### Type narrowing
1286
- * When this function returns `true`, TypeScript infers that:
1287
- * ```ts
1288
- * value is T
1289
- * ```
1290
- *
1291
- * This allows safe calling of the function or using its specific signature.
1292
- *
1293
- * ### Behavior
1294
- * - Returns `true` for:
1295
- * - Normal functions: `function test() {}`
1296
- * - Arrow functions: `() => {}`
1297
- * - Async functions: `async () => {}`
1298
- * - Generator functions: `function* gen() {}`
1299
- * - Class constructors (typeof `MyClass`).
1300
- * - Returns `false` for:
1301
- * - Non-callable objects or primitives.
1302
- * - Function-like objects that aren't real functions (e.g., `{ call() {} }`).
1303
- *
1304
- * ### Performance
1305
- * - Time complexity: **O(1)**
1306
- * - Space complexity: **O(1)**
1307
- *
1308
- * ### Examples
1309
- *
1310
- * @example
1311
- * // Basic usage
1312
- * isFunc(() => {}); // => true
1313
- * isFunc(function test() {}); // => true
1314
- * isFunc(class A {}); // => true
1315
- * isFunc(123); // => false
1316
- * isFunc({}); // => false
1317
- *
1318
- * @example
1319
- * // Type narrowing
1320
- * const fn: unknown = () => 'ok';
1321
- * if (isFunc<() => string>(fn)) {
1322
- * const result = fn(); // result: string
1323
- * }
1324
- *
1325
- * @example
1326
- * // Class constructors are also "functions"
1327
- * class MyClass {}
1328
- * isFunc(MyClass); // => true
1329
- *
1330
- * @category Type Guards
1331
- * @public
1332
- * @since 2.0.0
1333
- */
1334
64
  declare function isFunc<T extends Function = Function>(value: unknown): value is T;
1335
65
 
1336
- /**
1337
- * Checks whether a given value is a **valid IPv4 address**.
1338
- *
1339
- * @summary
1340
- * Validates that the input is a string containing four octets (e.g. `"192.168.0.1"`),
1341
- * where each octet is a number between `0` and `255`, separated by dots.
1342
- *
1343
- * @param value - Any value to test (string or unknown).
1344
- *
1345
- * @returns `true` if the value is a syntactically valid IPv4 address, otherwise `false`.
1346
- *
1347
- * @remarks
1348
- * ### Validation steps
1349
- * 1. Ensures the input is a string via {@link isStr}.
1350
- * 2. Trims leading and trailing whitespace.
1351
- * 3. Tests the cleaned string against a strict regular expression for IPv4 format:
1352
- * ```
1353
- * /^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.
1354
- * (25[0-5]|2[0-4]\d|[01]?\d\d?)\.
1355
- * (25[0-5]|2[0-4]\d|[01]?\d\d?)\.
1356
- * (25[0-5]|2[0-4]\d|[01]?\d\d?)$/
1357
- * ```
1358
- * Each group allows:
1359
- * - `0–9`, `00–99`, `100–199`, `200–249`, `250–255`
1360
- *
1361
- * ### Behavior notes
1362
- * - Returns `false` for non-strings, empty strings, or malformed IPs.
1363
- * - Does **not** support IPv6 (use a separate validator for that).
1364
- * - Does **not** perform CIDR or subnet validation — only syntax checking.
1365
- * - Leading zeros are allowed (e.g. `"010.000.000.001"` is accepted, as per regex).
1366
- *
1367
- * ### Performance
1368
- * - Time complexity: **O(1)** (fixed regex evaluation).
1369
- * - Space complexity: **O(1)**.
1370
- *
1371
- * ### Examples
1372
- *
1373
- * @example
1374
- * // Valid IPv4 addresses
1375
- * isIpAddr('192.168.0.1'); // => true
1376
- * isIpAddr('8.8.8.8'); // => true
1377
- * isIpAddr('0.0.0.0'); // => true
1378
- * isIpAddr('255.255.255.255'); // => true
1379
- *
1380
- * @example
1381
- * // Invalid IPv4 strings
1382
- * isIpAddr('256.0.0.1'); // => false (octet > 255)
1383
- * isIpAddr('192.168.0'); // => false (missing octet)
1384
- * isIpAddr('192.168.0.1.5'); // => false (too many octets)
1385
- * isIpAddr('192.168.0.A'); // => false (non-numeric)
1386
- * isIpAddr('192,168,0,1'); // => false (wrong separator)
1387
- *
1388
- * @example
1389
- * // Non-string inputs
1390
- * isIpAddr(12345); // => false
1391
- * isIpAddr(null); // => false
1392
- * isIpAddr(undefined); // => false
1393
- *
1394
- * @see isStr
1395
- *
1396
- * @category Validation
1397
- * @public
1398
- * @since 2.0.0
1399
- */
1400
66
  declare function isIpAddr(value: unknown): value is string;
1401
67
 
1402
- /**
1403
- * Checks whether a given value is a **valid MAC address**.
1404
- *
1405
- * @summary
1406
- * Validates that the input is a string formatted as a standard 6-octet
1407
- * MAC (Media Access Control) address, consisting of 12 hexadecimal digits
1408
- * separated by either colons (`:`) or hyphens (`-`).
1409
- *
1410
- * @param value - Any value to test (typically a string from user input or network data).
1411
- *
1412
- * @returns `true` if the value matches the MAC address pattern, otherwise `false`.
1413
- *
1414
- * @remarks
1415
- * ### Accepted formats
1416
- * - `00:1A:2B:3C:4D:5E`
1417
- * - `00-1A-2B-3C-4D-5E`
1418
- * - Both uppercase and lowercase hexadecimal digits are allowed.
1419
- * - Mixed separators (e.g., `"00:1A-2B:3C-4D:5E"`) are **not** accepted.
1420
- *
1421
- * ### Validation logic
1422
- * 1. Confirms that `value` is a string via {@link isStr}.
1423
- * 2. Uses the following regular expression:
1424
- * ```
1425
- * /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/
1426
- * ```
1427
- * which enforces:
1428
- * - Exactly 6 byte segments (`xx:xx:xx:xx:xx:xx` or `xx-xx-xx-xx-xx-xx`)
1429
- * - Each segment: two hexadecimal digits (`0–9`, `A–F`, `a–f`)
1430
- * - A consistent separator (`:` or `-`)
1431
- *
1432
- * ### Behavior notes
1433
- * - Returns `false` for empty strings, non-strings, or malformed addresses.
1434
- * - Does **not** support 8-octet EUI-64 or Cisco short 3-octet formats.
1435
- * - Does **not** check for broadcast or multicast address semantics — only syntax.
1436
- *
1437
- * ### Performance
1438
- * - Time complexity: **O(1)** (fixed regex match)
1439
- * - Space complexity: **O(1)** (no allocations beyond regex)
1440
- *
1441
- * ### Examples
1442
- *
1443
- * @example
1444
- * // Valid MAC addresses
1445
- * isMacAddr('00:1A:2B:3C:4D:5E'); // => true
1446
- * isMacAddr('AA-BB-CC-DD-EE-FF'); // => true
1447
- * isMacAddr('ff:ff:ff:ff:ff:ff'); // => true
1448
- *
1449
- * @example
1450
- * // Invalid MAC addresses
1451
- * isMacAddr('00:1A:2B:3C:4D'); // => false (too short)
1452
- * isMacAddr('00:1A:2B:3C:4D:5E:7F'); // => false (too long)
1453
- * isMacAddr('00:1A:2B:3C:4D:ZZ'); // => false (invalid hex)
1454
- * isMacAddr('001A.2B3C.4D5E'); // => false (wrong format)
1455
- * isMacAddr(''); // => false
1456
- *
1457
- * @example
1458
- * // Non-string values
1459
- * isMacAddr(null); // => false
1460
- * isMacAddr(undefined); // => false
1461
- * isMacAddr(123456); // => false
1462
- *
1463
- * @see isStr
1464
- * @see isIp
1465
- *
1466
- * @category Validation
1467
- * @public
1468
- * @since 2.0.0
1469
- */
1470
68
  declare function isMacAddr(value: unknown): value is string;
1471
69
 
1472
- /**
1473
- * Checks whether a given value is a **finite number**.
1474
- *
1475
- * @summary
1476
- * A strict type guard that returns `true` only if `value` is of type `"number"`
1477
- * and is a finite numeric value (not `NaN`, `Infinity`, or `-Infinity`).
1478
- *
1479
- * @param value - Any value to check.
1480
- *
1481
- * @returns `true` if the value is a finite number, otherwise `false`.
1482
- *
1483
- * @remarks
1484
- * ### Behavior
1485
- * - Uses the built-in `typeof` operator to ensure the value is a primitive number.
1486
- * - Rejects special non-finite numeric values:
1487
- * - `NaN`
1488
- * - `Infinity`
1489
- * - `-Infinity`
1490
- * - Does **not** coerce strings — `"123"` returns `false`.
1491
- * - Works only with **number primitives**, not `Number` objects (`new Number(5)` returns `false`).
1492
- *
1493
- * ### Type narrowing
1494
- * When this function returns `true`, TypeScript automatically infers:
1495
- * ```ts
1496
- * value is number
1497
- * ```
1498
- * allowing you to use numeric operators and arithmetic safely.
1499
- *
1500
- * ### Comparison with related checks
1501
- * | Function | Accepts | Rejects |
1502
- * |----------------|---------------------------------|--------------------------------|
1503
- * | `isNum` | finite numbers only | `NaN`, `Infinity`, non-numbers |
1504
- * | `isNumP` | positive finite numbers | `0`, negatives, `NaN` |
1505
- * | `isNumNZ` | zero or negative finite numbers | positives, `NaN` |
1506
- *
1507
- * ### Performance
1508
- * - Time complexity: **O(1)**
1509
- * - Space complexity: **O(1)**
1510
- *
1511
- * ### Examples
1512
- *
1513
- * @example
1514
- * // Valid finite numbers
1515
- * isNum(42); // => true
1516
- * isNum(0); // => true
1517
- * isNum(-3.14); // => true
1518
- *
1519
- * @example
1520
- * // Invalid numeric values
1521
- * isNum(NaN); // => false
1522
- * isNum(Infinity); // => false
1523
- * isNum(-Infinity); // => false
1524
- *
1525
- * @example
1526
- * // Non-number inputs
1527
- * isNum('123'); // => false
1528
- * isNum(true); // => false
1529
- * isNum(null); // => false
1530
- * isNum(undefined); // => false
1531
- *
1532
- * @example
1533
- * // TypeScript narrowing
1534
- * const x: unknown = 100;
1535
- * if (isNum(x)) {
1536
- * console.log(x.toFixed(2)); // OK — x is number
1537
- * }
1538
- *
1539
- * @category Type Guards
1540
- * @public
1541
- * @since 2.0.0
1542
- */
1543
70
  declare function isNum(value: unknown): value is number;
1544
71
 
1545
- /**
1546
- * Checks whether a given value is a **finite non-integer (floating-point) number**.
1547
- *
1548
- * @summary
1549
- * Returns `true` if the value is a finite number and **has a fractional part**
1550
- * (i.e. not an integer).
1551
- * Acts as a strict type guard for float-like numeric values.
1552
- *
1553
- * @param value - Any value to test.
1554
- *
1555
- * @returns `true` if the value is a finite, non-integer number; otherwise `false`.
1556
- *
1557
- * @remarks
1558
- * ### Behavior
1559
- * - First verifies that the value is a finite number via {@link isNum}.
1560
- * - Then ensures it is **not** an integer using `!Number.isInteger(value)`.
1561
- * - Rejects all non-numeric, `NaN`, or infinite values.
1562
- *
1563
- * ### Comparison with related checks
1564
- * | Function | Matches | Rejects |
1565
- * |----------------|--------------------------------|------------------------------------|
1566
- * | `isNum` | any finite number | `NaN`, `Infinity`, `-Infinity` |
1567
- * | `isNumFloat` | finite numbers **with fraction** | integers, `NaN`, non-numbers |
1568
- * | `isNumInt` | finite **integers** only | floats, `NaN`, non-numbers |
1569
- *
1570
- * ### Performance
1571
- * - Time complexity: **O(1)**
1572
- * - Space complexity: **O(1)**
1573
- *
1574
- * ### Examples
1575
- *
1576
- * @example
1577
- * // Valid floats
1578
- * isNumFloat(3.14); // => true
1579
- * isNumFloat(-0.001); // => true
1580
- * isNumFloat(1 / 3); // => true
1581
- *
1582
- * @example
1583
- * // Integers
1584
- * isNumFloat(0); // => false
1585
- * isNumFloat(42); // => false
1586
- * isNumFloat(-7); // => false
1587
- *
1588
- * @example
1589
- * // Invalid or non-number values
1590
- * isNumFloat(NaN); // => false
1591
- * isNumFloat(Infinity); // => false
1592
- * isNumFloat('3.14'); // => false
1593
- * isNumFloat(null); // => false
1594
- *
1595
- * @example
1596
- * // Type narrowing
1597
- * const val: unknown = 12.5;
1598
- * if (isNumFloat(val)) {
1599
- * const n = val * 2; // val is number
1600
- * }
1601
- *
1602
- * @see isNum
1603
- * @see Number.isInteger
1604
- *
1605
- * @category Type Guards
1606
- * @public
1607
- * @since 2.0.0
1608
- */
1609
72
  declare function isNumFloat(value: unknown): value is number;
1610
73
 
1611
- /**
1612
- * Checks whether a given value is a **negative finite number**.
1613
- *
1614
- * @summary
1615
- * A strict type guard that returns `true` only if the input is a finite number
1616
- * and its value is **less than 0**.
1617
- * Useful for safely detecting negative numeric values without coercion.
1618
- *
1619
- * @param value - Any value to test.
1620
- *
1621
- * @returns `true` if the value is a finite number less than zero, otherwise `false`.
1622
- *
1623
- * @remarks
1624
- * ### Behavior
1625
- * - Relies on {@link isNum} to ensure the value is a finite number (not `NaN`, `Infinity`, etc.).
1626
- * - Then checks `value < 0`.
1627
- * - Returns `false` for zero, positive numbers, and all non-numeric types.
1628
- *
1629
- * ### Comparison with related checks
1630
- * | Function | Description | Condition |
1631
- * |--------------|----------------------------------------|-----------------------------|
1632
- * | `isNum` | Any finite number | `Number.isFinite(value)` |
1633
- * | `isNumP` | Positive numbers only | `value > 0` |
1634
- * | `isNumN` | Negative numbers only | `value < 0` |
1635
- * | `isNumNZ` | Negative or zero numbers | `value <= 0` |
1636
- * | `isNumFloat` | Finite non-integer (fractional) numbers | `!Number.isInteger(value)` |
1637
- *
1638
- * ### Performance
1639
- * - Time complexity: **O(1)**
1640
- * - Space complexity: **O(1)**
1641
- *
1642
- * ### Examples
1643
- *
1644
- * @example
1645
- * // Negative numbers
1646
- * isNumN(-1); // => true
1647
- * isNumN(-3.14); // => true
1648
- * isNumN(-0.0001); // => true
1649
- *
1650
- * @example
1651
- * // Non-negative numbers
1652
- * isNumN(0); // => false
1653
- * isNumN(1); // => false
1654
- * isNumN(42); // => false
1655
- *
1656
- * @example
1657
- * // Invalid values
1658
- * isNumN(NaN); // => false
1659
- * isNumN('-5'); // => false
1660
- * isNumN(null); // => false
1661
- * isNumN(undefined); // => false
1662
- *
1663
- * @example
1664
- * // Type narrowing
1665
- * const val: unknown = -12;
1666
- * if (isNumN(val)) {
1667
- * const abs = Math.abs(val); // val is number
1668
- * }
1669
- *
1670
- * @see isNum
1671
- * @see isNumP
1672
- * @see isNumNZ
1673
- * @see isNumFloat
1674
- *
1675
- * @category Type Guards
1676
- * @public
1677
- * @since 2.0.0
1678
- */
1679
74
  declare function isNumN(value: unknown): value is number;
1680
75
 
1681
- /**
1682
- * Checks whether a given value is a **finite number that is less than or equal to zero**.
1683
- *
1684
- * @summary
1685
- * A strict type guard that returns `true` if the input is a finite number and
1686
- * its value is **negative or zero**.
1687
- * Commonly used to identify non-positive numeric values.
1688
- *
1689
- * @param value - Any value to test.
1690
- *
1691
- * @returns `true` if the value is a finite number less than or equal to zero; otherwise `false`.
1692
- *
1693
- * @remarks
1694
- * ### Behavior
1695
- * - Uses {@link isNum} to ensure the input is a finite number (rejects `NaN`, `Infinity`, etc.).
1696
- * - Then checks the condition `value <= 0`.
1697
- * - Returns `false` for all positive numbers and non-numeric values.
1698
- *
1699
- * ### Comparison with related checks
1700
- * | Function | Description | Condition |
1701
- * |--------------|-----------------------------------|----------------|
1702
- * | `isNum` | Any finite number | — |
1703
- * | `isNumP` | Positive numbers only | `value > 0` |
1704
- * | `isNumN` | Negative numbers only | `value < 0` |
1705
- * | `isNumNZ` | Negative **or zero** numbers | `value <= 0` |
1706
- * | `isNumFloat` | Finite non-integer (fractional) | `!Number.isInteger(value)` |
1707
- *
1708
- * ### Performance
1709
- * - Time complexity: **O(1)**
1710
- * - Space complexity: **O(1)**
1711
- *
1712
- * ### Examples
1713
- *
1714
- * @example
1715
- * // Negative and zero values
1716
- * isNumNZ(-1); // => true
1717
- * isNumNZ(-0.5); // => true
1718
- * isNumNZ(0); // => true
1719
- *
1720
- * @example
1721
- * // Positive values
1722
- * isNumNZ(0.0001); // => false
1723
- * isNumNZ(5); // => false
1724
- *
1725
- * @example
1726
- * // Invalid or non-numeric inputs
1727
- * isNumNZ('0'); // => false
1728
- * isNumNZ(NaN); // => false
1729
- * isNumNZ(Infinity); // => false
1730
- * isNumNZ(null); // => false
1731
- *
1732
- * @example
1733
- * // Type narrowing
1734
- * const x: unknown = -10;
1735
- * if (isNumNZ(x)) {
1736
- * console.log(x.toFixed(2)); // x is number
1737
- * }
1738
- *
1739
- * @see isNum
1740
- * @see isNumP
1741
- * @see isNumN
1742
- * @see isNumFloat
1743
- *
1744
- * @category Type Guards
1745
- * @public
1746
- * @since 2.0.0
1747
- */
1748
76
  declare function isNumNZ(value: unknown): value is number;
1749
77
 
1750
- /**
1751
- * Checks whether a given value is a **positive finite number**.
1752
- *
1753
- * @summary
1754
- * A strict type guard that returns `true` only if the input is a finite number
1755
- * greater than zero (`> 0`).
1756
- * Useful for safely validating numeric values that must be positive — such as
1757
- * counters, IDs, amounts, or dimensions.
1758
- *
1759
- * @param value - Any value to test.
1760
- *
1761
- * @returns `true` if the value is a finite positive number, otherwise `false`.
1762
- *
1763
- * @remarks
1764
- * ### Behavior
1765
- * - Uses {@link isNum} to ensure the input is a finite number (`NaN`, `Infinity`, and `-Infinity` are rejected).
1766
- * - Returns `true` only when `value > 0`.
1767
- * - Returns `false` for zero, negative, or non-numeric values.
1768
- *
1769
- * ### Comparison with related checks
1770
- * | Function | Description | Condition |
1771
- * |--------------|-----------------------------------|----------------------------|
1772
- * | `isNum` | Any finite number | — |
1773
- * | `isNumP` | Positive numbers only | `value > 0` |
1774
- * | `isNumN` | Negative numbers only | `value < 0` |
1775
- * | `isNumNZ` | Negative **or zero** numbers | `value <= 0` |
1776
- * | `isNumFloat` | Finite non-integer (fractional) | `!Number.isInteger(value)` |
1777
- *
1778
- * ### Performance
1779
- * - Time complexity: **O(1)**
1780
- * - Space complexity: **O(1)**
1781
- *
1782
- * ### Examples
1783
- *
1784
- * @example
1785
- * // Positive values
1786
- * isNumP(1); // => true
1787
- * isNumP(3.14); // => true
1788
- * isNumP(0.00001); // => true
1789
- *
1790
- * @example
1791
- * // Zero and negatives
1792
- * isNumP(0); // => false
1793
- * isNumP(-1); // => false
1794
- * isNumP(-0.5); // => false
1795
- *
1796
- * @example
1797
- * // Invalid or non-numeric inputs
1798
- * isNumP('5'); // => false
1799
- * isNumP(NaN); // => false
1800
- * isNumP(Infinity); // => false
1801
- * isNumP(null); // => false
1802
- *
1803
- * @example
1804
- * // Type narrowing
1805
- * const x: unknown = 12;
1806
- * if (isNumP(x)) {
1807
- * console.log(x.toFixed(1)); // x is number
1808
- * }
1809
- *
1810
- * @see isNum
1811
- * @see isNumN
1812
- * @see isNumNZ
1813
- * @see isNumFloat
1814
- *
1815
- * @category Type Guards
1816
- * @public
1817
- * @since 2.0.0
1818
- */
1819
78
  declare function isNumP(value: unknown): value is number;
1820
79
 
1821
- /**
1822
- * Checks whether a given value is a **finite number greater than or equal to zero**.
1823
- *
1824
- * @summary
1825
- * A strict type guard that returns `true` if the input is a finite number
1826
- * and its value is **non-negative** (`≥ 0`).
1827
- * Useful for safely validating values such as counters, sizes, durations,
1828
- * and other quantities that cannot be negative.
1829
- *
1830
- * @param value - Any value to test.
1831
- *
1832
- * @returns `true` if the value is a finite number greater than or equal to zero; otherwise `false`.
1833
- *
1834
- * @remarks
1835
- * ### Behavior
1836
- * - Uses {@link isNum} to ensure the input is a finite number (`NaN`, `Infinity`, `-Infinity` are rejected).
1837
- * - Returns `true` when `value >= 0`.
1838
- * - Returns `false` for negative numbers or non-numeric inputs.
1839
- *
1840
- * ### Comparison with related checks
1841
- * | Function | Description | Condition |
1842
- * |--------------|----------------------------------|----------------------------|
1843
- * | `isNum` | Any finite number | — |
1844
- * | `isNumP` | Positive numbers only | `value > 0` |
1845
- * | `isNumPZ` | Non-negative numbers (`≥ 0`) | `value >= 0` |
1846
- * | `isNumN` | Negative numbers only | `value < 0` |
1847
- * | `isNumNZ` | Negative or zero numbers | `value <= 0` |
1848
- * | `isNumFloat` | Finite non-integer numbers | `!Number.isInteger(value)` |
1849
- *
1850
- * ### Performance
1851
- * - Time complexity: **O(1)**
1852
- * - Space complexity: **O(1)**
1853
- *
1854
- * ### Examples
1855
- *
1856
- * @example
1857
- * // Non-negative numbers
1858
- * isNumPZ(0); // => true
1859
- * isNumPZ(5); // => true
1860
- * isNumPZ(3.14); // => true
1861
- *
1862
- * @example
1863
- * // Negative numbers
1864
- * isNumPZ(-1); // => false
1865
- * isNumPZ(-0.1); // => false
1866
- *
1867
- * @example
1868
- * // Invalid or non-numeric inputs
1869
- * isNumPZ('10'); // => false
1870
- * isNumPZ(NaN); // => false
1871
- * isNumPZ(Infinity); // => false
1872
- * isNumPZ(null); // => false
1873
- *
1874
- * @example
1875
- * // Type narrowing
1876
- * const val: unknown = 7;
1877
- * if (isNumPZ(val)) {
1878
- * console.log(Math.sqrt(val)); // val is number
1879
- * }
1880
- *
1881
- * @see isNum
1882
- * @see isNumP
1883
- * @see isNumN
1884
- * @see isNumNZ
1885
- * @see isNumFloat
1886
- *
1887
- * @category Type Guards
1888
- * @public
1889
- * @since 2.0.0
1890
- */
1891
80
  declare function isNumPZ(value: unknown): value is number;
1892
81
 
1893
- /**
1894
- * Checks whether a given value is a **plain object** (i.e. `{}`), not `null`, not an array, and not a class instance.
1895
- *
1896
- * @summary
1897
- * A strict type guard that returns `true` only if the input is a plain object
1898
- * created using an object literal (`{}`) or `Object.create(null)`.
1899
- * Excludes arrays, functions, `null`, and instances of custom classes.
1900
- *
1901
- * @param value - Any value to test.
1902
- *
1903
- * @returns `true` if the value is a non-null, non-array plain object; otherwise `false`.
1904
- *
1905
- * @remarks
1906
- * ### Behavior
1907
- * The check ensures all of the following:
1908
- * 1. `typeof value === "object"` — confirms the value is object-like.
1909
- * 2. `value !== null` — excludes `null`, since `typeof null === "object"`.
1910
- * 3. `Object.prototype.toString.call(value) === "[object Object]"` — filters out built-ins like `Map`, `Set`, `Date`, etc.
1911
- * 4. `!Array.isArray(value)` — ensures arrays are excluded.
1912
- *
1913
- * ### What counts as a "plain object"
1914
- * `{}`, `{ a: 1 }`, `Object.create(null)`
1915
- * `[]`, `new Date()`, `new Map()`, `null`, class instances.
1916
- *
1917
- * ### Comparison with related concepts
1918
- * | Example value | Result | Explanation |
1919
- * |--------------------------|---------|----------------------------------|
1920
- * | `{}` | true | Plain object |
1921
- * | `Object.create(null)` | true | No prototype but still object |
1922
- * | `[]` | false | Array excluded |
1923
- * | `null` | false | Explicitly filtered |
1924
- * | `new Date()` | false | Built-in class instance |
1925
- * | `class A {}; new A()` | false | Custom class instance |
1926
- *
1927
- * ### Type narrowing
1928
- * When this function returns `true`, TypeScript infers:
1929
- * ```ts
1930
- * value is Record<string, unknown>
1931
- * ```
1932
- * allowing safe property access and iteration.
1933
- *
1934
- * ### Performance
1935
- * - Time complexity: **O(1)**
1936
- * - Space complexity: **O(1)**
1937
- *
1938
- * ### Examples
1939
- *
1940
- * @example
1941
- * // Plain objects
1942
- * isObj({}); // => true
1943
- * isObj({ key: 'value' }); // => true
1944
- * isObj(Object.create(null)); // => true
1945
- *
1946
- * @example
1947
- * // Non-objects or special cases
1948
- * isObj(null); // => false
1949
- * isObj([]); // => false
1950
- * isObj(new Date()); // => false
1951
- * isObj(new Map()); // => false
1952
- * isObj(() => {}); // => false
1953
- *
1954
- * @example
1955
- * // Type narrowing
1956
- * const val: unknown = { x: 1 };
1957
- * if (isObj(val)) {
1958
- * console.log(val.x); // safe: val is Record<string, unknown>
1959
- * }
1960
- *
1961
- * @category Type Guards
1962
- * @public
1963
- * @since 2.0.0
1964
- */
1965
82
  declare function isObj(value: unknown): value is Record<string, unknown>;
1966
83
 
1967
- /**
1968
- * Checks whether a given value is a **non-empty plain object**.
1969
- *
1970
- * @summary
1971
- * A strict type guard that returns `true` only if the input is a plain object
1972
- * (validated by {@link isObj}) **and** has at least one own enumerable key.
1973
- * In other words, it must be an object literal like `{ a: 1 }`, not `{}`.
1974
- *
1975
- * @param value - Any value to test.
1976
- *
1977
- * @returns `true` if the value is a plain object with at least one own property; otherwise `false`.
1978
- *
1979
- * @remarks
1980
- * ### Behavior
1981
- * - Uses {@link isObj} to verify the value is a plain object (not `null`, not an array, not a class instance).
1982
- * - Calls `Object.keys(value).length > 0` to ensure the object has one or more keys.
1983
- * - Returns `false` for empty objects (`{}`), arrays, functions, `null`, and other non-object types.
1984
- *
1985
- * ### Comparison with related checks
1986
- * | Function | Description | Example |
1987
- * |------------------|---------------------------------------|----------------------|
1988
- * | `isObj` | Checks if value is a plain object | `{}` true / `[]` false |
1989
- * | `isObjFilled` | Checks if plain object is **non-empty** | `{a: 1}` true / `{}` false |
1990
- * | `isArrFilled` | Checks if array is non-empty | `[1]` true / `[]` false |
1991
- * | `isStrFilled` | Checks if string is non-empty | `'a'` true / `''` false |
1992
- *
1993
- * ### Type narrowing
1994
- * When this function returns `true`, TypeScript infers:
1995
- * ```ts
1996
- * value is Record<string, unknown>
1997
- * ```
1998
- * allowing safe property access and iteration.
1999
- *
2000
- * ### Performance
2001
- * - Time complexity: **O(n)** — proportional to the number of object keys.
2002
- * - Space complexity: **O(1)**.
2003
- *
2004
- * ### Examples
2005
- *
2006
- * @example
2007
- * // Non-empty plain objects
2008
- * isObjFilled({ a: 1 }); // => true
2009
- * isObjFilled({ key: null }); // => true
2010
- * isObjFilled({ nested: {} }); // => true
2011
- *
2012
- * @example
2013
- * // Empty or invalid objects
2014
- * isObjFilled({}); // => false
2015
- * isObjFilled([]); // => false
2016
- * isObjFilled(null); // => false
2017
- * isObjFilled(new Date()); // => false
2018
- *
2019
- * @example
2020
- * // Type narrowing
2021
- * const data: unknown = { x: 5 };
2022
- * if (isObjFilled(data)) {
2023
- * console.log(Object.keys(data)); // safe
2024
- * }
2025
- *
2026
- * @see isObj
2027
- * @see isArrFilled
2028
- * @see isStrFilled
2029
- *
2030
- * @category Type Guards
2031
- * @public
2032
- * @since 2.0.0
2033
- */
2034
84
  declare function isObjFilled(value: unknown): value is Record<string, unknown>;
2035
85
 
2036
86
  type Primitive = string | number | boolean | bigint | symbol | null | undefined;
2037
87
  declare function isObjFlat(value: unknown): value is Record<string, Primitive>;
2038
88
 
2039
- /**
2040
- * Validates whether a string meets configurable **password strength requirements**.
2041
- *
2042
- * @summary
2043
- * A flexible password validation helper that checks for length, uppercase and lowercase letters,
2044
- * digits, and special characters.
2045
- * All rules are configurable through the optional {@link PasswordOptions} parameter.
2046
- *
2047
- * @param value - The value to validate as a password.
2048
- * @param options - Optional validation rules (see {@link PasswordOptions}).
2049
- * Defaults ensure strong password requirements:
2050
- * ```ts
2051
- * {
2052
- * minLength: 8,
2053
- * maxLength: 256,
2054
- * requireUppercase: true,
2055
- * requireLowercase: true,
2056
- * requireDigit: true,
2057
- * requireSpecial: true
2058
- * }
2059
- * ```
2060
- *
2061
- * @returns `true` if the value is a valid string matching all configured requirements, otherwise `false`.
2062
- *
2063
- * @remarks
2064
- * ### Behavior
2065
- * 1. Ensures `value` is a string using {@link isStr}.
2066
- * 2. Enforces **length limits** (`minLength` ≤ length ≤ `maxLength`).
2067
- * 3. Optionally checks for:
2068
- * - Uppercase characters (Latin or Cyrillic): `/[A-ZА-Я]/`
2069
- * - Lowercase characters (Latin or Cyrillic): `/[a-zа-я]/`
2070
- * - Digits: `/\d/`
2071
- * - Special characters: `/[~!?@#$%^&*_\-+()\[\]{}><\\\/|"'.,:;=]/`
2072
- * 4. Returns `true` only if all active checks pass.
2073
- *
2074
- * ### Default rule set (strong password)
2075
- * - At least 8 characters long
2076
- * - Contains uppercase and lowercase letters
2077
- * - Contains at least one digit
2078
- * - Contains at least one special symbol
2079
- * - Not longer than 256 characters
2080
- *
2081
- * ### Example configuration
2082
- * ```ts
2083
- * // Minimal check — only length between 6 and 20
2084
- * isPassword('abcdef', { minLength: 6, maxLength: 20, requireSpecial: false });
2085
- *
2086
- * // Strict corporate policy
2087
- * isPassword('Qwerty#123', { minLength: 10, requireSpecial: true });
2088
- *
2089
- * // Simplified mobile app rule
2090
- * isPassword('myPass1', { requireSpecial: false });
2091
- * ```
2092
- *
2093
- * ### Type narrowing
2094
- * When this function returns `true`, TypeScript infers:
2095
- * ```ts
2096
- * value is string
2097
- * ```
2098
- * allowing you to safely treat it as a verified password.
2099
- *
2100
- * ### Performance
2101
- * - Time complexity: **O(n)** (depends on string length and regex scans).
2102
- * - Space complexity: **O(1)**.
2103
- *
2104
- * ### Examples
2105
- *
2106
- * @example
2107
- * // Default strong policy (8+ chars, upper, lower, digit, special)
2108
- * isPassword('Aa1@aaaa'); // => true
2109
- * isPassword('Password123!'); // => true
2110
- * isPassword('qwerty'); // => false (no upper/digit/special)
2111
- *
2112
- * @example
2113
- * // Custom rules
2114
- * isPassword('abc123', {
2115
- * minLength: 6,
2116
- * requireUppercase: false,
2117
- * requireSpecial: false
2118
- * }); // => true
2119
- *
2120
- * @example
2121
- * // Invalid inputs
2122
- * isPassword(''); // => false
2123
- * isPassword(null); // => false
2124
- * isPassword(undefined); // => false
2125
- * isPassword(123456); // => false
2126
- *
2127
- * @see isStr
2128
- *
2129
- * @category Validation
2130
- * @public
2131
- * @since 2.0.0
2132
- */
2133
89
  declare function isPassword(value: unknown, { minLength, maxLength, requireUppercase, requireLowercase, requireDigit, requireSpecial, }?: PasswordOptions): value is string;
2134
90
 
2135
- /**
2136
- * Checks whether a given value is a **valid phone number** in a generic international format.
2137
- *
2138
- * @summary
2139
- * A flexible, language-neutral phone number validator that accepts both string and numeric inputs.
2140
- * It supports optional leading `"+"`, allows dashes (`"-"`) as separators, and ensures that the
2141
- * number structure is syntactically valid — not necessarily region-specific.
2142
- *
2143
- * @param value - Any value to test (string or number).
2144
- *
2145
- * @returns `true` if the value represents a valid phone-like number, otherwise `false`.
2146
- *
2147
- * @remarks
2148
- * ### Validation logic
2149
- * 1. **Type check:**
2150
- * Accepts strings and finite numbers (`isStrFilled` or `isNum` must pass).
2151
- * 2. **Normalization:**
2152
- * Converts to string and trims whitespace.
2153
- * 3. **Negative or misplaced signs:**
2154
- * Rejects numbers starting with `"-"`.
2155
- * 4. **Plus sign validation:**
2156
- * - Only one `+` is allowed.
2157
- * - If present, it must appear **only at the start**.
2158
- * 5. **Character whitelist:**
2159
- * The number must match the pattern `/^\+?[0-9-]+$/`,
2160
- * i.e., only digits, dashes, and an optional leading plus sign.
2161
- * 6. **Length check:**
2162
- * Must be between **3** and **20** characters (inclusive).
2163
- * 7. **Ending rule:**
2164
- * The last character must be a digit.
2165
- * 8. **Double-dash check:**
2166
- * Rejects sequences containing `"--"`.
2167
- *
2168
- * ### Behavior
2169
- * - Accepts: `+1234567890`, `380-67-123-4567`, `79001234567`, `12345`.
2170
- * - Rejects: `"--123"`, `"++123"`, `"12a34"`, `"12 34"`, `"-123"`, `"123-"`.
2171
- * - Not region-specific — does **not** check country codes or local dialing rules.
2172
- * - Designed for structural validation only.
2173
- *
2174
- * ### Comparison
2175
- * | Example | Valid | Reason |
2176
- * |----------------------|:------:|--------------------------------|
2177
- * | `+380671234567` | true | Proper international format |
2178
- * | `067-123-4567` | true | Local format with dashes |
2179
- * | `123` | true | Minimum valid length |
2180
- * | `+12-34-56--78` | false | Contains `"--"` |
2181
- * | `+12A345` | false | Contains letters |
2182
- * | `123-` | false | Ends with non-digit |
2183
- * | `++38050` | false | Multiple `"+"` symbols |
2184
- * | `380+501234` | false | Misplaced plus |
2185
- *
2186
- * ### Type narrowing
2187
- * When this function returns `true`, TypeScript infers:
2188
- * ```ts
2189
- * value is string
2190
- * ```
2191
- * even if the original value was numeric — ensuring it can be safely stored or formatted as text.
2192
- *
2193
- * ### Performance
2194
- * - Time complexity: **O(n)** — single regex checks and scans.
2195
- * - Space complexity: **O(1)**.
2196
- *
2197
- * ### Examples
2198
- *
2199
- * @example
2200
- * // Valid international numbers
2201
- * isPhone('+380671234567'); // => true
2202
- * isPhone('380-67-123-4567'); // => true
2203
- * isPhone(380501234567); // => true
2204
- *
2205
- * @example
2206
- * // Invalid formats
2207
- * isPhone('--12345'); // => false
2208
- * isPhone('+12+34'); // => false
2209
- * isPhone('12A345'); // => false
2210
- * isPhone('123-'); // => false
2211
- * isPhone(''); // => false
2212
- *
2213
- * @example
2214
- * // Type narrowing
2215
- * const val: unknown = '+14155552671';
2216
- * if (isPhone(val)) {
2217
- * console.log(val.replace(/\D/g, '')); // safe normalization
2218
- * }
2219
- *
2220
- * @see isStrFilled
2221
- * @see isNum
2222
- * @see formatToPhone
2223
- *
2224
- * @category Validation
2225
- * @public
2226
- * @since 2.0.0
2227
- */
2228
91
  declare function isPhone(value: unknown): value is string;
2229
92
 
2230
- /**
2231
- * Checks whether a given value is a **string** primitive.
2232
- *
2233
- * @summary
2234
- * A strict type guard that returns `true` only if the provided value
2235
- * has the JavaScript type `"string"`.
2236
- * Rejects all non-string types, including `String` objects created via `new String()`.
2237
- *
2238
- * @param value - Any value to test.
2239
- *
2240
- * @returns `true` if the value is a string primitive, otherwise `false`.
2241
- *
2242
- * @remarks
2243
- * ### Behavior
2244
- * - Uses the `typeof` operator for a strict type check.
2245
- * - Does **not** coerce values — `"123"` is valid, but `123` is not.
2246
- * - Returns `false` for:
2247
- * - `String` wrapper objects (`new String('abc')`)
2248
- * - Non-string types (`number`, `boolean`, `object`, `undefined`, etc.)
2249
- *
2250
- * ### Type narrowing
2251
- * When this function returns `true`, TypeScript infers:
2252
- * ```ts
2253
- * value is string
2254
- * ```
2255
- * enabling full access to string methods safely.
2256
- *
2257
- * ### Comparison
2258
- * | Input | Result | Note |
2259
- * |------------------|:------:|-----------------------------------|
2260
- * | `'hello'` | true | String literal |
2261
- * | `new String('x')`| false | Object wrapper, not primitive |
2262
- * | `123` | false | Number |
2263
- * | `null` | false | Not a string |
2264
- * | `undefined` | false | Not a string |
2265
- *
2266
- * ### Performance
2267
- * - Time complexity: **O(1)**
2268
- * - Space complexity: **O(1)**
2269
- *
2270
- * ### Examples
2271
- *
2272
- * @example
2273
- * // Basic usage
2274
- * isStr('Hello'); // => true
2275
- * isStr(''); // => true
2276
- * isStr(123); // => false
2277
- * isStr(null); // => false
2278
- *
2279
- * @example
2280
- * // Type narrowing
2281
- * const val: unknown = 'abc';
2282
- * if (isStr(val)) {
2283
- * console.log(val.toUpperCase()); // safe
2284
- * }
2285
- *
2286
- * @category Type Guards
2287
- * @public
2288
- * @since 2.0.0
2289
- */
2290
93
  declare function isStr(value: unknown): value is string;
2291
94
 
2292
- /**
2293
- * Checks whether a given value is a **string representation of a boolean** — `"true"` or `"false"`.
2294
- *
2295
- * @summary
2296
- * A strict type guard that returns `true` if the input is a non-empty string
2297
- * equal to `"true"` or `"false"` (case-insensitive, with whitespace ignored).
2298
- * Commonly used for validating query parameters, environment variables, or serialized booleans.
2299
- *
2300
- * @param value - Any value to test.
2301
- *
2302
- * @returns `true` if the value is a string `"true"` or `"false"` (ignoring case and whitespace), otherwise `false`.
2303
- *
2304
- * @remarks
2305
- * ### Behavior
2306
- * 1. Uses {@link isStrFilled} to ensure the input is a non-empty string.
2307
- * 2. Trims whitespace and converts it to lowercase.
2308
- * 3. Returns `true` only if the normalized string equals `"true"` or `"false"`.
2309
- * 4. Returns `false` for other strings, numbers, or non-string types.
2310
- *
2311
- * ### Typical usage
2312
- * This utility is helpful when you need to:
2313
- * - Parse stringified boolean flags (`'true'`, `'false'`)
2314
- * - Validate configuration or query params
2315
- * - Handle environment variables (`process.env.FEATURE_ENABLED`)
2316
- *
2317
- * ### Type narrowing
2318
- * When this function returns `true`, TypeScript infers:
2319
- * ```ts
2320
- * value is string
2321
- * ```
2322
- * and you can safely pass it to a boolean converter (e.g. `formatToBool()`).
2323
- *
2324
- * ### Performance
2325
- * - Time complexity: **O(1)**
2326
- * - Space complexity: **O(1)**
2327
- *
2328
- * ### Examples
2329
- *
2330
- * @example
2331
- * // Valid boolean strings
2332
- * isStrBool('true'); // => true
2333
- * isStrBool('FALSE'); // => true
2334
- * isStrBool(' True '); // => true
2335
- *
2336
- * @example
2337
- * // Invalid strings
2338
- * isStrBool('yes'); // => false
2339
- * isStrBool('0'); // => false
2340
- * isStrBool(''); // => false
2341
- *
2342
- * @example
2343
- * // Non-string inputs
2344
- * isStrBool(true); // => false
2345
- * isStrBool(1); // => false
2346
- * isStrBool(null); // => false
2347
- *
2348
- * @example
2349
- * // Combined with formatToBool()
2350
- * import { formatToBool } from '../bool/formatToBool';
2351
- *
2352
- * const val: unknown = 'False';
2353
- * if (isStrBool(val)) {
2354
- * console.log(formatToBool(val)); // false
2355
- * }
2356
- *
2357
- * @see isStr
2358
- * @see isStrFilled
2359
- * @see isBool
2360
- * @see formatToBool
2361
- *
2362
- * @category Validation
2363
- * @public
2364
- * @since 2.0.0
2365
- */
2366
95
  declare function isStrBool(value: unknown): value is string;
2367
96
 
2368
- /**
2369
- * Checks whether a given value is a **non-empty string** (not just whitespace).
2370
- *
2371
- * @summary
2372
- * A strict type guard that returns `true` only if the value is a string
2373
- * containing at least one non-whitespace character.
2374
- * This is an extended form of {@link isStr} that excludes empty (`""`) and
2375
- * whitespace-only strings (`" "`).
2376
- *
2377
- * @param value - Any value to test.
2378
- *
2379
- * @returns `true` if the value is a string with visible content, otherwise `false`.
2380
- *
2381
- * @remarks
2382
- * ### Behavior
2383
- * - Uses {@link isStr} to confirm the value is a string primitive.
2384
- * - Calls `.trim()` to remove whitespace and checks if the resulting length is greater than zero.
2385
- * - Returns `false` for:
2386
- * - Empty strings (`""`)
2387
- * - Whitespace-only strings (`" "`, `"\n"`, `"\t"`)
2388
- * - Non-string values (`number`, `boolean`, `object`, `null`, etc.)
2389
- *
2390
- * ### Comparison
2391
- * | Function | Description | Example |
2392
- * |-----------------|-----------------------------------|---------------------------|
2393
- * | `isStr` | Any string (including empty) | `""` true |
2394
- * | `isStrFilled` | Non-empty trimmed string only | `" "` false / `"x"` true |
2395
- *
2396
- * ### Type narrowing
2397
- * When this function returns `true`, TypeScript infers:
2398
- * ```ts
2399
- * value is string
2400
- * ```
2401
- * ensuring safe use of string operations.
2402
- *
2403
- * ### Performance
2404
- * - Time complexity: **O(n)** (due to `.trim()`).
2405
- * - Space complexity: **O(1)**.
2406
- *
2407
- * ### Examples
2408
- *
2409
- * @example
2410
- * // Valid strings
2411
- * isStrFilled('hello'); // => true
2412
- * isStrFilled(' text '); // => true
2413
- *
2414
- * @example
2415
- * // Empty or whitespace-only
2416
- * isStrFilled(''); // => false
2417
- * isStrFilled(' '); // => false
2418
- *
2419
- * @example
2420
- * // Non-string values
2421
- * isStrFilled(null); // => false
2422
- * isStrFilled(123); // => false
2423
- * isStrFilled(undefined); // => false
2424
- *
2425
- * @example
2426
- * // Type narrowing
2427
- * const val: unknown = ' value ';
2428
- * if (isStrFilled(val)) {
2429
- * console.log(val.trim().toUpperCase()); // safe
2430
- * }
2431
- *
2432
- * @see isStr
2433
- * @see isArrFilled
2434
- * @see isObjFilled
2435
- *
2436
- * @category Type Guards
2437
- * @public
2438
- * @since 2.0.0
2439
- */
2440
97
  declare function isStrFilled(value: unknown): value is string;
2441
98
 
2442
- /**
2443
- * Checks whether a given value is a string equal to **"asc"** or **"desc"** (case-insensitive).
2444
- *
2445
- * @summary
2446
- * A strict type guard that validates sorting direction strings —
2447
- * `"asc"` (ascending) or `"desc"` (descending).
2448
- * Useful for validating API parameters, SQL sort directives, or UI sort controls.
2449
- *
2450
- * @param value - Any value to test.
2451
- *
2452
- * @returns `true` if the value is a non-empty string representing `"asc"` or `"desc"`, otherwise `false`.
2453
- *
2454
- * @remarks
2455
- * ### Behavior
2456
- * 1. Uses {@link isStrFilled} to ensure the value is a non-empty string.
2457
- * 2. Trims whitespace and converts it to lowercase.
2458
- * 3. Returns `true` only if the normalized value equals `"asc"` or `"desc"`.
2459
- * 4. Returns `false` for empty strings, other words, or non-string types.
2460
- *
2461
- * ### Type narrowing
2462
- * When this function returns `true`, TypeScript infers:
2463
- * ```ts
2464
- * value is 'asc' | 'desc'
2465
- * ```
2466
- * which is ideal for type-safe sort order handling in functions and APIs.
2467
- *
2468
- * ### Performance
2469
- * - Time complexity: **O(1)** (fixed length checks)
2470
- * - Space complexity: **O(1)**
2471
- *
2472
- * ### Examples
2473
- *
2474
- * @example
2475
- * // Valid inputs
2476
- * isStrAscDesc('asc'); // => true
2477
- * isStrAscDesc('DESC'); // => true
2478
- * isStrAscDesc(' Asc '); // => true
2479
- *
2480
- * @example
2481
- * // Invalid inputs
2482
- * isStrAscDesc('ascending'); // => false
2483
- * isStrAscDesc(''); // => false
2484
- * isStrAscDesc(null); // => false
2485
- * isStrAscDesc('up'); // => false
2486
- *
2487
- * @example
2488
- * // Type narrowing in use
2489
- * function sortData(order: unknown) {
2490
- * if (isStrAscDesc(order)) {
2491
- * console.log(`Sorting in ${order} order`);
2492
- * } else {
2493
- * console.log('Invalid sort direction');
2494
- * }
2495
- * }
2496
- *
2497
- * @see isStr
2498
- * @see isStrFilled
2499
- *
2500
- * @category Validation
2501
- * @public
2502
- * @since 2.0.0
2503
- */
2504
99
  declare function isStrAscDesc(value: unknown): value is 'asc' | 'desc';
2505
100
 
2506
- /**
2507
- * Checks whether a given value is a **valid variable-like identifier**.
2508
- *
2509
- * @summary
2510
- * A strict type guard that returns `true` only if the value is a string
2511
- * matching the pattern of a valid **programming variable name**:
2512
- * must start with a letter (`A–Z`, `a–z`) or underscore (`_`),
2513
- * and may contain only letters, digits, or underscores afterward.
2514
- *
2515
- * @param value - Any value to test.
2516
- *
2517
- * @returns `true` if the value is a syntactically valid variable name; otherwise `false`.
2518
- *
2519
- * @remarks
2520
- * ### Validation rule
2521
- * Uses the following regular expression:
2522
- * ```regex
2523
- * /^[A-Za-z_][A-Za-z0-9_]*$/
2524
- * ```
2525
- * This enforces:
2526
- * - **First character:** a Latin letter (`A–Z`, `a–z`) or underscore (`_`)
2527
- * - **Subsequent characters:** any combination of letters, digits, or underscores
2528
- * - **No spaces, symbols, or Unicode letters** are allowed
2529
- *
2530
- * ### Typical use cases
2531
- * - Validating variable names in configuration files or templates
2532
- * - Checking safe property keys for code generation
2533
- * - Ensuring identifiers in scripting or parsing logic
2534
- *
2535
- * ### Behavior
2536
- * - Returns `false` for:
2537
- * - Strings starting with digits (`"1abc"`)
2538
- * - Strings containing hyphens or spaces (`"my-var"`, `"user name"`)
2539
- * - Empty strings or non-string values
2540
- * - Returns `true` for:
2541
- * - `"name"`, `"_value"`, `"myVar1"`, `"SOME_CONSTANT"`
2542
- *
2543
- * ### Type narrowing
2544
- * When this function returns `true`, TypeScript infers:
2545
- * ```ts
2546
- * value is string
2547
- * ```
2548
- * ensuring safe string usage in contexts like symbol tables or identifier maps.
2549
- *
2550
- * ### Performance
2551
- * - Time complexity: **O(n)** — proportional to string length (regex evaluation)
2552
- * - Space complexity: **O(1)**
2553
- *
2554
- * ### Examples
2555
- *
2556
- * @example
2557
- * // Valid identifiers
2558
- * isVar('name'); // => true
2559
- * isVar('_id'); // => true
2560
- * isVar('myVar1'); // => true
2561
- * isVar('SOME_CONSTANT'); // => true
2562
- *
2563
- * @example
2564
- * // Invalid identifiers
2565
- * isVar(''); // => false
2566
- * isVar('1var'); // => false
2567
- * isVar('user-name'); // => false
2568
- * isVar('my var'); // => false
2569
- * isVar('$value'); // => false
2570
- *
2571
- * @example
2572
- * // Non-string values
2573
- * isVar(null); // => false
2574
- * isVar(123); // => false
2575
- * isVar({}); // => false
2576
- *
2577
- * @see isStr
2578
- * @see isStrFilled
2579
- *
2580
- * @category Validation
2581
- * @public
2582
- * @since 2.0.0
2583
- */
2584
101
  declare function isVar(value: unknown): value is string;
2585
102
 
2586
103
  declare function isClass(value: unknown): boolean;
2587
104
 
2588
- /**
2589
- * Structural JSON-like type used throughout decoding.
2590
- *
2591
- * @remarks
2592
- * This mirrors the standard JSON value domain:
2593
- * `null`, booleans, numbers, strings, arrays of JSON-like values,
2594
- * and plain object maps with string keys pointing to JSON-like values.
2595
- *
2596
- * @public
2597
- * @category JSON
2598
- * @since 2.0.0
2599
- */
2600
- type JSONLike = null | boolean | number | string | JSONLike[] | {
2601
- [k: string]: JSONLike;
2602
- };
2603
-
2604
- /**
2605
- * Parses a string that may represent JSON, quoted scalars, or plain text.
2606
- *
2607
- * @remarks
2608
- * The parsing order is:
2609
- *
2610
- * 1. Try JSON via {@link jsonParse}. If it works, return the parsed value.
2611
- * 2. If not JSON, check if the string is quoted with `'`, `"` or `` ` ``.
2612
- * If quoted, return the **unquoted** inner text.
2613
- * 3. If not quoted:
2614
- * - If `allowString === true`, return the **trimmed** string as-is.
2615
- * - Otherwise return `null`.
2616
- *
2617
- * This helper is used recursively by {@link jsonDecode} to decode string fields
2618
- * found inside arrays/objects.
2619
- *
2620
- * @param s - Source string.
2621
- * @param allowString - Whether to allow returning raw (unquoted) strings.
2622
- * @returns A JSON-like value, or `null` if the string cannot be interpreted
2623
- * and `allowString` is `false`.
2624
- *
2625
- * @example
2626
- * ```ts
2627
- * jsonStrLike('{"a":1}', false); // -> { a: 1 }
2628
- * jsonStrLike('"hello"', false); // -> "hello"
2629
- * jsonStrLike('hello', false); // -> null
2630
- * jsonStrLike('hello', true); // -> "hello"
2631
- * ```
2632
- *
2633
- * @internal
2634
- */
2635
- declare function jsonStrLike(s: string, allowString: boolean): JSONLike | null;
2636
-
2637
- /**
2638
- * Attempts to parse a string using native {@link JSON.parse}.
2639
- *
2640
- * @remarks
2641
- * Returns a discriminated union with `{ ok: true, value }` on success,
2642
- * or `{ ok: false }` on any parsing error. Exceptions are caught and
2643
- * **never thrown** to callers.
2644
- *
2645
- * @param str - The candidate JSON string.
2646
- * @returns A result object indicating parse success/failure.
2647
- *
2648
- * @example
2649
- * ```ts
2650
- * jsonParse('{"a":1}'); // { ok: true, value: { a: 1 } }
2651
- * jsonParse('not json'); // { ok: false }
2652
- * ```
2653
- *
2654
- * @internal
2655
- */
2656
- declare function jsonParse(str: string): {
2657
- ok: true;
2658
- value: JSONLike;
2659
- } | {
2660
- ok: false;
2661
- };
2662
-
2663
- /**
2664
- * Best-effort decoder that normalizes unknown input into a JSON-like value.
2665
- *
2666
- * @remarks
2667
- * `jsonDecode` accepts many shapes of input and produces a `JSONLike` (or `null`)
2668
- * according to the following rules:
2669
- *
2670
- * - **Primitive passthrough**: `null`, numbers, and booleans are returned as-is.
2671
- * - **Arrays/Objects (filled)**: for each string element/property, we attempt to decode
2672
- * it via {@link jsonStrLike} (JSON → unquoted string → raw string if `allowString`).
2673
- * Non-string items are passed through unchanged (cast to `JSONLike`).
2674
- * - **Arrays/Objects (empty)**: returned as-is (they’re valid JSON).
2675
- * - **Standalone strings**: decoded via {@link jsonStrLike}.
2676
- * - **Other values**: return `null`.
2677
- *
2678
- * The function is **non-throwing**; any JSON parse errors are swallowed internally
2679
- * and mapped to either unquoted/raw strings (depending on `allowString`) or `null`.
2680
- *
2681
- * - Uses native `JSON.parse` — safe for untrusted strings provided you do not eval the result.
2682
- * - Does **not** perform schema validation; if you need strict shapes, validate after decoding.
2683
- *
2684
- * @typeParam T - Target type to cast the normalized result to.
2685
- * Defaults to `JSONLike`. Use with care — this is a **type cast**, not a runtime check.
2686
- *
2687
- * @param value - The unknown input to decode (can be primitives, arrays, objects, etc.).
2688
- * @param allowString - If `true`, non-JSON, non-quoted strings are returned as trimmed strings.
2689
- * If `false`, such strings decode to `null`.
2690
- *
2691
- * @returns The decoded value cast to `T`, or `null` when it cannot be decoded.
2692
- *
2693
- * @example
2694
- * ```ts
2695
- * // 1) Primitives pass through
2696
- * jsonDecode(42); // 42
2697
- * jsonDecode(true); // true
2698
- * jsonDecode(null); // null
2699
- *
2700
- * // 2) JSON string
2701
- * jsonDecode('{"a":[1,"2"]}'); // { a: [1, "2"] }
2702
- *
2703
- * // 3) Quoted string
2704
- * jsonDecode('"hello"'); // "hello"
2705
- *
2706
- * // 4) Raw string with allowString=false (default)
2707
- * jsonDecode('hello'); // null
2708
- *
2709
- * // 5) Raw string with allowString=true
2710
- * jsonDecode('hello', true); // "hello"
2711
- *
2712
- * // 6) Arrays/objects with string fields get per-field decoding
2713
- * jsonDecode({ a: '{"k":1}', b: 'world' }, true);
2714
- * // -> { a: { k: 1 }, b: "world" }
2715
- * ```
2716
- *
2717
- * @throws Never throws; invalid inputs yield `null` or are passed through per rules above.
2718
- *
2719
- * @public
2720
- * @category JSON
2721
- * @since 2.0.0
2722
- */
2723
- declare function jsonDecode<T = JSONLike>(value: unknown, allowString?: boolean): T | null;
2724
-
2725
- /**
2726
- * Safely serializes a plain object or array into a JSON string.
2727
- *
2728
- * @remarks
2729
- * This helper wraps {@link JSON.stringify} and adds two key safety features:
2730
- *
2731
- * 1. It only serializes **objects** and **arrays**, ignoring all other data types
2732
- * (numbers, strings, booleans, `null`, `undefined`).
2733
- * 2. It catches all potential `JSON.stringify` errors (such as circular references)
2734
- * and returns an empty string `""` instead of throwing.
2735
- *
2736
- * The function is thus ideal for safe logging, diagnostics, or best-effort
2737
- * serialization where throwing is undesirable.
2738
- *
2739
- * - The output is always a valid JSON string (or empty string on failure).
2740
- * - Use {@link jsonDecode} to reverse the process and safely parse it back.
2741
- * - BigInt values are **not supported** by `JSON.stringify` — they will trigger
2742
- * a caught error, resulting in an empty string.
2743
- *
2744
- * @param value - Any value to encode. Only arrays or plain objects will be serialized;
2745
- * other types return an empty string.
2746
- *
2747
- * @returns The JSON-encoded string representation of the input,
2748
- * or an empty string (`""`) if:
2749
- * - The input is not an array or object.
2750
- * - Serialization fails (e.g., circular reference or BigInt values).
2751
- *
2752
- * @example
2753
- * ```ts
2754
- * // Example 1: Basic usage
2755
- * jsonEncode({ a: 1, b: true });
2756
- * // -> '{"a":1,"b":true}'
2757
- *
2758
- * // Example 2: Arrays
2759
- * jsonEncode([1, 2, 3]);
2760
- * // -> '[1,2,3]'
2761
- *
2762
- * // Example 3: Non-serializable input
2763
- * jsonEncode(123); // -> ''
2764
- * jsonEncode('hello'); // -> ''
2765
- * jsonEncode(undefined); // -> ''
2766
- *
2767
- * // Example 4: Circular reference
2768
- * const obj: any = {};
2769
- * obj.self = obj;
2770
- * jsonEncode(obj); // -> '' (fails safely)
2771
- * ```
2772
- *
2773
- * @throws Never throws — all exceptions from `JSON.stringify` are caught internally.
2774
- *
2775
- * @see {@link jsonDecode} — performs the inverse operation with safe parsing and normalization.
2776
- * @see {@link JSON.stringify} — the native method used under the hood.
2777
- *
2778
- * @public
2779
- * @category JSON
2780
- * @since 2.0.0
2781
- */
2782
- declare function jsonEncode(value: unknown): string;
2783
-
2784
- /**
2785
- * Converts an arbitrary numeric input to a JavaScript `number`, optionally rounding
2786
- * it to a fixed number of fractional digits using **half-up** rounding.
2787
- *
2788
- * @remarks
2789
- * This function is a convenience wrapper around your fixed-precision helpers:
2790
- *
2791
- * 1. {@link parseToFixedDecimal} — parses the unknown input (`number`/`string`/etc.)
2792
- * into an exact, lossless fixed-decimal representation.
2793
- * 2. `roundFixedDecimal` — (invoked only when `round > 1`) rounds that fixed-decimal
2794
- * value to the requested scale using the **half-up** algorithm.
2795
- * 3. {@link fixedDecimalToNum} — converts the (optionally rounded) fixed-decimal
2796
- * back to a JavaScript `number`.
2797
- *
2798
- * Because rounding is done in fixed-precision space, you avoid common IEEE-754
2799
- * floating-point artifacts (e.g., `0.1 + 0.2 !== 0.3`) during parsing/rounding.
2800
- * Precision is finally limited only at the last step when the value is converted
2801
- * to a JS `number`.
2802
- *
2803
- * @param value - Any value that represents a number. Typical cases:
2804
- * - `number` (e.g., `12`, `-0.034`, `1e6`)
2805
- * - numeric `string` (e.g., `"42"`, `"-123.456"`)
2806
- * - values that your {@link parseToFixedDecimal} knows how to normalize.
2807
- *
2808
- * If the value cannot be parsed by {@link parseToFixedDecimal}, an error will be thrown from there.
2809
- *
2810
- * @param round - Target number of fractional digits for rounding **in fixed-precision**.
2811
- * - If `round > 1`, the function rounds to exactly `round` digits after the decimal point
2812
- * using **half-up** (i.e., `.5` rounds away from zero) via `roundFixedDecimal`.
2813
- * - If `round <= 1`, no rounding is applied; the parsed value is passed through as-is.
2814
- *
2815
- * @defaultValue `1` (no rounding; passthrough)
2816
- *
2817
- * @returns The resulting numeric value as a JavaScript `number`.
2818
- *
2819
- * @throws {Error}
2820
- * - Re-throws any parsing/normalization errors from {@link parseToFixedDecimal}.
2821
- * - Re-throws any rounding errors from `roundFixedDecimal` (e.g., invalid scale).
2822
- *
2823
- * @example
2824
- * // No rounding (default `round = 1` → passthrough)
2825
- * numNormalize("123.456"); // => 123.456
2826
- * numNormalize(0.034); // => 0.034
2827
- *
2828
- * @example
2829
- * // Round to 2 fractional digits (half-up)
2830
- * numNormalize("123.456", 2); // => 123.46 (because .456 → .46)
2831
- * numNormalize("-1.235", 2); // => -1.24 (half-up away from zero)
2832
- *
2833
- * @example
2834
- * // Large values: parsed and rounded in fixed precision, then converted to number
2835
- * numNormalize("234893249238948.000003432", 6); // precise rounding in fixed space,
2836
- * // final result as JS number
2837
- *
2838
- * @example
2839
- * // Explicit passthrough (any `round <= 1` behaves the same)
2840
- * numNormalize("1000.555", 1); // => 1000.555 (no rounding step invoked)
2841
- * numNormalize("1000.555", 0); // => 1000.555 (still no rounding)
2842
- *
2843
- * @see parseToFixedDecimal
2844
- * @see fixedDecimalToNum
2845
- * @see roundFixedDecimal
2846
- *
2847
- * @category Number Formatting
2848
- * @since 2.0.0
2849
- * @public
2850
- */
2851
105
  declare function numNormalize(value: unknown, round?: number, throwError?: boolean): number;
2852
106
 
2853
- /**
2854
- * Converts any given string-like value into a lower-cased, trimmed string.
2855
- *
2856
- * @summary
2857
- * Safely transforms an unknown value into a normalized lowercase string.
2858
- * If the input is not a valid non-empty string, the function returns an empty string (`""`).
2859
- *
2860
- * @param value - Any unknown input to convert to lowercase.
2861
- *
2862
- * @returns A lowercase string, or an empty string if the input is not a valid string.
2863
- *
2864
- * @remarks
2865
- * ### Processing steps
2866
- * 1. **Type check** — ensures the input is a string using {@link isStr}.
2867
- * 2. **Trimming** — removes leading and trailing whitespace via {@link strTrim}.
2868
- * 3. **Validation** — ensures the result is non-empty with {@link isStrFilled}.
2869
- * 4. **Lowercasing** — calls `String.prototype.toLowerCase()` on the trimmed text.
2870
- * 5. If the string is empty or not valid at any step, returns `""`.
2871
- *
2872
- * ### Error safety
2873
- * - The function **never throws**, regardless of input type.
2874
- * - Non-string inputs (numbers, booleans, objects, arrays, `null`, `undefined`) all yield `""`.
2875
- *
2876
- * ### Use cases
2877
- * - Case-insensitive string comparison (normalize both sides with `strLowerCase`).
2878
- * - Normalizing user input before storing or indexing.
2879
- * - Simplifying logic where optional strings may be `null` or empty.
2880
- *
2881
- * ### Performance
2882
- * - Time complexity: **O(n)** (where `n` = string length, due to trimming and lowercasing).
2883
- * - Space complexity: **O(n)** (new string created by normalization).
2884
- *
2885
- * ### Examples
2886
- *
2887
- * @example
2888
- * // Basic strings
2889
- * strLowerCase('HELLO'); // => "hello"
2890
- * strLowerCase(' TEST '); // => "test"
2891
- *
2892
- * @example
2893
- * // Mixed types
2894
- * strLowerCase(123); // => ""
2895
- * strLowerCase(true); // => ""
2896
- * strLowerCase(null); // => ""
2897
- *
2898
- * @example
2899
- * // Empty or whitespace inputs
2900
- * strLowerCase(' '); // => ""
2901
- * strLowerCase(''); // => ""
2902
- *
2903
- * @example
2904
- * // Already lowercase
2905
- * strLowerCase('data'); // => "data"
2906
- *
2907
- * @see isStr
2908
- * @see isStrFilled
2909
- * @see strTrim
2910
- *
2911
- * @category String
2912
- * @public
2913
- * @since 2.0.0
2914
- */
2915
107
  declare function strLowerCase(value?: unknown): string;
2916
108
 
2917
109
  declare function strNormalCase(value?: unknown): string;
2918
110
 
2919
- /**
2920
- * Converts `undefined` or empty (whitespace-only) strings into `null`.
2921
- *
2922
- * @summary
2923
- * Safely normalizes optional values by replacing both `undefined` and blank strings
2924
- * with `null`, while preserving all other values as-is.
2925
- * This helps unify "missing" or "empty" values under a single, database-friendly
2926
- * `null` representation.
2927
- *
2928
- * @param value - Any input value that may be a string, `undefined`, or another type.
2929
- *
2930
- * @returns
2931
- * - `null` if:
2932
- * - The input is `undefined`, or
2933
- * - The input is a string that becomes empty after trimming (using {@link strTrim}).
2934
- * - Otherwise returns the original `value`.
2935
- *
2936
- * @remarks
2937
- * ### Processing steps
2938
- * 1. If `value` is `undefined`, returns `null`.
2939
- * 2. If `value` is a string:
2940
- * - Trims it with {@link strTrim}, removing whitespace and invisible characters.
2941
- * - If the trimmed result is empty (`''`), returns `null`.
2942
- * 3. Otherwise returns the original value unchanged.
2943
- *
2944
- * ### Behavior notes
2945
- * - Non-string, defined values (like `0`, `false`, `{}`, `[]`) are **not modified**.
2946
- * - The function is **pure** (non-mutating) and safe for use in JSON or ORM normalization.
2947
- * - Often used to prepare form data, REST payloads, or DB entities for consistent nullability.
2948
- *
2949
- * ### Comparison with {@link strUndefined}
2950
- * | Case | `strNull` | `strUndefined` |
2951
- * |------|----------------|----------------------|
2952
- * | `undefined` | `null` | `undefined` |
2953
- * | `''` (empty string) | `null` | `undefined` |
2954
- * | `'text'` | `'text'` | `'text'` |
2955
- * | non-string (e.g. `0`) | `0` | `0` |
2956
- *
2957
- * ### Use cases
2958
- * - Unifying “empty” form values before DB insertion (`''` or `undefined` → `null`)
2959
- * - Sanitizing request bodies before persistence or validation
2960
- * - Preventing inconsistent null/undefined states across backend and frontend layers
2961
- *
2962
- * ### Performance
2963
- * - Time complexity: **O(n)** (depends on string length)
2964
- * - Space complexity: **O(n)** (creates a trimmed string copy)
2965
- *
2966
- * ### Examples
2967
- *
2968
- * @example
2969
- * // Empty and whitespace strings
2970
- * strNull(''); // => null
2971
- * strNull(' '); // => null
2972
- *
2973
- * @example
2974
- * // Undefined also becomes null
2975
- * strNull(undefined); // => null
2976
- *
2977
- * @example
2978
- * // Non-empty strings remain as-is
2979
- * strNull('Hello'); // => "Hello"
2980
- * strNull(' Data '); // => " Data "
2981
- *
2982
- * @example
2983
- * // Non-string types are preserved
2984
- * strNull(0); // => 0
2985
- * strNull(false); // => false
2986
- * strNull([]); // => []
2987
- * strNull({}); // => {}
2988
- *
2989
- * @see isStr
2990
- * @see strTrim
2991
- * @see strUndefined
2992
- *
2993
- * @category String
2994
- * @public
2995
- * @since 2.0.0
2996
- */
2997
111
  declare function strNull(value: unknown): {} | null;
2998
112
 
2999
- /**
3000
- * Normalizes and validates a phone number into international format (`E.164` style).
3001
- *
3002
- * @summary
3003
- * Converts various human-entered phone number formats (with spaces, dashes, parentheses,
3004
- * or local prefixes) into a clean, standardized string beginning with `"+"`
3005
- * and containing 10–15 digits.
3006
- *
3007
- * Returns `null` if the value is not a valid phone number after normalization.
3008
- *
3009
- * @param value - The input value to format. Can be any unknown type; only strings are processed.
3010
- * @param defaultCountry - Optional international prefix to prepend for 10-digit local numbers
3011
- * (defaults to `"+7"` — Russia/Kazakhstan).
3012
- * Use your target country code (e.g., `"+34"` for Spain, `"+1"` for USA).
3013
- *
3014
- * @returns
3015
- * A normalized phone number in `+XXXXXXXXXX` format if valid, or `null` if the input
3016
- * cannot be interpreted as a valid number.
3017
- *
3018
- * @remarks
3019
- * ### Normalization rules
3020
- * 1. **Input validation:**
3021
- * If `value` is not a string, returns `null`.
3022
- *
3023
- * 2. **Trimming and cleaning:**
3024
- * Removes all whitespace, hyphens, parentheses, and dots.
3025
- * Example:
3026
- * `" (123) 456-7890 "` → `"1234567890"`.
3027
- *
3028
- * 3. **International formats:**
3029
- * - `00` prefix (common in Europe) is replaced with `"+"`.
3030
- * → `"0049123456789"` → `"+49123456789"`.
3031
- *
3032
- * 4. **Local numbers (10 digits):**
3033
- * Prepends the `defaultCountry` code.
3034
- * → `"1234567890"` → `"+71234567890"` (default country `+7`).
3035
- *
3036
- * 5. **Generic international numbers (9–15 digits):**
3037
- * If not starting with `"0"`, adds `"+"` prefix.
3038
- * → `"380501234567"` → `"+380501234567"`.
3039
- *
3040
- * 6. **Validation check:**
3041
- * The result must match the pattern `/^\+\d{10,15}$/`
3042
- * — i.e., plus sign followed by 10–15 digits.
3043
- * If not, returns `null`.
3044
- *
3045
- * ### Error safety
3046
- * - Never throws — all invalid or unexpected inputs return `null`.
3047
- * - Automatically cleans up common formatting symbols without side effects.
3048
- *
3049
- * ### Performance
3050
- * - Time complexity: **O(n)** (string length).
3051
- * - Space complexity: **O(n)** (new string creation during cleanup).
3052
- *
3053
- * ### Common pitfalls
3054
- * - Numbers starting with `"0"` are **rejected**, since they are ambiguous.
3055
- * - 8-digit local formats are not automatically expanded — use a country-specific parser if needed.
3056
- * - This function performs **basic formatting and validation**, not full ITU-T E.164 compliance.
3057
- *
3058
- * ### Examples
3059
- *
3060
- * @example
3061
- * // International format already valid
3062
- * strPhone('+380501234567'); // => "+380501234567"
3063
- *
3064
- * @example
3065
- * // European "00" prefix
3066
- * strPhone('00442079460729'); // => "+442079460729"
3067
- *
3068
- * @example
3069
- * // Local 10-digit number (default country +7)
3070
- * strPhone('9123456789'); // => "+79123456789"
3071
- *
3072
- * @example
3073
- * // With custom default country
3074
- * strPhone('9876543210', '+34'); // => "+349876543210"
3075
- *
3076
- * @example
3077
- * // Strings with spaces, punctuation, parentheses
3078
- * strPhone('(050) 123-45-67'); // => "+70501234567"
3079
- * strPhone('+1 (202) 555-0183'); // => "+12025550183"
3080
- *
3081
- * @example
3082
- * // Invalid or ambiguous inputs
3083
- * strPhone(''); // => null
3084
- * strPhone('000123456'); // => null
3085
- * strPhone('abcdefgh'); // => null
3086
- * strPhone(null); // => null
3087
- * strPhone(true); // => null
3088
- *
3089
- * @see isStr
3090
- * @see strTrim
3091
- *
3092
- * @category String
3093
- * @public
3094
- * @since 2.0.0
3095
- */
3096
113
  declare function strPhone(value?: unknown, defaultCountry?: string): string | null;
3097
114
 
3098
- /**
3099
- * Trims, normalizes, and cleans up invisible characters from a string.
3100
- *
3101
- * @summary
3102
- * Safely converts any input into a clean, Unicode-normalized string with all
3103
- * leading/trailing whitespace removed and zero-width characters stripped out.
3104
- *
3105
- * Returns an empty string (`""`) for all non-string inputs.
3106
- *
3107
- * @param value - Any value that may contain text or string-like content.
3108
- *
3109
- * @returns A normalized, trimmed string without invisible Unicode separators.
3110
- * Returns an empty string if `value` is not a string.
3111
- *
3112
- * @remarks
3113
- * ### Processing steps
3114
- * 1. **Type check:**
3115
- * Uses {@link isStr} to ensure the input is a string.
3116
- * Non-strings are converted to `""`.
3117
- *
3118
- * 2. **Trimming:**
3119
- * Removes all leading and trailing whitespace (`String.prototype.trim()`).
3120
- *
3121
- * 3. **Unicode normalization:**
3122
- * Applies `normalize('NFKC')` — Compatibility Composition — which:
3123
- * - Converts full-width and compatibility forms into canonical ones.
3124
- * Example: `"ABC"` → `"ABC"`.
3125
- * - Normalizes composed characters (e.g., `"é"` vs `"é"`).
3126
- *
3127
- * 4. **Invisible character cleanup:**
3128
- * Removes hidden zero-width Unicode characters commonly introduced by copy/paste:
3129
- * - `U+200B` ZERO WIDTH SPACE
3130
- * - `U+200C` ZERO WIDTH NON-JOINER
3131
- * - `U+200D` ZERO WIDTH JOINER
3132
- * - `U+FEFF` ZERO WIDTH NO-BREAK SPACE (BOM)
3133
- *
3134
- * 5. **Safe stringification:**
3135
- * Non-string values are returned as empty string rather than `"undefined"` or `"null"`.
3136
- *
3137
- * ### Benefits
3138
- * - Eliminates subtle text differences that break comparisons or hashing.
3139
- * - Prevents user input issues caused by hidden characters.
3140
- * - Safe to use in both frontend and backend environments.
3141
- *
3142
- * ### Performance
3143
- * - Time complexity: **O(n)** — proportional to the input string length.
3144
- * - Space complexity: **O(n)** — creates a new normalized copy.
3145
- *
3146
- * ### Common use cases
3147
- * - Sanitizing user input before validation or storage.
3148
- * - Cleaning keys, tags, and names from external data sources.
3149
- * - Preparing values for strict equality or hashing.
3150
- *
3151
- * ### Examples
3152
- *
3153
- * @example
3154
- * // Basic trimming
3155
- * strTrim(' Hello '); // => "Hello"
3156
- *
3157
- * @example
3158
- * // Removes zero-width characters
3159
- * strTrim('word\u200B'); // => "word"
3160
- *
3161
- * @example
3162
- * // Unicode normalization
3163
- * strTrim('ABC'); // => "ABC"
3164
- * strTrim('e\u0301'); // => "é"
3165
- *
3166
- * @example
3167
- * // Non-string inputs
3168
- * strTrim(123); // => ""
3169
- * strTrim(null); // => ""
3170
- * strTrim(undefined); // => ""
3171
- * strTrim({ text: 'hi' }); // => ""
3172
- *
3173
- * @see isStr
3174
- * @see String.prototype.normalize
3175
- *
3176
- * @category String
3177
- * @public
3178
- * @since 2.0.0
3179
- */
3180
115
  declare function strTrim(value: unknown, border?: string): string;
3181
116
 
3182
- /**
3183
- * Converts `null` or empty (whitespace-only) strings into `undefined`.
3184
- *
3185
- * @summary
3186
- * Normalizes optional values by replacing both `null` and blank strings
3187
- * with `undefined`, while keeping all other values unchanged.
3188
- * This is useful when preparing objects for APIs or serialization,
3189
- * where `undefined` fields are automatically omitted or ignored.
3190
- *
3191
- * @param value - Any value that may be a string, `null`, or another type.
3192
- *
3193
- * @returns
3194
- * - `undefined` if:
3195
- * - The value is `null`, or
3196
- * - The value is a string that becomes empty after trimming (via {@link strTrim}).
3197
- * - Otherwise returns the original value.
3198
- *
3199
- * @remarks
3200
- * ### Processing steps
3201
- * 1. If `value` is `null`, return `undefined`.
3202
- * 2. If `value` is a string:
3203
- * - Trim using {@link strTrim} to remove whitespace and invisible characters.
3204
- * - If trimmed result is empty, return `undefined`.
3205
- * 3. Otherwise, return the original value unchanged.
3206
- *
3207
- * ### Behavior notes
3208
- * - Non-string, non-null values (`0`, `false`, `{}`, `[]`, etc.) are **not modified**.
3209
- * - The function is **non-mutating** — it never changes the original reference.
3210
- * - It complements {@link strNull}, depending on whether your system
3211
- * prefers `undefined` (omit field) or `null` (explicit empty value).
3212
- *
3213
- * ### Comparison with {@link strNull}
3214
- * | Case | `strNull` | `strUndefined` |
3215
- * |------|----------------|----------------------|
3216
- * | `null` | `null` | `undefined` |
3217
- * | `undefined` | `null` | `undefined` |
3218
- * | `''` (empty string) | `null` | `undefined` |
3219
- * | `'text'` | `'text'` | `'text'` |
3220
- * | Non-string (e.g. `0`) | `0` | `0` |
3221
- *
3222
- * ### Use cases
3223
- * - Preparing data before sending to REST or GraphQL APIs
3224
- * (so empty fields are omitted during JSON serialization)
3225
- * - Cleaning form input values before saving or validation
3226
- * - Ensuring `undefined` consistency in optional object properties
3227
- *
3228
- * ### Performance
3229
- * - Time complexity: **O(n)** (depends on string length)
3230
- * - Space complexity: **O(n)** (due to string trimming)
3231
- *
3232
- * ### Examples
3233
- *
3234
- * @example
3235
- * // Empty and whitespace-only strings
3236
- * strUndefined(''); // => undefined
3237
- * strUndefined(' '); // => undefined
3238
- *
3239
- * @example
3240
- * // null is also normalized
3241
- * strUndefined(null); // => undefined
3242
- *
3243
- * @example
3244
- * // Non-empty strings remain unchanged
3245
- * strUndefined('Hello'); // => "Hello"
3246
- *
3247
- * @example
3248
- * // Non-string types are preserved
3249
- * strUndefined(0); // => 0
3250
- * strUndefined(false); // => false
3251
- * strUndefined([]); // => []
3252
- * strUndefined({}); // => {}
3253
- *
3254
- * @see isStr
3255
- * @see strTrim
3256
- * @see strNull
3257
- *
3258
- * @category String
3259
- * @public
3260
- * @since 2.0.0
3261
- */
3262
117
  declare function strUndefined(value: unknown): {} | undefined;
3263
118
 
3264
119
  declare const strNormalize: (v: unknown) => unknown;
@@ -3275,4 +130,4 @@ declare function urlObj(value?: string): UrlObj;
3275
130
 
3276
131
  declare function urlDecode(input: string): string;
3277
132
 
3278
- export { type JSONLike, type JsonLike, type PasswordOptions, type TimeParts, type UniqueDeepOptions, arrFuncArgs, arrReplaceTemplate, arrSplitBatches, arrUniqueDeep, boolNormalize, dateFloorMin, datePartsSec, dateSecParts, dateStr, env, ipNumStr, ipStrNum, isArr, isArrFilled, isBool, isBoolOrBoolTree, isClass, isDate, isEmail, isExists, isFunc, isIpAddr, isMacAddr, isNum, isNumFloat, isNumN, isNumNZ, isNumP, isNumPZ, isObj, isObjFilled, isObjFlat, isPassword, isPhone, isStr, isStrAscDesc, isStrBool, isStrFilled, isVar, jsonDecode, jsonEncode, jsonParse, jsonStrLike, numNormalize, strLowerCase, strNormalCase, strNormalize, strNull, strPhone, strTrim, strUndefined, urlDecode, urlObj, wait };
133
+ export { type JsonLike, type PasswordOptions, type TimeParts, type UniqueDeepOptions, arrFuncArgs, arrReplaceTemplate, arrSplitBatches, arrUniqueDeep, boolNormalize, dateFloorMin, datePartsSec, dateSecParts, dateStr, env, ipNumStr, ipStrNum, isArr, isArrFilled, isBool, isBoolOrBoolTree, isClass, isDate, isEmail, isExists, isFunc, isIpAddr, isMacAddr, isNum, isNumFloat, isNumN, isNumNZ, isNumP, isNumPZ, isObj, isObjFilled, isObjFlat, isPassword, isPhone, isStr, isStrAscDesc, isStrBool, isStrFilled, isVar, numNormalize, strLowerCase, strNormalCase, strNormalize, strNull, strPhone, strTrim, strUndefined, urlDecode, urlObj, wait };