@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,2483 +1,13 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import { a as
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/** ----------------------------------------------------------
|
|
15
|
-
* * ***Predicate: `areArraysEqual`.***
|
|
16
|
-
* ----------------------------------------------------------
|
|
17
|
-
* **Compares two arrays deeply to check if they are equal.**
|
|
18
|
-
* @description Supports deep comparison of arrays containing nested arrays or objects,
|
|
19
|
-
* can also ignore the order of elements at all levels by recursively sorting.
|
|
20
|
-
* @param {unknown[]} array1
|
|
21
|
-
* ***The first array to compare, can contain nested arrays or objects.***
|
|
22
|
-
* @param {unknown[]} array2
|
|
23
|
-
* ***The second array to compare against, should match structure of `array1`.***
|
|
24
|
-
* @param {boolean|undefined} [ignoreOrder=false]
|
|
25
|
-
* ***Whether to ignore the order of elements when comparing.***
|
|
26
|
-
* - If `true`, will sort both arrays recursively before comparing, default is `false`.
|
|
27
|
-
* @returns {boolean}
|
|
28
|
-
* Returns `true` if both arrays are deeply equal, otherwise `false`.
|
|
29
|
-
* @throws **{@link TypeError | `TypeError`}** if `array1` or `array2` are not arrays, or if `ignoreOrder` is not a boolean.
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* areArraysEqual([1, 2, 3], [1, 2, 3]);
|
|
33
|
-
* // ➔ true
|
|
34
|
-
* areArraysEqual([1, 2, 3], [3, 2, 1]);
|
|
35
|
-
* // ➔ false
|
|
36
|
-
* areArraysEqual([1, 2, 3], [3, 2, 1], true);
|
|
37
|
-
* // ➔ true (order ignored)
|
|
38
|
-
* areArraysEqual([{ x: 1 }, { y: 2 }], [{ y: 2 }, { x: 1 }], true);
|
|
39
|
-
* // ➔ true
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
declare const areArraysEqual: (array1: unknown[], array2: unknown[], ignoreOrder?: boolean) => boolean;
|
|
43
|
-
|
|
44
|
-
/** ---------------------------------
|
|
45
|
-
* * ***Predicate: `areObjectsEqual`.***
|
|
46
|
-
* ---------------------------------
|
|
47
|
-
* **Compares two objects for deep equality.**
|
|
48
|
-
* @template T1 The type of the first object.
|
|
49
|
-
* @template T2 The type of the second object.
|
|
50
|
-
* @param {*} object1 - The first object to compare.
|
|
51
|
-
* @param {*} object2 - The second object to compare.
|
|
52
|
-
* @returns {boolean} Return `true` if both objects are deeply equal, otherwise `false`.
|
|
53
|
-
* @example
|
|
54
|
-
* areObjectsEqual({ a: 1, b: 2 }, { a: 1, b: 2 });
|
|
55
|
-
* // ➔ true
|
|
56
|
-
* areObjectsEqual({ a: 1 }, { a: 1, b: undefined });
|
|
57
|
-
* // ➔ false
|
|
58
|
-
* areObjectsEqual([1, 2, 3], [1, 2, 3]);
|
|
59
|
-
* // ➔ true
|
|
60
|
-
*/
|
|
61
|
-
declare const areObjectsEqual: (object1: unknown, object2: unknown) => boolean;
|
|
62
|
-
|
|
63
|
-
/** ---------------------------------
|
|
64
|
-
* * ***Predicate: `areURLsEqualPath`.***
|
|
65
|
-
* ---------------------------------
|
|
66
|
-
* **Checks if two URLs are the same, ignoring query parameters, this function compares only the protocol, host, and pathname.**
|
|
67
|
-
* @param {URL} urlA - The first URL to compare.
|
|
68
|
-
* @param {URL} urlB - The second URL to compare.
|
|
69
|
-
* @returns {boolean} Returns `true` if both URLs are the same (ignoring search parameters), otherwise `false`.
|
|
70
|
-
* @example
|
|
71
|
-
* // Same domain, same path, different query -> true
|
|
72
|
-
* areURLsEqualPath(
|
|
73
|
-
* new URL("https://example.com/page?a=1"),
|
|
74
|
-
* new URL("https://example.com/page?b=2")
|
|
75
|
-
* );
|
|
76
|
-
* // ➔ true
|
|
77
|
-
*
|
|
78
|
-
* // Same domain, different path -> false
|
|
79
|
-
* areURLsEqualPath(
|
|
80
|
-
* new URL("https://example.com/page1"),
|
|
81
|
-
* new URL("https://example.com/page2")
|
|
82
|
-
* );
|
|
83
|
-
* // ➔ false
|
|
84
|
-
*
|
|
85
|
-
* // Different protocol -> false
|
|
86
|
-
* areURLsEqualPath(
|
|
87
|
-
* new URL("http://example.com/page"),
|
|
88
|
-
* new URL("https://example.com/page")
|
|
89
|
-
* );
|
|
90
|
-
* // ➔ false
|
|
91
|
-
*
|
|
92
|
-
* // Same protocol, same host, same path (ignores query & hash) -> true
|
|
93
|
-
* areURLsEqualPath(
|
|
94
|
-
* new URL("https://example.com/page#section"),
|
|
95
|
-
* new URL("https://example.com/page")
|
|
96
|
-
* );
|
|
97
|
-
* // ➔ true
|
|
98
|
-
*/
|
|
99
|
-
declare const areURLsEqualPath: (urlA: URL, urlB: URL) => boolean;
|
|
100
|
-
|
|
101
|
-
/** ---------------------------------
|
|
102
|
-
* * ***Predicate: `areURLsIdentical`.***
|
|
103
|
-
* ---------------------------------
|
|
104
|
-
* **Checks if two URLs are exactly the same, including protocol, host, pathname, and query parameters.**
|
|
105
|
-
* @param {URL} urlA - The first URL to compare.
|
|
106
|
-
* @param {URL} urlB - The second URL to compare.
|
|
107
|
-
* @returns {boolean} Returns `true` if both URLs are identical, otherwise `false`.
|
|
108
|
-
* @example
|
|
109
|
-
* // Identical URLs -> true
|
|
110
|
-
* areURLsIdentical(
|
|
111
|
-
* new URL("https://example.com/page?a=1"),
|
|
112
|
-
* new URL("https://example.com/page?a=1")
|
|
113
|
-
* );
|
|
114
|
-
* // ➔ true
|
|
115
|
-
*
|
|
116
|
-
* // Same path, different query parameter -> false
|
|
117
|
-
* areURLsIdentical(
|
|
118
|
-
* new URL("https://example.com/page?a=1"),
|
|
119
|
-
* new URL("https://example.com/page?b=2")
|
|
120
|
-
* );
|
|
121
|
-
* // ➔ false
|
|
122
|
-
*
|
|
123
|
-
* // Same host & query, but different protocol -> false
|
|
124
|
-
* areURLsIdentical(
|
|
125
|
-
* new URL("http://example.com/page?a=1"),
|
|
126
|
-
* new URL("https://example.com/page?a=1")
|
|
127
|
-
* );
|
|
128
|
-
* // ➔ false
|
|
129
|
-
*
|
|
130
|
-
* // Same everything except trailing slash -> false
|
|
131
|
-
* areURLsIdentical(
|
|
132
|
-
* new URL("https://example.com/page"),
|
|
133
|
-
* new URL("https://example.com/page/")
|
|
134
|
-
* );
|
|
135
|
-
* // ➔ false
|
|
136
|
-
*/
|
|
137
|
-
declare const areURLsIdentical: (urlA: URL, urlB: URL) => boolean;
|
|
138
|
-
|
|
139
|
-
type OptionsTextContainsAll = {
|
|
140
|
-
/** If `true`, matches whole words only, defaultValue is `false`.
|
|
141
|
-
*
|
|
142
|
-
* @default false
|
|
143
|
-
*/
|
|
144
|
-
exactMatch?: boolean;
|
|
145
|
-
/** Optional regex flags (default: `"i"` for case-insensitive).
|
|
146
|
-
*
|
|
147
|
-
* @default "i"
|
|
148
|
-
*/
|
|
149
|
-
flags?: string;
|
|
150
|
-
};
|
|
151
|
-
/** ----------------------------------------------------------
|
|
152
|
-
* * ***Predicate: `textContainsAll`.***
|
|
153
|
-
* ----------------------------------------------------------
|
|
154
|
-
* **Checks if the given `text` contains all of the specified `searchWords`.**
|
|
155
|
-
* - **Behavior:**
|
|
156
|
-
* - Returns `false` if `text` or `searchWords` is `null`/`undefined`/invalid.
|
|
157
|
-
* - Uses **regular expressions** for flexible pattern matching.
|
|
158
|
-
* - **Escapes special characters** to prevent regex injection attacks.
|
|
159
|
-
* - **Trims input** to avoid false positives with empty spaces.
|
|
160
|
-
* - **Supports exact word matching** (optional).
|
|
161
|
-
* @param {string|null|undefined} text - The string text to search within.
|
|
162
|
-
* @param {string[]|null} [searchWords] - An array of words/phrases to match against the text.
|
|
163
|
-
* @param {OptionsTextContainsAll} [options] - Optional configuration object.
|
|
164
|
-
* @param {OptionsTextContainsAll["exactMatch"]} [options.exactMatch=false] - If `true`, matches whole words only, defaultValue is `false`.
|
|
165
|
-
* @param {OptionsTextContainsAll["flags"]} [options.flags="i"] - Optional regex flags (default: `"i"` for case-insensitive).
|
|
166
|
-
* @returns {boolean} Return `true` if all `searchWords` are found in `text`, otherwise `false`.
|
|
167
|
-
* @example
|
|
168
|
-
* textContainsAll("Hello world, WithAI APP", ["Hello", "world"]);
|
|
169
|
-
* // ➔ true
|
|
170
|
-
* textContainsAll("JavaScript and TypeScript", ["Java", "Script"]);
|
|
171
|
-
* // ➔ true
|
|
172
|
-
* textContainsAll("Machine Learning", ["AI", "Learning"]);
|
|
173
|
-
* // ➔ false
|
|
174
|
-
* textContainsAll("open-source", ["open"], { exactMatch: true });
|
|
175
|
-
* // ➔ false (because options `exactMatch=true`)
|
|
176
|
-
* textContainsAll(null, ["test"]);
|
|
177
|
-
* // ➔ false (invalid text)
|
|
178
|
-
* textContainsAll("Hello", null);
|
|
179
|
-
* // ➔ false (invalid searchWords)
|
|
180
|
-
*/
|
|
181
|
-
declare const textContainsAll: <T extends string>(text?: T | null, searchWords?: T[] | string[] | null, options?: OptionsTextContainsAll) => boolean;
|
|
182
|
-
|
|
183
|
-
type OptionsTextContainsAny = {
|
|
184
|
-
/** If `true`, matches whole words only, defaultValue is `false`.
|
|
185
|
-
*
|
|
186
|
-
* @default false
|
|
187
|
-
*/
|
|
188
|
-
exactMatch?: boolean;
|
|
189
|
-
/** Optional regex flags (default: `"i"` for case-insensitive).
|
|
190
|
-
*
|
|
191
|
-
* @default "i"
|
|
192
|
-
*/
|
|
193
|
-
flags?: string;
|
|
194
|
-
};
|
|
195
|
-
/** ----------------------------------------------------------
|
|
196
|
-
* * ***Predicate: `textContainsAny`.***
|
|
197
|
-
* ----------------------------------------------------------
|
|
198
|
-
* **Checks if the given `text` contains at least one of the specified `searchWords`.**
|
|
199
|
-
* - **Behavior:**
|
|
200
|
-
* - Returns `false` if `text` or `searchWords` is `null`/`undefined`/invalid.
|
|
201
|
-
* - Uses **regular expressions** for flexible pattern matching.
|
|
202
|
-
* - **Escapes special characters** to prevent regex injection attacks.
|
|
203
|
-
* - **Trims input** to avoid false positives with empty spaces.
|
|
204
|
-
* - **Supports exact word matching** (optional).
|
|
205
|
-
* @param {string|null|undefined} text - The string text to search within.
|
|
206
|
-
* @param {string[]|null} [searchWords] - An array of words/phrases to match against the text.
|
|
207
|
-
* @param {OptionsTextContainsAny} [options] - Optional configuration object.
|
|
208
|
-
* @param {OptionsTextContainsAny["exactMatch"]} [options.exactMatch=false] - If `true`, matches whole words only, defaultValue is `false`.
|
|
209
|
-
* @param {OptionsTextContainsAny["flags"]} [options.flags="i"] - Optional regex flags (default: `"i"` for case-insensitive).
|
|
210
|
-
* @returns {boolean} Return `true` if at least one `searchWord` is found in `text`, otherwise `false`.
|
|
211
|
-
* @example
|
|
212
|
-
* textContainsAny("Hello world", ["hello", "test"]);
|
|
213
|
-
* // ➔ true
|
|
214
|
-
* textContainsAny("withAI APP", ["chat", "ai"]);
|
|
215
|
-
* // ➔ false
|
|
216
|
-
* textContainsAny("TypeScript is great!", ["script", "java"]);
|
|
217
|
-
* // ➔ true
|
|
218
|
-
* textContainsAny("open-source", ["open"], { exactMatch: true });
|
|
219
|
-
* // ➔ false (because options `exactMatch=true`)
|
|
220
|
-
* textContainsAny(null, ["test"]);
|
|
221
|
-
* // ➔ false (invalid text)
|
|
222
|
-
* textContainsAny("Hello", null);
|
|
223
|
-
* // ➔ false (invalid searchWords)
|
|
224
|
-
*/
|
|
225
|
-
declare const textContainsAny: <T extends string>(text?: T | null, searchWords?: T[] | string[] | null, options?: OptionsTextContainsAny) => boolean;
|
|
226
|
-
|
|
227
|
-
/** ----------------------------------------------------------
|
|
228
|
-
* * ***Predicate: `doesKeyExist`.***
|
|
229
|
-
* ----------------------------------------------------------
|
|
230
|
-
* **Recursively checks if a given key exists in an object or array.**
|
|
231
|
-
* - **Behavior:**
|
|
232
|
-
* - **Supports deeply nested objects and arrays**, searching recursively.
|
|
233
|
-
* - Uses `Object.prototype.hasOwnProperty.call()` to safely check if the
|
|
234
|
-
* key exists at each level, even if its value is `null` or `undefined`.
|
|
235
|
-
* - Optimized to return `true` immediately when the key is found (short-circuits).
|
|
236
|
-
* - Handles edge cases gracefully:
|
|
237
|
-
* - Returns `false` for `null`, `undefined`, or non-object inputs.
|
|
238
|
-
* - Returns `false` if key is not found anywhere, even in deeply nested
|
|
239
|
-
* structures.
|
|
240
|
-
* - **ℹ️ Note:**
|
|
241
|
-
* - This function only checks for **the existence of the key itself**,
|
|
242
|
-
* not whether its value is non-null or non-undefined.
|
|
243
|
-
* - If you need to check for both existence and meaningful value, write a stricter function.
|
|
244
|
-
* @template T - The type of the input object or array.
|
|
245
|
-
* @param {T | Record<string, unknown> | unknown[]} object - The object or array to search.
|
|
246
|
-
* @param {PropertyKey} key - The key to look for (string, number, or symbol).
|
|
247
|
-
* @returns {boolean} Returns `true` if the key exists anywhere in the object or array (even with `null` / `undefined` value), otherwise `false`.
|
|
248
|
-
* @example
|
|
249
|
-
* doesKeyExist({ name: "John", age: 30 }, "age");
|
|
250
|
-
* // ➔ true
|
|
251
|
-
* doesKeyExist({ user: { profile: { email: "test@example.com" } } }, "email");
|
|
252
|
-
* // ➔ true
|
|
253
|
-
* doesKeyExist([{ id: 1 }, { id: 2 }], "id");
|
|
254
|
-
* // ➔ true
|
|
255
|
-
* doesKeyExist({ a: { b: { c: 10 } } }, "d");
|
|
256
|
-
* // ➔ false
|
|
257
|
-
* doesKeyExist(null, "name");
|
|
258
|
-
* // ➔ false
|
|
259
|
-
* doesKeyExist(undefined, "test");
|
|
260
|
-
* // ➔ false
|
|
261
|
-
*
|
|
262
|
-
* // Key exists even if value is null or undefined:
|
|
263
|
-
* doesKeyExist({ a: null, b: undefined, c: { d: null } }, "a"); // ➔ true
|
|
264
|
-
* doesKeyExist({ a: null, b: undefined, c: { d: null } }, "b"); // ➔ true
|
|
265
|
-
* doesKeyExist({ a: null, b: undefined, c: { d: null } }, "d"); // ➔ true
|
|
266
|
-
*
|
|
267
|
-
* doesKeyExist({ a: 1 }, true);
|
|
268
|
-
* // ➔ ❌ Throws TypeError
|
|
269
|
-
* doesKeyExist({ a: 1 }, ["not", "valid"]);
|
|
270
|
-
* // ➔ ❌ Throws TypeError
|
|
271
|
-
*/
|
|
272
|
-
declare const doesKeyExist: (object: Record<string, unknown> | unknown[], key: PropertyKey) => boolean;
|
|
273
|
-
|
|
274
|
-
/** ----------------------------------------------------------
|
|
275
|
-
* * ***Predicate: `arrayHasAnyMatch`.***
|
|
276
|
-
* ----------------------------------------------------------
|
|
277
|
-
* **Checks if at least one element from `targetArray` exists in `sourceArray`.**
|
|
278
|
-
* - **Behavior:**
|
|
279
|
-
* - Uses `Set` for **faster lookup** compared to `Array.prototype.includes()`.
|
|
280
|
-
* - Supports **any data type** (`number`, `string`, `boolean`, `object`, `array`, `function`, etc.).
|
|
281
|
-
* - Uses **reference equality** for non-primitive values (object, array, function).
|
|
282
|
-
* - Returns `false` if either array is missing, empty, or not an array.
|
|
283
|
-
* @template T - The expected type of array elements.
|
|
284
|
-
* @param {T[] | null | undefined} sourceArray - The array to search within.
|
|
285
|
-
* @param {T[] | null | undefined} targetArray - The array containing elements to match.
|
|
286
|
-
* @returns {boolean}
|
|
287
|
-
* ***Return:***
|
|
288
|
-
* - `true` if **at least one element from `targetArray` is strictly found
|
|
289
|
-
* in `sourceArray`**.
|
|
290
|
-
* - Comparison uses:
|
|
291
|
-
* - **Value equality** for primitives (`number`, `string`, `boolean`, `null`, `undefined`).
|
|
292
|
-
* - **Reference equality** for `objects`, `arrays`, and `functions`.
|
|
293
|
-
* - `false` if:
|
|
294
|
-
* - No matching elements exist,
|
|
295
|
-
* - Either array is not provided, not an actual array, or is empty.
|
|
296
|
-
* @example
|
|
297
|
-
* arrayHasAnyMatch(["apple", "banana", "cherry"], ["banana", "grape"]);
|
|
298
|
-
* // ➔ true
|
|
299
|
-
* arrayHasAnyMatch(["red", "blue"], ["green", "yellow"]);
|
|
300
|
-
* // ➔ false
|
|
301
|
-
* arrayHasAnyMatch([1, 2, 3], [3, 4, 5]);
|
|
302
|
-
* // ➔ true
|
|
303
|
-
* arrayHasAnyMatch([], ["test"]);
|
|
304
|
-
* // ➔ false
|
|
305
|
-
* arrayHasAnyMatch(["A", "B", "C"], []);
|
|
306
|
-
* // ➔ false
|
|
307
|
-
*
|
|
308
|
-
* const obj = { x: 1 };
|
|
309
|
-
* arrayHasAnyMatch([obj], [obj]);
|
|
310
|
-
* // ➔ true (same reference)
|
|
311
|
-
* arrayHasAnyMatch([{ x: 1 }], [{ x: 1 }]);
|
|
312
|
-
* // ➔ false (different reference)
|
|
313
|
-
*
|
|
314
|
-
* const fn = () => "hello";
|
|
315
|
-
* arrayHasAnyMatch([fn], [fn]);
|
|
316
|
-
* // ➔ true
|
|
317
|
-
* arrayHasAnyMatch([() => "hello"], [() => "hello"]);
|
|
318
|
-
* // ➔ false (different function reference)
|
|
319
|
-
*
|
|
320
|
-
* const arr = [1, 2];
|
|
321
|
-
* arrayHasAnyMatch([arr], [arr]);
|
|
322
|
-
* // ➔ true
|
|
323
|
-
* arrayHasAnyMatch([[1, 2]], [[1, 2]]);
|
|
324
|
-
* // ➔ false (different array object)
|
|
325
|
-
*/
|
|
326
|
-
declare const arrayHasAnyMatch: <T>(sourceArray: T[] | null | undefined, targetArray: T[] | null | undefined) => boolean;
|
|
327
|
-
|
|
328
|
-
/** Restrict array indices to a fixed numeric range (1–25). */
|
|
329
|
-
type ArrayIndex = NumberRangeUnion<1, 25>;
|
|
330
|
-
/** Remove `undefined` from a type. */
|
|
331
|
-
type NonUndef<T> = T extends undefined ? never : T;
|
|
332
|
-
/** Remove `null` from a type. */
|
|
333
|
-
type NonNull<T> = T extends null ? never : T;
|
|
334
|
-
/** Convert optional boolean for "discard undefined" to actual boolean. */
|
|
335
|
-
type EffectiveDiscardUndefined<O extends boolean | undefined> = O extends boolean ? O : true;
|
|
336
|
-
/** Convert optional boolean for "discard null" to actual boolean. */
|
|
337
|
-
type EffectiveDiscardNull<O extends boolean | undefined> = O extends boolean ? O : false;
|
|
338
|
-
/** Unwrap array type. */
|
|
339
|
-
type UnwrapArray<T> = T extends (infer U)[] ? U : T extends readonly (infer U)[] ? U : T;
|
|
340
|
-
/** Force symbol key to be deep required. */
|
|
341
|
-
type IsOptionalKey<T, K extends keyof T> = Record<never, never> extends Pick<T, K> ? true : false;
|
|
342
|
-
/** * ***Returns numeric keys of an object.***
|
|
343
|
-
*
|
|
344
|
-
* @private ***types for {@link hasOwnProp}.***
|
|
345
|
-
*/
|
|
346
|
-
type NumericKeyOfHasOwnProp<Obj> = Extract<keyof Obj, number>;
|
|
347
|
-
/** * ***Generate all nested keys of an object or array in dot/bracket notation.***
|
|
348
|
-
*
|
|
349
|
-
* @private ***types for {@link hasOwnProp}.***
|
|
350
|
-
*
|
|
351
|
-
* Example:
|
|
352
|
-
* ```ts
|
|
353
|
-
* type Keys = NestedKeyOfHasOwnProp<{ users: { name: string }[] }>
|
|
354
|
-
* // Keys = "users" | "users.[number]" | "users.[number].name"
|
|
355
|
-
* ```
|
|
356
|
-
*/
|
|
357
|
-
type NestedKeyOfHasOwnProp<T> = T extends readonly (infer U)[] ? `[${number}]` | `[${number}].${NestedKeyOfHasOwnProp<U>}` : T extends object ? {
|
|
358
|
-
[K in keyof T & (string | number)]: K extends string | number ? NonNullable<T[K]> extends readonly unknown[] ? `${K}` | `${K}.[${ArrayIndex}]` | `${K}.[${ArrayIndex}].${NestedKeyOfHasOwnProp<UnwrapArray<T[K]>>}` : NonNullable<T[K]> extends object ? `${K}` | `${K}.${NestedKeyOfHasOwnProp<NonNullable<T[K]>>}` : `${K}` : never;
|
|
359
|
-
}[keyof T & (string | number)] : never;
|
|
360
|
-
/** Apply discard rules to the last key of a path.
|
|
361
|
-
*
|
|
362
|
-
* Rules:
|
|
363
|
-
* - If discardUndefined=true -> remove `undefined` from value
|
|
364
|
-
* - If discardNull=true -> remove `null` from value
|
|
365
|
-
*
|
|
366
|
-
* Order: first strip undefined (if requested), then strip null (if requested)
|
|
367
|
-
*/
|
|
368
|
-
type ApplyLastRulesHasOwnProp<V, DiscardU extends boolean, DiscardN extends boolean> = DiscardU extends true ? DiscardN extends true ? NonNull<NonUndef<V>> : NonUndef<V> : DiscardN extends true ? NonNull<V> : V | Extract<V, undefined>;
|
|
369
|
-
/** Force an array index N to type U. */
|
|
370
|
-
type RefineArrayAtIndex<T extends readonly unknown[], N extends number, U> = T & {
|
|
371
|
-
[K in N]: U;
|
|
372
|
-
};
|
|
373
|
-
/** Narrow object/array type based on a path string.
|
|
374
|
-
*
|
|
375
|
-
* @template T - object type to narrow
|
|
376
|
-
* @template P - path string like "user.addresses.[2].zip"
|
|
377
|
-
* @template DU - discard undefined
|
|
378
|
-
* @template DN - discard null
|
|
379
|
-
*/
|
|
380
|
-
type NarrowByPathHasOwnProp<T, P extends string, DU extends boolean = true, DN extends boolean = false> = P extends `${infer Head}.${infer Rest}` ? Head extends `[${infer N extends number}]` ? T extends readonly (infer U)[] ? RefineArrayAtIndex<T, N, NarrowByPathHasOwnProp<U, Rest, DU, DN>> : T : Head extends keyof T ? Rest extends `[${infer M extends number}]${infer R}` ? M extends R ? {
|
|
381
|
-
[K in keyof T]-?: NarrowByPathHasOwnProp<EffectiveDiscardUndefined<DU> extends true ? NonUndef<T[K]> : EffectiveDiscardNull<DN> extends true ? NonNull<T[K]> : T[K], Rest, DU, DN>;
|
|
382
|
-
} : EffectiveDiscardUndefined<DU> extends true ? {
|
|
383
|
-
[K in keyof T]-?: K extends Head ? Exclude<NarrowByPathHasOwnProp<EffectiveDiscardNull<DN> extends true ? Exclude<T[K], null> : EffectiveDiscardUndefined<DU> extends true ? Exclude<T[K], undefined> : T[K], Rest, DU, DN>, undefined> : EffectiveDiscardNull<DN> extends true ? Exclude<T[K], null> : EffectiveDiscardUndefined<DU> extends true ? Exclude<T[K], undefined> : T[K];
|
|
384
|
-
} : {
|
|
385
|
-
[K in keyof T]: K extends Head ? NarrowByPathHasOwnProp<EffectiveDiscardNull<DN> extends true ? Exclude<T[K], null> : EffectiveDiscardUndefined<DU> extends true ? Exclude<T[K], undefined> : T[K], Rest, DU, DN> : EffectiveDiscardNull<DN> extends true ? Exclude<T[K], null> : EffectiveDiscardUndefined<DU> extends true ? Exclude<T[K], undefined> : T[K];
|
|
386
|
-
} : {
|
|
387
|
-
[K in keyof T]: K extends Head ? NarrowByPathHasOwnProp<NonNullable<T[K]>, Rest, DU, DN> : T[K];
|
|
388
|
-
} & {
|
|
389
|
-
[K in Head]-?: NarrowByPathHasOwnProp<NonNullable<T[K]>, Rest, DU, DN>;
|
|
390
|
-
} : T : P extends `[${infer N extends number}]` ? T extends readonly (infer U)[] ? RefineArrayAtIndex<T, N, ApplyLastRulesHasOwnProp<NonNullable<U>, DU, DN>> : T : P extends keyof T ? DU extends true ? {
|
|
391
|
-
[K in keyof T]: K extends P ? ApplyLastRulesHasOwnProp<T[K], DU, DN> : T[K];
|
|
392
|
-
} & {
|
|
393
|
-
[K in P]-?: ApplyLastRulesHasOwnProp<T[P], DU, DN>;
|
|
394
|
-
} : {
|
|
395
|
-
[K in keyof T]: K extends P ? ApplyLastRulesHasOwnProp<T[K], DU, DN> : T[K];
|
|
396
|
-
} : T;
|
|
397
|
-
/** * ***Expand an array/string/function into a nested type according
|
|
398
|
-
* to a dot/bracket path.***
|
|
399
|
-
* @private ***types for {@link hasOwnProp}.***
|
|
400
|
-
*/
|
|
401
|
-
type SmartDetectStringHasOwnProp<Obj extends string | undefined | null, Key extends string | number> = Obj extends undefined ? undefined : Obj extends null ? null : IsPositive<ParseNumber<Key>> extends true ? Extends<IsStringLiteral<Obj>, true> extends true ? CharAt<Exclude<Obj, null | undefined>, ParseNumber<Key>> : string | undefined | null : IsPositive<ParseNumber<Key>> extends true ? string | undefined | null : AnyString | undefined | null;
|
|
402
|
-
/** @private ***types for {@link hasOwnProp}.*** */
|
|
403
|
-
type SmartDetectArrayFuncHasOwnProp<Obj extends unknown[] | AnyFunction, Key extends PropertyKey> = Prettify<Obj & DotToNestedSpecialSmartDetect<Key> & {
|
|
404
|
-
length: number;
|
|
405
|
-
}, {
|
|
406
|
-
recursive: false;
|
|
407
|
-
}>;
|
|
408
|
-
/** * ***Smartly detect nested path keys of an unknown object or function,
|
|
409
|
-
* falls-back to inferred nested structure when path is not valid.***
|
|
410
|
-
*
|
|
411
|
-
* @private ***types for {@link hasOwnProp}.***
|
|
412
|
-
*/
|
|
413
|
-
type SmartDetectUnknownKeyHasOwnProp<Obj extends unknown | AnyFunction, Key extends PropertyKey, DiscardUndefined extends boolean = true, DiscardNull extends boolean = false> = Trim<Key> extends "" ? Obj : Prettify<Obj & (Key extends NestedKeyOfHasOwnProp<Obj> ? GuardedHasOwnProp<Obj, Key, DiscardUndefined, DiscardNull> : DotToNestedSpecialSmartDetect<Key>), {
|
|
414
|
-
recursive: true;
|
|
415
|
-
}>;
|
|
416
|
-
/** Convert dot/bracket path string to nested object type with leaf value.
|
|
417
|
-
* Path not found in object key ➔ return unknown.
|
|
418
|
-
*/
|
|
419
|
-
type DotToNestedSpecialSmartDetect<Path extends PropertyKey, Value = unknown> = IsEmptyString<Extract<Path, string>> extends true ? undefined : Path extends `${infer Head}.${infer Rest}` ? Head extends `[${number}]` ? DotToNestedSpecialSmartDetect<Rest, Value>[] : {
|
|
420
|
-
[Key in Head]: DotToNestedSpecialSmartDetect<Rest, Value>;
|
|
421
|
-
} : Path extends `[${number}]` ? Value[] : {
|
|
422
|
-
[Key in Path]: Value;
|
|
423
|
-
};
|
|
424
|
-
/** * ***Guarded wrapper for `NarrowByPathHasOwnProp` with `Prettify`.***
|
|
425
|
-
* @private ***types for {@link hasOwnProp}.***
|
|
426
|
-
*/
|
|
427
|
-
type GuardedHasOwnProp<Obj, Key extends NestedKeyOfHasOwnProp<Obj>, DiscardUndefined extends boolean | undefined, DiscardNull extends boolean | undefined> = Prettify<Obj & NarrowByPathHasOwnProp<Obj, Key & string, EffectiveDiscardUndefined<DiscardUndefined>, EffectiveDiscardNull<DiscardNull>>, {
|
|
428
|
-
recursive: true;
|
|
429
|
-
}>;
|
|
430
|
-
/** * ***Make a specific symbol key deeply required in an object symbols.***
|
|
431
|
-
* **Used internally to enforce stronger type narrowing.**
|
|
432
|
-
* @private ***types for {@link hasOwnProp}.***
|
|
433
|
-
*/
|
|
434
|
-
type DeepRequiredSymbolHasOwnProp<Obj, Sym extends symbol, DU extends boolean = true, DN extends boolean = false> = Prettify<Obj & ({
|
|
435
|
-
[K in keyof Obj & Sym as DU extends true ? K : never]-?: DN extends true ? NonNull<NonUndef<Obj[K]>> : NonUndef<Obj[K]>;
|
|
436
|
-
} & {
|
|
437
|
-
[K in keyof Obj & Sym as DU extends true ? never : K]?: DN extends true ? NonNull<Obj[K]> : Obj[K];
|
|
438
|
-
}), {
|
|
439
|
-
recursive: true;
|
|
440
|
-
}>;
|
|
441
|
-
/** * ***Apply discard rules to numeric keys in an object type.***
|
|
442
|
-
*
|
|
443
|
-
* - If `discardUndefined = true` ➔ undefined removed, key required
|
|
444
|
-
* - If `discardNull = true` ➔ null removed
|
|
445
|
-
*
|
|
446
|
-
* @private ***types for {@link hasOwnProp}.***
|
|
447
|
-
*/
|
|
448
|
-
type NumericKeyHasOwnPropMapped<Obj extends object, K extends NumericKeyOfHasOwnProp<Obj>, DU extends boolean, DN extends boolean> = Prettify<Obj & (IsOptionalKey<Obj, K> extends true ? {
|
|
449
|
-
[P in K]?: DN extends true ? NonNull<Obj[K]> : Obj[K];
|
|
450
|
-
} & (DU extends true ? {
|
|
451
|
-
[P in K]-?: NonUndef<Obj[K]>;
|
|
452
|
-
} : Record<never, never>) : {
|
|
453
|
-
[P in K]-?: DN extends true ? NonNull<Obj[K]> : Obj[K];
|
|
454
|
-
} & (DU extends true ? {
|
|
455
|
-
[P in K]-?: NonUndef<Obj[K]>;
|
|
456
|
-
} : Record<never, never>)), {
|
|
457
|
-
recursive: true;
|
|
458
|
-
}>;
|
|
459
|
-
/** * ***Options to control `hasOwnProp` behavior.***
|
|
460
|
-
* @private ***types options for {@link hasOwnProp}.***
|
|
461
|
-
*/
|
|
462
|
-
type HasOwnPropOptions<DiscardUndefined extends boolean = true, DiscardNull extends boolean = false> = {
|
|
463
|
-
/** If `true` ***(default)***, properties with `undefined` values are treated as non-existent.
|
|
464
|
-
*
|
|
465
|
-
* - **Effects:**
|
|
466
|
-
* - **Runtime:** `hasOwnProp(obj, key)` returns `false` if the property exists but its value is `undefined`.
|
|
467
|
-
* - **TypeScript narrowing:** The property's type is narrowed to exclude `undefined`.
|
|
468
|
-
* - **Example:**
|
|
469
|
-
* ```ts
|
|
470
|
-
* const obj = { a: undefined, b: 123 };
|
|
471
|
-
* hasOwnProp(obj, "a"); // ➔ false
|
|
472
|
-
* hasOwnProp(obj, "a", { discardUndefined: false }); // ➔ true
|
|
473
|
-
* ```
|
|
474
|
-
*/
|
|
475
|
-
discardUndefined?: DiscardUndefined;
|
|
476
|
-
/** If `true` ***(default: `false`)***, properties with `null` values are treated as non-existent.
|
|
477
|
-
*
|
|
478
|
-
* - **Effects:**
|
|
479
|
-
* - **Runtime:** `hasOwnProp(obj, key)` returns `false` if the property exists but its value is `null`.
|
|
480
|
-
* - **TypeScript narrowing:** The property's type is narrowed to exclude `null`.
|
|
481
|
-
* - **Example:**
|
|
482
|
-
* ```ts
|
|
483
|
-
* const obj = { a: null, b: 123 };
|
|
484
|
-
* hasOwnProp(obj, "a"); // ➔ true (default discardNull = false)
|
|
485
|
-
* hasOwnProp(obj, "a", { discardNull: true }); // ➔ false
|
|
486
|
-
* ```
|
|
487
|
-
*/
|
|
488
|
-
discardNull?: DiscardNull;
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
/** -------------------------------------------------------
|
|
492
|
-
* * ***Predicate: `hasOwnProp`.***
|
|
493
|
-
* -------------------------------------------------------
|
|
494
|
-
* **A **type-safe** replacement for `Object.prototype.hasOwnProperty` with runtime validation and **TypeScript-aware type narrowing**.**
|
|
495
|
-
* - #### Supported Targets:
|
|
496
|
-
* - **Plain objects** ➔ `{ foo: "bar" }`.
|
|
497
|
-
* - **Arrays** ➔ `[ { id: 1 }, { id: 2 } ]`.
|
|
498
|
-
* - **Strings** ➔ `"hello"` (as array-like objects with `.length`, index, etc.).
|
|
499
|
-
* - **Functions** ➔ callable objects with extra props.
|
|
500
|
-
* - **Symbols** ➔ own property symbols.
|
|
501
|
-
* - #### Key Advantages over `in` or `obj.hasOwnProperty(key)`:
|
|
502
|
-
* - Supports **dot/bracket path notation** (e.g. `"user.address.city"`, `"addresses[0].zip"`).
|
|
503
|
-
* - Handles **symbol** keys safely.
|
|
504
|
-
* - **Narrows** the type of `obj` in TypeScript (stronger type safety).
|
|
505
|
-
* - Configurable handling of **`undefined`** and **`null`**.
|
|
506
|
-
* - #### Runtime Behavior:
|
|
507
|
-
* - ***✅ Returns `true` if:***
|
|
508
|
-
* - Value `obj` is an object/array/string/function **and** the property
|
|
509
|
-
* exists **and**, it passes the `options` checks.
|
|
510
|
-
* - ***❌ Returns `false` if:***
|
|
511
|
-
* - Value `obj` is not a valid type.
|
|
512
|
-
* - The property does not exist.
|
|
513
|
-
* - The value is `undefined` and `discardUndefined: true` (**default**).
|
|
514
|
-
* - The value is `null` and `discardNull: true`.
|
|
515
|
-
* - The `key` (after trimming) is an **empty string** ➔ treated as **invalid**.
|
|
516
|
-
* - #### TypeScript Behavior:
|
|
517
|
-
* - ***Inside an `if (hasOwnProp(...)) {}` block:***
|
|
518
|
-
* - The property is **guaranteed to exist**.
|
|
519
|
-
* - Depending on `options`, the property type is narrowed to exclude
|
|
520
|
-
* `undefined` and/or `null`.
|
|
521
|
-
* - #### ⚠️ Caveats:
|
|
522
|
-
* - ***Empty keys are invalid:***
|
|
523
|
-
* - If the `key` string is empty (`""`) after trimming whitespace or other characters,
|
|
524
|
-
* it will **not** be considered a valid property and always returns `false`.
|
|
525
|
-
* - ***Arrays are limited by TypeScript inference:***
|
|
526
|
-
* - Checking index `[0]` only narrows **that specific index**, not the rest, example:
|
|
527
|
-
* 1. `hasOwnProp(users, "[0].id")` does **not** imply `users[1].id` exists.
|
|
528
|
-
* - 👉 For different indices, use **optional chaining** (`users[1]?.id`).
|
|
529
|
-
* - ***Autocomplete limitation for array indices:***
|
|
530
|
-
* - Autocompletion for `[index]` is only supported up to **25** (`[0]` ➔ `[24]`).
|
|
531
|
-
* - This limit is intentional for **performance and safety:**
|
|
532
|
-
* 1. Generating infinite union types for all possible indices would cause
|
|
533
|
-
* **TypeScript IntelliSense to hang or crash**.
|
|
534
|
-
* - ℹ️ You can still check higher indices manually (e.g. `"[999].id"`),
|
|
535
|
-
* but they will not show up in IntelliSense suggestions.
|
|
536
|
-
* @param {HasOwnPropOptions} [options] - ***Optional configuration object.***
|
|
537
|
-
* @param {HasOwnPropOptions["discardUndefined"]} [options.discardUndefined=true]
|
|
538
|
-
* ***If `true`, properties with `undefined` values are treated as **missing**, default: `true`.***
|
|
539
|
-
* @param {HasOwnPropOptions["discardNull"]} [options.discardNull=false]
|
|
540
|
-
* ***If `true`, properties with `null` values are treated as **missing**, default: `false`.***
|
|
541
|
-
* @param {*} obj ***The `object`, `array`, `string`, `function`, or `other value` to check against.***
|
|
542
|
-
* @param {PropertyKey} key
|
|
543
|
-
* ***The property key to check, can be:***
|
|
544
|
-
* - `string` (supports dot/bracket paths, e.g. `"user.address.city"`, `"[0].id"`).
|
|
545
|
-
* - `number` (array-like index).
|
|
546
|
-
* - `symbol` (own property symbols).
|
|
547
|
-
* @returns {boolean} Return `true` if the property exists (and passes `options`), otherwise `false`.
|
|
548
|
-
* @example
|
|
549
|
-
*
|
|
550
|
-
* - #### ✅ Objects:
|
|
551
|
-
* ```ts
|
|
552
|
-
* const obj: { name?: string | null } = {};
|
|
553
|
-
*
|
|
554
|
-
* if (hasOwnProp(obj, "name")) {
|
|
555
|
-
* // obj is now ➔ { name: string | null }
|
|
556
|
-
* console.log(obj.name); // string | null
|
|
557
|
-
* }
|
|
558
|
-
*
|
|
559
|
-
* if (hasOwnProp(obj, "name", { discardUndefined: true, discardNull: true })) {
|
|
560
|
-
* // obj is now ➔ { name: string }
|
|
561
|
-
* console.log(obj.name.toUpperCase()); // safe
|
|
562
|
-
* }
|
|
563
|
-
* ```
|
|
564
|
-
* - #### ✅ Arrays:
|
|
565
|
-
* ```ts
|
|
566
|
-
* const users = [{ id: 1 }, { id: 2 }];
|
|
567
|
-
*
|
|
568
|
-
* if (hasOwnProp(users, "[1].id")) {
|
|
569
|
-
* // ➔ users[1].id is guaranteed to exist
|
|
570
|
-
* console.log(users[1].id); // number
|
|
571
|
-
* }
|
|
572
|
-
*
|
|
573
|
-
* // ⚠️ Caveat: narrowing only applies to checked index
|
|
574
|
-
* if (hasOwnProp(users, "[0].id")) {
|
|
575
|
-
* console.log(users[0].id); // ✅ safe
|
|
576
|
-
* console.log(users[1].id); // ❌ not guaranteed!
|
|
577
|
-
* }
|
|
578
|
-
*
|
|
579
|
-
* // 👉 Solution: optional chaining
|
|
580
|
-
* console.log(users[1]?.id); // ➔ safe, even without narrowing
|
|
581
|
-
* ```
|
|
582
|
-
*
|
|
583
|
-
* - #### ✅ Symbols:
|
|
584
|
-
* ```ts
|
|
585
|
-
* const secret = Symbol("secret");
|
|
586
|
-
* const obj2 = { [secret]: 42 };
|
|
587
|
-
*
|
|
588
|
-
* if (hasOwnProp(obj2, secret)) {
|
|
589
|
-
* console.log(obj2[secret] + 1); // ➔ 43
|
|
590
|
-
* }
|
|
591
|
-
* ```
|
|
592
|
-
* - #### ✅ Strings:
|
|
593
|
-
* ```ts
|
|
594
|
-
* if (hasOwnProp("hello", "length")) {
|
|
595
|
-
* console.log("hello".length); // ➔ 5
|
|
596
|
-
* }
|
|
597
|
-
*
|
|
598
|
-
* if (hasOwnProp("hello", 1)) {
|
|
599
|
-
* console.log("hello"[1]); // ➔ "e"
|
|
600
|
-
* }
|
|
601
|
-
* ```
|
|
602
|
-
* - #### ✅ Functions:
|
|
603
|
-
* ```ts
|
|
604
|
-
* function fn() {}
|
|
605
|
-
* fn.extra = 123;
|
|
606
|
-
*
|
|
607
|
-
* if (hasOwnProp(fn, "extra")) {
|
|
608
|
-
* console.log(fn.extra); // ➔ 123
|
|
609
|
-
* }
|
|
610
|
-
* ```
|
|
611
|
-
* - #### ❌ Empty key:
|
|
612
|
-
* ```ts
|
|
613
|
-
* const obj = { a: 1 };
|
|
614
|
-
*
|
|
615
|
-
* hasOwnProp(obj, ""); // ➔ false (invalid key)
|
|
616
|
-
* hasOwnProp(obj, " "); // ➔ false (trimmed to empty)
|
|
617
|
-
* ```
|
|
618
|
-
*/
|
|
619
|
-
declare function hasOwnProp<Obj>(obj: IsAny<Obj> extends true ? Obj : never, key: PropertyKey, options?: HasOwnPropOptions<boolean, boolean>
|
|
620
|
-
/** @ts-expect-error we force `any` to `unknown` at result */
|
|
621
|
-
): obj is unknown;
|
|
622
|
-
declare function hasOwnProp<Obj extends null | undefined>(obj: Obj, key: PropertyKey, options?: HasOwnPropOptions<boolean, boolean>): false;
|
|
623
|
-
declare function hasOwnProp<Obj extends object | AnyFunction, Key extends NestedKeyOfHasOwnProp<Obj>, DiscardUndefined extends boolean = true, DiscardNull extends boolean = false>(obj: Obj | null | undefined, key: Key, options?: HasOwnPropOptions<DiscardUndefined, DiscardNull>
|
|
624
|
-
/** @ts-expect-error we force to override recursive type result */
|
|
625
|
-
): obj is GuardedHasOwnProp<Obj, Key, DiscardUndefined, DiscardNull>;
|
|
626
|
-
declare function hasOwnProp<Obj extends object, Num extends NumericKeyOfHasOwnProp<Obj>, DiscardUndefined extends boolean = true, DiscardNull extends boolean = false>(obj: Obj | null | undefined, key: Num, options?: HasOwnPropOptions<DiscardUndefined, DiscardNull>
|
|
627
|
-
/** @ts-expect-error we force to override recursive type result */
|
|
628
|
-
): obj is NumericKeyHasOwnPropMapped<Obj, Num, DiscardUndefined, DiscardNull>;
|
|
629
|
-
declare function hasOwnProp<Obj extends object | AnyFunction, Sym extends symbol, DiscardUndefined extends boolean = true, DiscardNull extends boolean = false>(obj: Obj | null | undefined, key: Sym, options?: HasOwnPropOptions<DiscardUndefined, DiscardNull>
|
|
630
|
-
/** @ts-expect-error we force to override recursive type result */
|
|
631
|
-
): obj is DeepRequiredSymbolHasOwnProp<Obj, Sym, DiscardUndefined, DiscardNull>;
|
|
632
|
-
declare function hasOwnProp<Obj extends string | null | undefined, Key extends string | number>(obj: Obj | null | undefined, key: Key, options?: HasOwnPropOptions<boolean, boolean>
|
|
633
|
-
/** @ts-expect-error we force to override recursive type result */
|
|
634
|
-
): obj is IsStringLiteral<SmartDetectStringHasOwnProp<Obj, Key>> extends true ? AnyString | SmartDetectStringHasOwnProp<Obj, Key> : SmartDetectStringHasOwnProp<Obj, Key>;
|
|
635
|
-
declare function hasOwnProp<Obj extends unknown[] | AnyFunction, Key extends PropertyKey>(obj: Obj, key: Key, options?: HasOwnPropOptions<boolean, boolean>): obj is SmartDetectArrayFuncHasOwnProp<Obj, Key>;
|
|
636
|
-
declare function hasOwnProp<Obj extends unknown | AnyFunction, Key extends PropertyKey, DiscardUndefined extends boolean = true, DiscardNull extends boolean = false>(obj: Obj, key: Key | "length" | (IsPlainObjectResult<Obj> extends never ? never : keyof Obj), options?: HasOwnPropOptions<DiscardUndefined, DiscardNull>
|
|
637
|
-
/** @ts-expect-error we force to override recursive type result */
|
|
638
|
-
): obj is SmartDetectUnknownKeyHasOwnProp<Obj, Key, DiscardUndefined, DiscardNull>;
|
|
639
|
-
|
|
640
|
-
/** -------------------
|
|
641
|
-
* * ***Type guard: `isArguments`.***
|
|
642
|
-
* -------------------
|
|
643
|
-
* **Checks if `value` is likely an `arguments` object.**
|
|
644
|
-
* @param {*} value The value to check.
|
|
645
|
-
* @returns {boolean} Returns `true` if `value` is an ***[`IArguments`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments)*** object, else `false`.
|
|
646
|
-
* @example
|
|
647
|
-
* isArguments(function() { return arguments; }());
|
|
648
|
-
* // ➔ true
|
|
649
|
-
* isArguments([1, 2, 3]);
|
|
650
|
-
* // ➔ false
|
|
651
|
-
*/
|
|
652
|
-
declare const isArguments: (value: unknown) => value is IArguments;
|
|
653
|
-
|
|
654
|
-
/** ----------------------------------------------------------
|
|
655
|
-
* * ***Type guard: `isArray`.***
|
|
656
|
-
* ----------------------------------------------------------
|
|
657
|
-
***Checks if a value is an ***[`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)***.**
|
|
658
|
-
* - **Behavior:**
|
|
659
|
-
* - Uses ***[`Array.isArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)*** for reliable and safe type checking.
|
|
660
|
-
* - Supports TypeScript **type narrowing** using `value is T[]`.
|
|
661
|
-
* - Handles edge cases like `null`, `undefined`, and non-array objects.
|
|
662
|
-
* @template T - The expected type of array elements.
|
|
663
|
-
* @param {*} value - The value to check.
|
|
664
|
-
* @returns {boolean} Returns `true` if the value is an `array`, otherwise `false`.
|
|
665
|
-
* @example
|
|
666
|
-
* isArray([1, 2, 3]);
|
|
667
|
-
* // ➔ true
|
|
668
|
-
* isArray([]);
|
|
669
|
-
* // ➔ true
|
|
670
|
-
* isArray("hello");
|
|
671
|
-
* // ➔ false
|
|
672
|
-
* isArray({ key: "value" });
|
|
673
|
-
* // ➔ false
|
|
674
|
-
* isArray(null);
|
|
675
|
-
* // ➔ false
|
|
676
|
-
* isArray(undefined);
|
|
677
|
-
* // ➔ false
|
|
678
|
-
*/
|
|
679
|
-
declare function isArray(value: []): value is [];
|
|
680
|
-
declare function isArray<T>(value: T): value is ArrayFallback<T>;
|
|
681
|
-
declare function isArray(value: unknown): value is unknown[];
|
|
682
|
-
|
|
683
|
-
/** ----------------------------------------------------
|
|
684
|
-
* * ***Type guard: `isArrayBuffer`.***
|
|
685
|
-
* ----------------------------------------------------
|
|
686
|
-
* **Checks if `value` is classified as an `ArrayBuffer` object.**
|
|
687
|
-
* @param {*} value The value to check.
|
|
688
|
-
* @returns {boolean} Returns `true` if `value` is instance of ***[`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)***, else `false`.
|
|
689
|
-
* @example
|
|
690
|
-
* isArrayBuffer(new ArrayBuffer(2));
|
|
691
|
-
* // ➔ true
|
|
692
|
-
* isArrayBuffer(new Array(2));
|
|
693
|
-
* // ➔ false
|
|
694
|
-
*/
|
|
695
|
-
declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
|
|
696
|
-
|
|
697
|
-
/** ----------------------------------------------------
|
|
698
|
-
* * ***Type guard: `isArrayLike`.***
|
|
699
|
-
* ----------------------------------------------------
|
|
700
|
-
* **Checks if `value` is array-like, a value is considered array-like if it's
|
|
701
|
-
* not a function and has a `value.length` that's an integer greater than or
|
|
702
|
-
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.**
|
|
703
|
-
* @template T - The type of the value being checked.
|
|
704
|
-
* @param {*} value The value to check.
|
|
705
|
-
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
|
706
|
-
* @example
|
|
707
|
-
* isArrayLike([1, 2, 3]);
|
|
708
|
-
* // ➔ true
|
|
709
|
-
* isArrayLike(document.body.children);
|
|
710
|
-
* // ➔ true
|
|
711
|
-
* isArrayLike(noop);
|
|
712
|
-
* // ➔ false
|
|
713
|
-
* isArrayLike('abc');
|
|
714
|
-
* // ➔ false
|
|
715
|
-
*/
|
|
716
|
-
declare function isArrayLike<T extends {
|
|
717
|
-
__anyHack: unknown;
|
|
718
|
-
}>(value: T): boolean;
|
|
719
|
-
declare function isArrayLike(value: AnyFunction | null | undefined): value is never;
|
|
720
|
-
declare function isArrayLike(value: unknown): value is {
|
|
721
|
-
length: number;
|
|
722
|
-
};
|
|
723
|
-
|
|
724
|
-
/** ----------------------------------------------------
|
|
725
|
-
* * ***Type guard: `isArrayLikeObject`.***
|
|
726
|
-
* ----------------------------------------------------
|
|
727
|
-
* **This method is like ***`isArrayLike` utility function*** except that
|
|
728
|
-
* it also checks if `value` is an object.**
|
|
729
|
-
* @template T - The type of the value being checked.
|
|
730
|
-
* @param {*} value The value to check.
|
|
731
|
-
* @returns {boolean} Returns `true` if `value` is `array-like object`, else `false`.
|
|
732
|
-
* @example
|
|
733
|
-
* isArrayLikeObject([1, 2, 3]);
|
|
734
|
-
* // ➔ true
|
|
735
|
-
* isArrayLikeObject(document.body.children);
|
|
736
|
-
* // ➔ true
|
|
737
|
-
* isArrayLikeObject('abc');
|
|
738
|
-
* // ➔ false
|
|
739
|
-
* isArrayLikeObject(noop);
|
|
740
|
-
* // ➔ false
|
|
741
|
-
*/
|
|
742
|
-
declare function isArrayLikeObject<T extends {
|
|
743
|
-
__anyHack: unknown;
|
|
744
|
-
}>(value: T): boolean;
|
|
745
|
-
declare function isArrayLikeObject(value: AnyFunction | string | boolean | number | null | undefined): value is never;
|
|
746
|
-
declare function isArrayLikeObject(value: unknown): value is object & {
|
|
747
|
-
length: number;
|
|
748
|
-
};
|
|
749
|
-
|
|
750
|
-
/** ----------------------------------------------------------
|
|
751
|
-
* * ***Type guard: `isBigInt`.***
|
|
752
|
-
* ----------------------------------------------------------
|
|
753
|
-
* **Checks if a value is of type **[`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)**.**
|
|
754
|
-
* - **Behavior:**
|
|
755
|
-
* - Uses `typeof value === "bigint"` for strict type checking.
|
|
756
|
-
* - Supports TypeScript type narrowing with `value is bigint`.
|
|
757
|
-
* - Returns `false` for `BigInt` object (object-wrapped), e.g:
|
|
758
|
-
* - `Object(BigInt(123))`.
|
|
759
|
-
* @param {*} value - The value to check.
|
|
760
|
-
* @returns {boolean} Return `true` if value is a primitive bigint.
|
|
761
|
-
* @example
|
|
762
|
-
* isBigInt(123n);
|
|
763
|
-
* // ➔ true
|
|
764
|
-
* isBigInt(BigInt(123));
|
|
765
|
-
* // ➔ true
|
|
766
|
-
* isBigInt("123");
|
|
767
|
-
* // ➔ false
|
|
768
|
-
* isBigInt(Object(BigInt(1)));
|
|
769
|
-
* // ➔ false
|
|
770
|
-
*/
|
|
771
|
-
declare const isBigInt: (value: unknown) => value is bigint;
|
|
772
|
-
|
|
773
|
-
/** ----------------------------------------------------------
|
|
774
|
-
* * ***Type guard: `isBoolean`.***
|
|
775
|
-
* ----------------------------------------------------------
|
|
776
|
-
* **Checks if a value is of type **[`boolean`](https://developer.mozilla.org/en-US/docs/Glossary/Boolean/JavaScript)**.**
|
|
777
|
-
* @param {*} value - The value to check.
|
|
778
|
-
* @returns {boolean} Returns `true` if the value is a `boolean`, otherwise `false`.
|
|
779
|
-
* @example
|
|
780
|
-
* isBoolean(true); // ➔ true
|
|
781
|
-
* isBoolean(false); // ➔ true
|
|
782
|
-
* isBoolean("true"); // ➔ false
|
|
783
|
-
*/
|
|
784
|
-
declare const isBoolean: (value: unknown) => value is boolean;
|
|
785
|
-
|
|
786
|
-
/** ----------------------------------------------------
|
|
787
|
-
* * ***Type guard: `isBooleanObject`.***
|
|
788
|
-
* ----------------------------------------------------
|
|
789
|
-
* **Checks if a value is a **`Boolean` object wrapper**
|
|
790
|
-
* (`new Boolean(...)`), not a primitive boolean.**
|
|
791
|
-
* @param {*} value The value to check.
|
|
792
|
-
* @returns {value is Boolean} Returns `true` if `value` is a `Boolean` object.
|
|
793
|
-
* @example
|
|
794
|
-
* isBooleanObject(new Boolean(true));
|
|
795
|
-
* // ➔ true
|
|
796
|
-
* isBooleanObject(true);
|
|
797
|
-
* // ➔ false
|
|
798
|
-
*/
|
|
799
|
-
declare function isBooleanObject(value: unknown): value is Boolean;
|
|
800
|
-
|
|
801
|
-
/** ----------------------------------------------------
|
|
802
|
-
* * ***Type guard: `isBuffer`.***
|
|
803
|
-
* ----------------------------------------------------------
|
|
804
|
-
* **Checks if a value is a *****{@link Buffer | `Node.js - Buffer`}***** instance.**
|
|
805
|
-
* @param {*} value The value to check.
|
|
806
|
-
* @returns {boolean} Returns `true` if `value` is a `Buffer`, else `false`.
|
|
807
|
-
* @example
|
|
808
|
-
* isBuffer(new Buffer(2));
|
|
809
|
-
* // ➔ true
|
|
810
|
-
* isBuffer(Buffer.alloc(10));
|
|
811
|
-
* // ➔ true
|
|
812
|
-
* isBuffer(Buffer.from('foo'));
|
|
813
|
-
* // ➔ true
|
|
814
|
-
* isBuffer([]);
|
|
815
|
-
* // ➔ false
|
|
816
|
-
* isBuffer('a string');
|
|
817
|
-
* // ➔ false
|
|
818
|
-
* isBuffer(new Uint8Array(1024));
|
|
819
|
-
* // ➔ false
|
|
820
|
-
*/
|
|
821
|
-
declare const isBuffer: (value: unknown) => value is Buffer;
|
|
822
|
-
|
|
823
|
-
/** -----------------------------------------------------------
|
|
824
|
-
* * ***Predicate: `isCurrencyLike`.***
|
|
825
|
-
* -----------------------------------------------------------
|
|
826
|
-
* **Determines if the given `input` can be interpreted as a currency-like number,
|
|
827
|
-
* using the same **multi-locale parsing logic** as ***`parseCurrencyString`***.**
|
|
828
|
-
* - **Highlights:**
|
|
829
|
-
* - *Supports strings or numbers like:*
|
|
830
|
-
* - `"15.000,10"` ***(European)***.
|
|
831
|
-
* - `"15,000.10"` ***(US)***.
|
|
832
|
-
* - `"15'000.10"` ***(Swiss)***.
|
|
833
|
-
* - `"15 000,10"` ***(French)***.
|
|
834
|
-
* - `"Rp 15.000,10"` or `"$15,000.10"`.
|
|
835
|
-
* - Also accepts simple numbers (`15300.95`).
|
|
836
|
-
* - **ℹ️ Note:**
|
|
837
|
-
* - Uses the same core logic as
|
|
838
|
-
* ***`parseCurrencyString`*** but
|
|
839
|
-
* just checks if a final parsed float is sensible.
|
|
840
|
-
* @param {*} input - The input value to check.
|
|
841
|
-
* @returns {boolean} Return `true` if it can be reasonably parsed into a currency-like number, `false` otherwise.
|
|
842
|
-
* @example
|
|
843
|
-
* isCurrencyLike(15300.95);
|
|
844
|
-
* // ➔ true
|
|
845
|
-
* isCurrencyLike("$15,000.10");
|
|
846
|
-
* // ➔ true
|
|
847
|
-
* isCurrencyLike("(15'000.10)");
|
|
848
|
-
* // ➔ true
|
|
849
|
-
* isCurrencyLike("Rp 15.000,10");
|
|
850
|
-
* // ➔ true
|
|
851
|
-
* isCurrencyLike("");
|
|
852
|
-
* // ➔ false
|
|
853
|
-
* isCurrencyLike("abc");
|
|
854
|
-
* // ➔ false
|
|
855
|
-
*/
|
|
856
|
-
declare const isCurrencyLike: (input: unknown) => boolean;
|
|
857
|
-
|
|
858
|
-
type isDateOptions = {
|
|
859
|
-
/** * ***Skip the validity check (`!isNaN(date.getTime())`).***
|
|
860
|
-
*
|
|
861
|
-
* When `true`, the function only checks that the value is an
|
|
862
|
-
* instance of `Date` without verifying that it represents a valid
|
|
863
|
-
* date value, default: `false`.
|
|
864
|
-
*
|
|
865
|
-
* @default false
|
|
866
|
-
*/
|
|
867
|
-
skipInvalidDate?: boolean;
|
|
868
|
-
};
|
|
869
|
-
/** ----------------------------------------------------------
|
|
870
|
-
* * ***Type guard: `isDate`.***
|
|
871
|
-
* ----------------------------------------------------------
|
|
872
|
-
* **Determines whether the given `value` is a real, valid JavaScript
|
|
873
|
-
* **[`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)** object.**
|
|
874
|
-
* - **Behavior:**
|
|
875
|
-
* - Returns **true** only if:
|
|
876
|
-
* - `value` is an instance of `Date`.
|
|
877
|
-
* - and, unless `options.skipInvalidDate` is `true`,
|
|
878
|
-
* the underlying time value is valid (`!isNaN(value.getTime())`).
|
|
879
|
-
* - Returns **false** for:
|
|
880
|
-
* - non-Date values (strings, numbers, etc.).
|
|
881
|
-
* - `Date` instances that represent an invalid time value
|
|
882
|
-
* (e.g. `new Date("bad")`), unless skipping is enabled.
|
|
883
|
-
* @param {*} value - The value to check.
|
|
884
|
-
* @param {isDateOptions} [options] - Optional settings.
|
|
885
|
-
* @returns {boolean} Return `true` if value is a valid Date object.
|
|
886
|
-
* @example
|
|
887
|
-
* isDate(new Date());
|
|
888
|
-
* // ➜ true
|
|
889
|
-
* isDate(new Date("invalid"));
|
|
890
|
-
* // ➜ false
|
|
891
|
-
* isDate("2024-01-01");
|
|
892
|
-
* // ➜ false
|
|
893
|
-
*
|
|
894
|
-
* // Skipping validity check:
|
|
895
|
-
* isDate(new Date("invalid"), { skipInvalidDate: true });
|
|
896
|
-
* // ➜ true
|
|
897
|
-
*/
|
|
898
|
-
declare const isDate: (value: unknown, options?: isDateOptions) => value is Date;
|
|
899
|
-
|
|
900
|
-
/** ----------------------------------------------------------
|
|
901
|
-
* * ***Predicate: `isDeepEqual`.***
|
|
902
|
-
* ----------------------------------------------------------
|
|
903
|
-
* **Performs a deep equality check between two values.**
|
|
904
|
-
* - **Behavior:**
|
|
905
|
-
* - Compares nested `arrays`, `objects`, `Dates`, `RegExp`, `NaN`, `Symbols`,
|
|
906
|
-
* `Set`, and `Map`.
|
|
907
|
-
* - Handles special cases:
|
|
908
|
-
* - `NaN` is considered equal to `NaN`.
|
|
909
|
-
* - `Date` objects are equal if `.getTime()` is equal.
|
|
910
|
-
* - `RegExp` objects are equal if `.toString()` is equal.
|
|
911
|
-
* - `Symbol("x")` and `Symbol("x")` are treated equal if
|
|
912
|
-
* `.toString()` matches.
|
|
913
|
-
* - `Set` and `Map` are deeply compared by content (order-insensitive).
|
|
914
|
-
* - **ℹ️ Note:**
|
|
915
|
-
* - Does not support circular references.
|
|
916
|
-
* @param {*} a - First value to compare.
|
|
917
|
-
* @param {*} b - Second value to compare.
|
|
918
|
-
* @returns {boolean} `true` if both values are deeply equal, otherwise `false`.
|
|
919
|
-
* @example
|
|
920
|
-
* // ✅ Primitives
|
|
921
|
-
* isDeepEqual(1, 1);
|
|
922
|
-
* // ➔ true
|
|
923
|
-
* isDeepEqual(NaN, NaN);
|
|
924
|
-
* // ➔ true
|
|
925
|
-
* isDeepEqual("hello", "world");
|
|
926
|
-
* // ➔ false
|
|
927
|
-
*
|
|
928
|
-
* // ✅ Objects
|
|
929
|
-
* isDeepEqual({ x: 1 }, { x: 1 });
|
|
930
|
-
* // ➔ true
|
|
931
|
-
* isDeepEqual({ x: 1 }, { y: 1 });
|
|
932
|
-
* // ➔ false
|
|
933
|
-
*
|
|
934
|
-
* // ✅ Arrays
|
|
935
|
-
* isDeepEqual([1, 2], [1, 2]);
|
|
936
|
-
* // ➔ true
|
|
937
|
-
* isDeepEqual([1, 2], [2, 1]);
|
|
938
|
-
* // ➔ false
|
|
939
|
-
*
|
|
940
|
-
* // ✅ Dates
|
|
941
|
-
* isDeepEqual(new Date(123), new Date(123));
|
|
942
|
-
* // ➔ true
|
|
943
|
-
*
|
|
944
|
-
* // ✅ Sets
|
|
945
|
-
* isDeepEqual(new Set([1, 2]), new Set([2, 1]));
|
|
946
|
-
* // ➔ true
|
|
947
|
-
*
|
|
948
|
-
* // ✅ Maps
|
|
949
|
-
* isDeepEqual(new Map([["a", 1]]), new Map([["a", 1]]));
|
|
950
|
-
* // ➔ true
|
|
951
|
-
*
|
|
952
|
-
* // ❌ Different types
|
|
953
|
-
* isDeepEqual(1, "1");
|
|
954
|
-
* // ➔ false
|
|
955
|
-
*/
|
|
956
|
-
declare const isDeepEqual: (a: unknown, b: unknown) => boolean;
|
|
957
|
-
|
|
958
|
-
/** ----------------------------------------------------
|
|
959
|
-
* * ***Type guard: `isElement`.***
|
|
960
|
-
* ----------------------------------------------------------
|
|
961
|
-
* **Checks if `value` is likely a
|
|
962
|
-
* **[`DOM Element`](https://developer.mozilla.org/en-US/docs/Web/API/Element)**.**
|
|
963
|
-
* @template T - The type of the value being checked.
|
|
964
|
-
* @param {*} value The value to check.
|
|
965
|
-
* @returns {boolean} Returns `true` if `value` is extends instance of **[`Element`](https://developer.mozilla.org/en-US/docs/Web/API/Element)**, else `false`.
|
|
966
|
-
* @example
|
|
967
|
-
* isElement(document.body);
|
|
968
|
-
* // ➔ true
|
|
969
|
-
* isElement(document.createElement("div"));
|
|
970
|
-
* // ➔ true
|
|
971
|
-
* isElement('<body>');
|
|
972
|
-
* // ➔ false
|
|
973
|
-
* isElement(document);
|
|
974
|
-
* // ➔ false
|
|
975
|
-
* isElement({ tagName: "DIV" });
|
|
976
|
-
* // ➔ false
|
|
977
|
-
*/
|
|
978
|
-
declare function isElement(value: []): value is [];
|
|
979
|
-
declare function isElement<T extends Element>(value: T): value is T;
|
|
980
|
-
declare function isElement(value: unknown): value is Element;
|
|
981
|
-
|
|
982
|
-
/**
|
|
983
|
-
* -------------------------------------------------------------------
|
|
984
|
-
* * ***Array-like structure interface.***
|
|
985
|
-
* -------------------------------------------------------------------
|
|
986
|
-
* **Represents objects with indexed elements and a `length` property,
|
|
987
|
-
* similar to arrays, but not necessarily full Array instances.**
|
|
988
|
-
* @template T The type of elements stored in the array-like object.
|
|
989
|
-
* @example
|
|
990
|
-
* ```ts
|
|
991
|
-
* function logArrayLike<T>(items: ArrayLike<T>) {
|
|
992
|
-
* for (let i = 0; i < items.length; i++) {
|
|
993
|
-
* console.log(items[i]);
|
|
994
|
-
* }
|
|
995
|
-
* }
|
|
996
|
-
*
|
|
997
|
-
* const myNodeList: ArrayLike<Element> = document.querySelectorAll("div");
|
|
998
|
-
* logArrayLike(myNodeList);
|
|
999
|
-
* ```
|
|
1000
|
-
*/
|
|
1001
|
-
interface ArrayLike<T> {
|
|
1002
|
-
/** * ***Number of elements in the array-like object.*** */
|
|
1003
|
-
readonly length: number;
|
|
1004
|
-
/** * ***Indexed access to elements.*** */
|
|
1005
|
-
readonly [n: number]: T;
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
/** -------------------------------------------------------------------
|
|
1009
|
-
* * ***Represents an object with no allowed properties.***
|
|
1010
|
-
* -------------------------------------------------------------------
|
|
1011
|
-
* **Useful for cases where you want to ensure a type has **no keys**.**
|
|
1012
|
-
* @template T - The base type to convert into an empty object type.
|
|
1013
|
-
* @example
|
|
1014
|
-
* ```ts
|
|
1015
|
-
* type Test = EmptyObject<{ a: number }>;
|
|
1016
|
-
* // ➔ { a?: never }
|
|
1017
|
-
* ```
|
|
1018
|
-
*/
|
|
1019
|
-
type EmptyObject<T> = {
|
|
1020
|
-
[K in keyof T]?: never;
|
|
1021
|
-
};
|
|
1022
|
-
/** -------------------------------------------------------------------
|
|
1023
|
-
* * ***Conditional empty object type.***
|
|
1024
|
-
* -------------------------------------------------------------------
|
|
1025
|
-
* **Produces `EmptyObject<T>` only if it is assignable to `T`.**
|
|
1026
|
-
* @template T - The base type to check.
|
|
1027
|
-
* @example
|
|
1028
|
-
* ```ts
|
|
1029
|
-
* type Test = EmptyObjectOf<{ a: number }>;
|
|
1030
|
-
* // ➔ { a?: never } | never depending on assignability
|
|
1031
|
-
* ```
|
|
1032
|
-
*/
|
|
1033
|
-
type EmptyObjectOf<T> = EmptyObject<T> extends T ? EmptyObject<T> : never;
|
|
1034
|
-
/** -------------------------------------------------------------------
|
|
1035
|
-
* * ***List type alias.***
|
|
1036
|
-
* -------------------------------------------------------------------
|
|
1037
|
-
* **Represents any array-like structure.**
|
|
1038
|
-
* @template T - The type of elements in the list.
|
|
1039
|
-
* @example
|
|
1040
|
-
* ```ts
|
|
1041
|
-
* const arr: List<number> = [1, 2, 3];
|
|
1042
|
-
* const nodeList: List<Element> = document.querySelectorAll("div");
|
|
1043
|
-
* ```
|
|
1044
|
-
*/
|
|
1045
|
-
type List<T> = ArrayLike<T>;
|
|
1046
|
-
|
|
1047
|
-
/** ----------------------------------------------------
|
|
1048
|
-
* * ***Predicate: `isEmpty`.***
|
|
1049
|
-
* ----------------------------------------------------------
|
|
1050
|
-
* **Checks if `value` is an empty object, collection, map, or set.**
|
|
1051
|
-
* - **Behavior:**
|
|
1052
|
-
* - **Objects** are empty if they have no own enumerable string keyed properties.
|
|
1053
|
-
* - **Array-like values** (arrays, strings, `arguments`, typed arrays, buffers)
|
|
1054
|
-
* are empty if their `length` is `0`.
|
|
1055
|
-
* - **Maps** and **Sets** are empty if their `size` is `0`.
|
|
1056
|
-
* - **Booleans**, **numbers** (including `NaN`), **symbols**, and `null`/
|
|
1057
|
-
* `undefined` are treated as empty.
|
|
1058
|
-
* - **Functions** are considered empty if they have no own enumerable keys.
|
|
1059
|
-
* - **ℹ️ Note:**
|
|
1060
|
-
* - For more `Strict`, you can use
|
|
1061
|
-
* ***`isEmptyValue` utility function*** instead.
|
|
1062
|
-
* @template T - The type of the value being checked.
|
|
1063
|
-
* @param {*} value The value to check.
|
|
1064
|
-
* @returns {boolean} Returns `true` if `value` is empty, else `false`.
|
|
1065
|
-
* @example
|
|
1066
|
-
* isEmpty(null);
|
|
1067
|
-
* // ➔ true
|
|
1068
|
-
* isEmpty(true);
|
|
1069
|
-
* // ➔ true
|
|
1070
|
-
* isEmpty(false);
|
|
1071
|
-
* // ➔ true
|
|
1072
|
-
* isEmpty(1);
|
|
1073
|
-
* // ➔ true
|
|
1074
|
-
* isEmpty(0);
|
|
1075
|
-
* // ➔ true
|
|
1076
|
-
* isEmpty(Symbol("x"));
|
|
1077
|
-
* // ➔ true
|
|
1078
|
-
* isEmpty(() => {});
|
|
1079
|
-
* // ➔ true
|
|
1080
|
-
* isEmpty("");
|
|
1081
|
-
* // ➔ true
|
|
1082
|
-
* isEmpty(" ");
|
|
1083
|
-
* // ➔ false
|
|
1084
|
-
* isEmpty([1, 2, 3]);
|
|
1085
|
-
* // ➔ false
|
|
1086
|
-
* isEmpty({ 'a': 1 });
|
|
1087
|
-
* // ➔ false
|
|
1088
|
-
*/
|
|
1089
|
-
declare function isEmpty<T extends {
|
|
1090
|
-
__trapAny: any;
|
|
1091
|
-
}>(value?: T): boolean;
|
|
1092
|
-
declare function isEmpty(value: string): value is "";
|
|
1093
|
-
declare function isEmpty(value: Map<any, any> | Set<any> | List<any> | null | undefined): boolean;
|
|
1094
|
-
declare function isEmpty(value: object): boolean;
|
|
1095
|
-
declare function isEmpty<T extends object>(value: T | null | undefined): value is EmptyObjectOf<T> | null | undefined;
|
|
1096
|
-
declare function isEmpty(value: any): boolean;
|
|
1097
|
-
|
|
1098
|
-
/** ----------------------------------------------------------
|
|
1099
|
-
* * ***Predicate: `isEmptyArray`.***
|
|
1100
|
-
* ----------------------------------------------------------
|
|
1101
|
-
* **Checks whether a given value is an empty array.**
|
|
1102
|
-
* - **Behavior:**
|
|
1103
|
-
* - Non-array inputs are considered ***`empty`*** ***(defensive strategy)***.
|
|
1104
|
-
* @param {*} [value] - The value to check.
|
|
1105
|
-
* @returns {boolean} Returns `true` if it's ***not an array*** or ***an empty-array***.
|
|
1106
|
-
* @example
|
|
1107
|
-
* isEmptyArray([]); // ➔ true
|
|
1108
|
-
* isEmptyArray([1, 2, 3]); // ➔ false
|
|
1109
|
-
* isEmptyArray("not an array"); // ➔ true
|
|
1110
|
-
* isEmptyArray(null); // ➔ true
|
|
1111
|
-
* isEmptyArray(undefined); // ➔ true
|
|
1112
|
-
*
|
|
1113
|
-
* if (isEmptyArray(data.items)) {
|
|
1114
|
-
* console.log("No items to display.");
|
|
1115
|
-
* }
|
|
1116
|
-
*/
|
|
1117
|
-
declare const isEmptyArray: (value: unknown) => boolean;
|
|
1118
|
-
|
|
1119
|
-
/** ----------------------------------------------------------
|
|
1120
|
-
* * ***Predicate: `isEmptyDeep`.***
|
|
1121
|
-
* ----------------------------------------------------------
|
|
1122
|
-
* **Recursively checks whether a value is **deeply empty**.**
|
|
1123
|
-
* - **Returns `true` for:**
|
|
1124
|
-
* - Empty objects: `{}`
|
|
1125
|
-
* - Empty arrays: `[]`
|
|
1126
|
-
* - Nested empty structures: `{ a: [], b: {} }`
|
|
1127
|
-
* - Falsy values (except numbers): `null`, `undefined`, `false`, `""`, `NaN`
|
|
1128
|
-
* - **Returns `false` for:**
|
|
1129
|
-
* - Non-zero numbers
|
|
1130
|
-
* - Objects or arrays containing non-empty values
|
|
1131
|
-
* - Non-empty strings, `true`, functions, symbols, etc.
|
|
1132
|
-
* @param {*} value - The value to deeply check.
|
|
1133
|
-
* @returns {boolean} `true` if the value is deeply empty, otherwise `false`.
|
|
1134
|
-
* @example
|
|
1135
|
-
* isEmptyDeep({});
|
|
1136
|
-
* // ➔ true
|
|
1137
|
-
* isEmptyDeep([]);
|
|
1138
|
-
* // ➔ true
|
|
1139
|
-
* isEmptyDeep({ a: {} });
|
|
1140
|
-
* // ➔ true
|
|
1141
|
-
* isEmptyDeep([[], {}]);
|
|
1142
|
-
* // ➔ true
|
|
1143
|
-
* isEmptyDeep({ a: [1] });
|
|
1144
|
-
* // ➔ false
|
|
1145
|
-
* isEmptyDeep([0]);
|
|
1146
|
-
* // ➔ false
|
|
1147
|
-
* isEmptyDeep("test");
|
|
1148
|
-
* // ➔ false
|
|
1149
|
-
* isEmptyDeep("");
|
|
1150
|
-
* // ➔ true
|
|
1151
|
-
* isEmptyDeep(0);
|
|
1152
|
-
* // ➔ false
|
|
1153
|
-
* isEmptyDeep(NaN);
|
|
1154
|
-
* // ➔ true
|
|
1155
|
-
*/
|
|
1156
|
-
declare const isEmptyDeep: (value: unknown) => boolean;
|
|
1157
|
-
|
|
1158
|
-
type IsEmptyObjectOptions = {
|
|
1159
|
-
/** Whether to check for symbol properties in addition to string keys, defaultValue: `false`.
|
|
1160
|
-
*
|
|
1161
|
-
* @default false
|
|
1162
|
-
*/
|
|
1163
|
-
checkSymbols?: boolean;
|
|
1164
|
-
};
|
|
1165
|
-
/** ----------------------------------------------------------
|
|
1166
|
-
* * ***Predicate: `isEmptyObject`.***
|
|
1167
|
-
* ----------------------------------------------------------
|
|
1168
|
-
* **Checks if a value is a plain object with **no own enumerable string-key properties**,
|
|
1169
|
-
* and optionally **no own enumerable symbol-key properties** when `checkSymbols` is `true`.**
|
|
1170
|
-
* - **Behavior:**
|
|
1171
|
-
* - If the value is **not an object** (e.g. `null`, array, primitive), it is considered empty.
|
|
1172
|
-
* - If `options.checkSymbols` is `true`, **symbol properties** are also checked.
|
|
1173
|
-
* @param {*} value - The value to check.
|
|
1174
|
-
* @param {IsEmptyObjectOptions} [options] - Optional settings.
|
|
1175
|
-
* @param {IsEmptyObjectOptions["checkSymbols"]} [options.checkSymbols=false] - Whether to also check symbol properties.
|
|
1176
|
-
* @returns {boolean} Return `true` if the value is considered empty or not an object, false otherwise.
|
|
1177
|
-
* @example
|
|
1178
|
-
* isEmptyObject({});
|
|
1179
|
-
* // ➔ true
|
|
1180
|
-
* isEmptyObject({}, { checkSymbols: true });
|
|
1181
|
-
* // ➔ true
|
|
1182
|
-
* isEmptyObject({ a: 1 });
|
|
1183
|
-
* // ➔ false
|
|
1184
|
-
* isEmptyObject({ [Symbol('s')]: 1 });
|
|
1185
|
-
* // ➔ true
|
|
1186
|
-
* isEmptyObject({ [Symbol('s')]: 1 }, { checkSymbols: true });
|
|
1187
|
-
* // ➔ false
|
|
1188
|
-
* isEmptyObject(null);
|
|
1189
|
-
* // ➔ true (not object)
|
|
1190
|
-
* isEmptyObject([]);
|
|
1191
|
-
* // ➔ true (not plain object)
|
|
1192
|
-
* isEmptyObject(123);
|
|
1193
|
-
* // ➔ true (not object)
|
|
1194
|
-
*/
|
|
1195
|
-
declare function isEmptyObject(value: unknown, options?: IsEmptyObjectOptions): boolean;
|
|
1196
|
-
|
|
1197
|
-
type IsEmptyStringOptions = {
|
|
1198
|
-
/** Whether to trim the string before checking, defaultValue: `true`.
|
|
1199
|
-
*
|
|
1200
|
-
* @default true */
|
|
1201
|
-
trim?: boolean;
|
|
1202
|
-
};
|
|
1203
|
-
/** ----------------------------------------------------------
|
|
1204
|
-
* * ***Predicate: `isEmptyString`.***
|
|
1205
|
-
* ----------------------------------------------------------
|
|
1206
|
-
* **Checks whether a given value is an **empty-string**.**
|
|
1207
|
-
* - **Behavior:**
|
|
1208
|
-
* - Considers `""` and whitespace-only strings as
|
|
1209
|
-
* empty (if `trim` is enabled, which is the default).
|
|
1210
|
-
* - Non-string inputs are also considered empty.
|
|
1211
|
-
* @param {*} value - The value to check.
|
|
1212
|
-
* @param {IsEmptyStringOptions} [options] - Optional settings.
|
|
1213
|
-
* @param {IsEmptyStringOptions["trim"]} [options.trim=true] - Whether to trim the string before checking, defaultValue: `true`.
|
|
1214
|
-
* @returns {boolean} Returns `true` if the value is string not a string or value string is considered empty.
|
|
1215
|
-
* @example
|
|
1216
|
-
* isEmptyString("");
|
|
1217
|
-
* // ➔ true
|
|
1218
|
-
* isEmptyString(" ");
|
|
1219
|
-
* // ➔ true (default trims)
|
|
1220
|
-
* isEmptyString(" ", { trim: false });
|
|
1221
|
-
* // ➔ false
|
|
1222
|
-
* isEmptyString("hello");
|
|
1223
|
-
* // ➔ false
|
|
1224
|
-
* isEmptyString(undefined);
|
|
1225
|
-
* // ➔ true
|
|
1226
|
-
* isEmptyString(null);
|
|
1227
|
-
* // ➔ true
|
|
1228
|
-
* isEmptyString(123 as any);
|
|
1229
|
-
* // ➔ true
|
|
1230
|
-
*
|
|
1231
|
-
* // Used in validation
|
|
1232
|
-
* if (isEmptyString(form.name)) {
|
|
1233
|
-
* throw new Error("Name cannot be empty.");
|
|
1234
|
-
* }
|
|
1235
|
-
*/
|
|
1236
|
-
declare const isEmptyString: (value: unknown, options?: IsEmptyStringOptions) => boolean;
|
|
1237
|
-
|
|
1238
|
-
type IsEmptyValueOptions = {
|
|
1239
|
-
/** **Whether to check symbol properties when checking empty objects.**
|
|
1240
|
-
* - **DefaultValue:** `false`.
|
|
1241
|
-
*
|
|
1242
|
-
* @default false
|
|
1243
|
-
*/
|
|
1244
|
-
checkSymbols?: boolean;
|
|
1245
|
-
};
|
|
1246
|
-
/** ----------------------------------------------------------
|
|
1247
|
-
* * ***Predicate: `isEmptyValue`.***
|
|
1248
|
-
* ----------------------------------------------------------
|
|
1249
|
-
* **Determines if a value is **`empty`**.**
|
|
1250
|
-
* - **Covering:**
|
|
1251
|
-
* - Empty objects: `{}`
|
|
1252
|
-
* - Empty arrays: `[]`
|
|
1253
|
-
* - Empty strings: `""` or whitespace-only (trimmed)
|
|
1254
|
-
* - `null`, `undefined`, `false`, or `NaN`
|
|
1255
|
-
* - **Returns **`false`** for:**
|
|
1256
|
-
* - Non-empty objects/arrays
|
|
1257
|
-
* - Non-empty strings
|
|
1258
|
-
* - Numbers (except `NaN`)
|
|
1259
|
-
* - `Functions`, `true`, `symbols`, `etc`.
|
|
1260
|
-
* @param {*} value - The value to evaluate.
|
|
1261
|
-
* @param {IsEmptyValueOptions} [options] - Optional settings.
|
|
1262
|
-
* @returns {boolean} Return `true` if the value is considered empty, otherwise `false`.
|
|
1263
|
-
* @example
|
|
1264
|
-
* isEmptyValue({});
|
|
1265
|
-
* // ➔ true
|
|
1266
|
-
* isEmptyValue([]);
|
|
1267
|
-
* // ➔ true
|
|
1268
|
-
* isEmptyValue({ key: "value" });
|
|
1269
|
-
* // ➔ false
|
|
1270
|
-
* isEmptyValue({ [Symbol("foo")]: 123 });
|
|
1271
|
-
* // ➔ true (default `checkSymbols` is `false`)
|
|
1272
|
-
* isEmptyValue({ [Symbol("foo")]: 123 }, { checkSymbols: false });
|
|
1273
|
-
* // ➔ true (default `checkSymbols` is `false`)
|
|
1274
|
-
* isEmptyValue({ [Symbol("foo")]: 123 }, { checkSymbols: true });
|
|
1275
|
-
* // ➔ false
|
|
1276
|
-
* isEmptyValue([1, 2, 3]);
|
|
1277
|
-
* // ➔ false
|
|
1278
|
-
* isEmptyValue(NaN);
|
|
1279
|
-
* // ➔ true
|
|
1280
|
-
* isEmptyValue(true);
|
|
1281
|
-
* // ➔ false
|
|
1282
|
-
* isEmptyValue(false);
|
|
1283
|
-
* // ➔ true
|
|
1284
|
-
* isEmptyValue(null);
|
|
1285
|
-
* // ➔ true
|
|
1286
|
-
* isEmptyValue(undefined);
|
|
1287
|
-
* // ➔ true
|
|
1288
|
-
* isEmptyValue("");
|
|
1289
|
-
* // ➔ true
|
|
1290
|
-
* isEmptyValue(" ");
|
|
1291
|
-
* // ➔ true
|
|
1292
|
-
* isEmptyValue(0);
|
|
1293
|
-
* // ➔ false
|
|
1294
|
-
* isEmptyValue(-1);
|
|
1295
|
-
* // ➔ false
|
|
1296
|
-
* isEmptyValue(2);
|
|
1297
|
-
* // ➔ false
|
|
1298
|
-
* isEmptyValue(() => {});
|
|
1299
|
-
* // ➔ false
|
|
1300
|
-
*/
|
|
1301
|
-
declare const isEmptyValue: (value: unknown, options?: IsEmptyValueOptions) => boolean;
|
|
1302
|
-
|
|
1303
|
-
/** ----------------------------------------------------
|
|
1304
|
-
* * ***Predicate: `isEqual`.***
|
|
1305
|
-
* ----------------------------------------------------------
|
|
1306
|
-
* **Performs a deep comparison between two values to determine if they are equivalent.**
|
|
1307
|
-
* @description
|
|
1308
|
-
* Checks whether two values are **deeply equal**, not just reference-equal (`===`).
|
|
1309
|
-
* - **✅ This method compares:**
|
|
1310
|
-
* - Arrays and TypedArrays
|
|
1311
|
-
* - ArrayBuffers
|
|
1312
|
-
* - Plain objects (`Object`) ➔ own enumerable properties only
|
|
1313
|
-
* - Booleans, Numbers, Strings, Symbols
|
|
1314
|
-
* - Dates
|
|
1315
|
-
* - Errors
|
|
1316
|
-
* - Maps
|
|
1317
|
-
* - Sets
|
|
1318
|
-
* - Regular expressions
|
|
1319
|
-
* - ❌ `Functions` and `DOM nodes` are ***not supported***.
|
|
1320
|
-
* @param {*} value The value to compare.
|
|
1321
|
-
* @param {*} other The other value to compare.
|
|
1322
|
-
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
1323
|
-
* @example
|
|
1324
|
-
* const obj1 = { user: "fred" };
|
|
1325
|
-
* const obj2 = { user: "fred" };
|
|
1326
|
-
*
|
|
1327
|
-
* isEqual(obj1, obj2);
|
|
1328
|
-
* // ➔ true
|
|
1329
|
-
* obj1 === obj2;
|
|
1330
|
-
* // ➔ false (different references)
|
|
1331
|
-
* isEqual([1, 2, 3], [1, 2, 3]);
|
|
1332
|
-
* // ➔ true
|
|
1333
|
-
* isEqual(new Date("2020-01-01"), new Date("2020-01-01"));
|
|
1334
|
-
* // ➔ true
|
|
1335
|
-
* isEqual(new Set([1, 2]), new Set([2, 1]));
|
|
1336
|
-
* // ➔ true
|
|
1337
|
-
* isEqual(/abc/i, new RegExp("abc", "i"));
|
|
1338
|
-
* // ➔ true
|
|
1339
|
-
* isEqual({ a: 1 }, { a: 1, b: undefined });
|
|
1340
|
-
* // ➔ false
|
|
1341
|
-
*/
|
|
1342
|
-
declare function isEqual(value: unknown, other: unknown): boolean;
|
|
1343
|
-
|
|
1344
|
-
/** -------------------------------------------------------------------
|
|
1345
|
-
* * ***Customizer function for `isEqualWith`.***
|
|
1346
|
-
* -------------------------------------------------------------------
|
|
1347
|
-
* **Allows customizing how two values are compared for deep equality.**
|
|
1348
|
-
* @param value
|
|
1349
|
-
* - The current value being compared.
|
|
1350
|
-
* @param other
|
|
1351
|
-
* - The corresponding value from the other object.
|
|
1352
|
-
* @param indexOrKey
|
|
1353
|
-
* - The property key (for objects) or index (for arrays) of the current value.
|
|
1354
|
-
* @param parent
|
|
1355
|
-
* - The parent object or array containing `value`.
|
|
1356
|
-
* @param otherParent
|
|
1357
|
-
* - The parent object or array containing `other`.
|
|
1358
|
-
* @param stack
|
|
1359
|
-
* - WeakMap or tracking structure for already visited objects to handle circular references.
|
|
1360
|
-
* @returns
|
|
1361
|
-
* - `true` → Treat the values as equal.
|
|
1362
|
-
* - `false` → Treat the values as unequal.
|
|
1363
|
-
* - `undefined` → Fallback to default deep equality comparison.
|
|
1364
|
-
* @example
|
|
1365
|
-
* ```ts
|
|
1366
|
-
* const customizer: CustomizerIsEqualWith = (value, other, key) => {
|
|
1367
|
-
* if (typeof value === "string" && typeof other === "string") {
|
|
1368
|
-
* return value.toLowerCase() === other.toLowerCase();
|
|
1369
|
-
* }
|
|
1370
|
-
* return undefined;
|
|
1371
|
-
* };
|
|
1372
|
-
*
|
|
1373
|
-
* baseDeepEqual({ name: "Alice" }, { name: "alice" }, customizer);
|
|
1374
|
-
* // returns true
|
|
1375
|
-
* ```
|
|
1376
|
-
*/
|
|
1377
|
-
type CustomizerIsEqualWith = (
|
|
1378
|
-
/** * ***The current value being compared.*** */
|
|
1379
|
-
value: unknown,
|
|
1380
|
-
/** * ***The corresponding value from the other object.*** */
|
|
1381
|
-
other: unknown,
|
|
1382
|
-
/** * ***Property key (for objects) or index (for arrays) of the current value.*** */
|
|
1383
|
-
indexOrKey: PropertyKey,
|
|
1384
|
-
/** * ***Parent object or array containing `value`.*** */
|
|
1385
|
-
parent: unknown,
|
|
1386
|
-
/** * ***Parent object or array containing `other`.*** */
|
|
1387
|
-
otherParent: unknown,
|
|
1388
|
-
/** * ***WeakMap or tracking structure for visited objects to handle circular references.*** */
|
|
1389
|
-
stack: unknown) => boolean | undefined;
|
|
1390
|
-
|
|
1391
|
-
/** ----------------------------------------------------
|
|
1392
|
-
* * ***Predicate: `isEqualWith`.***
|
|
1393
|
-
* ----------------------------------------------------
|
|
1394
|
-
* **Performs a deep comparison between two values with support for a
|
|
1395
|
-
* customizer function.**
|
|
1396
|
-
* @description
|
|
1397
|
-
* This method is like ***`isEqual` utility function*** except that it
|
|
1398
|
-
* accepts a `customizer` which is invoked to compare values.
|
|
1399
|
-
* - **Behavior:**
|
|
1400
|
-
* - If `customizer` returns `undefined`, the comparison is handled by
|
|
1401
|
-
* the default deep equality algorithm.
|
|
1402
|
-
* - The `customizer` is invoked with up to six arguments:
|
|
1403
|
-
* - `(value, other, indexOrKey, parent, otherParent, stack)`,
|
|
1404
|
-
* see **{@link CustomizerIsEqualWith | `CustomizerIsEqualWith`}**.
|
|
1405
|
-
* - Supports comparing `arrays`, `objects`, `maps`, `sets`, `dates`,
|
|
1406
|
-
* `regexes`, `typed arrays`, `etc`.
|
|
1407
|
-
* - Functions and DOM nodes are **not** supported.
|
|
1408
|
-
* @param {*} value The value to compare.
|
|
1409
|
-
* @param {*} other The other value to compare.
|
|
1410
|
-
* @param {CustomizerIsEqualWith} [customizer] The function to customize comparisons.
|
|
1411
|
-
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
1412
|
-
* @example
|
|
1413
|
-
* function isGreeting(value: unknown) {
|
|
1414
|
-
* return typeof value === "string" && /^h(?:i|ello)$/.test(value);
|
|
1415
|
-
* }
|
|
1416
|
-
*
|
|
1417
|
-
* function customizer(objValue: unknown, othValue: unknown) {
|
|
1418
|
-
* if (isGreeting(objValue) && isGreeting(othValue)) {
|
|
1419
|
-
* return true;
|
|
1420
|
-
* }
|
|
1421
|
-
* }
|
|
1422
|
-
*
|
|
1423
|
-
* const array = ["hello", "goodbye"];
|
|
1424
|
-
* const other = ["hi", "goodbye"];
|
|
1425
|
-
*
|
|
1426
|
-
* isEqualWith(array, other, customizer);
|
|
1427
|
-
* // ➔ true
|
|
1428
|
-
*/
|
|
1429
|
-
declare function isEqualWith(value: unknown, other: unknown, customizer?: CustomizerIsEqualWith): boolean;
|
|
1430
|
-
|
|
1431
|
-
/** ----------------------------------------------------------
|
|
1432
|
-
* * ***Type guard: `isError`.***
|
|
1433
|
-
* ----------------------------------------------------------
|
|
1434
|
-
* **Checks whether the given value is an ****[`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** object**.**
|
|
1435
|
-
* - **Behavior:**
|
|
1436
|
-
* - Ensures that the provided value is a valid JavaScript error instance.
|
|
1437
|
-
* - Useful in TypeScript for narrowing types during error handling.
|
|
1438
|
-
* @param {*} error - The value to check.
|
|
1439
|
-
* @returns {boolean} Returns `true` if `value` is instance of **[`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)**, else `false`.
|
|
1440
|
-
* @example
|
|
1441
|
-
* isError(new Error("Something went wrong"));
|
|
1442
|
-
* // ➔ true
|
|
1443
|
-
* isError("Error message");
|
|
1444
|
-
* // ➔ false
|
|
1445
|
-
* isError(null);
|
|
1446
|
-
* // ➔ false
|
|
1447
|
-
*/
|
|
1448
|
-
declare const isError: (error: unknown) => error is Error;
|
|
1449
|
-
|
|
1450
|
-
/** ----------------------------------------------------------
|
|
1451
|
-
* * ***Type guard: `isFinite`.***
|
|
1452
|
-
* -----------------------------------------------------------
|
|
1453
|
-
* **Checks if a value is a finite primitive number.**
|
|
1454
|
-
* @description
|
|
1455
|
-
* This function verifies that `value` is a **primitive number** and is **finite**
|
|
1456
|
-
* (i.e., not `NaN`, `Infinity`, or `-Infinity`).
|
|
1457
|
-
* - **Behavior:**
|
|
1458
|
-
* - Behaves like
|
|
1459
|
-
* [`Number.isFinite()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite).
|
|
1460
|
-
* - But also works as a **TypeScript type guard**.
|
|
1461
|
-
* @param {*} value - The value to check.
|
|
1462
|
-
* @returns {boolean} Returns `true` if `value` is a finite primitive number, else `false`.
|
|
1463
|
-
* @example
|
|
1464
|
-
* import * as RzlUtilsJs from "@rzl-zone/utils-js/predicates";
|
|
1465
|
-
*
|
|
1466
|
-
* // Strict finite number check (only primitive numbers)
|
|
1467
|
-
* RzlUtilsJs.isFinite(3);
|
|
1468
|
-
* // ➔ true
|
|
1469
|
-
* RzlUtilsJs.isFinite(Number.MIN_VALUE);
|
|
1470
|
-
* // ➔ true
|
|
1471
|
-
* RzlUtilsJs.isFinite("3");
|
|
1472
|
-
* // ➔ false (string is not a number)
|
|
1473
|
-
* RzlUtilsJs.isFinite(NaN);
|
|
1474
|
-
* // ➔ false
|
|
1475
|
-
* RzlUtilsJs.isFinite(Infinity);
|
|
1476
|
-
* // ➔ false
|
|
1477
|
-
* RzlUtilsJs.isFinite(new Number(3));
|
|
1478
|
-
* // ➔ false (Number object is not primitive)
|
|
1479
|
-
*
|
|
1480
|
-
* // Comparison with global isFinite()
|
|
1481
|
-
* isFinite("3");
|
|
1482
|
-
* // ➔ true (global coerces string to number)
|
|
1483
|
-
* isFinite(new Number(3));
|
|
1484
|
-
* // ➔ true (object coerced to primitive number)
|
|
1485
|
-
*/
|
|
1486
|
-
declare function isFinite(value: unknown): value is number;
|
|
1487
|
-
|
|
1488
|
-
/** ----------------------------------------------------------
|
|
1489
|
-
* * ***Type guard: `isFunction`.***
|
|
1490
|
-
* -----------------------------------------------------------
|
|
1491
|
-
* **Checks if a value is a function.**
|
|
1492
|
-
* - **Behavior:**
|
|
1493
|
-
* - Uses `typeof value === "function"` for strict type checking.
|
|
1494
|
-
* - Safe alternative to `Function` type (doesn't trigger ESLint warning).
|
|
1495
|
-
* - Supports TypeScript type narrowing with `value is (...args: any[]) => any`.
|
|
1496
|
-
* @param {*} value - The value to check.
|
|
1497
|
-
* @returns {boolean} Return `true` if the value is a function.
|
|
1498
|
-
* @example
|
|
1499
|
-
* isFunction(() => {});
|
|
1500
|
-
* // ➔ true
|
|
1501
|
-
* isFunction(async () => {});
|
|
1502
|
-
* // ➔ true
|
|
1503
|
-
* isFunction(null);
|
|
1504
|
-
* // ➔ false
|
|
1505
|
-
* isFunction({});
|
|
1506
|
-
* // ➔ false
|
|
1507
|
-
*/
|
|
1508
|
-
declare const isFunction: (value: unknown) => value is AnyFunction;
|
|
1509
|
-
|
|
1510
|
-
/** ----------------------------------------------------
|
|
1511
|
-
* * ***Type guard: `isInfinityNumber`.***
|
|
1512
|
-
* ----------------------------------------------------
|
|
1513
|
-
* **Checks if a value is positive or negative
|
|
1514
|
-
* [`Infinity`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity).**
|
|
1515
|
-
* - **ℹ️ Note:**
|
|
1516
|
-
* - This is stricter than the global `isFinite`,
|
|
1517
|
-
* because it only returns `true` for `Infinity` or `-Infinity`,
|
|
1518
|
-
* not other non-finite values.
|
|
1519
|
-
* @param {*} value The value to check.
|
|
1520
|
-
* @returns {boolean} Returns `true` if `value` is `Infinity` or `-Infinity`, else `false`.
|
|
1521
|
-
* @example
|
|
1522
|
-
* import * as RzlUtilsJs from "@rzl-zone/utils-js/predicates";
|
|
1523
|
-
*
|
|
1524
|
-
* RzlUtilsJs.isInfinityNumber(Infinity);
|
|
1525
|
-
* // ➔ true
|
|
1526
|
-
* RzlUtilsJs.isInfinityNumber(-Infinity);
|
|
1527
|
-
* // ➔ true
|
|
1528
|
-
* RzlUtilsJs.isInfinityNumber(new Number(Infinity));
|
|
1529
|
-
* // ➔ true
|
|
1530
|
-
* RzlUtilsJs.isInfinityNumber(NaN);
|
|
1531
|
-
* // ➔ false
|
|
1532
|
-
* RzlUtilsJs.isInfinityNumber(123);
|
|
1533
|
-
* // ➔ false
|
|
1534
|
-
*/
|
|
1535
|
-
declare function isInfinityNumber(value: unknown): boolean;
|
|
1536
|
-
|
|
1537
|
-
/** ---------------------------------------------------------
|
|
1538
|
-
* * ***Type guard: `isInteger`.***
|
|
1539
|
-
* ----------------------------------------------------------
|
|
1540
|
-
* **Checks if a value is an integer number.**
|
|
1541
|
-
* - **ℹ️ Note:**
|
|
1542
|
-
* - This method is based on
|
|
1543
|
-
* [`Number.isInteger`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger).
|
|
1544
|
-
* @param {*} value The value to check.
|
|
1545
|
-
* @returns {boolean} Returns `true` if `value` is an integer, else `false`.
|
|
1546
|
-
* @example
|
|
1547
|
-
* isInteger(3);
|
|
1548
|
-
* // ➔ true
|
|
1549
|
-
* isInteger(Number.MIN_VALUE);
|
|
1550
|
-
* // ➔ false
|
|
1551
|
-
* isInteger(NaN);
|
|
1552
|
-
* // ➔ false
|
|
1553
|
-
* isInteger(Infinity);
|
|
1554
|
-
* // ➔ false
|
|
1555
|
-
* isInteger(-Infinity);
|
|
1556
|
-
* // ➔ false
|
|
1557
|
-
* isInteger('3');
|
|
1558
|
-
* // ➔ false
|
|
1559
|
-
*/
|
|
1560
|
-
declare function isInteger(value: unknown): value is number;
|
|
1561
|
-
|
|
1562
|
-
/** ----------------------------------------
|
|
1563
|
-
* * ***Predicate: `isLength`.***
|
|
1564
|
-
* ----------------------------------------------------------
|
|
1565
|
-
* **Checks whether the given value is a **valid array-like length**.**
|
|
1566
|
-
* - **Behavior:**
|
|
1567
|
-
* - ✅ Ensures the value is a **non-negative integer**.
|
|
1568
|
-
* - ✅ Ensures the value is **not greater than `Number.MAX_SAFE_INTEGER`**.
|
|
1569
|
-
* - ❌ Excludes non-numeric values, `Infinity`, and fractional numbers.
|
|
1570
|
-
* - **ℹ️ Note:**
|
|
1571
|
-
* - This method is loosely based-on
|
|
1572
|
-
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
|
1573
|
-
* - A valid length must be a non-negative integer and **not greater
|
|
1574
|
-
* than `Number.MAX_SAFE_INTEGER`**.
|
|
1575
|
-
* @param {*} value The value to check.
|
|
1576
|
-
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
1577
|
-
* @example
|
|
1578
|
-
* isLength(3);
|
|
1579
|
-
* // ➔ true
|
|
1580
|
-
* isLength(Number.MAX_SAFE_INTEGER);
|
|
1581
|
-
* // ➔ true
|
|
1582
|
-
* isLength(Number.MAX_SAFE_INTEGER + 1);
|
|
1583
|
-
* // ➔ false
|
|
1584
|
-
* isLength("3");
|
|
1585
|
-
* // ➔ false
|
|
1586
|
-
* isLength(-1);
|
|
1587
|
-
* // ➔ false
|
|
1588
|
-
* isLength(3.14);
|
|
1589
|
-
* // ➔ false
|
|
1590
|
-
* isLength(Infinity);
|
|
1591
|
-
* // ➔ false
|
|
1592
|
-
* isLength(-Infinity);
|
|
1593
|
-
* // ➔ false
|
|
1594
|
-
* isLength(Number.MIN_VALUE);
|
|
1595
|
-
* // ➔ false
|
|
1596
|
-
*/
|
|
1597
|
-
declare function isLength(value: unknown): boolean;
|
|
1598
|
-
|
|
1599
|
-
/** --------------------------------------------------
|
|
1600
|
-
* * ***Type guard: `isMap`.***
|
|
1601
|
-
* ----------------------------------------------------------
|
|
1602
|
-
* **Checks whether the given value is a **[`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) object**.**
|
|
1603
|
-
* - **Behavior:**
|
|
1604
|
-
* - Ensures that the provided value is an instance of **[`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)**.
|
|
1605
|
-
* - Useful in TypeScript for narrowing types when working with collections.
|
|
1606
|
-
* @param {*} value The value to check.
|
|
1607
|
-
* @returns {boolean} Returns `true` if `value` is instance of **[`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)**, else `false`.
|
|
1608
|
-
* @example
|
|
1609
|
-
* isMap(new Map());
|
|
1610
|
-
* // ➔ true
|
|
1611
|
-
* isMap(new WeakMap());
|
|
1612
|
-
* // ➔ false
|
|
1613
|
-
* isMap({});
|
|
1614
|
-
* // ➔ false
|
|
1615
|
-
*/
|
|
1616
|
-
declare function isMap<K = unknown, V = unknown>(value: Map<K, V>): value is Map<K, V>;
|
|
1617
|
-
declare function isMap(value: unknown): value is Map<unknown, unknown>;
|
|
1618
|
-
|
|
1619
|
-
/** ----------------------------------------------------
|
|
1620
|
-
* * ***Predicate: `isMatch`.***
|
|
1621
|
-
* ----------------------------------------------------
|
|
1622
|
-
* **Performs a partial deep comparison between `object` and `source`.**
|
|
1623
|
-
* @description
|
|
1624
|
-
* Determines whether `object` contains equivalent property values from `source`.
|
|
1625
|
-
* - **Behavior:**
|
|
1626
|
-
* - ✅ Returns `true` if **all properties** in `source` exist in `object` and are deeply equal.
|
|
1627
|
-
* - ❌ Does **not** require `object` and `source` to be the same shape—`object` may have extra properties.
|
|
1628
|
-
* - ⚠️ Arrays are treated as objects: only matching indexed keys are compared.
|
|
1629
|
-
* - **Remarks:**
|
|
1630
|
-
* - This is functionally equivalent to a partially applied `matches(source)` predicate.
|
|
1631
|
-
* - Special cases:
|
|
1632
|
-
* - An empty array (`[]`) in `source` matches any array in `object`.
|
|
1633
|
-
* - An empty object (`{}`) in `source` matches any object in `object`.
|
|
1634
|
-
* @param {object} object - The object to inspect.
|
|
1635
|
-
* @param {object} source - The object containing property values to match.
|
|
1636
|
-
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
|
1637
|
-
* @example
|
|
1638
|
-
* const object = { a: 1, b: 2 };
|
|
1639
|
-
*
|
|
1640
|
-
* isMatch(object, { b: 2 });
|
|
1641
|
-
* // ➔ true
|
|
1642
|
-
* isMatch(object, { b: 1 });
|
|
1643
|
-
* // ➔ false
|
|
1644
|
-
* isMatch([1, 2, 3], [1, 2]);
|
|
1645
|
-
* // ➔ true (treats arrays as objects with index keys)
|
|
1646
|
-
*/
|
|
1647
|
-
declare function isMatch(object: object, source: object): boolean;
|
|
1648
|
-
|
|
1649
|
-
/** -------------------------------------------------------------------
|
|
1650
|
-
* * ***Customizer function for `isMatchWith`.***
|
|
1651
|
-
* -------------------------------------------------------------------
|
|
1652
|
-
* **Allows customizing how two values are compared for partial/object match.**
|
|
1653
|
-
* @param value
|
|
1654
|
-
* - The current value from the object being tested.
|
|
1655
|
-
* @param other
|
|
1656
|
-
* - The corresponding value from the source object.
|
|
1657
|
-
* @param indexOrKey
|
|
1658
|
-
* - The property key (for objects) or index (for arrays) of the current value.
|
|
1659
|
-
* @param object
|
|
1660
|
-
* - The parent object containing `value`.
|
|
1661
|
-
* @param source
|
|
1662
|
-
* - The parent source object containing `other`.
|
|
1663
|
-
* @returns
|
|
1664
|
-
* - `true` → Treat the values as matching.
|
|
1665
|
-
* - `false` → Treat the values as not matching.
|
|
1666
|
-
* - `undefined` → Fallback to default match comparison.
|
|
1667
|
-
* @example
|
|
1668
|
-
* ```ts
|
|
1669
|
-
* const customizer: CustomizerIsMatchWith = (value, other) => {
|
|
1670
|
-
* if (typeof value === "string" && typeof other === "string") {
|
|
1671
|
-
* return value.toLowerCase() === other.toLowerCase();
|
|
1672
|
-
* }
|
|
1673
|
-
* return undefined;
|
|
1674
|
-
* };
|
|
1675
|
-
*
|
|
1676
|
-
* baseIsMatch({ name: "Alice" }, { name: "alice" }, customizer);
|
|
1677
|
-
* // returns true
|
|
1678
|
-
* ```
|
|
1679
|
-
*/
|
|
1680
|
-
type CustomizerIsMatchWith = (
|
|
1681
|
-
/** * ***Current value from the object being tested.*** */
|
|
1682
|
-
value: unknown,
|
|
1683
|
-
/** * ***Corresponding value from the source object.*** */
|
|
1684
|
-
other: unknown,
|
|
1685
|
-
/** * ***Property key (objects) or index (arrays) of the current value.*** */
|
|
1686
|
-
indexOrKey: PropertyKey,
|
|
1687
|
-
/** * ***Parent object containing `value`.*** */
|
|
1688
|
-
object: object,
|
|
1689
|
-
/** * ***Parent source object containing `other`.*** */
|
|
1690
|
-
source: object) => boolean | undefined;
|
|
1691
|
-
|
|
1692
|
-
/** ----------------------------------------------------
|
|
1693
|
-
* * ***Predicate: `isMatchWith`.***
|
|
1694
|
-
* ----------------------------------------------------
|
|
1695
|
-
* **Performs a partial deep comparison between `object` and `source`, like `isMatch`, but with a `customizer` function to control comparisons.**
|
|
1696
|
-
* @description
|
|
1697
|
-
* If `customizer` returns a value other than `undefined`, that value is used
|
|
1698
|
-
* as the result of the comparison for the current property. Otherwise,
|
|
1699
|
-
* the comparison falls back to the default deep equality logic.
|
|
1700
|
-
* - **Behavior:**
|
|
1701
|
-
* - The `customizer` function is invoked with up to **five** arguments:
|
|
1702
|
-
* - `(objValue, srcValue, keyOrIndex, object, source)`,
|
|
1703
|
-
* see **{@link CustomizerIsMatchWith | `CustomizerIsMatchWith`}**.
|
|
1704
|
-
* - Returning `true` from `customizer` will short-circuit further comparison
|
|
1705
|
-
* for that key.
|
|
1706
|
-
* - Returning `false` will cause `isMatchWith` to return `false` immediately.
|
|
1707
|
-
* - Returning `undefined` allows default comparison to proceed.
|
|
1708
|
-
* @param {object} value - The object to inspect.
|
|
1709
|
-
* @param {object} other - The object of property values to match.
|
|
1710
|
-
* @param {CustomizerIsMatchWith} [customizer] - The function to customize comparisons.
|
|
1711
|
-
* @returns Returns `true` if `object` is a match, else `false`.
|
|
1712
|
-
* @example
|
|
1713
|
-
* function isGreeting(value: unknown) {
|
|
1714
|
-
* return typeof value === 'string' && /^h(?:i|ello)$/.test(value);
|
|
1715
|
-
* }
|
|
1716
|
-
*
|
|
1717
|
-
* function customizer(objValue: unknown, srcValue: unknown) {
|
|
1718
|
-
* if (isGreeting(objValue) && isGreeting(srcValue)) {
|
|
1719
|
-
* return true;
|
|
1720
|
-
* }
|
|
1721
|
-
* }
|
|
1722
|
-
*
|
|
1723
|
-
* const object = { greeting: 'hello' };
|
|
1724
|
-
* const source = { greeting: 'hi' };
|
|
1725
|
-
*
|
|
1726
|
-
* isMatchWith(object, source, customizer);
|
|
1727
|
-
* // ➔ true
|
|
1728
|
-
*/
|
|
1729
|
-
declare function isMatchWith(value: object, other: object, customizer?: CustomizerIsMatchWith): boolean;
|
|
1730
|
-
|
|
1731
|
-
/** ----------------------------------------------------
|
|
1732
|
-
* * ***Type guard: `isNaN`.***
|
|
1733
|
-
* ----------------------------------------------------
|
|
1734
|
-
* **Checks if a value is [`NaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN).**
|
|
1735
|
-
* - **ℹ️ Note:**
|
|
1736
|
-
* - This method is based on
|
|
1737
|
-
* [`Number.isNaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
|
|
1738
|
-
* and is **not** the same as the global
|
|
1739
|
-
* [`isNaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN),
|
|
1740
|
-
* which returns `true` for `undefined` and other non-number values.
|
|
1741
|
-
* @param {*} value The value to check.
|
|
1742
|
-
* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
|
|
1743
|
-
* @example
|
|
1744
|
-
* import * as RzlUtilsJs from "@rzl-zone/utils-js/predicates";
|
|
1745
|
-
*
|
|
1746
|
-
* RzlUtilsJs.isNaN(NaN);
|
|
1747
|
-
* // ➔ true
|
|
1748
|
-
* RzlUtilsJs.isNaN(new Number(NaN));
|
|
1749
|
-
* // ➔ true
|
|
1750
|
-
* RzlUtilsJs.isNaN(undefined);
|
|
1751
|
-
* // ➔ false
|
|
1752
|
-
*
|
|
1753
|
-
* // This global isNaN:
|
|
1754
|
-
* isNaN(undefined);
|
|
1755
|
-
* // ➔ true
|
|
1756
|
-
*/
|
|
1757
|
-
declare function isNaN(value: unknown): boolean;
|
|
1758
|
-
|
|
1759
|
-
/** ----------------------------------------------------
|
|
1760
|
-
* * ***Type guard: `isNative`.***
|
|
1761
|
-
* ----------------------------------------------------------
|
|
1762
|
-
* **Checks if a value is a **pristine native function**.**
|
|
1763
|
-
* - **ℹ️ Note:**
|
|
1764
|
-
* - This method may not reliably detect native functions when using packages
|
|
1765
|
-
* like `core-js`, as they override native behavior.
|
|
1766
|
-
* - Attempts to detect native functions in such environments may fail or
|
|
1767
|
-
* throw errors.
|
|
1768
|
-
* - This also affects packages like
|
|
1769
|
-
* **[`babel-polyfill`](https://www.npmjs.com/package/babel-polyfill).**
|
|
1770
|
-
* @param {*} value The value to check.
|
|
1771
|
-
* @returns {boolean} Returns `true` if `value` is a native function, else `false`.
|
|
1772
|
-
* @example
|
|
1773
|
-
* isNative(Array.prototype.push);
|
|
1774
|
-
* // ➔ true
|
|
1775
|
-
*
|
|
1776
|
-
* import * as RzlUtilsJs from "@rzl-zone/utils-js/predicates";
|
|
1777
|
-
* isNative(RzlUtilsJs);
|
|
1778
|
-
* // ➔ false
|
|
1779
|
-
*/
|
|
1780
|
-
declare function isNative(value: unknown): value is AnyFunction;
|
|
1781
|
-
|
|
1782
|
-
/** ----------------------------------------------------
|
|
1783
|
-
* * ***Type guard: `isNil`.***
|
|
1784
|
-
* ----------------------------------------------------------
|
|
1785
|
-
* **Checks if a value is **[`null`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/null)** or **[`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**.**
|
|
1786
|
-
* - **Behavior:**
|
|
1787
|
-
* - Narrows type to `null` or `undefined` when true.
|
|
1788
|
-
* @param {*} value - The value to check.
|
|
1789
|
-
* @returns {boolean} Returns `true` if the value is `null` or `undefined`, otherwise `false`.
|
|
1790
|
-
* @example
|
|
1791
|
-
* isNil(null);
|
|
1792
|
-
* // ➔ true
|
|
1793
|
-
* isNil(undefined);
|
|
1794
|
-
* // ➔ true
|
|
1795
|
-
* isNil(void 0);
|
|
1796
|
-
* // ➔ true
|
|
1797
|
-
* isNil(NaN);
|
|
1798
|
-
* // ➔ false
|
|
1799
|
-
*/
|
|
1800
|
-
declare function isNil(value: unknown): value is null | undefined;
|
|
1801
|
-
|
|
1802
|
-
/** ----------------------------------------------------------
|
|
1803
|
-
* * ***Type guard: `isNonEmptyArray`.***
|
|
1804
|
-
* ----------------------------------------------------------
|
|
1805
|
-
* **Checks if a value is a **non-empty array**.**
|
|
1806
|
-
* - **Behavior:**
|
|
1807
|
-
* - Ensures the value is an actual array using **[`Array.isArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)**.
|
|
1808
|
-
* - Ensures the array contains at least one item.
|
|
1809
|
-
* - Narrows type to `T[]` (non-empty array) when true.
|
|
1810
|
-
* @template T - The type of the value being checked.
|
|
1811
|
-
* @param {*} value - The value to check.
|
|
1812
|
-
* @returns {boolean} Return `true` if value is a non-empty array.
|
|
1813
|
-
* @example
|
|
1814
|
-
* isNonEmptyArray([1, 2, 3]); // ➔ true
|
|
1815
|
-
* isNonEmptyArray([]); // ➔ false
|
|
1816
|
-
* isNonEmptyArray(null); // ➔ false
|
|
1817
|
-
* isNonEmptyArray("test"); // ➔ false
|
|
1818
|
-
*/
|
|
1819
|
-
declare function isNonEmptyArray(value: []): value is [];
|
|
1820
|
-
declare function isNonEmptyArray<T>(value: T): value is ArrayFallback<T>;
|
|
1821
|
-
declare function isNonEmptyArray(value: unknown): value is unknown[];
|
|
1822
|
-
|
|
1823
|
-
type IsNonEmptyStringOptions = {
|
|
1824
|
-
/** Whether to trim the string before checking, defaultValue: `true`.
|
|
1825
|
-
*
|
|
1826
|
-
* @default true */
|
|
1827
|
-
trim?: boolean;
|
|
1828
|
-
};
|
|
1829
|
-
/** ----------------------------------------------------------
|
|
1830
|
-
* * ***Type guard: `isNonEmptyString`.***
|
|
1831
|
-
* ----------------------------------------------------------
|
|
1832
|
-
* **Checks if a value is a **non-empty string**.**
|
|
1833
|
-
* @description
|
|
1834
|
-
* Determines whether the given `value` is a string containing at least one non-whitespace character, with optional trimming behavior.
|
|
1835
|
-
* - **Behavior:**
|
|
1836
|
-
* - Ensures the value is a string using ***`isString` utility function***.
|
|
1837
|
-
* - Optionally trims whitespace before checking (`trim` defaults to `true`).
|
|
1838
|
-
* - Narrows type to `string` when true.
|
|
1839
|
-
* @param {*} value - The value to test.
|
|
1840
|
-
* @param {IsNonEmptyStringOptions} [options] - Optional settings.
|
|
1841
|
-
* @param {boolean} options.trim - If `true`, trims the string before checking, defaults: `true`.
|
|
1842
|
-
* @returns {boolean} Return `true` if `value` is a non-empty string, otherwise `false`.
|
|
1843
|
-
* @example
|
|
1844
|
-
* isNonEmptyString("hello");
|
|
1845
|
-
* // ➔ true
|
|
1846
|
-
* isNonEmptyString(" ", { trim: true });
|
|
1847
|
-
* // ➔ false
|
|
1848
|
-
* isNonEmptyString(" ", { trim: false });
|
|
1849
|
-
* // ➔ true
|
|
1850
|
-
* isNonEmptyString("");
|
|
1851
|
-
* // ➔ false
|
|
1852
|
-
* isNonEmptyString(123);
|
|
1853
|
-
* // ➔ false
|
|
1854
|
-
* isNonEmptyString(undefined);
|
|
1855
|
-
* // ➔ false
|
|
1856
|
-
* isNonEmptyString(null);
|
|
1857
|
-
* // ➔ false
|
|
1858
|
-
* isNonEmptyString({});
|
|
1859
|
-
* // ➔ false
|
|
1860
|
-
* isNonEmptyString([]);
|
|
1861
|
-
* // ➔ false
|
|
1862
|
-
*/
|
|
1863
|
-
declare const isNonEmptyString: (value: unknown, options?: IsNonEmptyStringOptions) => value is string;
|
|
1864
|
-
|
|
1865
|
-
type IsNonEmptyValueOptions = {
|
|
1866
|
-
/** Whether to check symbol properties when checking empty objects, default: `false`.
|
|
1867
|
-
*
|
|
1868
|
-
* @default false
|
|
1869
|
-
*/
|
|
1870
|
-
checkSymbols?: boolean;
|
|
1871
|
-
};
|
|
1872
|
-
/** ----------------------------------------------------------
|
|
1873
|
-
* * ***Predicated: `isNonEmptyValue`.***
|
|
1874
|
-
* ----------------------------------------------------------
|
|
1875
|
-
* **Determines if a value is a **non-empty** object (`{}` with props), **non-empty** array (`[]` with items) or generally truthy.**
|
|
1876
|
-
* - **Behavior:**
|
|
1877
|
-
* - Returns `true` for:
|
|
1878
|
-
* - Objects **with properties**
|
|
1879
|
-
* - Arrays **with items**
|
|
1880
|
-
* - Non-empty, non-whitespace strings
|
|
1881
|
-
* - Numbers (except `NaN`, includes `0`)
|
|
1882
|
-
* - Functions
|
|
1883
|
-
* - `true`
|
|
1884
|
-
* - Returns `false` for:
|
|
1885
|
-
* - Empty objects (`{}`)
|
|
1886
|
-
* - Empty arrays (`[]`)
|
|
1887
|
-
* - `null` or `undefined`
|
|
1888
|
-
* - Empty strings (`""`) or whitespace-only strings (`" "`)
|
|
1889
|
-
* - `false`
|
|
1890
|
-
* - `NaN`
|
|
1891
|
-
* - Safely handles `null`, `undefined`, and non-object types without throwing.
|
|
1892
|
-
* @param {*} value - The value to evaluate.
|
|
1893
|
-
* @param {IsNonEmptyValueOptions} [options] - Optional settings.
|
|
1894
|
-
* @returns {boolean} Return `true` if the value is considered non-empty/truthy, otherwise `false`.
|
|
1895
|
-
* @example
|
|
1896
|
-
* isNonEmptyValue({});
|
|
1897
|
-
* // ➔ false
|
|
1898
|
-
* isNonEmptyValue([]);
|
|
1899
|
-
* // ➔ false
|
|
1900
|
-
* isNonEmptyValue({ key: "value" });
|
|
1901
|
-
* // ➔ true
|
|
1902
|
-
* isNonEmptyValue({ [Symbol("foo")]: 123 });
|
|
1903
|
-
* // ➔ false (default `checkSymbols` is `false`)
|
|
1904
|
-
* isNonEmptyValue({ [Symbol("foo")]: 123 }, { checkSymbols: false });
|
|
1905
|
-
* // ➔ false (default `checkSymbols` is `false`)
|
|
1906
|
-
* isNonEmptyValue({ [Symbol("foo")]: 123 }, { checkSymbols: true });
|
|
1907
|
-
* // ➔ true
|
|
1908
|
-
* isNonEmptyValue([1, 2, 3]);
|
|
1909
|
-
* // ➔ true
|
|
1910
|
-
* isNonEmptyValue(NaN);
|
|
1911
|
-
* // ➔ false
|
|
1912
|
-
* isNonEmptyValue(true);
|
|
1913
|
-
* // ➔ true
|
|
1914
|
-
* isNonEmptyValue(false);
|
|
1915
|
-
* // ➔ false
|
|
1916
|
-
* isNonEmptyValue(null);
|
|
1917
|
-
* // ➔ false
|
|
1918
|
-
* isNonEmptyValue(undefined);
|
|
1919
|
-
* // ➔ false
|
|
1920
|
-
* isNonEmptyValue("");
|
|
1921
|
-
* // ➔ false
|
|
1922
|
-
* isNonEmptyValue(" ");
|
|
1923
|
-
* // ➔ false
|
|
1924
|
-
* isNonEmptyValue(0);
|
|
1925
|
-
* // ➔ true
|
|
1926
|
-
* isNonEmptyValue(-1);
|
|
1927
|
-
* // ➔ true
|
|
1928
|
-
* isNonEmptyValue(2);
|
|
1929
|
-
* // ➔ true
|
|
1930
|
-
* isNonEmptyValue(() => {});
|
|
1931
|
-
* // ➔ true
|
|
1932
|
-
*/
|
|
1933
|
-
declare const isNonEmptyValue: (value: unknown, options?: IsNonEmptyValueOptions) => boolean;
|
|
1934
|
-
|
|
1935
|
-
/** ---------------------------------------------------------
|
|
1936
|
-
* * ***Type guard: `isNull`.***
|
|
1937
|
-
* ----------------------------------------------------------
|
|
1938
|
-
* **Checks if a value is **[`null`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/null)**.**
|
|
1939
|
-
* - **Behavior:**
|
|
1940
|
-
* - Narrows type to `null` when true.
|
|
1941
|
-
* - Strictly compares the value against `null`.
|
|
1942
|
-
* @param {*} val - The value to check.
|
|
1943
|
-
* @returns {boolean} Returns `true` if the value is `null`, otherwise `false`.
|
|
1944
|
-
* @example
|
|
1945
|
-
* isNull(null); // ➔ true
|
|
1946
|
-
* isNull(0); // ➔ false
|
|
1947
|
-
* isNull(undefined); // ➔ false
|
|
1948
|
-
*/
|
|
1949
|
-
declare const isNull: (val: unknown) => val is null;
|
|
1950
|
-
|
|
1951
|
-
/** ----------------------------------------------------
|
|
1952
|
-
* * ***Type guard: `isNumberObject`.***
|
|
1953
|
-
* ----------------------------------------------------
|
|
1954
|
-
* **Checks if a value is a **`Number` object wrapper**
|
|
1955
|
-
* (`new Number(...)`), not a primitive number.**
|
|
1956
|
-
* @param {*} value The value to check.
|
|
1957
|
-
* @returns {boolean} Returns `true` if `value` is a `Number` object.
|
|
1958
|
-
* @example
|
|
1959
|
-
* isNumberObject(new Number(42));
|
|
1960
|
-
* // ➔ true
|
|
1961
|
-
* isNumberObject(42);
|
|
1962
|
-
* // ➔ false
|
|
1963
|
-
*/
|
|
1964
|
-
declare function isNumberObject(value: unknown): value is Number;
|
|
1965
|
-
|
|
1966
|
-
type IsObject<T> = unknown extends T ? T & Record<PropertyKey, unknown> : T extends object ? T extends AnObjectNonArray ? T : IsHasKeysObject<T> extends false ? T & Record<PropertyKey, unknown> : IsArray<T> extends true ? Exclude<T, unknown[]> : T : never;
|
|
1967
|
-
/** ---------------------------------------------------------
|
|
1968
|
-
* * ***Type guard: `isObject`.***
|
|
1969
|
-
* ----------------------------------------------------------
|
|
1970
|
-
* **Checks if a value is an **object** (excluding `null` and `arrays`).**
|
|
1971
|
-
* - **✅ Returns `true` for any non-null object (arrays excluded), including:**
|
|
1972
|
-
* - Plain-objects (`{}`, `Object.create(null)`)
|
|
1973
|
-
* - Custom class instances
|
|
1974
|
-
* - Built-ins: `Date`, `RegExp`, `Error`, `URL`, `URLSearchParams`
|
|
1975
|
-
* - Collections: `Map`, `Set`, `WeakMap`, `WeakSet`
|
|
1976
|
-
* - Binary/typed data: `ArrayBuffer`, `DataView`, typed arrays (`Uint8Array`, `Int32Array`, etc.)
|
|
1977
|
-
* - DOM/Node objects: `HTMLElement`, `DocumentFragment`, etc.
|
|
1978
|
-
* - Proxies (wrapping any object type)
|
|
1979
|
-
* - **❌ Returns `false` for:**
|
|
1980
|
-
* - `null`
|
|
1981
|
-
* - Arrays (`[]`, `new Array()`)
|
|
1982
|
-
* - Functions (regular functions, arrow functions, class constructors)
|
|
1983
|
-
* - Primitives: `string`, `number`, `boolean`, `symbol`, `bigint`
|
|
1984
|
-
* - Boxed primitives: `new String()`, `new Number()`, `new Boolean()`
|
|
1985
|
-
* - `undefined` (including `NaN`, which is a primitive number)
|
|
1986
|
-
* - **ℹ️ Note:**
|
|
1987
|
-
* - If you specifically need to check for ***plain-objects*** only, use ***`isPlainObject` utility function*** instead.
|
|
1988
|
-
* - If you specifically need to check for ***object***, ***plain-objects***, and include ***array***, use ***`isObjectOrArray` utility function*** instead.
|
|
1989
|
-
* @template T - The type of the value being checked.
|
|
1990
|
-
* @param {*} value - The value to check.
|
|
1991
|
-
* @returns {boolean} Returns `true` if the value is a ***plain-objects***, otherwise `false`.
|
|
1992
|
-
* @example
|
|
1993
|
-
* isObject({}); // ➔ true
|
|
1994
|
-
* isObject(Object.create(null)); // ➔ true
|
|
1995
|
-
* isObject(new Date()); // ➔ true
|
|
1996
|
-
* isObject(new Map()); // ➔ true
|
|
1997
|
-
* isObject(new Uint8Array()); // ➔ true
|
|
1998
|
-
* isObject(new String("x")); // ➔ true
|
|
1999
|
-
* isObject([]); // ➔ false
|
|
2000
|
-
* isObject(null); // ➔ false
|
|
2001
|
-
* isObject(undefined); // ➔ false
|
|
2002
|
-
* isObject(123); // ➔ false
|
|
2003
|
-
* isObject(() => {}); // ➔ false
|
|
2004
|
-
*/
|
|
2005
|
-
declare function isObject<T extends object>(value: T): value is IsObject<T>;
|
|
2006
|
-
declare function isObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
2007
|
-
|
|
2008
|
-
/** ----------------------------------------------------------
|
|
2009
|
-
* * ***Type guard: `isObjectLoose`.***
|
|
2010
|
-
* ----------------------------------------------------------
|
|
2011
|
-
* **Checks if a value is the
|
|
2012
|
-
* [ECMAScript language type ***Object***](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types).**
|
|
2013
|
-
* - **✅ Returns `true` for:**
|
|
2014
|
-
* - Plain objects (`{}`)
|
|
2015
|
-
* - Arrays (`[]`)
|
|
2016
|
-
* - Functions
|
|
2017
|
-
* - Regexes (`/abc/`)
|
|
2018
|
-
* - Boxed primitives:
|
|
2019
|
-
* - `new Number(0)`
|
|
2020
|
-
* - `new String("")`
|
|
2021
|
-
* - `new Boolean(false)`
|
|
2022
|
-
* - **❌ Returns `false` for:**
|
|
2023
|
-
* - `null`
|
|
2024
|
-
* - `undefined`
|
|
2025
|
-
* - Primitives:
|
|
2026
|
-
* - `string`
|
|
2027
|
-
* - `number`
|
|
2028
|
-
* - `boolean`
|
|
2029
|
-
* - `symbol`
|
|
2030
|
-
* - `bigint`
|
|
2031
|
-
* - **ℹ️ Note:**
|
|
2032
|
-
* - **For More Strict Object Use ***`isObject`*** or ***`isPlainObject` utility function*** instead.**
|
|
2033
|
-
* @template T - The type of the value being checked.
|
|
2034
|
-
* @param {*} value The value to check.
|
|
2035
|
-
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
2036
|
-
* @example
|
|
2037
|
-
* isObjectLoose({});
|
|
2038
|
-
* // ➔ true
|
|
2039
|
-
* isObjectLoose([1, 2, 3]);
|
|
2040
|
-
* // ➔ true
|
|
2041
|
-
* isObjectLoose(()=> {});
|
|
2042
|
-
* // ➔ true
|
|
2043
|
-
* isObjectLoose(null);
|
|
2044
|
-
* // ➔ false
|
|
2045
|
-
* isObjectLoose(undefined);
|
|
2046
|
-
* // ➔ false
|
|
2047
|
-
*/
|
|
2048
|
-
declare function isObjectLoose<T = object>(value: unknown): value is T;
|
|
2049
|
-
|
|
2050
|
-
type IsObjectOrArray<T> = OrArr<[
|
|
2051
|
-
IsNever<T>,
|
|
2052
|
-
Extends<T, Record<PropertyKey, unknown>>,
|
|
2053
|
-
Extends<unknown, T>
|
|
2054
|
-
]> extends true ? T & Record<PropertyKey, unknown> & unknown[] : T extends object ? T extends unknown[] ? T : T extends AnObjectNonArray ? T : IsHasKeysObject<T> extends false ? T & Record<PropertyKey, unknown> : T : Extract<T, Record<PropertyKey, unknown> & unknown[]>;
|
|
2055
|
-
/** ---------------------------------------------------------
|
|
2056
|
-
* * ***Type guard: `isObjectOrArray`.***
|
|
2057
|
-
* ----------------------------------------------------------
|
|
2058
|
-
* **Checks if a value is an **object** or an **array**.**
|
|
2059
|
-
* - **✅ Returns `true` for:**
|
|
2060
|
-
* - Plain objects (`{}`, `Object.create(null)`)
|
|
2061
|
-
* - Custom objects
|
|
2062
|
-
* - Arrays (`[]`, `[1,2,3]`)
|
|
2063
|
-
* - **❌ Returns `false` for:**
|
|
2064
|
-
* - `null`
|
|
2065
|
-
* - `undefined`
|
|
2066
|
-
* - Primitives:
|
|
2067
|
-
* - `string`
|
|
2068
|
-
* - `number`
|
|
2069
|
-
* - `boolean`
|
|
2070
|
-
* - `symbol`
|
|
2071
|
-
* - `bigint`
|
|
2072
|
-
* - Functions
|
|
2073
|
-
* @template T - The type of the value being checked.
|
|
2074
|
-
* @param {*} value - The value to check.
|
|
2075
|
-
* @returns {boolean} Returns `true` if the value is an `object` or `array`.
|
|
2076
|
-
* @example
|
|
2077
|
-
* isObjectOrArray([1,2,3]); // ➔ true
|
|
2078
|
-
* isObjectOrArray({ name: "Alice" }); // ➔ true
|
|
2079
|
-
* isObjectOrArray(null); // ➔ false
|
|
2080
|
-
* isObjectOrArray(undefined); // ➔ false
|
|
2081
|
-
* isObjectOrArray("hello"); // ➔ false
|
|
2082
|
-
*/
|
|
2083
|
-
declare function isObjectOrArray(value: []): value is [];
|
|
2084
|
-
declare function isObjectOrArray<T>(value: T): value is IsObjectOrArray<T>;
|
|
2085
|
-
|
|
2086
|
-
/** ----------------------------------------------------------
|
|
2087
|
-
* * ***Type guard: `PropertyKey`.***
|
|
2088
|
-
* ----------------------------------------------------------
|
|
2089
|
-
* **Checks if a value is a valid `PropertyKey`.**
|
|
2090
|
-
* - **In JavaScript/TypeScript, a **`PropertyKey`** is any of:**
|
|
2091
|
-
* - **`string`**
|
|
2092
|
-
* - **`number`**
|
|
2093
|
-
* - **`symbol`**
|
|
2094
|
-
* - **This function ensures the given `value` is one of these types.**
|
|
2095
|
-
* - Narrows type to {@link PropertyKey | ***`PropertyKey`***} when true.
|
|
2096
|
-
* - Useful for working with dynamic object keys.
|
|
2097
|
-
* - Strictly rejects `null`, `undefined`, `boolean`, `object`, `function`, etc.
|
|
2098
|
-
* @param {*} value - The value to check.
|
|
2099
|
-
* @returns {boolean} Return `true` if `value` is a valid property key, otherwise `false`.
|
|
2100
|
-
* @example
|
|
2101
|
-
* isPropertyKey("foo");
|
|
2102
|
-
* // ➔ true
|
|
2103
|
-
* isPropertyKey(123);
|
|
2104
|
-
* // ➔ true
|
|
2105
|
-
* isPropertyKey(Symbol("id"));
|
|
2106
|
-
* // ➔ true
|
|
2107
|
-
* isPropertyKey({});
|
|
2108
|
-
* // ➔ false
|
|
2109
|
-
* isPropertyKey(null);
|
|
2110
|
-
* // ➔ false
|
|
2111
|
-
*/
|
|
2112
|
-
declare function isPropertyKey(value: unknown): value is PropertyKey;
|
|
2113
|
-
|
|
2114
|
-
/** ----------------------------------------------------------
|
|
2115
|
-
* * ***Type guard: `isRegExp`.***
|
|
2116
|
-
* ----------------------------------------------------------
|
|
2117
|
-
* **Checks if a value is a [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) instance.**
|
|
2118
|
-
* @param {*} value - The value to check.
|
|
2119
|
-
* @returns {boolean} Return `true` if value is an instance of **`RegExp`**.
|
|
2120
|
-
* @example
|
|
2121
|
-
* isRegExp(/abc/); // ➔ true
|
|
2122
|
-
* isRegExp(new RegExp("abc")); // ➔ true
|
|
2123
|
-
* isRegExp("abc"); // ➔ false
|
|
2124
|
-
*/
|
|
2125
|
-
declare const isRegExp: (value: unknown) => value is RegExp;
|
|
2126
|
-
|
|
2127
|
-
/** --------------------------------------------------
|
|
2128
|
-
* * ***Type guard: `isSafeInteger`.***
|
|
2129
|
-
* --------------------------------------------------
|
|
2130
|
-
* **Checks if `value` is a **[`Safe-Integer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)**.**
|
|
2131
|
-
* - **Behavior:**
|
|
2132
|
-
* - Narrows type to `number` when true.
|
|
2133
|
-
* - **An integer is considered *safe* if:**
|
|
2134
|
-
* - It is an `IEEE-754` **double precision number**.
|
|
2135
|
-
* - It can be exactly represented without rounding errors.
|
|
2136
|
-
* - It lies within the range **-(2^53 - 1) to 2^53 - 1**.
|
|
2137
|
-
* - **Note:**
|
|
2138
|
-
* - This method is based on **{@link Number.isSafeInteger | `Number.isSafeInteger`}**.
|
|
2139
|
-
* @param {*} value - The value to check.
|
|
2140
|
-
* @returns {boolean} Return `true` if `value` is a safe integer, otherwise `false`.
|
|
2141
|
-
* @example
|
|
2142
|
-
* isSafeInteger(3);
|
|
2143
|
-
* // ➔ true
|
|
2144
|
-
* isSafeInteger(Number.MIN_VALUE);
|
|
2145
|
-
* // ➔ false
|
|
2146
|
-
* isSafeInteger(Infinity);
|
|
2147
|
-
* // ➔ false
|
|
2148
|
-
* isSafeInteger('3');
|
|
2149
|
-
* // ➔ false
|
|
2150
|
-
*/
|
|
2151
|
-
declare function isSafeInteger(value: unknown): value is number;
|
|
2152
|
-
|
|
2153
|
-
/** ---------------------------------------------------------
|
|
2154
|
-
* * ***Environment Predicate: `isServer`.***
|
|
2155
|
-
* ---------------------------------------------------------
|
|
2156
|
-
* **Detects whether the current code is executing in a
|
|
2157
|
-
* **non-browser JavaScript runtime** (server-side) rather
|
|
2158
|
-
* than in a web browser.**
|
|
2159
|
-
* @description
|
|
2160
|
-
* It simply checks for the absence of key browser globals like
|
|
2161
|
-
* [**`window`**](https://developer.mozilla.org/docs/Web/API/Window/window) and
|
|
2162
|
-
* [**`document`**](https://developer.mozilla.org/docs/Web/API/Window/document).
|
|
2163
|
-
* - *If those globals aren’t present, we treat the runtime as a server environment.*
|
|
2164
|
-
* @returns {boolean}
|
|
2165
|
-
* * ***true** – Code is executing on the `server`.*
|
|
2166
|
-
* * ***false** – Code is executing in a `browser`.*
|
|
2167
|
-
* @example
|
|
2168
|
-
* if (isServer()) {
|
|
2169
|
-
* console.log("Running on a server-side runtime");
|
|
2170
|
-
* } else {
|
|
2171
|
-
* console.log("Running in a browser");
|
|
2172
|
-
* }
|
|
2173
|
-
*/
|
|
2174
|
-
declare const isServer: () => boolean;
|
|
2175
|
-
|
|
2176
|
-
/** ---------------------------------------------------------
|
|
2177
|
-
* * ***Type guard: `isSet`.***
|
|
2178
|
-
* ----------------------------------------------------------
|
|
2179
|
-
* **Checks if a value is a **[`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/Set)** object.**
|
|
2180
|
-
* - **Behavior:**
|
|
2181
|
-
* - Narrows type to `Set<T>` when true.
|
|
2182
|
-
* - Excludes `WeakSet`, arrays, plain objects, and other non-Set values.
|
|
2183
|
-
* @template T - The type of the value being checked.
|
|
2184
|
-
* @param {*} value - The value to check.
|
|
2185
|
-
* @returns {boolean} Returns `true` if the value is a `Set`, otherwise `false`.
|
|
2186
|
-
* @example
|
|
2187
|
-
* isSet(new Set);
|
|
2188
|
-
* // ➔ true
|
|
2189
|
-
* isSet(new WeakSet);
|
|
2190
|
-
* // ➔ false
|
|
2191
|
-
*/
|
|
2192
|
-
declare function isSet<T = unknown>(value: Set<T>): value is Set<T>;
|
|
2193
|
-
declare function isSet(value: unknown): value is Set<unknown>;
|
|
2194
|
-
|
|
2195
|
-
/** ---------------------------------------------------------
|
|
2196
|
-
* * ***Type guard: `isString`.***
|
|
2197
|
-
* ----------------------------------------------------------
|
|
2198
|
-
* **Checks if a value is of type
|
|
2199
|
-
* **[`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**.**
|
|
2200
|
-
* - **Behavior:**
|
|
2201
|
-
* - Narrows type to `string` when true.
|
|
2202
|
-
* - Uses the `typeof` operator for strict checking.
|
|
2203
|
-
* @param {*} value - The value to check.
|
|
2204
|
-
* @returns {boolean} Returns `true` if the value is a string, otherwise `false`.
|
|
2205
|
-
* @example
|
|
2206
|
-
* isString("hello"); // ➔ true
|
|
2207
|
-
* isString(123); // ➔ false
|
|
2208
|
-
*
|
|
2209
|
-
* // Usage in type narrowing
|
|
2210
|
-
* const value: unknown = getValue();
|
|
2211
|
-
* if (isString(value)) {
|
|
2212
|
-
* // TypeScript now knows `value` is a string
|
|
2213
|
-
* console.log(value.toUpperCase());
|
|
2214
|
-
* }
|
|
2215
|
-
*/
|
|
2216
|
-
declare const isString: (value: unknown) => value is string;
|
|
2217
|
-
|
|
2218
|
-
/** ----------------------------------------------------
|
|
2219
|
-
* * ***Type guard: `isStringObject`.***
|
|
2220
|
-
* ----------------------------------------------------
|
|
2221
|
-
* **Checks if a value is a **`String` object wrapper**
|
|
2222
|
-
* (`new String(...)`), not a primitive string.**
|
|
2223
|
-
* @param {*} value The value to check.
|
|
2224
|
-
* @returns {boolean} Returns `true` if `value` is a `String` object.
|
|
2225
|
-
* @example
|
|
2226
|
-
* isStringObject(new String("hello"));
|
|
2227
|
-
* // ➔ true
|
|
2228
|
-
* isStringObject("hello");
|
|
2229
|
-
* // ➔ false
|
|
2230
|
-
*/
|
|
2231
|
-
declare function isStringObject(value: unknown): value is String;
|
|
2232
|
-
|
|
2233
|
-
/** ----------------------------------------------------------
|
|
2234
|
-
* * ***Type guard: `isSymbol`.***
|
|
2235
|
-
* ----------------------------------------------------------
|
|
2236
|
-
* **Checks if a value is of type
|
|
2237
|
-
* **[`symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/Symbol)**.**
|
|
2238
|
-
* - **Behavior:**
|
|
2239
|
-
* - Narrows type to `symbol` when true.
|
|
2240
|
-
* - Uses the `typeof` operator for strict checking.
|
|
2241
|
-
* @param {*} value - The value to check.
|
|
2242
|
-
* @returns {boolean} Returns `true` if the value is a symbol, otherwise `false`.
|
|
2243
|
-
* @example
|
|
2244
|
-
* isSymbol(Symbol("id")); // ➔ true
|
|
2245
|
-
* isSymbol("not a symbol"); // ➔ false
|
|
2246
|
-
* isSymbol(123); // ➔ false
|
|
2247
|
-
* isSymbol(undefined); // ➔ false
|
|
2248
|
-
*/
|
|
2249
|
-
declare const isSymbol: (value: unknown) => value is symbol;
|
|
2250
|
-
|
|
2251
|
-
/** --------------------------------------------------
|
|
2252
|
-
* * ***Type guard: `isTypedArray`.***
|
|
2253
|
-
* ----------------------------------------------------------
|
|
2254
|
-
* **Checks if `value` is classified as a
|
|
2255
|
-
* **[`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)**.**
|
|
2256
|
-
* - **Behavior:**
|
|
2257
|
-
* - Validates that `value` is a non-null object.
|
|
2258
|
-
* - Uses `Object.prototype.toString` tag matching against known typed array tags.
|
|
2259
|
-
* - Narrows type to **{@link TypedArray | `TypedArray`}** when true.
|
|
2260
|
-
* @param {*} value - The value to check.
|
|
2261
|
-
* @returns {boolean} Returns `true` if the value is a typed array, otherwise `false`.
|
|
2262
|
-
* @example
|
|
2263
|
-
* isTypedArray(new Uint8Array); // ➔ true
|
|
2264
|
-
* isTypedArray(new Uint8Array()); // ➔ true
|
|
2265
|
-
* isTypedArray(new Float32Array()); // ➔ true
|
|
2266
|
-
* isTypedArray(new Uint8ClampedArray()); // ➔ true
|
|
2267
|
-
* isTypedArray([]); // ➔ false
|
|
2268
|
-
* isTypedArray(Buffer.from("hi")); // ➔ false
|
|
2269
|
-
*/
|
|
2270
|
-
declare function isTypedArray(value: unknown): value is TypedArray;
|
|
2271
|
-
|
|
2272
|
-
/** ---------------------------------------------------------
|
|
2273
|
-
* * ***Type guard: `isURL`.***
|
|
2274
|
-
* ----------------------------------------------------------
|
|
2275
|
-
* **Checks if a value is an instance of the
|
|
2276
|
-
* **[`URL`](https://developer.mozilla.org/docs/Web/API/URL)** class.**
|
|
2277
|
-
* - **Behavior:**
|
|
2278
|
-
* - Narrows type to `URL` when true.
|
|
2279
|
-
* - Excludes `strings`, `plain-objects`, and `other non-URL values`.
|
|
2280
|
-
* @param {*} value - The value to check.
|
|
2281
|
-
* @returns {boolean} Returns `true` if the value is an instance of `URL`, otherwise `false`.
|
|
2282
|
-
* @example
|
|
2283
|
-
* isURL(new URL("https://example.com"));
|
|
2284
|
-
* // ➔ true
|
|
2285
|
-
* isURL("https://example.com");
|
|
2286
|
-
* // ➔ false
|
|
2287
|
-
*/
|
|
2288
|
-
declare const isURL: (value: unknown) => value is URL;
|
|
2289
|
-
|
|
2290
|
-
/** ---------------------------------------------------------
|
|
2291
|
-
* * ***Type guard: `isUndefined`.***
|
|
2292
|
-
* ----------------------------------------------------------
|
|
2293
|
-
* **Checks if a value is
|
|
2294
|
-
* **[`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**.**
|
|
2295
|
-
* - **Behavior:**
|
|
2296
|
-
* - Narrows type to `undefined` when true.
|
|
2297
|
-
* - Excludes `null`, `objects`, `arrays`, `strings`, `numbers`, and
|
|
2298
|
-
* `all other values`.
|
|
2299
|
-
* @param {*} value - The value to check.
|
|
2300
|
-
* @returns {boolean} Returns `true` if the value is `undefined`, otherwise `false`.
|
|
2301
|
-
* @example
|
|
2302
|
-
* isUndefined(undefined); // ➔ true
|
|
2303
|
-
* isUndefined([]); // ➔ false
|
|
2304
|
-
* isUndefined(123); // ➔ false
|
|
2305
|
-
* isUndefined(null); // ➔ false
|
|
2306
|
-
* isUndefined("abc"); // ➔ false
|
|
2307
|
-
*/
|
|
2308
|
-
declare const isUndefined: (value: unknown) => value is undefined;
|
|
2309
|
-
|
|
2310
|
-
/** ---------------------------------------------------------
|
|
2311
|
-
* * ***Options for `isValidDomain` predicate.***
|
|
2312
|
-
* ---------------------------------------------------------
|
|
2313
|
-
* **Customize the behavior of domain validation.**
|
|
2314
|
-
*/
|
|
2315
|
-
type IsValidDomainOptions = {
|
|
2316
|
-
/** * ***Enable conversion of Unicode domains (IDN) to ASCII (punycode).***
|
|
2317
|
-
*
|
|
2318
|
-
* - Example: `"пример.рф"` ➔ `"xn--e1afmkfd.xn--p1ai"`
|
|
2319
|
-
* - Allows validating Unicode domains correctly.
|
|
2320
|
-
* - Default: `false`
|
|
2321
|
-
*
|
|
2322
|
-
* @defaultValue `false`.
|
|
2323
|
-
*/
|
|
2324
|
-
allowUnicode?: boolean;
|
|
2325
|
-
/** * ***If `true`, validates **only top-level domains (TLDs)** that are not part of any SLD/second-level domain.***
|
|
2326
|
-
*
|
|
2327
|
-
* - Accepts country-code TLDs like `"ai"` or `"ai."` ✅
|
|
2328
|
-
* - Rejects common TLDs that are part of SLDs like `"com"` ❌
|
|
2329
|
-
* - Only the final label is checked; subdomains are ignored.
|
|
2330
|
-
* - Default: `false`
|
|
2331
|
-
*
|
|
2332
|
-
* @defaultValue `false`.
|
|
2333
|
-
*/
|
|
2334
|
-
topLevel?: boolean;
|
|
2335
|
-
/** * ***Allow or disallow subdomains.***
|
|
2336
|
-
*
|
|
2337
|
-
* - Example: `"sub.example.com"` ✅ if `subdomain` is `true`, ❌ if `false`
|
|
2338
|
-
* - Wildcards and SLDs are considered when evaluating subdomains.
|
|
2339
|
-
* - Default: `true`
|
|
2340
|
-
*
|
|
2341
|
-
* @defaultValue `true`.
|
|
2342
|
-
*/
|
|
2343
|
-
subdomain?: boolean;
|
|
2344
|
-
/** * ***Allow a wildcard `*` in the left-most label.***
|
|
2345
|
-
*
|
|
2346
|
-
* - Example: `"*.example.com"` ✅ if `wildcard` is `true`, ❌ if `false`
|
|
2347
|
-
* - Wildcards are only valid in the first label and require at least one additional label.
|
|
2348
|
-
* - Default: `false`
|
|
2349
|
-
*
|
|
2350
|
-
* @defaultValue `false`.
|
|
2351
|
-
*/
|
|
2352
|
-
wildcard?: boolean;
|
|
2353
|
-
/** * ***Allow a port after the domain.***
|
|
2354
|
-
*
|
|
2355
|
-
* - Example: `"localhost:3000"` or `"example.com:8080"` ✅ if `allowPort` is `true`
|
|
2356
|
-
* - Validates that the port is a number between `1` and `65535`.
|
|
2357
|
-
* - Does not affect domain validation rules otherwise.
|
|
2358
|
-
* - Default: `false`
|
|
2359
|
-
*
|
|
2360
|
-
* @defaultValue `false`.
|
|
2361
|
-
*/
|
|
2362
|
-
allowPort?: boolean;
|
|
2363
|
-
/** * ***Allow special domains like `localhost`.***
|
|
2364
|
-
*
|
|
2365
|
-
* - Example: `"localhost"` ✅ if `allowLocalhost` is `true`
|
|
2366
|
-
* - Works with or without a port if `allowPort` is enabled.
|
|
2367
|
-
* - Default: `false`
|
|
2368
|
-
*
|
|
2369
|
-
* @defaultValue `false`.
|
|
2370
|
-
*/
|
|
2371
|
-
allowLocalhost?: boolean;
|
|
2372
|
-
/** * ***Allow URLs with protocol (`http`/`https`) and automatically extract the hostname.***
|
|
2373
|
-
*
|
|
2374
|
-
* - Example: `"https://example.com/foo/bar"` ➔ `"example.com"`
|
|
2375
|
-
* - The function will validate only the hostname part and ignore the path, query, and fragment.
|
|
2376
|
-
* - Default: `false`
|
|
2377
|
-
*
|
|
2378
|
-
* @defaultValue `false`.
|
|
2379
|
-
*/
|
|
2380
|
-
allowProtocol?: boolean;
|
|
2381
|
-
};
|
|
2382
|
-
/** ---------------------------------------------------------
|
|
2383
|
-
* * ***Predicate: `isValidDomain`.***
|
|
2384
|
-
* ---------------------------------------------------------
|
|
2385
|
-
* **Validates whether a given string is a properly formatted domain name.**
|
|
2386
|
-
*
|
|
2387
|
-
* - **Supports options for:**
|
|
2388
|
-
* - `allowUnicode` ➔ allows internationalized domain names (IDN) with Unicode characters.
|
|
2389
|
-
* - `topLevel` ➔ validates **only top-level domains (TLDs)**; ignores subdomains and SLDs.
|
|
2390
|
-
* - `subdomain` ➔ allows or disallows subdomains.
|
|
2391
|
-
* - `wildcard` ➔ allows wildcard (`*`) in the left-most label.
|
|
2392
|
-
* - `allowPort` ➔ allows a port number after the domain (e.g., `example.com:8080`).
|
|
2393
|
-
* - `allowLocalhost` ➔ allows the special domain `"localhost"`.
|
|
2394
|
-
* - `allowProtocol` ➔ allows a URL with protocol (`http`/`https`) and extracts the hostname.
|
|
2395
|
-
*
|
|
2396
|
-
* - **Behavior:**
|
|
2397
|
-
* - ✅ Converts Unicode to ASCII (punycode) if `allowUnicode` is `true`.
|
|
2398
|
-
* - ✅ Checks label lengths (≤63 chars), valid characters, and punycode consistency.
|
|
2399
|
-
* - ✅ Validates port if `allowPort` is `true` (must be 1–65535).
|
|
2400
|
-
* - ✅ Accepts `"localhost"` if `allowLocalhost` is `true`.
|
|
2401
|
-
* - ✅ Extracts hostname from URLs if `allowProtocol` is `true`.
|
|
2402
|
-
* - ❌ Rejects invalid domains, labels starting/ending with `-`, double dots, malformed TLDs, or invalid port numbers.
|
|
2403
|
-
* - ✅ Handles both standard domains (example.com), URLs with protocols (https://example.com/foo), and IDNs (пример.рф).
|
|
2404
|
-
*
|
|
2405
|
-
* @param {*} value - The value to validate; only strings are valid domains.
|
|
2406
|
-
* @param {IsValidDomainOptions} [options] - Optional configuration for domain validation.
|
|
2407
|
-
* @param {boolean} [options.allowUnicode=false] - Enable punycode conversion for Unicode domains.
|
|
2408
|
-
* @param {boolean} [options.topLevel=false] - Validate only TLDs (e.g., `ai`, `uk.`); ignores SLDs like `com`.
|
|
2409
|
-
* @param {boolean} [options.subdomain=true] - Allow subdomains; set `false` to reject any subdomain.
|
|
2410
|
-
* @param {boolean} [options.wildcard=false] - Allow wildcard `*` in the left-most label (e.g., `*.example.com`).
|
|
2411
|
-
* @param {boolean} [options.allowPort=false] - Allow port number after domain (e.g., `:3000`); must be 1–65535.
|
|
2412
|
-
* @param {boolean} [options.allowLocalhost=false] - Allow special domain `"localhost"`.
|
|
2413
|
-
* @param {boolean} [options.allowProtocol=false] - Allow URLs with protocol (`http`/`https`) and extract hostname only.
|
|
2414
|
-
* @returns {boolean} Returns `true` if the value is a valid domain according to the rules and options; otherwise `false`.
|
|
2415
|
-
*
|
|
2416
|
-
* @example
|
|
2417
|
-
* isValidDomain("google.com");
|
|
2418
|
-
* // ➔ true
|
|
2419
|
-
* isValidDomain("пример.рф", { allowUnicode: true });
|
|
2420
|
-
* // ➔ true
|
|
2421
|
-
* isValidDomain("sub.example.com", { subdomain: false });
|
|
2422
|
-
* // ➔ false
|
|
2423
|
-
* isValidDomain("*.example.com", { wildcard: true });
|
|
2424
|
-
* // ➔ true
|
|
2425
|
-
* isValidDomain("com", { topLevel: true });
|
|
2426
|
-
* // ➔ false (common TLD rejected because it's part of SLD)
|
|
2427
|
-
* isValidDomain("ai.", { topLevel: true });
|
|
2428
|
-
* // ➔ true (country-code TLD accepted)
|
|
2429
|
-
* isValidDomain("localhost", { allowLocalhost: true });
|
|
2430
|
-
* // ➔ true
|
|
2431
|
-
* isValidDomain("localhost:3000", { allowLocalhost: true, allowPort: true });
|
|
2432
|
-
* // ➔ true
|
|
2433
|
-
* isValidDomain("example.com:8080", { allowPort: true });
|
|
2434
|
-
* // ➔ true
|
|
2435
|
-
* isValidDomain("https://example.com/foo/bar", { allowProtocol: true });
|
|
2436
|
-
* // ➔ true (protocol stripped and hostname validated)
|
|
2437
|
-
* isValidDomain("invalid_domain.com");
|
|
2438
|
-
* // ➔ false
|
|
2439
|
-
*/
|
|
2440
|
-
declare function isValidDomain(value: unknown, options?: IsValidDomainOptions): boolean;
|
|
2441
|
-
|
|
2442
|
-
/** ---------------------------------------------------------
|
|
2443
|
-
* * ***Predicate: `isValidURL`.***
|
|
2444
|
-
* ---------------------------------------------------------
|
|
2445
|
-
* **Validates whether a given string is a properly formatted URL.**
|
|
2446
|
-
* - **Ensures that the input is:**
|
|
2447
|
-
* - A non-empty string.
|
|
2448
|
-
* - A valid **[`URL`](https://developer.mozilla.org/docs/Web/API/URL)** with `http://` or `https://` scheme.
|
|
2449
|
-
* - **Behavior:**
|
|
2450
|
-
* - ✅ Includes decoding for percent-encoded URLs (e.g., `https%3A%2F%2F...`).
|
|
2451
|
-
* - ❌ Rejects invalid strings, unsupported schemes, and malformed domains.
|
|
2452
|
-
* @param {*} url - The value to validate.
|
|
2453
|
-
* @returns {boolean} Return `true` if the value is a **valid URL string**, otherwise `false`.
|
|
2454
|
-
* @example
|
|
2455
|
-
* isValidURL("https://example.com");
|
|
2456
|
-
* // ➔ true
|
|
2457
|
-
* isValidURL("ftp://example.com");
|
|
2458
|
-
* // ➔ false
|
|
2459
|
-
* isValidURL("not-a-url");
|
|
2460
|
-
* // ➔ false
|
|
2461
|
-
*/
|
|
2462
|
-
declare const isValidURL: (url: unknown) => boolean;
|
|
2463
|
-
|
|
2464
|
-
/** --------------------------------------------------
|
|
2465
|
-
* * ***Type guard: `isWeakMap`.***
|
|
2466
|
-
* ----------------------------------------------------------
|
|
2467
|
-
* **Checks if a value is a **[`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/WeakMap)** object.**
|
|
2468
|
-
* - **Behavior:**
|
|
2469
|
-
* - Narrows type to `WeakMap<K, V>` when true.
|
|
2470
|
-
* - Excludes `Map`, `arrays`, `plain-objects,` and `other non-WeakMap values`.
|
|
2471
|
-
* @template K - Keys must be objects.
|
|
2472
|
-
* @template V - Type of values stored in the WeakMap.
|
|
2473
|
-
* @param {*} value - The value to check.
|
|
2474
|
-
* @returns {boolean} Returns `true` if the value is a `WeakMap`, otherwise `false`.
|
|
2475
|
-
* @example
|
|
2476
|
-
* isWeakMap(new WeakMap);
|
|
2477
|
-
* // ➔ true
|
|
2478
|
-
* isWeakMap(new Map);
|
|
2479
|
-
* // ➔ false
|
|
2480
|
-
*/
|
|
2481
|
-
declare function isWeakMap<K extends object = object, V = unknown>(value: unknown): value is WeakMap<K, V>;
|
|
2482
|
-
|
|
2483
|
-
export { IsPlainObjectResult, areArraysEqual, areObjectsEqual, areURLsEqualPath, areURLsIdentical, arrayHasAnyMatch, doesKeyExist, hasOwnProp, isArguments, isArray, isArrayBuffer, isArrayLike, isArrayLikeObject, isBigInt, isBoolean, isBooleanObject, isBuffer, isCurrencyLike, isDate, isDeepEqual, isElement, isEmpty, isEmptyArray, isEmptyDeep, isEmptyObject, isEmptyString, isEmptyValue, isEqual, isEqualWith, isError, isFinite, isFunction, isInfinityNumber, isInteger, isLength, isMap, isMatch, isMatchWith, isNaN, isNative, isNil, isNonEmptyArray, isNonEmptyString, isNonEmptyValue, isNull, isNumberObject, isObject, isObjectLoose, isObjectOrArray, isPropertyKey, isRegExp, isSafeInteger, isServer, isSet, isString, isStringObject, isSymbol, isTypedArray, isURL, isUndefined, isValidDomain, isValidURL, isWeakMap, textContainsAll, textContainsAny };
|
|
2
|
+
* ========================================================================
|
|
3
|
+
* @rzl-zone/utils-js
|
|
4
|
+
* ------------------------------------------------------------------------
|
|
5
|
+
* Version: `3.12.1-beta.1`
|
|
6
|
+
* Author: `Rizalvin Dwiky <rizalvindwiky@gmail.com>`
|
|
7
|
+
* Repository: `https://github.com/rzl-zone/rzl-zone/tree/main/packages/utils-js`
|
|
8
|
+
* ========================================================================
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { a as IsNumberOptions, c as GetPreciseTypeOptions, l as getPreciseType, n as isPlainObject, o as isNumber, s as AcronymsList, t as IsPlainObjectResult } from "../isPlainObject-DxNDL8XU.js";
|
|
12
|
+
import { $ as isArrayBuffer, A as isInteger, B as isEmptyDeep, C as isNil, D as isMatch, E as isMatchWith, F as isEqualWith, G as isDate, H as isEmpty, I as isEqual, J as isBooleanObject, K as isCurrencyLike, L as isEmptyValue, M as isFunction, N as isFinite, O as isMap, P as isError, Q as isArrayLike, R as isEmptyString, S as isNonEmptyArray, T as isNaN, U as isElement, V as isEmptyArray, W as isDeepEqual, X as isBigInt, Y as isBoolean, Z as isArrayLikeObject, _ as isObject, a as isURL, at as textContainsAny, b as isNonEmptyValue, c as isStringObject, ct as areURLsEqualPath, d as isServer, et as isArray, f as isSafeInteger, g as isObjectLoose, h as isObjectOrArray, i as isUndefined, it as doesKeyExist, j as isInfinityNumber, k as isLength, l as isString, lt as areObjectsEqual, m as isPropertyKey, n as isValidURL, nt as hasOwnProp, o as isTypedArray, ot as textContainsAll, p as isRegExp, q as isBuffer, r as isValidDomain, rt as arrayHasAnyMatch, s as isSymbol, st as areURLsIdentical, t as isWeakMap, tt as isArguments, u as isSet, ut as areArraysEqual, v as isNumberObject, w as isNative, x as isNonEmptyString, y as isNull, z as isEmptyObject } from "../index-UPp94Agr.js";
|
|
13
|
+
export { AcronymsList, GetPreciseTypeOptions, IsNumberOptions, IsPlainObjectResult, areArraysEqual, areObjectsEqual, areURLsEqualPath, areURLsIdentical, arrayHasAnyMatch, doesKeyExist, getPreciseType, hasOwnProp, isArguments, isArray, isArrayBuffer, isArrayLike, isArrayLikeObject, isBigInt, isBoolean, isBooleanObject, isBuffer, isCurrencyLike, isDate, isDeepEqual, isElement, isEmpty, isEmptyArray, isEmptyDeep, isEmptyObject, isEmptyString, isEmptyValue, isEqual, isEqualWith, isError, isFinite, isFunction, isInfinityNumber, isInteger, isLength, isMap, isMatch, isMatchWith, isNaN, isNative, isNil, isNonEmptyArray, isNonEmptyString, isNonEmptyValue, isNull, isNumber, isNumberObject, isObject, isObjectLoose, isObjectOrArray, isPlainObject, isPropertyKey, isRegExp, isSafeInteger, isServer, isSet, isString, isStringObject, isSymbol, isTypedArray, isURL, isUndefined, isValidDomain, isValidURL, isWeakMap, textContainsAll, textContainsAny };
|