@rzl-zone/utils-js 3.0.2-beta.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -27
- package/dist/NumberRangeUnion-DC-C3_Kq.d.ts +23 -23
- package/dist/any-BmdI8UbK.d.ts +56 -56
- package/dist/arrays-normalize-recursive-CnjYJ9xg.d.ts +66 -66
- package/dist/assertions/index.cjs +1 -1
- package/dist/assertions/index.d.ts +398 -418
- package/dist/assertions/index.js +1 -1
- package/dist/chunk-26XIKDJI.cjs +1 -0
- package/dist/chunk-2NWHDDM5.js +1 -0
- package/dist/chunk-2UIRWYE3.js +1 -0
- package/dist/chunk-3KBHD3BS.cjs +1 -0
- package/dist/chunk-4HD2O5A4.js +1 -0
- package/dist/chunk-5C2SMIGX.cjs +1 -0
- package/dist/chunk-5I2B5DOG.js +1 -0
- package/dist/chunk-6HQDHIOD.js +1 -0
- package/dist/chunk-735HJXBT.cjs +1 -0
- package/dist/chunk-7BXIZM57.cjs +1 -0
- package/dist/chunk-7KJBDGEP.js +1 -0
- package/dist/chunk-7U44T63D.cjs +1 -0
- package/dist/chunk-AJ65QFV2.js +1 -0
- package/dist/chunk-APHDUCVQ.js +1 -0
- package/dist/chunk-BSVZRN7C.js +1 -0
- package/dist/chunk-C6JFHUR2.cjs +1 -0
- package/dist/chunk-CPLBRGST.js +1 -0
- package/dist/chunk-CTBRLEOG.js +1 -0
- package/dist/chunk-DUK2K4FB.js +1 -0
- package/dist/chunk-DVMHRLKP.cjs +1 -0
- package/dist/chunk-E63WVPZE.cjs +1 -0
- package/dist/chunk-EBMHQW7X.cjs +1 -0
- package/dist/chunk-EGNZCW4K.js +1 -0
- package/dist/chunk-FEKDB32T.js +1 -0
- package/dist/chunk-FIAAX3UE.js +1 -0
- package/dist/chunk-FUS3DVLB.cjs +1 -0
- package/dist/chunk-GGRMHIFJ.cjs +1 -0
- package/dist/chunk-HQ5GQTEE.js +1 -0
- package/dist/chunk-I5X5IN4H.js +1 -0
- package/dist/chunk-I7YGXQPI.cjs +1 -0
- package/dist/chunk-INUFZJLX.cjs +1 -0
- package/dist/chunk-IREHUBF7.js +1 -0
- package/dist/chunk-J2RGTPGK.cjs +1 -0
- package/dist/chunk-KHO2SBNA.cjs +1 -0
- package/dist/chunk-KXIXXSWX.cjs +1 -0
- package/dist/chunk-LBMEEJWA.js +1 -0
- package/dist/chunk-MC3LXMCQ.js +1 -0
- package/dist/chunk-MMSYCIJ2.cjs +1 -1
- package/dist/chunk-NU3N4WHD.cjs +1 -0
- package/dist/chunk-ODZQXH7E.cjs +1 -0
- package/dist/chunk-ONZFBJVW.js +1 -0
- package/dist/chunk-PXDRHFIE.js +1 -0
- package/dist/chunk-Q6NHYWVX.js +1 -0
- package/dist/chunk-QNKGP5DY.js +1 -0
- package/dist/chunk-S6Z6I2EG.cjs +1 -0
- package/dist/chunk-SMADKXZE.js +1 -0
- package/dist/chunk-TSLYDPBJ.js +1 -0
- package/dist/chunk-TVXADXCC.cjs +1 -0
- package/dist/chunk-UDA26MCU.cjs +1 -0
- package/dist/chunk-UET567YM.cjs +1 -0
- package/dist/chunk-VEYMQ3UA.js +1 -0
- package/dist/chunk-W2W3L2M5.js +1 -0
- package/dist/chunk-WBWTXKMC.cjs +1 -0
- package/dist/chunk-WVSPXFTY.js +1 -0
- package/dist/chunk-XC2PYCT4.cjs +1 -0
- package/dist/chunk-XIXA5KDF.cjs +1 -0
- package/dist/chunk-Y4O5KZF6.cjs +1 -0
- package/dist/chunk-YRM7IJLX.js +1 -0
- package/dist/chunk-YT3MSZKK.cjs +1 -0
- package/dist/chunk-YXHCULSO.cjs +1 -0
- package/dist/chunk-YZR5OGJA.cjs +1 -0
- package/dist/chunk-Z4DXK7A6.cjs +1 -0
- package/dist/chunk-ZXIWDFEQ.js +1 -0
- package/dist/conversions/index.cjs +1 -1
- package/dist/conversions/index.d.ts +1368 -1515
- package/dist/conversions/index.js +1 -1
- package/dist/env/index.cjs +1 -1
- package/dist/env/index.d.ts +14 -17
- package/dist/env/index.js +1 -1
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.d.ts +111 -108
- package/dist/events/index.js +1 -1
- package/dist/extends-Bk_SBGdT.d.ts +367 -0
- package/dist/formatting/index.cjs +1 -1
- package/dist/formatting/index.d.ts +878 -840
- package/dist/formatting/index.js +1 -1
- package/dist/generator/index.cjs +1 -1
- package/dist/generator/index.d.ts +173 -150
- package/dist/generator/index.js +1 -1
- package/dist/if-CvT4R7Kh.d.ts +16 -16
- package/dist/is-array-Cymwrsmm.d.ts +1119 -0
- package/dist/isPlainObject-BVhBAPHX.d.ts +169 -0
- package/dist/never-BfayMBF9.d.ts +64 -64
- package/dist/next/index.cjs +1 -8
- package/dist/next/index.d.ts +196 -176
- package/dist/next/index.js +1 -8
- package/dist/next/server/index.cjs +1 -2
- package/dist/next/server/index.d.ts +26 -40
- package/dist/next/server/index.js +1 -2
- package/dist/nils-DMz3kU7M.d.ts +155 -155
- package/dist/omit-VvmIsZmX.d.ts +25 -25
- package/dist/operations/index.cjs +1 -1
- package/dist/operations/index.d.ts +121 -176
- package/dist/operations/index.js +1 -1
- package/dist/or-DyZCRvaU.d.ts +89 -0
- package/dist/parsers/index.cjs +1 -1
- package/dist/parsers/index.d.ts +35 -36
- package/dist/parsers/index.js +1 -1
- package/dist/predicates/index.cjs +1 -1
- package/dist/predicates/index.d.ts +1797 -1677
- package/dist/predicates/index.js +1 -1
- package/dist/prettify-C4xLcYOP.d.ts +328 -328
- package/dist/promise/index.cjs +1 -1
- package/dist/promise/index.d.ts +29 -38
- package/dist/promise/index.js +1 -1
- package/dist/rzl-utils.global.js +1 -4
- package/dist/string-XA-til3C.d.ts +351 -0
- package/dist/strings/index.cjs +1 -1
- package/dist/strings/index.d.ts +712 -787
- package/dist/strings/index.js +1 -1
- package/dist/tailwind/index.cjs +1 -0
- package/dist/tailwind/index.d.ts +565 -0
- package/dist/tailwind/index.js +1 -0
- package/dist/type-data-DDs-u2kq.d.ts +241 -241
- package/dist/types/index.d.ts +3266 -3266
- package/dist/urls/index.cjs +1 -1
- package/dist/urls/index.d.ts +384 -409
- package/dist/urls/index.js +1 -1
- package/package.json +61 -18
- package/dist/array-CIZRbqTF.d.ts +0 -223
- package/dist/chunk-2TRAPBZ7.cjs +0 -1
- package/dist/chunk-3D74QO5D.cjs +0 -1
- package/dist/chunk-4DK3RCC4.js +0 -2
- package/dist/chunk-4JOQ45HL.js +0 -1
- package/dist/chunk-55CZALRS.js +0 -1
- package/dist/chunk-56QBKKRE.js +0 -1
- package/dist/chunk-5JFV3GDE.cjs +0 -4
- package/dist/chunk-5SZUSNGZ.js +0 -1
- package/dist/chunk-62HX5Z45.cjs +0 -1
- package/dist/chunk-7NA6DUHR.cjs +0 -2
- package/dist/chunk-7YWAQOA4.cjs +0 -1
- package/dist/chunk-BVPMMWDL.cjs +0 -1
- package/dist/chunk-BYZAD3XN.cjs +0 -1
- package/dist/chunk-CEFYHEM4.cjs +0 -1
- package/dist/chunk-CN53M4QZ.cjs +0 -1
- package/dist/chunk-D47MHBSD.cjs +0 -1
- package/dist/chunk-DGH75GJD.js +0 -1
- package/dist/chunk-E5NUI7PN.js +0 -1
- package/dist/chunk-ELDDNERR.js +0 -1
- package/dist/chunk-EXZ47NOW.js +0 -1
- package/dist/chunk-FDITZ5C6.cjs +0 -1
- package/dist/chunk-FF76ISQ2.js +0 -1
- package/dist/chunk-FIEZKTAZ.cjs +0 -1
- package/dist/chunk-FSSV24W7.cjs +0 -1
- package/dist/chunk-GCGU2WB7.js +0 -1
- package/dist/chunk-GECI2YBP.js +0 -1
- package/dist/chunk-GQE4OVHC.cjs +0 -1
- package/dist/chunk-GRVZXQXL.cjs +0 -1
- package/dist/chunk-I4AVNHPA.cjs +0 -1
- package/dist/chunk-JFRL7NKU.js +0 -4
- package/dist/chunk-JWHM3WZQ.cjs +0 -1
- package/dist/chunk-KCQDDZJE.cjs +0 -1
- package/dist/chunk-L54ZPSYJ.js +0 -1
- package/dist/chunk-LVKAYEZ4.js +0 -1
- package/dist/chunk-MBDWTK54.cjs +0 -1
- package/dist/chunk-MNGGDB2G.js +0 -1
- package/dist/chunk-MY7BA4GI.cjs +0 -1
- package/dist/chunk-N2IJPIND.cjs +0 -1
- package/dist/chunk-NIMNTEGV.js +0 -1
- package/dist/chunk-NNM7QCNB.js +0 -1
- package/dist/chunk-PUQXRLZH.cjs +0 -1
- package/dist/chunk-PVJF2JHM.js +0 -1
- package/dist/chunk-QCFXEUKL.js +0 -1
- package/dist/chunk-QFCGBBSY.js +0 -1
- package/dist/chunk-QQYAUPSK.cjs +0 -1
- package/dist/chunk-RN3TP3S3.js +0 -1
- package/dist/chunk-RV2VULM7.cjs +0 -1
- package/dist/chunk-SW6HYEW7.cjs +0 -1
- package/dist/chunk-SYJC7UAW.js +0 -1
- package/dist/chunk-TC4VBE4Y.cjs +0 -1
- package/dist/chunk-TUXDINHF.cjs +0 -1
- package/dist/chunk-U5Y2FXMN.cjs +0 -1
- package/dist/chunk-UUPQI6ND.cjs +0 -1
- package/dist/chunk-VYCGZ2S6.js +0 -1
- package/dist/chunk-W5EDKJK3.js +0 -1
- package/dist/chunk-WHAVUFEU.js +0 -1
- package/dist/chunk-XCFIOTCV.js +0 -1
- package/dist/chunk-XE27XPJR.js +0 -1
- package/dist/chunk-XH6MCRLP.js +0 -1
- package/dist/chunk-XVB3ZZEB.js +0 -1
- package/dist/chunk-ZBSIGJFO.cjs +0 -1
- package/dist/chunk-ZYAML74V.js +0 -1
- package/dist/extends-Mp81Hq9-.d.ts +0 -145
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/is-array-Ckm_47hw.d.ts +0 -1557
- package/dist/isPlainObject-BKYaI6a8.d.ts +0 -182
- package/dist/stylings/index.cjs +0 -1
- package/dist/stylings/index.d.ts +0 -49
- package/dist/stylings/index.js +0 -1
|
@@ -1,1633 +1,1486 @@
|
|
|
1
|
-
import{A as AnyFunction,T as TypedArray,W as WebApiObjects,I as IntlObjects}from'../type-data-DDs-u2kq.js';import{N as NormalizeEmptyArraysRecursive,R as RemoveEmptyArrayElements,F as FixNeverArrayRecursive}from'../arrays-normalize-recursive-CnjYJ9xg.js';import{h as Nullish,a as KeepNull,b as KeepUndef}from'../nils-DMz3kU7M.js';import{I as IsAny}from'../any-BmdI8UbK.js';import{
|
|
1
|
+
import{A as AnyFunction,T as TypedArray,W as WebApiObjects,I as IntlObjects}from'../type-data-DDs-u2kq.js';import{N as NormalizeEmptyArraysRecursive,R as RemoveEmptyArrayElements,F as FixNeverArrayRecursive}from'../arrays-normalize-recursive-CnjYJ9xg.js';import{h as Nullish,a as KeepNull,b as KeepUndef}from'../nils-DMz3kU7M.js';import{I as IsAny}from'../any-BmdI8UbK.js';import{i as IfNotExtends,I as IfExtends,E as Extends}from'../extends-Bk_SBGdT.js';import{P as Prettify}from'../prettify-C4xLcYOP.js';import{N as NumberRangeUnion}from'../NumberRangeUnion-DC-C3_Kq.js';import{O as OrArr,a as AndArr}from'../or-DyZCRvaU.js';import'../if-CvT4R7Kh.js';import'../never-BfayMBF9.js';type ExcludeNil<T>=Exclude<T,null|undefined>;
|
|
2
2
|
/** ----------------------------------------------------------
|
|
3
|
-
* * ***Element extractor***
|
|
4
|
-
* ----------------------------------------------------------
|
|
5
|
-
*/
|
|
3
|
+
* * ***Element extractor***
|
|
4
|
+
* ----------------------------------------------------------
|
|
5
|
+
*/
|
|
6
6
|
type ElementOf<A extends readonly unknown[]>=A extends readonly(infer U)[]?U:never;
|
|
7
7
|
/** ----------------------------------------------------------
|
|
8
|
-
* * ***Compute `FilterNilArray`***
|
|
9
|
-
* ----------------------------------------------------------
|
|
10
|
-
*
|
|
11
|
-
* for a tuple/array A by using the element type (without null|undefined).
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
8
|
+
* * ***Compute `FilterNilArray`***
|
|
9
|
+
* ----------------------------------------------------------
|
|
10
|
+
*
|
|
11
|
+
* for a tuple/array A by using the element type (without null|undefined).
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
14
|
type FilterNilArrayFromTuple<A extends readonly unknown[]>=FilterNilArray<ExcludeNil<ElementOf<A>>>;
|
|
15
15
|
/** ----------------------------------------------------------
|
|
16
|
-
* ***Preserve `mutability`: if A is mutable (extends unknown[]), keep B; otherwise make B readonly***. */
|
|
16
|
+
* ***Preserve `mutability`: if A is mutable (extends unknown[]), keep B; otherwise make B readonly***. */
|
|
17
17
|
type PreserveMutability<A extends readonly unknown[],B>=A extends unknown[]?B:Readonly<B>;type IsDeepEmptyArray<T>=T extends readonly []?true:T extends readonly(infer U)[]?IsDeepEmptyArray<U>:false;type FilterNilRecursive<T>=T extends readonly(infer U)[]?T extends(infer U)[]?FilterNilRecursive<ExcludeEmptyArray<U>>[]:readonly FilterNilRecursive<ExcludeEmptyArray<U>>[]:Exclude<T,null|undefined>;type ExcludeEmptyArray<T>=T extends []?never:T;type NormalizerArrays<T>=NormalizeEmptyArraysRecursive<RemoveEmptyArrayElements<FilterNilRecursive<T[]>>>;type FilterNilArray<T>=IsDeepEmptyArray<NormalizerArrays<T>>extends true?[]:FixNeverArrayRecursive<NormalizerArrays<T>>;type ResUnFTN<Force extends false|"stringOrNumber"|"primitives"|"all"=false>=Force extends"all"?Array<unknown[]|Record<string,unknown>|string>:Force extends"stringOrNumber"?Array<string|boolean|bigint|symbol|null|undefined|Record<string,unknown>|AnyFunction|unknown[]|Date|RegExp|Map<unknown,unknown>|Set<unknown>|Promise<unknown>>:Force extends"primitives"?Array<string|symbol|Record<string,unknown>|AnyFunction|unknown[]|Date|RegExp|Map<unknown,unknown>|Set<unknown>|Promise<unknown>>:Force extends false?Array<string|number|bigint|boolean|symbol|RegExp|Record<string,unknown>|AnyFunction|Date|Map<unknown,unknown>|Set<unknown>|Promise<unknown>|unknown[]|null|undefined>:unknown[];type ResFTN<Force extends false|"stringOrNumber"|"primitives"|"all"=false>=Force extends"all"?Array<string|Record<string,unknown>>:Force extends"stringOrNumber"?Array<string|boolean|bigint|symbol|null|undefined|Record<string,unknown>|AnyFunction|Date|RegExp|Promise<unknown>>:Force extends"primitives"?Array<string|symbol|RegExp|Record<string,unknown>|AnyFunction|Date|Promise<unknown>>:Force extends false?Array<string|number|bigint|boolean|symbol|RegExp|Record<string,unknown>|AnyFunction|Date|Promise<unknown>|null|undefined>:unknown[];type DedupeResult<Force extends ForceToStringOptions=false,FTN extends boolean=false>=FTN extends false?ResUnFTN<Force>:ResFTN<Force>;type ForceToStringOptions=false|"stringOrNumber"|"primitives"|"all";type DedupeArrayOptions<F extends ForceToStringOptions,Fl extends boolean>={
|
|
18
18
|
/** Enables string conversion for comparison, default is `false`.
|
|
19
|
-
*
|
|
20
|
-
* @default false
|
|
21
|
-
* @type {ForceToStringOptions}
|
|
22
|
-
*/
|
|
19
|
+
*
|
|
20
|
+
* @default false
|
|
21
|
+
* @type {ForceToStringOptions}
|
|
22
|
+
*/
|
|
23
23
|
forceToString?:F;
|
|
24
24
|
/** If true, deeply flattens arrays, Maps, and Sets before deduplication, default is `false`.
|
|
25
|
-
*
|
|
26
|
-
* @default false
|
|
27
|
-
*/
|
|
25
|
+
*
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
28
|
flatten?:Fl;};
|
|
29
29
|
/** ----------------------------------------------------------
|
|
30
|
-
* * ***
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* -
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @template
|
|
39
|
-
* @param {T[]}
|
|
40
|
-
* @returns {T[] | undefined} A new array with `null` and `undefined` values removed,
|
|
41
|
-
* or `undefined` if the input is explicitly `undefined` or `null`.
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* filterNilArray(
|
|
49
|
-
* // ➔
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* //
|
|
53
|
-
*
|
|
54
|
-
* filterNilArray(null);
|
|
55
|
-
* // ➔
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*
|
|
62
|
-
* filterNilArray([1, [null, 2, [undefined, 3]]]);
|
|
63
|
-
* // ➔ [1, [2, [3]]]
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
declare function filterNilArray(input?:null):undefined;declare function filterNilArray<A extends readonly unknown[]>(input:A):PreserveMutability<A,FilterNilArrayFromTuple<A>>;declare function filterNilArray<A extends readonly unknown[]>(input:A|null|undefined):PreserveMutability<A,FilterNilArrayFromTuple<A>>|undefined;declare function filterNilArray<T>(input?:(T|null|undefined)[]|null|undefined):FilterNilArray<T>|undefined;declare function filterNilArray(input:readonly unknown[]|null|undefined):unknown[]|undefined;declare function filterNilArray(input:unknown[]):unknown[];
|
|
30
|
+
* * ***Utility: `filterNilArray`.***
|
|
31
|
+
* ---------------------------------------------
|
|
32
|
+
* **Removes `null` and `undefined` values from an array, including nested arrays.**
|
|
33
|
+
* - **Behavior:**
|
|
34
|
+
* - Returns `undefined` if the input is explicitly `undefined` or `null`.
|
|
35
|
+
* - Returns `[]` if input is empty or all elements are removed after filtering.
|
|
36
|
+
* - Recursively filters nested arrays while preserving structure.
|
|
37
|
+
* - Ensures proper type inference for safer downstream operations.
|
|
38
|
+
* @template A - The type of elements in the array.
|
|
39
|
+
* @param {T[]|null|undefined} input - The array to be filtered.
|
|
40
|
+
* @returns {T[] | undefined} A new array with `null` and `undefined` values removed,
|
|
41
|
+
* or `undefined` if the input is explicitly `undefined` or `null`.
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* filterNilArray([1, null, 2, undefined, 3]);
|
|
45
|
+
* // ➔ [1, 2, 3]
|
|
46
|
+
* filterNilArray([null, undefined]);
|
|
47
|
+
* // ➔ []
|
|
48
|
+
* filterNilArray(undefined);
|
|
49
|
+
* // ➔ undefined
|
|
50
|
+
* filterNilArray(null);
|
|
51
|
+
* // ➔ undefined
|
|
52
|
+
* filterNilArray([]); // or
|
|
53
|
+
* filterNilArray([[[]]]); // or
|
|
54
|
+
* filterNilArray([[[],undefined,null]]);
|
|
55
|
+
* // ➔ []
|
|
56
|
+
* filterNilArray([1, [null, 2, [undefined, 3]]]);
|
|
57
|
+
* // ➔ [1, [2, [3]]]
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare function filterNilArray(input:null|undefined):undefined;declare function filterNilArray<A extends readonly unknown[]>(input:A):PreserveMutability<A,FilterNilArrayFromTuple<A>>;declare function filterNilArray<A extends readonly unknown[]>(input:A|null|undefined):PreserveMutability<A,FilterNilArrayFromTuple<A>>|undefined;declare function filterNilArray<A>(input:(A|null|undefined)[]|null|undefined):FilterNilArray<A>|undefined;declare function filterNilArray(input:readonly unknown[]|null|undefined):unknown[]|undefined;declare function filterNilArray(input:unknown[]):unknown[];
|
|
67
61
|
/** ----------------------------------------------------------
|
|
68
|
-
* * ***
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* // ➔ ["
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* dedupeArray([
|
|
109
|
-
* // ➔ [
|
|
110
|
-
*
|
|
111
|
-
* dedupeArray([
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* // ➔ ["
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* // ➔ ["
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* // ➔ ["
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* // ➔ [
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* // ➔ [
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* // ➔ [[
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* dedupeArray([
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
|
|
147
|
-
* });
|
|
148
|
-
* // ➔ ["NaN", "1"]
|
|
149
|
-
*
|
|
150
|
-
* dedupeArray([new Date("2025-01-01"), new Date("2025-01-01")]);
|
|
151
|
-
* // ➔ [Date("2025-01-01")] (same time, deduped)
|
|
152
|
-
*
|
|
153
|
-
* dedupeArray([new Date("2025-01-01"), new Date("2025-01-01")], {
|
|
154
|
-
* forceToString: "all"
|
|
155
|
-
* });
|
|
156
|
-
* // ➔ ["2025-01-01T00:00:00.000Z"]
|
|
157
|
-
*
|
|
158
|
-
* dedupeArray([/abc/, /abc/], {
|
|
159
|
-
* forceToString: "all"
|
|
160
|
-
* });
|
|
161
|
-
* // ➔ ["/abc/"]
|
|
162
|
-
*
|
|
163
|
-
* dedupeArray([new Map(), new Set(), new Error("err")], {
|
|
164
|
-
* forceToString: "all"
|
|
165
|
-
* });
|
|
166
|
-
* // ➔ ["[object Map]", "[object Set]", "Error: err"]
|
|
167
|
-
*
|
|
168
|
-
* dedupeArray([Promise.resolve(1), Promise.resolve(1)], {
|
|
169
|
-
* forceToString: "all"
|
|
170
|
-
* });
|
|
171
|
-
* // ➔ ["[object Promise]"]
|
|
172
|
-
*
|
|
173
|
-
* dedupeArray([{ a: 1 }, { a: 1 }, { a: 2 }], {
|
|
174
|
-
* forceToString: "primitives"
|
|
175
|
-
* });
|
|
176
|
-
* // ➔ [{ a: "1" }, { a: "2" }]
|
|
177
|
-
*
|
|
178
|
-
* dedupeArray([{ a: { b: 1 } }, { a: { b: 1 } }], {
|
|
179
|
-
* forceToString: "all"
|
|
180
|
-
* });
|
|
181
|
-
* // ➔ [{ a: { b: "1" } }]
|
|
182
|
-
*
|
|
183
|
-
* dedupeArray("not an array");
|
|
184
|
-
* // Throws TypeError
|
|
185
|
-
*
|
|
186
|
-
* dedupeArray([1, 2, 3], {
|
|
187
|
-
* forceToString: "invalid"
|
|
188
|
-
* });
|
|
189
|
-
* // Throws TypeError
|
|
190
|
-
* ```
|
|
191
|
-
*/
|
|
62
|
+
* * ***Utility: `dedupeArray`.***
|
|
63
|
+
* ---------------------------------------------
|
|
64
|
+
* @description
|
|
65
|
+
* Deduplicates values in an array (with optional flattening and deep stringification).
|
|
66
|
+
* - Supports various modes for converting values to strings before deduplication:
|
|
67
|
+
* - `"stringOrNumber"`: Converts strings and numbers to strings.
|
|
68
|
+
* - `"primitives"`: Converts all primitives (string, number, boolean, bigint, null, undefined, NaN) to strings.
|
|
69
|
+
* - `"all"`: Converts all values (primitives, objects, Maps, Sets, Symbols, RegExp, Dates, Errors, Promises, functions)
|
|
70
|
+
* to strings, including nested object properties.
|
|
71
|
+
* - `false` (default): No conversion applied.
|
|
72
|
+
* - Options:
|
|
73
|
+
* - `forceToString`: Enables string conversion for comparison, default is `false`.
|
|
74
|
+
* - `flatten`: If true, deeply flattens arrays, Maps, and Sets before deduplication, default is `false`.
|
|
75
|
+
* @template ForceToString - `forceToString` mode.
|
|
76
|
+
* @template Flattening - `flatten` mode.
|
|
77
|
+
* @param {unknown[]} inputArray - The array to deduplicate. Can be deeply nested and contain any mix of types.
|
|
78
|
+
* @param {DedupeArrayOptions<ForceToString, Flattening>|undefined} [options] - Options to control string conversion.
|
|
79
|
+
* @returns {DedupeResult<ForceToString, Flattening>} Deduplicated array with optional transformations.
|
|
80
|
+
* @throws {TypeError} If the input is not an array, or options is not an object, or if `forceToString` is invalid.
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* dedupeArray(["apple", "banana", "apple"]);
|
|
84
|
+
* // ➔ ["apple", "banana"]
|
|
85
|
+
* dedupeArray([[1, 2], [1, 2]], { flatten: true });
|
|
86
|
+
* // ➔ [1, 2]
|
|
87
|
+
* dedupeArray([new Set([1, 2]), new Set([2, 3])], { flatten: true });
|
|
88
|
+
* // ➔ [1, 2, 3]
|
|
89
|
+
* dedupeArray([1, "1", 2, "2"], {
|
|
90
|
+
* forceToString: "stringOrNumber"
|
|
91
|
+
* }); // ➔ ["1", "2"]
|
|
92
|
+
* dedupeArray([true, "true", false, undefined], {
|
|
93
|
+
* forceToString: "primitives"
|
|
94
|
+
* }); // ➔ ["true", "false", "undefined"]
|
|
95
|
+
* dedupeArray([1, "1", { a: 1 }], {
|
|
96
|
+
* forceToString: "all"
|
|
97
|
+
* }); // ➔ ["1", { a: "1" }]
|
|
98
|
+
* dedupeArray([1, 1, [2, 2, [3, 3]]]);
|
|
99
|
+
* // ➔ [1, [2, [3]]]
|
|
100
|
+
* dedupeArray([null, undefined, null]);
|
|
101
|
+
* // ➔ [null, undefined]
|
|
102
|
+
* dedupeArray([[], [[]], [[[]]], [[]], [[[]]]]);
|
|
103
|
+
* // ➔ [[], [[]], [[[]]]]
|
|
104
|
+
* const fn = () => 1;
|
|
105
|
+
* dedupeArray([fn, fn, () => 1]);
|
|
106
|
+
* // ➔ [fn, () => 1] cause: ref () => 1 and fn is different but ref const `fn` and `fn` is same ref.
|
|
107
|
+
* dedupeArray([Symbol("x"), Symbol("x")]);
|
|
108
|
+
* // ➔ [Symbol("x")] (symbols are same by identity, so dedupe
|
|
109
|
+
* dedupeArray([NaN, NaN, 1, "1"]);
|
|
110
|
+
* // ➔ [NaN, 1, "1"]
|
|
111
|
+
* dedupeArray([NaN, NaN, 1, "1"], {
|
|
112
|
+
* forceToString: "primitives"
|
|
113
|
+
* }); // ➔ ["NaN", "1"]
|
|
114
|
+
* dedupeArray([new Date("2025-01-01"), new Date("2025-01-01")]);
|
|
115
|
+
* // ➔ [Date("2025-01-01")] (same time, deduped)
|
|
116
|
+
* dedupeArray([new Date("2025-01-01"), new Date("2025-01-01")], {
|
|
117
|
+
* forceToString: "all"
|
|
118
|
+
* }); // ➔ ["2025-01-01T00:00:00.000Z"]
|
|
119
|
+
* dedupeArray([/abc/, /abc/], {
|
|
120
|
+
* forceToString: "all"
|
|
121
|
+
* }); // ➔ ["/abc/"]
|
|
122
|
+
* dedupeArray([new Map(), new Set(), new Error("err")], {
|
|
123
|
+
* forceToString: "all"
|
|
124
|
+
* }); // ➔ ["[object Map]", "[object Set]", "Error: err"]
|
|
125
|
+
* dedupeArray([Promise.resolve(1), Promise.resolve(1)], {
|
|
126
|
+
* forceToString: "all"
|
|
127
|
+
* }); // ➔ ["[object Promise]"]
|
|
128
|
+
* dedupeArray([{ a: 1 }, { a: 1 }, { a: 2 }], {
|
|
129
|
+
* forceToString: "primitives"
|
|
130
|
+
* }); // ➔ [{ a: "1" }, { a: "2" }]
|
|
131
|
+
* dedupeArray([{ a: { b: 1 } }, { a: { b: 1 } }], {
|
|
132
|
+
* forceToString: "all"
|
|
133
|
+
* }); // ➔ [{ a: { b: "1" } }]
|
|
134
|
+
* dedupeArray("not an array");
|
|
135
|
+
* // ➔ Throws TypeError
|
|
136
|
+
* dedupeArray([1, 2, 3], {
|
|
137
|
+
* forceToString: "invalid"
|
|
138
|
+
* }); // ➔ Throws TypeError
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
192
141
|
declare const dedupeArray:<ForceToString extends ForceToStringOptions=false,Flattening extends boolean=false>(inputArray:unknown[],options?:DedupeArrayOptions<ForceToString,Flattening>)=>DedupeResult<ForceToString,Flattening>;type NormalizeInputToNumberArrayUnRecursive<T>=T extends string|bigint|boolean|number|Nullish?T:HasNonNumberLikeNonNullish<T>;
|
|
193
|
-
/**
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* @
|
|
197
|
-
|
|
198
|
-
*/
|
|
142
|
+
/** Detects whether `T` contains any number-like type (`string | number | bigint`).
|
|
143
|
+
*
|
|
144
|
+
* @template T Input type.
|
|
145
|
+
* @returns `true` if `T` contains number-like, otherwise `false`.
|
|
146
|
+
*/
|
|
199
147
|
type HasNumberLike<T>=[Extract<T,string|bigint|number>] extends [never]?false:true;
|
|
200
|
-
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* @
|
|
206
|
-
|
|
207
|
-
*/
|
|
148
|
+
/** Detects whether `T` contains a string type.
|
|
149
|
+
*
|
|
150
|
+
* - Useful for identifying values that may fail parsing to number (`undefined` when `R=false`).
|
|
151
|
+
*
|
|
152
|
+
* @template T Input type.
|
|
153
|
+
* @returns `true` if `T` contains `string`, otherwise `false`.
|
|
154
|
+
*/
|
|
208
155
|
type HasString<T>=[Extract<T,string>] extends [never]?false:true;
|
|
209
|
-
/**
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
|
|
214
|
-
* @returns `true` if such types exist, otherwise `false`.
|
|
215
|
-
*/
|
|
156
|
+
/** Detects whether `T` contains non-number-like, non-nullish values (`objects`, `arrays`, `symbols`, `functions`, `etc`.).
|
|
157
|
+
*
|
|
158
|
+
* @template T Input type.
|
|
159
|
+
* @returns `true` if such types exist, otherwise `false`.
|
|
160
|
+
*/
|
|
216
161
|
type HasNonNumberLikeNonNullish<T>=[ Exclude<T,string|bigint|number|Nullish>] extends [never]?false:true;
|
|
217
|
-
/**
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
|
|
234
|
-
* - `undefined` if parsing fails (string or invalid non-number-like).
|
|
235
|
-
* - Original `null` / `undefined` from input.
|
|
236
|
-
*/
|
|
162
|
+
/** Computes the return type of `toNumberArrayUnRecursive` based on input type `T` and option `R`.
|
|
163
|
+
*
|
|
164
|
+
* **Behavior:**
|
|
165
|
+
* - If `R = true` (`removeInvalidValueNumber: true`):
|
|
166
|
+
* - If `T` is only `null | undefined` → returns `[]`.
|
|
167
|
+
* - If `T` contains number-like (`string | number | bigint`) → returns `number[]`.
|
|
168
|
+
* - Otherwise → returns `[]`.
|
|
169
|
+
* - If `R = false` (`removeInvalidValueNumber: false`):
|
|
170
|
+
* - Preserves `null[]` or `undefined[]` if input is purely nullish.
|
|
171
|
+
* - Otherwise returns an array of:
|
|
172
|
+
* - `number` if `T` includes number-like.
|
|
173
|
+
* - `undefined` if parsing fails (string or invalid non-number-like).
|
|
174
|
+
* - Original `null` / `undefined` from input.
|
|
175
|
+
* @template T Input element type.
|
|
176
|
+
* @template R Flag indicating whether invalid values should be removed (`true`) or kept (`false`).
|
|
177
|
+
*
|
|
178
|
+
*/
|
|
237
179
|
type ToNumberArrayUnRecursiveReturn<T,R extends boolean>=R extends true?[ Exclude<T,null|undefined>] extends [never]?[]:HasNumberLike<T>extends true?number[]:[]:[ Exclude<T,null>] extends [never]?null[]:[Exclude<T,undefined>] extends [never]?undefined[]:Array<(HasNumberLike<T>extends true?number:never)|(HasString<T>extends true?undefined:never)|(HasNonNumberLikeNonNullish<T>extends true?undefined:never)|KeepNull<T>|KeepUndef<T>>;
|
|
238
|
-
/**
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
|
|
242
|
-
*/
|
|
180
|
+
/** Options object for `toNumberArrayUnRecursive`.
|
|
181
|
+
*
|
|
182
|
+
* @template T Flag indicating whether invalid values should be removed.
|
|
183
|
+
*/
|
|
243
184
|
type ToNumberArrayUnRecursiveOptions<T extends boolean>={
|
|
244
|
-
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
|
|
248
|
-
*/
|
|
185
|
+
/** If true, removes invalid number values (`NaN`, non-numeric strings, `null`, `undefined`) from the result, defaultValue: `true`.
|
|
186
|
+
*
|
|
187
|
+
* @default true
|
|
188
|
+
*/
|
|
249
189
|
removeInvalidValueNumber?:T;};
|
|
250
190
|
/** -------------------------------------------------------
|
|
251
|
-
* * ***
|
|
252
|
-
* -------------------------------------------------------
|
|
253
|
-
*
|
|
254
|
-
* -
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* @template
|
|
264
|
-
* @
|
|
265
|
-
*
|
|
266
|
-
* @
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
* // ➔
|
|
278
|
-
*
|
|
279
|
-
* toNumberArrayUnRecursive(
|
|
280
|
-
*
|
|
281
|
-
|
|
282
|
-
* toNumberArrayUnRecursive(['1', null, undefined, 'abc'], {
|
|
283
|
-
* removeInvalidValueNumber: false
|
|
284
|
-
* });
|
|
285
|
-
* // ➔ [1, null, undefined, undefined]
|
|
286
|
-
*
|
|
287
|
-
* toNumberArrayUnRecursive(null); // ➔ undefined
|
|
288
|
-
* toNumberArrayUnRecursive(undefined); // ➔ undefined
|
|
289
|
-
* toNumberArrayUnRecursive(1); // ➔ undefined
|
|
290
|
-
* ```
|
|
291
|
-
*/
|
|
191
|
+
* * ***Utility: `toNumberArrayUnRecursive`.***
|
|
192
|
+
* -------------------------------------------------------
|
|
193
|
+
* **Converts a flat array of strings, numbers, nulls, or undefineds into numbers.**
|
|
194
|
+
* - **Behavior:**
|
|
195
|
+
* - Only supports **flat arrays** (non-recursive).
|
|
196
|
+
* - Valid inputs: `string`, `number`, `null`, `undefined`.
|
|
197
|
+
* - `BigInt` will be converted to `number`.
|
|
198
|
+
* - Other values → coerced into `undefined`.
|
|
199
|
+
* - Invalid values can be **removed** (`removeInvalidValueNumber: true`) or **kept** (`false`).
|
|
200
|
+
* - **ℹ️ Note:**
|
|
201
|
+
* - _For recursive / nested arrays, use **{@link toNumberDeep | `toNumberDeep`}** instead._
|
|
202
|
+
* @template T Element type of the input array.
|
|
203
|
+
* @template R Whether invalid values should be removed (`true`) or kept (`false`).
|
|
204
|
+
* @param {Array<T> | readonly T[] | null | undefined} [array] The array to convert. Returns `undefined` if not an array.
|
|
205
|
+
* @param {ToNumberArrayUnRecursiveOptions<RemoveInvalidValue>} [options] Options controlling conversion behavior. Defaults to `{ removeInvalidValueNumber: true }`.
|
|
206
|
+
* @returns {ToNumberArrayUnRecursiveReturn<NormalizeInput<T>, RemoveInvalidValue>} A new array of string representations, with invalid values optionally removed.
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* toNumberArrayUnRecursive(['1', 2, '3']);
|
|
210
|
+
* // ➔ [1, 2, 3]
|
|
211
|
+
* toNumberArrayUnRecursive([1, null, undefined, 'abc']);
|
|
212
|
+
* // ➔ [1]
|
|
213
|
+
* toNumberArrayUnRecursive(['1', null, undefined, 'abc'], {
|
|
214
|
+
* removeInvalidValueNumber: false
|
|
215
|
+
* });
|
|
216
|
+
* // ➔ [1, null, undefined, undefined]
|
|
217
|
+
* toNumberArrayUnRecursive(null); // ➔ undefined
|
|
218
|
+
* toNumberArrayUnRecursive(undefined); // ➔ undefined
|
|
219
|
+
* toNumberArrayUnRecursive(1); // ➔ undefined
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
292
222
|
declare function toNumberArrayUnRecursive(array?:null|undefined,options?:ToNumberArrayUnRecursiveOptions<boolean>):undefined;declare function toNumberArrayUnRecursive(array?:Array<never>,options?:ToNumberArrayUnRecursiveOptions<boolean>):[];declare function toNumberArrayUnRecursive<T,R extends boolean=true>(array?:Array<T>|readonly T[]|null,options?:ToNumberArrayUnRecursiveOptions<R>):ToNumberArrayUnRecursiveReturn<NormalizeInputToNumberArrayUnRecursive<T>,R>;declare function toNumberArrayUnRecursive<T=unknown>(array?:T,options?:ToNumberArrayUnRecursiveOptions<boolean>):undefined;
|
|
293
|
-
/**
|
|
294
|
-
* Union of primitive types that can be safely converted to string.
|
|
295
|
-
*/
|
|
223
|
+
/** Union of primitive types that can be safely converted to string. */
|
|
296
224
|
type AllowedToString=string|number|boolean|bigint;
|
|
297
|
-
/**
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
* -
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
|
|
304
|
-
*/
|
|
225
|
+
/** Checks whether `T` contains any type that is allowed for conversion to string.
|
|
226
|
+
*
|
|
227
|
+
* - Returns `true` if `T` contains `string`, `number`, `boolean`, or `bigint`.
|
|
228
|
+
* - Otherwise returns `false`.
|
|
229
|
+
*
|
|
230
|
+
* @template T Input type to check.
|
|
231
|
+
*/
|
|
305
232
|
type HasAllowed<T>=[Extract<T,AllowedToString>] extends [never]?false:true;
|
|
306
|
-
/**
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* -
|
|
310
|
-
*
|
|
311
|
-
|
|
312
|
-
* @template T Input type to check.
|
|
313
|
-
*/
|
|
233
|
+
/** Checks whether `T` contains any non-nullish value that is disallowed for conversion.
|
|
234
|
+
*
|
|
235
|
+
* - Disallowed non-nullish types include `objects`, `arrays`, `symbols`, `functions`, `etc`.
|
|
236
|
+
* - Returns `true` if such types exist, otherwise `false`.
|
|
237
|
+
* @template T Input type to check.
|
|
238
|
+
*/
|
|
314
239
|
type HasDisallowedNonNullish<T>=[Exclude<T,AllowedToString|Nullish>] extends [never]?false:true;
|
|
315
|
-
/**
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
* - If `
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
|
|
329
|
-
*/
|
|
240
|
+
/** Computes the resulting type of `toStringArrayUnRecursive` based on input type `T` and option `R`.
|
|
241
|
+
*
|
|
242
|
+
* **Behavior:**
|
|
243
|
+
* - If `R = true` (`removeInvalidValue = true`):
|
|
244
|
+
* - If `T` contains any allowed values → `string[]`.
|
|
245
|
+
* - If `T` contains only nullish or disallowed types → `[]`.
|
|
246
|
+
*
|
|
247
|
+
* - If `R = false` (`removeInvalidValue = false`):
|
|
248
|
+
* - Include `string` if `T` has allowed values.
|
|
249
|
+
* - Include `undefined` if `T` has disallowed non-nullish values.
|
|
250
|
+
* - Preserve `null` and `undefined` from original `T`.
|
|
251
|
+
* @template T Input element type.
|
|
252
|
+
* @template R Flag indicating whether invalid values should be removed (`true`) or kept (`false`).
|
|
253
|
+
*/
|
|
330
254
|
type ToStringArrayUnRecursiveReturn<T,R extends boolean>=R extends true?HasAllowed<T>extends true?string[]:[]:Array<(HasAllowed<T>extends true?string:never)|(HasDisallowedNonNullish<T>extends true?undefined:never)|KeepNull<T>|KeepUndef<T>>;
|
|
331
|
-
/**
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
|
|
335
|
-
*/
|
|
255
|
+
/** Options object for `toStringArrayUnRecursive`.
|
|
256
|
+
*
|
|
257
|
+
* @template T Flag indicating whether invalid values should be removed.
|
|
258
|
+
*/
|
|
336
259
|
type ToStringArrayUnRecursiveOptions<T extends boolean>={
|
|
337
|
-
/**
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
|
|
341
|
-
*/
|
|
260
|
+
/** If true, removes invalid values (`null` and `undefined`) from the output, defaultValue: `true`.
|
|
261
|
+
*
|
|
262
|
+
* @default true
|
|
263
|
+
*/
|
|
342
264
|
removeInvalidValue?:T;};
|
|
343
265
|
/** ---------------------------------------------
|
|
344
|
-
* * ***
|
|
345
|
-
* ---------------------------------------------
|
|
346
|
-
*
|
|
347
|
-
* -
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
* @param {
|
|
360
|
-
* Options object to control transformation behavior.
|
|
361
|
-
*
|
|
362
|
-
* @
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
* //
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
* // ➔ ['
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
|
|
392
|
-
* // Not an array → returns undefined
|
|
393
|
-
* toStringArrayUnRecursive(null);
|
|
394
|
-
* // ➔ undefined
|
|
395
|
-
*
|
|
396
|
-
* toStringArrayUnRecursive(undefined);
|
|
397
|
-
* // ➔ undefined
|
|
398
|
-
*
|
|
399
|
-
* toStringArrayUnRecursive(1);
|
|
400
|
-
* // ➔ undefined
|
|
401
|
-
*
|
|
402
|
-
* toStringArrayUnRecursive("string");
|
|
403
|
-
* // ➔ undefined
|
|
404
|
-
* ```
|
|
405
|
-
*/
|
|
266
|
+
* * ***Utility: `toStringArrayUnRecursive`.***
|
|
267
|
+
* ---------------------------------------------
|
|
268
|
+
* **Converts all values in a flat array into string representations.**
|
|
269
|
+
* - **Behavior:**
|
|
270
|
+
* - Only processes **flat arrays** (non-recursive).
|
|
271
|
+
* - Supports input values: `string`, `number`, `bigint`, `boolean`,
|
|
272
|
+
* `null`, `undefined`.
|
|
273
|
+
* - Invalid values (`null` and `undefined`) can be **removed** or **kept**
|
|
274
|
+
* depending on the option.
|
|
275
|
+
* - Other unsupported types will be converted to `undefined` (and removed
|
|
276
|
+
* if `removeInvalidValue=true`).
|
|
277
|
+
* - **ℹ️ Note:**
|
|
278
|
+
* - _For recursive / nested arrays, use **{@link toStringDeep | `toStringDeep`}** instead._
|
|
279
|
+
* @template T Element type of the input array.
|
|
280
|
+
* @template R Whether invalid values should be removed (`true`) or kept (`false`).
|
|
281
|
+
* @param {Array<string | number | bigint | boolean | null | undefined> | null | undefined} [array] The flat array to transform. Returns `undefined` if not an array.
|
|
282
|
+
* @param {ToStringArrayUnRecursiveOptions<RemoveInvalidValue>} [options] Options object to control transformation behavior.
|
|
283
|
+
* @param {RemoveInvalidValue extends true ? boolean : boolean} [options.removeInvalidValue=true] Whether to remove invalid values (`null`, `undefined`, or unsupported types). Default: `true`.
|
|
284
|
+
* @returns {RemoveInvalidValue extends true ? string[] : (string | null | undefined)[]} A new array of string representations, with invalid values optionally removed.
|
|
285
|
+
* @example
|
|
286
|
+
* ```ts
|
|
287
|
+
* // Convert numbers and strings
|
|
288
|
+
* toStringArrayUnRecursive([1, 2, '3']);
|
|
289
|
+
* // ➔ ['1', '2', '3']
|
|
290
|
+
* // Remove null and undefined
|
|
291
|
+
* toStringArrayUnRecursive([1, null, undefined, 'abc'], {
|
|
292
|
+
* removeInvalidValue: true
|
|
293
|
+
* });
|
|
294
|
+
* // ➔ ['1', 'abc']
|
|
295
|
+
* // Keep null and undefined
|
|
296
|
+
* toStringArrayUnRecursive([1, null, undefined, 'abc'], {
|
|
297
|
+
* removeInvalidValue: false
|
|
298
|
+
* });
|
|
299
|
+
* // ➔ ['1', null, undefined, 'abc']
|
|
300
|
+
* // Convert boolean and bigint
|
|
301
|
+
* toStringArrayUnRecursive([true, false, 10n]);
|
|
302
|
+
* // ➔ ['true', 'false', '10']
|
|
303
|
+
* // Not an array → returns undefined
|
|
304
|
+
* toStringArrayUnRecursive(null);
|
|
305
|
+
* // ➔ undefined
|
|
306
|
+
* toStringArrayUnRecursive(undefined);
|
|
307
|
+
* // ➔ undefined
|
|
308
|
+
* toStringArrayUnRecursive(1);
|
|
309
|
+
* // ➔ undefined
|
|
310
|
+
* toStringArrayUnRecursive("string");
|
|
311
|
+
* // ➔ undefined
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
406
314
|
declare function toStringArrayUnRecursive(array?:undefined|null,options?:ToStringArrayUnRecursiveOptions<boolean>):undefined;declare function toStringArrayUnRecursive(array?:Array<never>,options?:ToStringArrayUnRecursiveOptions<boolean>):[];declare function toStringArrayUnRecursive<T,R extends boolean=true>(array?:Array<T>|readonly T[]|null,options?:ToStringArrayUnRecursiveOptions<R>):ToStringArrayUnRecursiveReturn<T,R>;declare function toStringArrayUnRecursive<T=unknown>(array?:T,options?:ToStringArrayUnRecursiveOptions<boolean>):undefined;
|
|
407
315
|
/** ---------------------------------
|
|
408
|
-
* * ***
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
* This is stricter than normal JS coercion
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
* @
|
|
420
|
-
* @
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
* toBooleanContent(
|
|
424
|
-
* toBooleanContent("");
|
|
425
|
-
* toBooleanContent("
|
|
426
|
-
* toBooleanContent(" asd ");
|
|
427
|
-
* toBooleanContent(
|
|
428
|
-
* toBooleanContent(
|
|
429
|
-
* toBooleanContent(
|
|
430
|
-
* toBooleanContent(
|
|
431
|
-
* toBooleanContent([]); // ➔
|
|
432
|
-
* toBooleanContent(
|
|
433
|
-
* toBooleanContent({});
|
|
434
|
-
* toBooleanContent({
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
declare const toBooleanContent:(value?:unknown)=>boolean;
|
|
316
|
+
* * ***Utility: `toBooleanContent`.***
|
|
317
|
+
* ---------------------------------------------
|
|
318
|
+
* **Converts a given value into a boolean (***strict***).**
|
|
319
|
+
* - **This is stricter than normal JS coercion:**
|
|
320
|
+
* - `null` and `undefined` return `false`.
|
|
321
|
+
* - Empty strings return `false`, non-empty strings return `true`.
|
|
322
|
+
* - Numbers: `0` is `false`, others `true`.
|
|
323
|
+
* - Booleans returned as-is.
|
|
324
|
+
* - Arrays: `[]` is `false`, non-empty is `true`.
|
|
325
|
+
* - Objects: `{}` is `false`, object with keys is `true`.
|
|
326
|
+
* @param {*} value - The value to be converted.
|
|
327
|
+
* @returns {boolean} `true` if the value is considered non-empty, otherwise `false`.
|
|
328
|
+
* @example
|
|
329
|
+
* toBooleanContent(null); // ➔ false
|
|
330
|
+
* toBooleanContent(undefined); // ➔ false
|
|
331
|
+
* toBooleanContent(""); // ➔ false
|
|
332
|
+
* toBooleanContent(" "); // ➔ false
|
|
333
|
+
* toBooleanContent("abc"); // ➔ true
|
|
334
|
+
* toBooleanContent(" asd "); // ➔ true
|
|
335
|
+
* toBooleanContent(0); // ➔ false
|
|
336
|
+
* toBooleanContent(42); // ➔ true
|
|
337
|
+
* toBooleanContent(NaN); // ➔ true
|
|
338
|
+
* toBooleanContent([]); // ➔ false
|
|
339
|
+
* toBooleanContent([1]); // ➔ true
|
|
340
|
+
* toBooleanContent({}); // ➔ false
|
|
341
|
+
* toBooleanContent({ a: 1 }); // ➔ true
|
|
342
|
+
* toBooleanContent({[Symbol("key")]: 123}); // ➔ false
|
|
343
|
+
*/
|
|
344
|
+
declare const toBooleanContent:(value:unknown)=>boolean;
|
|
438
345
|
/** -------------------------------------------------
|
|
439
|
-
* * ***
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
* JavaScript's normal truthy checks because it looks *inside*
|
|
445
|
-
* nested arrays & objects.
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
* @
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
* toBooleanContentDeep(
|
|
459
|
-
* toBooleanContentDeep(
|
|
460
|
-
* toBooleanContentDeep(
|
|
461
|
-
* toBooleanContentDeep(
|
|
462
|
-
* toBooleanContentDeep(
|
|
463
|
-
* toBooleanContentDeep(
|
|
464
|
-
* toBooleanContentDeep("
|
|
465
|
-
* toBooleanContentDeep(
|
|
466
|
-
* toBooleanContentDeep(
|
|
467
|
-
* toBooleanContentDeep(
|
|
468
|
-
* toBooleanContentDeep(
|
|
469
|
-
* toBooleanContentDeep(
|
|
470
|
-
* toBooleanContentDeep({ a:
|
|
471
|
-
* toBooleanContentDeep({
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
* toBooleanContentDeep({[Symbol("key")]: 123}); // ➔false
|
|
475
|
-
*/
|
|
476
|
-
declare const toBooleanContentDeep:(value?:unknown)=>boolean;type ToBooleanExplicitOptions={
|
|
346
|
+
* * ***Utility: `toBooleanContentDeep`.***
|
|
347
|
+
* ---------------------------------------------
|
|
348
|
+
* **This function does a deep inspection to determine if the input
|
|
349
|
+
* contains any meaningful / non-empty value.**
|
|
350
|
+
* @description
|
|
351
|
+
* It is stricter than JavaScript's normal truthy checks because it looks *inside*
|
|
352
|
+
* nested arrays & objects (recursively checks).
|
|
353
|
+
* - **Rules:**
|
|
354
|
+
* - `null` and `undefined` return `false`
|
|
355
|
+
* - Empty strings `""` return `false`
|
|
356
|
+
* - `0` returns `false`
|
|
357
|
+
* - Empty arrays `[]` or empty objects `{}` return `false`
|
|
358
|
+
* - Checks deeply nested arrays/objects — if any value inside is "non-empty", returns `true`
|
|
359
|
+
* @param {*} value - The value to check.
|
|
360
|
+
* @returns {boolean} `true` if the value or anything nested inside is non-empty, otherwise `false`.
|
|
361
|
+
* @example
|
|
362
|
+
* toBooleanContentDeep(null); // ➔ false
|
|
363
|
+
* toBooleanContentDeep(""); // ➔ false
|
|
364
|
+
* toBooleanContentDeep(0); // ➔ false
|
|
365
|
+
* toBooleanContentDeep([]); // ➔ false
|
|
366
|
+
* toBooleanContentDeep({}); // ➔ false
|
|
367
|
+
* toBooleanContentDeep([[], {}]); // ➔ false
|
|
368
|
+
* toBooleanContentDeep("abc"); // ➔ true
|
|
369
|
+
* toBooleanContentDeep(42); // ➔ true
|
|
370
|
+
* toBooleanContentDeep(NaN); // ➔ true
|
|
371
|
+
* toBooleanContentDeep([0, "", 5]); // ➔ true
|
|
372
|
+
* toBooleanContentDeep([NaN, "", 0]); // ➔ true
|
|
373
|
+
* toBooleanContentDeep([0, "", null]); // ➔ false
|
|
374
|
+
* toBooleanContentDeep({ a: 0 }); // ➔ false
|
|
375
|
+
* toBooleanContentDeep({ a: 1 }); // ➔ true
|
|
376
|
+
* toBooleanContentDeep({ a: { b: [] }}); // ➔ false
|
|
377
|
+
* toBooleanContentDeep({ a: { b: "x" }}); // ➔ true
|
|
378
|
+
* toBooleanContentDeep({[Symbol("key")]: 123}); // ➔false
|
|
379
|
+
*/
|
|
380
|
+
declare const toBooleanContentDeep:(value:unknown)=>boolean;type ToBooleanExplicitOptions={
|
|
477
381
|
/** Whether string comparison ignores case, _defaultValue: `false`_.
|
|
478
|
-
*
|
|
479
|
-
* @default false
|
|
480
|
-
*/
|
|
382
|
+
*
|
|
383
|
+
* @default false
|
|
384
|
+
*/
|
|
481
385
|
caseInsensitive?:boolean;
|
|
482
386
|
/** Whether to trim whitespace before comparison, _defaultValue: `true`_.
|
|
483
|
-
*
|
|
484
|
-
* @default true
|
|
485
|
-
*/
|
|
387
|
+
*
|
|
388
|
+
* @default true
|
|
389
|
+
*/
|
|
486
390
|
trimString?:boolean;
|
|
487
391
|
/** Whether to consider the string `"indeterminate"` as `true`, _defaultValue: `false`_.
|
|
488
|
-
*
|
|
489
|
-
* @default false
|
|
490
|
-
*/
|
|
392
|
+
*
|
|
393
|
+
* @default false
|
|
394
|
+
*/
|
|
491
395
|
includeIndeterminate?:boolean;};
|
|
492
396
|
/** ---------------------------------
|
|
493
|
-
* * ***
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
* Supports optional `caseInsensitive` and `trimString` to customize
|
|
504
|
-
*
|
|
505
|
-
* @param {
|
|
506
|
-
* @param {
|
|
507
|
-
* @param {
|
|
508
|
-
* @param {
|
|
509
|
-
* @param {
|
|
510
|
-
* @returns {boolean} `true` if the value matches a truthy representation, otherwise `false`.
|
|
511
|
-
* @throws {TypeError} Throws if any option provided is not a boolean.
|
|
512
|
-
*
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
* toBooleanExplicit(
|
|
516
|
-
* // ➔ true
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
* toBooleanExplicit(
|
|
522
|
-
* // ➔
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
* toBooleanExplicit(
|
|
528
|
-
* // ➔
|
|
529
|
-
*
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
* toBooleanExplicit("
|
|
534
|
-
* // ➔ false (
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
* toBooleanExplicit("
|
|
540
|
-
* // ➔
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
* toBooleanExplicit(" YES ", { trimString: false });
|
|
546
|
-
* // ➔ false (whitespace not trimmed)
|
|
547
|
-
*
|
|
548
|
-
* toBooleanExplicit(" YES ", { trimString: true, caseInsensitive: true });
|
|
549
|
-
* // ➔ true
|
|
550
|
-
*
|
|
551
|
-
* toBooleanExplicit(" YES ", { trimString: true, caseInsensitive: false });
|
|
552
|
-
* // ➔ false
|
|
553
|
-
*
|
|
554
|
-
* toBooleanExplicit("indeterminate");
|
|
555
|
-
* // ➔ false (default)
|
|
556
|
-
*
|
|
557
|
-
* toBooleanExplicit("indeterminate", { includeIndeterminate: true });
|
|
558
|
-
* // ➔ true
|
|
559
|
-
*/
|
|
560
|
-
declare const toBooleanExplicit:(value?:unknown,options?:ToBooleanExplicitOptions)=>boolean;
|
|
397
|
+
* * ***Utility: `toBooleanExplicit`.***
|
|
398
|
+
* ---------------------------------------------
|
|
399
|
+
* **Converts a value into a strict boolean.**
|
|
400
|
+
* - **Behavior:**
|
|
401
|
+
* - It supports various common string representations of truthy values,
|
|
402
|
+
* including `"true"`, `"on"`, `"yes"`, `"1"`, the number `1`, the boolean `true`,
|
|
403
|
+
* and optionally the string `"indeterminate"` if enabled.
|
|
404
|
+
* - **ℹ️ Note:**
|
|
405
|
+
* - Any other value, including `undefined`, `null`, `false`, `0`, and
|
|
406
|
+
* unrecognized strings will return `false`.
|
|
407
|
+
* - Supports optional `caseInsensitive` and `trimString` to customize
|
|
408
|
+
* string normalization.
|
|
409
|
+
* @param {*} value - The value to convert.
|
|
410
|
+
* @param {ToBooleanExplicitOptions} [options] - Options for conversion behavior.
|
|
411
|
+
* @param {ToBooleanExplicitOptions["caseInsensitive"]} [options.caseInsensitive=false] - Whether string comparison ignores case, default: `false`.
|
|
412
|
+
* @param {ToBooleanExplicitOptions["trimString"]} [options.trimString=true] - Whether to trim whitespace before comparison, default: `true`.
|
|
413
|
+
* @param {ToBooleanExplicitOptions["includeIndeterminate"]} [options.includeIndeterminate=false] - If `true`, the string `"indeterminate"` is considered a truthy value, defaults to `false`.
|
|
414
|
+
* @returns {boolean} `true` if the value matches a truthy representation, otherwise `false`.
|
|
415
|
+
* @throws {TypeError} Throws if any option provided is not a boolean.
|
|
416
|
+
* @example
|
|
417
|
+
* toBooleanExplicit(1);
|
|
418
|
+
* // ➔ true
|
|
419
|
+
* toBooleanExplicit(true);
|
|
420
|
+
* // ➔ true
|
|
421
|
+
* toBooleanExplicit("on");
|
|
422
|
+
* // ➔ true
|
|
423
|
+
* toBooleanExplicit("1");
|
|
424
|
+
* // ➔ true
|
|
425
|
+
* toBooleanExplicit(0);
|
|
426
|
+
* // ➔ false
|
|
427
|
+
* toBooleanExplicit("off");
|
|
428
|
+
* // ➔ false
|
|
429
|
+
* toBooleanExplicit("Yes");
|
|
430
|
+
* // ➔ false (caseInsensitive is false by default)
|
|
431
|
+
* toBooleanExplicit(" yes ");
|
|
432
|
+
* // ➔ true (whitespace trimmed by default)
|
|
433
|
+
* toBooleanExplicit("YES", { caseInsensitive: true });
|
|
434
|
+
* // ➔ true
|
|
435
|
+
* toBooleanExplicit("YES", { caseInsensitive: false });
|
|
436
|
+
* // ➔ false
|
|
437
|
+
* toBooleanExplicit(" YES ", { trimString: false });
|
|
438
|
+
* // ➔ false (whitespace not trimmed)
|
|
439
|
+
* toBooleanExplicit(" YES ", { trimString: true, caseInsensitive: true });
|
|
440
|
+
* // ➔ true
|
|
441
|
+
* toBooleanExplicit(" YES ", { trimString: true, caseInsensitive: false });
|
|
442
|
+
* // ➔ false
|
|
443
|
+
* toBooleanExplicit("indeterminate");
|
|
444
|
+
* // ➔ false (default)
|
|
445
|
+
* toBooleanExplicit("indeterminate", { includeIndeterminate: true });
|
|
446
|
+
* // ➔ true
|
|
447
|
+
*/
|
|
448
|
+
declare const toBooleanExplicit:(value:unknown,options?:ToBooleanExplicitOptions)=>boolean;
|
|
561
449
|
/** ---------------------------------
|
|
562
|
-
* * ***
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
* This follows JavaScript's typical truthy/falsy rules with some tweaks
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
* @
|
|
574
|
-
* @
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
* toBooleanLoose(
|
|
578
|
-
* toBooleanLoose(
|
|
579
|
-
* toBooleanLoose(
|
|
580
|
-
* toBooleanLoose(
|
|
581
|
-
* toBooleanLoose(
|
|
582
|
-
* toBooleanLoose(
|
|
583
|
-
* toBooleanLoose(
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
*/
|
|
587
|
-
declare const toBooleanLoose:(value?:unknown)=>boolean;
|
|
450
|
+
* * ***Utility: `toBooleanLoose`.***
|
|
451
|
+
* ---------------------------------------------
|
|
452
|
+
* **Converts a given value into a boolean (loose).**
|
|
453
|
+
* - **This follows JavaScript's typical truthy/falsy rules with some tweaks:**
|
|
454
|
+
* - `null` and `undefined` return `false`.
|
|
455
|
+
* - Empty strings return `false`, non-empty strings return `true`.
|
|
456
|
+
* - Numbers: `0` is `false`, others `true`.
|
|
457
|
+
* - Booleans returned as-is.
|
|
458
|
+
* - Arrays: `[]` is `false`, non-empty is `true`.
|
|
459
|
+
* - Other objects: uses `Boolean(value)`, so `{}` is `true`.
|
|
460
|
+
* @param {*} value - The value to be converted.
|
|
461
|
+
* @returns {boolean} `true` if the value is truthy, otherwise `false`.
|
|
462
|
+
* @example
|
|
463
|
+
* toBooleanLoose(null); // ➔ false
|
|
464
|
+
* toBooleanLoose(""); // ➔ false
|
|
465
|
+
* toBooleanLoose("abc"); // ➔ true
|
|
466
|
+
* toBooleanLoose(0); // ➔ false
|
|
467
|
+
* toBooleanLoose(42); // ➔ true
|
|
468
|
+
* toBooleanLoose([]); // ➔ false
|
|
469
|
+
* toBooleanLoose([1]); // ➔ true
|
|
470
|
+
* toBooleanLoose({}); // ➔ true
|
|
471
|
+
* toBooleanLoose({ a: 1 }); // ➔ true
|
|
472
|
+
*/
|
|
473
|
+
declare const toBooleanLoose:(value:unknown)=>boolean;
|
|
588
474
|
/** -------------------------------------------------------------
|
|
589
|
-
* * ***
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
* - Supports multi-locale formats
|
|
593
|
-
* - US
|
|
594
|
-
* - Swiss
|
|
595
|
-
* - French
|
|
596
|
-
* - Indian
|
|
597
|
-
* - European
|
|
598
|
-
* - Compact
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
* -
|
|
602
|
-
* -
|
|
603
|
-
* -
|
|
604
|
-
* -
|
|
605
|
-
*
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
*
|
|
610
|
-
*
|
|
611
|
-
*
|
|
612
|
-
*
|
|
613
|
-
*
|
|
614
|
-
*
|
|
615
|
-
*
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
* -
|
|
627
|
-
* -
|
|
628
|
-
* -
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
*
|
|
636
|
-
*
|
|
637
|
-
*
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
* parseCurrencyString("
|
|
645
|
-
* // ➔
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
*
|
|
649
|
-
*
|
|
650
|
-
* parseCurrencyString("
|
|
651
|
-
* // ➔
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
* // ➔ 123456.78
|
|
658
|
-
*
|
|
659
|
-
* parseCurrencyString("15300000,2121");
|
|
660
|
-
* // ➔ 15300000.2121
|
|
661
|
-
*
|
|
662
|
-
* parseCurrencyString("USD 15 300 000.21");
|
|
663
|
-
* // ➔ 15300000.21
|
|
664
|
-
*
|
|
665
|
-
* parseCurrencyString("");
|
|
666
|
-
* // ➔ 0
|
|
667
|
-
*
|
|
668
|
-
* parseCurrencyString("abc");
|
|
669
|
-
* // ➔ 0
|
|
670
|
-
* ```
|
|
671
|
-
*/
|
|
672
|
-
declare const parseCurrencyString:(input?:string|null)=>number;
|
|
475
|
+
* * ***Utility: `parseCurrencyString`.***
|
|
476
|
+
* ---------------------------------------------
|
|
477
|
+
* **Parses a human-friendly currency string into a JavaScript number.**
|
|
478
|
+
* - **Supports multi-locale formats:**
|
|
479
|
+
* - ***US:*** `"15,000.10"` ➔ `15300.10`.
|
|
480
|
+
* - ***Swiss:*** `"15'000.10"` ➔ `15300.10`.
|
|
481
|
+
* - ***French:*** `"15 000,10"` ➔ `15300.10`.
|
|
482
|
+
* - ***Indian:*** `"1,23,456.78"` ➔ `123456.78`.
|
|
483
|
+
* - ***European:*** `"151.000,10"` ➔ `151300.10`.
|
|
484
|
+
* - ***Compact:*** `"15300000,10"` ➔ `15300000.10`.
|
|
485
|
+
* - **Features:**
|
|
486
|
+
* - Strips symbols automatically: `"Rp"`, `"$"`, `"EUR"`, `etc`.
|
|
487
|
+
* - Handles bracket negatives: `"(15.000,10)"` ➔ `-15300.10`.
|
|
488
|
+
* - Normalizes decimal separator (last dot or comma).
|
|
489
|
+
* - Detects non-breaking spaces (`\u00A0`, `\u202F`) often in European data.
|
|
490
|
+
* - Fallback to `0` for empty, invalid, or non-numeric strings.
|
|
491
|
+
* - **How it parses internally:**
|
|
492
|
+
* 1. Removes all characters except digits, `.`, `,`, `'`, `space`,
|
|
493
|
+
* `\u00A0`, `\u202F`.
|
|
494
|
+
* 2. Detects bracket (...) as negative.
|
|
495
|
+
* 3. If Indian style (`1,23,456`) detected by multiple ,`\d{2}`, removes all commas.
|
|
496
|
+
* 4. Otherwise:
|
|
497
|
+
* - If multiple dots & no commas ➔ thousands: removes all `.`.
|
|
498
|
+
* - If multiple commas & no dots ➔ thousands: removes all `,`.
|
|
499
|
+
* - If mixed, treats last `,` or `.` as decimal.
|
|
500
|
+
* 5. Converts final decimal to `.` for JS float.
|
|
501
|
+
* - **Gotchas:**
|
|
502
|
+
* - If both `.` and `,` are present, last occurrence is used as decimal.
|
|
503
|
+
* - For strings like `"1.121.234,56"` ➔ decimal is `,`.
|
|
504
|
+
* - For `"1,121,234.56"` ➔ decimal is `.`.
|
|
505
|
+
* - For `"15300000,2121"` ➔ decimal becomes `.` internally.
|
|
506
|
+
* - **ℹ️ Note:**
|
|
507
|
+
* - You can use this function as a first step to **sanitize currency inputs**
|
|
508
|
+
* before storing into database or doing math.
|
|
509
|
+
* - Always pair this with your formatter for consistent output display.
|
|
510
|
+
* @param {string|null|undefined} input Any messy currency string, may contain:
|
|
511
|
+
* - Currency symbols (`Rp`,`$`, `CHF`, `EUR`).
|
|
512
|
+
* - Thousands separators (`.`, `,`, `'`, `space`, `\u00A0`, `\u202F`).
|
|
513
|
+
* - Various decimal formats (`,` or `.`).
|
|
514
|
+
* - Bracket negative: `"(15.000,10)"`.
|
|
515
|
+
* @returns {number}
|
|
516
|
+
* JavaScript float representation.
|
|
517
|
+
* Will return `0` for invalid, empty, or non-string input.
|
|
518
|
+
* @example
|
|
519
|
+
* ```ts
|
|
520
|
+
* parseCurrencyString("Rp 15.300.000,21");
|
|
521
|
+
* // ➔ 15300000.21
|
|
522
|
+
* parseCurrencyString("15 300 000,21");
|
|
523
|
+
* // ➔ 15300000.21
|
|
524
|
+
* parseCurrencyString("CHF 15'300'000.21");
|
|
525
|
+
* // ➔ 15300000.21
|
|
526
|
+
* parseCurrencyString("$15,300,000.21");
|
|
527
|
+
* // ➔ 15300000.21
|
|
528
|
+
* parseCurrencyString("(15.000,10)");
|
|
529
|
+
* // ➔ -15000.10
|
|
530
|
+
* parseCurrencyString("1,23,456.78");
|
|
531
|
+
* // ➔ 123456.78
|
|
532
|
+
* parseCurrencyString("15300000,2121");
|
|
533
|
+
* // ➔ 15300000.2121
|
|
534
|
+
* parseCurrencyString("USD 15 300 000.21");
|
|
535
|
+
* // ➔ 15300000.21
|
|
536
|
+
* parseCurrencyString("");
|
|
537
|
+
* // ➔ 0
|
|
538
|
+
* parseCurrencyString("abc");
|
|
539
|
+
* // ➔ 0
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
declare const parseCurrencyString:(input:string|null|undefined)=>number;
|
|
673
543
|
/** ----------------------------------------------------------
|
|
674
|
-
* * ***
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
* - Supported conversions for string inputs (case-insensitive, trimmed)
|
|
678
|
-
* - `"true"`
|
|
679
|
-
* - `"false"`
|
|
680
|
-
* - `"null"`
|
|
681
|
-
* - `"yes"`
|
|
682
|
-
* - `"no"`
|
|
683
|
-
* - `"nan"`
|
|
684
|
-
* - `"undefined"`
|
|
685
|
-
*
|
|
686
|
-
* -
|
|
687
|
-
* -
|
|
688
|
-
*
|
|
689
|
-
* -
|
|
690
|
-
*
|
|
691
|
-
*
|
|
692
|
-
*
|
|
693
|
-
*
|
|
694
|
-
*
|
|
695
|
-
*
|
|
696
|
-
* convertType("
|
|
697
|
-
* convertType("
|
|
698
|
-
* convertType("
|
|
699
|
-
* convertType(
|
|
700
|
-
* convertType(
|
|
701
|
-
* convertType(
|
|
702
|
-
|
|
703
|
-
* convertType(100) // ➔ 100
|
|
704
|
-
* convertType(NaN) // ➔ NaN
|
|
705
|
-
* convertType({}) // ➔ {}
|
|
706
|
-
*/
|
|
544
|
+
* * ***Utility: `convertType`.***
|
|
545
|
+
* ---------------------------------------------
|
|
546
|
+
* **Converts a value from a string to its corresponding JavaScript primitive type.**
|
|
547
|
+
* - **Supported conversions for string inputs (case-insensitive, trimmed):**
|
|
548
|
+
* - `"true"` ➔ `true` (***boolean***).
|
|
549
|
+
* - `"false"` ➔ `false` (***boolean***).
|
|
550
|
+
* - `"null"` ➔ `null` (***null***).
|
|
551
|
+
* - `"yes"` ➔ `true` (***boolean***).
|
|
552
|
+
* - `"no"` ➔ `false` (***boolean***).
|
|
553
|
+
* - `"nan"` or `"NaN"` ➔ `NaN` (***number***).
|
|
554
|
+
* - `"undefined"` ➔ `undefined` (***undefined***).
|
|
555
|
+
* - Numeric strings with optional thousands separators (e.g. `"3,567,890.14"`) ➔ `3567890.14` ***as a `number` type***.
|
|
556
|
+
* - Strings containing only whitespace are converted to empty string `""`.
|
|
557
|
+
* - Non-string inputs are returned unchanged.
|
|
558
|
+
* - Strings not matching any special case are trimmed and returned as-is.
|
|
559
|
+
* @param {*} value - The value to convert, usually a string or other type.
|
|
560
|
+
* @returns {*} The converted JavaScript primitive (***`boolean`***, ***`number`***, ***`null`***, ***`undefined`***, ***`NaN`***) or the original value if no conversion applies.
|
|
561
|
+
* @example
|
|
562
|
+
* convertType("true"); // ➔ true
|
|
563
|
+
* convertType(" 42 "); // ➔ 42
|
|
564
|
+
* convertType("FALSE"); // ➔ false
|
|
565
|
+
* convertType(" null "); // ➔ null
|
|
566
|
+
* convertType(" "); // ➔ ""
|
|
567
|
+
* convertType(" Hello World "); // ➔ "Hello World"
|
|
568
|
+
* convertType("NaN"); // ➔ NaN
|
|
569
|
+
* convertType(100); // ➔ 100
|
|
570
|
+
* convertType(NaN); // ➔ NaN
|
|
571
|
+
* convertType({}); // ➔ {}
|
|
572
|
+
*/
|
|
707
573
|
declare const convertType:(value:unknown)=>unknown;type NonJsonParsableType=Omit<Exclude<unknown,string|null|undefined>,string>;type Contains<T,U>=[Extract<T,U>] extends [never]?false:true;type UnknownValue={undefined:true;};type SafeJsonParseResult<TData,T>=IfNotExtends<T,NonJsonParsableType>extends true?T extends never?undefined:T extends void?undefined:T extends number?undefined:Contains<T,string>extends true?Contains<T,null & string>extends true?TData|null|undefined:TData|undefined:IfExtends<T,null>extends true?null:IfNotExtends<T,NonJsonParsableType>extends true?TData|null|undefined:undefined:Contains<T,string>extends true?IsAny<T>extends true?TData|undefined|null:TData|undefined:undefined;
|
|
708
574
|
/** --------------------------------------------------
|
|
709
|
-
* * ***Options for cleaning and transforming parsed JSON data.***
|
|
710
|
-
* --------------------------------------------------
|
|
711
|
-
*/
|
|
575
|
+
* * ***Options for cleaning and transforming parsed JSON data.***
|
|
576
|
+
* --------------------------------------------------
|
|
577
|
+
*/
|
|
712
578
|
type ParseParsedDataOptions={
|
|
713
579
|
/** Convert numeric strings to numbers (e.g., `"42"` ➔ `42`), defaultValue: `false`.
|
|
714
|
-
*
|
|
715
|
-
* @default false
|
|
716
|
-
*/
|
|
580
|
+
*
|
|
581
|
+
* @default false
|
|
582
|
+
*/
|
|
717
583
|
convertNumbers?:boolean;
|
|
718
584
|
/** Convert numeric strings "NaN" to NaN (e.g., `"NaN"` ➔ `NaN`), defaultValue: `false`.
|
|
719
|
-
*
|
|
720
|
-
* @default false
|
|
721
|
-
*/
|
|
585
|
+
*
|
|
586
|
+
* @default false
|
|
587
|
+
*/
|
|
722
588
|
convertNaN?:boolean;
|
|
723
589
|
/** Convert `"true"` / `"false"` strings to boolean values, defaultValue: `false`.
|
|
724
|
-
*
|
|
725
|
-
* @default false
|
|
726
|
-
*/
|
|
590
|
+
*
|
|
591
|
+
* @default false
|
|
592
|
+
*/
|
|
727
593
|
convertBooleans?:boolean;
|
|
728
594
|
/** Convert valid date strings into `Date` objects, defaultValue: `false`.
|
|
729
|
-
*
|
|
730
|
-
* @default false
|
|
731
|
-
*/
|
|
595
|
+
*
|
|
596
|
+
* @default false
|
|
597
|
+
*/
|
|
732
598
|
convertDates?:boolean;
|
|
733
599
|
/** Custom date formats to be parsed (e.g., `["DD/MM/YYYY", "MM/DD/YYYY"]`), defaultValue: `[]`.
|
|
734
|
-
*
|
|
735
|
-
* @default []
|
|
736
|
-
*/
|
|
600
|
+
*
|
|
601
|
+
* @default []
|
|
602
|
+
*/
|
|
737
603
|
customDateFormats?:string[];
|
|
738
604
|
/** Remove `null` values from objects and arrays, defaultValue: `false`.
|
|
739
|
-
*
|
|
740
|
-
* @default false
|
|
741
|
-
*/
|
|
605
|
+
*
|
|
606
|
+
* @default false
|
|
607
|
+
*/
|
|
742
608
|
removeNulls?:boolean;
|
|
743
609
|
/** Remove `undefined` values from objects and arrays, defaultValue: `false`.
|
|
744
|
-
*
|
|
745
|
-
* - `false` (default): replaces `undefined` with `null`
|
|
746
|
-
* - `true`: removes keys with `undefined` values
|
|
747
|
-
*
|
|
748
|
-
* @default false
|
|
749
|
-
*/
|
|
610
|
+
*
|
|
611
|
+
* - `false` (default): replaces `undefined` with `null`
|
|
612
|
+
* - `true`: removes keys with `undefined` values
|
|
613
|
+
*
|
|
614
|
+
* @default false
|
|
615
|
+
*/
|
|
750
616
|
removeUndefined?:boolean;
|
|
751
617
|
/** Remove empty objects `{}` from the final output, defaultValue: `false`.
|
|
752
|
-
*
|
|
753
|
-
* @default false
|
|
754
|
-
*/
|
|
618
|
+
*
|
|
619
|
+
* @default false
|
|
620
|
+
*/
|
|
755
621
|
removeEmptyObjects?:boolean;
|
|
756
622
|
/** Remove empty arrays `[]` from the final output, defaultValue: `false`.
|
|
757
|
-
*
|
|
758
|
-
* @default false
|
|
759
|
-
*/
|
|
623
|
+
*
|
|
624
|
+
* @default false
|
|
625
|
+
*/
|
|
760
626
|
removeEmptyArrays?:boolean;
|
|
761
627
|
/** Strict mode: Removes values that do not match selected conversions, defaultValue: `false`.
|
|
762
|
-
*
|
|
763
|
-
* @default false
|
|
764
|
-
*/
|
|
628
|
+
*
|
|
629
|
+
* @default false
|
|
630
|
+
*/
|
|
765
631
|
strictMode?:boolean;
|
|
766
632
|
/** Enable error logging if JSON parsing fails, defaultValue: `false`.
|
|
767
|
-
*
|
|
768
|
-
* @default false
|
|
769
|
-
*/
|
|
633
|
+
*
|
|
634
|
+
* @default false
|
|
635
|
+
*/
|
|
770
636
|
loggingOnFail?:boolean;
|
|
771
637
|
/** Custom error handler function.
|
|
772
|
-
*
|
|
773
|
-
* - If provided, it will be called with the error.
|
|
774
|
-
*
|
|
775
|
-
* - If not provided, defaults to `undefined` in type, but internally a no-op function is used.
|
|
776
|
-
*
|
|
777
|
-
* @default undefined
|
|
778
|
-
*/
|
|
638
|
+
*
|
|
639
|
+
* - If provided, it will be called with the error.
|
|
640
|
+
*
|
|
641
|
+
* - If not provided, defaults to `undefined` in type, but internally a no-op function is used.
|
|
642
|
+
*
|
|
643
|
+
* @default undefined
|
|
644
|
+
*/
|
|
779
645
|
onError?:(error:Error)=>void;
|
|
780
646
|
/**
|
|
781
|
-
* Whether to check symbol properties when checking empty objects.
|
|
782
|
-
* @default false
|
|
783
|
-
*/
|
|
647
|
+
* Whether to check symbol properties when checking empty objects.
|
|
648
|
+
* @default false
|
|
649
|
+
*/
|
|
784
650
|
checkSymbols?:boolean;};
|
|
785
651
|
/** --------------------------------------------------
|
|
786
|
-
* * ***
|
|
787
|
-
*
|
|
788
|
-
*
|
|
789
|
-
* @template T - Expected output type.
|
|
790
|
-
* @param {
|
|
791
|
-
* @param {ParseParsedDataOptions} options - Cleaning options.
|
|
792
|
-
* @returns {T | undefined}
|
|
793
|
-
*
|
|
794
|
-
* ***⚠️
|
|
795
|
-
*
|
|
796
|
-
*
|
|
797
|
-
*
|
|
798
|
-
*
|
|
799
|
-
*
|
|
800
|
-
*
|
|
801
|
-
*
|
|
802
|
-
*
|
|
803
|
-
*
|
|
804
|
-
* }
|
|
805
|
-
*
|
|
806
|
-
*
|
|
807
|
-
* //
|
|
808
|
-
*
|
|
809
|
-
|
|
810
|
-
* });
|
|
811
|
-
* console.log(result); // ➔ { isActive: true }
|
|
812
|
-
* ```
|
|
813
|
-
*/
|
|
652
|
+
* * ***Utility: `cleanParsedData`.***
|
|
653
|
+
* ---------------------------------------------
|
|
654
|
+
* **Cleans parsed JSON data based on provided options.**
|
|
655
|
+
* @template T - Expected output type.
|
|
656
|
+
* @param {*} data - The parsed JSON data.
|
|
657
|
+
* @param {ParseParsedDataOptions} [options] - Cleaning options.
|
|
658
|
+
* @returns {T | null | undefined} The cleaned data.
|
|
659
|
+
* - ***⚠️ Notice:*** _If data is JSON string, we recommend use **{@link safeJsonParse | `safeJsonParse`}** for more safe._
|
|
660
|
+
* - ***⚠️ Note:*** _If using **`convertDates`** **options**, result may contain Date objects, you may need type assertions in strict TypeScript settings._
|
|
661
|
+
* @example
|
|
662
|
+
* ```ts
|
|
663
|
+
* // 1: Convert numbers and remove nulls
|
|
664
|
+
* const result = cleanParsedData({ age: "25", name: null }, {
|
|
665
|
+
* convertNumbers: true,
|
|
666
|
+
* removeNulls: true
|
|
667
|
+
* });
|
|
668
|
+
* console.log(result); // ➔ { age: 25 }
|
|
669
|
+
* // 2: Convert boolean strings
|
|
670
|
+
* const result = cleanParsedData({ isActive: "true" }, {
|
|
671
|
+
* convertBooleans: true
|
|
672
|
+
* });
|
|
673
|
+
* console.log(result); // ➔ { isActive: true }
|
|
674
|
+
* ```
|
|
675
|
+
*/
|
|
814
676
|
declare const cleanParsedData:<T=unknown>(data:T,options?:ParseParsedDataOptions)=>T|undefined|null;
|
|
815
677
|
/** --------------------------------------------------
|
|
816
|
-
* * ***
|
|
817
|
-
*
|
|
818
|
-
*
|
|
819
|
-
* @param {string} dateString - Date string to parse.
|
|
820
|
-
* @param {string} format - Date format to match.
|
|
821
|
-
* @returns {Date | null}
|
|
822
|
-
|
|
678
|
+
* * ***Utility: `parseCustomDate`.***
|
|
679
|
+
* ---------------------------------------------
|
|
680
|
+
* **Parses custom date formats like "DD/MM/YYYY" or "MM/DD/YYYY".**
|
|
681
|
+
* @param {string} dateString - Date string to parse.
|
|
682
|
+
* @param {string} format - Date format to match.
|
|
683
|
+
* @returns {Date | null} Returns a `Date` object if valid, otherwise `null`.
|
|
684
|
+
* @throws {TypeError} Throw an type-error if `dateString` **(first parameter)** and `format` **(second parameter)** is not a string or empty-string.
|
|
685
|
+
* @example
|
|
686
|
+
* // Valid: European format (DD/MM/YYYY)
|
|
687
|
+
* const date1 = parseCustomDate("03/09/2025", "DD/MM/YYYY");
|
|
688
|
+
* console.log(date1); // ➔ Date { Wed Sep 03 2025 ... }
|
|
689
|
+
*
|
|
690
|
+
* // Valid: US format (MM/DD/YYYY)
|
|
691
|
+
* const date2 = parseCustomDate("09/03/2025", "MM/DD/YYYY");
|
|
692
|
+
* console.log(date2); // ➔ Date { Wed Sep 03 2025 ... }
|
|
693
|
+
*
|
|
694
|
+
* // Invalid: wrong format
|
|
695
|
+
* const date3 = parseCustomDate("2025-09-03", "DD/MM/YYYY");
|
|
696
|
+
* console.log(date3); // ➔ null
|
|
697
|
+
*
|
|
698
|
+
* // Invalid: non-date string
|
|
699
|
+
* const date4 = parseCustomDate("hello", "DD/MM/YYYY");
|
|
700
|
+
* console.log(date4); // ➔ null
|
|
701
|
+
*
|
|
702
|
+
* // Throws: wrong parameter types or empty-string
|
|
703
|
+
* parseCustomDate(123, "DD/MM/YYYY");
|
|
704
|
+
* // ➔ TypeError: Parameter `dateString` and `format` must be of type `string`...
|
|
705
|
+
*/
|
|
823
706
|
declare const parseCustomDate:(dateString:string,format:string)=>Date|null;
|
|
824
707
|
/** --------------------------------------------------
|
|
825
|
-
* * ***
|
|
826
|
-
*
|
|
827
|
-
*
|
|
828
|
-
* -
|
|
829
|
-
* - Always provide both `<TData, TInput>` for best results.
|
|
830
|
-
* - ***Scroll down for full generic behavior explanation.***
|
|
831
|
-
* -
|
|
832
|
-
* -
|
|
833
|
-
* -
|
|
834
|
-
* 1. `null` ➔ if input is explicitly `null`.
|
|
835
|
-
* 2. `undefined` ➔ if input is `undefined`, not a `string`, or if parsing fails.
|
|
836
|
-
* 3. Parsed and cleaned result (`TData`) ➔ if input is a valid JSON string.
|
|
837
|
-
*
|
|
838
|
-
*
|
|
839
|
-
*
|
|
840
|
-
*
|
|
841
|
-
*
|
|
842
|
-
*
|
|
843
|
-
*
|
|
844
|
-
*
|
|
845
|
-
*
|
|
846
|
-
*
|
|
847
|
-
*
|
|
848
|
-
*
|
|
849
|
-
*
|
|
850
|
-
*
|
|
851
|
-
*
|
|
852
|
-
*
|
|
853
|
-
*
|
|
854
|
-
*
|
|
855
|
-
*
|
|
856
|
-
*
|
|
857
|
-
*
|
|
858
|
-
*
|
|
859
|
-
*
|
|
860
|
-
* @template TData - The expected output type after parsing and cleaning.
|
|
861
|
-
* @template TInput - The input value type, used for advanced type inference and return typing.
|
|
862
|
-
*
|
|
863
|
-
* @param {
|
|
864
|
-
*
|
|
865
|
-
*
|
|
866
|
-
*
|
|
867
|
-
* @
|
|
868
|
-
*
|
|
869
|
-
*
|
|
870
|
-
*
|
|
871
|
-
*
|
|
872
|
-
*
|
|
873
|
-
*
|
|
874
|
-
*
|
|
875
|
-
* // result ➔
|
|
876
|
-
*
|
|
877
|
-
*
|
|
878
|
-
*
|
|
879
|
-
*
|
|
880
|
-
*
|
|
881
|
-
*
|
|
882
|
-
*
|
|
883
|
-
*
|
|
884
|
-
*
|
|
885
|
-
*
|
|
886
|
-
*
|
|
887
|
-
*
|
|
888
|
-
*
|
|
889
|
-
*
|
|
890
|
-
*
|
|
891
|
-
*
|
|
892
|
-
*
|
|
893
|
-
*
|
|
894
|
-
*
|
|
895
|
-
*
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
*
|
|
899
|
-
* //
|
|
900
|
-
*
|
|
901
|
-
* const
|
|
902
|
-
*
|
|
903
|
-
*
|
|
904
|
-
*
|
|
905
|
-
*
|
|
906
|
-
*
|
|
907
|
-
*
|
|
908
|
-
*
|
|
909
|
-
*
|
|
910
|
-
*
|
|
911
|
-
*
|
|
912
|
-
*
|
|
913
|
-
*
|
|
914
|
-
*
|
|
915
|
-
*
|
|
916
|
-
*
|
|
917
|
-
* }
|
|
918
|
-
*
|
|
919
|
-
*
|
|
920
|
-
*
|
|
921
|
-
*
|
|
922
|
-
*
|
|
923
|
-
*
|
|
924
|
-
*
|
|
925
|
-
*
|
|
926
|
-
*
|
|
927
|
-
*
|
|
928
|
-
*
|
|
929
|
-
*
|
|
930
|
-
*
|
|
931
|
-
*
|
|
932
|
-
*
|
|
933
|
-
*
|
|
934
|
-
*
|
|
935
|
-
*
|
|
936
|
-
*
|
|
937
|
-
*
|
|
938
|
-
*
|
|
939
|
-
*
|
|
940
|
-
*
|
|
941
|
-
*
|
|
942
|
-
*
|
|
943
|
-
* ```
|
|
944
|
-
*
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
*
|
|
949
|
-
*
|
|
950
|
-
*
|
|
951
|
-
*
|
|
952
|
-
*
|
|
953
|
-
* const
|
|
954
|
-
*
|
|
955
|
-
*
|
|
956
|
-
*
|
|
957
|
-
*
|
|
958
|
-
*
|
|
959
|
-
*
|
|
960
|
-
|
|
961
|
-
*
|
|
962
|
-
* //-
|
|
963
|
-
*
|
|
964
|
-
*
|
|
965
|
-
*
|
|
966
|
-
* //-
|
|
967
|
-
*
|
|
968
|
-
|
|
969
|
-
*
|
|
970
|
-
* //-
|
|
971
|
-
*
|
|
972
|
-
*
|
|
973
|
-
* //-
|
|
974
|
-
*
|
|
975
|
-
*
|
|
976
|
-
* //-
|
|
977
|
-
*
|
|
978
|
-
*
|
|
979
|
-
*
|
|
980
|
-
*
|
|
981
|
-
*
|
|
982
|
-
*
|
|
983
|
-
*
|
|
984
|
-
*
|
|
985
|
-
* -
|
|
986
|
-
|
|
987
|
-
* - To ensure correct return typing, **always pass both generics** when `value` is dynamic,
|
|
988
|
-
* nullable, or unioned: `safeJsonParse<TData, typeof value>(value)`.
|
|
989
|
-
* - This makes the returned type exactly match your expectation: `TData | null | undefined`.
|
|
990
|
-
*/
|
|
708
|
+
* * ***Utility: `safeJsonParse`.***
|
|
709
|
+
* ---------------------------------------------
|
|
710
|
+
* **Safely parses JSON while handling errors and applying transformations.**
|
|
711
|
+
* - **Supports generics** to ensure accurate return type inference.
|
|
712
|
+
* - Always provide both `<TData, TInput>` for best results.
|
|
713
|
+
* - ℹ️ ***Scroll down for full generic behavior explanation.***
|
|
714
|
+
* - Automatically parses valid JSON strings into `objects`, `arrays`, `numbers`, etc.
|
|
715
|
+
* - Supports data transformation via options (e.g., convert strings to `numbers`, `booleans`, or `dates`).
|
|
716
|
+
* - **Returns:**
|
|
717
|
+
* 1. `null` ➔ if input is explicitly `null`.
|
|
718
|
+
* 2. `undefined` ➔ if input is `undefined`, not a `string`, or if parsing fails.
|
|
719
|
+
* 3. Parsed and cleaned result (`TData`) ➔ if input is a valid JSON string.
|
|
720
|
+
* - ⚠️ **JSON.stringify note**:
|
|
721
|
+
* - _If the input JSON string was created using `JSON.stringify()`, any properties with `undefined`
|
|
722
|
+
* values would have been automatically removed or converted to `null` depending on the serializer, example:_
|
|
723
|
+
* ```ts
|
|
724
|
+
* JSON.stringify({ a: undefined, b: 1 }); // ➔ '{"b":1}'
|
|
725
|
+
* JSON.parse('{"a": undefined, "b": 1}') // ❌ invalid JSON
|
|
726
|
+
* ```
|
|
727
|
+
* _Therefore, if you see `undefined` in raw input, it will likely throw unless pre-cleaned or replaced with `null`._
|
|
728
|
+
*
|
|
729
|
+
* ```ts
|
|
730
|
+
* safeJsonParse('{"name": "John", "score": undefined}');
|
|
731
|
+
* // result ➔ { name: "John", score: null } <- because `undefined` is not valid JSON, gets replaced to null.
|
|
732
|
+
* ```
|
|
733
|
+
* - ℹ️ **Additionally:**
|
|
734
|
+
* - This function normalizes single quotes (`'`) to double quotes (`"`) before parsing,
|
|
735
|
+
* so JSON strings using single quotes will be converted to valid JSON format, example:
|
|
736
|
+
* ```ts
|
|
737
|
+
* safeJsonParse("{'name': 'John', 'age': 30}");
|
|
738
|
+
* // result ➔ { name: "John", age: 30 }
|
|
739
|
+
*
|
|
740
|
+
* safeJsonParse("{'string\\'s': 'abc', \"quote's\": 'It\\'s awesome!', 'aNumber\\'s': 123, 'keyWith\\'Backslash\\'s': 'value\\'s'}");
|
|
741
|
+
* // result ➔ { "string's": "abc", "quote's": "It's awesome!", "aNumber's": 123, "keyWith'Backslash's": "value's" }
|
|
742
|
+
* ```
|
|
743
|
+
* @template TData - The expected output type after parsing and cleaning.
|
|
744
|
+
* @template TInput - The input value type, used for advanced type inference and return typing.
|
|
745
|
+
* @param {TInput} [value] - The JSON string or value to parse.
|
|
746
|
+
* @param {ParseParsedDataOptions} [options] - Options to clean, convert types, enable strict mode,
|
|
747
|
+
* support custom date formats, enable logging, or handle errors via callback.
|
|
748
|
+
* @returns {SafeJsonParseResult<TData, TInput>} Parsed and optionally cleaned result, or `null`/`undefined`.
|
|
749
|
+
* @throws {TypeError} If `options` is provided but not a valid object.
|
|
750
|
+
* @example
|
|
751
|
+
* 1. ***Basic parse with number & boolean conversion:***
|
|
752
|
+
* ```ts
|
|
753
|
+
* const result = safeJsonParse(30);
|
|
754
|
+
* // result ➔ undefined
|
|
755
|
+
* const result = safeJsonParse(30, {
|
|
756
|
+
* convertNumbers: true
|
|
757
|
+
* });
|
|
758
|
+
* // result ➔ 30
|
|
759
|
+
*
|
|
760
|
+
* const result = safeJsonParse('{"age": "30", "isActive": "true"}', {
|
|
761
|
+
* convertNumbers: true,
|
|
762
|
+
* convertBooleans: true
|
|
763
|
+
* });
|
|
764
|
+
* // result ➔ { age: 30, isActive: true }
|
|
765
|
+
* ```
|
|
766
|
+
* 2. ***Handling `undefined` in input string (manually written, not JSON.stringify):***
|
|
767
|
+
* ```ts
|
|
768
|
+
* const result = safeJsonParse('{"score": undefined}');
|
|
769
|
+
* // result ➔ { score: null } <- because `undefined` is not valid JSON, gets replaced
|
|
770
|
+
* ```
|
|
771
|
+
*
|
|
772
|
+
* 3. ***Handling `NaN` in input string (manually written, not JSON.stringify):***
|
|
773
|
+
* ```ts
|
|
774
|
+
* const value = NaN; // <- value is NaN or "NaN";
|
|
775
|
+
* const result = safeJsonParse(value);
|
|
776
|
+
* // result ➔ undefined <- will return as undefined, because options `convertNaN` is false (default),
|
|
777
|
+
* const result2 = safeJsonParse(value, { convertNaN: true });
|
|
778
|
+
* // result2 ➔ NaN <- will return as undefined because options `convertNaN` is false,
|
|
779
|
+
*
|
|
780
|
+
* const result4 = safeJsonParse('{"strNan": "NaN", "pureNan": NaN}');
|
|
781
|
+
* // NaN will convert to string (NaN ➔ "NaN") because options `convertNaN` is false (default),
|
|
782
|
+
* // result4 ➔ { strNan: "NaN", pureNan: "NaN" }
|
|
783
|
+
*
|
|
784
|
+
* const result3 = safeJsonParse('{"strNan": "NaN", "pureNan": NaN}', {
|
|
785
|
+
* convertNaN: true
|
|
786
|
+
* });
|
|
787
|
+
* // String "NaN" will convert to NaN ("NaN" ➔ NaN) because options `convertNaN` is true,
|
|
788
|
+
* // result3 ➔ { strNan: NaN, pureNan: NaN }
|
|
789
|
+
* ```
|
|
790
|
+
*
|
|
791
|
+
* 4. ***Strict mode (removes invalid values):***
|
|
792
|
+
* ```ts
|
|
793
|
+
* const result = safeJsonParse('{"name": " ", "score": "99abc"}', {
|
|
794
|
+
* convertNumbers: true,
|
|
795
|
+
* strictMode: true
|
|
796
|
+
* });
|
|
797
|
+
* // result ➔ {}
|
|
798
|
+
*
|
|
799
|
+
* const result2 = safeJsonParse('{"name": " ", "score": undefined}');
|
|
800
|
+
* // result2 ➔ { name: "",score: null }
|
|
801
|
+
* ```
|
|
802
|
+
*
|
|
803
|
+
* 5. ***Custom date format parsing:***
|
|
804
|
+
* ```ts
|
|
805
|
+
* const result = safeJsonParse('{"birthday": "25/12/2000"}', {
|
|
806
|
+
* convertDates: true,
|
|
807
|
+
* customDateFormats: ["DD/MM/YYYY"]
|
|
808
|
+
* });
|
|
809
|
+
* // result ➔ { birthday: new Date("2000-12-25T00:00:00.000Z") }
|
|
810
|
+
* ```
|
|
811
|
+
*
|
|
812
|
+
* 6. ***Invalid JSON with custom error handling:***
|
|
813
|
+
* ```ts
|
|
814
|
+
* safeJsonParse("{invalid}", {
|
|
815
|
+
* loggingOnFail: true,
|
|
816
|
+
* onError: (err) => console.log("Custom handler:", err.message)
|
|
817
|
+
* });
|
|
818
|
+
* // ➔ Logs parsing error and invokes handler
|
|
819
|
+
* ```
|
|
820
|
+
*
|
|
821
|
+
* 7. ***Null or non-string input returns null/undefined (default options):***
|
|
822
|
+
* ```ts
|
|
823
|
+
* safeJsonParse(123); // ➔ undefined
|
|
824
|
+
* safeJsonParse(null); // ➔ null
|
|
825
|
+
* safeJsonParse(undefined); // ➔ undefined
|
|
826
|
+
* ```
|
|
827
|
+
*
|
|
828
|
+
* 8. ***Generic usage: Provide both output and input type to ensure correct return typing:***
|
|
829
|
+
* ```ts
|
|
830
|
+
* type UserType = { name: string };
|
|
831
|
+
*
|
|
832
|
+
* const obj = JSON.stringify({
|
|
833
|
+
* name: "John"
|
|
834
|
+
* });
|
|
835
|
+
*
|
|
836
|
+
* const toParse = isAuth() ? obj : null;
|
|
837
|
+
* const toParse2 = isAuth() ? obj : undefined;
|
|
838
|
+
*
|
|
839
|
+
* // * `Without Generic`:
|
|
840
|
+
* const parsed = safeJsonParse(toParse);
|
|
841
|
+
* //- runtime: { name: "John" } | undefined | null
|
|
842
|
+
* //- type: Record<string, unknown> | undefined | null
|
|
843
|
+
* const parsed2 = safeJsonParse(toParse);
|
|
844
|
+
* //- runtime: { name: "John" } | undefined
|
|
845
|
+
* //- type: Record<string, unknown> | undefined
|
|
846
|
+
*
|
|
847
|
+
* // * `With Generic`:
|
|
848
|
+
* const parsed = safeJsonParse<UserType>(toParse);
|
|
849
|
+
* //- runtime: { name: "John" } | undefined | null
|
|
850
|
+
* //- type: undefined <- (⚠️ unexpected!)
|
|
851
|
+
* const parsed2 = safeJsonParse<UserType>(toParse);
|
|
852
|
+
* //- runtime: { name: "John" } | undefined
|
|
853
|
+
* //- type: undefined <- (⚠️ unexpected!)
|
|
854
|
+
* const parsed = safeJsonParse<UserType, typeof toParse>(toParse);
|
|
855
|
+
* //- runtime: { name: "John" } | null | undefined
|
|
856
|
+
* //- type: UserType | null | undefined
|
|
857
|
+
* const parsed2 = safeJsonParse<UserType, typeof toParse>(toParse);
|
|
858
|
+
* //- runtime: { name: "John" } | undefined
|
|
859
|
+
* //- type: UserType | undefined
|
|
860
|
+
* ```
|
|
861
|
+
* @note
|
|
862
|
+
* ⚠️ **Generic Behavior:**
|
|
863
|
+
* - This function supports advanced generic inference for clean, type-safe return values.
|
|
864
|
+
* - If only the first generic (`TData`) is provided and the second (`TInput`) is omitted,
|
|
865
|
+
* then `TInput` defaults to `undefined`, resulting in a return type of `undefined`.
|
|
866
|
+
* - To ensure correct return typing, **always pass both generics** when `value` is dynamic,
|
|
867
|
+
* nullable, or unioned: `safeJsonParse<TData, typeof value>(value)`.
|
|
868
|
+
* - This makes the returned type exactly match your expectation: `TData | null | undefined`.
|
|
869
|
+
*/
|
|
991
870
|
declare function safeJsonParse<TData extends Record<string,any>=Record<string,unknown>,TInput extends UnknownValue=UnknownValue>(value:TInput,options?:ParseParsedDataOptions):IsAny<TInput>extends true?TData|null|undefined:undefined;declare function safeJsonParse<TData extends Record<string,any>=Record<string,unknown>,TInput extends string|null|undefined|unknown=undefined>(value:TInput,options?:ParseParsedDataOptions):SafeJsonParseResult<TData,TInput>;
|
|
992
871
|
/** ----------------------------------------------------------
|
|
993
|
-
* * ***
|
|
994
|
-
*
|
|
995
|
-
*
|
|
996
|
-
*
|
|
997
|
-
* that are not digits (`0-9`).
|
|
998
|
-
*
|
|
999
|
-
*
|
|
1000
|
-
*
|
|
1001
|
-
*
|
|
1002
|
-
*
|
|
1003
|
-
*
|
|
1004
|
-
*
|
|
1005
|
-
*
|
|
1006
|
-
*
|
|
1007
|
-
*
|
|
1008
|
-
*
|
|
1009
|
-
*
|
|
1010
|
-
*
|
|
1011
|
-
*
|
|
1012
|
-
*
|
|
1013
|
-
* extractDigits(
|
|
1014
|
-
* extractDigits(
|
|
1015
|
-
* extractDigits(
|
|
1016
|
-
* extractDigits(
|
|
1017
|
-
* extractDigits(
|
|
1018
|
-
* extractDigits(
|
|
1019
|
-
* extractDigits(
|
|
1020
|
-
* extractDigits(
|
|
1021
|
-
* extractDigits(
|
|
1022
|
-
|
|
1023
|
-
* extractDigits([]); // ➔ 0
|
|
1024
|
-
* extractDigits("abc"); // ➔ 0
|
|
1025
|
-
* extractDigits(" 00a "); // ➔ 0
|
|
1026
|
-
*/
|
|
872
|
+
* * ***Utility: `extractDigits`.***
|
|
873
|
+
* ---------------------------------------------
|
|
874
|
+
* **Extracts digits from a string or number input.**
|
|
875
|
+
* - **Behavior:**
|
|
876
|
+
* - Converts the input to a string, trims whitespace, and removes any characters that are not digits (`0-9`).
|
|
877
|
+
* - Returns the cleaned numeric value as a `number`.
|
|
878
|
+
* - If the input is a `null`, `undefined`, results in no digits, or not a `string` (or empty-string) or `number`, it safely return `0`.
|
|
879
|
+
* @param {*} [value]
|
|
880
|
+
* The value to process.
|
|
881
|
+
* - Accepts a string, number, `null`, or `undefined`.
|
|
882
|
+
* @returns {number}
|
|
883
|
+
* - The numeric value after extracting digits.
|
|
884
|
+
* - Returns `0` if input is invalid or contains no digits.
|
|
885
|
+
* @example
|
|
886
|
+
* extractDigits(12345); // ➔ 12345
|
|
887
|
+
* extractDigits("9A8B7C6X1"); // ➔ 98761
|
|
888
|
+
* extractDigits("123abc456"); // ➔ 123456
|
|
889
|
+
* extractDigits("$1,234.56"); // ➔ 123456
|
|
890
|
+
* extractDigits(NaN); // ➔ 0
|
|
891
|
+
* extractDigits(null); // ➔ 0
|
|
892
|
+
* extractDigits(undefined); // ➔ 0
|
|
893
|
+
* extractDigits(Infinity); // ➔ 0
|
|
894
|
+
* extractDigits(-Infinity); // ➔ 0
|
|
895
|
+
* extractDigits({}); // ➔ 0
|
|
896
|
+
* extractDigits([]); // ➔ 0
|
|
897
|
+
* extractDigits(""); // ➔ 0
|
|
898
|
+
* extractDigits(" "); // ➔ 0
|
|
899
|
+
* extractDigits("abc"); // ➔ 0
|
|
900
|
+
* extractDigits(" 00a "); // ➔ 0
|
|
901
|
+
*/
|
|
1027
902
|
declare const extractDigits:(value:unknown)=>number;type Prev=[never,NumberRangeUnion<1,30>];type DotPath<T,Prefix extends string="",Depth extends number=NumberRangeUnion<1,30>>=Depth extends never?never:T extends(infer U)[]?U extends object?DotPath<U,`${Prefix}`,Prev[Depth]>:never:T extends object?{[K in Extract<keyof T,string>]:T[K] extends object?DotPath<T[K],`${Prefix}${K}.`,Prev[Depth]>|`${Prefix}${K}`:`${Prefix}${K}`;}[Extract<keyof T,string>]:never;type ConfigRemoveObjectPaths<T>={
|
|
1028
|
-
/**
|
|
1029
|
-
*
|
|
1030
|
-
*
|
|
1031
|
-
*
|
|
1032
|
-
*
|
|
1033
|
-
*
|
|
1034
|
-
*
|
|
1035
|
-
*
|
|
1036
|
-
*
|
|
1037
|
-
*
|
|
1038
|
-
*
|
|
1039
|
-
*
|
|
1040
|
-
*
|
|
1041
|
-
*
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
1044
|
-
*
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
1049
|
-
* //
|
|
1050
|
-
|
|
1051
|
-
* // right: { data: { keep: "yes" } },
|
|
1052
|
-
* // };
|
|
1053
|
-
*/
|
|
903
|
+
/** The dot-notation path to the property that should be removed.
|
|
904
|
+
* Can target deeply nested properties (e.g., `"left.data.sensitive"`).
|
|
905
|
+
*
|
|
906
|
+
* This is resolved relative to the root object `T`, and supports
|
|
907
|
+
* any valid **{@link DotPath | `DotPath`}** path within it.
|
|
908
|
+
* @type {DotPath<T>}
|
|
909
|
+
* @example
|
|
910
|
+
* const obj = {
|
|
911
|
+
* left: { data: { sensitive: "secret", id: 1 } },
|
|
912
|
+
* right: { data: { debug: true, keep: "yes" } },
|
|
913
|
+
* };
|
|
914
|
+
*
|
|
915
|
+
* // Removes "left.data.sensitive" and "right.data.debug"
|
|
916
|
+
* const result = removeObjectPaths(obj, [
|
|
917
|
+
* { key: "left.data.sensitive" },
|
|
918
|
+
* { key: "right.data.debug" },
|
|
919
|
+
* ]);
|
|
920
|
+
* console.log(result);
|
|
921
|
+
* // {
|
|
922
|
+
* // left: { data: { id: 1 } },
|
|
923
|
+
* // right: { data: { keep: "yes" } },
|
|
924
|
+
* // };
|
|
925
|
+
*/
|
|
1054
926
|
key:DotPath<T>;
|
|
1055
|
-
/**
|
|
1056
|
-
*
|
|
1057
|
-
*
|
|
1058
|
-
*
|
|
1059
|
-
*
|
|
1060
|
-
*
|
|
1061
|
-
*
|
|
1062
|
-
*
|
|
1063
|
-
*
|
|
1064
|
-
*
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1067
|
-
*
|
|
1068
|
-
*
|
|
1069
|
-
*
|
|
1070
|
-
*
|
|
1071
|
-
* };
|
|
1072
|
-
*
|
|
1073
|
-
* //
|
|
1074
|
-
*
|
|
1075
|
-
*
|
|
1076
|
-
* // {
|
|
1077
|
-
* //
|
|
1078
|
-
* //
|
|
1079
|
-
* //
|
|
1080
|
-
|
|
1081
|
-
* // ]
|
|
1082
|
-
* // };
|
|
1083
|
-
*/
|
|
927
|
+
/** When `true`, removes the specified property from **all matching nested levels**,
|
|
928
|
+
* including occurrences inside arrays, defaults to `false` for single-level removal.
|
|
929
|
+
*
|
|
930
|
+
* Useful if the target property might appear multiple times across different
|
|
931
|
+
* branches or array elements.
|
|
932
|
+
* @default false
|
|
933
|
+
* @example
|
|
934
|
+
* const obj = {
|
|
935
|
+
* items: [
|
|
936
|
+
* { data: { sensitive: "one", keep: true } },
|
|
937
|
+
* { data: { sensitive: "two", keep: true } },
|
|
938
|
+
* { other: { sensitive: "other" } },
|
|
939
|
+
* ]
|
|
940
|
+
* };
|
|
941
|
+
*
|
|
942
|
+
* // Removes all "data.sensitive" occurrences inside items[]
|
|
943
|
+
* const result = removeObjectPaths(obj, [{ key: "items.data.sensitive", deep: true }]);
|
|
944
|
+
* console.log(result);
|
|
945
|
+
* // {
|
|
946
|
+
* // items: [
|
|
947
|
+
* // { data: { keep: true } },
|
|
948
|
+
* // { data: { keep: true } },
|
|
949
|
+
* // { other: { sensitive: "other" } },
|
|
950
|
+
* // ]
|
|
951
|
+
* // };
|
|
952
|
+
*/
|
|
1084
953
|
deep?:boolean;};type KeysToRemove<T,K extends readonly ConfigRemoveObjectPaths<T>[]>=K[number] extends{key:infer Key;}?(Key extends string?Key:never):never;type RemoveNested<T,K extends string>=T extends Array<infer U>?RemoveNested<U,K>[]:T extends object?K extends`${infer Head}.${infer Rest}`?Head extends keyof T?{[P in keyof T]:P extends Head?RemoveNested<T[P],Rest>:T[P];}:T:SafeRemove<T,K>:T;type SafeRemove<T,K extends string>=K extends keyof T?Omit<T,K>:T;type ChangeNeverArrayToArrayDeep<T>=T extends never[]?[]:T extends Array<infer U>?ChangeNeverArrayToArrayDeep<U>[]:T extends object?{[K in keyof T]:ChangeNeverArrayToArrayDeep<T[K]>;}:T;type ResultRemoveObjectPaths<T,K extends readonly ConfigRemoveObjectPaths<T>[]>=Prettify<RemoveNested<ChangeNeverArrayToArrayDeep<T>,KeysToRemove<T,K>>,{recursive:true;}>extends never?T:Prettify<RemoveNested<ChangeNeverArrayToArrayDeep<T>,KeysToRemove<T,K>>,{recursive:true;}>;
|
|
1085
954
|
/** ------------------------------------------------------------------------
|
|
1086
|
-
* * ***
|
|
1087
|
-
* ------------------------------------------------------------------------
|
|
1088
|
-
*
|
|
1089
|
-
* - Features
|
|
1090
|
-
* - Removes one or more keys from an object based on their paths (supports dot notation for nested properties).
|
|
1091
|
-
* - Can delete deeply from all matching nested levels (even inside arrays) when `deep: true`.
|
|
1092
|
-
* - By default does **not mutate** the original object. Clones it first.
|
|
1093
|
-
* Set `deepClone = false` to mutate in place (useful for performance on large data).
|
|
1094
|
-
* - Ensures type safety on `key` paths via `DotPath<T>`, reducing accidental invalid paths.
|
|
1095
|
-
*
|
|
1096
|
-
*
|
|
1097
|
-
* - When `deep:
|
|
1098
|
-
*
|
|
1099
|
-
*
|
|
1100
|
-
*
|
|
1101
|
-
*
|
|
1102
|
-
*
|
|
1103
|
-
* -
|
|
1104
|
-
*
|
|
1105
|
-
*
|
|
1106
|
-
*
|
|
1107
|
-
*
|
|
1108
|
-
*
|
|
1109
|
-
*
|
|
1110
|
-
* @param {
|
|
1111
|
-
*
|
|
1112
|
-
* - `
|
|
1113
|
-
* - `
|
|
1114
|
-
* @
|
|
1115
|
-
*
|
|
1116
|
-
* -
|
|
1117
|
-
*
|
|
1118
|
-
*
|
|
1119
|
-
* @
|
|
1120
|
-
*
|
|
1121
|
-
|
|
1122
|
-
*
|
|
1123
|
-
*
|
|
1124
|
-
*
|
|
1125
|
-
*
|
|
1126
|
-
*
|
|
1127
|
-
* //
|
|
1128
|
-
* removeObjectPaths(
|
|
1129
|
-
* {
|
|
1130
|
-
* [{ key: "
|
|
1131
|
-
* );
|
|
1132
|
-
* // ➔ {
|
|
1133
|
-
*
|
|
1134
|
-
*
|
|
1135
|
-
*
|
|
1136
|
-
*
|
|
1137
|
-
* {
|
|
1138
|
-
*
|
|
1139
|
-
*
|
|
1140
|
-
*
|
|
1141
|
-
*
|
|
1142
|
-
*
|
|
1143
|
-
*
|
|
1144
|
-
*
|
|
1145
|
-
*
|
|
1146
|
-
*
|
|
1147
|
-
* );
|
|
1148
|
-
* // ➔ {
|
|
1149
|
-
*
|
|
1150
|
-
*
|
|
1151
|
-
*
|
|
1152
|
-
*
|
|
1153
|
-
*
|
|
1154
|
-
*
|
|
1155
|
-
*
|
|
1156
|
-
*
|
|
1157
|
-
|
|
1158
|
-
* removeObjectPaths({}, [{ key: "a" }]);
|
|
1159
|
-
* // ➔ {}
|
|
1160
|
-
*
|
|
1161
|
-
* @example
|
|
1162
|
-
* // 🚫 Invalid usage — `keysToDelete` is not an array
|
|
1163
|
-
* removeObjectPaths({}, "a");
|
|
1164
|
-
* // ➔ throws TypeError
|
|
1165
|
-
*
|
|
1166
|
-
* @example
|
|
1167
|
-
* // 🚫 Invalid usage — missing `key` property in array element
|
|
1168
|
-
* removeObjectPaths({}, [{ deep: true }]);
|
|
1169
|
-
* // ➔ throws TypeError
|
|
1170
|
-
*/
|
|
955
|
+
* * ***Utility: `removeObjectPaths`.***
|
|
956
|
+
* ------------------------------------------------------------------------
|
|
957
|
+
* **Deletes multiple keys (shallow or deeply nested) from an object.**
|
|
958
|
+
* - **Features:**
|
|
959
|
+
* - Removes one or more keys from an object based on their paths (supports dot notation for nested properties).
|
|
960
|
+
* - Can delete deeply from all matching nested levels (even inside arrays) when `deep: true`.
|
|
961
|
+
* - By default does **not mutate** the original object. Clones it first.
|
|
962
|
+
* Set `deepClone = false` to mutate in place (useful for performance on large data).
|
|
963
|
+
* - Ensures type safety on `key` paths via `DotPath<T>`, reducing accidental invalid paths.
|
|
964
|
+
* - **Behavior:**
|
|
965
|
+
* - When `deep: false` (default), only deletes the direct property at the specified path.
|
|
966
|
+
* - When `deep: true`, searches deeply and recursively deletes the key from all levels,
|
|
967
|
+
* including inside arrays of objects (applies the *same* path repeatedly).
|
|
968
|
+
* - Skips deletion if the specified path does not exist — no error is thrown.
|
|
969
|
+
* - **Edge Handling:**
|
|
970
|
+
* - If `object` is `null` or not an object, returns an empty object.
|
|
971
|
+
* - If `keysToDelete` is not an array of `{ key, deep? }` objects, throws a `TypeError`.
|
|
972
|
+
* - Ignores invalid intermediate paths (will skip those branches without throwing).
|
|
973
|
+
* @template T - The shape of the input object, used for type-safe dot paths.
|
|
974
|
+
* @param {Record<string, unknown>} object - The object to remove keys from. Must be an object or will return `{}`.
|
|
975
|
+
* @param {ConfigRemoveObjectPaths<T>[]} keysToDelete
|
|
976
|
+
* An array of instructions:
|
|
977
|
+
* - `key`: A string path using dot notation (e.g. `"user.profile.name"`).
|
|
978
|
+
* - `deep`: If `true`, will recursively remove all instances of the key path at any depth, defaultValue: `false`.
|
|
979
|
+
* @param {boolean|undefined} [deepClone=true]
|
|
980
|
+
* Whether to deep clone the original object before modifying.
|
|
981
|
+
* - `true` (default): returns a *new object* with the specified keys removed.
|
|
982
|
+
* - `false`: modifies the original object in place and returns it.
|
|
983
|
+
* @returns {Partial<T>}
|
|
984
|
+
* - A new object with specified keys removed if `deepClone` is `true`.
|
|
985
|
+
* - The *same mutated object* if `deepClone` is `false`.
|
|
986
|
+
* @throws {TypeError}
|
|
987
|
+
* - If `keysToDelete` is not an array of `{ key, deep? }` objects.
|
|
988
|
+
* @example
|
|
989
|
+
* // Shallow deletion
|
|
990
|
+
* removeObjectPaths(
|
|
991
|
+
* { a: 1, b: 2, c: { d: 3 } },
|
|
992
|
+
* [{ key: "b" }]
|
|
993
|
+
* );
|
|
994
|
+
* // ➔ { a: 1, c: { d: 3 } }
|
|
995
|
+
*
|
|
996
|
+
* // Nested deletion (shallow, removes only exact path)
|
|
997
|
+
* removeObjectPaths(
|
|
998
|
+
* { user: { profile: { name: "Alice", age: 30 } } },
|
|
999
|
+
* [{ key: "user.profile.age" }]
|
|
1000
|
+
* );
|
|
1001
|
+
* // ➔ { user: { profile: { name: "Alice" } } }
|
|
1002
|
+
*
|
|
1003
|
+
* // Deep deletion (recursively removes key from all levels and arrays)
|
|
1004
|
+
* removeObjectPaths(
|
|
1005
|
+
* { items: [{ price: 10 }, { price: 20, details: { price: 30 } }] },
|
|
1006
|
+
* [{ key: "price", deep: true }]
|
|
1007
|
+
* );
|
|
1008
|
+
* // ➔ { items: [{}, { details: {} }] }
|
|
1009
|
+
*
|
|
1010
|
+
* // Without cloning: mutates original object
|
|
1011
|
+
* const obj = { x: 1, y: 2 };
|
|
1012
|
+
* removeObjectPaths(obj, [{ key: "y" }], false);
|
|
1013
|
+
* console.log(obj); // ➔ { x: 1 }
|
|
1014
|
+
*
|
|
1015
|
+
* // No matching path — returns unchanged object
|
|
1016
|
+
* removeObjectPaths({}, [{ key: "a" }]);
|
|
1017
|
+
* // ➔ {}
|
|
1018
|
+
*
|
|
1019
|
+
* // 🚫 Invalid usage — `keysToDelete` is not an array
|
|
1020
|
+
* removeObjectPaths({}, "a");
|
|
1021
|
+
* // ➔ throws TypeError
|
|
1022
|
+
*
|
|
1023
|
+
* // 🚫 Invalid usage — missing `key` property in array element
|
|
1024
|
+
* removeObjectPaths({}, [{ deep: true }]);
|
|
1025
|
+
* // ➔ throws TypeError
|
|
1026
|
+
*/
|
|
1171
1027
|
declare function removeObjectPaths<T extends Record<string,unknown>,K extends ConfigRemoveObjectPaths<T>[]>(object:T,keysToDelete:K,deepClone?:boolean):ResultRemoveObjectPaths<T,K>;
|
|
1172
1028
|
/** -------------------------------------------------
|
|
1173
|
-
* * ***Options for `safeStableStringify
|
|
1174
|
-
* -------------------------------------------------
|
|
1175
|
-
*/
|
|
1029
|
+
* * ***Options for **{@link safeStableStringify | `safeStableStringify`}**.***
|
|
1030
|
+
* -------------------------------------------------
|
|
1031
|
+
*/
|
|
1176
1032
|
type SafeStableStringifyOptions={
|
|
1177
1033
|
/** Whether to sort **object keys** alphabetically (recursively).
|
|
1178
|
-
*
|
|
1179
|
-
* - `true` (default): object keys are sorted to ensure stable output.
|
|
1180
|
-
* - `false`: preserves original insertion order of keys.
|
|
1181
|
-
*
|
|
1182
|
-
* @default true
|
|
1183
|
-
*/
|
|
1034
|
+
*
|
|
1035
|
+
* - `true` (default): object keys are sorted to ensure stable output.
|
|
1036
|
+
* - `false`: preserves original insertion order of keys.
|
|
1037
|
+
*
|
|
1038
|
+
* @default true
|
|
1039
|
+
*/
|
|
1184
1040
|
sortKeys?:boolean;
|
|
1185
1041
|
/** Whether to sort **primitive values inside arrays**.
|
|
1186
|
-
*
|
|
1187
|
-
* - `true`: primitive values in arrays are sorted to ensure stable output.
|
|
1188
|
-
* - `false` (default): arrays retain their original order; objects and nested arrays are not reordered.
|
|
1189
|
-
*
|
|
1190
|
-
* @default false
|
|
1191
|
-
*/
|
|
1042
|
+
*
|
|
1043
|
+
* - `true`: primitive values in arrays are sorted to ensure stable output.
|
|
1044
|
+
* - `false` (default): arrays retain their original order; objects and nested arrays are not reordered.
|
|
1045
|
+
*
|
|
1046
|
+
* @default false
|
|
1047
|
+
*/
|
|
1192
1048
|
sortArray?:boolean;
|
|
1193
1049
|
/** Whether to pretty-print JSON output with 2-space indentation.
|
|
1194
|
-
*
|
|
1195
|
-
* - `true`: output is formatted with indentation and newlines.
|
|
1196
|
-
* - `false` (default): produces compact single-line JSON.
|
|
1197
|
-
*
|
|
1198
|
-
* @default false
|
|
1199
|
-
*/
|
|
1050
|
+
*
|
|
1051
|
+
* - `true`: output is formatted with indentation and newlines.
|
|
1052
|
+
* - `false` (default): produces compact single-line JSON.
|
|
1053
|
+
*
|
|
1054
|
+
* @default false
|
|
1055
|
+
*/
|
|
1200
1056
|
pretty?:boolean;};
|
|
1201
1057
|
/** --------------------------------------------
|
|
1202
|
-
* * ***
|
|
1203
|
-
*
|
|
1204
|
-
*
|
|
1205
|
-
* This function is an enhanced version of `JSON.stringify` with additional guarantees
|
|
1206
|
-
*
|
|
1207
|
-
*
|
|
1208
|
-
*
|
|
1209
|
-
*
|
|
1210
|
-
*
|
|
1211
|
-
*
|
|
1212
|
-
*
|
|
1213
|
-
*
|
|
1214
|
-
*
|
|
1215
|
-
*
|
|
1216
|
-
*
|
|
1217
|
-
*
|
|
1218
|
-
*
|
|
1219
|
-
*
|
|
1220
|
-
*
|
|
1221
|
-
*
|
|
1222
|
-
*
|
|
1223
|
-
*
|
|
1224
|
-
*
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
1227
|
-
*
|
|
1228
|
-
*
|
|
1229
|
-
*
|
|
1230
|
-
*
|
|
1231
|
-
*
|
|
1232
|
-
*
|
|
1233
|
-
*
|
|
1234
|
-
* -
|
|
1235
|
-
* -
|
|
1236
|
-
* -
|
|
1237
|
-
*
|
|
1238
|
-
*
|
|
1239
|
-
*
|
|
1240
|
-
*
|
|
1241
|
-
* -
|
|
1242
|
-
*
|
|
1243
|
-
*
|
|
1244
|
-
*
|
|
1245
|
-
*
|
|
1246
|
-
* @
|
|
1247
|
-
*
|
|
1248
|
-
*
|
|
1249
|
-
*
|
|
1250
|
-
*
|
|
1251
|
-
*
|
|
1252
|
-
*
|
|
1253
|
-
*
|
|
1254
|
-
*
|
|
1255
|
-
*
|
|
1256
|
-
* // ➔ '{"
|
|
1257
|
-
*
|
|
1258
|
-
* //
|
|
1259
|
-
* safeStableStringify(
|
|
1260
|
-
*
|
|
1261
|
-
* });
|
|
1262
|
-
* // ➔ '
|
|
1263
|
-
*
|
|
1264
|
-
* //
|
|
1265
|
-
* safeStableStringify([3, 1, 2], {
|
|
1266
|
-
*
|
|
1267
|
-
*
|
|
1268
|
-
*
|
|
1269
|
-
*
|
|
1270
|
-
*
|
|
1271
|
-
*
|
|
1272
|
-
*
|
|
1273
|
-
*
|
|
1274
|
-
*
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1277
|
-
*
|
|
1278
|
-
*
|
|
1279
|
-
*
|
|
1280
|
-
* sortArray:true
|
|
1281
|
-
*
|
|
1282
|
-
*
|
|
1283
|
-
*
|
|
1284
|
-
* //
|
|
1285
|
-
*
|
|
1286
|
-
*
|
|
1287
|
-
*
|
|
1288
|
-
*
|
|
1289
|
-
* //
|
|
1290
|
-
*
|
|
1291
|
-
* //
|
|
1292
|
-
*
|
|
1293
|
-
* //
|
|
1294
|
-
*
|
|
1295
|
-
*
|
|
1296
|
-
*
|
|
1297
|
-
*
|
|
1298
|
-
*
|
|
1299
|
-
* //
|
|
1300
|
-
*
|
|
1301
|
-
*
|
|
1302
|
-
*
|
|
1303
|
-
*
|
|
1304
|
-
*
|
|
1305
|
-
* //
|
|
1306
|
-
*
|
|
1307
|
-
* //
|
|
1308
|
-
*
|
|
1309
|
-
* //
|
|
1310
|
-
*
|
|
1311
|
-
*
|
|
1312
|
-
* safeStableStringify(
|
|
1313
|
-
* // ➔ '[
|
|
1314
|
-
*
|
|
1315
|
-
* //
|
|
1316
|
-
* const
|
|
1317
|
-
*
|
|
1318
|
-
*
|
|
1319
|
-
*
|
|
1320
|
-
|
|
1321
|
-
* // Complex nested sortArray with objects
|
|
1322
|
-
* const arr = [9, 7, [4, 2, 3], { z: [5, 1, 6] }];
|
|
1323
|
-
* safeStableStringify(arr, { sortArray:true, sortKeys:true });
|
|
1324
|
-
* // ➔ '[7,9,[2,3,4],{"z":[1,5,6]}]'
|
|
1325
|
-
* ```
|
|
1326
|
-
*/
|
|
1058
|
+
* * ***Utility: `safeStableStringify`.***
|
|
1059
|
+
* ---------------------------------------------
|
|
1060
|
+
* **Safely converts a JavaScript value into a stable, JSON-compatible string.**
|
|
1061
|
+
* - **This function is an enhanced version of `JSON.stringify` with additional guarantees:**
|
|
1062
|
+
* - ***Features:***
|
|
1063
|
+
* - Recursively sorts object keys **only if** `sortKeys` is `true` (default: `true`), to ensure stable
|
|
1064
|
+
* key order.
|
|
1065
|
+
* - If `sortKeys` is `false`, preserves the original insertion order of object keys.
|
|
1066
|
+
* - Optionally sorts array primitive values **only if** `sortArray` is `true` (default: `false`).
|
|
1067
|
+
* - Only primitive values in arrays are sorted.
|
|
1068
|
+
* - Objects and nested arrays keep their original position and are appended after sorted primitives.
|
|
1069
|
+
* - If `sortArray` is `false`, arrays retain their original order.
|
|
1070
|
+
* - Converts JavaScript special values for JSON safety:
|
|
1071
|
+
* - `undefined`, `NaN`, `Infinity`, `-Infinity` ➔ `null`
|
|
1072
|
+
* - `BigInt` ➔ string (JSON does not support BigInt)
|
|
1073
|
+
* - Converts boxed primitives box into their primitive equivalents:
|
|
1074
|
+
* - `new Number(42)` ➔ `Number(42)` ➔ `42`.
|
|
1075
|
+
* - `new String("hi")` ➔ `String("hi")` ➔ `"hi"`.
|
|
1076
|
+
* - `new Boolean(true)` ➔ `Boolean(true)` ➔ `true`.
|
|
1077
|
+
* - Functions and Symbols are removed.
|
|
1078
|
+
* - Circular references are replaced with the string `"[Circular]"`.
|
|
1079
|
+
* - Serializes:
|
|
1080
|
+
* - `Date` ➔ ISO string (`date.toISOString()`)
|
|
1081
|
+
* - `Set` ➔ `{ set: [values...] }` (values are recursively processed)
|
|
1082
|
+
* - `Map` ➔ `{ map: [ [key, value], ... ] }` (values are recursively processed)
|
|
1083
|
+
* - Compared to `JSON.stringify`, this ensures **stable output**:
|
|
1084
|
+
* - Same object structure always produces the same string.
|
|
1085
|
+
* - Useful for deep equality checks, hashing, caching keys, or snapshot tests.
|
|
1086
|
+
* @param {*} value
|
|
1087
|
+
* - Any JavaScript value to serialize, can be:
|
|
1088
|
+
* - Primitives (`number`, `string`, `boolean`, `bigint`, `null`, `undefined`)
|
|
1089
|
+
* - Boxed primitives (`new Number()`, `new String()`, `new Boolean()`)
|
|
1090
|
+
* - Arrays, plain objects, nested structures
|
|
1091
|
+
* - Date, Map, Set
|
|
1092
|
+
* - Circular structures
|
|
1093
|
+
* @param {SafeStableStringifyOptions} [options]
|
|
1094
|
+
* - Configuration options for `safeStableStringify`:
|
|
1095
|
+
* - `sortKeys` (boolean) – Whether to sort object keys alphabetically (recursively), default: `true`.
|
|
1096
|
+
* - `sortArray` (boolean) – Whether to sort primitive values inside arrays, default: `false`.
|
|
1097
|
+
* - `pretty` (boolean) – Whether to pretty-print JSON output with 2-space indentation, default: `false`.
|
|
1098
|
+
* @returns {string}
|
|
1099
|
+
* A stable JSON string representation of the input value.
|
|
1100
|
+
* @throws {TypeError}
|
|
1101
|
+
* Throws if `sortKeys`, `sortArray`, or `pretty` are not strictly boolean.
|
|
1102
|
+
* @example
|
|
1103
|
+
* ```ts
|
|
1104
|
+
* // Basic object key sorting
|
|
1105
|
+
* safeStableStringify({ b: 2, a: 1 });
|
|
1106
|
+
* // ➔ '{"a":1,"b":2}'
|
|
1107
|
+
*
|
|
1108
|
+
* // Disable key sorting (preserve insertion order)
|
|
1109
|
+
* safeStableStringify({ b: 2, a: 1 }, {
|
|
1110
|
+
* sortKeys:false
|
|
1111
|
+
* });
|
|
1112
|
+
* // ➔ '{"b":2,"a":1}'
|
|
1113
|
+
*
|
|
1114
|
+
* // Sorting arrays with sortArray
|
|
1115
|
+
* safeStableStringify([3, 1, 2], {
|
|
1116
|
+
* sortArray:true
|
|
1117
|
+
* });
|
|
1118
|
+
* // ➔ '[1,2,3]'
|
|
1119
|
+
*
|
|
1120
|
+
* // Nested object + sortArray=true
|
|
1121
|
+
* safeStableStringify({ z: [3, 1, 2], x: { d: 4, c: 3 } }, {
|
|
1122
|
+
* sortKeys:true,
|
|
1123
|
+
* sortArray:true
|
|
1124
|
+
* });
|
|
1125
|
+
* // ➔ '{"x":{"c":3,"d":4},"z":[1,2,3]}'
|
|
1126
|
+
*
|
|
1127
|
+
* // sortKeys=false and sortArray=true
|
|
1128
|
+
* safeStableStringify({ z: [3, 1, 2], x: { d: 4, c: 3 } }, {
|
|
1129
|
+
* sortKeys:false,
|
|
1130
|
+
* sortArray:true
|
|
1131
|
+
* });
|
|
1132
|
+
* // ➔ '{"z":[1,2,3],"x":{"d":4,"c":3}}'
|
|
1133
|
+
*
|
|
1134
|
+
* // Pretty print output
|
|
1135
|
+
* safeStableStringify([3, 1, 2], {
|
|
1136
|
+
* sortArray:true,
|
|
1137
|
+
* pretty:true
|
|
1138
|
+
* });
|
|
1139
|
+
* // ➔ `[
|
|
1140
|
+
* // 1,
|
|
1141
|
+
* // 2,
|
|
1142
|
+
* // 3
|
|
1143
|
+
* // ]`
|
|
1144
|
+
*
|
|
1145
|
+
* // Boxed primitives converted to primitive
|
|
1146
|
+
* safeStableStringify({ n: new Number(42), s: new String("hi"), b: new Boolean(true) });
|
|
1147
|
+
* // ➔ '{"n":42,"s":"hi","b":true}'
|
|
1148
|
+
*
|
|
1149
|
+
* // Handles Date, BigInt, Map and Set
|
|
1150
|
+
* safeStableStringify({
|
|
1151
|
+
* time: new Date("2025-01-01"),
|
|
1152
|
+
* big: BigInt(9007199254740991),
|
|
1153
|
+
* data: new Map([["key", new Set([1, 2])]])
|
|
1154
|
+
* });
|
|
1155
|
+
* // ➔ '{"big":"9007199254740991","data":{"map":[["key",{"set":[1,2]}]]},"time":"2025-01-01T00:00:00.000Z"}'
|
|
1156
|
+
*
|
|
1157
|
+
* // Functions and symbols are removed
|
|
1158
|
+
* safeStableStringify({ f: () => {}, s: Symbol("wow") });
|
|
1159
|
+
* // ➔ '{}'
|
|
1160
|
+
*
|
|
1161
|
+
* // undefined, NaN, Infinity convert to null
|
|
1162
|
+
* safeStableStringify([undefined, NaN, Infinity, -Infinity]);
|
|
1163
|
+
* // ➔ '[null,null,null,null]'
|
|
1164
|
+
*
|
|
1165
|
+
* // Circular reference
|
|
1166
|
+
* const obj = { name: "A" };
|
|
1167
|
+
* obj.self = obj;
|
|
1168
|
+
* safeStableStringify(obj);
|
|
1169
|
+
* // ➔ '{"name":"A","self":"[Circular]"}'
|
|
1170
|
+
*
|
|
1171
|
+
* // Complex nested sortArray with objects
|
|
1172
|
+
* const arr = [9, 7, [4, 2, 3], { z: [5, 1, 6] }];
|
|
1173
|
+
* safeStableStringify(arr, { sortArray: true, sortKeys: true });
|
|
1174
|
+
* // ➔ '[7,9,[2,3,4],{"z":[1,5,6]}]'
|
|
1175
|
+
* ```
|
|
1176
|
+
*/
|
|
1327
1177
|
declare const safeStableStringify:(value:unknown,options?:SafeStableStringifyOptions)=>string;
|
|
1328
1178
|
/** ----------------------------------------------------------
|
|
1329
|
-
* * ***
|
|
1330
|
-
*
|
|
1331
|
-
*
|
|
1332
|
-
* - `
|
|
1333
|
-
*
|
|
1334
|
-
*
|
|
1335
|
-
*
|
|
1336
|
-
*
|
|
1337
|
-
*
|
|
1338
|
-
* Special behaviors
|
|
1339
|
-
*
|
|
1340
|
-
*
|
|
1341
|
-
*
|
|
1342
|
-
*
|
|
1343
|
-
*
|
|
1344
|
-
*
|
|
1345
|
-
*
|
|
1346
|
-
*
|
|
1347
|
-
*
|
|
1348
|
-
*
|
|
1349
|
-
* @
|
|
1350
|
-
* @
|
|
1351
|
-
*
|
|
1352
|
-
*
|
|
1353
|
-
*
|
|
1354
|
-
*
|
|
1355
|
-
*
|
|
1356
|
-
*
|
|
1357
|
-
*
|
|
1358
|
-
*
|
|
1359
|
-
*
|
|
1360
|
-
*
|
|
1361
|
-
*
|
|
1362
|
-
*
|
|
1363
|
-
*
|
|
1364
|
-
*
|
|
1365
|
-
*
|
|
1366
|
-
*
|
|
1367
|
-
*
|
|
1368
|
-
*
|
|
1369
|
-
*
|
|
1370
|
-
*
|
|
1371
|
-
*
|
|
1372
|
-
*
|
|
1373
|
-
*
|
|
1374
|
-
*
|
|
1375
|
-
*
|
|
1376
|
-
*
|
|
1377
|
-
*
|
|
1378
|
-
*
|
|
1379
|
-
|
|
1380
|
-
*
|
|
1381
|
-
* @example
|
|
1382
|
-
* toStringDeepForce(/abc/i, "all");
|
|
1383
|
-
* // ➔ "/abc/i"
|
|
1384
|
-
*
|
|
1385
|
-
* @example
|
|
1386
|
-
* toStringDeepForce(new Map([["a", 1], ["b", 2]]), "all");
|
|
1387
|
-
* // ➔ [["a", "1"], ["b", "2"]]
|
|
1388
|
-
*
|
|
1389
|
-
* @example
|
|
1390
|
-
* toStringDeepForce(new Set([1, 2, 3]), "all");
|
|
1391
|
-
* // ➔ ["1", "2", "3"]
|
|
1392
|
-
*
|
|
1393
|
-
* @example
|
|
1394
|
-
* toStringDeepForce(new Error("Oops"), "all");
|
|
1395
|
-
* // ➔ "Error: Oops"
|
|
1396
|
-
*
|
|
1397
|
-
* @example
|
|
1398
|
-
* toStringDeepForce(Promise.resolve(1), "all");
|
|
1399
|
-
* // ➔ "[object Promise]"
|
|
1400
|
-
*
|
|
1401
|
-
* @example
|
|
1402
|
-
* toStringDeepForce({ func: () => 123 }, "all");
|
|
1403
|
-
* // ➔ { func: "() => 123" }
|
|
1404
|
-
*
|
|
1405
|
-
* @example
|
|
1406
|
-
* toStringDeepForce([1, "a", { b: 2 }], false);
|
|
1407
|
-
* // ➔ [1, "a", { b: 2 }]
|
|
1408
|
-
*/
|
|
1179
|
+
* * ***Utility: `toStringDeepForce`.***
|
|
1180
|
+
* ---------------------------------------------
|
|
1181
|
+
* **Recursively converts a value into a string based on the `forceToString` options.**
|
|
1182
|
+
* - **Rules `forceToString` options:**
|
|
1183
|
+
* - `"stringOrNumber"`: Converts strings and numbers to strings.
|
|
1184
|
+
* - `"primitives"`: Converts all primitives (number, string, boolean, bigint, undefined, null, NaN) to strings.
|
|
1185
|
+
* - `"all"`: Converts everything, including symbols, functions, Dates, RegExp, Maps, Sets, Errors, Promises,
|
|
1186
|
+
* and deeply all object properties, to strings.
|
|
1187
|
+
* - `false`: Leaves everything unchanged.
|
|
1188
|
+
* - **Special behaviors:**
|
|
1189
|
+
* - `NaN` ➔ `"NaN"` only in `"primitives"` or `"all"` mode.
|
|
1190
|
+
* - `Date` ➔ ISO string only in `"all"` mode.
|
|
1191
|
+
* - `RegExp` ➔ Source string (e.g. `/abc/i`) only in `"all"` mode.
|
|
1192
|
+
* - `Symbol` ➔ `Symbol(description)` string only in `"all"` mode.
|
|
1193
|
+
* - `Map` ➔ Array of [key, value] pairs with keys/values stringified deeply (only in `"all"` mode).
|
|
1194
|
+
* - `Set` ➔ Array of values stringified deeply (only in `"all"` mode).
|
|
1195
|
+
* - `Function` ➔ Source code string (e.g. `"() => 1"`) only in `"all"` mode.
|
|
1196
|
+
* - `Error`, `Promise` ➔ Stringified via `.toString()` only in `"all"` mode.
|
|
1197
|
+
* @param {*} value - The value to process. Can be anything: primitive, array, object, function, etc.
|
|
1198
|
+
* @param {false | "stringOrNumber" | "primitives" | "all"} forceToString - The mode of string conversion.
|
|
1199
|
+
* @returns {unknown} A new value with the conversion applied based on `forceToString`.
|
|
1200
|
+
* @example
|
|
1201
|
+
* toStringDeepForce(42, "stringOrNumber");
|
|
1202
|
+
* // ➔ "42"
|
|
1203
|
+
* toStringDeepForce(true, "primitives");
|
|
1204
|
+
* // ➔ "true"
|
|
1205
|
+
* toStringDeepForce(null, "primitives");
|
|
1206
|
+
* // ➔ "null"
|
|
1207
|
+
* toStringDeepForce(Symbol("x"), "all");
|
|
1208
|
+
* // ➔ "Symbol(x)"
|
|
1209
|
+
* toStringDeepForce({ a: 1, b: [2, NaN] }, "primitives");
|
|
1210
|
+
* // ➔ { a: "1", b: ["2", "NaN"] }
|
|
1211
|
+
* toStringDeepForce(new Date("2025-01-01"), "all");
|
|
1212
|
+
* // ➔ "2025-01-01T00:00:00.000Z"
|
|
1213
|
+
* toStringDeepForce(() => 1, "all");
|
|
1214
|
+
* // ➔ "() => 1"
|
|
1215
|
+
* toStringDeepForce(/abc/i, "all");
|
|
1216
|
+
* // ➔ "/abc/i"
|
|
1217
|
+
* toStringDeepForce(new Map([["a", 1], ["b", 2]]), "all");
|
|
1218
|
+
* // ➔ [["a", "1"], ["b", "2"]]
|
|
1219
|
+
* toStringDeepForce(new Set([1, 2, 3]), "all");
|
|
1220
|
+
* // ➔ ["1", "2", "3"]
|
|
1221
|
+
* toStringDeepForce(new Error("Oops"), "all");
|
|
1222
|
+
* // ➔ "Error: Oops"
|
|
1223
|
+
* toStringDeepForce(Promise.resolve(1), "all");
|
|
1224
|
+
* // ➔ "[object Promise]"
|
|
1225
|
+
* toStringDeepForce({ func: () => 123 }, "all");
|
|
1226
|
+
* // ➔ { func: "() => 123" }
|
|
1227
|
+
* toStringDeepForce([1, "a", { b: 2 }], false);
|
|
1228
|
+
* // ➔ [1, "a", { b: 2 }]
|
|
1229
|
+
*/
|
|
1409
1230
|
declare function toStringDeepForce(value:unknown,forceToString:false|"stringOrNumber"|"primitives"|"all"):unknown;
|
|
1410
1231
|
/** ----------------------------------------------------------
|
|
1411
|
-
* * Normalize leaked `never[]` into literal empty array `[]`.
|
|
1412
|
-
* ----------------------------------------------------------
|
|
1413
|
-
*/
|
|
1414
|
-
type FixNeverArray$1<T>=[T] extends [never[]]?[]:T;
|
|
1232
|
+
* * Normalize leaked `never[]` into literal empty array `[]`.
|
|
1233
|
+
* ----------------------------------------------------------
|
|
1234
|
+
*/
|
|
1235
|
+
type FixNeverArray$1<T,RemoveEmptyArrays extends boolean>=[T] extends [never[]]?RemoveEmptyArrays extends true?OrArr<[Extends<T,undefined>,Extends<undefined,T>]>extends true?undefined:never:[]:T;
|
|
1415
1236
|
/** ----------------------------------------------------------
|
|
1416
|
-
* * Simplify object type to remove unnecessary TypeScript wrappers.
|
|
1417
|
-
* ----------------------------------------------------------
|
|
1418
|
-
*/
|
|
1237
|
+
* * Simplify object type to remove unnecessary TypeScript wrappers.
|
|
1238
|
+
* ----------------------------------------------------------
|
|
1239
|
+
*/
|
|
1419
1240
|
type Simplify$1<T>=T extends object?{[K in keyof T]:T[K];}:T;
|
|
1420
1241
|
/** ----------------------------------------------------------
|
|
1421
|
-
* * Deeply convert all numbers and strings to `number | undefined`,
|
|
1422
|
-
* * recursively handling arrays, tuples, Sets, Maps, TypedArrays,
|
|
1423
|
-
* * and objects. Special types like Date remain unchanged.
|
|
1424
|
-
* ----------------------------------------------------------
|
|
1425
|
-
*
|
|
1426
|
-
* @template T - Input type to convert
|
|
1427
|
-
* @template RemoveEmptyObjects - Whether to remove empty objects
|
|
1428
|
-
* @template RemoveEmptyArrays - Whether to remove empty arrays
|
|
1429
|
-
* @template IsRoot - Internal flag for root level
|
|
1430
|
-
*/
|
|
1431
|
-
type ConvertedDeepNumberInternal<T,RemoveEmptyObjects extends boolean,RemoveEmptyArrays extends boolean,IsRoot extends boolean>=[
|
|
1242
|
+
* * Deeply convert all numbers and strings to `number | undefined`,
|
|
1243
|
+
* * recursively handling arrays, tuples, Sets, Maps, TypedArrays,
|
|
1244
|
+
* * and objects. Special types like Date remain unchanged.
|
|
1245
|
+
* ----------------------------------------------------------
|
|
1246
|
+
*
|
|
1247
|
+
* @template T - Input type to convert
|
|
1248
|
+
* @template RemoveEmptyObjects - Whether to remove empty objects
|
|
1249
|
+
* @template RemoveEmptyArrays - Whether to remove empty arrays
|
|
1250
|
+
* @template IsRoot - Internal flag for root level
|
|
1251
|
+
*/
|
|
1252
|
+
type ConvertedDeepNumberInternal<T,RemoveEmptyObjects extends boolean,RemoveEmptyArrays extends boolean,IsRoot extends boolean>=[T] extends [null|undefined]?IsRoot extends true?undefined:never:T extends Date|boolean|Boolean?number:T extends string|String|Number|number|`${number}`?number|undefined:AndArr<[Extends<RemoveEmptyArrays,true>,Extends<T,undefined[]>]>extends true?never:T extends readonly(infer E)[]?OrArr<[ Extends<RemoveEmptyArrays,true>,AndArr<[Extends<RemoveEmptyArrays,true>,Extends<IsRoot,true>]>]>extends true?FixNeverArray$1<Exclude<ConvertedDeepNumberInternal<E,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>,RemoveEmptyArrays>[]|undefined:FixNeverArray$1<Exclude<ConvertedDeepNumberInternal<E,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>[],RemoveEmptyArrays>:T extends Set<infer V>?AndArr<[Extends<RemoveEmptyArrays,true>]>extends true?FixNeverArray$1<Exclude<ConvertedDeepNumberInternal<V,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>[],RemoveEmptyArrays>:FixNeverArray$1<Exclude<ConvertedDeepNumberInternal<V,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>[],RemoveEmptyArrays>:T extends Map<infer K,infer V>?FixNeverArray$1<[ Exclude<ConvertedDeepNumberInternal<K,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>,Exclude<ConvertedDeepNumberInternal<V,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>][],RemoveEmptyArrays>:T extends Buffer?FixNeverArray$1<Exclude<ConvertedDeepNumberInternal<string,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>[],RemoveEmptyArrays>:T extends TypedArray?FixNeverArray$1<Exclude<ConvertedDeepNumberInternal<string,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>[],RemoveEmptyArrays>:T extends Record<PropertyKey,unknown>?_ConvertedObjectInternal$1<T,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>:never;
|
|
1432
1253
|
/** ----------------------------------------------------------
|
|
1433
|
-
* *
|
|
1434
|
-
*
|
|
1435
|
-
|
|
1436
|
-
|
|
1254
|
+
* * Internal object conversion utility.
|
|
1255
|
+
* * Removes empty objects/arrays based on flags.
|
|
1256
|
+
* ----------------------------------------------------------
|
|
1257
|
+
*/
|
|
1258
|
+
type _ConvertedObjectInternal$1<O extends Record<PropertyKey,unknown>|string|number,RemoveEmptyObjects extends boolean,RemoveEmptyArrays extends boolean,IsRoot extends boolean>={[K in keyof O as Exclude<ConvertedDeepNumberInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>,undefined>extends infer Convert?[Convert] extends [never]?never:undefined extends ConvertedDeepNumberInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>?never:RemoveEmptyArrays extends true?Convert extends readonly unknown[]?[Convert] extends [[]]?never:K:K:K:never]:Exclude<ConvertedDeepNumberInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>,undefined>;}&{[K in keyof O as Exclude<ConvertedDeepNumberInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>,undefined>extends infer Convert?[Convert] extends [never]?never:undefined extends ConvertedDeepNumberInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>?RemoveEmptyArrays extends true?Convert extends readonly unknown[]?[Convert] extends [[]]?never:K:K:K:never:never]?:Exclude<ConvertedDeepNumberInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>,undefined>;}extends infer M?RemoveEmptyObjects extends true?keyof M extends never?IsRoot extends true?{}:never:_ProcessedObject$1<M,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>:Simplify$1<M>:never;type AllPropsAreNumber$1<O>={[K in keyof O]:O[K] extends number|Number?true:O[K] extends Record<string,unknown>?AllPropsAreNumber$1<O[K]>:false;}[keyof O] extends false?false:true;type _ProcessedObject$1<M,RemoveEmptyObjects extends boolean,RemoveEmptyArrays extends boolean,IsRoot extends boolean>=M extends unknown[]?ConvertedDeepNumberInternal<M,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>:Prettify<Simplify$1<{[K in keyof M]:M[K] extends Record<string,unknown>?AllPropsAreNumber$1<M[K]>extends true?{[ChildKey in keyof M[K]]:M[K][ChildKey] extends number|Number?M[K][ChildKey]|undefined:_ProcessedObject$1<M[K][ChildKey],RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>;}|undefined:AndArr<[ Extends<RemoveEmptyArrays,true>,Extends<RemoveEmptyObjects,true>]>extends true?{[ChildKey in keyof M[K]]:_ProcessChild$1<M[K][ChildKey],RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>;}|undefined:{[ChildKey in keyof M[K]]:_ProcessChild$1<M[K][ChildKey],RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>;}:M[K] extends unknown[]?ConvertedDeepNumberInternal<M[K],RemoveEmptyObjects,RemoveEmptyArrays,false>:_ProcessedObject$1<M[K],RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>;}>,{recursive:true;}>;type _ProcessChild$1<T,RemoveEmptyObjects extends boolean,RemoveEmptyArrays extends boolean,IsRoot extends boolean>=T extends number|number[]?ConvertedDeepNumberInternal<T,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>:T extends Record<string,unknown>?_ProcessedObject$1<T,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>:_ProcessedObject$1<T,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>;
|
|
1437
1259
|
/** ----------------------------------------------------------
|
|
1438
|
-
* *
|
|
1439
|
-
* *
|
|
1440
|
-
* ----------------------------------------------------------
|
|
1441
|
-
*/
|
|
1442
|
-
type
|
|
1443
|
-
/** ----------------------------------------------------------
|
|
1444
|
-
* * Public type: Deeply converts numbers/strings to `number | undefined`,
|
|
1445
|
-
* * applies empty object/array removal, preserves special types.
|
|
1446
|
-
* ----------------------------------------------------------
|
|
1447
|
-
*/
|
|
1448
|
-
type ConvertedDeepNumber<T,RemoveEmptyObjects extends boolean=false,RemoveEmptyArrays extends boolean=false>=[unknown] extends [T]?unknown:FixNeverArray$1<ConvertedDeepNumberInternal<T,RemoveEmptyObjects,RemoveEmptyArrays,true>>;type ToNumberDeepOptions<RemoveEmptyObjects extends boolean=false,RemoveEmptyArrays extends boolean=false>={
|
|
1260
|
+
* * Public type: Deeply converts numbers/strings to `number | undefined`,
|
|
1261
|
+
* * applies empty object/array removal, preserves special types.
|
|
1262
|
+
* ----------------------------------------------------------
|
|
1263
|
+
*/
|
|
1264
|
+
type ConvertedDeepNumber<T,RemoveEmptyObjects extends boolean=false,RemoveEmptyArrays extends boolean=false>=[unknown] extends [T]?unknown:FixNeverArray$1<ConvertedDeepNumberInternal<T,RemoveEmptyObjects,RemoveEmptyArrays,true>,RemoveEmptyArrays>;type ToNumberDeepOptions<RemoveEmptyObjects extends boolean=false,RemoveEmptyArrays extends boolean=false>={
|
|
1449
1265
|
/** Whether to remove empty objects (`{}`) from the result.
|
|
1450
|
-
*
|
|
1451
|
-
* - `true` ➔ remove empty objects recursively.
|
|
1452
|
-
* - `false` **(default)** ➔ keep empty objects as-is.
|
|
1453
|
-
*
|
|
1454
|
-
* @default false
|
|
1455
|
-
*/
|
|
1266
|
+
*
|
|
1267
|
+
* - `true` ➔ remove empty objects recursively.
|
|
1268
|
+
* - `false` **(default)** ➔ keep empty objects as-is.
|
|
1269
|
+
*
|
|
1270
|
+
* @default false
|
|
1271
|
+
*/
|
|
1456
1272
|
removeEmptyObjects?:RemoveEmptyObjects;
|
|
1457
1273
|
/** Whether to remove empty arrays (`[]`) from the result.
|
|
1458
|
-
*
|
|
1459
|
-
* - `true` ➔ remove empty arrays recursively.
|
|
1460
|
-
* - `false` **(default)** ➔ keep empty arrays as-is.
|
|
1461
|
-
*
|
|
1462
|
-
* @default false
|
|
1463
|
-
*/
|
|
1274
|
+
*
|
|
1275
|
+
* - `true` ➔ remove empty arrays recursively.
|
|
1276
|
+
* - `false` **(default)** ➔ keep empty arrays as-is.
|
|
1277
|
+
*
|
|
1278
|
+
* @default false
|
|
1279
|
+
*/
|
|
1464
1280
|
removeEmptyArrays?:RemoveEmptyArrays;};
|
|
1465
1281
|
/** --------------------------------------------------
|
|
1466
|
-
* * ***
|
|
1467
|
-
*
|
|
1468
|
-
*
|
|
1469
|
-
* Features
|
|
1470
|
-
*
|
|
1471
|
-
*
|
|
1472
|
-
*
|
|
1473
|
-
*
|
|
1474
|
-
*
|
|
1475
|
-
*
|
|
1476
|
-
*
|
|
1477
|
-
*
|
|
1478
|
-
*
|
|
1479
|
-
*
|
|
1480
|
-
*
|
|
1481
|
-
*
|
|
1482
|
-
*
|
|
1483
|
-
*
|
|
1484
|
-
*
|
|
1485
|
-
*
|
|
1486
|
-
*
|
|
1487
|
-
*
|
|
1488
|
-
*
|
|
1489
|
-
*
|
|
1490
|
-
*
|
|
1491
|
-
*
|
|
1492
|
-
*
|
|
1493
|
-
*
|
|
1494
|
-
*
|
|
1495
|
-
*
|
|
1496
|
-
*
|
|
1497
|
-
*
|
|
1498
|
-
*
|
|
1499
|
-
*
|
|
1500
|
-
*
|
|
1501
|
-
*
|
|
1502
|
-
*
|
|
1503
|
-
*
|
|
1504
|
-
*
|
|
1505
|
-
*
|
|
1506
|
-
*
|
|
1507
|
-
*
|
|
1508
|
-
*
|
|
1509
|
-
*
|
|
1510
|
-
*
|
|
1511
|
-
*
|
|
1512
|
-
*
|
|
1513
|
-
* toNumberDeep(
|
|
1514
|
-
* // ➔
|
|
1515
|
-
*
|
|
1516
|
-
*
|
|
1517
|
-
*
|
|
1518
|
-
*
|
|
1519
|
-
* toNumberDeep({ a:
|
|
1520
|
-
* // ➔ { a:
|
|
1521
|
-
*
|
|
1522
|
-
*
|
|
1523
|
-
*
|
|
1524
|
-
*
|
|
1525
|
-
*
|
|
1526
|
-
*
|
|
1527
|
-
|
|
1282
|
+
* * ***Utility: `toNumberDeep`.***
|
|
1283
|
+
* ---------------------------------------------------
|
|
1284
|
+
* **Converts deeply nested arrays, objects, buffers, sets, maps, or typed arrays into numbers while preserving structure.**
|
|
1285
|
+
* - **Features:**
|
|
1286
|
+
* - Converts numeric strings, number to numbers:
|
|
1287
|
+
* - `3.5` ➔ `3.5`.
|
|
1288
|
+
* - `"3.5"` ➔ `3.5`.
|
|
1289
|
+
* - Converts boolean to number:
|
|
1290
|
+
* - `true` ➔ `1`.
|
|
1291
|
+
* - `false` ➔ `0`.
|
|
1292
|
+
* - Converts Date to getTime (timestamp) `Date ➔ number`, if invalid Date value will return `0`:
|
|
1293
|
+
* - `new Date("invalid")` ➔ `0`.
|
|
1294
|
+
* - `new Date("11-09-2025 22:04:11")` ➔ `1762700651000`.
|
|
1295
|
+
* - Converts `Buffer`, `TypedArray`, `Set`, `Map`, and `arrays` recursively to `arrays of numbers`.
|
|
1296
|
+
* - Converts boxed primitives box into their primitive equivalents then convert to number:
|
|
1297
|
+
* - For `new String` we convert everything to number (behavior JS of new String):
|
|
1298
|
+
* - `new String(123)` ➔ `Number("123".valueOf())` ➔ `123`.
|
|
1299
|
+
* - `new String("123")` ➔ `Number("123".valueOf())` ➔ `123`.
|
|
1300
|
+
* - If result from `valueOf()` is `NaN` or `Infinity` return `undefined` ***(will removing)***:
|
|
1301
|
+
* - `new String("hi")` ➔ `Number("hi".valueOf())` ➔ `NaN` ***(remove)***.
|
|
1302
|
+
* - For `new Boolean` we convert to boolean (behavior JS of new Boolean) then convert to number:
|
|
1303
|
+
* - `new Boolean(true)` ➔ `Number(true.valueOf())` ➔ `1`.
|
|
1304
|
+
* - `new Boolean(false)` ➔ `Number(false.valueOf())` ➔ `0`.
|
|
1305
|
+
* - Special behavior JS of new Boolean, return `false` **(convert to number: `0`)**
|
|
1306
|
+
* for `false`, (`0` / `-0`), `""` (empty-string),
|
|
1307
|
+
* `null`, `undefined`, `NaN`, otherwise `true` **(convert to number: `1`)**.
|
|
1308
|
+
* - For `new Number`:
|
|
1309
|
+
* - `new Number(42)` ➔ `42.valueOf()` ➔ `42`.
|
|
1310
|
+
* - `new Number(null)` ➔ `null.valueOf()` ➔ `0` (`null` is `0` behavior JS of new Number).
|
|
1311
|
+
* - `new Number(undefined)` ➔ `undefined.valueOf()` ➔ `undefined` ***(remove)***.
|
|
1312
|
+
* - If result from `valueOf()` is `NaN` or `Infinity` return `undefined` ***(will removing)***:
|
|
1313
|
+
* - `new Number(NaN)` ➔ `NaN` ➔ `undefined` ***(remove)***.
|
|
1314
|
+
* - `new Number(Infinity)` ➔ `Infinity` ➔ `undefined` ***(remove)***.
|
|
1315
|
+
* - `new Number(-Infinity)` ➔ `-Infinity` ➔ `undefined` ***(remove)***.
|
|
1316
|
+
* - Recursively processes `nested objects`, `arrays`, `buffers`, `sets`, `maps`, and `typed arrays`.
|
|
1317
|
+
* - Removes `empty-string`, `non-numeric strings`.
|
|
1318
|
+
* - Removes `null`, `undefined`, `NaN`, `Infinity`, `-Infinity`.
|
|
1319
|
+
* - Removes `unsupported` types like `functions` , `RegExp`, `symbols`, and `BigInt`.
|
|
1320
|
+
* - Can optionally remove empty arrays (`[]`) and/or empty objects (`{}`) **recursively**.
|
|
1321
|
+
* @template T - The input type.
|
|
1322
|
+
* @template RemoveEmptyObjects - Whether to remove empty objects.
|
|
1323
|
+
* @template RemoveEmptyArrays - Whether to remove empty arrays.
|
|
1324
|
+
* @param {*} input - The input value to convert.
|
|
1325
|
+
* @param {ToNumberDeepOptions<RemoveEmptyObjects, RemoveEmptyArrays>} [options] - Conversion options.
|
|
1326
|
+
* @returns {ConvertedDeepNumber<T, RemoveEmptyObjects, RemoveEmptyArrays>|undefined} The converted value, return `undefined` if the input is entirely empty or filtered out by options.
|
|
1327
|
+
* @example
|
|
1328
|
+
* ```ts
|
|
1329
|
+
* toNumberDeep("123");
|
|
1330
|
+
* // ➔ 123
|
|
1331
|
+
* toNumberDeep("abc");
|
|
1332
|
+
* // ➔ undefined
|
|
1333
|
+
* toNumberDeep([NaN, "10", "xyz"]);
|
|
1334
|
+
* // ➔ [10]
|
|
1335
|
+
* toNumberDeep({ a: "1", b: [null, "2"] });
|
|
1336
|
+
* // ➔ { a: 1, b: [2] }
|
|
1337
|
+
* toNumberDeep(Buffer.from([0, 1, 2]));
|
|
1338
|
+
* // ➔ [0, 1, 2]
|
|
1339
|
+
* toNumberDeep(new Set(["1", "2"]));
|
|
1340
|
+
* // ➔ [1, 2]
|
|
1341
|
+
* toNumberDeep(new Map([["a", "1"], ["b", "2"]]));
|
|
1342
|
+
* // ➔ [["a", 1], ["b", 2]]
|
|
1343
|
+
* toNumberDeep(new Int16Array([1, 2, 3]));
|
|
1344
|
+
* // ➔ [1, 2, 3]
|
|
1345
|
+
* toNumberDeep(new Date("2025-08-16T00:00:00Z"));
|
|
1346
|
+
* // ➔ 1755552000000
|
|
1347
|
+
* toNumberDeep({ a: {}, b: [] }, { removeEmptyObjects: true });
|
|
1348
|
+
* // ➔ { b: [] }
|
|
1349
|
+
* toNumberDeep({ a: {}, b: [] }, { removeEmptyArrays: true });
|
|
1350
|
+
* // ➔ { a: {} }
|
|
1351
|
+
* toNumberDeep({ x: {}, y: [], z: [{ a: {}, b: [] }] }, {
|
|
1352
|
+
* removeEmptyObjects: true, removeEmptyArrays: true
|
|
1353
|
+
* });
|
|
1354
|
+
* // ➔ { z: [] }
|
|
1355
|
+
* ```
|
|
1356
|
+
*/
|
|
1528
1357
|
declare function toNumberDeep(input?:null|undefined,options?:ToNumberDeepOptions<boolean,boolean>):undefined;declare function toNumberDeep<T,RemoveEmptyObjects extends boolean=false,RemoveEmptyArrays extends boolean=false>(input:T,options?:ToNumberDeepOptions<RemoveEmptyObjects,RemoveEmptyArrays>):ConvertedDeepNumber<T,RemoveEmptyObjects,RemoveEmptyArrays>;
|
|
1529
1358
|
/** ----------------------------------------------------------
|
|
1530
|
-
* * Normalize leaked `never[]` into literal empty array `[]`.
|
|
1531
|
-
* ---------------------------------------------------------- */
|
|
1532
|
-
type FixNeverArray<T,RemoveEmptyArrays extends boolean>=[T] extends [never[]]?RemoveEmptyArrays extends true?T
|
|
1359
|
+
* * Normalize leaked `never[]` into literal empty array `[]`.
|
|
1360
|
+
* ---------------------------------------------------------- */
|
|
1361
|
+
type FixNeverArray<T,RemoveEmptyArrays extends boolean>=[T] extends [never[]]?RemoveEmptyArrays extends true?OrArr<[Extends<T,undefined>,Extends<undefined,T>]>extends true?undefined:never:[]:T;
|
|
1533
1362
|
/** ----------------------------------------------------------
|
|
1534
|
-
* * Simplify object type to remove unnecessary TypeScript wrappers.
|
|
1535
|
-
* ---------------------------------------------------------- */
|
|
1363
|
+
* * Simplify object type to remove unnecessary TypeScript wrappers.
|
|
1364
|
+
* ---------------------------------------------------------- */
|
|
1536
1365
|
type Simplify<T>=T extends object?{[K in keyof T]:T[K];}:T;
|
|
1537
1366
|
/** ----------------------------------------------------------
|
|
1538
|
-
* * Deeply convert all numbers and numeric strings to `string`,
|
|
1539
|
-
* * recursively handling arrays, tuples, Sets, Maps, TypedArrays,
|
|
1540
|
-
* * Buffer, and objects. Special types like Date remain unchanged.
|
|
1541
|
-
* ---------------------------------------------------------- */
|
|
1542
|
-
type ConvertedDeepStringInternal<T,RemoveEmptyObjects extends boolean,RemoveEmptyArrays extends boolean,IsRoot extends boolean>=[T] extends [null|undefined]?IsRoot extends true?undefined:never:T extends
|
|
1543
|
-
/** ----------------------------------------------------------
|
|
1544
|
-
* * Remove undefined and keep only items for tuples
|
|
1545
|
-
* ---------------------------------------------------------- */
|
|
1546
|
-
type _MapTuple<Arr extends readonly unknown[],RemoveEmptyObjects extends boolean,RemoveEmptyArrays extends boolean>=Arr extends readonly [infer H,...infer R]?Exclude<ConvertedDeepStringInternal<H,RemoveEmptyObjects,RemoveEmptyArrays,false>,undefined>extends infer H2?[H2] extends [never]?_MapTuple<R,RemoveEmptyObjects,RemoveEmptyArrays>:[H2,..._MapTuple<R,RemoveEmptyObjects,RemoveEmptyArrays>]:never:[];
|
|
1367
|
+
* * Deeply convert all numbers and numeric strings to `string`,
|
|
1368
|
+
* * recursively handling arrays, tuples, Sets, Maps, TypedArrays,
|
|
1369
|
+
* * Buffer, and objects. Special types like Date remain unchanged.
|
|
1370
|
+
* ---------------------------------------------------------- */
|
|
1371
|
+
type ConvertedDeepStringInternal<T,RemoveEmptyObjects extends boolean,RemoveEmptyArrays extends boolean,IsRoot extends boolean>=[T] extends [null|undefined]?IsRoot extends true?undefined:never:T extends string|boolean|String|Boolean|Date|RegExp|WebApiObjects|IntlObjects|{[Symbol.toStringTag]:"Proxy";}|typeof Reflect?string:T extends Number|number|`${number}`?string|undefined:AndArr<[Extends<RemoveEmptyArrays,true>,Extends<T,undefined[]>]>extends true?never:T extends readonly(infer E)[]?OrArr<[ Extends<RemoveEmptyArrays,true>,AndArr<[Extends<RemoveEmptyArrays,true>,Extends<IsRoot,true>]>]>extends true?FixNeverArray<Exclude<ConvertedDeepStringInternal<E,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>,RemoveEmptyArrays>[]|undefined:FixNeverArray<Exclude<ConvertedDeepStringInternal<E,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>[],RemoveEmptyArrays>:T extends Set<infer V>?AndArr<[Extends<RemoveEmptyArrays,true>]>extends true?FixNeverArray<Exclude<ConvertedDeepStringInternal<V,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>,RemoveEmptyArrays>:FixNeverArray<Exclude<ConvertedDeepStringInternal<V,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>[],RemoveEmptyArrays>:T extends Map<infer K,infer V>?FixNeverArray<[ Exclude<ConvertedDeepStringInternal<K,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>,Exclude<ConvertedDeepStringInternal<V,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>][],RemoveEmptyArrays>:T extends Buffer?FixNeverArray<Exclude<ConvertedDeepStringInternal<string,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>[],RemoveEmptyArrays>:T extends TypedArray?FixNeverArray<Exclude<ConvertedDeepStringInternal<string,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>,undefined>[],RemoveEmptyArrays>:T extends Record<PropertyKey,unknown>?_ConvertedObjectInternal<T,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>:never;
|
|
1547
1372
|
/** ----------------------------------------------------------
|
|
1548
|
-
* * Internal object conversion utility.
|
|
1549
|
-
* * Removes empty objects/arrays based on flags.
|
|
1550
|
-
* ---------------------------------------------------------- */
|
|
1551
|
-
type _ConvertedObjectInternal<O extends Record<string|number|symbol,unknown>|string,RemoveEmptyObjects extends boolean,RemoveEmptyArrays extends boolean,IsRoot extends boolean>={[K in keyof O as Exclude<ConvertedDeepStringInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>,undefined>extends infer Convert?[Convert] extends [never]?never:undefined extends ConvertedDeepStringInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>?never:RemoveEmptyArrays extends true?Convert extends readonly unknown[]?[Convert] extends [[]]?never:K:K:K:never]:Exclude<ConvertedDeepStringInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>,undefined>;}&{[K in keyof O as Exclude<ConvertedDeepStringInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>,undefined>extends infer Convert?[Convert] extends [never]?never:undefined extends ConvertedDeepStringInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>?RemoveEmptyArrays extends true?Convert extends readonly unknown[]?[Convert] extends [[]]?never:K:K:K:never:never]?:Exclude<ConvertedDeepStringInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>,undefined>;}extends infer M?RemoveEmptyObjects extends true?keyof M extends never?IsRoot extends true?{}:never:
|
|
1373
|
+
* * Internal object conversion utility.
|
|
1374
|
+
* * Removes empty objects/arrays based on flags.
|
|
1375
|
+
* ---------------------------------------------------------- */
|
|
1376
|
+
type _ConvertedObjectInternal<O extends Record<string|number|symbol,unknown>|string,RemoveEmptyObjects extends boolean,RemoveEmptyArrays extends boolean,IsRoot extends boolean>={[K in keyof O as Exclude<ConvertedDeepStringInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>,undefined>extends infer Convert?[Convert] extends [never]?never:undefined extends ConvertedDeepStringInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>?never:RemoveEmptyArrays extends true?Convert extends readonly unknown[]?[Convert] extends [[]]?never:K:K:K:never]:Exclude<ConvertedDeepStringInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>,undefined>;}&{[K in keyof O as Exclude<ConvertedDeepStringInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>,undefined>extends infer Convert?[Convert] extends [never]?never:undefined extends ConvertedDeepStringInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>?RemoveEmptyArrays extends true?Convert extends readonly unknown[]?[Convert] extends [[]]?never:K:K:K:never:never]?:Exclude<ConvertedDeepStringInternal<O[K],RemoveEmptyObjects,RemoveEmptyArrays,false>,undefined>;}extends infer M?RemoveEmptyObjects extends true?keyof M extends never?IsRoot extends true?{}:never:_ProcessedObject<M,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>:Simplify<M>:never;type AllPropsAreNumber<O>={[K in keyof O]:O[K] extends number|Number?true:O[K] extends Record<string,unknown>?AllPropsAreNumber<O[K]>:false;}[keyof O] extends false?false:true;type _ProcessedObject<M,RemoveEmptyObjects extends boolean,RemoveEmptyArrays extends boolean,IsRoot extends boolean>=M extends unknown[]?ConvertedDeepStringInternal<M,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>:Prettify<Simplify<{[K in keyof M]:M[K] extends Record<string,unknown>?AllPropsAreNumber<M[K]>extends true?{[ChildKey in keyof M[K]]:M[K][ChildKey] extends number|Number?M[K][ChildKey]|undefined:_ProcessedObject<M[K][ChildKey],RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>;}|undefined:AndArr<[ Extends<RemoveEmptyArrays,true>,Extends<RemoveEmptyObjects,true>]>extends true?{[ChildKey in keyof M[K]]:_ProcessChild<M[K][ChildKey],RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>;}|undefined:{[ChildKey in keyof M[K]]:_ProcessChild<M[K][ChildKey],RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>;}:M[K] extends unknown[]?ConvertedDeepStringInternal<M[K],RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>:_ProcessedObject<M[K],RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>;}>,{recursive:true;}>;type _ProcessChild<T,RemoveEmptyObjects extends boolean,RemoveEmptyArrays extends boolean,IsRoot extends boolean>=T extends number|Number[]?ConvertedDeepStringInternal<T,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>:T extends Record<string,unknown>?_ProcessedObject<T,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>:_ProcessedObject<T,RemoveEmptyObjects,RemoveEmptyArrays,IsRoot>;
|
|
1552
1377
|
/** ----------------------------------------------------------
|
|
1553
|
-
* * Public type: Deeply converts numbers/strings to `string`,
|
|
1554
|
-
* * applies empty object/array removal, preserves special types.
|
|
1555
|
-
* ---------------------------------------------------------- */
|
|
1378
|
+
* * Public type: Deeply converts numbers/strings to `string`,
|
|
1379
|
+
* * applies empty object/array removal, preserves special types.
|
|
1380
|
+
* ---------------------------------------------------------- */
|
|
1556
1381
|
type ConvertedDeepString<T,RemoveEmptyObjects extends boolean=false,RemoveEmptyArrays extends boolean=false>=[unknown] extends [T]?unknown:FixNeverArray<Simplify<ConvertedDeepStringInternal<T,RemoveEmptyObjects,RemoveEmptyArrays,true>>,RemoveEmptyArrays>;type ToStringDeepOptions<RemoveEmptyObjects extends boolean=false,RemoveEmptyArrays extends boolean=false>={
|
|
1557
1382
|
/** Whether to remove empty objects (`{}`) from the result.
|
|
1558
|
-
*
|
|
1559
|
-
* - `true` ➔ remove empty objects recursively.
|
|
1560
|
-
* - `false` **(default)** ➔ keep empty objects as-is.
|
|
1561
|
-
*
|
|
1562
|
-
* @default false
|
|
1563
|
-
*/
|
|
1383
|
+
*
|
|
1384
|
+
* - `true` ➔ remove empty objects recursively.
|
|
1385
|
+
* - `false` **(default)** ➔ keep empty objects as-is.
|
|
1386
|
+
*
|
|
1387
|
+
* @default false
|
|
1388
|
+
*/
|
|
1564
1389
|
removeEmptyObjects?:RemoveEmptyObjects;
|
|
1565
1390
|
/** Whether to remove empty arrays (`[]`) from the result.
|
|
1566
|
-
*
|
|
1567
|
-
* - `true` ➔ remove empty arrays recursively.
|
|
1568
|
-
* - `false` **(default)** ➔ keep empty arrays as-is.
|
|
1569
|
-
*
|
|
1570
|
-
* @default false
|
|
1571
|
-
*/
|
|
1391
|
+
*
|
|
1392
|
+
* - `true` ➔ remove empty arrays recursively.
|
|
1393
|
+
* - `false` **(default)** ➔ keep empty arrays as-is.
|
|
1394
|
+
*
|
|
1395
|
+
* @default false
|
|
1396
|
+
*/
|
|
1572
1397
|
removeEmptyArrays?:RemoveEmptyArrays;};
|
|
1573
1398
|
/** --------------------------------------------------
|
|
1574
|
-
* * ***
|
|
1575
|
-
*
|
|
1576
|
-
*
|
|
1577
|
-
* Features
|
|
1578
|
-
*
|
|
1579
|
-
*
|
|
1580
|
-
*
|
|
1581
|
-
*
|
|
1582
|
-
*
|
|
1583
|
-
*
|
|
1584
|
-
*
|
|
1585
|
-
*
|
|
1586
|
-
*
|
|
1587
|
-
*
|
|
1588
|
-
*
|
|
1589
|
-
*
|
|
1590
|
-
*
|
|
1591
|
-
*
|
|
1592
|
-
*
|
|
1593
|
-
*
|
|
1594
|
-
*
|
|
1595
|
-
*
|
|
1596
|
-
*
|
|
1597
|
-
*
|
|
1598
|
-
*
|
|
1599
|
-
*
|
|
1600
|
-
*
|
|
1601
|
-
*
|
|
1602
|
-
*
|
|
1603
|
-
*
|
|
1604
|
-
*
|
|
1605
|
-
*
|
|
1606
|
-
*
|
|
1607
|
-
*
|
|
1608
|
-
*
|
|
1609
|
-
*
|
|
1610
|
-
*
|
|
1611
|
-
*
|
|
1612
|
-
*
|
|
1613
|
-
*
|
|
1614
|
-
*
|
|
1615
|
-
*
|
|
1616
|
-
* //
|
|
1617
|
-
*
|
|
1618
|
-
* //
|
|
1619
|
-
*
|
|
1620
|
-
*
|
|
1621
|
-
*
|
|
1622
|
-
*
|
|
1623
|
-
*
|
|
1624
|
-
*
|
|
1625
|
-
*
|
|
1626
|
-
*
|
|
1627
|
-
*
|
|
1628
|
-
*
|
|
1629
|
-
*
|
|
1630
|
-
* //
|
|
1631
|
-
*
|
|
1632
|
-
|
|
1633
|
-
|
|
1399
|
+
* * ***Utility: `toStringDeep`.***
|
|
1400
|
+
* ---------------------------------------------------
|
|
1401
|
+
* **Converts all values in an array, object, Set, Map, or deeply nested structure to string.**
|
|
1402
|
+
* - **Features:**
|
|
1403
|
+
* - Converts numbers and strings to string:
|
|
1404
|
+
* - `3.5` ➔ `"3.5"`.
|
|
1405
|
+
* - `"3.5"` ➔ `"3.5"`.
|
|
1406
|
+
* - Converts boolean to string:
|
|
1407
|
+
* - `true` ➔ `"true"`.
|
|
1408
|
+
* - `false` ➔ `"false"`.
|
|
1409
|
+
* - Converts Date to ISO string (`Date ➔ string`).
|
|
1410
|
+
* - Converts RegExp to string (e.g., `/abc/ ➔ "/abc/"`).
|
|
1411
|
+
* - Converts `Buffer`, `TypedArray`, `Set`, `Map`, and `arrays` recursively to `arrays of strings`.
|
|
1412
|
+
* - Converts boxed primitives box into their primitive equivalents then convert to string:
|
|
1413
|
+
* - For `new String` we convert everything to string (behavior JS of new String):
|
|
1414
|
+
* - `new String("hi")` ➔ `"hi".valueOf().toString()` ➔ `"hi"`.
|
|
1415
|
+
* - For `new Boolean` we convert to boolean (behavior JS of new Boolean) then convert to string:
|
|
1416
|
+
* - `new Boolean(true)` ➔ `true.valueOf().toString()` ➔ `"true"`.
|
|
1417
|
+
* - Special behavior JS of new Boolean, return `false` **(convert to string: `"false"`)**
|
|
1418
|
+
* for `false`, (`0` / `-0`), `""` (empty-string),
|
|
1419
|
+
* `null`, `undefined`, `NaN`, otherwise `true` **(convert to string: `"true"`)**.
|
|
1420
|
+
* - For `new Number`:
|
|
1421
|
+
* - `new Number(42)` ➔ `42.valueOf().toString()` ➔ `"42"`.
|
|
1422
|
+
* - `new Number(null)` ➔ `null.valueOf().toString()` ➔ `"0"` (`null` is `0` behavior JS of new Number).
|
|
1423
|
+
* - `new Number(undefined)` ➔ `undefined.valueOf().toString()` ➔ `undefined` ***(remove)***.
|
|
1424
|
+
* - If result from `valueOf()` is `NaN` or `Infinity` return `undefined` ***(will removing)***:
|
|
1425
|
+
* - `new Number(NaN)` ➔ `NaN` ➔ `undefined` ***(remove)***.
|
|
1426
|
+
* - `new Number(Infinity)` ➔ `Infinity` ➔ `undefined` ***(remove)***.
|
|
1427
|
+
* - `new Number(-Infinity)` ➔ `-Infinity` ➔ `undefined` ***(remove)***.
|
|
1428
|
+
* - Recursively processes `nested objects`, `arrays`, `buffers`, `sets`, `maps`, and `typed arrays`.
|
|
1429
|
+
* - Removes `null`, `undefined`, `NaN`, `Infinity`, `-Infinity`.
|
|
1430
|
+
* - Removes `unsupported` types like `functions`, `symbols`, and `BigInt`.
|
|
1431
|
+
* - Can optionally remove empty arrays (`[]`) and/or empty objects (`{}`) **recursively**.
|
|
1432
|
+
* @template T - The input data type (`primitive`, `object`, `array`, `Set`, `Map`, or `any nested combination`).
|
|
1433
|
+
* @template RemoveEmptyObjects - If `true`, empty objects `{}` will be removed recursively.
|
|
1434
|
+
* @template RemoveEmptyArrays - If `true`, empty arrays `[]` will be removed recursively (including arrays nested in `objects` / `arrays` / `Sets` / `Maps`).
|
|
1435
|
+
* @param {*} input - The data to convert.
|
|
1436
|
+
* @param {ToStringDeepOptions<RemoveEmptyObjects, RemoveEmptyArrays>} [options] - Conversion options.
|
|
1437
|
+
* @returns {ConvertedDeepString<T, RemoveEmptyObjects, RemoveEmptyArrays>|undefined}
|
|
1438
|
+
* The transformed data, or `undefined` if the entire structure becomes empty after processing.
|
|
1439
|
+
* @example
|
|
1440
|
+
* ```ts
|
|
1441
|
+
* // Simple array conversion
|
|
1442
|
+
* toStringDeep([1, "2", 3]);
|
|
1443
|
+
* // ➔ ["1", "2", "3"]
|
|
1444
|
+
*
|
|
1445
|
+
* // Simple top-level conversion
|
|
1446
|
+
* toStringDeep(123);
|
|
1447
|
+
* // ➔ "123"
|
|
1448
|
+
* toStringDeep("123");
|
|
1449
|
+
* // ➔ "123"
|
|
1450
|
+
* toStringDeep(true);
|
|
1451
|
+
* // ➔ "true"
|
|
1452
|
+
* toStringDeep(false);
|
|
1453
|
+
* // ➔ "false"
|
|
1454
|
+
*
|
|
1455
|
+
* // Nested arrays
|
|
1456
|
+
* toStringDeep([1, ["2", [3, [null, "4", true, false]]]]);
|
|
1457
|
+
* // ➔ ["1", ["2", ["3", ["4", "true", "false"]]]]
|
|
1458
|
+
*
|
|
1459
|
+
* // Object with nested values
|
|
1460
|
+
* toStringDeep({ a: 1, b: "2", c: { d: 3, e: null, f: true, g: false } });
|
|
1461
|
+
* // ➔ { a: "1", b: "2", c: { d: "3", f: "true", g: "false" } }
|
|
1462
|
+
*
|
|
1463
|
+
* // Removing empty objects
|
|
1464
|
+
* toStringDeep({ a: {}, b: "1" }, { removeEmptyObjects: true });
|
|
1465
|
+
* // ➔ { b: "1" }
|
|
1466
|
+
*
|
|
1467
|
+
* // Removing empty arrays recursively
|
|
1468
|
+
* toStringDeep(["1", [], { a: [] }], { removeEmptyArrays: true });
|
|
1469
|
+
* // ➔ ["1", { a: [] }]
|
|
1470
|
+
*
|
|
1471
|
+
* // Removing both empty objects and arrays recursively
|
|
1472
|
+
* toStringDeep({ a: {}, b: [], c: [{ d: {}, e: [] }, "1"] }, {
|
|
1473
|
+
* removeEmptyObjects: true,
|
|
1474
|
+
* removeEmptyArrays: true
|
|
1475
|
+
* });
|
|
1476
|
+
* // ➔ { c: ["1"] }
|
|
1477
|
+
*
|
|
1478
|
+
* // Fully empty structure becomes undefined
|
|
1479
|
+
* toStringDeep([null, undefined, {}], {
|
|
1480
|
+
* removeEmptyObjects: true,
|
|
1481
|
+
* removeEmptyArrays: true
|
|
1482
|
+
* });
|
|
1483
|
+
* // ➔ undefined
|
|
1484
|
+
* ```
|
|
1485
|
+
*/
|
|
1486
|
+
declare function toStringDeep(input?:null|undefined,options?:ToStringDeepOptions<boolean,boolean>):undefined;declare function toStringDeep<T,RemoveEmptyObjects extends boolean=false,RemoveEmptyArrays extends boolean=false>(input:T,options?:ToStringDeepOptions<RemoveEmptyObjects,RemoveEmptyArrays>):ConvertedDeepString<T,RemoveEmptyObjects,RemoveEmptyArrays>;export{cleanParsedData,convertType,dedupeArray,extractDigits,filterNilArray,parseCurrencyString,parseCustomDate,removeObjectPaths,safeJsonParse,safeStableStringify,toBooleanContent,toBooleanContentDeep,toBooleanExplicit,toBooleanLoose,toNumberArrayUnRecursive,toNumberDeep,toStringArrayUnRecursive,toStringDeep,toStringDeepForce};
|