@rzl-zone/utils-js 3.12.1-beta.0 → 3.13.0-beta.2

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