@rzl-zone/utils-js 3.0.1-beta.0 → 3.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assertions/index.cjs +1 -1
- package/dist/assertions/index.d.ts +96 -116
- package/dist/assertions/index.js +1 -1
- package/dist/chunk-25G6B35W.js +1 -0
- package/dist/chunk-2AUUPGMN.js +1 -0
- package/dist/chunk-2JQQQ625.js +1 -0
- package/dist/chunk-445TAVT4.cjs +1 -0
- package/dist/chunk-467VEMJH.js +1 -0
- package/dist/chunk-6Q4I2RPC.cjs +1 -0
- package/dist/chunk-6SMJMZ7G.cjs +1 -0
- package/dist/chunk-BLCANGFS.js +1 -0
- package/dist/chunk-CK3BZGEU.js +1 -0
- package/dist/{chunk-JWHM3WZQ.cjs → chunk-D43GV6EF.cjs} +1 -1
- package/dist/chunk-DFSTVQFI.cjs +1 -0
- package/dist/chunk-DYRDBYPF.cjs +1 -0
- package/dist/chunk-EXXLUO7L.cjs +1 -0
- package/dist/chunk-G72VSVGO.js +1 -0
- package/dist/chunk-GAJTFCUA.js +1 -0
- package/dist/chunk-GOJNH55O.cjs +1 -0
- package/dist/chunk-HXST7RJB.js +1 -0
- package/dist/{chunk-BYZAD3XN.cjs → chunk-HXTACM3O.cjs} +1 -1
- package/dist/chunk-IJTZWWRJ.cjs +1 -0
- package/dist/chunk-ISJ33O2J.cjs +1 -0
- package/dist/chunk-JISH2VGG.js +1 -0
- package/dist/{chunk-FF76ISQ2.js → chunk-JQZUWBIX.js} +1 -1
- package/dist/{chunk-XH6MCRLP.js → chunk-K4PLGD7C.js} +1 -1
- package/dist/chunk-KZQB7H4E.cjs +1 -0
- package/dist/chunk-LUVV5KSD.cjs +2 -0
- package/dist/chunk-LVUSFXQS.cjs +1 -0
- package/dist/chunk-ME5OV5HN.js +1 -0
- package/dist/chunk-MF5Y5K4N.cjs +1 -0
- package/dist/chunk-MJAW5RAK.js +1 -0
- package/dist/chunk-MWLEM7ED.js +1 -0
- package/dist/chunk-NSVLG7NY.js +4 -0
- package/dist/chunk-NUHOOAUN.cjs +1 -0
- package/dist/chunk-NUVGETPD.js +2 -0
- package/dist/chunk-O5VXBNUQ.cjs +4 -0
- package/dist/chunk-O7SJR4CY.cjs +1 -0
- package/dist/chunk-OX6RLS2F.cjs +1 -0
- package/dist/chunk-PFLNHD4B.cjs +1 -0
- package/dist/chunk-PSWITZK5.js +1 -0
- package/dist/chunk-PYUVKHUF.cjs +1 -0
- package/dist/chunk-REFMEB4A.js +1 -0
- package/dist/chunk-RHE3M2NJ.cjs +1 -0
- package/dist/chunk-RHIBYOFQ.js +1 -0
- package/dist/chunk-S7GMG4TB.js +1 -0
- package/dist/chunk-TQMZ2LPI.js +1 -0
- package/dist/{chunk-RN3TP3S3.js → chunk-U4TZO7WV.js} +1 -1
- package/dist/chunk-UUMKL74S.js +1 -0
- package/dist/{chunk-EXZ47NOW.js → chunk-VQLAPEL3.js} +1 -1
- package/dist/chunk-VTR75UID.cjs +1 -0
- package/dist/chunk-XFCJDSB2.cjs +1 -0
- package/dist/chunk-XOYX4PLZ.cjs +1 -0
- package/dist/chunk-Z6FLCEN6.js +1 -0
- package/dist/chunk-ZO5364A6.cjs +1 -0
- package/dist/conversions/index.cjs +1 -1
- package/dist/conversions/index.d.ts +396 -593
- package/dist/conversions/index.js +1 -1
- package/dist/env/index.d.ts +5 -8
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.d.ts +80 -77
- package/dist/events/index.js +1 -1
- package/dist/{array-CIZRbqTF.d.ts → extends-Bk_SBGdT.d.ts} +145 -1
- package/dist/formatting/index.cjs +1 -1
- package/dist/formatting/index.d.ts +478 -440
- package/dist/formatting/index.js +1 -1
- package/dist/generator/index.cjs +1 -1
- package/dist/generator/index.d.ts +135 -112
- package/dist/generator/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{is-array-Ckm_47hw.d.ts → is-array--YjXV-Wx.d.ts} +2 -352
- package/dist/{isPlainObject-BKYaI6a8.d.ts → isPlainObject-BVhBAPHX.d.ts} +49 -62
- package/dist/next/index.cjs +6 -6
- package/dist/next/index.d.ts +125 -105
- package/dist/next/index.js +5 -5
- package/dist/next/server/index.cjs +1 -1
- package/dist/next/server/index.d.ts +8 -22
- package/dist/next/server/index.js +1 -1
- package/dist/operations/index.cjs +1 -1
- package/dist/operations/index.d.ts +72 -127
- package/dist/operations/index.js +1 -1
- package/dist/parsers/index.cjs +1 -1
- package/dist/parsers/index.d.ts +26 -27
- package/dist/parsers/index.js +1 -1
- package/dist/predicates/index.cjs +1 -1
- package/dist/predicates/index.d.ts +686 -660
- package/dist/predicates/index.js +1 -1
- package/dist/promise/index.cjs +1 -1
- package/dist/promise/index.d.ts +14 -23
- package/dist/promise/index.js +1 -1
- package/dist/rzl-utils.global.js +3 -3
- package/dist/string-XA-til3C.d.ts +351 -0
- package/dist/strings/index.cjs +1 -1
- package/dist/strings/index.d.ts +301 -376
- package/dist/strings/index.js +1 -1
- package/dist/stylings/index.cjs +1 -1
- package/dist/stylings/index.d.ts +15 -23
- package/dist/stylings/index.js +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/urls/index.cjs +1 -1
- package/dist/urls/index.d.ts +279 -302
- package/dist/urls/index.js +1 -1
- package/package.json +53 -11
- package/dist/chunk-2TRAPBZ7.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-62HX5Z45.cjs +0 -1
- package/dist/chunk-7NA6DUHR.cjs +0 -2
- package/dist/chunk-BVPMMWDL.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-FDITZ5C6.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-KBKYG3IY.cjs +0 -1
- package/dist/chunk-KCQDDZJE.cjs +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-POCPQYZS.js +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-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-X3GTRVVK.cjs +0 -4
- package/dist/chunk-XCFIOTCV.js +0 -1
- package/dist/chunk-XE27XPJR.js +0 -1
- package/dist/chunk-XVB3ZZEB.js +0 -1
- package/dist/chunk-YEERJDOF.js +0 -4
- package/dist/chunk-ZBSIGJFO.cjs +0 -1
- package/dist/chunk-ZYAML74V.js +0 -1
- package/dist/extends-Mp81Hq9-.d.ts +0 -145
|
@@ -1,4 +1,4 @@
|
|
|
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}from'../extends-Bk_SBGdT.js';import{P as Prettify}from'../prettify-C4xLcYOP.js';import{N as NumberRangeUnion}from'../NumberRangeUnion-DC-C3_Kq.js';import'../if-CvT4R7Kh.js';import'../never-BfayMBF9.js';type ExcludeNil<T>=Exclude<T,null|undefined>;
|
|
2
2
|
/** ----------------------------------------------------------
|
|
3
3
|
* * ***Element extractor***
|
|
4
4
|
* ----------------------------------------------------------
|
|
@@ -27,178 +27,125 @@ forceToString?:F;
|
|
|
27
27
|
*/
|
|
28
28
|
flatten?:Fl;};
|
|
29
29
|
/** ----------------------------------------------------------
|
|
30
|
-
* * ***
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* -
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @template
|
|
39
|
-
* @param {T[]}
|
|
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
40
|
* @returns {T[] | undefined} A new array with `null` and `undefined` values removed,
|
|
41
41
|
* or `undefined` if the input is explicitly `undefined` or `null`.
|
|
42
|
-
*
|
|
43
42
|
* @example
|
|
44
43
|
* ```ts
|
|
45
44
|
* filterNilArray([1, null, 2, undefined, 3]);
|
|
46
45
|
* // ➔ [1, 2, 3]
|
|
47
|
-
*
|
|
48
46
|
* filterNilArray([null, undefined]);
|
|
49
47
|
* // ➔ []
|
|
50
|
-
*
|
|
51
48
|
* filterNilArray(undefined);
|
|
52
49
|
* // ➔ undefined
|
|
53
|
-
*
|
|
54
50
|
* filterNilArray(null);
|
|
55
51
|
* // ➔ undefined
|
|
56
|
-
*
|
|
57
52
|
* filterNilArray([]); // or
|
|
58
53
|
* filterNilArray([[[]]]); // or
|
|
59
54
|
* filterNilArray([[[],undefined,null]]);
|
|
60
55
|
* // ➔ []
|
|
61
|
-
*
|
|
62
56
|
* filterNilArray([1, [null, 2, [undefined, 3]]]);
|
|
63
57
|
* // ➔ [1, [2, [3]]]
|
|
64
58
|
* ```
|
|
65
59
|
*/
|
|
66
|
-
declare function filterNilArray(input
|
|
67
|
-
/** ----------------------------------------------------------
|
|
68
|
-
* * ***Removes `null` and `undefined` values from an array, including nested arrays.***
|
|
69
|
-
* ----------------------------------------------------------
|
|
70
|
-
*
|
|
71
|
-
* **⚠️ Notes:** This function is deprecated and renamed to `filterNilArray`, will remove in the next version.
|
|
72
|
-
*
|
|
73
|
-
* @deprecated Use `filterNilArray` instead.
|
|
74
|
-
*/
|
|
75
|
-
declare const filterNullArray:typeof filterNilArray;
|
|
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[];
|
|
76
61
|
/** ----------------------------------------------------------
|
|
77
|
-
* * ***
|
|
78
|
-
*
|
|
79
|
-
*
|
|
62
|
+
* * ***Utility: `dedupeArray`.***
|
|
63
|
+
* ---------------------------------------------
|
|
64
|
+
* @description
|
|
65
|
+
* Deduplicates values in an array (with optional flattening and deep stringification).
|
|
80
66
|
* - Supports various modes for converting values to strings before deduplication:
|
|
81
67
|
* - `"stringOrNumber"`: Converts strings and numbers to strings.
|
|
82
68
|
* - `"primitives"`: Converts all primitives (string, number, boolean, bigint, null, undefined, NaN) to strings.
|
|
83
69
|
* - `"all"`: Converts all values (primitives, objects, Maps, Sets, Symbols, RegExp, Dates, Errors, Promises, functions)
|
|
84
70
|
* to strings, including nested object properties.
|
|
85
71
|
* - `false` (default): No conversion applied.
|
|
86
|
-
*
|
|
87
72
|
* - Options:
|
|
88
73
|
* - `forceToString`: Enables string conversion for comparison, default is `false`.
|
|
89
74
|
* - `flatten`: If true, deeply flattens arrays, Maps, and Sets before deduplication, default is `false`.
|
|
90
|
-
*
|
|
91
75
|
* @template ForceToString - `forceToString` mode.
|
|
92
76
|
* @template Flattening - `flatten` mode.
|
|
93
|
-
*
|
|
94
77
|
* @param {unknown[]} inputArray - The array to deduplicate. Can be deeply nested and contain any mix of types.
|
|
95
|
-
* @param {
|
|
78
|
+
* @param {DedupeArrayOptions<ForceToString, Flattening>|undefined} [options] - Options to control string conversion.
|
|
96
79
|
* @returns {DedupeResult<ForceToString, Flattening>} Deduplicated array with optional transformations.
|
|
97
|
-
*
|
|
98
80
|
* @throws {TypeError} If the input is not an array, or options is not an object, or if `forceToString` is invalid.
|
|
99
|
-
*
|
|
100
81
|
* @example
|
|
101
82
|
* ```ts
|
|
102
83
|
* dedupeArray(["apple", "banana", "apple"]);
|
|
103
84
|
* // ➔ ["apple", "banana"]
|
|
104
|
-
*
|
|
105
85
|
* dedupeArray([[1, 2], [1, 2]], { flatten: true });
|
|
106
86
|
* // ➔ [1, 2]
|
|
107
|
-
*
|
|
108
87
|
* dedupeArray([new Set([1, 2]), new Set([2, 3])], { flatten: true });
|
|
109
88
|
* // ➔ [1, 2, 3]
|
|
110
|
-
*
|
|
111
89
|
* dedupeArray([1, "1", 2, "2"], {
|
|
112
90
|
* forceToString: "stringOrNumber"
|
|
113
|
-
* });
|
|
114
|
-
* // ➔ ["1", "2"]
|
|
115
|
-
*
|
|
91
|
+
* }); // ➔ ["1", "2"]
|
|
116
92
|
* dedupeArray([true, "true", false, undefined], {
|
|
117
93
|
* forceToString: "primitives"
|
|
118
|
-
* });
|
|
119
|
-
* // ➔ ["true", "false", "undefined"]
|
|
120
|
-
*
|
|
94
|
+
* }); // ➔ ["true", "false", "undefined"]
|
|
121
95
|
* dedupeArray([1, "1", { a: 1 }], {
|
|
122
96
|
* forceToString: "all"
|
|
123
|
-
* });
|
|
124
|
-
* // ➔ ["1", { a: "1" }]
|
|
125
|
-
*
|
|
97
|
+
* }); // ➔ ["1", { a: "1" }]
|
|
126
98
|
* dedupeArray([1, 1, [2, 2, [3, 3]]]);
|
|
127
99
|
* // ➔ [1, [2, [3]]]
|
|
128
|
-
*
|
|
129
100
|
* dedupeArray([null, undefined, null]);
|
|
130
101
|
* // ➔ [null, undefined]
|
|
131
|
-
*
|
|
132
102
|
* dedupeArray([[], [[]], [[[]]], [[]], [[[]]]]);
|
|
133
103
|
* // ➔ [[], [[]], [[[]]]]
|
|
134
|
-
*
|
|
135
104
|
* const fn = () => 1;
|
|
136
105
|
* dedupeArray([fn, fn, () => 1]);
|
|
137
106
|
* // ➔ [fn, () => 1] cause: ref () => 1 and fn is different but ref const `fn` and `fn` is same ref.
|
|
138
|
-
*
|
|
139
107
|
* dedupeArray([Symbol("x"), Symbol("x")]);
|
|
140
108
|
* // ➔ [Symbol("x")] (symbols are same by identity, so dedupe
|
|
141
|
-
*
|
|
142
109
|
* dedupeArray([NaN, NaN, 1, "1"]);
|
|
143
110
|
* // ➔ [NaN, 1, "1"]
|
|
144
|
-
*
|
|
145
111
|
* dedupeArray([NaN, NaN, 1, "1"], {
|
|
146
112
|
* forceToString: "primitives"
|
|
147
|
-
* });
|
|
148
|
-
* // ➔ ["NaN", "1"]
|
|
149
|
-
*
|
|
113
|
+
* }); // ➔ ["NaN", "1"]
|
|
150
114
|
* dedupeArray([new Date("2025-01-01"), new Date("2025-01-01")]);
|
|
151
115
|
* // ➔ [Date("2025-01-01")] (same time, deduped)
|
|
152
|
-
*
|
|
153
116
|
* dedupeArray([new Date("2025-01-01"), new Date("2025-01-01")], {
|
|
154
117
|
* forceToString: "all"
|
|
155
|
-
* });
|
|
156
|
-
* // ➔ ["2025-01-01T00:00:00.000Z"]
|
|
157
|
-
*
|
|
118
|
+
* }); // ➔ ["2025-01-01T00:00:00.000Z"]
|
|
158
119
|
* dedupeArray([/abc/, /abc/], {
|
|
159
120
|
* forceToString: "all"
|
|
160
|
-
* });
|
|
161
|
-
* // ➔ ["/abc/"]
|
|
162
|
-
*
|
|
121
|
+
* }); // ➔ ["/abc/"]
|
|
163
122
|
* dedupeArray([new Map(), new Set(), new Error("err")], {
|
|
164
123
|
* forceToString: "all"
|
|
165
|
-
* });
|
|
166
|
-
* // ➔ ["[object Map]", "[object Set]", "Error: err"]
|
|
167
|
-
*
|
|
124
|
+
* }); // ➔ ["[object Map]", "[object Set]", "Error: err"]
|
|
168
125
|
* dedupeArray([Promise.resolve(1), Promise.resolve(1)], {
|
|
169
126
|
* forceToString: "all"
|
|
170
|
-
* });
|
|
171
|
-
* // ➔ ["[object Promise]"]
|
|
172
|
-
*
|
|
127
|
+
* }); // ➔ ["[object Promise]"]
|
|
173
128
|
* dedupeArray([{ a: 1 }, { a: 1 }, { a: 2 }], {
|
|
174
129
|
* forceToString: "primitives"
|
|
175
|
-
* });
|
|
176
|
-
* // ➔ [{ a: "1" }, { a: "2" }]
|
|
177
|
-
*
|
|
130
|
+
* }); // ➔ [{ a: "1" }, { a: "2" }]
|
|
178
131
|
* dedupeArray([{ a: { b: 1 } }, { a: { b: 1 } }], {
|
|
179
132
|
* forceToString: "all"
|
|
180
|
-
* });
|
|
181
|
-
* // ➔ [{ a: { b: "1" } }]
|
|
182
|
-
*
|
|
133
|
+
* }); // ➔ [{ a: { b: "1" } }]
|
|
183
134
|
* dedupeArray("not an array");
|
|
184
|
-
* // Throws TypeError
|
|
185
|
-
*
|
|
135
|
+
* // ➔ Throws TypeError
|
|
186
136
|
* dedupeArray([1, 2, 3], {
|
|
187
137
|
* forceToString: "invalid"
|
|
188
|
-
* });
|
|
189
|
-
* // Throws TypeError
|
|
138
|
+
* }); // ➔ Throws TypeError
|
|
190
139
|
* ```
|
|
191
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
|
-
* Detects whether `T` contains any number-like type (`string | number | bigint`).
|
|
142
|
+
/** Detects whether `T` contains any number-like type (`string | number | bigint`).
|
|
195
143
|
*
|
|
196
144
|
* @template T Input type.
|
|
197
145
|
* @returns `true` if `T` contains number-like, otherwise `false`.
|
|
198
146
|
*/
|
|
199
147
|
type HasNumberLike<T>=[Extract<T,string|bigint|number>] extends [never]?false:true;
|
|
200
|
-
/**
|
|
201
|
-
* Detects whether `T` contains a string type.
|
|
148
|
+
/** Detects whether `T` contains a string type.
|
|
202
149
|
*
|
|
203
150
|
* - Useful for identifying values that may fail parsing to number (`undefined` when `R=false`).
|
|
204
151
|
*
|
|
@@ -206,96 +153,76 @@ type HasNumberLike<T>=[Extract<T,string|bigint|number>] extends [never]?false:tr
|
|
|
206
153
|
* @returns `true` if `T` contains `string`, otherwise `false`.
|
|
207
154
|
*/
|
|
208
155
|
type HasString<T>=[Extract<T,string>] extends [never]?false:true;
|
|
209
|
-
/**
|
|
210
|
-
* Detects whether `T` contains non-number-like, non-nullish values
|
|
211
|
-
* (objects, arrays, symbols, functions, etc.).
|
|
156
|
+
/** Detects whether `T` contains non-number-like, non-nullish values (`objects`, `arrays`, `symbols`, `functions`, `etc`.).
|
|
212
157
|
*
|
|
213
158
|
* @template T Input type.
|
|
214
159
|
* @returns `true` if such types exist, otherwise `false`.
|
|
215
160
|
*/
|
|
216
161
|
type HasNonNumberLikeNonNullish<T>=[ Exclude<T,string|bigint|number|Nullish>] extends [never]?false:true;
|
|
217
|
-
/**
|
|
218
|
-
* Computes the return type of `toNumberArrayUnRecursive` based on input type `T` and option `R`.
|
|
162
|
+
/** Computes the return type of `toNumberArrayUnRecursive` based on input type `T` and option `R`.
|
|
219
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.
|
|
220
175
|
* @template T Input element type.
|
|
221
176
|
* @template R Flag indicating whether invalid values should be removed (`true`) or kept (`false`).
|
|
222
177
|
*
|
|
223
|
-
* Behavior:
|
|
224
|
-
*
|
|
225
|
-
* - If `R = true` (`removeInvalidValueNumber: true`):
|
|
226
|
-
* - If `T` is only `null | undefined` → returns `[]`.
|
|
227
|
-
* - If `T` contains number-like (`string | number | bigint`) → returns `number[]`.
|
|
228
|
-
* - Otherwise → returns `[]`.
|
|
229
|
-
*
|
|
230
|
-
* - If `R = false` (`removeInvalidValueNumber: false`):
|
|
231
|
-
* - Preserves `null[]` or `undefined[]` if input is purely nullish.
|
|
232
|
-
* - Otherwise returns an array of:
|
|
233
|
-
* - `number` if `T` includes number-like.
|
|
234
|
-
* - `undefined` if parsing fails (string or invalid non-number-like).
|
|
235
|
-
* - Original `null` / `undefined` from input.
|
|
236
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
|
-
* Options object for `toNumberArrayUnRecursive`.
|
|
180
|
+
/** Options object for `toNumberArrayUnRecursive`.
|
|
240
181
|
*
|
|
241
182
|
* @template T Flag indicating whether invalid values should be removed.
|
|
242
183
|
*/
|
|
243
184
|
type ToNumberArrayUnRecursiveOptions<T extends boolean>={
|
|
244
|
-
/**
|
|
245
|
-
* If true, removes invalid number values (`NaN`, non-numeric strings, `null`, `undefined`) from the result, defaultValue: `true`.
|
|
185
|
+
/** If true, removes invalid number values (`NaN`, non-numeric strings, `null`, `undefined`) from the result, defaultValue: `true`.
|
|
246
186
|
*
|
|
247
187
|
* @default true
|
|
248
188
|
*/
|
|
249
189
|
removeInvalidValueNumber?:T;};
|
|
250
190
|
/** -------------------------------------------------------
|
|
251
|
-
* * ***
|
|
191
|
+
* * ***Utility: `toNumberArrayUnRecursive`.***
|
|
252
192
|
* -------------------------------------------------------
|
|
253
|
-
*
|
|
254
|
-
* -
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
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._
|
|
263
202
|
* @template T Element type of the input array.
|
|
264
|
-
* @template
|
|
265
|
-
*
|
|
266
|
-
* @param {
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* @param {ToNumberArrayUnRecursiveOptions<RemoveInvalidValue>} [options]
|
|
270
|
-
* Options controlling conversion behavior. Defaults to `{ removeInvalidValueNumber: true }`.
|
|
271
|
-
*
|
|
272
|
-
* @returns {ToNumberArrayUnRecursiveReturn<NormalizeInput<T>, RemoveInvalidValue>}
|
|
273
|
-
*
|
|
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.
|
|
274
207
|
* @example
|
|
275
208
|
* ```ts
|
|
276
209
|
* toNumberArrayUnRecursive(['1', 2, '3']);
|
|
277
210
|
* // ➔ [1, 2, 3]
|
|
278
|
-
*
|
|
279
211
|
* toNumberArrayUnRecursive([1, null, undefined, 'abc']);
|
|
280
212
|
* // ➔ [1]
|
|
281
|
-
*
|
|
282
213
|
* toNumberArrayUnRecursive(['1', null, undefined, 'abc'], {
|
|
283
214
|
* removeInvalidValueNumber: false
|
|
284
215
|
* });
|
|
285
216
|
* // ➔ [1, null, undefined, undefined]
|
|
286
|
-
*
|
|
287
217
|
* toNumberArrayUnRecursive(null); // ➔ undefined
|
|
288
218
|
* toNumberArrayUnRecursive(undefined); // ➔ undefined
|
|
289
219
|
* toNumberArrayUnRecursive(1); // ➔ undefined
|
|
290
220
|
* ```
|
|
291
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
|
-
* Checks whether `T` contains any type that is allowed for conversion to string.
|
|
225
|
+
/** Checks whether `T` contains any type that is allowed for conversion to string.
|
|
299
226
|
*
|
|
300
227
|
* - Returns `true` if `T` contains `string`, `number`, `boolean`, or `bigint`.
|
|
301
228
|
* - Otherwise returns `false`.
|
|
@@ -303,157 +230,134 @@ type AllowedToString=string|number|boolean|bigint;
|
|
|
303
230
|
* @template T Input type to check.
|
|
304
231
|
*/
|
|
305
232
|
type HasAllowed<T>=[Extract<T,AllowedToString>] extends [never]?false:true;
|
|
306
|
-
/**
|
|
307
|
-
* Checks whether `T` contains any non-nullish value that is disallowed for conversion.
|
|
233
|
+
/** Checks whether `T` contains any non-nullish value that is disallowed for conversion.
|
|
308
234
|
*
|
|
309
|
-
* - Disallowed non-nullish types include objects
|
|
235
|
+
* - Disallowed non-nullish types include `objects`, `arrays`, `symbols`, `functions`, `etc`.
|
|
310
236
|
* - Returns `true` if such types exist, otherwise `false`.
|
|
311
|
-
*
|
|
312
237
|
* @template T Input type to check.
|
|
313
238
|
*/
|
|
314
239
|
type HasDisallowedNonNullish<T>=[Exclude<T,AllowedToString|Nullish>] extends [never]?false:true;
|
|
315
|
-
/**
|
|
316
|
-
* Computes the resulting type of `toStringArrayUnRecursive` based on input type `T` and option `R`.
|
|
240
|
+
/** Computes the resulting type of `toStringArrayUnRecursive` based on input type `T` and option `R`.
|
|
317
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`.
|
|
318
251
|
* @template T Input element type.
|
|
319
252
|
* @template R Flag indicating whether invalid values should be removed (`true`) or kept (`false`).
|
|
320
|
-
*
|
|
321
|
-
* - If `R = true` (`removeInvalidValue = true`):
|
|
322
|
-
* - If `T` contains any allowed values → `string[]`.
|
|
323
|
-
* - If `T` contains only nullish or disallowed types → `[]`.
|
|
324
|
-
*
|
|
325
|
-
* - If `R = false` (`removeInvalidValue = false`):
|
|
326
|
-
* - Include `string` if `T` has allowed values.
|
|
327
|
-
* - Include `undefined` if `T` has disallowed non-nullish values.
|
|
328
|
-
* - Preserve `null` and `undefined` from original `T`.
|
|
329
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
|
-
* Options object for `toStringArrayUnRecursive`.
|
|
255
|
+
/** Options object for `toStringArrayUnRecursive`.
|
|
333
256
|
*
|
|
334
257
|
* @template T Flag indicating whether invalid values should be removed.
|
|
335
258
|
*/
|
|
336
259
|
type ToStringArrayUnRecursiveOptions<T extends boolean>={
|
|
337
|
-
/**
|
|
338
|
-
* If true, removes invalid values (`null` and `undefined`) from the output, defaultValue: `true`.
|
|
260
|
+
/** If true, removes invalid values (`null` and `undefined`) from the output, defaultValue: `true`.
|
|
339
261
|
*
|
|
340
262
|
* @default true
|
|
341
263
|
*/
|
|
342
264
|
removeInvalidValue?:T;};
|
|
343
265
|
/** ---------------------------------------------
|
|
344
|
-
* * ***
|
|
266
|
+
* * ***Utility: `toStringArrayUnRecursive`.***
|
|
345
267
|
* ---------------------------------------------
|
|
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
|
-
* Whether to remove invalid values (`null`, `undefined`, or unsupported types). Default: `true`.
|
|
364
|
-
*
|
|
365
|
-
* @returns {RemoveInvalidValue extends true
|
|
366
|
-
* ? string[]
|
|
367
|
-
* : (string | null | undefined)[]}
|
|
368
|
-
* A new array of string representations, with invalid values optionally removed.
|
|
369
|
-
*
|
|
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.
|
|
370
285
|
* @example
|
|
371
286
|
* ```ts
|
|
372
287
|
* // Convert numbers and strings
|
|
373
288
|
* toStringArrayUnRecursive([1, 2, '3']);
|
|
374
289
|
* // ➔ ['1', '2', '3']
|
|
375
|
-
*
|
|
376
290
|
* // Remove null and undefined
|
|
377
291
|
* toStringArrayUnRecursive([1, null, undefined, 'abc'], {
|
|
378
292
|
* removeInvalidValue: true
|
|
379
293
|
* });
|
|
380
294
|
* // ➔ ['1', 'abc']
|
|
381
|
-
*
|
|
382
295
|
* // Keep null and undefined
|
|
383
296
|
* toStringArrayUnRecursive([1, null, undefined, 'abc'], {
|
|
384
297
|
* removeInvalidValue: false
|
|
385
298
|
* });
|
|
386
299
|
* // ➔ ['1', null, undefined, 'abc']
|
|
387
|
-
*
|
|
388
300
|
* // Convert boolean and bigint
|
|
389
301
|
* toStringArrayUnRecursive([true, false, 10n]);
|
|
390
302
|
* // ➔ ['true', 'false', '10']
|
|
391
|
-
*
|
|
392
303
|
* // Not an array → returns undefined
|
|
393
304
|
* toStringArrayUnRecursive(null);
|
|
394
305
|
* // ➔ undefined
|
|
395
|
-
*
|
|
396
306
|
* toStringArrayUnRecursive(undefined);
|
|
397
307
|
* // ➔ undefined
|
|
398
|
-
*
|
|
399
308
|
* toStringArrayUnRecursive(1);
|
|
400
309
|
* // ➔ undefined
|
|
401
|
-
*
|
|
402
310
|
* toStringArrayUnRecursive("string");
|
|
403
311
|
* // ➔ undefined
|
|
404
312
|
* ```
|
|
405
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
|
-
* @param {unknown} [value] - The value to be converted.
|
|
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.
|
|
420
327
|
* @returns {boolean} `true` if the value is considered non-empty, otherwise `false`.
|
|
421
|
-
*
|
|
422
328
|
* @example
|
|
423
|
-
* toBooleanContent(null);
|
|
424
|
-
* toBooleanContent(
|
|
425
|
-
* toBooleanContent("
|
|
426
|
-
* toBooleanContent("
|
|
427
|
-
* toBooleanContent("abc");
|
|
428
|
-
* toBooleanContent(
|
|
429
|
-
* toBooleanContent(
|
|
430
|
-
* toBooleanContent(
|
|
431
|
-
* toBooleanContent(
|
|
432
|
-
* toBooleanContent([
|
|
433
|
-
* toBooleanContent(
|
|
434
|
-
* toBooleanContent({
|
|
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
|
|
435
342
|
* toBooleanContent({[Symbol("key")]: 123}); // ➔ false
|
|
436
343
|
*/
|
|
437
|
-
declare const toBooleanContent:(value
|
|
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
|
-
* @param {unknown} [value] - The value to check.
|
|
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.
|
|
455
360
|
* @returns {boolean} `true` if the value or anything nested inside is non-empty, otherwise `false`.
|
|
456
|
-
*
|
|
457
361
|
* @example
|
|
458
362
|
* toBooleanContentDeep(null); // ➔ false
|
|
459
363
|
* toBooleanContentDeep(""); // ➔ false
|
|
@@ -473,7 +377,7 @@ declare const toBooleanContent:(value?:unknown)=>boolean;
|
|
|
473
377
|
* toBooleanContentDeep({ a: { b: "x" }}); // ➔ true
|
|
474
378
|
* toBooleanContentDeep({[Symbol("key")]: 123}); // ➔false
|
|
475
379
|
*/
|
|
476
|
-
declare const toBooleanContentDeep:(value
|
|
380
|
+
declare const toBooleanContentDeep:(value:unknown)=>boolean;type ToBooleanExplicitOptions={
|
|
477
381
|
/** Whether string comparison ignores case, _defaultValue: `false`_.
|
|
478
382
|
*
|
|
479
383
|
* @default false
|
|
@@ -490,89 +394,71 @@ trimString?:boolean;
|
|
|
490
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 {
|
|
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`.
|
|
510
414
|
* @returns {boolean} `true` if the value matches a truthy representation, otherwise `false`.
|
|
511
415
|
* @throws {TypeError} Throws if any option provided is not a boolean.
|
|
512
|
-
*
|
|
513
416
|
* @example
|
|
514
|
-
*
|
|
515
417
|
* toBooleanExplicit(1);
|
|
516
418
|
* // ➔ true
|
|
517
|
-
*
|
|
518
419
|
* toBooleanExplicit(true);
|
|
519
420
|
* // ➔ true
|
|
520
|
-
*
|
|
521
421
|
* toBooleanExplicit("on");
|
|
522
422
|
* // ➔ true
|
|
523
|
-
*
|
|
524
423
|
* toBooleanExplicit("1");
|
|
525
424
|
* // ➔ true
|
|
526
|
-
*
|
|
527
425
|
* toBooleanExplicit(0);
|
|
528
426
|
* // ➔ false
|
|
529
|
-
*
|
|
530
427
|
* toBooleanExplicit("off");
|
|
531
428
|
* // ➔ false
|
|
532
|
-
*
|
|
533
429
|
* toBooleanExplicit("Yes");
|
|
534
430
|
* // ➔ false (caseInsensitive is false by default)
|
|
535
|
-
*
|
|
536
431
|
* toBooleanExplicit(" yes ");
|
|
537
432
|
* // ➔ true (whitespace trimmed by default)
|
|
538
|
-
*
|
|
539
433
|
* toBooleanExplicit("YES", { caseInsensitive: true });
|
|
540
434
|
* // ➔ true
|
|
541
|
-
*
|
|
542
435
|
* toBooleanExplicit("YES", { caseInsensitive: false });
|
|
543
436
|
* // ➔ false
|
|
544
|
-
*
|
|
545
437
|
* toBooleanExplicit(" YES ", { trimString: false });
|
|
546
438
|
* // ➔ false (whitespace not trimmed)
|
|
547
|
-
*
|
|
548
439
|
* toBooleanExplicit(" YES ", { trimString: true, caseInsensitive: true });
|
|
549
440
|
* // ➔ true
|
|
550
|
-
*
|
|
551
441
|
* toBooleanExplicit(" YES ", { trimString: true, caseInsensitive: false });
|
|
552
442
|
* // ➔ false
|
|
553
|
-
*
|
|
554
443
|
* toBooleanExplicit("indeterminate");
|
|
555
444
|
* // ➔ false (default)
|
|
556
|
-
*
|
|
557
445
|
* toBooleanExplicit("indeterminate", { includeIndeterminate: true });
|
|
558
446
|
* // ➔ true
|
|
559
447
|
*/
|
|
560
|
-
declare const toBooleanExplicit:(value
|
|
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
|
-
* @param {unknown} [value] - The value to be converted.
|
|
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.
|
|
574
461
|
* @returns {boolean} `true` if the value is truthy, otherwise `false`.
|
|
575
|
-
*
|
|
576
462
|
* @example
|
|
577
463
|
* toBooleanLoose(null); // ➔ false
|
|
578
464
|
* toBooleanLoose(""); // ➔ false
|
|
@@ -584,125 +470,105 @@ declare const toBooleanExplicit:(value?:unknown,options?:ToBooleanExplicitOption
|
|
|
584
470
|
* toBooleanLoose({}); // ➔ true
|
|
585
471
|
* toBooleanLoose({ a: 1 }); // ➔ true
|
|
586
472
|
*/
|
|
587
|
-
declare const toBooleanLoose:(value
|
|
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
|
-
* - Handles bracket negatives: `"(15.000,10)"` ➔ `-15300.10`
|
|
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`.
|
|
603
488
|
* - Normalizes decimal separator (last dot or comma).
|
|
604
489
|
* - Detects non-breaking spaces (`\u00A0`, `\u202F`) often in European data.
|
|
605
490
|
* - Fallback to `0` for empty, invalid, or non-numeric strings.
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
*
|
|
610
|
-
*
|
|
611
|
-
*
|
|
612
|
-
*
|
|
613
|
-
*
|
|
614
|
-
*
|
|
615
|
-
*
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
* -
|
|
627
|
-
* -
|
|
628
|
-
* -
|
|
629
|
-
*
|
|
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)"`.
|
|
630
515
|
* @returns {number}
|
|
631
516
|
* JavaScript float representation.
|
|
632
517
|
* Will return `0` for invalid, empty, or non-string input.
|
|
633
|
-
*
|
|
634
|
-
* ***⚠️ Notes:***
|
|
635
|
-
* - You can use this function as a first step to **sanitize currency inputs**
|
|
636
|
-
* before storing into database or doing math.
|
|
637
|
-
* - Always pair this with your formatter for consistent output display.
|
|
638
|
-
*
|
|
639
518
|
* @example
|
|
640
519
|
* ```ts
|
|
641
520
|
* parseCurrencyString("Rp 15.300.000,21");
|
|
642
521
|
* // ➔ 15300000.21
|
|
643
|
-
*
|
|
644
522
|
* parseCurrencyString("15 300 000,21");
|
|
645
523
|
* // ➔ 15300000.21
|
|
646
|
-
*
|
|
647
524
|
* parseCurrencyString("CHF 15'300'000.21");
|
|
648
525
|
* // ➔ 15300000.21
|
|
649
|
-
*
|
|
650
526
|
* parseCurrencyString("$15,300,000.21");
|
|
651
527
|
* // ➔ 15300000.21
|
|
652
|
-
*
|
|
653
528
|
* parseCurrencyString("(15.000,10)");
|
|
654
529
|
* // ➔ -15000.10
|
|
655
|
-
*
|
|
656
530
|
* parseCurrencyString("1,23,456.78");
|
|
657
531
|
* // ➔ 123456.78
|
|
658
|
-
*
|
|
659
532
|
* parseCurrencyString("15300000,2121");
|
|
660
533
|
* // ➔ 15300000.2121
|
|
661
|
-
*
|
|
662
534
|
* parseCurrencyString("USD 15 300 000.21");
|
|
663
535
|
* // ➔ 15300000.21
|
|
664
|
-
*
|
|
665
536
|
* parseCurrencyString("");
|
|
666
537
|
* // ➔ 0
|
|
667
|
-
*
|
|
668
538
|
* parseCurrencyString("abc");
|
|
669
539
|
* // ➔ 0
|
|
670
540
|
* ```
|
|
671
541
|
*/
|
|
672
|
-
declare const parseCurrencyString:(input
|
|
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
|
-
* - Numeric strings with optional thousands separators (e.g. `"3,567,890.14"`) ➔ ***`number`***.
|
|
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***.
|
|
687
556
|
* - Strings containing only whitespace are converted to empty string `""`.
|
|
688
|
-
*
|
|
689
557
|
* - Non-string inputs are returned unchanged.
|
|
690
558
|
* - Strings not matching any special case are trimmed and returned as-is.
|
|
691
|
-
*
|
|
692
|
-
* @
|
|
693
|
-
* @returns {unknown} The converted JavaScript primitive (***`boolean`***, ***`number`***, ***`null`***, ***`undefined`***, ***`NaN`***) or the original value if no conversion applies.
|
|
694
|
-
*
|
|
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.
|
|
695
561
|
* @example
|
|
696
|
-
* convertType("true") // ➔ true
|
|
697
|
-
* convertType(" 42 ") // ➔ 42
|
|
698
|
-
* convertType("FALSE") // ➔ false
|
|
699
|
-
* convertType(" null ") // ➔ null
|
|
700
|
-
* convertType(" ") // ➔ ""
|
|
701
|
-
* convertType(" Hello World ") // ➔ "Hello World"
|
|
702
|
-
* convertType("NaN") // ➔ NaN
|
|
703
|
-
* convertType(100) // ➔ 100
|
|
704
|
-
* convertType(NaN) // ➔ NaN
|
|
705
|
-
* convertType({}) // ➔ {}
|
|
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({}); // ➔ {}
|
|
706
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
|
/** --------------------------------------------------
|
|
@@ -783,28 +649,24 @@ onError?:(error:Error)=>void;
|
|
|
783
649
|
*/
|
|
784
650
|
checkSymbols?:boolean;};
|
|
785
651
|
/** --------------------------------------------------
|
|
786
|
-
* * ***
|
|
787
|
-
*
|
|
788
|
-
*
|
|
652
|
+
* * ***Utility: `cleanParsedData`.***
|
|
653
|
+
* ---------------------------------------------
|
|
654
|
+
* **Cleans parsed JSON data based on provided options.**
|
|
789
655
|
* @template T - Expected output type.
|
|
790
|
-
* @param {
|
|
791
|
-
* @param {ParseParsedDataOptions} options - Cleaning options.
|
|
792
|
-
* @returns {T | undefined}
|
|
793
|
-
*
|
|
794
|
-
* ***⚠️
|
|
795
|
-
*
|
|
796
|
-
* ***⚠️ Note:*** _If using `convertDates`, result may contain Date objects. You may need type assertions in strict TypeScript settings._
|
|
797
|
-
*
|
|
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._
|
|
798
661
|
* @example
|
|
799
662
|
* ```ts
|
|
800
|
-
* // Convert numbers and remove nulls
|
|
663
|
+
* // 1: Convert numbers and remove nulls
|
|
801
664
|
* const result = cleanParsedData({ age: "25", name: null }, {
|
|
802
665
|
* convertNumbers: true,
|
|
803
666
|
* removeNulls: true
|
|
804
667
|
* });
|
|
805
668
|
* console.log(result); // ➔ { age: 25 }
|
|
806
|
-
*
|
|
807
|
-
* // Convert boolean strings
|
|
669
|
+
* // 2: Convert boolean strings
|
|
808
670
|
* const result = cleanParsedData({ isActive: "true" }, {
|
|
809
671
|
* convertBooleans: true
|
|
810
672
|
* });
|
|
@@ -813,61 +675,78 @@ checkSymbols?:boolean;};
|
|
|
813
675
|
*/
|
|
814
676
|
declare const cleanParsedData:<T=unknown>(data:T,options?:ParseParsedDataOptions)=>T|undefined|null;
|
|
815
677
|
/** --------------------------------------------------
|
|
816
|
-
* * ***
|
|
817
|
-
*
|
|
818
|
-
*
|
|
678
|
+
* * ***Utility: `parseCustomDate`.***
|
|
679
|
+
* ---------------------------------------------
|
|
680
|
+
* **Parses custom date formats like "DD/MM/YYYY" or "MM/DD/YYYY".**
|
|
819
681
|
* @param {string} dateString - Date string to parse.
|
|
820
682
|
* @param {string} format - Date format to match.
|
|
821
|
-
* @returns {Date | null}
|
|
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`...
|
|
822
705
|
*/
|
|
823
706
|
declare const parseCustomDate:(dateString:string,format:string)=>Date|null;
|
|
824
707
|
/** --------------------------------------------------
|
|
825
|
-
* * ***
|
|
826
|
-
*
|
|
827
|
-
*
|
|
828
|
-
* -
|
|
708
|
+
* * ***Utility: `safeJsonParse`.***
|
|
709
|
+
* ---------------------------------------------
|
|
710
|
+
* **Safely parses JSON while handling errors and applying transformations.**
|
|
711
|
+
* - **Supports generics** to ensure accurate return type inference.
|
|
829
712
|
* - Always provide both `<TData, TInput>` for best results.
|
|
830
|
-
* - ***Scroll down for full generic behavior explanation.***
|
|
831
|
-
* -
|
|
832
|
-
* -
|
|
833
|
-
* -
|
|
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:**
|
|
834
717
|
* 1. `null` ➔ if input is explicitly `null`.
|
|
835
718
|
* 2. `undefined` ➔ if input is `undefined`, not a `string`, or if parsing fails.
|
|
836
719
|
* 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
|
-
*
|
|
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
|
+
* ```
|
|
860
743
|
* @template TData - The expected output type after parsing and cleaning.
|
|
861
744
|
* @template TInput - The input value type, used for advanced type inference and return typing.
|
|
862
|
-
*
|
|
863
745
|
* @param {TInput} [value] - The JSON string or value to parse.
|
|
864
746
|
* @param {ParseParsedDataOptions} [options] - Options to clean, convert types, enable strict mode,
|
|
865
747
|
* support custom date formats, enable logging, or handle errors via callback.
|
|
866
|
-
*
|
|
867
748
|
* @returns {SafeJsonParseResult<TData, TInput>} Parsed and optionally cleaned result, or `null`/`undefined`.
|
|
868
|
-
*
|
|
869
749
|
* @throws {TypeError} If `options` is provided but not a valid object.
|
|
870
|
-
*
|
|
871
750
|
* @example
|
|
872
751
|
* 1. ***Basic parse with number & boolean conversion:***
|
|
873
752
|
* ```ts
|
|
@@ -990,25 +869,19 @@ declare const parseCustomDate:(dateString:string,format:string)=>Date|null;
|
|
|
990
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
|
-
* If the input is a `null`, `undefined`, results in no digits, or not a `string` or `number`,
|
|
1002
|
-
* it safely returns `0`.
|
|
1003
|
-
*
|
|
1004
|
-
* @param {string | number | null | undefined} [value]
|
|
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]
|
|
1005
880
|
* The value to process.
|
|
1006
881
|
* - Accepts a string, number, `null`, or `undefined`.
|
|
1007
|
-
*
|
|
1008
882
|
* @returns {number}
|
|
1009
883
|
* - The numeric value after extracting digits.
|
|
1010
884
|
* - Returns `0` if input is invalid or contains no digits.
|
|
1011
|
-
*
|
|
1012
885
|
* @example
|
|
1013
886
|
* extractDigits(12345); // ➔ 12345
|
|
1014
887
|
* extractDigits("9A8B7C6X1"); // ➔ 98761
|
|
@@ -1021,19 +894,18 @@ declare function safeJsonParse<TData extends Record<string,any>=Record<string,un
|
|
|
1021
894
|
* extractDigits(-Infinity); // ➔ 0
|
|
1022
895
|
* extractDigits({}); // ➔ 0
|
|
1023
896
|
* extractDigits([]); // ➔ 0
|
|
897
|
+
* extractDigits(""); // ➔ 0
|
|
898
|
+
* extractDigits(" "); // ➔ 0
|
|
1024
899
|
* extractDigits("abc"); // ➔ 0
|
|
1025
900
|
* extractDigits(" 00a "); // ➔ 0
|
|
1026
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
|
-
* The dot-notation path to the property that should be removed.
|
|
903
|
+
/** The dot-notation path to the property that should be removed.
|
|
1030
904
|
* Can target deeply nested properties (e.g., `"left.data.sensitive"`).
|
|
1031
905
|
*
|
|
1032
906
|
* This is resolved relative to the root object `T`, and supports
|
|
1033
|
-
* any valid {@link DotPath} path within it.
|
|
1034
|
-
*
|
|
907
|
+
* any valid **{@link DotPath | `DotPath`}** path within it.
|
|
1035
908
|
* @type {DotPath<T>}
|
|
1036
|
-
*
|
|
1037
909
|
* @example
|
|
1038
910
|
* const obj = {
|
|
1039
911
|
* left: { data: { sensitive: "secret", id: 1 } },
|
|
@@ -1052,15 +924,12 @@ declare const extractDigits:(value:unknown)=>number;type Prev=[never,NumberRange
|
|
|
1052
924
|
* // };
|
|
1053
925
|
*/
|
|
1054
926
|
key:DotPath<T>;
|
|
1055
|
-
/**
|
|
1056
|
-
*
|
|
1057
|
-
* including occurrences inside arrays. Defaults to `false` for single-level removal.
|
|
927
|
+
/** When `true`, removes the specified property from **all matching nested levels**,
|
|
928
|
+
* including occurrences inside arrays, defaults to `false` for single-level removal.
|
|
1058
929
|
*
|
|
1059
930
|
* Useful if the target property might appear multiple times across different
|
|
1060
931
|
* branches or array elements.
|
|
1061
|
-
*
|
|
1062
932
|
* @default false
|
|
1063
|
-
*
|
|
1064
933
|
* @example
|
|
1065
934
|
* const obj = {
|
|
1066
935
|
* items: [
|
|
@@ -1083,46 +952,39 @@ key:DotPath<T>;
|
|
|
1083
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
|
-
* * ***
|
|
955
|
+
* * ***Utility: `removeObjectPaths`.***
|
|
1087
956
|
* ------------------------------------------------------------------------
|
|
1088
|
-
*
|
|
1089
|
-
* - Features
|
|
957
|
+
* **Deletes multiple keys (shallow or deeply nested) from an object.**
|
|
958
|
+
* - **Features:**
|
|
1090
959
|
* - Removes one or more keys from an object based on their paths (supports dot notation for nested properties).
|
|
1091
960
|
* - Can delete deeply from all matching nested levels (even inside arrays) when `deep: true`.
|
|
1092
961
|
* - By default does **not mutate** the original object. Clones it first.
|
|
1093
962
|
* Set `deepClone = false` to mutate in place (useful for performance on large data).
|
|
1094
963
|
* - Ensures type safety on `key` paths via `DotPath<T>`, reducing accidental invalid paths.
|
|
1095
|
-
*
|
|
1096
|
-
* - Behavior:
|
|
964
|
+
* - **Behavior:**
|
|
1097
965
|
* - When `deep: false` (default), only deletes the direct property at the specified path.
|
|
1098
966
|
* - When `deep: true`, searches deeply and recursively deletes the key from all levels,
|
|
1099
967
|
* including inside arrays of objects (applies the *same* path repeatedly).
|
|
1100
968
|
* - Skips deletion if the specified path does not exist — no error is thrown.
|
|
1101
|
-
*
|
|
1102
|
-
* - Edge Handling:
|
|
969
|
+
* - **Edge Handling:**
|
|
1103
970
|
* - If `object` is `null` or not an object, returns an empty object.
|
|
1104
971
|
* - If `keysToDelete` is not an array of `{ key, deep? }` objects, throws a `TypeError`.
|
|
1105
972
|
* - Ignores invalid intermediate paths (will skip those branches without throwing).
|
|
1106
|
-
*
|
|
1107
973
|
* @template T - The shape of the input object, used for type-safe dot paths.
|
|
1108
|
-
*
|
|
1109
|
-
* @param {T}
|
|
1110
|
-
* @param {Array<{ key: DotPath<T>, deep?: boolean }>} keysToDelete
|
|
974
|
+
* @param {Record<string, unknown>} object - The object to remove keys from. Must be an object or will return `{}`.
|
|
975
|
+
* @param {ConfigRemoveObjectPaths<T>[]} keysToDelete
|
|
1111
976
|
* An array of instructions:
|
|
1112
977
|
* - `key`: A string path using dot notation (e.g. `"user.profile.name"`).
|
|
1113
978
|
* - `deep`: If `true`, will recursively remove all instances of the key path at any depth, defaultValue: `false`.
|
|
1114
|
-
* @param {boolean} [deepClone=true]
|
|
979
|
+
* @param {boolean|undefined} [deepClone=true]
|
|
1115
980
|
* Whether to deep clone the original object before modifying.
|
|
1116
981
|
* - `true` (default): returns a *new object* with the specified keys removed.
|
|
1117
982
|
* - `false`: modifies the original object in place and returns it.
|
|
1118
|
-
*
|
|
1119
983
|
* @returns {Partial<T>}
|
|
1120
984
|
* - A new object with specified keys removed if `deepClone` is `true`.
|
|
1121
985
|
* - The *same mutated object* if `deepClone` is `false`.
|
|
1122
|
-
*
|
|
1123
986
|
* @throws {TypeError}
|
|
1124
987
|
* - If `keysToDelete` is not an array of `{ key, deep? }` objects.
|
|
1125
|
-
*
|
|
1126
988
|
* @example
|
|
1127
989
|
* // Shallow deletion
|
|
1128
990
|
* removeObjectPaths(
|
|
@@ -1131,7 +993,6 @@ deep?:boolean;};type KeysToRemove<T,K extends readonly ConfigRemoveObjectPaths<T
|
|
|
1131
993
|
* );
|
|
1132
994
|
* // ➔ { a: 1, c: { d: 3 } }
|
|
1133
995
|
*
|
|
1134
|
-
* @example
|
|
1135
996
|
* // Nested deletion (shallow, removes only exact path)
|
|
1136
997
|
* removeObjectPaths(
|
|
1137
998
|
* { user: { profile: { name: "Alice", age: 30 } } },
|
|
@@ -1139,7 +1000,6 @@ deep?:boolean;};type KeysToRemove<T,K extends readonly ConfigRemoveObjectPaths<T
|
|
|
1139
1000
|
* );
|
|
1140
1001
|
* // ➔ { user: { profile: { name: "Alice" } } }
|
|
1141
1002
|
*
|
|
1142
|
-
* @example
|
|
1143
1003
|
* // Deep deletion (recursively removes key from all levels and arrays)
|
|
1144
1004
|
* removeObjectPaths(
|
|
1145
1005
|
* { items: [{ price: 10 }, { price: 20, details: { price: 30 } }] },
|
|
@@ -1147,30 +1007,26 @@ deep?:boolean;};type KeysToRemove<T,K extends readonly ConfigRemoveObjectPaths<T
|
|
|
1147
1007
|
* );
|
|
1148
1008
|
* // ➔ { items: [{}, { details: {} }] }
|
|
1149
1009
|
*
|
|
1150
|
-
* @example
|
|
1151
1010
|
* // Without cloning: mutates original object
|
|
1152
1011
|
* const obj = { x: 1, y: 2 };
|
|
1153
1012
|
* removeObjectPaths(obj, [{ key: "y" }], false);
|
|
1154
1013
|
* console.log(obj); // ➔ { x: 1 }
|
|
1155
1014
|
*
|
|
1156
|
-
* @example
|
|
1157
1015
|
* // No matching path — returns unchanged object
|
|
1158
1016
|
* removeObjectPaths({}, [{ key: "a" }]);
|
|
1159
1017
|
* // ➔ {}
|
|
1160
1018
|
*
|
|
1161
|
-
* @example
|
|
1162
1019
|
* // 🚫 Invalid usage — `keysToDelete` is not an array
|
|
1163
1020
|
* removeObjectPaths({}, "a");
|
|
1164
1021
|
* // ➔ throws TypeError
|
|
1165
1022
|
*
|
|
1166
|
-
* @example
|
|
1167
1023
|
* // 🚫 Invalid usage — missing `key` property in array element
|
|
1168
1024
|
* removeObjectPaths({}, [{ deep: true }]);
|
|
1169
1025
|
* // ➔ throws TypeError
|
|
1170
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
|
|
1029
|
+
* * ***Options for **{@link safeStableStringify | `safeStableStringify`}**.***
|
|
1174
1030
|
* -------------------------------------------------
|
|
1175
1031
|
*/
|
|
1176
1032
|
type SafeStableStringifyOptions={
|
|
@@ -1199,56 +1055,50 @@ sortArray?:boolean;
|
|
|
1199
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
|
-
* @param {unknown} value
|
|
1233
|
-
* - Any JavaScript value to serialize. Can be:
|
|
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:
|
|
1234
1088
|
* - Primitives (`number`, `string`, `boolean`, `bigint`, `null`, `undefined`)
|
|
1235
1089
|
* - Boxed primitives (`new Number()`, `new String()`, `new Boolean()`)
|
|
1236
1090
|
* - Arrays, plain objects, nested structures
|
|
1237
1091
|
* - Date, Map, Set
|
|
1238
1092
|
* - Circular structures
|
|
1239
|
-
*
|
|
1240
1093
|
* @param {SafeStableStringifyOptions} [options]
|
|
1241
1094
|
* - Configuration options for `safeStableStringify`:
|
|
1242
|
-
* - `sortKeys` (boolean) – Whether to sort object keys alphabetically (recursively)
|
|
1243
|
-
* - `sortArray` (boolean) – Whether to sort primitive values inside arrays
|
|
1244
|
-
* - `pretty` (boolean) – Whether to pretty-print JSON output with 2-space indentation
|
|
1245
|
-
*
|
|
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`.
|
|
1246
1098
|
* @returns {string}
|
|
1247
1099
|
* A stable JSON string representation of the input value.
|
|
1248
|
-
*
|
|
1249
1100
|
* @throws {TypeError}
|
|
1250
1101
|
* Throws if `sortKeys`, `sortArray`, or `pretty` are not strictly boolean.
|
|
1251
|
-
*
|
|
1252
1102
|
* @example
|
|
1253
1103
|
* ```ts
|
|
1254
1104
|
* // Basic object key sorting
|
|
@@ -1320,89 +1170,60 @@ pretty?:boolean;};
|
|
|
1320
1170
|
*
|
|
1321
1171
|
* // Complex nested sortArray with objects
|
|
1322
1172
|
* const arr = [9, 7, [4, 2, 3], { z: [5, 1, 6] }];
|
|
1323
|
-
* safeStableStringify(arr, { sortArray:true, sortKeys:true });
|
|
1173
|
+
* safeStableStringify(arr, { sortArray: true, sortKeys: true });
|
|
1324
1174
|
* // ➔ '[7,9,[2,3,4],{"z":[1,5,6]}]'
|
|
1325
1175
|
* ```
|
|
1326
1176
|
*/
|
|
1327
1177
|
declare const safeStableStringify:(value:unknown,options?:SafeStableStringifyOptions)=>string;
|
|
1328
1178
|
/** ----------------------------------------------------------
|
|
1329
|
-
* * ***
|
|
1330
|
-
*
|
|
1331
|
-
*
|
|
1332
|
-
* - `
|
|
1333
|
-
*
|
|
1334
|
-
*
|
|
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,
|
|
1335
1186
|
* and deeply all object properties, to strings.
|
|
1336
|
-
*
|
|
1337
|
-
*
|
|
1338
|
-
*
|
|
1339
|
-
*
|
|
1340
|
-
*
|
|
1341
|
-
*
|
|
1342
|
-
*
|
|
1343
|
-
*
|
|
1344
|
-
*
|
|
1345
|
-
*
|
|
1346
|
-
* -
|
|
1347
|
-
*
|
|
1348
|
-
*
|
|
1349
|
-
* @param {unknown} value - The value to process. Can be anything: primitive, array, object, function, etc.
|
|
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.
|
|
1350
1198
|
* @param {false | "stringOrNumber" | "primitives" | "all"} forceToString - The mode of string conversion.
|
|
1351
1199
|
* @returns {unknown} A new value with the conversion applied based on `forceToString`.
|
|
1352
|
-
*
|
|
1353
1200
|
* @example
|
|
1354
1201
|
* toStringDeepForce(42, "stringOrNumber");
|
|
1355
1202
|
* // ➔ "42"
|
|
1356
|
-
*
|
|
1357
|
-
* @example
|
|
1358
1203
|
* toStringDeepForce(true, "primitives");
|
|
1359
1204
|
* // ➔ "true"
|
|
1360
|
-
*
|
|
1361
|
-
* @example
|
|
1362
1205
|
* toStringDeepForce(null, "primitives");
|
|
1363
1206
|
* // ➔ "null"
|
|
1364
|
-
*
|
|
1365
|
-
* @example
|
|
1366
1207
|
* toStringDeepForce(Symbol("x"), "all");
|
|
1367
1208
|
* // ➔ "Symbol(x)"
|
|
1368
|
-
*
|
|
1369
|
-
* @example
|
|
1370
1209
|
* toStringDeepForce({ a: 1, b: [2, NaN] }, "primitives");
|
|
1371
1210
|
* // ➔ { a: "1", b: ["2", "NaN"] }
|
|
1372
|
-
*
|
|
1373
|
-
* @example
|
|
1374
1211
|
* toStringDeepForce(new Date("2025-01-01"), "all");
|
|
1375
1212
|
* // ➔ "2025-01-01T00:00:00.000Z"
|
|
1376
|
-
*
|
|
1377
|
-
* @example
|
|
1378
1213
|
* toStringDeepForce(() => 1, "all");
|
|
1379
1214
|
* // ➔ "() => 1"
|
|
1380
|
-
*
|
|
1381
|
-
* @example
|
|
1382
1215
|
* toStringDeepForce(/abc/i, "all");
|
|
1383
1216
|
* // ➔ "/abc/i"
|
|
1384
|
-
*
|
|
1385
|
-
* @example
|
|
1386
1217
|
* toStringDeepForce(new Map([["a", 1], ["b", 2]]), "all");
|
|
1387
1218
|
* // ➔ [["a", "1"], ["b", "2"]]
|
|
1388
|
-
*
|
|
1389
|
-
* @example
|
|
1390
1219
|
* toStringDeepForce(new Set([1, 2, 3]), "all");
|
|
1391
1220
|
* // ➔ ["1", "2", "3"]
|
|
1392
|
-
*
|
|
1393
|
-
* @example
|
|
1394
1221
|
* toStringDeepForce(new Error("Oops"), "all");
|
|
1395
1222
|
* // ➔ "Error: Oops"
|
|
1396
|
-
*
|
|
1397
|
-
* @example
|
|
1398
1223
|
* toStringDeepForce(Promise.resolve(1), "all");
|
|
1399
1224
|
* // ➔ "[object Promise]"
|
|
1400
|
-
*
|
|
1401
|
-
* @example
|
|
1402
1225
|
* toStringDeepForce({ func: () => 123 }, "all");
|
|
1403
1226
|
* // ➔ { func: "() => 123" }
|
|
1404
|
-
*
|
|
1405
|
-
* @example
|
|
1406
1227
|
* toStringDeepForce([1, "a", { b: 2 }], false);
|
|
1407
1228
|
* // ➔ [1, "a", { b: 2 }]
|
|
1408
1229
|
*/
|
|
@@ -1463,62 +1284,47 @@ removeEmptyObjects?:RemoveEmptyObjects;
|
|
|
1463
1284
|
*/
|
|
1464
1285
|
removeEmptyArrays?:RemoveEmptyArrays;};
|
|
1465
1286
|
/** --------------------------------------------------
|
|
1466
|
-
* * ***
|
|
1467
|
-
*
|
|
1468
|
-
*
|
|
1469
|
-
* Features
|
|
1470
|
-
*
|
|
1471
|
-
*
|
|
1472
|
-
*
|
|
1473
|
-
*
|
|
1474
|
-
*
|
|
1475
|
-
*
|
|
1476
|
-
*
|
|
1477
|
-
*
|
|
1287
|
+
* * ***Utility: `toNumberDeep`.***
|
|
1288
|
+
* ---------------------------------------------------
|
|
1289
|
+
* **Converts deeply nested arrays, objects, buffers, sets, maps, or typed arrays into numbers while preserving structure.**
|
|
1290
|
+
* - **Features:**
|
|
1291
|
+
* - Removes `null`, `undefined`, `NaN`, `Infinity`, `-Infinity`, empty-string, non-numeric strings, and functions.
|
|
1292
|
+
* - Recursively processes nested objects, arrays, buffers, sets, maps, and typed arrays.
|
|
1293
|
+
* - Converts numeric strings to numbers (e.g., `"3.5"` ➔ `3.5`).
|
|
1294
|
+
* - Keeps empty objects `{}` unless `removeEmptyObjects: true`.
|
|
1295
|
+
* - Keeps empty arrays `[]` unless `removeEmptyArrays: true`.
|
|
1296
|
+
* - Buffers and TypedArrays are converted into arrays of numbers.
|
|
1297
|
+
* - Date objects are converted into their timestamp (`number`).
|
|
1478
1298
|
* @template T - The input type.
|
|
1479
1299
|
* @template RemoveEmptyObjects - Whether to remove empty objects.
|
|
1480
1300
|
* @template RemoveEmptyArrays - Whether to remove empty arrays.
|
|
1481
|
-
*
|
|
1482
|
-
* @param {T} input - The input value to convert.
|
|
1301
|
+
* @param {*} input - The input value to convert.
|
|
1483
1302
|
* @param {ToNumberDeepOptions<RemoveEmptyObjects, RemoveEmptyArrays>} [options] - Conversion options.
|
|
1484
|
-
* @returns {ConvertedDeepNumber<T, RemoveEmptyObjects, RemoveEmptyArrays
|
|
1485
|
-
* - `undefined` if the input is entirely empty or filtered out by options.
|
|
1486
|
-
*
|
|
1303
|
+
* @returns {ConvertedDeepNumber<T, RemoveEmptyObjects, RemoveEmptyArrays>|undefined} The converted value, return `undefined` if the input is entirely empty or filtered out by options.
|
|
1487
1304
|
* @example
|
|
1488
1305
|
* ```ts
|
|
1489
1306
|
* toNumberDeep("123");
|
|
1490
1307
|
* // ➔ 123
|
|
1491
|
-
*
|
|
1492
1308
|
* toNumberDeep("abc");
|
|
1493
1309
|
* // ➔ undefined
|
|
1494
|
-
*
|
|
1495
1310
|
* toNumberDeep([NaN, "10", "xyz"]);
|
|
1496
1311
|
* // ➔ [10]
|
|
1497
|
-
*
|
|
1498
1312
|
* toNumberDeep({ a: "1", b: [null, "2"] });
|
|
1499
1313
|
* // ➔ { a: 1, b: [2] }
|
|
1500
|
-
*
|
|
1501
1314
|
* toNumberDeep(Buffer.from([0, 1, 2]));
|
|
1502
1315
|
* // ➔ [0, 1, 2]
|
|
1503
|
-
*
|
|
1504
1316
|
* toNumberDeep(new Set(["1", "2"]));
|
|
1505
1317
|
* // ➔ [1, 2]
|
|
1506
|
-
*
|
|
1507
1318
|
* toNumberDeep(new Map([["a", "1"], ["b", "2"]]));
|
|
1508
1319
|
* // ➔ [["a", 1], ["b", 2]]
|
|
1509
|
-
*
|
|
1510
1320
|
* toNumberDeep(new Int16Array([1, 2, 3]));
|
|
1511
1321
|
* // ➔ [1, 2, 3]
|
|
1512
|
-
*
|
|
1513
1322
|
* toNumberDeep(new Date("2025-08-16T00:00:00Z"));
|
|
1514
1323
|
* // ➔ 1755552000000
|
|
1515
|
-
*
|
|
1516
1324
|
* toNumberDeep({ a: {}, b: [] }, { removeEmptyObjects: true });
|
|
1517
1325
|
* // ➔ { b: [] }
|
|
1518
|
-
*
|
|
1519
1326
|
* toNumberDeep({ a: {}, b: [] }, { removeEmptyArrays: true });
|
|
1520
1327
|
* // ➔ { a: {} }
|
|
1521
|
-
*
|
|
1522
1328
|
* toNumberDeep({ x: {}, y: [], z: [{ a: {}, b: [] }] }, {
|
|
1523
1329
|
* removeEmptyObjects: true, removeEmptyArrays: true
|
|
1524
1330
|
* });
|
|
@@ -1571,28 +1377,25 @@ removeEmptyObjects?:RemoveEmptyObjects;
|
|
|
1571
1377
|
*/
|
|
1572
1378
|
removeEmptyArrays?:RemoveEmptyArrays;};
|
|
1573
1379
|
/** --------------------------------------------------
|
|
1574
|
-
* * ***
|
|
1575
|
-
*
|
|
1576
|
-
*
|
|
1577
|
-
* Features
|
|
1578
|
-
*
|
|
1579
|
-
*
|
|
1580
|
-
*
|
|
1581
|
-
*
|
|
1582
|
-
*
|
|
1583
|
-
*
|
|
1584
|
-
*
|
|
1585
|
-
*
|
|
1586
|
-
*
|
|
1380
|
+
* * ***Utility: `toStringDeep`.***
|
|
1381
|
+
* ---------------------------------------------------
|
|
1382
|
+
* **Converts all values in an array, object, Set, Map, or deeply nested structure to string.**
|
|
1383
|
+
* - **Features:**
|
|
1384
|
+
* - Converts numbers and strings to string (e.g., `123` ➔ `"123"`).
|
|
1385
|
+
* - Converts Date to ISO string (`Date ➔ string`).
|
|
1386
|
+
* - Converts RegExp to string (e.g., `/abc/ ➔ "/abc/"`).
|
|
1387
|
+
* - Converts Buffer, TypedArray, Set, Map, and arrays recursively to arrays of strings.
|
|
1388
|
+
* - Removes `null`, `undefined`, `NaN`, `Infinity`, `-Infinity`.
|
|
1389
|
+
* - Removes unsupported types like functions, symbols, and BigInt.
|
|
1390
|
+
* - Recursively processes nested objects, arrays, Sets, and Maps.
|
|
1391
|
+
* - Can optionally remove empty arrays (`[]`) and/or empty objects (`{}`) **recursively**.
|
|
1587
1392
|
* @template T - The input data type (primitive, object, array, Set, Map, or any nested combination).
|
|
1588
1393
|
* @template RemoveEmptyObjects - If `true`, empty objects `{}` will be removed recursively.
|
|
1589
|
-
* @template RemoveEmptyArrays - If `true`, empty arrays `[]` will be removed recursively (including arrays nested in objects/arrays/Sets/Maps).
|
|
1590
|
-
*
|
|
1591
|
-
* @param {T} input - The data to convert.
|
|
1394
|
+
* @template RemoveEmptyArrays - If `true`, empty arrays `[]` will be removed recursively (including arrays nested in `objects` / `arrays` / `Sets` / `Maps`).
|
|
1395
|
+
* @param {*} input - The data to convert.
|
|
1592
1396
|
* @param {ToStringDeepOptions<RemoveEmptyObjects, RemoveEmptyArrays>} [options] - Conversion options.
|
|
1593
|
-
* @returns {ConvertedDeepString<T, RemoveEmptyObjects, RemoveEmptyArrays
|
|
1397
|
+
* @returns {ConvertedDeepString<T, RemoveEmptyObjects, RemoveEmptyArrays>|undefined}
|
|
1594
1398
|
* The transformed data, or `undefined` if the entire structure becomes empty after processing.
|
|
1595
|
-
*
|
|
1596
1399
|
* @example
|
|
1597
1400
|
* ```ts
|
|
1598
1401
|
* // Simple array conversion
|
|
@@ -1630,4 +1433,4 @@ removeEmptyArrays?:RemoveEmptyArrays;};
|
|
|
1630
1433
|
* // ➔ undefined
|
|
1631
1434
|
* ```
|
|
1632
1435
|
*/
|
|
1633
|
-
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,
|
|
1436
|
+
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};
|