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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/{LICENSE.md → LICENSE} +3 -3
  2. package/README.md +62 -89
  3. package/dist/.references/index.d.cts +25 -0
  4. package/dist/.references/index.d.ts +25 -0
  5. package/dist/assertIsArray-BChqwPiP.cjs +26 -0
  6. package/dist/assertIsArray-BChqwPiP.cjs.map +1 -0
  7. package/dist/assertIsArray-BfAbIUfa.js +20 -0
  8. package/dist/assertIsArray-BfAbIUfa.js.map +1 -0
  9. package/dist/assertIsBoolean-BlBct0Fc.js +1073 -0
  10. package/dist/assertIsBoolean-BlBct0Fc.js.map +1 -0
  11. package/dist/assertIsBoolean-DozdtbNi.cjs +1283 -0
  12. package/dist/assertIsBoolean-DozdtbNi.cjs.map +1 -0
  13. package/dist/assertIsString-Bvk7bUL7.cjs +26 -0
  14. package/dist/assertIsString-Bvk7bUL7.cjs.map +1 -0
  15. package/dist/assertIsString-DqV9NwbI.js +20 -0
  16. package/dist/assertIsString-DqV9NwbI.js.map +1 -0
  17. package/dist/assertions/index.cjs +37 -40
  18. package/dist/assertions/index.cjs.map +1 -0
  19. package/dist/assertions/index.d.cts +12 -0
  20. package/dist/assertions/index.d.ts +10 -824
  21. package/dist/assertions/index.js +30 -13
  22. package/dist/assertions/index.js.map +1 -0
  23. package/dist/conversions/index.cjs +34 -103
  24. package/dist/conversions/index.d.cts +12 -0
  25. package/dist/conversions/index.d.ts +10 -1791
  26. package/dist/conversions/index.js +14 -24
  27. package/dist/conversions-CBs8-REq.cjs +448 -0
  28. package/dist/conversions-CBs8-REq.cjs.map +1 -0
  29. package/dist/conversions-EMJa3g-D.js +382 -0
  30. package/dist/conversions-EMJa3g-D.js.map +1 -0
  31. package/dist/events/index.cjs +55 -31
  32. package/dist/events/index.cjs.map +1 -0
  33. package/dist/events/index.d.cts +174 -0
  34. package/dist/events/index.d.ts +31 -35
  35. package/dist/events/index.js +50 -12
  36. package/dist/events/index.js.map +1 -0
  37. package/dist/formatEnvPort-DpIXzPAZ.js +159 -0
  38. package/dist/formatEnvPort-DpIXzPAZ.js.map +1 -0
  39. package/dist/formatEnvPort-hHNvOim-.cjs +171 -0
  40. package/dist/formatEnvPort-hHNvOim-.cjs.map +1 -0
  41. package/dist/formatters/index.cjs +21 -61
  42. package/dist/formatters/index.d.cts +12 -0
  43. package/dist/formatters/index.d.ts +10 -2152
  44. package/dist/formatters/index.js +10 -18
  45. package/dist/formatters-QcZO_Cpx.js +367 -0
  46. package/dist/formatters-QcZO_Cpx.js.map +1 -0
  47. package/dist/formatters-lAYgA11L.cjs +427 -0
  48. package/dist/formatters-lAYgA11L.cjs.map +1 -0
  49. package/dist/generators/index.cjs +161 -41
  50. package/dist/generators/index.cjs.map +1 -0
  51. package/dist/generators/index.d.cts +12 -0
  52. package/dist/generators/index.d.ts +10 -338
  53. package/dist/generators/index.js +154 -14
  54. package/dist/generators/index.js.map +1 -0
  55. package/dist/index-26W7ItWx.d.ts +760 -0
  56. package/dist/index-BPPQjAfs.d.cts +2359 -0
  57. package/dist/index-BXjlgBLz.d.cts +2139 -0
  58. package/dist/index-B_Wwo91H.d.ts +2359 -0
  59. package/dist/index-CpufydcI.d.cts +704 -0
  60. package/dist/index-Czc4O526.d.ts +333 -0
  61. package/dist/index-DPs1_p5G.d.cts +760 -0
  62. package/dist/index-DRpOyBSC.d.ts +1703 -0
  63. package/dist/index-DWWvtHUn.d.cts +822 -0
  64. package/dist/index-DnM0LD0n.d.cts +333 -0
  65. package/dist/index-GUZ9fK6T.d.ts +2139 -0
  66. package/dist/index-I4fAzwXV.d.ts +704 -0
  67. package/dist/index-JDrOl_19.d.ts +822 -0
  68. package/dist/index-b66P49Qe.d.cts +1703 -0
  69. package/dist/isBigInt-B1cijjqm.cjs +20 -0
  70. package/dist/isBigInt-B1cijjqm.cjs.map +1 -0
  71. package/dist/isBigInt-C0bN0Rhu.js +14 -0
  72. package/dist/isBigInt-C0bN0Rhu.js.map +1 -0
  73. package/dist/isEmptyObject-DI42NEo0.cjs +37 -0
  74. package/dist/isEmptyObject-DI42NEo0.cjs.map +1 -0
  75. package/dist/isEmptyObject-DeLVIJpl.js +25 -0
  76. package/dist/isEmptyObject-DeLVIJpl.js.map +1 -0
  77. package/dist/isEmptyString-BTUWYTbw.js +15 -0
  78. package/dist/isEmptyString-BTUWYTbw.js.map +1 -0
  79. package/dist/isEmptyString-CCK3bP74.cjs +21 -0
  80. package/dist/isEmptyString-CCK3bP74.cjs.map +1 -0
  81. package/dist/isEmptyValue-DMSMFTU8.cjs +30 -0
  82. package/dist/isEmptyValue-DMSMFTU8.cjs.map +1 -0
  83. package/dist/isEmptyValue-fjnfQnt5.js +24 -0
  84. package/dist/isEmptyValue-fjnfQnt5.js.map +1 -0
  85. package/dist/isEqual-B1fRgEuU.cjs +111 -0
  86. package/dist/isEqual-B1fRgEuU.cjs.map +1 -0
  87. package/dist/isEqual-DhyP8fB_.js +87 -0
  88. package/dist/isEqual-DhyP8fB_.js.map +1 -0
  89. package/dist/isFinite-BYMOo0os.js +15 -0
  90. package/dist/isFinite-BYMOo0os.js.map +1 -0
  91. package/dist/isFinite-sFkps2TY.cjs +21 -0
  92. package/dist/isFinite-sFkps2TY.cjs.map +1 -0
  93. package/dist/isInteger-DS9V7l_f.js +14 -0
  94. package/dist/isInteger-DS9V7l_f.js.map +1 -0
  95. package/dist/isInteger-FTCthMre.cjs +20 -0
  96. package/dist/isInteger-FTCthMre.cjs.map +1 -0
  97. package/dist/isPlainObject-DcFGh3_5.d.ts +530 -0
  98. package/dist/isPlainObject-doTI11Ib.d.cts +530 -0
  99. package/dist/isServer-D1TXfOs3.js +14 -0
  100. package/dist/isServer-D1TXfOs3.js.map +1 -0
  101. package/dist/isServer-q-QLFCqE.cjs +20 -0
  102. package/dist/isServer-q-QLFCqE.cjs.map +1 -0
  103. package/dist/isTypedArray-47R0wdrc.js +31 -0
  104. package/dist/isTypedArray-47R0wdrc.js.map +1 -0
  105. package/dist/isTypedArray-DiCoqffZ.cjs +43 -0
  106. package/dist/isTypedArray-DiCoqffZ.cjs.map +1 -0
  107. package/dist/isURL-CQiowFq2.js +14 -0
  108. package/dist/isURL-CQiowFq2.js.map +1 -0
  109. package/dist/isURL-WZypXsax.cjs +20 -0
  110. package/dist/isURL-WZypXsax.cjs.map +1 -0
  111. package/dist/isValidDomain-BSXshgkC.cjs +1788 -0
  112. package/dist/isValidDomain-BSXshgkC.cjs.map +1 -0
  113. package/dist/isValidDomain-DwA2EN79.js +1782 -0
  114. package/dist/isValidDomain-DwA2EN79.js.map +1 -0
  115. package/dist/next/index.cjs +119 -212
  116. package/dist/next/index.cjs.map +1 -0
  117. package/dist/next/index.d.cts +226 -0
  118. package/dist/next/index.d.ts +26 -31
  119. package/dist/next/index.js +117 -210
  120. package/dist/next/index.js.map +1 -0
  121. package/dist/next/server/index.cjs +25 -40
  122. package/dist/next/server/index.cjs.map +1 -0
  123. package/dist/next/server/index.d.cts +39 -0
  124. package/dist/next/server/index.d.ts +9 -10
  125. package/dist/next/server/index.js +23 -38
  126. package/dist/next/server/index.js.map +1 -0
  127. package/dist/noop-B2mTBhW-.cjs +18 -0
  128. package/dist/noop-B2mTBhW-.cjs.map +1 -0
  129. package/dist/noop-BzktGBVz.js +12 -0
  130. package/dist/noop-BzktGBVz.js.map +1 -0
  131. package/dist/normalizeSpaces-DQHR3Tlr.cjs +29 -0
  132. package/dist/normalizeSpaces-DQHR3Tlr.cjs.map +1 -0
  133. package/dist/normalizeSpaces-WS_iERJk.js +23 -0
  134. package/dist/normalizeSpaces-WS_iERJk.js.map +1 -0
  135. package/dist/normalizeString-2WLth_Gj.js +15 -0
  136. package/dist/normalizeString-2WLth_Gj.js.map +1 -0
  137. package/dist/normalizeString-D8euBcRD.cjs +21 -0
  138. package/dist/normalizeString-D8euBcRD.cjs.map +1 -0
  139. package/dist/operations/index.cjs +65 -32
  140. package/dist/operations/index.cjs.map +1 -0
  141. package/dist/operations/index.d.cts +139 -0
  142. package/dist/operations/index.d.ts +10 -15
  143. package/dist/operations/index.js +61 -17
  144. package/dist/operations/index.js.map +1 -0
  145. package/dist/parsers/index.cjs +12 -19
  146. package/dist/parsers/index.d.cts +239 -0
  147. package/dist/parsers/index.d.ts +71 -72
  148. package/dist/parsers/index.js +10 -12
  149. package/dist/parsers-DXtpsDyj.cjs +649 -0
  150. package/dist/parsers-DXtpsDyj.cjs.map +1 -0
  151. package/dist/parsers-Dpuq-V4u.js +643 -0
  152. package/dist/parsers-Dpuq-V4u.js.map +1 -0
  153. package/dist/parsing-B43x1sxn.js +50 -0
  154. package/dist/parsing-B43x1sxn.js.map +1 -0
  155. package/dist/parsing-lRoxn1Nz.cjs +56 -0
  156. package/dist/parsing-lRoxn1Nz.cjs.map +1 -0
  157. package/dist/predicates/index.cjs +91 -296
  158. package/dist/predicates/index.d.cts +13 -0
  159. package/dist/predicates/index.d.ts +12 -2482
  160. package/dist/predicates/index.js +23 -25
  161. package/dist/predicates-DiaYA7Ps.cjs +413 -0
  162. package/dist/predicates-DiaYA7Ps.cjs.map +1 -0
  163. package/dist/predicates-gNepszvo.js +257 -0
  164. package/dist/predicates-gNepszvo.js.map +1 -0
  165. package/dist/promises/index.cjs +76 -24
  166. package/dist/promises/index.cjs.map +1 -0
  167. package/dist/promises/index.d.cts +123 -0
  168. package/dist/promises/index.d.ts +28 -31
  169. package/dist/promises/index.js +73 -13
  170. package/dist/promises/index.js.map +1 -0
  171. package/dist/punyCode-CTWXVVFo.cjs +185 -0
  172. package/dist/punyCode-CTWXVVFo.cjs.map +1 -0
  173. package/dist/punyCode-hmiFzLWT.js +179 -0
  174. package/dist/punyCode-hmiFzLWT.js.map +1 -0
  175. package/dist/removeSpaces-BE8lfh-4.js +19 -0
  176. package/dist/removeSpaces-BE8lfh-4.js.map +1 -0
  177. package/dist/removeSpaces-DRRxNWlb.cjs +25 -0
  178. package/dist/removeSpaces-DRRxNWlb.cjs.map +1 -0
  179. package/dist/safeJsonParse-BBnQElk8.cjs +208 -0
  180. package/dist/safeJsonParse-BBnQElk8.cjs.map +1 -0
  181. package/dist/safeJsonParse-CXruaP0p.js +184 -0
  182. package/dist/safeJsonParse-CXruaP0p.js.map +1 -0
  183. package/dist/safeStableStringify-BNh3D0K0.js +88 -0
  184. package/dist/safeStableStringify-BNh3D0K0.js.map +1 -0
  185. package/dist/safeStableStringify-Cc62pfRp.cjs +106 -0
  186. package/dist/safeStableStringify-Cc62pfRp.cjs.map +1 -0
  187. package/dist/strings/index.cjs +76 -81
  188. package/dist/strings/index.cjs.map +1 -0
  189. package/dist/strings/index.d.cts +12 -0
  190. package/dist/strings/index.d.ts +10 -775
  191. package/dist/strings/index.js +59 -14
  192. package/dist/strings/index.js.map +1 -0
  193. package/dist/tailwind/index.cjs +19 -47
  194. package/dist/tailwind/index.d.cts +12 -0
  195. package/dist/tailwind/index.d.ts +11 -712
  196. package/dist/tailwind/index.js +10 -12
  197. package/dist/tailwind-DJ4cmLUw.cjs +247 -0
  198. package/dist/tailwind-DJ4cmLUw.cjs.map +1 -0
  199. package/dist/tailwind-IJvOdkZp.js +199 -0
  200. package/dist/tailwind-IJvOdkZp.js.map +1 -0
  201. package/dist/toStringArrayUnRecursive-CFs0jTEg.js +39 -0
  202. package/dist/toStringArrayUnRecursive-CFs0jTEg.js.map +1 -0
  203. package/dist/toStringArrayUnRecursive-xUaU8Ot9.cjs +51 -0
  204. package/dist/toStringArrayUnRecursive-xUaU8Ot9.cjs.map +1 -0
  205. package/dist/urls/index.cjs +129 -57
  206. package/dist/urls/index.cjs.map +1 -0
  207. package/dist/urls/index.d.cts +740 -0
  208. package/dist/urls/index.d.ts +218 -224
  209. package/dist/urls/index.js +121 -26
  210. package/dist/urls/index.js.map +1 -0
  211. package/package.json +203 -194
  212. package/dist/chunk-22V4WP3H.js +0 -53
  213. package/dist/chunk-2XSZ2ANI.js +0 -63
  214. package/dist/chunk-3T6VSWYX.js +0 -21
  215. package/dist/chunk-5WIEDF2J.js +0 -1823
  216. package/dist/chunk-6EDFZJZ5.cjs +0 -598
  217. package/dist/chunk-6LXWT2I5.js +0 -32
  218. package/dist/chunk-6YGBRENU.js +0 -209
  219. package/dist/chunk-7FGNVDEV.cjs +0 -38
  220. package/dist/chunk-AXDYWO67.js +0 -119
  221. package/dist/chunk-B6PMNZ4M.cjs +0 -35
  222. package/dist/chunk-BAV5T2E3.cjs +0 -15
  223. package/dist/chunk-BLF7SD66.js +0 -95
  224. package/dist/chunk-BMZZXZJ2.cjs +0 -30
  225. package/dist/chunk-BOYP3ARU.js +0 -264
  226. package/dist/chunk-BPYW5YL7.js +0 -16
  227. package/dist/chunk-C2PV3VWC.cjs +0 -118
  228. package/dist/chunk-CCJ2MSN7.js +0 -16
  229. package/dist/chunk-DAPAK2W3.cjs +0 -123
  230. package/dist/chunk-DLS3G6WQ.cjs +0 -23
  231. package/dist/chunk-DNMCR5JH.js +0 -370
  232. package/dist/chunk-DVMHRLKP.cjs +0 -16
  233. package/dist/chunk-EBYFYZW4.cjs +0 -26
  234. package/dist/chunk-ENMRZ4BE.js +0 -302
  235. package/dist/chunk-FJ4BQFVO.js +0 -587
  236. package/dist/chunk-GIKL4PUF.cjs +0 -106
  237. package/dist/chunk-GOFINGT6.js +0 -35
  238. package/dist/chunk-GXKQ3LHF.js +0 -101
  239. package/dist/chunk-HNBRGN4R.js +0 -24
  240. package/dist/chunk-HYN6FC5A.cjs +0 -249
  241. package/dist/chunk-IZGVBYFN.js +0 -242
  242. package/dist/chunk-JIE447J5.js +0 -676
  243. package/dist/chunk-JXEIJM5M.cjs +0 -237
  244. package/dist/chunk-K47GZDBH.js +0 -115
  245. package/dist/chunk-K5536YHG.cjs +0 -269
  246. package/dist/chunk-KHO2SBNA.cjs +0 -16
  247. package/dist/chunk-KXJ7X325.cjs +0 -308
  248. package/dist/chunk-L5RDAVVH.js +0 -14
  249. package/dist/chunk-LJHPTLWB.js +0 -109
  250. package/dist/chunk-M7ELWZXM.cjs +0 -1825
  251. package/dist/chunk-MSUW5VHZ.js +0 -1590
  252. package/dist/chunk-MUHRPRR7.cjs +0 -65
  253. package/dist/chunk-MV3TSQSH.cjs +0 -397
  254. package/dist/chunk-NLZLXWAU.cjs +0 -678
  255. package/dist/chunk-NVRZPF5M.cjs +0 -18
  256. package/dist/chunk-ONZFBJVW.js +0 -14
  257. package/dist/chunk-PGNL7JXO.cjs +0 -251
  258. package/dist/chunk-Q4GEQS7X.cjs +0 -564
  259. package/dist/chunk-QNKGP5DY.js +0 -14
  260. package/dist/chunk-QYI2VJLS.cjs +0 -211
  261. package/dist/chunk-RBWZII5I.js +0 -59
  262. package/dist/chunk-RMP7VMPB.cjs +0 -33
  263. package/dist/chunk-RZOGBYIS.js +0 -21
  264. package/dist/chunk-SU3UELUB.cjs +0 -36
  265. package/dist/chunk-SYHPSOUU.cjs +0 -1626
  266. package/dist/chunk-SZUNAEMR.js +0 -246
  267. package/dist/chunk-TER22LO4.cjs +0 -64
  268. package/dist/chunk-TJHGRQ4P.js +0 -33
  269. package/dist/chunk-U23I7JPB.cjs +0 -56
  270. package/dist/chunk-U7HHN47R.js +0 -552
  271. package/dist/chunk-UDA26MCU.cjs +0 -16
  272. package/dist/chunk-UIAWUZ4H.js +0 -31
  273. package/dist/chunk-ULQPCIA2.js +0 -16
  274. package/dist/chunk-VJDDGRIK.cjs +0 -16
  275. package/dist/chunk-WETQI6HM.js +0 -232
  276. package/dist/chunk-WLOQQFDS.cjs +0 -18
  277. package/dist/chunk-WVSPXFTY.js +0 -14
  278. package/dist/chunk-WXFTVXBF.cjs +0 -23
  279. package/dist/chunk-XPVTIGU2.cjs +0 -113
  280. package/dist/chunk-XX6RUGTM.cjs +0 -18
  281. package/dist/chunk-YWHHVDT4.js +0 -13
  282. package/dist/chunk-ZPDMWDGZ.cjs +0 -101
  283. package/dist/chunk-ZVWZEGQP.js +0 -28
  284. package/dist/index.d.ts +0 -24
  285. package/dist/isPlainObject-0p3VveWr.d.ts +0 -534
  286. package/dist/rzl-utils.global.js +0 -10
@@ -1,41 +1,26 @@
1
1
  /*!
2
- * ====================================================
3
- * Rzl Utils-JS.
4
- * ----------------------------------------------------
5
- * Version: 3.11.1.
6
- * Author: Rizalvin Dwiky.
7
- * Repository: https://github.com/rzl-zone/utils-js.
8
- * ====================================================
9
- */
10
- import { isFunction, assertIsBoolean } from '../../chunk-MSUW5VHZ.js';
11
- import 'server-only';
12
- import { NextRequest } from 'next/server';
13
-
14
- var getClientIpOrUrl = (request, includeFullUrl = true) => {
15
- if (!isFunction(NextRequest)) {
16
- throw new Error(
17
- "Function `getClientIpOrUrl` is designed to be used in a `NextJS` environment."
18
- );
19
- }
20
- if (!(request instanceof NextRequest)) {
21
- throw new TypeError(
22
- "First parameter (`request`) must be an `instance of NextRequest` from `NextJS`."
23
- );
24
- }
25
- assertIsBoolean(includeFullUrl, {
26
- message: ({ currentType, validType }) => `Second parameter (\`includeFullUrl\`) must be of type \`${validType}\`, but received: \`${currentType}\`.`
27
- });
28
- const forwardedIps = (request.headers.get("x-forwarded-for") ?? "127.0.0.1").trim().split(",");
29
- if (forwardedIps[0] === "::ffff:127.0.0.1" || forwardedIps[0] === "::1") {
30
- forwardedIps[0] = "127.0.0.1";
31
- }
32
- const clientIp = forwardedIps.length > 1 ? forwardedIps[forwardedIps.length - 1].trim() : forwardedIps[0];
33
- if (!includeFullUrl) {
34
- return clientIp;
35
- }
36
- const protocol = request.headers.get("x-forwarded-proto") || "http";
37
- const port = request.headers.get("x-forwarded-port") || "3000";
38
- return `${process.env.NODE_ENV === "production" ? protocol : "http"}://${clientIp}:${port}`;
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
+ import { P as isFunction, t as assertIsBoolean } from "../../assertIsBoolean-BlBct0Fc.js";
11
+ import "@rzl-zone/node-only";
12
+ import { NextRequest } from "next/server";
13
+ const getClientIpOrUrl = (request, includeFullUrl = true) => {
14
+ if (!isFunction(NextRequest)) throw new Error("Function `getClientIpOrUrl` is designed to be used in a `NextJS` environment.");
15
+ if (!(request instanceof NextRequest)) throw new TypeError("First parameter (`request`) must be an `instance of NextRequest` from `NextJS`.");
16
+ assertIsBoolean(includeFullUrl, { message: ({ currentType, validType }) => `Second parameter (\`includeFullUrl\`) must be of type \`${validType}\`, but received: \`${currentType}\`.` });
17
+ const forwardedIps = (request.headers.get("x-forwarded-for") ?? "127.0.0.1").trim().split(",");
18
+ if (forwardedIps[0] === "::ffff:127.0.0.1" || forwardedIps[0] === "::1") forwardedIps[0] = "127.0.0.1";
19
+ const clientIp = forwardedIps.length > 1 ? forwardedIps[forwardedIps.length - 1]?.trim() || "" : forwardedIps[0] || "";
20
+ if (!includeFullUrl) return clientIp;
21
+ const protocol = request.headers.get("x-forwarded-proto") || "http";
22
+ const port = request.headers.get("x-forwarded-port") || "3000";
23
+ return `${process.env.NODE_ENV === "production" ? protocol : "http"}://${clientIp}:${port}`;
39
24
  };
40
-
41
25
  export { getClientIpOrUrl };
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/next/server/getClientIpOrUrl.ts"],"sourcesContent":["import \"@rzl-zone/node-only\";\n\nimport { NextRequest } from \"next/server\";\n\nimport { isFunction } from \"@/predicates/is/isFunction\";\nimport { assertIsBoolean } from \"@/assertions/booleans/assertIsBoolean\";\n\n/** ---------------------------------\n * * ***Utility for NextJS Server: `getClientIpOrUrl`.***\n * ---------------------------------\n * **Retrieves the real client IP address and constructs the full URL using headers like `x-forwarded-for`, `x-forwarded-proto`, and `x-forwarded-port`.**\n * - **ℹ️ Note:**\n * - Only supported in **Next.js** environments (specifically in `server-only` contexts).\n * - Should be used in **middleware**, **route-handler** or **server actions** that have access to ***[`NextRequest - NextJS`](https://nextjs.org/docs/app/api-reference/functions/next-request)***.\n * @param {NextRequest} request - The incoming ***`NextJS`*** request object, must be instanceof `NextRequest` from `next/server`.\n * @param {boolean|undefined} [includeFullUrl=true] - Whether to return the full URL (`protocol`, `IP`, and `port` like `protocol://ip:port`) or just the IP address, defaultValue: `true`.\n * @returns {string} The extracted client IP address or the full constructed URL.\n * @throws **{@link Error | `Error`}** if the function is used outside a Next.js server environment.\n * @throws **{@link TypeError | `TypeError`}** if the arguments do not match the expected types.\n * @example\n * // Basic usage in Next.js middleware\n * import { NextRequest } from \"next/server\";\n * import { getClientIpOrUrl } from \"@rzl-zone/utils-js/next/server\";\n *\n * export function middleware(request: NextRequest) {\n * const clientIp = getClientIpOrUrl(request, false);\n * console.log(\"Client IP:\", clientIp);\n * }\n *\n * // Get full URL\n * const url = getClientIpOrUrl(request);\n * console.log(\"Client full URL:\", url);\n */\nexport const getClientIpOrUrl = (\n request: NextRequest,\n includeFullUrl: boolean = true\n): string => {\n // Ensure we're in a Next.js edge/server environment\n if (!isFunction(NextRequest)) {\n throw new Error(\n \"Function `getClientIpOrUrl` is designed to be used in a `NextJS` environment.\"\n );\n }\n\n if (!(request instanceof NextRequest)) {\n throw new TypeError(\n \"First parameter (`request`) must be an `instance of NextRequest` from `NextJS`.\"\n );\n }\n\n assertIsBoolean(includeFullUrl, {\n message: ({ currentType, validType }) =>\n `Second parameter (\\`includeFullUrl\\`) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n });\n\n const forwardedIps = (request.headers.get(\"x-forwarded-for\") ?? \"127.0.0.1\")\n .trim()\n .split(\",\");\n\n // Normalize IPv6 loopback addresses\n if (forwardedIps[0] === \"::ffff:127.0.0.1\" || forwardedIps[0] === \"::1\") {\n forwardedIps[0] = \"127.0.0.1\";\n }\n\n // Get the last non-empty IP from the list (more reliable for real client IP)\n const clientIp: string =\n forwardedIps.length > 1\n ? forwardedIps[forwardedIps.length - 1]?.trim() || \"\"\n : forwardedIps[0] || \"\";\n\n if (!includeFullUrl) {\n return clientIp;\n }\n\n // Construct full URL using protocol, IP, and port\n const protocol = request.headers.get(\"x-forwarded-proto\") || \"http\";\n // const protocol = \"http\";\n const port = request.headers.get(\"x-forwarded-port\") || \"3000\";\n\n return `${\n process.env.NODE_ENV === \"production\" ? protocol : \"http\"\n }://${clientIp}:${port}`;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,oBACX,SACA,iBAA0B,SACf;CAEX,IAAI,CAAC,WAAW,YAAY,EAC1B,MAAM,IAAI,MACR,gFACD;CAGH,IAAI,EAAE,mBAAmB,cACvB,MAAM,IAAI,UACR,kFACD;CAGH,gBAAgB,gBAAgB,EAC9B,UAAU,EAAE,aAAa,gBACvB,2DAA2D,UAAU,sBAAsB,YAAY,MAC1G,CAAC;CAEF,MAAM,gBAAgB,QAAQ,QAAQ,IAAI,kBAAkB,IAAI,aAC7D,MAAM,CACN,MAAM,IAAI;CAGb,IAAI,aAAa,OAAO,sBAAsB,aAAa,OAAO,OAChE,aAAa,KAAK;CAIpB,MAAM,WACJ,aAAa,SAAS,IAClB,aAAa,aAAa,SAAS,IAAI,MAAM,IAAI,KACjD,aAAa,MAAM;CAEzB,IAAI,CAAC,gBACH,OAAO;CAIT,MAAM,WAAW,QAAQ,QAAQ,IAAI,oBAAoB,IAAI;CAE7D,MAAM,OAAO,QAAQ,QAAQ,IAAI,mBAAmB,IAAI;CAExD,OAAO,GACL,QAAQ,IAAI,aAAa,eAAe,WAAW,OACpD,KAAK,SAAS,GAAG"}
@@ -0,0 +1,18 @@
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
+ "use strict";
11
+ const noop = () => {};
12
+ Object.defineProperty(exports, 'noop', {
13
+ enumerable: true,
14
+ get: function () {
15
+ return noop;
16
+ }
17
+ });
18
+ //# sourceMappingURL=noop-B2mTBhW-.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noop-B2mTBhW-.cjs","names":[],"sources":["../src/generators/utils/noop.ts"],"sourcesContent":["/**\n * --------------------------------------------------\n * * ***Utility: `noop`.***\n * --------------------------------------------------\n * **A no-operation function that performs no action.**\n *\n * @description\n * Commonly used as a **placeholder**, **default callback**, or **stub function**.\n *\n * - **Behavior**:\n * - Does not return any meaningful value (`void`).\n * - Safely callable in any context without side effects.\n *\n * @remarks\n * Although this function returns `void`, it implicitly results in `undefined`,\n * but the return value should never be relied upon.\n *\n * @example\n * **1. Basic usage** — does nothing and returns undefined implicitly:\n * ```\n * import { noop } from \"@rzl-zone/utils-js/generators\";\n *\n * noop(); // ➔ no effect (void)\n * ```\n * @example\n * **2. Using with type-checking helpers:**\n * ```ts\n * import { noop } from \"@rzl-zone/utils-js/generators\";\n * import { isFunction, isUndefined } from \"@rzl-zone/utils-js/predicates\";\n *\n * isFunction(noop); // ➔ true — `noop` is a function\n * isUndefined(noop()); // ➔ true — calling `noop()` returns `undefined`\n * isFunction(noop()); // ➔ false — the return value is `undefined`, not a function\n * ```\n * @example\n * **3. As a default callback:**\n * ```ts\n * import { noop } from \"@rzl-zone/utils-js/generators\";\n *\n * const callback = noop;\n * callback(); // ➔ no effect (void)\n * ```\n */\nexport const noop = (): void => {};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAa,aAAmB"}
@@ -0,0 +1,12 @@
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
+ const noop = () => {};
11
+ export { noop as t };
12
+ //# sourceMappingURL=noop-BzktGBVz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noop-BzktGBVz.js","names":[],"sources":["../src/generators/utils/noop.ts"],"sourcesContent":["/**\n * --------------------------------------------------\n * * ***Utility: `noop`.***\n * --------------------------------------------------\n * **A no-operation function that performs no action.**\n *\n * @description\n * Commonly used as a **placeholder**, **default callback**, or **stub function**.\n *\n * - **Behavior**:\n * - Does not return any meaningful value (`void`).\n * - Safely callable in any context without side effects.\n *\n * @remarks\n * Although this function returns `void`, it implicitly results in `undefined`,\n * but the return value should never be relied upon.\n *\n * @example\n * **1. Basic usage** — does nothing and returns undefined implicitly:\n * ```\n * import { noop } from \"@rzl-zone/utils-js/generators\";\n *\n * noop(); // ➔ no effect (void)\n * ```\n * @example\n * **2. Using with type-checking helpers:**\n * ```ts\n * import { noop } from \"@rzl-zone/utils-js/generators\";\n * import { isFunction, isUndefined } from \"@rzl-zone/utils-js/predicates\";\n *\n * isFunction(noop); // ➔ true — `noop` is a function\n * isUndefined(noop()); // ➔ true — calling `noop()` returns `undefined`\n * isFunction(noop()); // ➔ false — the return value is `undefined`, not a function\n * ```\n * @example\n * **3. As a default callback:**\n * ```ts\n * import { noop } from \"@rzl-zone/utils-js/generators\";\n *\n * const callback = noop;\n * callback(); // ➔ no effect (void)\n * ```\n */\nexport const noop = (): void => {};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAa,aAAmB"}
@@ -0,0 +1,29 @@
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
+ "use strict";
11
+ const require_assertIsBoolean = require('./assertIsBoolean-DozdtbNi.cjs');
12
+ const normalizeSpaces = (value, options = {
13
+ withTrim: true,
14
+ trimOnly: false
15
+ }) => {
16
+ if (!require_assertIsBoolean.isNonEmptyString(value)) return "";
17
+ if (!require_assertIsBoolean.isPlainObject(options)) options = {};
18
+ const { trimOnly = false, withTrim = true } = options;
19
+ if (trimOnly) return value.trim();
20
+ if (withTrim) value = value.trim();
21
+ return value.replace(/\s+/g, " ");
22
+ };
23
+ Object.defineProperty(exports, 'normalizeSpaces', {
24
+ enumerable: true,
25
+ get: function () {
26
+ return normalizeSpaces;
27
+ }
28
+ });
29
+ //# sourceMappingURL=normalizeSpaces-DQHR3Tlr.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeSpaces-DQHR3Tlr.cjs","names":["isNonEmptyString","isPlainObject"],"sources":["../src/strings/sanitizations/normalizeSpaces.ts"],"sourcesContent":["import { isPlainObject } from \"@/predicates/is/isPlainObject\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\ntype NormalizeSpacesOptions = {\n /** If `true`, skips normalization and only trims whitespace from start & end, defaultValue: `false`.\n *\n * @default false\n */\n trimOnly?: boolean;\n /** If `false`, skips trimming value, defaultValue: `true`.\n *\n * @default true\n */\n withTrim?: boolean;\n};\n\n/** ----------------------------------------------------------\n * * ***Utility: `normalizeSpaces`.***\n * ----------------------------------------------------------\n * **Normalizes whitespace in a string by reducing multiple spaces\n * to a single space, optionally trims, or only trims based on options.**\n * - **Behavior:**\n * - Collapses all consecutive whitespace (spaces, tabs, newlines) into a single space.\n * - Can trim leading/trailing spaces (default behavior), or preserve them with `withTrim: false`.\n * - Can skip normalization entirely and only trim using `trimOnly: true`.\n * - Returns an empty string if input is `null` or `undefined`.\n * @param {string | null | undefined} value - The input string to be processed. If `null` or `undefined`, returns an empty string.\n * @param {NormalizeSpacesOptions} [options] - Configuration options.\n * @param {NormalizeSpacesOptions[\"trimOnly\"]} [options.trimOnly=false] - If `true`, skips normalization and only trims the string.\n * @param {NormalizeSpacesOptions[\"withTrim\"]} [options.withTrim=true] - If `false`, preserves leading/trailing whitespace.\n * @returns {string} The processed string.\n * @example\n * normalizeSpaces(\" Hello World\\tthis is\\n\\nok \");\n * // ➔ \"Hello World this is ok\"\n * normalizeSpaces(\" Hello World\\tthis is\\n\\nok \", { trimOnly: true });\n * // ➔ \"Hello World\tthis is\\n\\nok\"\n * normalizeSpaces(\" Hello World \", { withTrim: false });\n * // ➔ \" Hello World \"\n * normalizeSpaces(null);\n * // ➔ \"\"\n */\nexport const normalizeSpaces = (\n value: string | null | undefined,\n options: NormalizeSpacesOptions = {\n withTrim: true,\n trimOnly: false\n }\n): string => {\n if (!isNonEmptyString(value)) return \"\";\n\n if (!isPlainObject(options)) {\n options = {};\n }\n\n const { trimOnly = false, withTrim = true } = options;\n\n if (trimOnly) return value.trim();\n\n if (withTrim) {\n value = value.trim();\n }\n\n // Remove all duplicate spaces (including tabs, newlines, etc.)\n return value.replace(/\\s+/g, \" \");\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,mBACX,OACA,UAAkC;CAChC,UAAU;CACV,UAAU;CACX,KACU;CACX,IAAI,CAACA,yCAAiB,MAAM,EAAE,OAAO;CAErC,IAAI,CAACC,sCAAc,QAAQ,EACzB,UAAU,EAAE;CAGd,MAAM,EAAE,WAAW,OAAO,WAAW,SAAS;CAE9C,IAAI,UAAU,OAAO,MAAM,MAAM;CAEjC,IAAI,UACF,QAAQ,MAAM,MAAM;CAItB,OAAO,MAAM,QAAQ,QAAQ,IAAI"}
@@ -0,0 +1,23 @@
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
+ import { A as isPlainObject, y as isNonEmptyString } from "./assertIsBoolean-BlBct0Fc.js";
11
+ const normalizeSpaces = (value, options = {
12
+ withTrim: true,
13
+ trimOnly: false
14
+ }) => {
15
+ if (!isNonEmptyString(value)) return "";
16
+ if (!isPlainObject(options)) options = {};
17
+ const { trimOnly = false, withTrim = true } = options;
18
+ if (trimOnly) return value.trim();
19
+ if (withTrim) value = value.trim();
20
+ return value.replace(/\s+/g, " ");
21
+ };
22
+ export { normalizeSpaces as t };
23
+ //# sourceMappingURL=normalizeSpaces-WS_iERJk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeSpaces-WS_iERJk.js","names":[],"sources":["../src/strings/sanitizations/normalizeSpaces.ts"],"sourcesContent":["import { isPlainObject } from \"@/predicates/is/isPlainObject\";\nimport { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\ntype NormalizeSpacesOptions = {\n /** If `true`, skips normalization and only trims whitespace from start & end, defaultValue: `false`.\n *\n * @default false\n */\n trimOnly?: boolean;\n /** If `false`, skips trimming value, defaultValue: `true`.\n *\n * @default true\n */\n withTrim?: boolean;\n};\n\n/** ----------------------------------------------------------\n * * ***Utility: `normalizeSpaces`.***\n * ----------------------------------------------------------\n * **Normalizes whitespace in a string by reducing multiple spaces\n * to a single space, optionally trims, or only trims based on options.**\n * - **Behavior:**\n * - Collapses all consecutive whitespace (spaces, tabs, newlines) into a single space.\n * - Can trim leading/trailing spaces (default behavior), or preserve them with `withTrim: false`.\n * - Can skip normalization entirely and only trim using `trimOnly: true`.\n * - Returns an empty string if input is `null` or `undefined`.\n * @param {string | null | undefined} value - The input string to be processed. If `null` or `undefined`, returns an empty string.\n * @param {NormalizeSpacesOptions} [options] - Configuration options.\n * @param {NormalizeSpacesOptions[\"trimOnly\"]} [options.trimOnly=false] - If `true`, skips normalization and only trims the string.\n * @param {NormalizeSpacesOptions[\"withTrim\"]} [options.withTrim=true] - If `false`, preserves leading/trailing whitespace.\n * @returns {string} The processed string.\n * @example\n * normalizeSpaces(\" Hello World\\tthis is\\n\\nok \");\n * // ➔ \"Hello World this is ok\"\n * normalizeSpaces(\" Hello World\\tthis is\\n\\nok \", { trimOnly: true });\n * // ➔ \"Hello World\tthis is\\n\\nok\"\n * normalizeSpaces(\" Hello World \", { withTrim: false });\n * // ➔ \" Hello World \"\n * normalizeSpaces(null);\n * // ➔ \"\"\n */\nexport const normalizeSpaces = (\n value: string | null | undefined,\n options: NormalizeSpacesOptions = {\n withTrim: true,\n trimOnly: false\n }\n): string => {\n if (!isNonEmptyString(value)) return \"\";\n\n if (!isPlainObject(options)) {\n options = {};\n }\n\n const { trimOnly = false, withTrim = true } = options;\n\n if (trimOnly) return value.trim();\n\n if (withTrim) {\n value = value.trim();\n }\n\n // Remove all duplicate spaces (including tabs, newlines, etc.)\n return value.replace(/\\s+/g, \" \");\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,mBACX,OACA,UAAkC;CAChC,UAAU;CACV,UAAU;CACX,KACU;CACX,IAAI,CAAC,iBAAiB,MAAM,EAAE,OAAO;CAErC,IAAI,CAAC,cAAc,QAAQ,EACzB,UAAU,EAAE;CAGd,MAAM,EAAE,WAAW,OAAO,WAAW,SAAS;CAE9C,IAAI,UAAU,OAAO,MAAM,MAAM;CAEjC,IAAI,UACF,QAAQ,MAAM,MAAM;CAItB,OAAO,MAAM,QAAQ,QAAQ,IAAI"}
@@ -0,0 +1,15 @@
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
+ import { y as isNonEmptyString } from "./assertIsBoolean-BlBct0Fc.js";
11
+ const normalizeString = (input) => {
12
+ return isNonEmptyString(input) ? input.trim() : "";
13
+ };
14
+ export { normalizeString as t };
15
+ //# sourceMappingURL=normalizeString-2WLth_Gj.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeString-2WLth_Gj.js","names":[],"sources":["../src/strings/sanitizations/normalizeString.ts"],"sourcesContent":["import { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\n/** ----------------------------------------------------------\n * * ***Utility: `normalizeString`.***\n * ----------------------------------------------------------\n * **Normalizes a string by ensuring it is a valid string and trimming whitespace.**\n * - **Behavior:**\n * - If the input is `undefined`, `null`, or an `empty string` after trimming,\n * it returns an empty string `(\"\")`.\n * @param {string | undefined | null} input - The input string to be normalize. If `null` or `undefined`, returns an empty string.\n * @returns {string} A trimmed string or an empty string if the input is invalid.\n * @example\n * normalizeString(\" Hello World \");\n * // ➔ \"Hello World\"\n * normalizeString(\" Hello World \");\n * // ➔ \"Hello World\"\n * normalizeString(\"\");\n * // ➔ \"\"\n * normalizeString(null);\n * // ➔ \"\"\n * normalizeString(undefined);\n * // ➔ \"\"\n */\nexport const normalizeString = (input: string | null | undefined): string => {\n return isNonEmptyString(input) ? input.trim() : \"\";\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,mBAAmB,UAA6C;CAC3E,OAAO,iBAAiB,MAAM,GAAG,MAAM,MAAM,GAAG"}
@@ -0,0 +1,21 @@
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
+ "use strict";
11
+ const require_assertIsBoolean = require('./assertIsBoolean-DozdtbNi.cjs');
12
+ const normalizeString = (input) => {
13
+ return require_assertIsBoolean.isNonEmptyString(input) ? input.trim() : "";
14
+ };
15
+ Object.defineProperty(exports, 'normalizeString', {
16
+ enumerable: true,
17
+ get: function () {
18
+ return normalizeString;
19
+ }
20
+ });
21
+ //# sourceMappingURL=normalizeString-D8euBcRD.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeString-D8euBcRD.cjs","names":["isNonEmptyString"],"sources":["../src/strings/sanitizations/normalizeString.ts"],"sourcesContent":["import { isNonEmptyString } from \"@/predicates/is/isNonEmptyString\";\n\n/** ----------------------------------------------------------\n * * ***Utility: `normalizeString`.***\n * ----------------------------------------------------------\n * **Normalizes a string by ensuring it is a valid string and trimming whitespace.**\n * - **Behavior:**\n * - If the input is `undefined`, `null`, or an `empty string` after trimming,\n * it returns an empty string `(\"\")`.\n * @param {string | undefined | null} input - The input string to be normalize. If `null` or `undefined`, returns an empty string.\n * @returns {string} A trimmed string or an empty string if the input is invalid.\n * @example\n * normalizeString(\" Hello World \");\n * // ➔ \"Hello World\"\n * normalizeString(\" Hello World \");\n * // ➔ \"Hello World\"\n * normalizeString(\"\");\n * // ➔ \"\"\n * normalizeString(null);\n * // ➔ \"\"\n * normalizeString(undefined);\n * // ➔ \"\"\n */\nexport const normalizeString = (input: string | null | undefined): string => {\n return isNonEmptyString(input) ? input.trim() : \"\";\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,mBAAmB,UAA6C;CAC3E,OAAOA,yCAAiB,MAAM,GAAG,MAAM,MAAM,GAAG"}
@@ -1,33 +1,66 @@
1
1
  /*!
2
- * ====================================================
3
- * Rzl Utils-JS.
4
- * ----------------------------------------------------
5
- * Version: 3.11.1.
6
- * Author: Rizalvin Dwiky.
7
- * Repository: https://github.com/rzl-zone/utils-js.
8
- * ====================================================
9
- */
10
- 'use strict';
11
-
12
- var chunkXPVTIGU2_cjs = require('../chunk-XPVTIGU2.cjs');
13
- require('../chunk-K5536YHG.cjs');
14
- require('../chunk-GIKL4PUF.cjs');
15
- require('../chunk-7FGNVDEV.cjs');
16
- require('../chunk-DLS3G6WQ.cjs');
17
- require('../chunk-BAV5T2E3.cjs');
18
- require('../chunk-DAPAK2W3.cjs');
19
- require('../chunk-UDA26MCU.cjs');
20
- require('../chunk-SYHPSOUU.cjs');
21
-
22
- Object.defineProperty(exports, "findDuplicates", {
23
- enumerable: true,
24
- get: function () { return chunkXPVTIGU2_cjs.findDuplicates; }
25
- });
26
- Object.defineProperty(exports, "omitKeys", {
27
- enumerable: true,
28
- get: function () { return chunkXPVTIGU2_cjs.omitKeys; }
29
- });
30
- Object.defineProperty(exports, "omitKeysDeep", {
31
- enumerable: true,
32
- get: function () { return chunkXPVTIGU2_cjs.omitKeysDeep; }
33
- });
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
+ "use strict";
11
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
12
+ const require_assertIsBoolean = require('../assertIsBoolean-DozdtbNi.cjs');
13
+ const require_assertIsArray = require('../assertIsArray-BChqwPiP.cjs');
14
+ const require_isEmptyObject = require('../isEmptyObject-DI42NEo0.cjs');
15
+ const require_safeStableStringify = require('../safeStableStringify-Cc62pfRp.cjs');
16
+ const require_isEqual = require('../isEqual-B1fRgEuU.cjs');
17
+ const require_safeJsonParse = require('../safeJsonParse-BBnQElk8.cjs');
18
+ const findDuplicates = (values) => {
19
+ require_assertIsArray.assertIsArray(values, { message: ({ currentType, validType }) => `First parameter (\`values\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.` });
20
+ const duplicates = [];
21
+ values.forEach((item, index) => {
22
+ for (let i = index + 1; i < values.length; i++) if (require_isEqual.isEqual(item, values[i])) {
23
+ if (!duplicates.some((dup) => require_isEqual.isEqual(dup, item))) duplicates.push(item);
24
+ break;
25
+ }
26
+ });
27
+ return duplicates;
28
+ };
29
+ const omitKeys = (object, keysToOmit) => {
30
+ if (!require_assertIsBoolean.isPlainObject(object)) return {};
31
+ require_assertIsArray.assertIsArray(keysToOmit, { message: ({ currentType, validType }) => `Second parameter (\`keysToOmit\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.` });
32
+ const duplicates = findDuplicates(keysToOmit);
33
+ if (duplicates.length > 0) throw new Error(`Function "omitKeys" Error: Duplicate keys detected - \`${duplicates}\``);
34
+ return Object.fromEntries(Object.entries(object).filter(([key]) => !keysToOmit.includes(key)));
35
+ };
36
+ const omitKeysDeep = (object, keysToOmit) => {
37
+ if (!require_assertIsBoolean.isPlainObject(object)) return {};
38
+ require_assertIsArray.assertIsArray(keysToOmit, { message: ({ currentType, validType }) => `Second parameter (\`keysToOmit\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.` });
39
+ const duplicates = findDuplicates(keysToOmit);
40
+ if (require_assertIsBoolean.isNonEmptyArray(duplicates)) throw new Error(`Function "omitKeysDeep" Error: Duplicate keys detected - \`${require_safeStableStringify.safeStableStringify(duplicates, { keepUndefined: true })}\`.`);
41
+ const omitAtPath = (obj, pathParts) => {
42
+ if (!require_assertIsBoolean.isObjectOrArray(obj)) return obj;
43
+ const [current, ...rest] = pathParts;
44
+ if (require_isEmptyObject.isEmptyArray(rest)) if (require_assertIsBoolean.isArray(obj)) {
45
+ const index = parseInt(current);
46
+ if (!require_assertIsBoolean.isNaN(index) && index in obj) obj.splice(index, 1);
47
+ } else delete obj[current];
48
+ else {
49
+ const next = obj[current];
50
+ if (require_assertIsBoolean.isObjectOrArray(next)) obj[current] = omitAtPath(next, rest);
51
+ }
52
+ return obj;
53
+ };
54
+ const deepRemoveEmptyObjects = (obj) => {
55
+ if (require_assertIsBoolean.isArray(obj)) return obj.map(deepRemoveEmptyObjects).filter((item) => !(require_assertIsBoolean.isObjectOrArray(item) && Object.keys(item).length === 0));
56
+ if (require_assertIsBoolean.isObjectOrArray(obj)) return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, deepRemoveEmptyObjects(v)]).filter(([, v]) => !require_assertIsBoolean.isUndefined(v) && !(require_assertIsBoolean.isObjectOrArray(v) && Object.keys(v).length === 0)));
57
+ return obj;
58
+ };
59
+ const result = require_safeJsonParse.safeJsonParse(require_safeStableStringify.safeStableStringify(object));
60
+ for (const key of keysToOmit) omitAtPath(result, key.split("."));
61
+ return deepRemoveEmptyObjects(result);
62
+ };
63
+ exports.findDuplicates = findDuplicates;
64
+ exports.omitKeys = omitKeys;
65
+ exports.omitKeysDeep = omitKeysDeep;
66
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["isEqual","isPlainObject","isPlainObject","isNonEmptyArray","safeStableStringify","isObjectOrArray","isEmptyArray","isArray","isNaN","isUndefined","safeJsonParse"],"sources":["../../src/operations/findDuplicates.ts","../../src/operations/omitKeys.ts","../../src/operations/omitKeysDeep.ts"],"sourcesContent":["import { isEqual } from \"@/predicates/is/isEqual\";\nimport { assertIsArray } from \"@/assertions/objects/assertIsArray\";\n\n/** ----------------------------------------------------------------------\n * * ***Utility: `findDuplicates`.***\n * ----------------------------------------------------------------------\n * **Finds duplicate values in an array by deep equality comparison.**\n * - **Behavior:**\n * - Uses ***`isEqual` utility function*** to compare elements\n * (handles objects, arrays, dates, NaN, etc.).\n * - Returns a new array containing only the *first occurrences* of duplicated values.\n * - Does **not mutate** the original array.\n * - Throws ***{@link TypeError | `TypeError`}*** if input is not an array.\n * @template T Type of elements in the input array.\n * @param {T[]} values - The array to check for duplicates.\n * @returns {T[]} An array of the duplicate values found in the input,\n * preserving order of their first duplicate appearance.\n * @throws **{@link TypeError | `TypeError`}** if the provided `values` argument is not an array.\n * @example\n * findDuplicates([1, 2, 2, 3, 4, 4]);\n * // ➔ [2, 4]\n * findDuplicates([\"apple\", \"banana\", \"apple\", \"orange\"]);\n * // ➔ [\"apple\"]\n * findDuplicates([{ a: 1 }, { a: 1 }, { a: 2 }]);\n * // ➔ [{ a: 1 }]\n * findDuplicates([NaN, NaN, 1]);\n * // ➔ [NaN]\n * findDuplicates([true, false, true]);\n * // ➔ [true]\n * findDuplicates([1, 2, 3]);\n * // ➔ []\n */\nexport const findDuplicates = <T>(values: T[]): T[] => {\n assertIsArray(values, {\n message: ({ currentType, validType }) =>\n `First parameter (\\`values\\`) must be of type \\`${validType}\\` (array literal or instance), but received: \\`${currentType}\\`.`\n });\n\n const duplicates: T[] = [];\n values.forEach((item, index) => {\n for (let i = index + 1; i < values.length; i++) {\n if (isEqual(item, values[i])) {\n if (!duplicates.some((dup) => isEqual(dup, item))) {\n duplicates.push(item);\n }\n break;\n }\n }\n });\n\n return duplicates;\n};\n","import { findDuplicates } from \"./findDuplicates\";\nimport { isPlainObject } from \"@/predicates/is/isPlainObject\";\nimport { assertIsArray } from \"@/assertions/objects/assertIsArray\";\n\n/** --------------------------------\n * * ***Utility: `omitKeys`.***\n * --------------------------------\n * **This function creates a shallow copy of the given object omitting the\n * specified keys.**\n * - **Behavior:**\n * - It will return a new object without mutating the original.\n * - It also validates that ***`keysToOmit`*** does not contain duplicate keys.\n * - **ℹ️ Internally:**\n * - It uses ***`isEqual`*** to check for duplicates in\n * the ***`keysToOmit`*** array.\n * @template I The type of the input object.\n * @template K The keys to omit from the object.\n * @param {I} object - The source object to omit keys from.\n * @param {K[]} keysToOmit - An array of keys to exclude from the returned object.\n * @returns {Omit<I, K>} A new object without the specified keys.\n * @throws **{@link TypeError | `TypeError`}** if `keysToOmit` is not an array.\n * @throws **{@link Error | `Error`}** if duplicate keys are found in `keysToOmit`.\n * @example\n * omitKeys({ a: 1, b: 2, c: 3 }, [\"b\", \"c\"]);\n * //➔ { a: 1 }\n * omitKeys({ name: \"John\", age: 30 }, [\"age\"]);\n * //➔ { name: \"John\" }\n * omitKeys({ a: 1, b: 2 }, []);\n * //➔ { a: 1, b: 2 } (no changes)\n */\nexport const omitKeys = <I extends Record<string, unknown>, K extends keyof I>(\n object: I,\n keysToOmit: K[]\n): Omit<I, K> => {\n if (!isPlainObject(object)) return {} as Omit<I, K>;\n\n assertIsArray(keysToOmit, {\n message: ({ currentType, validType }) =>\n `Second parameter (\\`keysToOmit\\`) must be of type \\`${validType}\\` (array literal or instance), but received: \\`${currentType}\\`.`\n });\n\n // Check for duplicate keys\n const duplicates = findDuplicates(keysToOmit);\n if (duplicates.length > 0) {\n throw new Error(\n `Function \"omitKeys\" Error: Duplicate keys detected - \\`${duplicates}\\``\n );\n }\n\n // Remove specified keys\n return Object.fromEntries(\n Object.entries(object).filter(([key]) => !keysToOmit.includes(key as K))\n ) as Omit<I, K>;\n};\n","import type { NumberRangeUnion } from \"@rzl-zone/ts-types-plus\";\n\nimport { findDuplicates } from \"./findDuplicates\";\n\nimport { isNaN } from \"@/predicates/is/isNaN\";\nimport { isArray } from \"@/predicates/is/isArray\";\nimport { isUndefined } from \"@/predicates/is/isUndefined\";\nimport { isEmptyArray } from \"@/predicates/is/isEmptyArray\";\nimport { isPlainObject } from \"@/predicates/is/isPlainObject\";\nimport { isNonEmptyArray } from \"@/predicates/is/isNonEmptyArray\";\nimport { isObjectOrArray } from \"@/predicates/is/isObjectOrArray\";\n\nimport { assertIsArray } from \"@/assertions/objects/assertIsArray\";\n\nimport { safeJsonParse } from \"@/conversions/json/safeJsonParse\";\nimport { safeStableStringify } from \"@/conversions/stringify/safeStableStringify\";\n\ntype IndexArray = NumberRangeUnion<0, 30>;\ntype DotPath<T, Prev extends string = \"\"> =\n T extends Array<infer U>\n ? DotPath<U, `${Prev}${Prev extends \"\" ? \"\" : \".\"}${IndexArray}`>\n : T extends object\n ? {\n [K in keyof T & string]:\n | `${Prev}${Prev extends \"\" ? \"\" : \".\"}${K}`\n | DotPath<T[K], `${Prev}${Prev extends \"\" ? \"\" : \".\"}${K}`>;\n }[keyof T & string]\n : never;\n\n/** ------------------------------------------------------\n * * ***Utility: `omitKeysDeep`.***\n * ------------------------------------------------------\n * **Recursively omits properties from an object using dot notation paths.**\n * - **Behavior:**\n * - Removes resulting empty objects (`{}`) and arrays (`[]`), cascading upwards\n * to remove empty parents until root if needed.\n * - **⚠️ Be careful:**\n * - If after omission an object or array becomes empty, it will be removed entirely\n * including all the way up to the root if necessary, resulting in `{}`.\n * - **ℹ️ Note:**\n * - For array indices, TypeScript autocomplete only suggests `0`–`30`\n * (to prevent editor lag on large unions).\n * However, higher indices are still fully supported at runtime — you can\n * manually type `\"arr.99.key\"` and it will work the same.\n * @template I - Type of the input object\n * @param {I} object\n * The object to process, should be a plain nested object or array structure.\n * @param {DotPath<I>[]} keysToOmit\n * An array of string paths in dot notation indicating the properties to remove, paths\n * can include numeric indices to target array elements, e.g. `\"arr.0.x\"` to\n * remove `x` from the first object inside the `arr` array.\n * @returns {Partial<I>}\n * A new deeply cloned object with the specified keys omitted, with resulting\n * empty objects or arrays fully removed (even if it collapses to `{}`).\n * @throws **{@link TypeError | `TypeError`}** if `keysToOmit` is not an array.\n * @throws **{@link Error | `Error`}** if `keysToOmit` contains duplicate paths.\n * @example\n * omitKeysDeep({ arr: [{ a: 1 }] }, [\"arr.0.a\"]);\n * // ➔ {} (array becomes empty and removed)\n * omitKeysDeep({ a: { b: { c: 1 }, d: 2 }, e: 3 }, [\"a.b.c\"]);\n * // ➔ { a: { d: 2 }, e: 3 }\n * omitKeysDeep({ a: [{ b: 1 }, { c: 2 }] }, [\"a.0.b\"]);\n * // ➔ { a: [{ c: 2 }] }\n * omitKeysDeep({ a: [{ b: 1 }] }, [\"a.0.b\"]);\n * // ➔ {} (array becomes empty and removed)\n * omitKeysDeep({ complex: [{ deep: [{ x: 1, y: 2 }] }] }, [\"complex.0.deep.0.x\"]);\n * // ➔ { complex: [{ deep: [{ y: 2 }] }] }\n * omitKeysDeep({ complex: [{ deep: [{ x: 1 }] }] }, [\"complex.0.deep.0.x\"]);\n * // ➔ {} (deep chain emptied and collapsed)\n * omitKeysDeep({ data: [[{ foo: 1, bar: 2 }]] }, [\"data.0.0.foo\"]);\n * // ➔ { data: [[{ bar: 2 }]] }\n * omitKeysDeep({ data: [[{ foo: 1 }]] }, [\"data.0.0.foo\"]);\n * // ➔ {} (nested arrays emptied completely)\n * omitKeysDeep({ x: [{ y: [{ z: 1 }, { w: 2 }] }] }, [\"x.0.y.0.z\"]);\n * // ➔ { x: [{ y: [{ w: 2 }] }] }\n * omitKeysDeep({ x: [{ y: [{ z: 1 }] }] }, [\"x.0.y.0.z\"]);\n * // ➔ {} (entire nested arrays removed)\n * omitKeysDeep({ p: { q: { r: 5 } }, s: 6 }, [\"p.q.r\"]);\n * // ➔ { s: 6 } (`p` removed because it becomes empty)\n * omitKeysDeep({ arr: [{ a: 1, b: 2 }, { c: 3 }] }, [\"arr.0.a\"]);\n * // ➔ { arr: [{ b: 2 }, { c: 3 }] }\n * omitKeysDeep({ root: [{ sub: [{ leaf: 10 }] }] }, [\"root.0.sub.0.leaf\"]);\n * // ➔ {} (deep nested arrays emptied to root)\n * omitKeysDeep({ meta: { tags: [\"x\", \"y\"], count: 2 } }, [\"meta.count\"]);\n * // ➔ { meta: { tags: [\"x\", \"y\"] } }\n * omitKeysDeep({ arr: [[{ a: 1 }, { b: 2 }]] }, [\"arr.0.0.a\"]);\n * // ➔ { arr: [[{ b: 2 }]] }\n * omitKeysDeep({ arr: [[{ a: 1 }]] }, [\"arr.0.0.a\"]);\n * // ➔ {} (double nested emptied)\n * omitKeysDeep({ nested: [{ list: [{ id: 1, val: 2 }] }] }, [\"nested.0.list.0.val\"]);\n * // ➔ { nested: [{ list: [{ id: 1 }] }] }\n * omitKeysDeep({ nested: [{ list: [{ id: 1 }] }] }, [\"nested.0.list.0.id\"]);\n * // ➔ {} (full collapse to empty)\n * omitKeysDeep({ mixed: { a: [1, 2, 3], b: { c: 4 } } }, [\"mixed.b.c\"]);\n * // ➔ { mixed: { a: [1, 2, 3] } }\n */\nexport const omitKeysDeep = <I extends Record<string, unknown>>(\n object: I,\n keysToOmit: DotPath<I>[]\n): Partial<I> => {\n if (!isPlainObject(object)) return {} as Partial<I>;\n\n assertIsArray(keysToOmit, {\n message: ({ currentType, validType }) =>\n `Second parameter (\\`keysToOmit\\`) must be of type \\`${validType}\\` (array literal or instance), but received: \\`${currentType}\\`.`\n });\n\n const duplicates = findDuplicates(keysToOmit);\n if (isNonEmptyArray(duplicates)) {\n throw new Error(\n `Function \"omitKeysDeep\" Error: Duplicate keys detected - \\`${safeStableStringify(\n duplicates,\n {\n keepUndefined: true\n }\n )}\\`.`\n );\n }\n\n const omitAtPath = (obj: unknown, pathParts: string[]) => {\n if (!isObjectOrArray(obj)) return obj;\n\n const [current, ...rest] = pathParts;\n\n if (isEmptyArray(rest)) {\n if (isArray(obj)) {\n // Support numeric index\n const index = parseInt(current);\n if (!isNaN(index) && index in obj) {\n obj.splice(index, 1);\n }\n } else {\n delete obj[current];\n }\n } else {\n const next = obj[current];\n if (isObjectOrArray(next)) {\n obj[current] = omitAtPath(next, rest);\n }\n }\n return obj;\n };\n\n const deepRemoveEmptyObjects = (obj: unknown): unknown => {\n if (isArray(obj)) {\n return obj\n .map(deepRemoveEmptyObjects)\n .filter(\n (item) => !(isObjectOrArray(item) && Object.keys(item).length === 0)\n );\n }\n if (isObjectOrArray(obj)) {\n const cleaned = Object.fromEntries(\n Object.entries(obj)\n .map(([k, v]) => [k, deepRemoveEmptyObjects(v)])\n .filter(\n ([, v]) =>\n !isUndefined(v) &&\n !(isObjectOrArray(v) && Object.keys(v).length === 0)\n )\n );\n return cleaned;\n }\n return obj;\n };\n\n const result = safeJsonParse(safeStableStringify(object)); // clone deep to avoid mutating original\n for (const key of keysToOmit) {\n const parts = key.split(\".\");\n omitAtPath(result, parts);\n }\n\n return deepRemoveEmptyObjects(result) as Partial<I>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,kBAAqB,WAAqB;CACrD,oCAAc,QAAQ,EACpB,UAAU,EAAE,aAAa,gBACvB,kDAAkD,UAAU,kDAAkD,YAAY,MAC7H,CAAC;CAEF,MAAM,aAAkB,EAAE;CAC1B,OAAO,SAAS,MAAM,UAAU;EAC9B,KAAK,IAAI,IAAI,QAAQ,GAAG,IAAI,OAAO,QAAQ,KACzC,IAAIA,wBAAQ,MAAM,OAAO,GAAG,EAAE;GAC5B,IAAI,CAAC,WAAW,MAAM,QAAQA,wBAAQ,KAAK,KAAK,CAAC,EAC/C,WAAW,KAAK,KAAK;GAEvB;;GAGJ;CAEF,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACpBT,MAAa,YACX,QACA,eACe;CACf,IAAI,CAACC,sCAAc,OAAO,EAAE,OAAO,EAAE;CAErC,oCAAc,YAAY,EACxB,UAAU,EAAE,aAAa,gBACvB,uDAAuD,UAAU,kDAAkD,YAAY,MAClI,CAAC;CAGF,MAAM,aAAa,eAAe,WAAW;CAC7C,IAAI,WAAW,SAAS,GACtB,MAAM,IAAI,MACR,0DAA0D,WAAW,IACtE;CAIH,OAAO,OAAO,YACZ,OAAO,QAAQ,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,SAAS,IAAS,CAAC,CACzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC4CH,MAAa,gBACX,QACA,eACe;CACf,IAAI,CAACC,sCAAc,OAAO,EAAE,OAAO,EAAE;CAErC,oCAAc,YAAY,EACxB,UAAU,EAAE,aAAa,gBACvB,uDAAuD,UAAU,kDAAkD,YAAY,MAClI,CAAC;CAEF,MAAM,aAAa,eAAe,WAAW;CAC7C,IAAIC,wCAAgB,WAAW,EAC7B,MAAM,IAAI,MACR,8DAA8DC,gDAC5D,YACA,EACE,eAAe,MAChB,CACF,CAAC,KACH;CAGH,MAAM,cAAc,KAAc,cAAwB;EACxD,IAAI,CAACC,wCAAgB,IAAI,EAAE,OAAO;EAElC,MAAM,CAAC,SAAS,GAAG,QAAQ;EAE3B,IAAIC,mCAAa,KAAK,EACpB,IAAIC,gCAAQ,IAAI,EAAE;GAEhB,MAAM,QAAQ,SAAS,QAAQ;GAC/B,IAAI,CAACC,8BAAM,MAAM,IAAI,SAAS,KAC5B,IAAI,OAAO,OAAO,EAAE;SAGtB,OAAO,IAAI;OAER;GACL,MAAM,OAAO,IAAI;GACjB,IAAIH,wCAAgB,KAAK,EACvB,IAAI,WAAW,WAAW,MAAM,KAAK;;EAGzC,OAAO;;CAGT,MAAM,0BAA0B,QAA0B;EACxD,IAAIE,gCAAQ,IAAI,EACd,OAAO,IACJ,IAAI,uBAAuB,CAC3B,QACE,SAAS,EAAEF,wCAAgB,KAAK,IAAI,OAAO,KAAK,KAAK,CAAC,WAAW,GACnE;EAEL,IAAIA,wCAAgB,IAAI,EAUtB,OATgB,OAAO,YACrB,OAAO,QAAQ,IAAI,CAChB,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,uBAAuB,EAAE,CAAC,CAAC,CAC/C,QACE,GAAG,OACF,CAACI,oCAAY,EAAE,IACf,EAAEJ,wCAAgB,EAAE,IAAI,OAAO,KAAK,EAAE,CAAC,WAAW,GACrD,CAES;EAEhB,OAAO;;CAGT,MAAM,SAASK,oCAAcN,gDAAoB,OAAO,CAAC;CACzD,KAAK,MAAM,OAAO,YAEhB,WAAW,QADG,IAAI,MAAM,IACA,CAAC;CAG3B,OAAO,uBAAuB,OAAO"}
@@ -0,0 +1,139 @@
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 { NumberRangeUnion } from "@rzl-zone/ts-types-plus";
12
+ /** ----------------------------------------------------------------------
13
+ * * ***Utility: `findDuplicates`.***
14
+ * ----------------------------------------------------------------------
15
+ * **Finds duplicate values in an array by deep equality comparison.**
16
+ * - **Behavior:**
17
+ * - Uses ***`isEqual` utility function*** to compare elements
18
+ * (handles objects, arrays, dates, NaN, etc.).
19
+ * - Returns a new array containing only the *first occurrences* of duplicated values.
20
+ * - Does **not mutate** the original array.
21
+ * - Throws ***{@link TypeError | `TypeError`}*** if input is not an array.
22
+ * @template T Type of elements in the input array.
23
+ * @param {T[]} values - The array to check for duplicates.
24
+ * @returns {T[]} An array of the duplicate values found in the input,
25
+ * preserving order of their first duplicate appearance.
26
+ * @throws **{@link TypeError | `TypeError`}** if the provided `values` argument is not an array.
27
+ * @example
28
+ * findDuplicates([1, 2, 2, 3, 4, 4]);
29
+ * // ➔ [2, 4]
30
+ * findDuplicates(["apple", "banana", "apple", "orange"]);
31
+ * // ➔ ["apple"]
32
+ * findDuplicates([{ a: 1 }, { a: 1 }, { a: 2 }]);
33
+ * // ➔ [{ a: 1 }]
34
+ * findDuplicates([NaN, NaN, 1]);
35
+ * // ➔ [NaN]
36
+ * findDuplicates([true, false, true]);
37
+ * // ➔ [true]
38
+ * findDuplicates([1, 2, 3]);
39
+ * // ➔ []
40
+ */
41
+ declare const findDuplicates: <T>(values: T[]) => T[];
42
+ /** --------------------------------
43
+ * * ***Utility: `omitKeys`.***
44
+ * --------------------------------
45
+ * **This function creates a shallow copy of the given object omitting the
46
+ * specified keys.**
47
+ * - **Behavior:**
48
+ * - It will return a new object without mutating the original.
49
+ * - It also validates that ***`keysToOmit`*** does not contain duplicate keys.
50
+ * - **ℹ️ Internally:**
51
+ * - It uses ***`isEqual`*** to check for duplicates in
52
+ * the ***`keysToOmit`*** array.
53
+ * @template I The type of the input object.
54
+ * @template K The keys to omit from the object.
55
+ * @param {I} object - The source object to omit keys from.
56
+ * @param {K[]} keysToOmit - An array of keys to exclude from the returned object.
57
+ * @returns {Omit<I, K>} A new object without the specified keys.
58
+ * @throws **{@link TypeError | `TypeError`}** if `keysToOmit` is not an array.
59
+ * @throws **{@link Error | `Error`}** if duplicate keys are found in `keysToOmit`.
60
+ * @example
61
+ * omitKeys({ a: 1, b: 2, c: 3 }, ["b", "c"]);
62
+ * //➔ { a: 1 }
63
+ * omitKeys({ name: "John", age: 30 }, ["age"]);
64
+ * //➔ { name: "John" }
65
+ * omitKeys({ a: 1, b: 2 }, []);
66
+ * //➔ { a: 1, b: 2 } (no changes)
67
+ */
68
+ declare const omitKeys: <I extends Record<string, unknown>, K extends keyof I>(object: I, keysToOmit: K[]) => Omit<I, K>;
69
+ type IndexArray = NumberRangeUnion<0, 30>;
70
+ type DotPath<T, Prev extends string = ""> = T extends Array<infer U> ? DotPath<U, `${Prev}${Prev extends "" ? "" : "."}${IndexArray}`> : T extends object ? { [K in keyof T & string]: `${Prev}${Prev extends "" ? "" : "."}${K}` | DotPath<T[K], `${Prev}${Prev extends "" ? "" : "."}${K}`> }[keyof T & string] : never;
71
+ /** ------------------------------------------------------
72
+ * * ***Utility: `omitKeysDeep`.***
73
+ * ------------------------------------------------------
74
+ * **Recursively omits properties from an object using dot notation paths.**
75
+ * - **Behavior:**
76
+ * - Removes resulting empty objects (`{}`) and arrays (`[]`), cascading upwards
77
+ * to remove empty parents until root if needed.
78
+ * - **⚠️ Be careful:**
79
+ * - If after omission an object or array becomes empty, it will be removed entirely
80
+ * including all the way up to the root if necessary, resulting in `{}`.
81
+ * - **ℹ️ Note:**
82
+ * - For array indices, TypeScript autocomplete only suggests `0`–`30`
83
+ * (to prevent editor lag on large unions).
84
+ * However, higher indices are still fully supported at runtime — you can
85
+ * manually type `"arr.99.key"` and it will work the same.
86
+ * @template I - Type of the input object
87
+ * @param {I} object
88
+ * The object to process, should be a plain nested object or array structure.
89
+ * @param {DotPath<I>[]} keysToOmit
90
+ * An array of string paths in dot notation indicating the properties to remove, paths
91
+ * can include numeric indices to target array elements, e.g. `"arr.0.x"` to
92
+ * remove `x` from the first object inside the `arr` array.
93
+ * @returns {Partial<I>}
94
+ * A new deeply cloned object with the specified keys omitted, with resulting
95
+ * empty objects or arrays fully removed (even if it collapses to `{}`).
96
+ * @throws **{@link TypeError | `TypeError`}** if `keysToOmit` is not an array.
97
+ * @throws **{@link Error | `Error`}** if `keysToOmit` contains duplicate paths.
98
+ * @example
99
+ * omitKeysDeep({ arr: [{ a: 1 }] }, ["arr.0.a"]);
100
+ * // ➔ {} (array becomes empty and removed)
101
+ * omitKeysDeep({ a: { b: { c: 1 }, d: 2 }, e: 3 }, ["a.b.c"]);
102
+ * // ➔ { a: { d: 2 }, e: 3 }
103
+ * omitKeysDeep({ a: [{ b: 1 }, { c: 2 }] }, ["a.0.b"]);
104
+ * // ➔ { a: [{ c: 2 }] }
105
+ * omitKeysDeep({ a: [{ b: 1 }] }, ["a.0.b"]);
106
+ * // ➔ {} (array becomes empty and removed)
107
+ * omitKeysDeep({ complex: [{ deep: [{ x: 1, y: 2 }] }] }, ["complex.0.deep.0.x"]);
108
+ * // ➔ { complex: [{ deep: [{ y: 2 }] }] }
109
+ * omitKeysDeep({ complex: [{ deep: [{ x: 1 }] }] }, ["complex.0.deep.0.x"]);
110
+ * // ➔ {} (deep chain emptied and collapsed)
111
+ * omitKeysDeep({ data: [[{ foo: 1, bar: 2 }]] }, ["data.0.0.foo"]);
112
+ * // ➔ { data: [[{ bar: 2 }]] }
113
+ * omitKeysDeep({ data: [[{ foo: 1 }]] }, ["data.0.0.foo"]);
114
+ * // ➔ {} (nested arrays emptied completely)
115
+ * omitKeysDeep({ x: [{ y: [{ z: 1 }, { w: 2 }] }] }, ["x.0.y.0.z"]);
116
+ * // ➔ { x: [{ y: [{ w: 2 }] }] }
117
+ * omitKeysDeep({ x: [{ y: [{ z: 1 }] }] }, ["x.0.y.0.z"]);
118
+ * // ➔ {} (entire nested arrays removed)
119
+ * omitKeysDeep({ p: { q: { r: 5 } }, s: 6 }, ["p.q.r"]);
120
+ * // ➔ { s: 6 } (`p` removed because it becomes empty)
121
+ * omitKeysDeep({ arr: [{ a: 1, b: 2 }, { c: 3 }] }, ["arr.0.a"]);
122
+ * // ➔ { arr: [{ b: 2 }, { c: 3 }] }
123
+ * omitKeysDeep({ root: [{ sub: [{ leaf: 10 }] }] }, ["root.0.sub.0.leaf"]);
124
+ * // ➔ {} (deep nested arrays emptied to root)
125
+ * omitKeysDeep({ meta: { tags: ["x", "y"], count: 2 } }, ["meta.count"]);
126
+ * // ➔ { meta: { tags: ["x", "y"] } }
127
+ * omitKeysDeep({ arr: [[{ a: 1 }, { b: 2 }]] }, ["arr.0.0.a"]);
128
+ * // ➔ { arr: [[{ b: 2 }]] }
129
+ * omitKeysDeep({ arr: [[{ a: 1 }]] }, ["arr.0.0.a"]);
130
+ * // ➔ {} (double nested emptied)
131
+ * omitKeysDeep({ nested: [{ list: [{ id: 1, val: 2 }] }] }, ["nested.0.list.0.val"]);
132
+ * // ➔ { nested: [{ list: [{ id: 1 }] }] }
133
+ * omitKeysDeep({ nested: [{ list: [{ id: 1 }] }] }, ["nested.0.list.0.id"]);
134
+ * // ➔ {} (full collapse to empty)
135
+ * omitKeysDeep({ mixed: { a: [1, 2, 3], b: { c: 4 } } }, ["mixed.b.c"]);
136
+ * // ➔ { mixed: { a: [1, 2, 3] } }
137
+ */
138
+ declare const omitKeysDeep: <I extends Record<string, unknown>>(object: I, keysToOmit: DotPath<I>[]) => Partial<I>;
139
+ export { findDuplicates, omitKeys, omitKeysDeep };
@@ -1,14 +1,14 @@
1
1
  /*!
2
- * ====================================================
3
- * Rzl Utils-JS.
4
- * ----------------------------------------------------
5
- * Version: 3.11.1.
6
- * Author: Rizalvin Dwiky.
7
- * Repository: https://github.com/rzl-zone/utils-js.
8
- * ====================================================
9
- */
10
- import { NumberRangeUnion } from '@rzl-zone/ts-types-plus';
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
+ */
11
10
 
11
+ import { NumberRangeUnion } from "@rzl-zone/ts-types-plus";
12
12
  /** ----------------------------------------------------------------------
13
13
  * * ***Utility: `findDuplicates`.***
14
14
  * ----------------------------------------------------------------------
@@ -39,7 +39,6 @@ import { NumberRangeUnion } from '@rzl-zone/ts-types-plus';
39
39
  * // ➔ []
40
40
  */
41
41
  declare const findDuplicates: <T>(values: T[]) => T[];
42
-
43
42
  /** --------------------------------
44
43
  * * ***Utility: `omitKeys`.***
45
44
  * --------------------------------
@@ -67,11 +66,8 @@ declare const findDuplicates: <T>(values: T[]) => T[];
67
66
  * //➔ { a: 1, b: 2 } (no changes)
68
67
  */
69
68
  declare const omitKeys: <I extends Record<string, unknown>, K extends keyof I>(object: I, keysToOmit: K[]) => Omit<I, K>;
70
-
71
69
  type IndexArray = NumberRangeUnion<0, 30>;
72
- type DotPath<T, Prev extends string = ""> = T extends Array<infer U> ? DotPath<U, `${Prev}${Prev extends "" ? "" : "."}${IndexArray}`> : T extends object ? {
73
- [K in keyof T & string]: `${Prev}${Prev extends "" ? "" : "."}${K}` | DotPath<T[K], `${Prev}${Prev extends "" ? "" : "."}${K}`>;
74
- }[keyof T & string] : never;
70
+ type DotPath<T, Prev extends string = ""> = T extends Array<infer U> ? DotPath<U, `${Prev}${Prev extends "" ? "" : "."}${IndexArray}`> : T extends object ? { [K in keyof T & string]: `${Prev}${Prev extends "" ? "" : "."}${K}` | DotPath<T[K], `${Prev}${Prev extends "" ? "" : "."}${K}`> }[keyof T & string] : never;
75
71
  /** ------------------------------------------------------
76
72
  * * ***Utility: `omitKeysDeep`.***
77
73
  * ------------------------------------------------------
@@ -140,5 +136,4 @@ type DotPath<T, Prev extends string = ""> = T extends Array<infer U> ? DotPath<U
140
136
  * // ➔ { mixed: { a: [1, 2, 3] } }
141
137
  */
142
138
  declare const omitKeysDeep: <I extends Record<string, unknown>>(object: I, keysToOmit: DotPath<I>[]) => Partial<I>;
143
-
144
139
  export { findDuplicates, omitKeys, omitKeysDeep };