@rzl-zone/utils-js 3.12.0 → 3.12.1-beta.1

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