@rzl-zone/utils-js 3.12.0 → 3.12.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE.md → LICENSE} +3 -3
- package/README.md +69 -96
- package/dist/.references/index.d.cts +25 -0
- package/dist/.references/index.d.ts +25 -0
- package/dist/assertIsArray-DJXkjHZs.cjs +26 -0
- package/dist/assertIsArray-DJXkjHZs.cjs.map +1 -0
- package/dist/assertIsArray-bTA3XLjq.js +20 -0
- package/dist/assertIsArray-bTA3XLjq.js.map +1 -0
- package/dist/assertIsBoolean-C8WEXVr2.cjs +1283 -0
- package/dist/assertIsBoolean-C8WEXVr2.cjs.map +1 -0
- package/dist/assertIsBoolean-DR1SaXPD.js +1073 -0
- package/dist/assertIsBoolean-DR1SaXPD.js.map +1 -0
- package/dist/assertIsString-BiHQSrB2.cjs +26 -0
- package/dist/assertIsString-BiHQSrB2.cjs.map +1 -0
- package/dist/assertIsString-CEB07_83.js +20 -0
- package/dist/assertIsString-CEB07_83.js.map +1 -0
- package/dist/assertions/index.cjs +37 -40
- package/dist/assertions/index.cjs.map +1 -0
- package/dist/assertions/index.d.cts +12 -0
- package/dist/assertions/index.d.ts +10 -824
- package/dist/assertions/index.js +30 -13
- package/dist/assertions/index.js.map +1 -0
- package/dist/conversions/index.cjs +34 -103
- package/dist/conversions/index.d.cts +12 -0
- package/dist/conversions/index.d.ts +10 -1791
- package/dist/conversions/index.js +14 -24
- package/dist/conversions-BNIh_tCH.js +380 -0
- package/dist/conversions-BNIh_tCH.js.map +1 -0
- package/dist/conversions-D_Kh0a_C.cjs +446 -0
- package/dist/conversions-D_Kh0a_C.cjs.map +1 -0
- package/dist/events/index.cjs +55 -31
- package/dist/events/index.cjs.map +1 -0
- package/dist/events/index.d.cts +176 -0
- package/dist/events/index.d.ts +164 -166
- package/dist/events/index.js +50 -12
- package/dist/events/index.js.map +1 -0
- package/dist/formatEnvPort-B3OLxQk9.cjs +171 -0
- package/dist/formatEnvPort-B3OLxQk9.cjs.map +1 -0
- package/dist/formatEnvPort-ByFVLjSV.js +159 -0
- package/dist/formatEnvPort-ByFVLjSV.js.map +1 -0
- package/dist/formatters/index.cjs +21 -61
- package/dist/formatters/index.d.cts +12 -0
- package/dist/formatters/index.d.ts +10 -2152
- package/dist/formatters/index.js +10 -18
- package/dist/formatters--1m_vpE8.js +369 -0
- package/dist/formatters--1m_vpE8.js.map +1 -0
- package/dist/formatters-Cbij0XLU.cjs +429 -0
- package/dist/formatters-Cbij0XLU.cjs.map +1 -0
- package/dist/generators/index.cjs +165 -41
- package/dist/generators/index.cjs.map +1 -0
- package/dist/generators/index.d.cts +12 -0
- package/dist/generators/index.d.ts +10 -338
- package/dist/generators/index.js +158 -14
- package/dist/generators/index.js.map +1 -0
- package/dist/index-59zbLcPr.d.ts +340 -0
- package/dist/index-B6tawc8L.d.cts +1716 -0
- package/dist/index-C267akkJ.d.ts +2158 -0
- package/dist/index-CeBC2Vvl.d.cts +2361 -0
- package/dist/index-CgRDTI6f.d.ts +822 -0
- package/dist/index-CoiUBVmr.d.ts +720 -0
- package/dist/index-D4fcasfZ.d.cts +720 -0
- package/dist/index-DDrSQKIc.d.ts +1716 -0
- package/dist/index-DsGxO31H.d.cts +765 -0
- package/dist/index-Hg1qJkjl.d.ts +765 -0
- package/dist/index-Qm3iFwd0.d.cts +2158 -0
- package/dist/index-UPp94Agr.d.ts +2361 -0
- package/dist/index-gBA_8SuF.d.cts +340 -0
- package/dist/index-jyDqzicx.d.cts +822 -0
- package/dist/isBigInt-C4krUeAw.cjs +20 -0
- package/dist/isBigInt-C4krUeAw.cjs.map +1 -0
- package/dist/isBigInt-DKe0M6hp.js +14 -0
- package/dist/isBigInt-DKe0M6hp.js.map +1 -0
- package/dist/isEmptyObject-DCipFwxJ.js +25 -0
- package/dist/isEmptyObject-DCipFwxJ.js.map +1 -0
- package/dist/isEmptyObject-ZkSwRC_D.cjs +37 -0
- package/dist/isEmptyObject-ZkSwRC_D.cjs.map +1 -0
- package/dist/isEmptyString-BXzKAC2j.js +15 -0
- package/dist/isEmptyString-BXzKAC2j.js.map +1 -0
- package/dist/isEmptyString-UiiUsSQj.cjs +21 -0
- package/dist/isEmptyString-UiiUsSQj.cjs.map +1 -0
- package/dist/isEmptyValue-BQzcjVaL.cjs +30 -0
- package/dist/isEmptyValue-BQzcjVaL.cjs.map +1 -0
- package/dist/isEmptyValue-jqOr7OHD.js +24 -0
- package/dist/isEmptyValue-jqOr7OHD.js.map +1 -0
- package/dist/isEqual-BX49cF9m.js +87 -0
- package/dist/isEqual-BX49cF9m.js.map +1 -0
- package/dist/isEqual-BvumA3RA.cjs +111 -0
- package/dist/isEqual-BvumA3RA.cjs.map +1 -0
- package/dist/isFinite-BCnaDpod.js +15 -0
- package/dist/isFinite-BCnaDpod.js.map +1 -0
- package/dist/isFinite-D24ZaE6c.cjs +21 -0
- package/dist/isFinite-D24ZaE6c.cjs.map +1 -0
- package/dist/isInteger-Caeuz0rB.cjs +20 -0
- package/dist/isInteger-Caeuz0rB.cjs.map +1 -0
- package/dist/isInteger-naMbJsxJ.js +14 -0
- package/dist/isInteger-naMbJsxJ.js.map +1 -0
- package/dist/isPlainObject-BF-2-phb.d.cts +339 -0
- package/dist/isPlainObject-DxNDL8XU.d.ts +339 -0
- package/dist/isServer-BJHVnixd.cjs +20 -0
- package/dist/isServer-BJHVnixd.cjs.map +1 -0
- package/dist/isServer-Da3o3XSs.js +14 -0
- package/dist/isServer-Da3o3XSs.js.map +1 -0
- package/dist/isTypedArray-DuNA8tK6.js +31 -0
- package/dist/isTypedArray-DuNA8tK6.js.map +1 -0
- package/dist/isTypedArray-TJptiw2b.cjs +43 -0
- package/dist/isTypedArray-TJptiw2b.cjs.map +1 -0
- package/dist/isURL-C-kSk6KJ.js +14 -0
- package/dist/isURL-C-kSk6KJ.js.map +1 -0
- package/dist/isURL-DeUPO_oR.cjs +20 -0
- package/dist/isURL-DeUPO_oR.cjs.map +1 -0
- package/dist/isValidDomain-BB9IGhJs.cjs +1845 -0
- package/dist/isValidDomain-BB9IGhJs.cjs.map +1 -0
- package/dist/isValidDomain-DoE98yhJ.js +1827 -0
- package/dist/isValidDomain-DoE98yhJ.js.map +1 -0
- package/dist/next/index.cjs +119 -214
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +220 -0
- package/dist/next/index.d.ts +203 -214
- package/dist/next/index.js +117 -212
- package/dist/next/index.js.map +1 -0
- package/dist/next/server/index.cjs +25 -40
- package/dist/next/server/index.cjs.map +1 -0
- package/dist/next/server/index.d.cts +39 -0
- package/dist/next/server/index.d.ts +34 -35
- package/dist/next/server/index.js +23 -38
- package/dist/next/server/index.js.map +1 -0
- package/dist/noop-B13_ii35.cjs +18 -0
- package/dist/noop-B13_ii35.cjs.map +1 -0
- package/dist/noop-ubqAIbHD.js +12 -0
- package/dist/noop-ubqAIbHD.js.map +1 -0
- package/dist/normalizeSpaces-Bg2IZW7W.js +23 -0
- package/dist/normalizeSpaces-Bg2IZW7W.js.map +1 -0
- package/dist/normalizeSpaces-ZXnR4Qzp.cjs +29 -0
- package/dist/normalizeSpaces-ZXnR4Qzp.cjs.map +1 -0
- package/dist/normalizeString-BDdkaXui.js +15 -0
- package/dist/normalizeString-BDdkaXui.js.map +1 -0
- package/dist/normalizeString-BE6ELqEb.cjs +21 -0
- package/dist/normalizeString-BE6ELqEb.cjs.map +1 -0
- package/dist/operations/index.cjs +65 -32
- package/dist/operations/index.cjs.map +1 -0
- package/dist/operations/index.d.cts +139 -0
- package/dist/operations/index.d.ts +129 -134
- package/dist/operations/index.js +61 -17
- package/dist/operations/index.js.map +1 -0
- package/dist/parsers/index.cjs +12 -19
- package/dist/parsers/index.d.cts +239 -0
- package/dist/parsers/index.d.ts +234 -235
- package/dist/parsers/index.js +10 -12
- package/dist/parsers-BSBPgvsq.js +643 -0
- package/dist/parsers-BSBPgvsq.js.map +1 -0
- package/dist/parsers-OqDeffqc.cjs +649 -0
- package/dist/parsers-OqDeffqc.cjs.map +1 -0
- package/dist/parsing-Cao8b358.js +50 -0
- package/dist/parsing-Cao8b358.js.map +1 -0
- package/dist/parsing-DOGSCH6N.cjs +56 -0
- package/dist/parsing-DOGSCH6N.cjs.map +1 -0
- package/dist/predicates/index.cjs +91 -296
- package/dist/predicates/index.d.cts +13 -0
- package/dist/predicates/index.d.ts +12 -2482
- package/dist/predicates/index.js +23 -25
- package/dist/predicates-Bj6meyXV.js +256 -0
- package/dist/predicates-Bj6meyXV.js.map +1 -0
- package/dist/predicates-D0ubqgqy.cjs +412 -0
- package/dist/predicates-D0ubqgqy.cjs.map +1 -0
- package/dist/promises/index.cjs +76 -24
- package/dist/promises/index.cjs.map +1 -0
- package/dist/promises/index.d.cts +123 -0
- package/dist/promises/index.d.ts +116 -119
- package/dist/promises/index.js +73 -13
- package/dist/promises/index.js.map +1 -0
- package/dist/punyCode-8SrbMWfM.js +179 -0
- package/dist/punyCode-8SrbMWfM.js.map +1 -0
- package/dist/punyCode-D-Qu6nj6.cjs +185 -0
- package/dist/punyCode-D-Qu6nj6.cjs.map +1 -0
- package/dist/removeSpaces-Bmc5DX4F.js +19 -0
- package/dist/removeSpaces-Bmc5DX4F.js.map +1 -0
- package/dist/removeSpaces-CWIvhZHg.cjs +25 -0
- package/dist/removeSpaces-CWIvhZHg.cjs.map +1 -0
- package/dist/rzl-utils.global.js +20 -9
- package/dist/safeJsonParse-BP38mwlj.js +184 -0
- package/dist/safeJsonParse-BP38mwlj.js.map +1 -0
- package/dist/safeJsonParse-Sms2CJf4.cjs +208 -0
- package/dist/safeJsonParse-Sms2CJf4.cjs.map +1 -0
- package/dist/safeStableStringify-CJtP89qn.cjs +106 -0
- package/dist/safeStableStringify-CJtP89qn.cjs.map +1 -0
- package/dist/safeStableStringify-CXOZ9Ub8.js +88 -0
- package/dist/safeStableStringify-CXOZ9Ub8.js.map +1 -0
- package/dist/strings/index.cjs +79 -81
- package/dist/strings/index.cjs.map +1 -0
- package/dist/strings/index.d.cts +12 -0
- package/dist/strings/index.d.ts +10 -775
- package/dist/strings/index.js +62 -14
- package/dist/strings/index.js.map +1 -0
- package/dist/tailwind/index.cjs +19 -47
- package/dist/tailwind/index.d.cts +12 -0
- package/dist/tailwind/index.d.ts +11 -712
- package/dist/tailwind/index.js +10 -12
- package/dist/tailwind-B2ssevxq.js +199 -0
- package/dist/tailwind-B2ssevxq.js.map +1 -0
- package/dist/tailwind-CHIx9uxu.cjs +247 -0
- package/dist/tailwind-CHIx9uxu.cjs.map +1 -0
- package/dist/toStringArrayUnRecursive-C4zYCja7.cjs +51 -0
- package/dist/toStringArrayUnRecursive-C4zYCja7.cjs.map +1 -0
- package/dist/toStringArrayUnRecursive-DJGtPsFb.js +39 -0
- package/dist/toStringArrayUnRecursive-DJGtPsFb.js.map +1 -0
- package/dist/urls/index.cjs +130 -57
- package/dist/urls/index.cjs.map +1 -0
- package/dist/urls/index.d.cts +737 -0
- package/dist/urls/index.d.ts +699 -708
- package/dist/urls/index.js +122 -26
- package/dist/urls/index.js.map +1 -0
- package/package.json +203 -194
- package/dist/chunk-2AFQ33D3.cjs +0 -64
- package/dist/chunk-2CYDJVGM.js +0 -246
- package/dist/chunk-2MW4JDQ2.cjs +0 -598
- package/dist/chunk-2VTDXC3N.cjs +0 -1825
- package/dist/chunk-44XX2P34.js +0 -209
- package/dist/chunk-4YLBKLGS.cjs +0 -18
- package/dist/chunk-566CXQW7.cjs +0 -560
- package/dist/chunk-57EPKYID.cjs +0 -397
- package/dist/chunk-5MGEC3YG.js +0 -63
- package/dist/chunk-6EF52423.cjs +0 -249
- package/dist/chunk-6SCOKU3S.js +0 -109
- package/dist/chunk-6VUXD3CF.js +0 -119
- package/dist/chunk-7B76BSNK.cjs +0 -118
- package/dist/chunk-7Y6I2DSU.cjs +0 -101
- package/dist/chunk-A7S7E2EE.cjs +0 -308
- package/dist/chunk-AJZ6PMMZ.js +0 -16
- package/dist/chunk-AXGBL2IO.cjs +0 -251
- package/dist/chunk-B4TC6FBV.cjs +0 -678
- package/dist/chunk-BAV5T2E3.cjs +0 -15
- package/dist/chunk-BKIJBNIE.js +0 -21
- package/dist/chunk-BNIMTFK5.js +0 -59
- package/dist/chunk-BXW7YXB7.js +0 -1823
- package/dist/chunk-CFYZC4S6.js +0 -53
- package/dist/chunk-CSG4SCL3.js +0 -1587
- package/dist/chunk-CWQW7AKK.js +0 -676
- package/dist/chunk-DVMHRLKP.cjs +0 -16
- package/dist/chunk-EN7LVZBZ.js +0 -548
- package/dist/chunk-EV4Y7HCY.cjs +0 -26
- package/dist/chunk-F66VDYIZ.cjs +0 -18
- package/dist/chunk-FLJX37EL.cjs +0 -30
- package/dist/chunk-GKC3UDMC.cjs +0 -1623
- package/dist/chunk-H65I3GRZ.cjs +0 -106
- package/dist/chunk-HHYWB7VZ.js +0 -24
- package/dist/chunk-HNGGISFL.cjs +0 -65
- package/dist/chunk-HNSQAVSZ.cjs +0 -35
- package/dist/chunk-HSP6IWZK.js +0 -17
- package/dist/chunk-IDZS7J6T.js +0 -242
- package/dist/chunk-JS6R55VL.js +0 -302
- package/dist/chunk-JZVT5FK7.js +0 -232
- package/dist/chunk-KHO2SBNA.cjs +0 -16
- package/dist/chunk-KIDJCMNJ.js +0 -33
- package/dist/chunk-KOLEURVT.cjs +0 -38
- package/dist/chunk-L4V53MQK.cjs +0 -269
- package/dist/chunk-L5RDAVVH.js +0 -14
- package/dist/chunk-NODTV4F3.js +0 -16
- package/dist/chunk-NYK5K3V2.cjs +0 -211
- package/dist/chunk-ODUO3RTL.cjs +0 -113
- package/dist/chunk-ONZFBJVW.js +0 -14
- package/dist/chunk-PFXCTE37.js +0 -28
- package/dist/chunk-PPST7QAQ.js +0 -587
- package/dist/chunk-Q5IMYDFL.cjs +0 -33
- package/dist/chunk-QFFBIOJ4.js +0 -31
- package/dist/chunk-QNKGP5DY.js +0 -14
- package/dist/chunk-RRQHMOPE.cjs +0 -19
- package/dist/chunk-RU5OSRBU.js +0 -95
- package/dist/chunk-SDMPEJ4F.js +0 -35
- package/dist/chunk-SYNL5IKP.js +0 -115
- package/dist/chunk-TCDOWZQE.js +0 -16
- package/dist/chunk-TQPGXGKB.cjs +0 -123
- package/dist/chunk-TULOI4GL.js +0 -370
- package/dist/chunk-UBHCP4N5.cjs +0 -36
- package/dist/chunk-UCHF3M34.cjs +0 -56
- package/dist/chunk-UDA26MCU.cjs +0 -16
- package/dist/chunk-V3C4FYZL.cjs +0 -18
- package/dist/chunk-VAAHZFBF.js +0 -32
- package/dist/chunk-VJDDGRIK.cjs +0 -16
- package/dist/chunk-WVSPXFTY.js +0 -14
- package/dist/chunk-WYP76WXB.js +0 -101
- package/dist/chunk-YDE4ZBB7.cjs +0 -237
- package/dist/chunk-YKQEOO7C.cjs +0 -23
- package/dist/chunk-YSZC56SZ.js +0 -264
- package/dist/chunk-YWHHVDT4.js +0 -13
- package/dist/index.d.ts +0 -24
- package/dist/isPlainObject-DTJVV2Kf.d.ts +0 -536
|
@@ -1,144 +1,139 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { NumberRangeUnion } from '@rzl-zone/ts-types-plus';
|
|
2
|
+
* ========================================================================
|
|
3
|
+
* @rzl-zone/utils-js
|
|
4
|
+
* ------------------------------------------------------------------------
|
|
5
|
+
* Version: `3.12.1-beta.1`
|
|
6
|
+
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
|
+
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
|
+
* ========================================================================
|
|
9
|
+
*/
|
|
11
10
|
|
|
11
|
+
import { NumberRangeUnion } from "@rzl-zone/ts-types-plus";
|
|
12
12
|
/** ----------------------------------------------------------------------
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
41
|
declare const findDuplicates: <T>(values: T[]) => T[];
|
|
42
|
-
|
|
43
42
|
/** --------------------------------
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
+
*/
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
+
*/
|
|
142
138
|
declare const omitKeysDeep: <I extends Record<string, unknown>>(object: I, keysToOmit: DotPath<I>[]) => Partial<I>;
|
|
143
|
-
|
|
144
139
|
export { findDuplicates, omitKeys, omitKeysDeep };
|
package/dist/operations/index.js
CHANGED
|
@@ -1,18 +1,62 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
* ========================================================================
|
|
3
|
+
* @rzl-zone/utils-js
|
|
4
|
+
* ------------------------------------------------------------------------
|
|
5
|
+
* Version: `3.12.1-beta.1`
|
|
6
|
+
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
|
+
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
|
+
* ========================================================================
|
|
9
|
+
*/
|
|
10
|
+
import { A as isPlainObject, D as isNaN, M as isArray, S as isUndefined, p as isNonEmptyArray, x as isObjectOrArray } from "../assertIsBoolean-DR1SaXPD.js";
|
|
11
|
+
import { t as assertIsArray } from "../assertIsArray-bTA3XLjq.js";
|
|
12
|
+
import { n as isEmptyArray } from "../isEmptyObject-DCipFwxJ.js";
|
|
13
|
+
import { t as safeStableStringify } from "../safeStableStringify-CXOZ9Ub8.js";
|
|
14
|
+
import { t as isEqual } from "../isEqual-BX49cF9m.js";
|
|
15
|
+
import { t as safeJsonParse } from "../safeJsonParse-BP38mwlj.js";
|
|
16
|
+
const findDuplicates = (values) => {
|
|
17
|
+
assertIsArray(values, { message: ({ currentType, validType }) => `First parameter (\`values\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.` });
|
|
18
|
+
const duplicates = [];
|
|
19
|
+
values.forEach((item, index) => {
|
|
20
|
+
for (let i = index + 1; i < values.length; i++) if (isEqual(item, values[i])) {
|
|
21
|
+
if (!duplicates.some((dup) => isEqual(dup, item))) duplicates.push(item);
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return duplicates;
|
|
26
|
+
};
|
|
27
|
+
const omitKeys = (object, keysToOmit) => {
|
|
28
|
+
if (!isPlainObject(object)) return {};
|
|
29
|
+
assertIsArray(keysToOmit, { message: ({ currentType, validType }) => `Second parameter (\`keysToOmit\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.` });
|
|
30
|
+
const duplicates = findDuplicates(keysToOmit);
|
|
31
|
+
if (duplicates.length > 0) throw new Error(`Function "omitKeys" Error: Duplicate keys detected - \`${duplicates}\``);
|
|
32
|
+
return Object.fromEntries(Object.entries(object).filter(([key]) => !keysToOmit.includes(key)));
|
|
33
|
+
};
|
|
34
|
+
const omitKeysDeep = (object, keysToOmit) => {
|
|
35
|
+
if (!isPlainObject(object)) return {};
|
|
36
|
+
assertIsArray(keysToOmit, { message: ({ currentType, validType }) => `Second parameter (\`keysToOmit\`) must be of type \`${validType}\` (array literal or instance), but received: \`${currentType}\`.` });
|
|
37
|
+
const duplicates = findDuplicates(keysToOmit);
|
|
38
|
+
if (isNonEmptyArray(duplicates)) throw new Error(`Function "omitKeysDeep" Error: Duplicate keys detected - \`${safeStableStringify(duplicates, { keepUndefined: true })}\`.`);
|
|
39
|
+
const omitAtPath = (obj, pathParts) => {
|
|
40
|
+
if (!isObjectOrArray(obj)) return obj;
|
|
41
|
+
const [current, ...rest] = pathParts;
|
|
42
|
+
if (isEmptyArray(rest) && current) if (isArray(obj)) {
|
|
43
|
+
const index = parseInt(current);
|
|
44
|
+
if (!isNaN(index) && index in obj) obj.splice(index, 1);
|
|
45
|
+
} else delete obj[current];
|
|
46
|
+
else {
|
|
47
|
+
const next = current ? obj[current] : void 0;
|
|
48
|
+
if (isObjectOrArray(next) && current) obj[current] = omitAtPath(next, rest);
|
|
49
|
+
}
|
|
50
|
+
return obj;
|
|
51
|
+
};
|
|
52
|
+
const deepRemoveEmptyObjects = (obj) => {
|
|
53
|
+
if (isArray(obj)) return obj.map(deepRemoveEmptyObjects).filter((item) => !(isObjectOrArray(item) && Object.keys(item).length === 0));
|
|
54
|
+
if (isObjectOrArray(obj)) return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, deepRemoveEmptyObjects(v)]).filter(([, v]) => !isUndefined(v) && !(isObjectOrArray(v) && Object.keys(v).length === 0)));
|
|
55
|
+
return obj;
|
|
56
|
+
};
|
|
57
|
+
const result = safeJsonParse(safeStableStringify(object));
|
|
58
|
+
for (const key of keysToOmit) omitAtPath(result, key.split("."));
|
|
59
|
+
return deepRemoveEmptyObjects(result);
|
|
60
|
+
};
|
|
61
|
+
export { findDuplicates, omitKeys, omitKeysDeep };
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"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) && current) {\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 = current ? obj[current] : undefined;\n if (isObjectOrArray(next) && current) {\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,cAAc,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,IAAI,QAAQ,MAAM,OAAO,GAAG,EAAE;GAC5B,IAAI,CAAC,WAAW,MAAM,QAAQ,QAAQ,KAAK,KAAK,CAAC,EAC/C,WAAW,KAAK,KAAK;GAEvB;;GAGJ;CAEF,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACpBT,MAAa,YACX,QACA,eACe;CACf,IAAI,CAAC,cAAc,OAAO,EAAE,OAAO,EAAE;CAErC,cAAc,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,CAAC,cAAc,OAAO,EAAE,OAAO,EAAE;CAErC,cAAc,YAAY,EACxB,UAAU,EAAE,aAAa,gBACvB,uDAAuD,UAAU,kDAAkD,YAAY,MAClI,CAAC;CAEF,MAAM,aAAa,eAAe,WAAW;CAC7C,IAAI,gBAAgB,WAAW,EAC7B,MAAM,IAAI,MACR,8DAA8D,oBAC5D,YACA,EACE,eAAe,MAChB,CACF,CAAC,KACH;CAGH,MAAM,cAAc,KAAc,cAAwB;EACxD,IAAI,CAAC,gBAAgB,IAAI,EAAE,OAAO;EAElC,MAAM,CAAC,SAAS,GAAG,QAAQ;EAE3B,IAAI,aAAa,KAAK,IAAI,SACxB,IAAI,QAAQ,IAAI,EAAE;GAEhB,MAAM,QAAQ,SAAS,QAAQ;GAC/B,IAAI,CAAC,MAAM,MAAM,IAAI,SAAS,KAC5B,IAAI,OAAO,OAAO,EAAE;SAGtB,OAAO,IAAI;OAER;GACL,MAAM,OAAO,UAAU,IAAI,WAAW;GACtC,IAAI,gBAAgB,KAAK,IAAI,SAC3B,IAAI,WAAW,WAAW,MAAM,KAAK;;EAGzC,OAAO;;CAGT,MAAM,0BAA0B,QAA0B;EACxD,IAAI,QAAQ,IAAI,EACd,OAAO,IACJ,IAAI,uBAAuB,CAC3B,QACE,SAAS,EAAE,gBAAgB,KAAK,IAAI,OAAO,KAAK,KAAK,CAAC,WAAW,GACnE;EAEL,IAAI,gBAAgB,IAAI,EAUtB,OATgB,OAAO,YACrB,OAAO,QAAQ,IAAI,CAChB,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,uBAAuB,EAAE,CAAC,CAAC,CAC/C,QACE,GAAG,OACF,CAAC,YAAY,EAAE,IACf,EAAE,gBAAgB,EAAE,IAAI,OAAO,KAAK,EAAE,CAAC,WAAW,GACrD,CAES;EAEhB,OAAO;;CAGT,MAAM,SAAS,cAAc,oBAAoB,OAAO,CAAC;CACzD,KAAK,MAAM,OAAO,YAEhB,WAAW,QADG,IAAI,MAAM,IACA,CAAC;CAG3B,OAAO,uBAAuB,OAAO"}
|
package/dist/parsers/index.cjs
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
require('../chunk-YKQEOO7C.cjs');
|
|
15
|
-
require('../chunk-GKC3UDMC.cjs');
|
|
16
|
-
|
|
17
|
-
Object.defineProperty(exports, "extractFileName", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () { return chunkB4TC6FBV_cjs.extractFileName; }
|
|
20
|
-
});
|
|
2
|
+
* ========================================================================
|
|
3
|
+
* @rzl-zone/utils-js
|
|
4
|
+
* ------------------------------------------------------------------------
|
|
5
|
+
* Version: `3.12.1-beta.1`
|
|
6
|
+
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
|
+
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
|
+
* ========================================================================
|
|
9
|
+
*/
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
12
|
+
const require_parsers = require('../parsers-OqDeffqc.cjs');
|
|
13
|
+
exports.extractFileName = require_parsers.extractFileName;
|