@rzl-zone/utils-js 3.0.0-beta.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -27
- package/dist/NumberRangeUnion-DC-C3_Kq.d.ts +23 -23
- package/dist/any-BmdI8UbK.d.ts +56 -56
- package/dist/arrays-normalize-recursive-CnjYJ9xg.d.ts +66 -66
- package/dist/assertions/index.cjs +1 -1
- package/dist/assertions/index.d.ts +398 -418
- package/dist/assertions/index.js +1 -1
- package/dist/chunk-2HSNUPEO.cjs +1 -0
- package/dist/chunk-3YCFMGRB.js +1 -0
- package/dist/chunk-4Z75R3IT.cjs +1 -0
- package/dist/chunk-5C2SMIGX.cjs +1 -0
- package/dist/chunk-5Z2G23WP.js +1 -0
- package/dist/chunk-6C3ATUGM.cjs +1 -0
- package/dist/chunk-AJ25PWXX.cjs +1 -0
- package/dist/chunk-BHIBDDQF.js +1 -0
- package/dist/chunk-CE4JI2YB.js +1 -0
- package/dist/chunk-CMJ6UYWW.cjs +1 -0
- package/dist/chunk-D3VSHABU.cjs +1 -0
- package/dist/chunk-DG2GWBTS.cjs +1 -0
- package/dist/chunk-DVMHRLKP.cjs +1 -0
- package/dist/chunk-ECRNH4FW.js +1 -0
- package/dist/chunk-EKS4IZJR.cjs +1 -0
- package/dist/chunk-EOZKYR5S.cjs +1 -0
- package/dist/chunk-EUANTHVN.js +1 -0
- package/dist/chunk-EW3I4O7X.js +1 -0
- package/dist/chunk-F3E77L46.js +1 -0
- package/dist/chunk-FIAAX3UE.js +1 -0
- package/dist/chunk-FV7SEBKD.cjs +1 -0
- package/dist/chunk-GGWPB23G.cjs +1 -0
- package/dist/chunk-GVWGQNLF.js +1 -0
- package/dist/chunk-H3FXL4DU.cjs +1 -0
- package/dist/chunk-HHPDLSX2.cjs +1 -0
- package/dist/chunk-IMCLPT5V.cjs +1 -0
- package/dist/chunk-IRGE5W7L.js +1 -0
- package/dist/chunk-J2RGTPGK.cjs +1 -0
- package/dist/chunk-JARPXKBM.cjs +1 -0
- package/dist/chunk-JFJUPYDT.cjs +1 -0
- package/dist/chunk-JLP56WSM.js +1 -0
- package/dist/chunk-K3MV4AIN.cjs +1 -0
- package/dist/chunk-KHO2SBNA.cjs +1 -0
- package/dist/chunk-KOVO72OM.js +1 -0
- package/dist/chunk-LJ4M3VGE.js +1 -0
- package/dist/chunk-LJVGJLP4.js +1 -0
- package/dist/chunk-M47QIBXI.cjs +1 -0
- package/dist/chunk-MC3LXMCQ.js +1 -0
- package/dist/chunk-MISCBZJC.js +1 -0
- package/dist/chunk-MMSYCIJ2.cjs +1 -1
- package/dist/chunk-MTUBDVJ2.js +1 -0
- package/dist/chunk-O7UT5AN3.cjs +1 -0
- package/dist/chunk-OGPPP2S3.js +1 -0
- package/dist/chunk-OLPKAX7F.cjs +1 -0
- package/dist/chunk-ONZFBJVW.js +1 -0
- package/dist/chunk-ORZFHBEY.js +1 -0
- package/dist/chunk-OWV2P376.js +1 -0
- package/dist/chunk-QNKGP5DY.js +1 -0
- package/dist/chunk-RV2WK5E6.js +1 -0
- package/dist/chunk-SBF43G3B.cjs +1 -0
- package/dist/chunk-T4CIAKEK.js +1 -0
- package/dist/chunk-UDA26MCU.cjs +1 -0
- package/dist/chunk-VCFXNV3Q.cjs +1 -0
- package/dist/chunk-VHAPTHEA.cjs +1 -0
- package/dist/chunk-WVSPXFTY.js +1 -0
- package/dist/chunk-X74TUJSE.cjs +1 -0
- package/dist/chunk-XC3QHAK2.cjs +1 -0
- package/dist/chunk-XLDAIZRK.js +1 -0
- package/dist/chunk-XZJ7C4N6.js +1 -0
- package/dist/chunk-YV3K2EKJ.js +1 -0
- package/dist/chunk-ZHV5ZYVN.cjs +1 -0
- package/dist/chunk-ZL7J6GTP.js +1 -0
- package/dist/chunk-ZTCLKKMB.js +1 -0
- package/dist/conversions/index.cjs +1 -1
- package/dist/conversions/index.d.ts +1307 -1504
- package/dist/conversions/index.js +1 -1
- package/dist/env/index.cjs +1 -1
- package/dist/env/index.d.ts +14 -17
- package/dist/env/index.js +1 -1
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.d.ts +111 -108
- package/dist/events/index.js +1 -1
- package/dist/extends-Bk_SBGdT.d.ts +367 -0
- package/dist/formatting/index.cjs +1 -1
- package/dist/formatting/index.d.ts +878 -840
- package/dist/formatting/index.js +1 -1
- package/dist/generator/index.cjs +1 -1
- package/dist/generator/index.d.ts +173 -150
- package/dist/generator/index.js +1 -1
- package/dist/if-CvT4R7Kh.d.ts +16 -16
- package/dist/is-array--YjXV-Wx.d.ts +1207 -0
- package/dist/isPlainObject-BVhBAPHX.d.ts +169 -0
- package/dist/never-BfayMBF9.d.ts +64 -64
- package/dist/next/index.cjs +1 -8
- package/dist/next/index.d.ts +196 -176
- package/dist/next/index.js +1 -8
- package/dist/next/server/index.cjs +1 -2
- package/dist/next/server/index.d.ts +26 -40
- package/dist/next/server/index.js +1 -2
- package/dist/nils-DMz3kU7M.d.ts +155 -155
- package/dist/omit-VvmIsZmX.d.ts +25 -25
- package/dist/operations/index.cjs +1 -1
- package/dist/operations/index.d.ts +121 -176
- package/dist/operations/index.js +1 -1
- package/dist/parsers/index.cjs +1 -1
- package/dist/parsers/index.d.ts +35 -36
- package/dist/parsers/index.js +1 -1
- package/dist/predicates/index.cjs +1 -1
- package/dist/predicates/index.d.ts +1701 -1675
- package/dist/predicates/index.js +1 -1
- package/dist/prettify-C4xLcYOP.d.ts +328 -328
- package/dist/promise/index.cjs +1 -1
- package/dist/promise/index.d.ts +29 -38
- package/dist/promise/index.js +1 -1
- package/dist/rzl-utils.global.js +1 -4
- package/dist/string-XA-til3C.d.ts +351 -0
- package/dist/strings/index.cjs +1 -1
- package/dist/strings/index.d.ts +712 -787
- package/dist/strings/index.js +1 -1
- package/dist/tailwind/index.cjs +1 -0
- package/dist/tailwind/index.d.ts +565 -0
- package/dist/tailwind/index.js +1 -0
- package/dist/type-data-DDs-u2kq.d.ts +241 -241
- package/dist/types/index.d.ts +3266 -3266
- package/dist/urls/index.cjs +1 -1
- package/dist/urls/index.d.ts +384 -409
- package/dist/urls/index.js +1 -1
- package/package.json +61 -18
- package/dist/array-CIZRbqTF.d.ts +0 -223
- package/dist/chunk-2TRAPBZ7.cjs +0 -1
- package/dist/chunk-3D74QO5D.cjs +0 -1
- package/dist/chunk-4DK3RCC4.js +0 -2
- package/dist/chunk-4JOQ45HL.js +0 -1
- package/dist/chunk-55CZALRS.js +0 -1
- package/dist/chunk-56QBKKRE.js +0 -1
- package/dist/chunk-5JFV3GDE.cjs +0 -4
- package/dist/chunk-5SZUSNGZ.js +0 -1
- package/dist/chunk-62HX5Z45.cjs +0 -1
- package/dist/chunk-7NA6DUHR.cjs +0 -2
- package/dist/chunk-7YWAQOA4.cjs +0 -1
- package/dist/chunk-BVPMMWDL.cjs +0 -1
- package/dist/chunk-BYZAD3XN.cjs +0 -1
- package/dist/chunk-CEFYHEM4.cjs +0 -1
- package/dist/chunk-CN53M4QZ.cjs +0 -1
- package/dist/chunk-D47MHBSD.cjs +0 -1
- package/dist/chunk-DGH75GJD.js +0 -1
- package/dist/chunk-E5NUI7PN.js +0 -1
- package/dist/chunk-ELDDNERR.js +0 -1
- package/dist/chunk-EXZ47NOW.js +0 -1
- package/dist/chunk-FDITZ5C6.cjs +0 -1
- package/dist/chunk-FF76ISQ2.js +0 -1
- package/dist/chunk-FIEZKTAZ.cjs +0 -1
- package/dist/chunk-FSSV24W7.cjs +0 -1
- package/dist/chunk-GCGU2WB7.js +0 -1
- package/dist/chunk-GECI2YBP.js +0 -1
- package/dist/chunk-GQE4OVHC.cjs +0 -1
- package/dist/chunk-GRVZXQXL.cjs +0 -1
- package/dist/chunk-I4AVNHPA.cjs +0 -1
- package/dist/chunk-JFRL7NKU.js +0 -4
- package/dist/chunk-JWHM3WZQ.cjs +0 -1
- package/dist/chunk-KCQDDZJE.cjs +0 -1
- package/dist/chunk-L54ZPSYJ.js +0 -1
- package/dist/chunk-LVKAYEZ4.js +0 -1
- package/dist/chunk-MBDWTK54.cjs +0 -1
- package/dist/chunk-MNGGDB2G.js +0 -1
- package/dist/chunk-MY7BA4GI.cjs +0 -1
- package/dist/chunk-N2IJPIND.cjs +0 -1
- package/dist/chunk-NIMNTEGV.js +0 -1
- package/dist/chunk-NNM7QCNB.js +0 -1
- package/dist/chunk-PUQXRLZH.cjs +0 -1
- package/dist/chunk-PVJF2JHM.js +0 -1
- package/dist/chunk-QCFXEUKL.js +0 -1
- package/dist/chunk-QFCGBBSY.js +0 -1
- package/dist/chunk-QQYAUPSK.cjs +0 -1
- package/dist/chunk-RN3TP3S3.js +0 -1
- package/dist/chunk-RV2VULM7.cjs +0 -1
- package/dist/chunk-SW6HYEW7.cjs +0 -1
- package/dist/chunk-SYJC7UAW.js +0 -1
- package/dist/chunk-TC4VBE4Y.cjs +0 -1
- package/dist/chunk-TUXDINHF.cjs +0 -1
- package/dist/chunk-U5Y2FXMN.cjs +0 -1
- package/dist/chunk-UUPQI6ND.cjs +0 -1
- package/dist/chunk-VYCGZ2S6.js +0 -1
- package/dist/chunk-W5EDKJK3.js +0 -1
- package/dist/chunk-WHAVUFEU.js +0 -1
- package/dist/chunk-XCFIOTCV.js +0 -1
- package/dist/chunk-XE27XPJR.js +0 -1
- package/dist/chunk-XH6MCRLP.js +0 -1
- package/dist/chunk-XVB3ZZEB.js +0 -1
- package/dist/chunk-ZBSIGJFO.cjs +0 -1
- package/dist/chunk-ZYAML74V.js +0 -1
- package/dist/extends-Mp81Hq9-.d.ts +0 -145
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/is-array-Ckm_47hw.d.ts +0 -1557
- package/dist/isPlainObject-BKYaI6a8.d.ts +0 -182
- package/dist/stylings/index.cjs +0 -1
- package/dist/stylings/index.d.ts +0 -49
- package/dist/stylings/index.js +0 -1
|
@@ -1,220 +1,283 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{k as IsPositive,P as ParseNumber,I as IsStringLiteral,C as CharAt,d as IsUnknown,m as IsReadonlyArray,o as IsArray,f as OrArr}from'../is-array--YjXV-Wx.js';import{A as AnyString,a as IsEmptyString,T as Trim}from'../string-XA-til3C.js';import{I as IsAny}from'../any-BmdI8UbK.js';import{A as AnyFunction,a as AnObjectNonArray,T as TypedArray}from'../type-data-DDs-u2kq.js';import{E as Extends}from'../extends-Bk_SBGdT.js';import{P as Prettify}from'../prettify-C4xLcYOP.js';import{N as NumberRangeUnion}from'../NumberRangeUnion-DC-C3_Kq.js';import{a as IsPlainObjectResult}from'../isPlainObject-BVhBAPHX.js';export{G as GetPreciseTypeOptions,I as IsNumberOptions,g as getPreciseType,i as isNumber,b as isPlainObject}from'../isPlainObject-BVhBAPHX.js';import{I as IsNever}from'../never-BfayMBF9.js';import'../if-CvT4R7Kh.js';type EmptyObject<T>={[K in keyof T]?:never;};type EmptyObjectOf<T>=EmptyObject<T>extends T?EmptyObject<T>:never;type List<T>=ArrayLike<T>;type CustomizerIsEqualWith=(value:unknown,other:unknown,indexOrKey:PropertyKey,parent:unknown,otherParent:unknown,stack:unknown)=>boolean|undefined;type CustomizerIsMatchWith=(value:unknown,other:unknown,indexOrKey:PropertyKey,object:object,source:object)=>boolean|undefined;
|
|
2
2
|
/** ----------------------------------------------------------
|
|
3
|
-
* * ***
|
|
4
|
-
* ----------------------------------------------------------
|
|
5
|
-
*
|
|
6
|
-
* Supports deep comparison of arrays containing nested arrays or objects
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* ```
|
|
30
|
-
|
|
31
|
-
* // → true
|
|
32
|
-
*
|
|
33
|
-
* areArraysEqual([1, 2, 3], [3, 2, 1]);
|
|
34
|
-
* // → false
|
|
35
|
-
*
|
|
36
|
-
* areArraysEqual([1, 2, 3], [3, 2, 1], true);
|
|
37
|
-
* // → true (order ignored)
|
|
38
|
-
*
|
|
39
|
-
* areArraysEqual([{ x: 1 }, { y: 2 }], [{ y: 2 }, { x: 1 }], true);
|
|
40
|
-
* // → true
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
3
|
+
* * ***Predicate: `areArraysEqual`.***
|
|
4
|
+
* ----------------------------------------------------------
|
|
5
|
+
* **Compares two arrays deeply to check if they are equal.**
|
|
6
|
+
* @description Supports deep comparison of arrays containing nested arrays or objects,
|
|
7
|
+
* can also ignore the order of elements at all levels by recursively sorting.
|
|
8
|
+
* @param {unknown[]} array1
|
|
9
|
+
* The first array to compare. Can contain nested arrays or objects.
|
|
10
|
+
* @param {unknown[]} array2
|
|
11
|
+
* The second array to compare against. Should match structure of `array1`.
|
|
12
|
+
* @param {boolean|undefined} [ignoreOrder=false]
|
|
13
|
+
* Whether to ignore the order of elements when comparing.
|
|
14
|
+
* - If `true`, will sort both arrays recursively before comparing, default is `false`.
|
|
15
|
+
* @returns {boolean}
|
|
16
|
+
* Returns `true` if both arrays are deeply equal, otherwise `false`.
|
|
17
|
+
* @throws {TypeError}
|
|
18
|
+
* Throws if `array1` or `array2` are not arrays, or if `ignoreOrder` is not a boolean.
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* areArraysEqual([1, 2, 3], [1, 2, 3]);
|
|
22
|
+
* // ➔ true
|
|
23
|
+
* areArraysEqual([1, 2, 3], [3, 2, 1]);
|
|
24
|
+
* // ➔ false
|
|
25
|
+
* areArraysEqual([1, 2, 3], [3, 2, 1], true);
|
|
26
|
+
* // ➔ true (order ignored)
|
|
27
|
+
* areArraysEqual([{ x: 1 }, { y: 2 }], [{ y: 2 }, { x: 1 }], true);
|
|
28
|
+
* // ➔ true
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
43
31
|
declare const areArraysEqual:(array1:unknown[],array2:unknown[],ignoreOrder?:boolean)=>boolean;
|
|
44
32
|
/** ---------------------------------
|
|
45
|
-
* * ***
|
|
46
|
-
* ---------------------------------
|
|
47
|
-
*
|
|
48
|
-
* @template T1 The type of the first object.
|
|
49
|
-
* @template T2 The type of the second object.
|
|
50
|
-
* @param {
|
|
51
|
-
* @param {
|
|
52
|
-
* @returns {boolean} `true` if both objects are deeply equal, otherwise `false`.
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* areObjectsEqual({ a: 1 }, { a: 1, b: undefined });
|
|
57
|
-
*
|
|
58
|
-
|
|
33
|
+
* * ***Predicate: `areObjectsEqual`.***
|
|
34
|
+
* ---------------------------------
|
|
35
|
+
* **Compares two objects for deep equality.**
|
|
36
|
+
* @template T1 The type of the first object.
|
|
37
|
+
* @template T2 The type of the second object.
|
|
38
|
+
* @param {*} object1 - The first object to compare.
|
|
39
|
+
* @param {*} object2 - The second object to compare.
|
|
40
|
+
* @returns {boolean} Return `true` if both objects are deeply equal, otherwise `false`.
|
|
41
|
+
* @example
|
|
42
|
+
* areObjectsEqual({ a: 1, b: 2 }, { a: 1, b: 2 });
|
|
43
|
+
* // ➔ true
|
|
44
|
+
* areObjectsEqual({ a: 1 }, { a: 1, b: undefined });
|
|
45
|
+
* // ➔ false
|
|
46
|
+
* areObjectsEqual([1, 2, 3], [1, 2, 3]);
|
|
47
|
+
* // ➔ true
|
|
48
|
+
*/
|
|
59
49
|
declare const areObjectsEqual:(object1:unknown,object2:unknown)=>boolean;
|
|
60
50
|
/** ---------------------------------
|
|
61
|
-
* * ***
|
|
62
|
-
* ---------------------------------
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* @
|
|
67
|
-
* @
|
|
68
|
-
*
|
|
69
|
-
|
|
51
|
+
* * ***Predicate: `areURLsEqualPath`.***
|
|
52
|
+
* ---------------------------------
|
|
53
|
+
* **Checks if two URLs are the same, ignoring query parameters, this function compares only the protocol, host, and pathname.**
|
|
54
|
+
* @param {URL} urlA - The first URL to compare.
|
|
55
|
+
* @param {URL} urlB - The second URL to compare.
|
|
56
|
+
* @returns {boolean} Returns `true` if both URLs are the same (ignoring search parameters), otherwise `false`.
|
|
57
|
+
* @example
|
|
58
|
+
* // Same domain, same path, different query -> true
|
|
59
|
+
* areURLsEqualPath(new URL("https://example.com/page?a=1"), new URL("https://example.com/page?b=2"));
|
|
60
|
+
* // ➔ true
|
|
61
|
+
*
|
|
62
|
+
* // Same domain, different path -> false
|
|
63
|
+
* areURLsEqualPath(new URL("https://example.com/page1"), new URL("https://example.com/page2"));
|
|
64
|
+
* // ➔ false
|
|
65
|
+
*
|
|
66
|
+
* // Different protocol -> false
|
|
67
|
+
* areURLsEqualPath(new URL("http://example.com/page"), new URL("https://example.com/page"));
|
|
68
|
+
* // ➔ false
|
|
69
|
+
*
|
|
70
|
+
* // Same protocol, same host, same path (ignores query & hash) -> true
|
|
71
|
+
* areURLsEqualPath(new URL("https://example.com/page#section"), new URL("https://example.com/page"));
|
|
72
|
+
* // ➔ true
|
|
73
|
+
*/
|
|
70
74
|
declare const areURLsEqualPath:(urlA:URL,urlB:URL)=>boolean;
|
|
71
75
|
/** ---------------------------------
|
|
72
|
-
* * ***
|
|
73
|
-
* ---------------------------------
|
|
74
|
-
*
|
|
75
|
-
* @param {URL} urlA - The first URL to compare.
|
|
76
|
-
* @param {URL} urlB - The second URL to compare.
|
|
77
|
-
* @returns {boolean} Returns `true` if both URLs are identical, otherwise `false`.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
|
|
100
|
-
*/
|
|
101
|
-
declare const textContainsAll:<T extends string>(text:T,searchWords:T[]|string[],options?:{
|
|
102
|
-
/** If `true`, matches whole words only, defaultValue is `false`. */
|
|
76
|
+
* * ***Predicate: `areURLsIdentical`.***
|
|
77
|
+
* ---------------------------------
|
|
78
|
+
* **Checks if two URLs are exactly the same, including protocol, host, pathname, and query parameters.**
|
|
79
|
+
* @param {URL} urlA - The first URL to compare.
|
|
80
|
+
* @param {URL} urlB - The second URL to compare.
|
|
81
|
+
* @returns {boolean} Returns `true` if both URLs are identical, otherwise `false`.
|
|
82
|
+
* @example
|
|
83
|
+
* // Identical URLs -> true
|
|
84
|
+
* areURLsIdentical(new URL("https://example.com/page?a=1"), new URL("https://example.com/page?a=1"));
|
|
85
|
+
* // ➔ true
|
|
86
|
+
*
|
|
87
|
+
* // Same path, different query parameter -> false
|
|
88
|
+
* areURLsIdentical(new URL("https://example.com/page?a=1"), new URL("https://example.com/page?b=2"));
|
|
89
|
+
* // ➔ false
|
|
90
|
+
*
|
|
91
|
+
* // Same host & query, but different protocol -> false
|
|
92
|
+
* areURLsIdentical(new URL("http://example.com/page?a=1"), new URL("https://example.com/page?a=1"));
|
|
93
|
+
* // ➔ false
|
|
94
|
+
*
|
|
95
|
+
* // Same everything except trailing slash -> false
|
|
96
|
+
* areURLsIdentical(new URL("https://example.com/page"), new URL("https://example.com/page/"));
|
|
97
|
+
* // ➔ false
|
|
98
|
+
*/
|
|
99
|
+
declare const areURLsIdentical:(urlA:URL,urlB:URL)=>boolean;type OptionsTextContainsAll={
|
|
100
|
+
/** If `true`, matches whole words only, defaultValue is `false`.
|
|
101
|
+
*
|
|
102
|
+
* @default false
|
|
103
|
+
*/
|
|
103
104
|
exactMatch?:boolean;
|
|
104
|
-
/** Optional regex flags (default: `"i"` for case-insensitive).
|
|
105
|
-
|
|
105
|
+
/** Optional regex flags (default: `"i"` for case-insensitive).
|
|
106
|
+
*
|
|
107
|
+
* @default "i"
|
|
108
|
+
*/
|
|
109
|
+
flags?:string;};
|
|
106
110
|
/** ----------------------------------------------------------
|
|
107
|
-
* * ***
|
|
108
|
-
* ----------------------------------------------------------
|
|
109
|
-
*
|
|
110
|
-
* -
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* @param {string
|
|
117
|
-
* @param {
|
|
118
|
-
* @param {
|
|
119
|
-
* @
|
|
120
|
-
*
|
|
121
|
-
* @
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
111
|
+
* * ***Predicate: `textContainsAll`.***
|
|
112
|
+
* ----------------------------------------------------------
|
|
113
|
+
* **Checks if the given `text` contains all of the specified `searchWords`.**
|
|
114
|
+
* - **Behavior:**
|
|
115
|
+
* - Returns `false` if `text` or `searchWords` is `null`/`undefined`/invalid.
|
|
116
|
+
* - Uses **regular expressions** for flexible pattern matching.
|
|
117
|
+
* - **Escapes special characters** to prevent regex injection attacks.
|
|
118
|
+
* - **Trims input** to avoid false positives with empty spaces.
|
|
119
|
+
* - **Supports exact word matching** (optional).
|
|
120
|
+
* @param {string|null|undefined} text - The string text to search within.
|
|
121
|
+
* @param {string[]|null} [searchWords] - An array of words/phrases to match against the text.
|
|
122
|
+
* @param {OptionsTextContainsAll} [options] - Optional configuration object.
|
|
123
|
+
* @param {OptionsTextContainsAll["exactMatch"]} [options.exactMatch=false] - If `true`, matches whole words only, defaultValue is `false`.
|
|
124
|
+
* @param {OptionsTextContainsAll["flags"]} [options.flags="i"] - Optional regex flags (default: `"i"` for case-insensitive).
|
|
125
|
+
* @returns {boolean} Return `true` if all `searchWords` are found in `text`, otherwise `false`.
|
|
126
|
+
* @example
|
|
127
|
+
* textContainsAll("Hello world, WithAI APP", ["Hello", "world"]);
|
|
128
|
+
* // ➔ true
|
|
129
|
+
* textContainsAll("JavaScript and TypeScript", ["Java", "Script"]);
|
|
130
|
+
* // ➔ true
|
|
131
|
+
* textContainsAll("Machine Learning", ["AI", "Learning"]);
|
|
132
|
+
* // ➔ false
|
|
133
|
+
* textContainsAll("open-source", ["open"], { exactMatch: true });
|
|
134
|
+
* // ➔ false (because options `exactMatch=true`)
|
|
135
|
+
* textContainsAll(null, ["test"]);
|
|
136
|
+
* // ➔ false (invalid text)
|
|
137
|
+
* textContainsAll("Hello", null);
|
|
138
|
+
* // ➔ false (invalid searchWords)
|
|
139
|
+
*/
|
|
140
|
+
declare const textContainsAll:<T extends string>(text?:T|null,searchWords?:T[]|string[]|null,options?:OptionsTextContainsAll)=>boolean;type OptionsTextContainsAny={
|
|
141
|
+
/** If `true`, matches whole words only, defaultValue is `false`.
|
|
142
|
+
*
|
|
143
|
+
* @default false
|
|
144
|
+
*/
|
|
129
145
|
exactMatch?:boolean;
|
|
130
|
-
/** Optional regex flags (default: `"i"` for case-insensitive).
|
|
131
|
-
|
|
146
|
+
/** Optional regex flags (default: `"i"` for case-insensitive).
|
|
147
|
+
*
|
|
148
|
+
* @default "i"
|
|
149
|
+
*/
|
|
150
|
+
flags?:string;};
|
|
151
|
+
/** ----------------------------------------------------------
|
|
152
|
+
* * ***Predicate: `textContainsAny`.***
|
|
153
|
+
* ----------------------------------------------------------
|
|
154
|
+
* **Checks if the given `text` contains at least one 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 {OptionsTextContainsAny} [options] - Optional configuration object.
|
|
164
|
+
* @param {OptionsTextContainsAny["exactMatch"]} [options.exactMatch=false] - If `true`, matches whole words only, defaultValue is `false`.
|
|
165
|
+
* @param {OptionsTextContainsAny["flags"]} [options.flags="i"] - Optional regex flags (default: `"i"` for case-insensitive).
|
|
166
|
+
* @returns {boolean} Return `true` if at least one `searchWord` is found in `text`, otherwise `false`.
|
|
167
|
+
* @example
|
|
168
|
+
* textContainsAny("Hello world", ["hello", "test"]);
|
|
169
|
+
* // ➔ true
|
|
170
|
+
* textContainsAny("withAI APP", ["chat", "ai"]);
|
|
171
|
+
* // ➔ false
|
|
172
|
+
* textContainsAny("TypeScript is great!", ["script", "java"]);
|
|
173
|
+
* // ➔ true
|
|
174
|
+
* textContainsAny("open-source", ["open"], { exactMatch: true });
|
|
175
|
+
* // ➔ false (because options `exactMatch=true`)
|
|
176
|
+
* textContainsAny(null, ["test"]);
|
|
177
|
+
* // ➔ false (invalid text)
|
|
178
|
+
* textContainsAny("Hello", null);
|
|
179
|
+
* // ➔ false (invalid searchWords)
|
|
180
|
+
*/
|
|
181
|
+
declare const textContainsAny:<T extends string>(text?:T|null,searchWords?:T[]|string[]|null,options?:OptionsTextContainsAny)=>boolean;
|
|
132
182
|
/** ----------------------------------------------------------
|
|
133
|
-
* * ***
|
|
134
|
-
* ----------------------------------------------------------
|
|
135
|
-
*
|
|
136
|
-
* -
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* @
|
|
150
|
-
* @param {
|
|
151
|
-
* @
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* doesKeyExist({ name: "John", age: 30 }, "age");
|
|
155
|
-
*
|
|
156
|
-
* doesKeyExist(
|
|
157
|
-
*
|
|
158
|
-
* doesKeyExist(
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* doesKeyExist(
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* doesKeyExist({ a:
|
|
169
|
-
* doesKeyExist({ a:
|
|
170
|
-
|
|
183
|
+
* * ***Predicate: `doesKeyExist`.***
|
|
184
|
+
* ----------------------------------------------------------
|
|
185
|
+
* **Recursively checks if a given key exists in an object or array.**
|
|
186
|
+
* - **Behavior:**
|
|
187
|
+
* - **Supports deeply nested objects and arrays**, searching recursively.
|
|
188
|
+
* - Uses `Object.prototype.hasOwnProperty.call()` to safely check if the
|
|
189
|
+
* key exists at each level, even if its value is `null` or `undefined`.
|
|
190
|
+
* - Optimized to return `true` immediately when the key is found (short-circuits).
|
|
191
|
+
* - Handles edge cases gracefully:
|
|
192
|
+
* - Returns `false` for `null`, `undefined`, or non-object inputs.
|
|
193
|
+
* - Returns `false` if key is not found anywhere, even in deeply nested
|
|
194
|
+
* structures.**
|
|
195
|
+
* - **ℹ️ Note:**
|
|
196
|
+
* - This function only checks for **the existence of the key itself**,
|
|
197
|
+
* not whether its value is non-null or non-undefined.
|
|
198
|
+
* - If you need to check for both existence and meaningful value, write a stricter function.
|
|
199
|
+
* @template T - The type of the input object or array.
|
|
200
|
+
* @param {T | Record<string, unknown> | unknown[]} object - The object or array to search.
|
|
201
|
+
* @param {PropertyKey} key - The key to look for (string, number, or symbol).
|
|
202
|
+
* @returns {boolean} Returns `true` if the key exists anywhere in the object or array (even with `null` / `undefined` value), otherwise `false`.
|
|
203
|
+
* @example
|
|
204
|
+
* doesKeyExist({ name: "John", age: 30 }, "age");
|
|
205
|
+
* // ➔ true
|
|
206
|
+
* doesKeyExist({ user: { profile: { email: "test@example.com" } } }, "email");
|
|
207
|
+
* // ➔ true
|
|
208
|
+
* doesKeyExist([{ id: 1 }, { id: 2 }], "id");
|
|
209
|
+
* // ➔ true
|
|
210
|
+
* doesKeyExist({ a: { b: { c: 10 } } }, "d");
|
|
211
|
+
* // ➔ false
|
|
212
|
+
* doesKeyExist(null, "name");
|
|
213
|
+
* // ➔ false
|
|
214
|
+
* doesKeyExist(undefined, "test");
|
|
215
|
+
* // ➔ false
|
|
216
|
+
*
|
|
217
|
+
* // Key exists even if value is null or undefined:
|
|
218
|
+
* doesKeyExist({ a: null, b: undefined, c: { d: null } }, "a"); // ➔ true
|
|
219
|
+
* doesKeyExist({ a: null, b: undefined, c: { d: null } }, "b"); // ➔ true
|
|
220
|
+
* doesKeyExist({ a: null, b: undefined, c: { d: null } }, "d"); // ➔ true
|
|
221
|
+
*
|
|
222
|
+
* doesKeyExist({ a: 1 }, true);
|
|
223
|
+
* // ➔ ❌ Throws TypeError
|
|
224
|
+
* doesKeyExist({ a: 1 }, ["not", "valid"]);
|
|
225
|
+
* // ➔ ❌ Throws TypeError
|
|
226
|
+
*/
|
|
171
227
|
declare const doesKeyExist:(object:Record<string,unknown>|unknown[],key:PropertyKey)=>boolean;
|
|
172
228
|
/** ----------------------------------------------------------
|
|
173
|
-
* * ***
|
|
174
|
-
* ----------------------------------------------------------
|
|
175
|
-
*
|
|
176
|
-
* -
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* @template T - The expected type of array elements.
|
|
182
|
-
*
|
|
183
|
-
* @param {T[]}
|
|
184
|
-
* @
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* - Comparison uses:
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* arrayHasAnyMatch(["red", "blue"], ["green", "yellow"]);
|
|
198
|
-
*
|
|
199
|
-
* arrayHasAnyMatch([], [
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
* arrayHasAnyMatch([
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* arrayHasAnyMatch([
|
|
216
|
-
|
|
217
|
-
|
|
229
|
+
* * ***Predicate: `arrayHasAnyMatch`.***
|
|
230
|
+
* ----------------------------------------------------------
|
|
231
|
+
* **Checks if at least one element from `targetArray` exists in `sourceArray`.**
|
|
232
|
+
* - **Behavior:**
|
|
233
|
+
* - Uses `Set` for **faster lookup** compared to `Array.prototype.includes()`.
|
|
234
|
+
* - Supports **any data type** (`number`, `string`, `boolean`, `object`, `array`, `function`, etc.).
|
|
235
|
+
* - Uses **reference equality** for non-primitive values (object, array, function).
|
|
236
|
+
* - Returns `false` if either array is missing, empty, or not an array.
|
|
237
|
+
* @template T - The expected type of array elements.
|
|
238
|
+
* @param {T[] | null | undefined} sourceArray - The array to search within.
|
|
239
|
+
* @param {T[] | null | undefined} targetArray - The array containing elements to match.
|
|
240
|
+
* @returns {boolean}
|
|
241
|
+
* ***Return:***
|
|
242
|
+
* - `true` if **at least one element from `targetArray` is strictly found
|
|
243
|
+
* in `sourceArray`**.
|
|
244
|
+
* - Comparison uses:
|
|
245
|
+
* - **Value equality** for primitives (`number`, `string`, `boolean`, `null`, `undefined`).
|
|
246
|
+
* - **Reference equality** for `objects`, `arrays`, and `functions`.
|
|
247
|
+
* - `false` if:
|
|
248
|
+
* - No matching elements exist,
|
|
249
|
+
* - Either array is not provided, not an actual array, or is empty.
|
|
250
|
+
* @example
|
|
251
|
+
* arrayHasAnyMatch(["apple", "banana", "cherry"], ["banana", "grape"]);
|
|
252
|
+
* // ➔ true
|
|
253
|
+
* arrayHasAnyMatch(["red", "blue"], ["green", "yellow"]);
|
|
254
|
+
* // ➔ false
|
|
255
|
+
* arrayHasAnyMatch([1, 2, 3], [3, 4, 5]);
|
|
256
|
+
* // ➔ true
|
|
257
|
+
* arrayHasAnyMatch([], ["test"]);
|
|
258
|
+
* // ➔ false
|
|
259
|
+
* arrayHasAnyMatch(["A", "B", "C"], []);
|
|
260
|
+
* // ➔ false
|
|
261
|
+
*
|
|
262
|
+
* const obj = { x: 1 };
|
|
263
|
+
* arrayHasAnyMatch([obj], [obj]);
|
|
264
|
+
* // ➔ true (same reference)
|
|
265
|
+
* arrayHasAnyMatch([{ x: 1 }], [{ x: 1 }]);
|
|
266
|
+
* // ➔ false (different reference)
|
|
267
|
+
*
|
|
268
|
+
* const fn = () => "hello";
|
|
269
|
+
* arrayHasAnyMatch([fn], [fn]);
|
|
270
|
+
* // ➔ true
|
|
271
|
+
* arrayHasAnyMatch([() => "hello"], [() => "hello"]);
|
|
272
|
+
* // ➔ false (different function reference)
|
|
273
|
+
*
|
|
274
|
+
* const arr = [1, 2];
|
|
275
|
+
* arrayHasAnyMatch([arr], [arr]);
|
|
276
|
+
* // ➔ true
|
|
277
|
+
* arrayHasAnyMatch([[1, 2]], [[1, 2]]);
|
|
278
|
+
* // ➔ false (different array object)
|
|
279
|
+
*/
|
|
280
|
+
declare const arrayHasAnyMatch:<T>(sourceArray:T[]|null|undefined,targetArray:T[]|null|undefined)=>boolean;
|
|
218
281
|
/** Restrict array indices to a fixed numeric range (1–25). */
|
|
219
282
|
type ArrayIndex=NumberRangeUnion<1,25>;
|
|
220
283
|
/** Remove `undefined` from a type. */
|
|
@@ -232,232 +295,212 @@ type IsOptionalKey<T,K extends keyof T>=Record<never,never>extends Pick<T,K>?tru
|
|
|
232
295
|
/** Returns numeric keys of an object. */
|
|
233
296
|
type NumericKeyOfHasOwnProp<Obj>=Extract<keyof Obj,number>;
|
|
234
297
|
/** Generate all nested keys of an object or array in dot/bracket notation.
|
|
235
|
-
*
|
|
236
|
-
* Example:
|
|
237
|
-
* ```ts
|
|
238
|
-
* type Keys = NestedKeyOfHasOwnProp<{ users: { name: string }[] }>
|
|
239
|
-
* // Keys = "users" | "users.[number]" | "users.[number].name"
|
|
240
|
-
* ```
|
|
241
|
-
*/
|
|
298
|
+
*
|
|
299
|
+
* Example:
|
|
300
|
+
* ```ts
|
|
301
|
+
* type Keys = NestedKeyOfHasOwnProp<{ users: { name: string }[] }>
|
|
302
|
+
* // Keys = "users" | "users.[number]" | "users.[number].name"
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
242
305
|
type NestedKeyOfHasOwnProp<T>=T extends readonly(infer U)[]?`[${number}]`|`[${number}].${NestedKeyOfHasOwnProp<U>}`:T extends object?{[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;}[keyof T &(string|number)]:never;
|
|
243
306
|
/** Apply discard rules to the last key of a path.
|
|
244
|
-
*
|
|
245
|
-
* Rules:
|
|
246
|
-
* - If discardUndefined=true -> remove `undefined` from value
|
|
247
|
-
* - If discardNull=true -> remove `null` from value
|
|
248
|
-
*
|
|
249
|
-
* Order: first strip undefined (if requested), then strip null (if requested)
|
|
250
|
-
*/
|
|
307
|
+
*
|
|
308
|
+
* Rules:
|
|
309
|
+
* - If discardUndefined=true -> remove `undefined` from value
|
|
310
|
+
* - If discardNull=true -> remove `null` from value
|
|
311
|
+
*
|
|
312
|
+
* Order: first strip undefined (if requested), then strip null (if requested)
|
|
313
|
+
*/
|
|
251
314
|
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>;
|
|
252
315
|
/** Force an array index N to type U. */
|
|
253
316
|
type RefineArrayAtIndex<T extends readonly unknown[],N extends number,U>=T &{[K in N]:U;};
|
|
254
317
|
/** Narrow object/array type based on a path string.
|
|
255
|
-
*
|
|
256
|
-
* @template T - object type to narrow
|
|
257
|
-
* @template P - path string like "user.addresses.[2].zip"
|
|
258
|
-
* @template DU - discard undefined
|
|
259
|
-
* @template DN - discard null
|
|
260
|
-
*/
|
|
318
|
+
*
|
|
319
|
+
* @template T - object type to narrow
|
|
320
|
+
* @template P - path string like "user.addresses.[2].zip"
|
|
321
|
+
* @template DU - discard undefined
|
|
322
|
+
* @template DN - discard null
|
|
323
|
+
*/
|
|
261
324
|
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?{[K in keyof T]-?:NarrowByPathHasOwnProp<EffectiveDiscardUndefined<DU>extends true?NonUndef<T[K]>:EffectiveDiscardNull<DN>extends true?NonNull<T[K]>:T[K],Rest,DU,DN>;}:EffectiveDiscardUndefined<DU>extends true?{[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];}:{[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];}:{[K in keyof T]:K extends Head?NarrowByPathHasOwnProp<NonNullable<T[K]>,Rest,DU,DN>:T[K];}&{[K in Head]-?:NarrowByPathHasOwnProp<NonNullable<T[K]>,Rest,DU,DN>;}: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?{[K in keyof T]:K extends P?ApplyLastRulesHasOwnProp<T[K],DU,DN>:T[K];}&{[K in P]-?:ApplyLastRulesHasOwnProp<T[P],DU,DN>;}:{[K in keyof T]:K extends P?ApplyLastRulesHasOwnProp<T[K],DU,DN>:T[K];}:T;
|
|
262
325
|
/** Expand an array/string/function into a nested type according to a dot/bracket path. */
|
|
263
326
|
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;type SmartDetectArrayFuncHasOwnProp<Obj extends unknown[]|AnyFunction,Key extends PropertyKey>=Prettify<Obj & DotToNestedSpecialSmartDetect<Key>&{length:number;},{recursive:false;}>;
|
|
264
327
|
/** Smartly detect nested path keys of an unknown object or function, falls-back to inferred nested structure when path is not valid. */
|
|
265
328
|
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>),{recursive:true;}>;
|
|
266
329
|
/** Convert dot/bracket path string to nested object type with leaf value.
|
|
267
|
-
* Path not found in object key → return unknown.
|
|
268
|
-
*/
|
|
330
|
+
* Path not found in object key → return unknown.
|
|
331
|
+
*/
|
|
269
332
|
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>[]:{[Key in Head]:DotToNestedSpecialSmartDetect<Rest,Value>;}:Path extends`[${number}]`?Value[]:{[Key in Path]:Value;};
|
|
270
333
|
/** Guarded wrapper for `NarrowByPathHasOwnProp` with `Prettify`. */
|
|
271
334
|
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>>,{recursive:true;}>;
|
|
272
335
|
/** Make a specific symbol key deeply required in an object symbols.
|
|
273
|
-
*
|
|
274
|
-
* Used internally to enforce stronger type narrowing.
|
|
275
|
-
*/
|
|
336
|
+
*
|
|
337
|
+
* Used internally to enforce stronger type narrowing.
|
|
338
|
+
*/
|
|
276
339
|
type DeepRequiredSymbolHasOwnProp<Obj,Sym extends symbol,DU extends boolean=true,DN extends boolean=false>=Prettify<Obj &({[K in keyof Obj & Sym as DU extends true?K:never]-?:DN extends true?NonNull<NonUndef<Obj[K]>>:NonUndef<Obj[K]>;}&{[K in keyof Obj & Sym as DU extends true?never:K]?:DN extends true?NonNull<Obj[K]>:Obj[K];}),{recursive:true;}>;
|
|
277
340
|
/** Apply discard rules to numeric keys in an object type.
|
|
278
|
-
*
|
|
279
|
-
* - If `discardUndefined = true` → undefined removed, key required
|
|
280
|
-
* - If `discardNull = true` → null removed
|
|
281
|
-
*/
|
|
341
|
+
*
|
|
342
|
+
* - If `discardUndefined = true` → undefined removed, key required
|
|
343
|
+
* - If `discardNull = true` → null removed
|
|
344
|
+
*/
|
|
282
345
|
type NumericKeyHasOwnPropMapped<Obj extends object,K extends NumericKeyOfHasOwnProp<Obj>,DU extends boolean,DN extends boolean>=Prettify<Obj &(IsOptionalKey<Obj,K>extends true?{[P in K]?:DN extends true?NonNull<Obj[K]>:Obj[K];}&(DU extends true?{[P in K]-?:NonUndef<Obj[K]>;}:Record<never,never>):{[P in K]-?:DN extends true?NonNull<Obj[K]>:Obj[K];}&(DU extends true?{[P in K]-?:NonUndef<Obj[K]>;}:Record<never,never>)),{recursive:true;}>;
|
|
283
346
|
/** Options to control `hasOwnProp` behavior. */
|
|
284
347
|
type HasOwnPropOptions<DiscardUndefined extends boolean=true,DiscardNull extends boolean=false>={
|
|
285
|
-
/**
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* **
|
|
289
|
-
*
|
|
290
|
-
* - **
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
|
|
297
|
-
* ```
|
|
298
|
-
*/
|
|
348
|
+
/** If `true` ***(default)***, properties with `undefined` values are treated as non-existent.
|
|
349
|
+
*
|
|
350
|
+
* - **Effects:**
|
|
351
|
+
* - **Runtime:** `hasOwnProp(obj, key)` returns `false` if the property exists but its value is `undefined`.
|
|
352
|
+
* - **TypeScript narrowing:** The property's type is narrowed to exclude `undefined`.
|
|
353
|
+
* - **Example:**
|
|
354
|
+
* ```ts
|
|
355
|
+
* const obj = { a: undefined, b: 123 };
|
|
356
|
+
* hasOwnProp(obj, "a"); // ➔ false
|
|
357
|
+
* hasOwnProp(obj, "a", { discardUndefined: false }); // ➔ true
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
299
360
|
discardUndefined?:DiscardUndefined;
|
|
300
|
-
/**
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
* **
|
|
304
|
-
*
|
|
305
|
-
* - **
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
|
|
312
|
-
* ```
|
|
313
|
-
*/
|
|
361
|
+
/** If `true` ***(default: `false`)***, properties with `null` values are treated as non-existent.
|
|
362
|
+
*
|
|
363
|
+
* - **Effects:**
|
|
364
|
+
* - **Runtime:** `hasOwnProp(obj, key)` returns `false` if the property exists but its value is `null`.
|
|
365
|
+
* - **TypeScript narrowing:** The property's type is narrowed to exclude `null`.
|
|
366
|
+
* - **Example:**
|
|
367
|
+
* ```ts
|
|
368
|
+
* const obj = { a: null, b: 123 };
|
|
369
|
+
* hasOwnProp(obj, "a"); // ➔ true (default discardNull = false)
|
|
370
|
+
* hasOwnProp(obj, "a", { discardNull: true }); // ➔ false
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
314
373
|
discardNull?:DiscardNull;};
|
|
315
374
|
/** -------------------------------------------------------
|
|
316
|
-
* * ***
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* -
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
* -
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
* -
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
* -
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
* ```
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
* ```
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
* }
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
|
|
445
|
-
* function fn() {}
|
|
446
|
-
* fn.extra = 123;
|
|
447
|
-
*
|
|
448
|
-
* if (hasOwnProp(fn, "extra")) {
|
|
449
|
-
* console.log(fn.extra); // ➔ 123
|
|
450
|
-
* }
|
|
451
|
-
* ```
|
|
452
|
-
*
|
|
453
|
-
* #### ❌ Empty key
|
|
454
|
-
* ```ts
|
|
455
|
-
* const obj = { a: 1 };
|
|
456
|
-
*
|
|
457
|
-
* hasOwnProp(obj, ""); // ➔ false (invalid key)
|
|
458
|
-
* hasOwnProp(obj, " "); // ➔ false (trimmed to empty)
|
|
459
|
-
* ```
|
|
460
|
-
*/
|
|
375
|
+
* * ***Utility: `hasOwnProp`.***
|
|
376
|
+
* -------------------------------------------------------
|
|
377
|
+
* **A **type-safe** replacement for `Object.prototype.hasOwnProperty` with runtime validation and **TypeScript-aware type narrowing**.**
|
|
378
|
+
* - #### Supported Targets:
|
|
379
|
+
* - **Plain objects** ➔ `{ foo: "bar" }`
|
|
380
|
+
* - **Arrays** ➔ `[ { id: 1 }, { id: 2 } ]`
|
|
381
|
+
* - **Strings** ➔ `"hello"` (as array-like objects with `.length`, index, etc.)
|
|
382
|
+
* - **Functions** ➔ callable objects with extra props
|
|
383
|
+
* - **Symbols** ➔ own property symbols
|
|
384
|
+
* - #### Key Advantages over `in` or `obj.hasOwnProperty(key)`:
|
|
385
|
+
* - Supports **dot/bracket path notation** (e.g. `"user.address.city"`, `"addresses[0].zip"`)
|
|
386
|
+
* - Handles **symbol** keys safely
|
|
387
|
+
* - **Narrows** the type of `obj` in TypeScript (stronger type safety)
|
|
388
|
+
* - Configurable handling of **`undefined`** and **`null`**
|
|
389
|
+
* - #### Runtime Behavior:
|
|
390
|
+
* - ***✅ Returns `true` if:***
|
|
391
|
+
* - `obj` is an object/array/string/function **and**
|
|
392
|
+
* - the property exists **and**
|
|
393
|
+
* - it passes the `options` checks
|
|
394
|
+
* - ***❌ Returns `false` if:***
|
|
395
|
+
* - `obj` is not a valid type
|
|
396
|
+
* - the property does not exist
|
|
397
|
+
* - the value is `undefined` and `discardUndefined: true` (default)
|
|
398
|
+
* - the value is `null` and `discardNull: true`
|
|
399
|
+
* - the `key` (after trimming) is an **empty string** ➔ treated as **invalid**
|
|
400
|
+
* - #### TypeScript Behavior:
|
|
401
|
+
* - ***Inside an `if (hasOwnProp(...)) {}` block:***
|
|
402
|
+
* - The property is **guaranteed to exist**.
|
|
403
|
+
* - Depending on `options`, the property type is narrowed to exclude
|
|
404
|
+
* `undefined` and/or `null`.
|
|
405
|
+
* - #### ⚠️ Caveats:
|
|
406
|
+
* - ***Empty keys are invalid:***
|
|
407
|
+
* - If the `key` string is empty (`""`) after trimming whitespace or other characters,
|
|
408
|
+
* it will **not** be considered a valid property and always returns `false`.
|
|
409
|
+
* - ***Arrays are limited by TypeScript inference:***
|
|
410
|
+
* - Checking index `[0]` only narrows **that specific index**, not the rest, example:
|
|
411
|
+
* 1. `hasOwnProp(users, "[0].id")` does **not** imply `users[1].id` exists.
|
|
412
|
+
* - 👉 For different indices, use **optional chaining** (`users[1]?.id`).
|
|
413
|
+
* - ***Autocomplete limitation for array indices:***
|
|
414
|
+
* - Autocompletion for `[index]` is only supported up to **25** (`[0]` ➔ `[24]`).
|
|
415
|
+
* - This limit is intentional for **performance and safety:**
|
|
416
|
+
* 1. Generating infinite union types for all possible indices would cause
|
|
417
|
+
* **TypeScript IntelliSense to hang or crash**.
|
|
418
|
+
* - ℹ️ You can still check higher indices manually (e.g. `"[999].id"`),
|
|
419
|
+
* but they will not show up in IntelliSense suggestions.
|
|
420
|
+
* - #### Options
|
|
421
|
+
* @param {HasOwnPropOptions} [options] - Optional configuration object.
|
|
422
|
+
* @param {HasOwnPropOptions["discardUndefined"]} [options.discardUndefined=true]
|
|
423
|
+
* If `true`, properties with `undefined` values are treated as **missing**, default: `true`.
|
|
424
|
+
* @param {HasOwnPropOptions["discardNull"]} [options.discardNull=false]
|
|
425
|
+
* If `true`, properties with `null` values are treated as **missing**, default: `false`.
|
|
426
|
+
* @param {*} obj - The `object`, `array`, `string`, `function`, or `other value` to check against.
|
|
427
|
+
* @param {PropertyKey} key
|
|
428
|
+
* The property key to check, can be:
|
|
429
|
+
* - `string` (supports dot/bracket paths, e.g. `"user.address.city"`, `"[0].id"`)
|
|
430
|
+
* - `number` (array-like index)
|
|
431
|
+
* - `symbol` (own property symbols)
|
|
432
|
+
* @returns {boolean} Return `true` if the property exists (and passes `options`), otherwise `false`.
|
|
433
|
+
* @example
|
|
434
|
+
*
|
|
435
|
+
* - #### ✅ Objects:
|
|
436
|
+
* ```ts
|
|
437
|
+
* const obj: { name?: string | null } = {};
|
|
438
|
+
*
|
|
439
|
+
* if (hasOwnProp(obj, "name")) {
|
|
440
|
+
* // obj is now ➔ { name: string | null }
|
|
441
|
+
* console.log(obj.name); // string | null
|
|
442
|
+
* }
|
|
443
|
+
*
|
|
444
|
+
* if (hasOwnProp(obj, "name", { discardUndefined: true, discardNull: true })) {
|
|
445
|
+
* // obj is now ➔ { name: string }
|
|
446
|
+
* console.log(obj.name.toUpperCase()); // safe
|
|
447
|
+
* }
|
|
448
|
+
* ```
|
|
449
|
+
* - #### ✅ Arrays:
|
|
450
|
+
* ```ts
|
|
451
|
+
* const users = [{ id: 1 }, { id: 2 }];
|
|
452
|
+
*
|
|
453
|
+
* if (hasOwnProp(users, "[1].id")) {
|
|
454
|
+
* // ➔ users[1].id is guaranteed to exist
|
|
455
|
+
* console.log(users[1].id); // number
|
|
456
|
+
* }
|
|
457
|
+
*
|
|
458
|
+
* // ⚠️ Caveat: narrowing only applies to checked index
|
|
459
|
+
* if (hasOwnProp(users, "[0].id")) {
|
|
460
|
+
* console.log(users[0].id); // ✅ safe
|
|
461
|
+
* console.log(users[1].id); // ❌ not guaranteed!
|
|
462
|
+
* }
|
|
463
|
+
*
|
|
464
|
+
* // 👉 Solution: optional chaining
|
|
465
|
+
* console.log(users[1]?.id); // ➔ safe, even without narrowing
|
|
466
|
+
* ```
|
|
467
|
+
*
|
|
468
|
+
* - #### ✅ Symbols:
|
|
469
|
+
* ```ts
|
|
470
|
+
* const secret = Symbol("secret");
|
|
471
|
+
* const obj2 = { [secret]: 42 };
|
|
472
|
+
*
|
|
473
|
+
* if (hasOwnProp(obj2, secret)) {
|
|
474
|
+
* console.log(obj2[secret] + 1); // ➔ 43
|
|
475
|
+
* }
|
|
476
|
+
* ```
|
|
477
|
+
* - #### ✅ Strings:
|
|
478
|
+
* ```ts
|
|
479
|
+
* if (hasOwnProp("hello", "length")) {
|
|
480
|
+
* console.log("hello".length); // ➔ 5
|
|
481
|
+
* }
|
|
482
|
+
*
|
|
483
|
+
* if (hasOwnProp("hello", 1)) {
|
|
484
|
+
* console.log("hello"[1]); // ➔ "e"
|
|
485
|
+
* }
|
|
486
|
+
* ```
|
|
487
|
+
* - #### ✅ Functions:
|
|
488
|
+
* ```ts
|
|
489
|
+
* function fn() {}
|
|
490
|
+
* fn.extra = 123;
|
|
491
|
+
*
|
|
492
|
+
* if (hasOwnProp(fn, "extra")) {
|
|
493
|
+
* console.log(fn.extra); // ➔ 123
|
|
494
|
+
* }
|
|
495
|
+
* ```
|
|
496
|
+
* - #### ❌ Empty key:
|
|
497
|
+
* ```ts
|
|
498
|
+
* const obj = { a: 1 };
|
|
499
|
+
*
|
|
500
|
+
* hasOwnProp(obj, ""); // ➔ false (invalid key)
|
|
501
|
+
* hasOwnProp(obj, " "); // ➔ false (trimmed to empty)
|
|
502
|
+
* ```
|
|
503
|
+
*/
|
|
461
504
|
declare function hasOwnProp<Obj>(obj:IsAny<Obj>extends true?Obj:never,key:PropertyKey,options?:HasOwnPropOptions<boolean,boolean>
|
|
462
505
|
/** @ts-expect-error we force `any` to `unknown` at result */
|
|
463
506
|
):obj is unknown;declare function hasOwnProp<Obj extends null|undefined>(obj:Obj,key:PropertyKey,options?:HasOwnPropOptions<boolean,boolean>):false;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>
|
|
@@ -472,1368 +515,1351 @@ declare function hasOwnProp<Obj>(obj:IsAny<Obj>extends true?Obj:never,key:Proper
|
|
|
472
515
|
/** @ts-expect-error we force to override recursive type result */
|
|
473
516
|
):obj is SmartDetectUnknownKeyHasOwnProp<Obj,Key,DiscardUndefined,DiscardNull>;
|
|
474
517
|
/** -------------------
|
|
475
|
-
* * ***Type guard: `isArguments`.***
|
|
476
|
-
* -------------------
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
* @
|
|
480
|
-
* @
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
* isArguments(
|
|
484
|
-
* // ➔
|
|
485
|
-
|
|
486
|
-
* // ➔ false
|
|
487
|
-
*/
|
|
518
|
+
* * ***Type guard: `isArguments`.***
|
|
519
|
+
* -------------------
|
|
520
|
+
* **Checks if `value` is likely an `arguments` object.**
|
|
521
|
+
* @param {*} value The value to check.
|
|
522
|
+
* @returns {boolean} Returns `true` if `value` is an ***[`IArguments`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments)*** object, else `false`.
|
|
523
|
+
* @example
|
|
524
|
+
* isArguments(function() { return arguments; }());
|
|
525
|
+
* // ➔ true
|
|
526
|
+
* isArguments([1, 2, 3]);
|
|
527
|
+
* // ➔ false
|
|
528
|
+
*/
|
|
488
529
|
declare const isArguments:(value:unknown)=>value is IArguments;
|
|
489
530
|
/** @deprecated bugs */
|
|
490
531
|
type IsArrayResult<T>=IsUnknown<T>extends true?unknown[] & T:IsNever<T>extends true?[]:IsReadonlyArray<T>extends true?T:IsArray<T>extends true?T:unknown[];
|
|
491
532
|
/** ----------------------------------------------------------
|
|
492
|
-
* * ***Type guard: `isArray`.***
|
|
493
|
-
* ----------------------------------------------------------
|
|
494
|
-
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
* @
|
|
501
|
-
* @
|
|
502
|
-
* @
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
|
|
516
|
-
*/
|
|
533
|
+
* * ***Type guard: `isArray`.***
|
|
534
|
+
* ----------------------------------------------------------
|
|
535
|
+
***Checks if a value is an ***[`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)***.**
|
|
536
|
+
* - **Behavior:**
|
|
537
|
+
* - Uses ***[`Array.isArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)*** for reliable and safe type checking.
|
|
538
|
+
* - Supports TypeScript **type narrowing** using `value is T[]`.
|
|
539
|
+
* - Handles edge cases like `null`, `undefined`, and non-array objects.
|
|
540
|
+
* @template T - The expected type of array elements.
|
|
541
|
+
* @param {*} value - The value to check.
|
|
542
|
+
* @returns {boolean} Returns `true` if the value is an `array`, otherwise `false`.
|
|
543
|
+
* @example
|
|
544
|
+
* isArray([1, 2, 3]);
|
|
545
|
+
* // ➔ true
|
|
546
|
+
* isArray([]);
|
|
547
|
+
* // ➔ true
|
|
548
|
+
* isArray("hello");
|
|
549
|
+
* // ➔ false
|
|
550
|
+
* isArray({ key: "value" });
|
|
551
|
+
* // ➔ false
|
|
552
|
+
* isArray(null);
|
|
553
|
+
* // ➔ false
|
|
554
|
+
* isArray(undefined);
|
|
555
|
+
* // ➔ false
|
|
556
|
+
*/
|
|
517
557
|
declare function isArray<T extends unknown[]>(value:T):value is Extract<T,unknown[]>;declare function isArray<T extends readonly unknown[]>(value:T):value is Extract<T,readonly unknown[]>;declare function isArray(value:unknown):value is unknown[];
|
|
518
558
|
/** ----------------------------------------------------
|
|
519
|
-
* * ***Type guard: `isArrayBuffer`.***
|
|
520
|
-
* ----------------------------------------------------
|
|
521
|
-
*
|
|
522
|
-
* @param {*} value The value to check.
|
|
523
|
-
* @returns {boolean} Returns `true` if `value` is instance of
|
|
524
|
-
* @example
|
|
525
|
-
* isArrayBuffer(new ArrayBuffer(2));
|
|
526
|
-
* // ➔ true
|
|
527
|
-
* isArrayBuffer(new Array(2));
|
|
528
|
-
* // ➔ false
|
|
529
|
-
*/
|
|
559
|
+
* * ***Type guard: `isArrayBuffer`.***
|
|
560
|
+
* ----------------------------------------------------
|
|
561
|
+
* **Checks if `value` is classified as an `ArrayBuffer` object.**
|
|
562
|
+
* @param {*} value The value to check.
|
|
563
|
+
* @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`.
|
|
564
|
+
* @example
|
|
565
|
+
* isArrayBuffer(new ArrayBuffer(2));
|
|
566
|
+
* // ➔ true
|
|
567
|
+
* isArrayBuffer(new Array(2));
|
|
568
|
+
* // ➔ false
|
|
569
|
+
*/
|
|
530
570
|
declare function isArrayBuffer(value:unknown):value is ArrayBuffer;
|
|
531
571
|
/** ----------------------------------------------------
|
|
532
|
-
* * ***Type guard: `isArrayLike`.***
|
|
533
|
-
* ----------------------------------------------------
|
|
534
|
-
*
|
|
535
|
-
* not a function and has a `value.length` that's an integer greater than or
|
|
536
|
-
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER
|
|
537
|
-
*
|
|
538
|
-
* @
|
|
539
|
-
* @
|
|
540
|
-
* @
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
|
|
550
|
-
*/
|
|
572
|
+
* * ***Type guard: `isArrayLike`.***
|
|
573
|
+
* ----------------------------------------------------
|
|
574
|
+
* **Checks if `value` is array-like, a value is considered array-like if it's
|
|
575
|
+
* not a function and has a `value.length` that's an integer greater than or
|
|
576
|
+
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.**
|
|
577
|
+
* @template T - The type of the value being checked.
|
|
578
|
+
* @param {*} value The value to check.
|
|
579
|
+
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
|
580
|
+
* @example
|
|
581
|
+
* isArrayLike([1, 2, 3]);
|
|
582
|
+
* // ➔ true
|
|
583
|
+
* isArrayLike(document.body.children);
|
|
584
|
+
* // ➔ true
|
|
585
|
+
* isArrayLike(noop);
|
|
586
|
+
* // ➔ false
|
|
587
|
+
* isArrayLike('abc');
|
|
588
|
+
* // ➔ false
|
|
589
|
+
*/
|
|
551
590
|
declare function isArrayLike<T extends{__anyHack:unknown;}>(value:T):boolean;declare function isArrayLike(value:AnyFunction|null|undefined):value is never;declare function isArrayLike(value:unknown):value is{length:number;};
|
|
552
591
|
/** ----------------------------------------------------
|
|
553
|
-
* * ***Type guard: `isArrayLikeObject`.***
|
|
554
|
-
* ----------------------------------------------------
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
* @
|
|
558
|
-
* @
|
|
559
|
-
* @
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
|
|
592
|
+
* * ***Type guard: `isArrayLikeObject`.***
|
|
593
|
+
* ----------------------------------------------------
|
|
594
|
+
* **This method is like ***{@link isArrayLike | `isArrayLike`}*** except that
|
|
595
|
+
* it also checks if `value` is an object.**
|
|
596
|
+
* @template T - The type of the value being checked.
|
|
597
|
+
* @param {*} value The value to check.
|
|
598
|
+
* @returns {boolean} Returns `true` if `value` is `array-like object`, else `false`.
|
|
599
|
+
* @example
|
|
600
|
+
* isArrayLikeObject([1, 2, 3]);
|
|
601
|
+
* // ➔ true
|
|
602
|
+
* isArrayLikeObject(document.body.children);
|
|
603
|
+
* // ➔ true
|
|
604
|
+
* isArrayLikeObject('abc');
|
|
605
|
+
* // ➔ false
|
|
606
|
+
* isArrayLikeObject(noop);
|
|
607
|
+
* // ➔ false
|
|
608
|
+
*/
|
|
569
609
|
declare function isArrayLikeObject<T extends{__anyHack:unknown;}>(value:T):boolean;declare function isArrayLikeObject(value:AnyFunction|string|boolean|number|null|undefined):value is never;declare function isArrayLikeObject(value:unknown):value is object &{length:number;};
|
|
570
610
|
/** ----------------------------------------------------------
|
|
571
|
-
* * ***Type guard: `isBigInt`.***
|
|
572
|
-
* ----------------------------------------------------------
|
|
573
|
-
*
|
|
574
|
-
* -
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
|
|
579
|
-
* @
|
|
580
|
-
* @
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
|
|
611
|
+
* * ***Type guard: `isBigInt`.***
|
|
612
|
+
* ----------------------------------------------------------
|
|
613
|
+
* **Checks if a value is of type bigint.**
|
|
614
|
+
* - **Behavior:**
|
|
615
|
+
* - Uses `typeof value === "bigint"` for strict type checking.
|
|
616
|
+
* - Supports TypeScript type narrowing with `value is bigint`.
|
|
617
|
+
* - Returns `false` for `BigInt` object (object-wrapped), e.g:
|
|
618
|
+
* - `Object(BigInt(123))`.
|
|
619
|
+
* @param {*} value - The value to check.
|
|
620
|
+
* @returns {boolean} Return `true` if value is a primitive **[`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)**.
|
|
621
|
+
* @example
|
|
622
|
+
* isBigInt(123n);
|
|
623
|
+
* // ➔ true
|
|
624
|
+
* isBigInt(BigInt(123));
|
|
625
|
+
* // ➔ true
|
|
626
|
+
* isBigInt("123");
|
|
627
|
+
* // ➔ false
|
|
628
|
+
* isBigInt(Object(BigInt(1)));
|
|
629
|
+
* // ➔ false
|
|
630
|
+
*/
|
|
590
631
|
declare const isBigInt:(value:unknown)=>value is bigint;
|
|
591
632
|
/** ----------------------------------------------------------
|
|
592
|
-
* * ***Type guard: `isBoolean`.***
|
|
593
|
-
* ----------------------------------------------------------
|
|
594
|
-
*
|
|
595
|
-
* @param {*} value - The value to check.
|
|
596
|
-
* @returns {boolean} Returns `true` if the value is a **[`boolean`](https://developer.mozilla.org/en-US/docs/Glossary/Boolean/JavaScript)**, otherwise `false`.
|
|
597
|
-
* @example
|
|
598
|
-
* isBoolean(true); // ➔ true
|
|
599
|
-
* isBoolean(false); // ➔ true
|
|
600
|
-
* isBoolean("true"); // ➔ false
|
|
601
|
-
*/
|
|
633
|
+
* * ***Type guard: `isBoolean`.***
|
|
634
|
+
* ----------------------------------------------------------
|
|
635
|
+
* **Checks if a value is of type boolean.**
|
|
636
|
+
* @param {*} value - The value to check.
|
|
637
|
+
* @returns {boolean} Returns `true` if the value is a **[`boolean`](https://developer.mozilla.org/en-US/docs/Glossary/Boolean/JavaScript)**, otherwise `false`.
|
|
638
|
+
* @example
|
|
639
|
+
* isBoolean(true); // ➔ true
|
|
640
|
+
* isBoolean(false); // ➔ true
|
|
641
|
+
* isBoolean("true"); // ➔ false
|
|
642
|
+
*/
|
|
602
643
|
declare const isBoolean:(value:unknown)=>value is boolean;
|
|
603
644
|
/** ----------------------------------------------------
|
|
604
|
-
* * ***Type guard: `isBuffer`.***
|
|
605
|
-
* ----------------------------------------------------------
|
|
606
|
-
*
|
|
607
|
-
* @param {*} value The value to check.
|
|
608
|
-
* @returns {boolean} Returns `true` if `value` is a
|
|
609
|
-
* @example
|
|
610
|
-
* isBuffer(new Buffer(2));
|
|
611
|
-
* // ➔ true
|
|
612
|
-
* isBuffer(Buffer.alloc(10));
|
|
613
|
-
* // ➔ true
|
|
614
|
-
* isBuffer(Buffer.from('foo'));
|
|
615
|
-
* // ➔ true
|
|
616
|
-
* isBuffer([]);
|
|
617
|
-
* // ➔ false
|
|
618
|
-
* isBuffer('a string');
|
|
619
|
-
* // ➔ false
|
|
620
|
-
* isBuffer(new Uint8Array(1024));
|
|
621
|
-
* // ➔ false
|
|
622
|
-
*/
|
|
645
|
+
* * ***Type guard: `isBuffer`.***
|
|
646
|
+
* ----------------------------------------------------------
|
|
647
|
+
* **Checks if a value is a **Node.js Buffer** instance.**
|
|
648
|
+
* @param {*} value The value to check.
|
|
649
|
+
* @returns {boolean} Returns `true` if `value` is a ***{@link Buffer | `Buffer`}***, else `false`.
|
|
650
|
+
* @example
|
|
651
|
+
* isBuffer(new Buffer(2));
|
|
652
|
+
* // ➔ true
|
|
653
|
+
* isBuffer(Buffer.alloc(10));
|
|
654
|
+
* // ➔ true
|
|
655
|
+
* isBuffer(Buffer.from('foo'));
|
|
656
|
+
* // ➔ true
|
|
657
|
+
* isBuffer([]);
|
|
658
|
+
* // ➔ false
|
|
659
|
+
* isBuffer('a string');
|
|
660
|
+
* // ➔ false
|
|
661
|
+
* isBuffer(new Uint8Array(1024));
|
|
662
|
+
* // ➔ false
|
|
663
|
+
*/
|
|
623
664
|
declare const isBuffer:(value:unknown)=>value is Buffer;
|
|
624
665
|
/** -----------------------------------------------------------
|
|
625
|
-
* * ***Checks whether a value looks like a currency or number string.***
|
|
626
|
-
* -----------------------------------------------------------
|
|
627
|
-
* Determines if the given `input` can be interpreted as a currency-like number,
|
|
628
|
-
* using the same **multi-locale parsing logic** as
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
*
|
|
636
|
-
* -
|
|
637
|
-
*
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
* @
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
*
|
|
649
|
-
*
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
|
|
657
|
-
* isCurrencyLike("abc");
|
|
658
|
-
* // ➔ false
|
|
659
|
-
*/
|
|
666
|
+
* * ***Checks whether a value looks like a currency or number string.***
|
|
667
|
+
* -----------------------------------------------------------
|
|
668
|
+
* **Determines if the given `input` can be interpreted as a currency-like number,
|
|
669
|
+
* using the same **multi-locale parsing logic** as ***{@link parseCurrencyString | `parseCurrencyString`}***.**
|
|
670
|
+
* - **Highlights:**
|
|
671
|
+
* - Supports strings or numbers like:
|
|
672
|
+
* - `"15.000,10"` ***(European)***.
|
|
673
|
+
* - `"15,000.10"` ***(US)***.
|
|
674
|
+
* - `"15'000.10"` ***(Swiss)***.
|
|
675
|
+
* - `"15 000,10"` ***(French)***.
|
|
676
|
+
* - `"Rp 15.000,10"` or `"$15,000.10"`.
|
|
677
|
+
* - Also accepts simple numbers (`15300.95`).
|
|
678
|
+
* - **ℹ️ Note:**
|
|
679
|
+
* - Uses the same core logic as
|
|
680
|
+
* ***{@link parseCurrencyString | `parseCurrencyString`}*** but
|
|
681
|
+
* just checks if a final parsed float is sensible.
|
|
682
|
+
* @param {*} input - The input value to check.
|
|
683
|
+
* @returns {boolean} Return `true` if it can be reasonably parsed into a currency-like number, `false` otherwise.
|
|
684
|
+
* @example
|
|
685
|
+
* isCurrencyLike(15300.95);
|
|
686
|
+
* // ➔ true
|
|
687
|
+
* isCurrencyLike("$15,000.10");
|
|
688
|
+
* // ➔ true
|
|
689
|
+
* isCurrencyLike("(15'000.10)");
|
|
690
|
+
* // ➔ true
|
|
691
|
+
* isCurrencyLike("Rp 15.000,10");
|
|
692
|
+
* // ➔ true
|
|
693
|
+
* isCurrencyLike("");
|
|
694
|
+
* // ➔ false
|
|
695
|
+
* isCurrencyLike("abc");
|
|
696
|
+
* // ➔ false
|
|
697
|
+
*/
|
|
660
698
|
declare const isCurrencyLike:(input:unknown)=>boolean;
|
|
661
699
|
/** ----------------------------------------------------------
|
|
662
|
-
* * ***Type guard: `isDate`.***
|
|
663
|
-
* ----------------------------------------------------------
|
|
664
|
-
*
|
|
665
|
-
*
|
|
666
|
-
* -
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
* @
|
|
671
|
-
* @
|
|
672
|
-
*
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
*
|
|
678
|
-
|
|
700
|
+
* * ***Type guard: `isDate`.***
|
|
701
|
+
* ----------------------------------------------------------
|
|
702
|
+
* **Determines whether the given `value` is a real, valid JavaScript
|
|
703
|
+
* **[`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)** object.**
|
|
704
|
+
* - **Behavior:**
|
|
705
|
+
* - Checks if value is an instance of `Date`.
|
|
706
|
+
* - Ensures the `date` is valid (`!isNaN(date.getTime())`).
|
|
707
|
+
* - Returns `false` for `strings` or `invalid date objects`.
|
|
708
|
+
* @param {*} value - The value to check.
|
|
709
|
+
* @returns {boolean} Return `true` if value is a valid Date object.
|
|
710
|
+
* @example
|
|
711
|
+
* isDate(new Date());
|
|
712
|
+
* // ➔ true
|
|
713
|
+
* isDate(new Date("invalid"));
|
|
714
|
+
* // ➔ false
|
|
715
|
+
* isDate("2024-01-01");
|
|
716
|
+
* // ➔ false
|
|
717
|
+
*/
|
|
679
718
|
declare const isDate:(value:unknown)=>value is Date;
|
|
680
719
|
/** ----------------------------------------------------------
|
|
681
|
-
* * ***
|
|
682
|
-
* ----------------------------------------------------------
|
|
683
|
-
*
|
|
684
|
-
* -
|
|
685
|
-
* - `
|
|
686
|
-
*
|
|
687
|
-
* -
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
*
|
|
692
|
-
|
|
693
|
-
*
|
|
694
|
-
*
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
* //
|
|
701
|
-
* isDeepEqual(
|
|
702
|
-
* // ➔
|
|
703
|
-
*
|
|
704
|
-
* //
|
|
705
|
-
* isDeepEqual(
|
|
706
|
-
* // ➔
|
|
707
|
-
*
|
|
708
|
-
* //
|
|
709
|
-
*
|
|
710
|
-
* //
|
|
711
|
-
* isDeepEqual(
|
|
712
|
-
* // ➔
|
|
713
|
-
*
|
|
714
|
-
* //
|
|
715
|
-
*
|
|
716
|
-
* //
|
|
717
|
-
* isDeepEqual(
|
|
718
|
-
* // ➔
|
|
719
|
-
*
|
|
720
|
-
* // ✅
|
|
721
|
-
* isDeepEqual(new
|
|
722
|
-
* // ➔ true
|
|
723
|
-
*
|
|
724
|
-
* // ✅
|
|
725
|
-
* isDeepEqual(new
|
|
726
|
-
* // ➔ true
|
|
727
|
-
*
|
|
728
|
-
* //
|
|
729
|
-
* isDeepEqual(1, "1
|
|
730
|
-
* // ➔
|
|
731
|
-
|
|
720
|
+
* * ***Predicate: `isDeepEqual`.***
|
|
721
|
+
* ----------------------------------------------------------
|
|
722
|
+
* **Performs a deep equality check between two values.**
|
|
723
|
+
* - **Behavior:**
|
|
724
|
+
* - Compares nested `arrays`, `objects`, `Dates`, `RegExp`, `NaN`, `Symbols`,
|
|
725
|
+
* `Set`, and `Map`.
|
|
726
|
+
* - Handles special cases:
|
|
727
|
+
* - `NaN` is considered equal to `NaN`.
|
|
728
|
+
* - `Date` objects are equal if `.getTime()` is equal.
|
|
729
|
+
* - `RegExp` objects are equal if `.toString()` is equal.
|
|
730
|
+
* - `Symbol("x")` and `Symbol("x")` are treated equal if
|
|
731
|
+
* `.toString()` matches.
|
|
732
|
+
* - `Set` and `Map` are deeply compared by content (order-insensitive).
|
|
733
|
+
* - **ℹ️ Note:**
|
|
734
|
+
* - Does not support circular references.
|
|
735
|
+
* @param {*} a - First value to compare.
|
|
736
|
+
* @param {*} b - Second value to compare.
|
|
737
|
+
* @returns {boolean} `true` if both values are deeply equal, otherwise `false`.
|
|
738
|
+
* @example
|
|
739
|
+
* // ✅ Primitives
|
|
740
|
+
* isDeepEqual(1, 1);
|
|
741
|
+
* // ➔ true
|
|
742
|
+
* isDeepEqual(NaN, NaN);
|
|
743
|
+
* // ➔ true
|
|
744
|
+
* isDeepEqual("hello", "world");
|
|
745
|
+
* // ➔ false
|
|
746
|
+
*
|
|
747
|
+
* // ✅ Objects
|
|
748
|
+
* isDeepEqual({ x: 1 }, { x: 1 });
|
|
749
|
+
* // ➔ true
|
|
750
|
+
* isDeepEqual({ x: 1 }, { y: 1 });
|
|
751
|
+
* // ➔ false
|
|
752
|
+
*
|
|
753
|
+
* // ✅ Arrays
|
|
754
|
+
* isDeepEqual([1, 2], [1, 2]);
|
|
755
|
+
* // ➔ true
|
|
756
|
+
* isDeepEqual([1, 2], [2, 1]);
|
|
757
|
+
* // ➔ false
|
|
758
|
+
*
|
|
759
|
+
* // ✅ Dates
|
|
760
|
+
* isDeepEqual(new Date(123), new Date(123));
|
|
761
|
+
* // ➔ true
|
|
762
|
+
*
|
|
763
|
+
* // ✅ Sets
|
|
764
|
+
* isDeepEqual(new Set([1, 2]), new Set([2, 1]));
|
|
765
|
+
* // ➔ true
|
|
766
|
+
*
|
|
767
|
+
* // ✅ Maps
|
|
768
|
+
* isDeepEqual(new Map([["a", 1]]), new Map([["a", 1]]));
|
|
769
|
+
* // ➔ true
|
|
770
|
+
*
|
|
771
|
+
* // ❌ Different types
|
|
772
|
+
* isDeepEqual(1, "1");
|
|
773
|
+
* // ➔ false
|
|
774
|
+
*/
|
|
732
775
|
declare const isDeepEqual:(a:unknown,b:unknown)=>boolean;
|
|
733
776
|
/** ----------------------------------------------------
|
|
734
|
-
* * ***Type guard: `isElement`.***
|
|
735
|
-
* ----------------------------------------------------------
|
|
736
|
-
*
|
|
737
|
-
*
|
|
738
|
-
* @
|
|
739
|
-
* @
|
|
740
|
-
* @
|
|
741
|
-
*
|
|
742
|
-
*
|
|
743
|
-
*
|
|
744
|
-
*
|
|
745
|
-
*
|
|
746
|
-
*
|
|
747
|
-
*
|
|
748
|
-
*
|
|
749
|
-
*
|
|
750
|
-
*
|
|
751
|
-
|
|
777
|
+
* * ***Type guard: `isElement`.***
|
|
778
|
+
* ----------------------------------------------------------
|
|
779
|
+
* **Checks if `value` is likely a
|
|
780
|
+
* **[`DOM Element`](https://developer.mozilla.org/en-US/docs/Web/API/Element)**.**
|
|
781
|
+
* @template T - The type of the value being checked.
|
|
782
|
+
* @param {*} value The value to check.
|
|
783
|
+
* @returns {boolean} Returns `true` if `value` is extends instance of **[`Element`](https://developer.mozilla.org/en-US/docs/Web/API/Element)**, else `false`.
|
|
784
|
+
* @example
|
|
785
|
+
* isElement(document.body);
|
|
786
|
+
* // ➔ true
|
|
787
|
+
* isElement(document.createElement("div"));
|
|
788
|
+
* // ➔ true
|
|
789
|
+
* isElement('<body>');
|
|
790
|
+
* // ➔ false
|
|
791
|
+
* isElement(document);
|
|
792
|
+
* // ➔ false
|
|
793
|
+
* isElement({ tagName: "DIV" });
|
|
794
|
+
* // ➔ false
|
|
795
|
+
*/
|
|
752
796
|
declare function isElement(value:[]):value is [];declare function isElement<T extends Element>(value:T):value is T;declare function isElement(value:unknown):value is Element;
|
|
753
797
|
/** ----------------------------------------------------
|
|
754
|
-
* * ***Utility: `isEmpty`.***
|
|
755
|
-
* ----------------------------------------------------------
|
|
756
|
-
*
|
|
757
|
-
* - **
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
*
|
|
763
|
-
*
|
|
764
|
-
*
|
|
765
|
-
*
|
|
766
|
-
*
|
|
767
|
-
*
|
|
768
|
-
* @
|
|
769
|
-
*
|
|
770
|
-
*
|
|
771
|
-
*
|
|
772
|
-
*
|
|
773
|
-
*
|
|
774
|
-
*
|
|
775
|
-
*
|
|
776
|
-
*
|
|
777
|
-
*
|
|
778
|
-
*
|
|
779
|
-
*
|
|
780
|
-
*
|
|
781
|
-
*
|
|
782
|
-
*
|
|
783
|
-
*
|
|
784
|
-
*
|
|
785
|
-
*
|
|
786
|
-
*
|
|
787
|
-
*
|
|
788
|
-
*
|
|
789
|
-
*
|
|
790
|
-
*
|
|
791
|
-
|
|
798
|
+
* * ***Utility: `isEmpty`.***
|
|
799
|
+
* ----------------------------------------------------------
|
|
800
|
+
* **Checks if `value` is an empty object, collection, map, or set.**
|
|
801
|
+
* - **Behavior:**
|
|
802
|
+
* - **Objects** are empty if they have no own enumerable string keyed properties.
|
|
803
|
+
* - **Array-like values** (arrays, strings, `arguments`, typed arrays, buffers)
|
|
804
|
+
* are empty if their `length` is `0`.
|
|
805
|
+
* - **Maps** and **Sets** are empty if their `size` is `0`.
|
|
806
|
+
* - **Booleans**, **numbers** (including `NaN`), **symbols**, and `null`/
|
|
807
|
+
* `undefined` are treated as empty.
|
|
808
|
+
* - **Functions** are considered empty if they have no own enumerable keys.
|
|
809
|
+
* - **ℹ️ Note:**
|
|
810
|
+
* - For more `Strict`, you can use
|
|
811
|
+
* **{@link isEmptyValue | `isEmptyValue`}** instead.
|
|
812
|
+
* @template T - The type of the value being checked.
|
|
813
|
+
* @param {*} value The value to check.
|
|
814
|
+
* @returns {boolean} Returns `true` if `value` is empty, else `false`.
|
|
815
|
+
* @example
|
|
816
|
+
* isEmpty(null);
|
|
817
|
+
* // ➔ true
|
|
818
|
+
* isEmpty(true);
|
|
819
|
+
* // ➔ true
|
|
820
|
+
* isEmpty(false);
|
|
821
|
+
* // ➔ true
|
|
822
|
+
* isEmpty(1);
|
|
823
|
+
* // ➔ true
|
|
824
|
+
* isEmpty(0);
|
|
825
|
+
* // ➔ true
|
|
826
|
+
* isEmpty(Symbol("x"));
|
|
827
|
+
* // ➔ true
|
|
828
|
+
* isEmpty(() => {});
|
|
829
|
+
* // ➔ true
|
|
830
|
+
* isEmpty("");
|
|
831
|
+
* // ➔ true
|
|
832
|
+
* isEmpty(" ");
|
|
833
|
+
* // ➔ false
|
|
834
|
+
* isEmpty([1, 2, 3]);
|
|
835
|
+
* // ➔ false
|
|
836
|
+
* isEmpty({ 'a': 1 });
|
|
837
|
+
* // ➔ false
|
|
838
|
+
*/
|
|
792
839
|
declare function isEmpty<T extends{__trapAny:any;}>(value?:T):boolean;declare function isEmpty(value:string):value is"";declare function isEmpty(value:Map<any,any>|Set<any>|List<any>|null|undefined):boolean;declare function isEmpty(value:object):boolean;declare function isEmpty<T extends object>(value:T|null|undefined):value is EmptyObjectOf<T>|null|undefined;declare function isEmpty(value:any):boolean;
|
|
793
840
|
/** ----------------------------------------------------------
|
|
794
|
-
* * ***Type guard: `isEmptyArray`.***
|
|
795
|
-
* ----------------------------------------------------------
|
|
796
|
-
*
|
|
797
|
-
* -
|
|
798
|
-
*
|
|
799
|
-
*
|
|
800
|
-
* @
|
|
801
|
-
* @
|
|
802
|
-
*
|
|
803
|
-
* isEmptyArray([]);
|
|
804
|
-
* isEmptyArray(
|
|
805
|
-
* isEmptyArray(
|
|
806
|
-
* isEmptyArray(
|
|
807
|
-
*
|
|
808
|
-
*
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
|
|
812
|
-
*/
|
|
841
|
+
* * ***Type guard: `isEmptyArray`.***
|
|
842
|
+
* ----------------------------------------------------------
|
|
843
|
+
* **Checks whether a given value is an empty array.**
|
|
844
|
+
* - **Behavior:**
|
|
845
|
+
* - Non-array inputs are considered `"empty"` ***(defensive strategy)***.
|
|
846
|
+
* @param {*} [value] - The value to check.
|
|
847
|
+
* @returns {boolean} Returns `true` if it's ***not an array*** or ***an empty-array***.
|
|
848
|
+
* @example
|
|
849
|
+
* isEmptyArray([]); // ➔ true
|
|
850
|
+
* isEmptyArray([1, 2, 3]); // ➔ false
|
|
851
|
+
* isEmptyArray("not an array"); // ➔ true
|
|
852
|
+
* isEmptyArray(null); // ➔ true
|
|
853
|
+
* isEmptyArray(undefined); // ➔ true
|
|
854
|
+
*
|
|
855
|
+
* if (isEmptyArray(data.items)) {
|
|
856
|
+
* console.log("No items to display.");
|
|
857
|
+
* }
|
|
858
|
+
*/
|
|
813
859
|
declare const isEmptyArray:(value:unknown)=>boolean;
|
|
814
860
|
/** ----------------------------------------------------------
|
|
815
|
-
* * ***Predicate: `isEmptyDeep`.***
|
|
816
|
-
* ----------------------------------------------------------
|
|
817
|
-
*
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
* -
|
|
822
|
-
* -
|
|
823
|
-
*
|
|
824
|
-
* -
|
|
825
|
-
*
|
|
826
|
-
* -
|
|
827
|
-
*
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
*
|
|
831
|
-
|
|
832
|
-
*
|
|
833
|
-
*
|
|
834
|
-
* isEmptyDeep({});
|
|
835
|
-
* // ➔ true
|
|
836
|
-
* isEmptyDeep([]);
|
|
837
|
-
* // ➔ true
|
|
838
|
-
* isEmptyDeep({ a:
|
|
839
|
-
* // ➔
|
|
840
|
-
* isEmptyDeep([
|
|
841
|
-
* // ➔
|
|
842
|
-
* isEmptyDeep(
|
|
843
|
-
* // ➔ false
|
|
844
|
-
* isEmptyDeep(
|
|
845
|
-
* // ➔
|
|
846
|
-
* isEmptyDeep(
|
|
847
|
-
* // ➔ false
|
|
848
|
-
* isEmptyDeep(
|
|
849
|
-
* // ➔ true
|
|
850
|
-
|
|
851
|
-
* // ➔ false
|
|
852
|
-
* isEmptyDeep(NaN);
|
|
853
|
-
* // ➔ true
|
|
854
|
-
*/
|
|
861
|
+
* * ***Predicate: `isEmptyDeep`.***
|
|
862
|
+
* ----------------------------------------------------------
|
|
863
|
+
* **Recursively checks whether a value is **deeply empty**.**
|
|
864
|
+
* - **Returns `true` for:**
|
|
865
|
+
* - Empty objects: `{}`
|
|
866
|
+
* - Empty arrays: `[]`
|
|
867
|
+
* - Nested empty structures: `{ a: [], b: {} }`
|
|
868
|
+
* - Falsy values (except numbers): `null`, `undefined`, `false`, `""`, `NaN`
|
|
869
|
+
* - **Returns `false` for:**
|
|
870
|
+
* - Non-zero numbers
|
|
871
|
+
* - Objects or arrays containing non-empty values
|
|
872
|
+
* - Non-empty strings, `true`, functions, symbols, etc.
|
|
873
|
+
* @param {*} value - The value to deeply check.
|
|
874
|
+
* @returns {boolean} `true` if the value is deeply empty, otherwise `false`.
|
|
875
|
+
* @example
|
|
876
|
+
* isEmptyDeep({});
|
|
877
|
+
* // ➔ true
|
|
878
|
+
* isEmptyDeep([]);
|
|
879
|
+
* // ➔ true
|
|
880
|
+
* isEmptyDeep({ a: {} });
|
|
881
|
+
* // ➔ true
|
|
882
|
+
* isEmptyDeep([[], {}]);
|
|
883
|
+
* // ➔ true
|
|
884
|
+
* isEmptyDeep({ a: [1] });
|
|
885
|
+
* // ➔ false
|
|
886
|
+
* isEmptyDeep([0]);
|
|
887
|
+
* // ➔ false
|
|
888
|
+
* isEmptyDeep("test");
|
|
889
|
+
* // ➔ false
|
|
890
|
+
* isEmptyDeep("");
|
|
891
|
+
* // ➔ true
|
|
892
|
+
* isEmptyDeep(0);
|
|
893
|
+
* // ➔ false
|
|
894
|
+
* isEmptyDeep(NaN);
|
|
895
|
+
* // ➔ true
|
|
896
|
+
*/
|
|
855
897
|
declare const isEmptyDeep:(value:unknown)=>boolean;type IsEmptyObjectOptions={
|
|
856
|
-
/** Whether to check for symbol properties in addition to string keys
|
|
857
|
-
*
|
|
858
|
-
*
|
|
859
|
-
|
|
860
|
-
* @default false
|
|
861
|
-
*/
|
|
898
|
+
/** Whether to check for symbol properties in addition to string keys, defaultValue: `true`.
|
|
899
|
+
*
|
|
900
|
+
* @default false
|
|
901
|
+
*/
|
|
862
902
|
checkSymbols?:boolean;};
|
|
863
903
|
/** ----------------------------------------------------------
|
|
864
|
-
* * ***Predicate: `isEmptyObject`.***
|
|
865
|
-
* ----------------------------------------------------------
|
|
866
|
-
*
|
|
867
|
-
* and optionally **no own enumerable symbol-key properties** when `checkSymbols` is `true
|
|
868
|
-
*
|
|
869
|
-
*
|
|
870
|
-
*
|
|
871
|
-
*
|
|
872
|
-
* @param {
|
|
873
|
-
* @param {IsEmptyObjectOptions} [options] -
|
|
874
|
-
* @
|
|
875
|
-
* @
|
|
876
|
-
*
|
|
877
|
-
*
|
|
878
|
-
*
|
|
879
|
-
*
|
|
880
|
-
*
|
|
881
|
-
*
|
|
882
|
-
*
|
|
883
|
-
*
|
|
884
|
-
*
|
|
885
|
-
*
|
|
886
|
-
*
|
|
887
|
-
*
|
|
888
|
-
*
|
|
889
|
-
*
|
|
890
|
-
*
|
|
891
|
-
*
|
|
892
|
-
|
|
893
|
-
*/
|
|
904
|
+
* * ***Predicate: `isEmptyObject`.***
|
|
905
|
+
* ----------------------------------------------------------
|
|
906
|
+
* **Checks if a value is a plain object with **no own enumerable string-key properties**,
|
|
907
|
+
* and optionally **no own enumerable symbol-key properties** when `checkSymbols` is `true`.**
|
|
908
|
+
* - **Behavior:**
|
|
909
|
+
* - If the value is **not an object** (e.g. `null`, array, primitive), it is considered empty.
|
|
910
|
+
* - If `options.checkSymbols` is `true`, **symbol properties** are also checked.
|
|
911
|
+
* @param {*} value - The value to check.
|
|
912
|
+
* @param {IsEmptyObjectOptions} [options] - Optional settings.
|
|
913
|
+
* @param {IsEmptyObjectOptions["checkSymbols"]} [options.checkSymbols=false] - Whether to also check symbol properties.
|
|
914
|
+
* @returns {boolean} Return `true` if the value is considered empty or not an object, false otherwise.
|
|
915
|
+
* @example
|
|
916
|
+
* isEmptyObject({});
|
|
917
|
+
* // ➔ true
|
|
918
|
+
* isEmptyObject({}, { checkSymbols: true });
|
|
919
|
+
* // ➔ true
|
|
920
|
+
* isEmptyObject({ a: 1 });
|
|
921
|
+
* // ➔ false
|
|
922
|
+
* isEmptyObject({ [Symbol('s')]: 1 });
|
|
923
|
+
* // ➔ true
|
|
924
|
+
* isEmptyObject({ [Symbol('s')]: 1 }, { checkSymbols: true });
|
|
925
|
+
* // ➔ false
|
|
926
|
+
* isEmptyObject(null);
|
|
927
|
+
* // ➔ true (not object)
|
|
928
|
+
* isEmptyObject([]);
|
|
929
|
+
* // ➔ true (not plain object)
|
|
930
|
+
* isEmptyObject(123);
|
|
931
|
+
* // ➔ true (not object)
|
|
932
|
+
*/
|
|
894
933
|
declare function isEmptyObject(value:unknown,options?:IsEmptyObjectOptions):boolean;type IsEmptyStringOptions={
|
|
895
|
-
/** Whether to trim the string before checking
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
*
|
|
899
|
-
* @default `true` */
|
|
934
|
+
/** Whether to trim the string before checking, defaultValue: `true`.
|
|
935
|
+
*
|
|
936
|
+
* @default `true` */
|
|
900
937
|
trim?:boolean;};
|
|
901
938
|
/** ----------------------------------------------------------
|
|
902
|
-
* * ***Predicate: `isEmptyString`.***
|
|
903
|
-
* ----------------------------------------------------------
|
|
904
|
-
*
|
|
905
|
-
*
|
|
906
|
-
*
|
|
907
|
-
*
|
|
908
|
-
*
|
|
909
|
-
* @param {*}
|
|
910
|
-
* @param {IsEmptyStringOptions
|
|
911
|
-
* @param {
|
|
912
|
-
* @returns {boolean} Returns `true` if the value is string not a string or value string is considered empty.
|
|
913
|
-
* @example
|
|
914
|
-
* isEmptyString("");
|
|
915
|
-
* // ➔ true
|
|
916
|
-
* isEmptyString(" ");
|
|
917
|
-
* // ➔ true (default trims)
|
|
918
|
-
* isEmptyString(" ", { trim: false });
|
|
919
|
-
* // ➔ false
|
|
920
|
-
* isEmptyString("hello");
|
|
921
|
-
* // ➔ false
|
|
922
|
-
* isEmptyString(undefined);
|
|
923
|
-
* // ➔ true
|
|
924
|
-
* isEmptyString(null);
|
|
925
|
-
* // ➔ true
|
|
926
|
-
* isEmptyString(123 as any);
|
|
927
|
-
* // ➔ true
|
|
928
|
-
*
|
|
929
|
-
* // Used in validation
|
|
930
|
-
* if (isEmptyString(form.name)) {
|
|
931
|
-
* throw new Error("Name cannot be empty.");
|
|
932
|
-
* }
|
|
933
|
-
*/
|
|
939
|
+
* * ***Predicate: `isEmptyString`.***
|
|
940
|
+
* ----------------------------------------------------------
|
|
941
|
+
* **Checks whether a given value is an **empty string**.**
|
|
942
|
+
* - **Behavior:**
|
|
943
|
+
* - Considers `""` and whitespace-only strings as
|
|
944
|
+
* empty (if `trim` is enabled, which is the default).
|
|
945
|
+
* - Non-string inputs are also considered empty.
|
|
946
|
+
* @param {*} value - The value to check.
|
|
947
|
+
* @param {IsEmptyStringOptions} [options] - Optional settings.
|
|
948
|
+
* @param {IsEmptyStringOptions["trim"]} [options.trim=true] - Whether to trim the string before checking, defaultValue: `true`.
|
|
949
|
+
* @returns {boolean} Returns `true` if the value is string not a string or value string is considered empty.
|
|
950
|
+
* @example
|
|
951
|
+
* isEmptyString("");
|
|
952
|
+
* // ➔ true
|
|
953
|
+
* isEmptyString(" ");
|
|
954
|
+
* // ➔ true (default trims)
|
|
955
|
+
* isEmptyString(" ", { trim: false });
|
|
956
|
+
* // ➔ false
|
|
957
|
+
* isEmptyString("hello");
|
|
958
|
+
* // ➔ false
|
|
959
|
+
* isEmptyString(undefined);
|
|
960
|
+
* // ➔ true
|
|
961
|
+
* isEmptyString(null);
|
|
962
|
+
* // ➔ true
|
|
963
|
+
* isEmptyString(123 as any);
|
|
964
|
+
* // ➔ true
|
|
965
|
+
*
|
|
966
|
+
* // Used in validation
|
|
967
|
+
* if (isEmptyString(form.name)) {
|
|
968
|
+
* throw new Error("Name cannot be empty.");
|
|
969
|
+
* }
|
|
970
|
+
*/
|
|
934
971
|
declare const isEmptyString:(value:unknown,options?:IsEmptyStringOptions)=>boolean;type IsEmptyValueOptions={
|
|
935
972
|
/** Whether to check symbol properties when checking empty objects.
|
|
936
|
-
*
|
|
937
|
-
* DefaultValue: `false`.
|
|
938
|
-
*
|
|
939
|
-
* @default false
|
|
940
|
-
*/
|
|
973
|
+
*
|
|
974
|
+
* DefaultValue: `false`.
|
|
975
|
+
*
|
|
976
|
+
* @default false
|
|
977
|
+
*/
|
|
941
978
|
checkSymbols?:boolean;};
|
|
942
979
|
/** ----------------------------------------------------------
|
|
943
|
-
* * ***Predicate: `isEmptyValue`.***
|
|
944
|
-
* ----------------------------------------------------------
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
*
|
|
949
|
-
*
|
|
950
|
-
*
|
|
951
|
-
*
|
|
952
|
-
*
|
|
953
|
-
*
|
|
954
|
-
*
|
|
955
|
-
*
|
|
956
|
-
* -
|
|
957
|
-
*
|
|
958
|
-
* @
|
|
959
|
-
* @
|
|
960
|
-
*
|
|
961
|
-
*
|
|
962
|
-
*
|
|
963
|
-
*
|
|
964
|
-
*
|
|
965
|
-
*
|
|
966
|
-
*
|
|
967
|
-
*
|
|
968
|
-
*
|
|
969
|
-
*
|
|
970
|
-
*
|
|
971
|
-
*
|
|
972
|
-
*
|
|
973
|
-
*
|
|
974
|
-
*
|
|
975
|
-
*
|
|
976
|
-
*
|
|
977
|
-
*
|
|
978
|
-
*
|
|
979
|
-
*
|
|
980
|
-
*
|
|
981
|
-
*
|
|
982
|
-
*
|
|
983
|
-
*
|
|
984
|
-
*
|
|
985
|
-
*
|
|
986
|
-
*
|
|
987
|
-
*
|
|
988
|
-
*
|
|
989
|
-
*
|
|
990
|
-
*
|
|
991
|
-
*
|
|
992
|
-
*
|
|
993
|
-
*
|
|
994
|
-
*
|
|
995
|
-
*
|
|
996
|
-
|
|
997
|
-
* isEmptyValue(() => {});
|
|
998
|
-
* // ➔ false
|
|
999
|
-
*/
|
|
980
|
+
* * ***Predicate: `isEmptyValue`.***
|
|
981
|
+
* ----------------------------------------------------------
|
|
982
|
+
* **Determines if a value is **`empty`**.**
|
|
983
|
+
* - **Covering:**
|
|
984
|
+
* - Empty objects: `{}`
|
|
985
|
+
* - Empty arrays: `[]`
|
|
986
|
+
* - Empty strings: `""` or whitespace-only (trimmed)
|
|
987
|
+
* - `null`, `undefined`, `false`, or `NaN`
|
|
988
|
+
* - **Returns **`false`** for:**
|
|
989
|
+
* - Non-empty objects/arrays
|
|
990
|
+
* - Non-empty strings
|
|
991
|
+
* - Numbers (except `NaN`)
|
|
992
|
+
* - `Functions`, `true`, `symbols`, `etc`.
|
|
993
|
+
* @param {*} value - The value to evaluate.
|
|
994
|
+
* @param {IsEmptyValueOptions} [options] - Optional settings.
|
|
995
|
+
* @returns {boolean} Return `true` if the value is considered empty, otherwise `false`.
|
|
996
|
+
* @example
|
|
997
|
+
* isEmptyValue({});
|
|
998
|
+
* // ➔ true
|
|
999
|
+
* isEmptyValue([]);
|
|
1000
|
+
* // ➔ true
|
|
1001
|
+
* isEmptyValue({ key: "value" });
|
|
1002
|
+
* // ➔ false
|
|
1003
|
+
* isEmptyValue({ [Symbol("foo")]: 123 });
|
|
1004
|
+
* // ➔ true (default `checkSymbols` is `false`)
|
|
1005
|
+
* isEmptyValue({ [Symbol("foo")]: 123 }, { checkSymbols: false });
|
|
1006
|
+
* // ➔ true (default `checkSymbols` is `false`)
|
|
1007
|
+
* isEmptyValue({ [Symbol("foo")]: 123 }, { checkSymbols: true });
|
|
1008
|
+
* // ➔ false
|
|
1009
|
+
* isEmptyValue([1, 2, 3]);
|
|
1010
|
+
* // ➔ false
|
|
1011
|
+
* isEmptyValue(NaN);
|
|
1012
|
+
* // ➔ true
|
|
1013
|
+
* isEmptyValue(true);
|
|
1014
|
+
* // ➔ false
|
|
1015
|
+
* isEmptyValue(false);
|
|
1016
|
+
* // ➔ true
|
|
1017
|
+
* isEmptyValue(null);
|
|
1018
|
+
* // ➔ true
|
|
1019
|
+
* isEmptyValue(undefined);
|
|
1020
|
+
* // ➔ true
|
|
1021
|
+
* isEmptyValue("");
|
|
1022
|
+
* // ➔ true
|
|
1023
|
+
* isEmptyValue(" ");
|
|
1024
|
+
* // ➔ true
|
|
1025
|
+
* isEmptyValue(0);
|
|
1026
|
+
* // ➔ false
|
|
1027
|
+
* isEmptyValue(-1);
|
|
1028
|
+
* // ➔ false
|
|
1029
|
+
* isEmptyValue(2);
|
|
1030
|
+
* // ➔ false
|
|
1031
|
+
* isEmptyValue(() => {});
|
|
1032
|
+
* // ➔ false
|
|
1033
|
+
*/
|
|
1000
1034
|
declare const isEmptyValue:(value:unknown,options?:IsEmptyValueOptions)=>boolean;
|
|
1001
1035
|
/** ----------------------------------------------------
|
|
1002
|
-
* * ***
|
|
1003
|
-
* ----------------------------------------------------------
|
|
1004
|
-
*
|
|
1005
|
-
*
|
|
1006
|
-
*
|
|
1007
|
-
*
|
|
1008
|
-
*
|
|
1009
|
-
*
|
|
1010
|
-
*
|
|
1011
|
-
*
|
|
1012
|
-
*
|
|
1013
|
-
*
|
|
1014
|
-
*
|
|
1015
|
-
*
|
|
1016
|
-
*
|
|
1017
|
-
*
|
|
1018
|
-
*
|
|
1019
|
-
*
|
|
1020
|
-
* @
|
|
1021
|
-
* @
|
|
1022
|
-
*
|
|
1023
|
-
*
|
|
1024
|
-
*
|
|
1025
|
-
*
|
|
1026
|
-
*
|
|
1027
|
-
*
|
|
1028
|
-
* // ➔
|
|
1029
|
-
*
|
|
1030
|
-
* // ➔
|
|
1031
|
-
* isEqual(
|
|
1032
|
-
* // ➔ true
|
|
1033
|
-
* isEqual(new
|
|
1034
|
-
* // ➔ true
|
|
1035
|
-
* isEqual(
|
|
1036
|
-
* // ➔ true
|
|
1037
|
-
* isEqual(
|
|
1038
|
-
* // ➔
|
|
1039
|
-
|
|
1040
|
-
* // ➔ false
|
|
1041
|
-
*/
|
|
1036
|
+
* * ***Predicate: `isEqual`.***
|
|
1037
|
+
* ----------------------------------------------------------
|
|
1038
|
+
* **Performs a deep comparison between two values to determine if they are equivalent.**
|
|
1039
|
+
* @description
|
|
1040
|
+
* Checks whether two values are **deeply equal**, not just reference-equal (`===`).
|
|
1041
|
+
* - **✅ This method compares:**
|
|
1042
|
+
* - Arrays and TypedArrays
|
|
1043
|
+
* - ArrayBuffers
|
|
1044
|
+
* - Plain objects (`Object`) ➔ own enumerable properties only
|
|
1045
|
+
* - Booleans, Numbers, Strings, Symbols
|
|
1046
|
+
* - Dates
|
|
1047
|
+
* - Errors
|
|
1048
|
+
* - Maps
|
|
1049
|
+
* - Sets
|
|
1050
|
+
* - Regular expressions
|
|
1051
|
+
* - ❌ `Functions` and `DOM nodes` are ***not supported***.
|
|
1052
|
+
* @param {*} value The value to compare.
|
|
1053
|
+
* @param {*} other The other value to compare.
|
|
1054
|
+
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
1055
|
+
* @example
|
|
1056
|
+
* const obj1 = { user: "fred" };
|
|
1057
|
+
* const obj2 = { user: "fred" };
|
|
1058
|
+
*
|
|
1059
|
+
* isEqual(obj1, obj2);
|
|
1060
|
+
* // ➔ true
|
|
1061
|
+
* obj1 === obj2;
|
|
1062
|
+
* // ➔ false (different references)
|
|
1063
|
+
* isEqual([1, 2, 3], [1, 2, 3]);
|
|
1064
|
+
* // ➔ true
|
|
1065
|
+
* isEqual(new Date("2020-01-01"), new Date("2020-01-01"));
|
|
1066
|
+
* // ➔ true
|
|
1067
|
+
* isEqual(new Set([1, 2]), new Set([2, 1]));
|
|
1068
|
+
* // ➔ true
|
|
1069
|
+
* isEqual(/abc/i, new RegExp("abc", "i"));
|
|
1070
|
+
* // ➔ true
|
|
1071
|
+
* isEqual({ a: 1 }, { a: 1, b: undefined });
|
|
1072
|
+
* // ➔ false
|
|
1073
|
+
*/
|
|
1042
1074
|
declare function isEqual(value:unknown,other:unknown):boolean;
|
|
1043
1075
|
/** ----------------------------------------------------
|
|
1044
|
-
* * ***
|
|
1045
|
-
* ----------------------------------------------------
|
|
1046
|
-
*
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
1049
|
-
*
|
|
1050
|
-
*
|
|
1051
|
-
*
|
|
1052
|
-
*
|
|
1053
|
-
*
|
|
1054
|
-
*
|
|
1055
|
-
*
|
|
1056
|
-
*
|
|
1057
|
-
*
|
|
1058
|
-
|
|
1059
|
-
*
|
|
1060
|
-
* @param {
|
|
1061
|
-
* @
|
|
1062
|
-
* @
|
|
1063
|
-
*
|
|
1064
|
-
*
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1067
|
-
*
|
|
1068
|
-
*
|
|
1069
|
-
*
|
|
1070
|
-
*
|
|
1071
|
-
*
|
|
1072
|
-
*
|
|
1073
|
-
*
|
|
1074
|
-
*
|
|
1075
|
-
*
|
|
1076
|
-
*
|
|
1077
|
-
*
|
|
1078
|
-
|
|
1079
|
-
|
|
1076
|
+
* * ***Predicate: `isEqualWith`.***
|
|
1077
|
+
* ----------------------------------------------------
|
|
1078
|
+
* **Performs a deep comparison between two values with support for a
|
|
1079
|
+
* customizer function.**
|
|
1080
|
+
* @description
|
|
1081
|
+
* This method is like **{@link isEqual | `isEqual`}** except that it
|
|
1082
|
+
* accepts a `customizer` which is invoked to compare values.
|
|
1083
|
+
* - **Behavior:**
|
|
1084
|
+
* - If `customizer` returns `undefined`, the comparison is handled by
|
|
1085
|
+
* the default deep equality algorithm.
|
|
1086
|
+
* - The `customizer` is invoked with up to six arguments:
|
|
1087
|
+
* - `(value, other, indexOrKey, parent, otherParent, stack)`,
|
|
1088
|
+
* see **{@link CustomizerIsEqualWith | `CustomizerIsEqualWith`}**.
|
|
1089
|
+
* - Supports comparing `arrays`, `objects`, `maps`, `sets`, `dates`,
|
|
1090
|
+
* `regexes`, `typed arrays`, `etc`.
|
|
1091
|
+
* - Functions and DOM nodes are **not** supported.
|
|
1092
|
+
* @param {*} value The value to compare.
|
|
1093
|
+
* @param {*} other The other value to compare.
|
|
1094
|
+
* @param {CustomizerIsEqualWith} [customizer] The function to customize comparisons.
|
|
1095
|
+
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
1096
|
+
* @example
|
|
1097
|
+
* function isGreeting(value: unknown) {
|
|
1098
|
+
* return typeof value === "string" && /^h(?:i|ello)$/.test(value);
|
|
1099
|
+
* }
|
|
1100
|
+
*
|
|
1101
|
+
* function customizer(objValue: unknown, othValue: unknown) {
|
|
1102
|
+
* if (isGreeting(objValue) && isGreeting(othValue)) {
|
|
1103
|
+
* return true;
|
|
1104
|
+
* }
|
|
1105
|
+
* }
|
|
1106
|
+
*
|
|
1107
|
+
* const array = ["hello", "goodbye"];
|
|
1108
|
+
* const other = ["hi", "goodbye"];
|
|
1109
|
+
*
|
|
1110
|
+
* isEqualWith(array, other, customizer);
|
|
1111
|
+
* // ➔ true
|
|
1112
|
+
*/
|
|
1113
|
+
declare function isEqualWith(value:unknown,other:unknown,customizer?:CustomizerIsEqualWith):boolean;
|
|
1080
1114
|
/** ----------------------------------------------------------
|
|
1081
|
-
* * ***Type guard: `isError`.***
|
|
1082
|
-
* ----------------------------------------------------------
|
|
1083
|
-
*
|
|
1084
|
-
*
|
|
1085
|
-
*
|
|
1086
|
-
*
|
|
1087
|
-
*
|
|
1088
|
-
* @
|
|
1089
|
-
* @
|
|
1090
|
-
*
|
|
1091
|
-
*
|
|
1092
|
-
*
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
1095
|
-
*
|
|
1096
|
-
|
|
1097
|
-
*/
|
|
1115
|
+
* * ***Type guard: `isError`.***
|
|
1116
|
+
* ----------------------------------------------------------
|
|
1117
|
+
* **Checks whether the given value is an **`Error` object**.**
|
|
1118
|
+
* - **Behavior:**
|
|
1119
|
+
* - Ensures that the provided value is a valid JavaScript error instance.
|
|
1120
|
+
* - Useful in TypeScript for narrowing types during error handling.
|
|
1121
|
+
* @param {*} error - The value to check.
|
|
1122
|
+
* @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`.
|
|
1123
|
+
* @example
|
|
1124
|
+
* isError(new Error("Something went wrong"));
|
|
1125
|
+
* // ➔ true
|
|
1126
|
+
* isError("Error message");
|
|
1127
|
+
* // ➔ false
|
|
1128
|
+
* isError(null);
|
|
1129
|
+
* // ➔ false
|
|
1130
|
+
*/
|
|
1098
1131
|
declare const isError:(error:unknown)=>error is Error;
|
|
1099
|
-
/**
|
|
1100
|
-
* * ***
|
|
1101
|
-
*
|
|
1102
|
-
*
|
|
1103
|
-
*
|
|
1104
|
-
*
|
|
1105
|
-
*
|
|
1106
|
-
* -
|
|
1107
|
-
*
|
|
1108
|
-
*
|
|
1109
|
-
*
|
|
1110
|
-
* @
|
|
1111
|
-
*
|
|
1112
|
-
* @example
|
|
1113
|
-
* import * as RzlUtilsJs from "@rzl-zone/utils-js";
|
|
1114
|
-
*
|
|
1115
|
-
* // Strict finite number check (only primitive numbers)
|
|
1116
|
-
* RzlUtilsJs.isFinite(3);
|
|
1117
|
-
* // ➔ true
|
|
1118
|
-
* RzlUtilsJs.isFinite(Number.MIN_VALUE);
|
|
1119
|
-
* // ➔ true
|
|
1120
|
-
* RzlUtilsJs.isFinite("3");
|
|
1121
|
-
* // ➔ false (string is not a number)
|
|
1122
|
-
* RzlUtilsJs.isFinite(NaN);
|
|
1123
|
-
* // ➔ false
|
|
1124
|
-
* RzlUtilsJs.isFinite(Infinity);
|
|
1125
|
-
* // ➔ false
|
|
1126
|
-
* RzlUtilsJs.isFinite(new Number(3));
|
|
1127
|
-
* // ➔ false (Number object is not primitive)
|
|
1128
|
-
*
|
|
1129
|
-
* // Comparison with global isFinite()
|
|
1130
|
-
* isFinite("3");
|
|
1131
|
-
* // ➔ true (global coerces string to number)
|
|
1132
|
-
* isFinite(new Number(3));
|
|
1133
|
-
* // ➔ true (object coerced to primitive number)
|
|
1134
|
-
*/
|
|
1132
|
+
/** ----------------------------------------------------------
|
|
1133
|
+
* * ***Type guard: `isFinite`.***
|
|
1134
|
+
* -----------------------------------------------------------
|
|
1135
|
+
* **Checks if a value is a finite primitive number.**
|
|
1136
|
+
* @description
|
|
1137
|
+
* This function verifies that `value` is a **primitive number** and is **finite**
|
|
1138
|
+
* (i.e., not `NaN`, `Infinity`, or `-Infinity`).
|
|
1139
|
+
* - **Behavior:**
|
|
1140
|
+
* - Behaves like
|
|
1141
|
+
* [`Number.isFinite()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite).
|
|
1142
|
+
* - But also works as a **TypeScript type guard**.
|
|
1143
|
+
* @param {*} value - The value to check.
|
|
1144
|
+
* @returns {boolean} Returns `true` if `value` is a finite primitive number, else `false`.
|
|
1145
|
+
* @example
|
|
1146
|
+
* import * as RzlUtilsJs from "@rzl-zone/utils-js";
|
|
1147
|
+
*
|
|
1148
|
+
* // Strict finite number check (only primitive numbers)
|
|
1149
|
+
* RzlUtilsJs.isFinite(3);
|
|
1150
|
+
* // ➔ true
|
|
1151
|
+
* RzlUtilsJs.isFinite(Number.MIN_VALUE);
|
|
1152
|
+
* // ➔ true
|
|
1153
|
+
* RzlUtilsJs.isFinite("3");
|
|
1154
|
+
* // ➔ false (string is not a number)
|
|
1155
|
+
* RzlUtilsJs.isFinite(NaN);
|
|
1156
|
+
* // ➔ false
|
|
1157
|
+
* RzlUtilsJs.isFinite(Infinity);
|
|
1158
|
+
* // ➔ false
|
|
1159
|
+
* RzlUtilsJs.isFinite(new Number(3));
|
|
1160
|
+
* // ➔ false (Number object is not primitive)
|
|
1161
|
+
*
|
|
1162
|
+
* // Comparison with global isFinite()
|
|
1163
|
+
* isFinite("3");
|
|
1164
|
+
* // ➔ true (global coerces string to number)
|
|
1165
|
+
* isFinite(new Number(3));
|
|
1166
|
+
* // ➔ true (object coerced to primitive number)
|
|
1167
|
+
*/
|
|
1135
1168
|
declare function isFinite(value:unknown):value is number;
|
|
1136
1169
|
/** ----------------------------------------------------------
|
|
1137
|
-
* * ***Type guard: `isFunction`.***
|
|
1138
|
-
*
|
|
1139
|
-
*
|
|
1140
|
-
* -
|
|
1141
|
-
*
|
|
1142
|
-
*
|
|
1143
|
-
*
|
|
1144
|
-
* @param {*} value - The value to check.
|
|
1145
|
-
* @returns {boolean} Return `true` if the value is a function.
|
|
1146
|
-
*
|
|
1147
|
-
*
|
|
1148
|
-
*
|
|
1149
|
-
*
|
|
1150
|
-
*
|
|
1151
|
-
*
|
|
1152
|
-
*
|
|
1153
|
-
*
|
|
1154
|
-
*
|
|
1155
|
-
|
|
1156
|
-
*/
|
|
1170
|
+
* * ***Type guard: `isFunction`.***
|
|
1171
|
+
* -----------------------------------------------------------
|
|
1172
|
+
* **Checks if a value is a function.**
|
|
1173
|
+
* - **Behavior:**
|
|
1174
|
+
* - Uses `typeof value === "function"` for strict type checking.
|
|
1175
|
+
* - Safe alternative to `Function` type (doesn't trigger ESLint warning).
|
|
1176
|
+
* - Supports TypeScript type narrowing with `value is (...args: any[]) => any`.
|
|
1177
|
+
* @param {*} value - The value to check.
|
|
1178
|
+
* @returns {boolean} Return `true` if the value is a function.
|
|
1179
|
+
* @example
|
|
1180
|
+
* isFunction(() => {});
|
|
1181
|
+
* // ➔ true
|
|
1182
|
+
* isFunction(async () => {});
|
|
1183
|
+
* // ➔ true
|
|
1184
|
+
* isFunction(null);
|
|
1185
|
+
* // ➔ false
|
|
1186
|
+
* isFunction({});
|
|
1187
|
+
* // ➔ false
|
|
1188
|
+
*/
|
|
1157
1189
|
declare const isFunction:(value:unknown)=>value is AnyFunction;
|
|
1158
|
-
/**
|
|
1159
|
-
* * ***Type guard: `isInteger`.***
|
|
1160
|
-
* ----------------------------------------------------------
|
|
1161
|
-
*
|
|
1162
|
-
*
|
|
1163
|
-
*
|
|
1164
|
-
*
|
|
1165
|
-
*
|
|
1166
|
-
* @
|
|
1167
|
-
* @
|
|
1168
|
-
*
|
|
1169
|
-
*
|
|
1170
|
-
*
|
|
1171
|
-
*
|
|
1172
|
-
*
|
|
1173
|
-
*
|
|
1174
|
-
*
|
|
1175
|
-
*
|
|
1176
|
-
*
|
|
1177
|
-
*
|
|
1178
|
-
*
|
|
1179
|
-
*
|
|
1180
|
-
|
|
1181
|
-
*/
|
|
1190
|
+
/** ---------------------------------------------------------
|
|
1191
|
+
* * ***Type guard: `isInteger`.***
|
|
1192
|
+
* ----------------------------------------------------------
|
|
1193
|
+
* **Checks if a value is an integer.**
|
|
1194
|
+
* - **ℹ️ Note:**
|
|
1195
|
+
* - This method is based on
|
|
1196
|
+
* [`Number.isInteger`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger).
|
|
1197
|
+
* @param {*} value The value to check.
|
|
1198
|
+
* @returns {boolean} Returns `true` if `value` is an integer, else `false`.
|
|
1199
|
+
* @example
|
|
1200
|
+
* isInteger(3);
|
|
1201
|
+
* // ➔ true
|
|
1202
|
+
* isInteger(Number.MIN_VALUE);
|
|
1203
|
+
* // ➔ false
|
|
1204
|
+
* isInteger(NaN);
|
|
1205
|
+
* // ➔ false
|
|
1206
|
+
* isInteger(Infinity);
|
|
1207
|
+
* // ➔ false
|
|
1208
|
+
* isInteger(-Infinity);
|
|
1209
|
+
* // ➔ false
|
|
1210
|
+
* isInteger('3');
|
|
1211
|
+
* // ➔ false
|
|
1212
|
+
*/
|
|
1182
1213
|
declare function isInteger(value:unknown):value is number;
|
|
1183
1214
|
/** ----------------------------------------
|
|
1184
|
-
* * ***Type guard: `isLength`.***
|
|
1185
|
-
* ----------------------------------------------------------
|
|
1186
|
-
*
|
|
1187
|
-
*
|
|
1188
|
-
*
|
|
1189
|
-
*
|
|
1190
|
-
*
|
|
1191
|
-
*
|
|
1192
|
-
*
|
|
1193
|
-
*
|
|
1194
|
-
*
|
|
1195
|
-
*
|
|
1196
|
-
*
|
|
1197
|
-
*
|
|
1198
|
-
* @
|
|
1199
|
-
*
|
|
1200
|
-
*
|
|
1201
|
-
* isLength(
|
|
1202
|
-
* // ➔ true
|
|
1203
|
-
* isLength(Number.MAX_SAFE_INTEGER);
|
|
1204
|
-
* // ➔
|
|
1205
|
-
* isLength(
|
|
1206
|
-
* // ➔ false
|
|
1207
|
-
* isLength(
|
|
1208
|
-
* // ➔ false
|
|
1209
|
-
* isLength(
|
|
1210
|
-
* // ➔ false
|
|
1211
|
-
* isLength(
|
|
1212
|
-
* // ➔ false
|
|
1213
|
-
* isLength(Infinity);
|
|
1214
|
-
* // ➔ false
|
|
1215
|
-
* isLength(
|
|
1216
|
-
* // ➔ false
|
|
1217
|
-
|
|
1218
|
-
* // ➔ false
|
|
1219
|
-
*/
|
|
1215
|
+
* * ***Type guard: `isLength`.***
|
|
1216
|
+
* ----------------------------------------------------------
|
|
1217
|
+
* **Checks whether the given value is a **valid array-like length**.**
|
|
1218
|
+
* - **Behavior:**
|
|
1219
|
+
* - ✅ Ensures the value is a **non-negative integer**.
|
|
1220
|
+
* - ✅ Ensures the value is **not greater than `Number.MAX_SAFE_INTEGER`**.
|
|
1221
|
+
* - ❌ Excludes non-numeric values, `Infinity`, and fractional numbers.
|
|
1222
|
+
* - **ℹ️ Note:**
|
|
1223
|
+
* - This method is loosely based on
|
|
1224
|
+
* - A valid length must be a non-negative integer and **not greater
|
|
1225
|
+
* than `Number.MAX_SAFE_INTEGER`**.
|
|
1226
|
+
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
|
1227
|
+
* @param {*} value The value to check.
|
|
1228
|
+
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
1229
|
+
* @example
|
|
1230
|
+
* isLength(3);
|
|
1231
|
+
* // ➔ true
|
|
1232
|
+
* isLength(Number.MAX_SAFE_INTEGER);
|
|
1233
|
+
* // ➔ true
|
|
1234
|
+
* isLength(Number.MAX_SAFE_INTEGER + 1);
|
|
1235
|
+
* // ➔ false
|
|
1236
|
+
* isLength("3");
|
|
1237
|
+
* // ➔ false
|
|
1238
|
+
* isLength(-1);
|
|
1239
|
+
* // ➔ false
|
|
1240
|
+
* isLength(3.14);
|
|
1241
|
+
* // ➔ false
|
|
1242
|
+
* isLength(Infinity);
|
|
1243
|
+
* // ➔ false
|
|
1244
|
+
* isLength(-Infinity);
|
|
1245
|
+
* // ➔ false
|
|
1246
|
+
* isLength(Number.MIN_VALUE);
|
|
1247
|
+
* // ➔ false
|
|
1248
|
+
*/
|
|
1220
1249
|
declare function isLength(value:unknown):boolean;
|
|
1221
1250
|
/** --------------------------------------------------
|
|
1222
|
-
* * ***Type guard: `isMap`.***
|
|
1223
|
-
* ----------------------------------------------------------
|
|
1224
|
-
*
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
1227
|
-
*
|
|
1228
|
-
*
|
|
1229
|
-
* @
|
|
1230
|
-
* @
|
|
1231
|
-
*
|
|
1232
|
-
*
|
|
1233
|
-
*
|
|
1234
|
-
*
|
|
1235
|
-
*
|
|
1236
|
-
*
|
|
1237
|
-
|
|
1238
|
-
*/
|
|
1251
|
+
* * ***Type guard: `isMap`.***
|
|
1252
|
+
* ----------------------------------------------------------
|
|
1253
|
+
* **Checks whether the given value is a **`Map` object**.**
|
|
1254
|
+
* - **Behavior:**
|
|
1255
|
+
* - Ensures that the provided value is an instance of **[Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)**.
|
|
1256
|
+
* - Useful in TypeScript for narrowing types when working with collections.
|
|
1257
|
+
* @param {*} value The value to check.
|
|
1258
|
+
* @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`.
|
|
1259
|
+
* @example
|
|
1260
|
+
* isMap(new Map());
|
|
1261
|
+
* // ➔ true
|
|
1262
|
+
* isMap(new WeakMap());
|
|
1263
|
+
* // ➔ false
|
|
1264
|
+
* isMap({});
|
|
1265
|
+
* // ➔ false
|
|
1266
|
+
*/
|
|
1239
1267
|
declare function isMap<K=unknown,V=unknown>(value:Map<K,V>):value is Map<K,V>;declare function isMap(value:unknown):value is Map<unknown,unknown>;
|
|
1240
1268
|
/** ----------------------------------------------------
|
|
1241
|
-
* * ***
|
|
1242
|
-
* ----------------------------------------------------
|
|
1243
|
-
*
|
|
1244
|
-
*
|
|
1245
|
-
*
|
|
1246
|
-
* -
|
|
1247
|
-
*
|
|
1248
|
-
*
|
|
1249
|
-
*
|
|
1250
|
-
* -
|
|
1251
|
-
*
|
|
1252
|
-
*
|
|
1253
|
-
*
|
|
1254
|
-
*
|
|
1255
|
-
* @param {object}
|
|
1256
|
-
* @
|
|
1257
|
-
* @
|
|
1258
|
-
*
|
|
1259
|
-
*
|
|
1260
|
-
*
|
|
1261
|
-
*
|
|
1262
|
-
*
|
|
1263
|
-
*
|
|
1264
|
-
*
|
|
1265
|
-
*
|
|
1266
|
-
|
|
1269
|
+
* * ***Predicate: `isMatch`.***
|
|
1270
|
+
* ----------------------------------------------------
|
|
1271
|
+
* **Performs a partial deep comparison between `object` and `source`.**
|
|
1272
|
+
* @description
|
|
1273
|
+
* Determines whether `object` contains equivalent property values from `source`.
|
|
1274
|
+
* - **Behavior:**
|
|
1275
|
+
* - ✅ Returns `true` if **all properties** in `source` exist in `object` and are deeply equal.
|
|
1276
|
+
* - ❌ Does **not** require `object` and `source` to be the same shape—`object` may have extra properties.
|
|
1277
|
+
* - ⚠️ Arrays are treated as objects: only matching indexed keys are compared.
|
|
1278
|
+
* - **Remarks:**
|
|
1279
|
+
* - This is functionally equivalent to a partially applied `matches(source)` predicate.
|
|
1280
|
+
* - Special cases:
|
|
1281
|
+
* - An empty array (`[]`) in `source` matches any array in `object`.
|
|
1282
|
+
* - An empty object (`{}`) in `source` matches any object in `object`.
|
|
1283
|
+
* @param {object} object - The object to inspect.
|
|
1284
|
+
* @param {object} source - The object containing property values to match.
|
|
1285
|
+
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
|
1286
|
+
* @example
|
|
1287
|
+
* const object = { a: 1, b: 2 };
|
|
1288
|
+
*
|
|
1289
|
+
* isMatch(object, { b: 2 });
|
|
1290
|
+
* // ➔ true
|
|
1291
|
+
* isMatch(object, { b: 1 });
|
|
1292
|
+
* // ➔ false
|
|
1293
|
+
* isMatch([1, 2, 3], [1, 2]);
|
|
1294
|
+
* // ➔ true (treats arrays as objects with index keys)
|
|
1295
|
+
*/
|
|
1267
1296
|
declare function isMatch(object:object,source:object):boolean;
|
|
1268
1297
|
/** ----------------------------------------------------
|
|
1269
|
-
* * ***
|
|
1270
|
-
*
|
|
1271
|
-
*
|
|
1272
|
-
*
|
|
1273
|
-
*
|
|
1274
|
-
* the
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1277
|
-
*
|
|
1278
|
-
*
|
|
1279
|
-
*
|
|
1280
|
-
*
|
|
1281
|
-
*
|
|
1282
|
-
*
|
|
1283
|
-
*
|
|
1284
|
-
* @param {
|
|
1285
|
-
* @param {
|
|
1286
|
-
* @
|
|
1287
|
-
*
|
|
1288
|
-
* @example
|
|
1289
|
-
* function isGreeting(value: unknown) {
|
|
1290
|
-
* return typeof value === 'string' && /^h(?:i|ello)$/.test(value);
|
|
1291
|
-
* }
|
|
1292
|
-
*
|
|
1293
|
-
* function customizer(objValue: unknown, srcValue: unknown) {
|
|
1294
|
-
* if (isGreeting(objValue) && isGreeting(srcValue)) {
|
|
1295
|
-
* return true;
|
|
1296
|
-
* }
|
|
1297
|
-
* }
|
|
1298
|
-
*
|
|
1299
|
-
* const object = { greeting: 'hello' };
|
|
1300
|
-
* const source = { greeting: 'hi' };
|
|
1301
|
-
*
|
|
1302
|
-
* isMatchWith(object, source, customizer);
|
|
1303
|
-
* // ➔ true
|
|
1304
|
-
*/
|
|
1305
|
-
declare function isMatchWith(value:object,other:object,customizer?:
|
|
1298
|
+
* * ***Predicate: `isMatchWith`.***
|
|
1299
|
+
* ----------------------------------------------------
|
|
1300
|
+
* **Performs a partial deep comparison between `object` and `source`, like `isMatch`, but with a `customizer` function to control comparisons.**
|
|
1301
|
+
* @description
|
|
1302
|
+
* If `customizer` returns a value other than `undefined`, that value is used
|
|
1303
|
+
* as the result of the comparison for the current property. Otherwise,
|
|
1304
|
+
* the comparison falls back to the default deep equality logic.
|
|
1305
|
+
* - **Behavior:**
|
|
1306
|
+
* - The `customizer` function is invoked with up to **five** arguments:
|
|
1307
|
+
* - `(objValue, srcValue, keyOrIndex, object, source)`,
|
|
1308
|
+
* see **{@link CustomizerIsMatchWith | `CustomizerIsMatchWith`}**.
|
|
1309
|
+
* - Returning `true` from `customizer` will short-circuit further comparison
|
|
1310
|
+
* for that key.
|
|
1311
|
+
* - Returning `false` will cause `isMatchWith` to return `false` immediately.
|
|
1312
|
+
* - Returning `undefined` allows default comparison to proceed.
|
|
1313
|
+
* @param {object} value - The object to inspect.
|
|
1314
|
+
* @param {object} other - The object of property values to match.
|
|
1315
|
+
* @param {CustomizerIsMatchWith} [customizer] - The function to customize comparisons.
|
|
1316
|
+
* @returns Returns `true` if `object` is a match, else `false`.
|
|
1317
|
+
* @example
|
|
1318
|
+
* function isGreeting(value: unknown) {
|
|
1319
|
+
* return typeof value === 'string' && /^h(?:i|ello)$/.test(value);
|
|
1320
|
+
* }
|
|
1321
|
+
*
|
|
1322
|
+
* function customizer(objValue: unknown, srcValue: unknown) {
|
|
1323
|
+
* if (isGreeting(objValue) && isGreeting(srcValue)) {
|
|
1324
|
+
* return true;
|
|
1325
|
+
* }
|
|
1326
|
+
* }
|
|
1327
|
+
*
|
|
1328
|
+
* const object = { greeting: 'hello' };
|
|
1329
|
+
* const source = { greeting: 'hi' };
|
|
1330
|
+
*
|
|
1331
|
+
* isMatchWith(object, source, customizer);
|
|
1332
|
+
* // ➔ true
|
|
1333
|
+
*/
|
|
1334
|
+
declare function isMatchWith(value:object,other:object,customizer?:CustomizerIsMatchWith):boolean;
|
|
1306
1335
|
/** ----------------------------------------------------
|
|
1307
|
-
* * ***Type guard: `isNaN`.***
|
|
1308
|
-
* ----------------------------------------------------
|
|
1309
|
-
*
|
|
1310
|
-
*
|
|
1311
|
-
*
|
|
1312
|
-
*
|
|
1313
|
-
*
|
|
1314
|
-
*
|
|
1315
|
-
*
|
|
1316
|
-
* @
|
|
1317
|
-
* @
|
|
1318
|
-
|
|
1319
|
-
*
|
|
1320
|
-
*
|
|
1321
|
-
*
|
|
1322
|
-
*
|
|
1323
|
-
*
|
|
1324
|
-
*
|
|
1325
|
-
*
|
|
1326
|
-
*
|
|
1327
|
-
*
|
|
1328
|
-
* isNaN
|
|
1329
|
-
*
|
|
1330
|
-
|
|
1336
|
+
* * ***Type guard: `isNaN`.***
|
|
1337
|
+
* ----------------------------------------------------
|
|
1338
|
+
* **Checks if a value is [`NaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN).**
|
|
1339
|
+
* - **ℹ️ Note:**
|
|
1340
|
+
* - This method is based on
|
|
1341
|
+
* [`Number.isNaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
|
|
1342
|
+
* and is **not** the same as the global
|
|
1343
|
+
* [`isNaN`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN),
|
|
1344
|
+
* which returns `true` for `undefined` and other non-number values.
|
|
1345
|
+
* @param {*} value The value to check.
|
|
1346
|
+
* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
|
|
1347
|
+
* @example
|
|
1348
|
+
* import * as RzlUtilsJs from "@rzl-zone/utils-js";
|
|
1349
|
+
*
|
|
1350
|
+
* RzlUtilsJs.isNaN(NaN);
|
|
1351
|
+
* // ➔ true
|
|
1352
|
+
* RzlUtilsJs.isNaN(new Number(NaN));
|
|
1353
|
+
* // ➔ true
|
|
1354
|
+
* RzlUtilsJs.isNaN(undefined);
|
|
1355
|
+
* // ➔ false
|
|
1356
|
+
*
|
|
1357
|
+
* // This global isNaN:
|
|
1358
|
+
* isNaN(undefined);
|
|
1359
|
+
* // ➔ true
|
|
1360
|
+
*/
|
|
1331
1361
|
declare function isNaN(value:unknown):boolean;
|
|
1332
1362
|
/** ----------------------------------------------------
|
|
1333
|
-
* * ***Type guard: `isNative`.***
|
|
1334
|
-
* ----------------------------------------------------------
|
|
1335
|
-
*
|
|
1336
|
-
*
|
|
1337
|
-
*
|
|
1338
|
-
*
|
|
1339
|
-
*
|
|
1340
|
-
*
|
|
1341
|
-
*
|
|
1342
|
-
*
|
|
1343
|
-
*
|
|
1344
|
-
*
|
|
1345
|
-
* @
|
|
1346
|
-
*
|
|
1347
|
-
*
|
|
1348
|
-
*
|
|
1349
|
-
*
|
|
1350
|
-
*
|
|
1351
|
-
*
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
* // ➔ false
|
|
1355
|
-
*/
|
|
1356
|
-
declare function isNative(value?:unknown):value is AnyFunction;
|
|
1363
|
+
* * ***Type guard: `isNative`.***
|
|
1364
|
+
* ----------------------------------------------------------
|
|
1365
|
+
* **Checks if a value is a **pristine native function**.**
|
|
1366
|
+
* - **ℹ️ Note:**
|
|
1367
|
+
* - This method may not reliably detect native functions when using packages
|
|
1368
|
+
* like `core-js`, as they override native behavior.
|
|
1369
|
+
* - Attempts to detect native functions in such environments may fail or
|
|
1370
|
+
* throw errors.
|
|
1371
|
+
* - This also affects packages like
|
|
1372
|
+
* **[`babel-polyfill`](https://www.npmjs.com/package/babel-polyfill).**
|
|
1373
|
+
* @param {*} value The value to check.
|
|
1374
|
+
* @returns {boolean} Returns `true` if `value` is a native function, else `false`.
|
|
1375
|
+
* @example
|
|
1376
|
+
* isNative(Array.prototype.push);
|
|
1377
|
+
* // ➔ true
|
|
1378
|
+
*
|
|
1379
|
+
* import * as RzlUtilsJs from "@rzl-zone/utils-js";
|
|
1380
|
+
* isNative(RzlUtilsJs);
|
|
1381
|
+
* // ➔ false
|
|
1382
|
+
*/
|
|
1383
|
+
declare function isNative(value:unknown):value is AnyFunction;
|
|
1357
1384
|
/** ----------------------------------------------------
|
|
1358
|
-
* * ***Type guard: `isNil`.***
|
|
1359
|
-
* ----------------------------------------------------------
|
|
1360
|
-
*
|
|
1361
|
-
*
|
|
1362
|
-
*
|
|
1363
|
-
* @
|
|
1364
|
-
* @
|
|
1365
|
-
*
|
|
1366
|
-
*
|
|
1367
|
-
*
|
|
1368
|
-
*
|
|
1369
|
-
*
|
|
1370
|
-
*
|
|
1371
|
-
*
|
|
1372
|
-
*
|
|
1373
|
-
|
|
1374
|
-
|
|
1385
|
+
* * ***Type guard: `isNil`.***
|
|
1386
|
+
* ----------------------------------------------------------
|
|
1387
|
+
* **Checks if a value is `null` or `undefined`.**
|
|
1388
|
+
* - **Behavior:**
|
|
1389
|
+
* - Narrows type to `null` or `undefined` when true.
|
|
1390
|
+
* @param {*} value - The value to check.
|
|
1391
|
+
* @returns {boolean} Returns `true` if the value is `null` or `undefined`, otherwise `false`.
|
|
1392
|
+
* @example
|
|
1393
|
+
* isNil(null);
|
|
1394
|
+
* // ➔ true
|
|
1395
|
+
* isNil(undefined);
|
|
1396
|
+
* // ➔ true
|
|
1397
|
+
* isNil(void 0);
|
|
1398
|
+
* // ➔ true
|
|
1399
|
+
* isNil(NaN);
|
|
1400
|
+
* // ➔ false
|
|
1401
|
+
*/
|
|
1402
|
+
declare function isNil(value:unknown):value is null|undefined;
|
|
1375
1403
|
/** ----------------------------------------------------------
|
|
1376
|
-
* * ***Type guard: `isNonEmptyArray`.***
|
|
1377
|
-
* ----------------------------------------------------------
|
|
1378
|
-
*
|
|
1379
|
-
*
|
|
1380
|
-
*
|
|
1381
|
-
*
|
|
1382
|
-
*
|
|
1383
|
-
*
|
|
1384
|
-
* @
|
|
1385
|
-
* @
|
|
1386
|
-
* @
|
|
1387
|
-
*
|
|
1388
|
-
*
|
|
1389
|
-
* isNonEmptyArray(
|
|
1390
|
-
* isNonEmptyArray(
|
|
1391
|
-
|
|
1392
|
-
* isNonEmptyArray("test"); // ➔ false
|
|
1393
|
-
*/
|
|
1404
|
+
* * ***Type guard: `isNonEmptyArray`.***
|
|
1405
|
+
* ----------------------------------------------------------
|
|
1406
|
+
* **Checks if a value is a **non-empty array**.**
|
|
1407
|
+
* - **Behavior:**
|
|
1408
|
+
* - Ensures the value is an actual array using **[`Array.isArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)**.
|
|
1409
|
+
* - Ensures the array contains at least one item.
|
|
1410
|
+
* - Narrows type to `T[]` (non-empty array) when true.
|
|
1411
|
+
* @template T - The type of the value being checked.
|
|
1412
|
+
* @param {*} value - The value to check.
|
|
1413
|
+
* @returns {boolean} Return `true` if value is a non-empty array.
|
|
1414
|
+
* @example
|
|
1415
|
+
* isNonEmptyArray([1, 2, 3]); // ➔ true
|
|
1416
|
+
* isNonEmptyArray([]); // ➔ false
|
|
1417
|
+
* isNonEmptyArray(null); // ➔ false
|
|
1418
|
+
* isNonEmptyArray("test"); // ➔ false
|
|
1419
|
+
*/
|
|
1394
1420
|
declare function isNonEmptyArray(value:[]):value is [];declare function isNonEmptyArray<T extends unknown[]>(value:T):value is NonNullable<Extract<T,unknown[]>>;declare function isNonEmptyArray(value:unknown):value is unknown[];type IsNonEmptyStringOptions={
|
|
1395
1421
|
/**
|
|
1396
|
-
* Whether to trim the string before checking.
|
|
1397
|
-
*
|
|
1398
|
-
* @default `true` */
|
|
1422
|
+
* Whether to trim the string before checking.
|
|
1423
|
+
*
|
|
1424
|
+
* @default `true` */
|
|
1399
1425
|
trim?:boolean;};
|
|
1400
1426
|
/** ----------------------------------------------------------
|
|
1401
|
-
* * ***Type guard: `isNonEmptyString`.***
|
|
1402
|
-
* ----------------------------------------------------------
|
|
1403
|
-
*
|
|
1404
|
-
*
|
|
1405
|
-
* Determines whether the given `value` is a string containing at least one non-whitespace character, with optional trimming behavior.
|
|
1406
|
-
*
|
|
1407
|
-
*
|
|
1408
|
-
*
|
|
1409
|
-
*
|
|
1410
|
-
*
|
|
1411
|
-
* @param {
|
|
1412
|
-
* @param {
|
|
1413
|
-
* @
|
|
1414
|
-
*
|
|
1415
|
-
*
|
|
1416
|
-
*
|
|
1417
|
-
*
|
|
1418
|
-
*
|
|
1419
|
-
*
|
|
1420
|
-
*
|
|
1421
|
-
*
|
|
1422
|
-
*
|
|
1423
|
-
*
|
|
1424
|
-
*
|
|
1425
|
-
*
|
|
1426
|
-
*
|
|
1427
|
-
*
|
|
1428
|
-
*
|
|
1429
|
-
*
|
|
1430
|
-
*
|
|
1431
|
-
*
|
|
1432
|
-
*
|
|
1433
|
-
|
|
1434
|
-
* isNonEmptyString([]);
|
|
1435
|
-
* // ➔ false
|
|
1436
|
-
*/
|
|
1427
|
+
* * ***Type guard: `isNonEmptyString`.***
|
|
1428
|
+
* ----------------------------------------------------------
|
|
1429
|
+
* **Checks if a value is a **non-empty string**.**
|
|
1430
|
+
* @description
|
|
1431
|
+
* Determines whether the given `value` is a string containing at least one non-whitespace character, with optional trimming behavior.
|
|
1432
|
+
* - **Behavior:**
|
|
1433
|
+
* - Ensures the value is a string using **{@link isString | `isString`}**.
|
|
1434
|
+
* - Optionally trims whitespace before checking (`trim` defaults to `true`).
|
|
1435
|
+
* - Narrows type to `string` when true.
|
|
1436
|
+
* @param {*} value - The value to test.
|
|
1437
|
+
* @param {IsNonEmptyStringOptions} [options] - Optional settings.
|
|
1438
|
+
* @param {boolean} options.trim - If `true`, trims the string before checking, defaults: `true`.
|
|
1439
|
+
* @returns {boolean} Return `true` if `value` is a non-empty string, otherwise `false`.
|
|
1440
|
+
* @example
|
|
1441
|
+
* isNonEmptyString("hello");
|
|
1442
|
+
* // ➔ true
|
|
1443
|
+
* isNonEmptyString(" ", { trim: true });
|
|
1444
|
+
* // ➔ false
|
|
1445
|
+
* isNonEmptyString(" ", { trim: false });
|
|
1446
|
+
* // ➔ true
|
|
1447
|
+
* isNonEmptyString("");
|
|
1448
|
+
* // ➔ false
|
|
1449
|
+
* isNonEmptyString(123);
|
|
1450
|
+
* // ➔ false
|
|
1451
|
+
* isNonEmptyString(undefined);
|
|
1452
|
+
* // ➔ false
|
|
1453
|
+
* isNonEmptyString(null);
|
|
1454
|
+
* // ➔ false
|
|
1455
|
+
* isNonEmptyString({});
|
|
1456
|
+
* // ➔ false
|
|
1457
|
+
* isNonEmptyString([]);
|
|
1458
|
+
* // ➔ false
|
|
1459
|
+
*/
|
|
1437
1460
|
declare const isNonEmptyString:(value:unknown,options?:IsNonEmptyStringOptions)=>value is string;type IsNonEmptyValueOptions={
|
|
1438
|
-
/**
|
|
1439
|
-
*
|
|
1440
|
-
* @default false
|
|
1441
|
-
*/
|
|
1461
|
+
/** Whether to check symbol properties when checking empty objects, default: `false`.
|
|
1462
|
+
*
|
|
1463
|
+
* @default false
|
|
1464
|
+
*/
|
|
1442
1465
|
checkSymbols?:boolean;};
|
|
1443
1466
|
/** ----------------------------------------------------------
|
|
1444
|
-
* * ***
|
|
1445
|
-
*
|
|
1446
|
-
*
|
|
1447
|
-
*
|
|
1448
|
-
*
|
|
1449
|
-
*
|
|
1450
|
-
*
|
|
1451
|
-
*
|
|
1452
|
-
*
|
|
1453
|
-
*
|
|
1454
|
-
*
|
|
1455
|
-
*
|
|
1456
|
-
|
|
1457
|
-
*
|
|
1458
|
-
*
|
|
1459
|
-
*
|
|
1460
|
-
*
|
|
1461
|
-
*
|
|
1462
|
-
*
|
|
1463
|
-
*
|
|
1464
|
-
*
|
|
1465
|
-
*
|
|
1466
|
-
*
|
|
1467
|
-
* isNonEmptyValue({
|
|
1468
|
-
* // ➔ false
|
|
1469
|
-
* isNonEmptyValue(
|
|
1470
|
-
* // ➔ false
|
|
1471
|
-
* isNonEmptyValue({
|
|
1472
|
-
* // ➔ true
|
|
1473
|
-
* isNonEmptyValue([
|
|
1474
|
-
* // ➔
|
|
1475
|
-
* isNonEmptyValue(
|
|
1476
|
-
* // ➔ false
|
|
1477
|
-
* isNonEmptyValue(true);
|
|
1478
|
-
* // ➔ true
|
|
1479
|
-
* isNonEmptyValue(
|
|
1480
|
-
* // ➔
|
|
1481
|
-
* isNonEmptyValue(
|
|
1482
|
-
* // ➔ false
|
|
1483
|
-
* isNonEmptyValue(
|
|
1484
|
-
* // ➔
|
|
1485
|
-
* isNonEmptyValue(
|
|
1486
|
-
* // ➔ false
|
|
1487
|
-
* isNonEmptyValue(
|
|
1488
|
-
* // ➔ false
|
|
1489
|
-
* isNonEmptyValue(
|
|
1490
|
-
* // ➔
|
|
1491
|
-
* isNonEmptyValue(
|
|
1492
|
-
* // ➔
|
|
1493
|
-
* isNonEmptyValue(
|
|
1494
|
-
* // ➔
|
|
1495
|
-
* isNonEmptyValue(
|
|
1496
|
-
* // ➔ true
|
|
1497
|
-
|
|
1467
|
+
* * ***Predicated: `isNonEmptyValue`.***
|
|
1468
|
+
* ----------------------------------------------------------
|
|
1469
|
+
* **Determines if a value is a **non-empty** object (`{}` with props), **non-empty** array (`[]` with items) or generally truthy.**
|
|
1470
|
+
* - **Behavior:**
|
|
1471
|
+
* - Returns `true` for:
|
|
1472
|
+
* - Objects **with properties**
|
|
1473
|
+
* - Arrays **with items**
|
|
1474
|
+
* - Non-empty, non-whitespace strings
|
|
1475
|
+
* - Numbers (except `NaN`, includes `0`)
|
|
1476
|
+
* - Functions
|
|
1477
|
+
* - `true`
|
|
1478
|
+
* - Returns `false` for:
|
|
1479
|
+
* - Empty objects (`{}`)
|
|
1480
|
+
* - Empty arrays (`[]`)
|
|
1481
|
+
* - `null` or `undefined`
|
|
1482
|
+
* - Empty strings (`""`) or whitespace-only strings (`" "`)
|
|
1483
|
+
* - `false`
|
|
1484
|
+
* - `NaN`
|
|
1485
|
+
* - Safely handles `null`, `undefined`, and non-object types without throwing.
|
|
1486
|
+
* @param {*} value - The value to evaluate.
|
|
1487
|
+
* @param {IsNonEmptyValueOptions} [options] - Optional settings.
|
|
1488
|
+
* @returns {boolean} Return `true` if the value is considered non-empty/truthy, otherwise `false`.
|
|
1489
|
+
* @example
|
|
1490
|
+
* isNonEmptyValue({});
|
|
1491
|
+
* // ➔ false
|
|
1492
|
+
* isNonEmptyValue([]);
|
|
1493
|
+
* // ➔ false
|
|
1494
|
+
* isNonEmptyValue({ key: "value" });
|
|
1495
|
+
* // ➔ true
|
|
1496
|
+
* isNonEmptyValue({ [Symbol("foo")]: 123 });
|
|
1497
|
+
* // ➔ false (default `checkSymbols` is `false`)
|
|
1498
|
+
* isNonEmptyValue({ [Symbol("foo")]: 123 }, { checkSymbols: false });
|
|
1499
|
+
* // ➔ false (default `checkSymbols` is `false`)
|
|
1500
|
+
* isNonEmptyValue({ [Symbol("foo")]: 123 }, { checkSymbols: true });
|
|
1501
|
+
* // ➔ true
|
|
1502
|
+
* isNonEmptyValue([1, 2, 3]);
|
|
1503
|
+
* // ➔ true
|
|
1504
|
+
* isNonEmptyValue(NaN);
|
|
1505
|
+
* // ➔ false
|
|
1506
|
+
* isNonEmptyValue(true);
|
|
1507
|
+
* // ➔ true
|
|
1508
|
+
* isNonEmptyValue(false);
|
|
1509
|
+
* // ➔ false
|
|
1510
|
+
* isNonEmptyValue(null);
|
|
1511
|
+
* // ➔ false
|
|
1512
|
+
* isNonEmptyValue(undefined);
|
|
1513
|
+
* // ➔ false
|
|
1514
|
+
* isNonEmptyValue("");
|
|
1515
|
+
* // ➔ false
|
|
1516
|
+
* isNonEmptyValue(" ");
|
|
1517
|
+
* // ➔ false
|
|
1518
|
+
* isNonEmptyValue(0);
|
|
1519
|
+
* // ➔ true
|
|
1520
|
+
* isNonEmptyValue(-1);
|
|
1521
|
+
* // ➔ true
|
|
1522
|
+
* isNonEmptyValue(2);
|
|
1523
|
+
* // ➔ true
|
|
1524
|
+
* isNonEmptyValue(() => {});
|
|
1525
|
+
* // ➔ true
|
|
1526
|
+
*/
|
|
1498
1527
|
declare const isNonEmptyValue:(value:unknown,options?:IsNonEmptyValueOptions)=>boolean;
|
|
1499
1528
|
/** ---------------------------------------------------------
|
|
1500
|
-
* * ***Type guard: `isNull`.***
|
|
1501
|
-
* ----------------------------------------------------------
|
|
1502
|
-
*
|
|
1503
|
-
*
|
|
1504
|
-
*
|
|
1505
|
-
*
|
|
1506
|
-
*
|
|
1507
|
-
* @
|
|
1508
|
-
* @
|
|
1509
|
-
*
|
|
1510
|
-
*
|
|
1511
|
-
* isNull(
|
|
1512
|
-
|
|
1513
|
-
* isNull(undefined); // ➔ false
|
|
1514
|
-
*/
|
|
1529
|
+
* * ***Type guard: `isNull`.***
|
|
1530
|
+
* ----------------------------------------------------------
|
|
1531
|
+
* **Checks if a value is **[`null`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/null)**.**
|
|
1532
|
+
* - **Behavior:**
|
|
1533
|
+
* - Narrows type to `null` when true.
|
|
1534
|
+
* - Strictly compares the value against `null`.
|
|
1535
|
+
* @param {*} val - The value to check.
|
|
1536
|
+
* @returns {boolean} Returns `true` if the value is `null`, otherwise `false`.
|
|
1537
|
+
* @example
|
|
1538
|
+
* isNull(null); // ➔ true
|
|
1539
|
+
* isNull(0); // ➔ false
|
|
1540
|
+
* isNull(undefined); // ➔ false
|
|
1541
|
+
*/
|
|
1515
1542
|
declare const isNull:(val:unknown)=>val is null;type HasKeys$1<T>=keyof T extends never?false:true;type IsObject<T>=unknown extends T?T & Record<PropertyKey,unknown>:T extends object?T extends AnObjectNonArray?T:HasKeys$1<T>extends false?T & Record<PropertyKey,unknown>:IsArray<T>extends true?Exclude<T,unknown[]>:T:never;
|
|
1516
1543
|
/** ---------------------------------------------------------
|
|
1517
|
-
* * ***Type guard: `isObject`.***
|
|
1518
|
-
* ----------------------------------------------------------
|
|
1519
|
-
*
|
|
1520
|
-
*
|
|
1521
|
-
*
|
|
1522
|
-
*
|
|
1523
|
-
* -
|
|
1524
|
-
* -
|
|
1525
|
-
* -
|
|
1526
|
-
* -
|
|
1527
|
-
* -
|
|
1528
|
-
*
|
|
1529
|
-
* -
|
|
1530
|
-
*
|
|
1531
|
-
*
|
|
1532
|
-
* - `
|
|
1533
|
-
* -
|
|
1534
|
-
* -
|
|
1535
|
-
*
|
|
1536
|
-
* -
|
|
1537
|
-
*
|
|
1538
|
-
*
|
|
1539
|
-
*
|
|
1540
|
-
*
|
|
1541
|
-
*
|
|
1542
|
-
|
|
1543
|
-
*
|
|
1544
|
-
*
|
|
1545
|
-
*
|
|
1546
|
-
* isObject(
|
|
1547
|
-
* isObject(
|
|
1548
|
-
* isObject(
|
|
1549
|
-
* isObject(
|
|
1550
|
-
* isObject(
|
|
1551
|
-
* isObject(
|
|
1552
|
-
|
|
1553
|
-
* isObject(null); // ➔ false
|
|
1554
|
-
* isObject(undefined); // ➔ false
|
|
1555
|
-
* isObject(123); // ➔ false
|
|
1556
|
-
* isObject(() => {}); // ➔ false
|
|
1557
|
-
*/
|
|
1544
|
+
* * ***Type guard: `isObject`.***
|
|
1545
|
+
* ----------------------------------------------------------
|
|
1546
|
+
* **Checks if a value is an **object** (excluding `null` and `arrays`).**
|
|
1547
|
+
* - **✅ Returns `true` for any non-null object (arrays excluded), including:**
|
|
1548
|
+
* - Plain-objects (`{}`, `Object.create(null)`)
|
|
1549
|
+
* - Custom class instances
|
|
1550
|
+
* - Built-ins: `Date`, `RegExp`, `Error`, `URL`, `URLSearchParams`
|
|
1551
|
+
* - Collections: `Map`, `Set`, `WeakMap`, `WeakSet`
|
|
1552
|
+
* - Binary/typed data: `ArrayBuffer`, `DataView`, typed arrays (`Uint8Array`, `Int32Array`, etc.)
|
|
1553
|
+
* - DOM/Node objects: `HTMLElement`, `DocumentFragment`, etc.
|
|
1554
|
+
* - Proxies (wrapping any object type)
|
|
1555
|
+
* - **❌ Returns `false` for:**
|
|
1556
|
+
* - `null`
|
|
1557
|
+
* - Arrays (`[]`, `new Array()`)
|
|
1558
|
+
* - Functions (regular functions, arrow functions, class constructors)
|
|
1559
|
+
* - Primitives: `string`, `number`, `boolean`, `symbol`, `bigint`
|
|
1560
|
+
* - Boxed primitives: `new String()`, `new Number()`, `new Boolean()`
|
|
1561
|
+
* - `undefined` (including `NaN`, which is a primitive number)
|
|
1562
|
+
* - **ℹ️ Note:**
|
|
1563
|
+
* - If you specifically need to check for ***plain-objects***, use **{@link isPlainObject}** instead.
|
|
1564
|
+
* @template T - The type of the value being checked.
|
|
1565
|
+
* @param {*} value - The value to check.
|
|
1566
|
+
* @returns {boolean} Returns `true` if the value is a ***plain-objects***, otherwise `false`.
|
|
1567
|
+
* @example
|
|
1568
|
+
* isObject({}); // ➔ true
|
|
1569
|
+
* isObject(Object.create(null)); // ➔ true
|
|
1570
|
+
* isObject(new Date()); // ➔ true
|
|
1571
|
+
* isObject(new Map()); // ➔ true
|
|
1572
|
+
* isObject(new Uint8Array()); // ➔ true
|
|
1573
|
+
* isObject(new String("x")); // ➔ true
|
|
1574
|
+
* isObject([]); // ➔ false
|
|
1575
|
+
* isObject(null); // ➔ false
|
|
1576
|
+
* isObject(undefined); // ➔ false
|
|
1577
|
+
* isObject(123); // ➔ false
|
|
1578
|
+
* isObject(() => {}); // ➔ false
|
|
1579
|
+
*/
|
|
1558
1580
|
declare function isObject<T extends object>(value:T):value is IsObject<T>;declare function isObject(value:unknown):value is Record<PropertyKey,unknown>;
|
|
1559
1581
|
/** ----------------------------------------------------------
|
|
1560
|
-
* * ***Type guard: `isObjectLoose`.***
|
|
1561
|
-
* ----------------------------------------------------------
|
|
1562
|
-
*
|
|
1563
|
-
*
|
|
1564
|
-
*
|
|
1565
|
-
*
|
|
1566
|
-
*
|
|
1567
|
-
* -
|
|
1568
|
-
* -
|
|
1569
|
-
* -
|
|
1570
|
-
*
|
|
1571
|
-
*
|
|
1572
|
-
* - `new
|
|
1573
|
-
*
|
|
1574
|
-
*
|
|
1575
|
-
*
|
|
1576
|
-
*
|
|
1577
|
-
*
|
|
1578
|
-
*
|
|
1579
|
-
*
|
|
1580
|
-
* - `
|
|
1581
|
-
* - `
|
|
1582
|
-
*
|
|
1583
|
-
*
|
|
1584
|
-
*
|
|
1585
|
-
*
|
|
1586
|
-
* @
|
|
1587
|
-
*
|
|
1588
|
-
*
|
|
1589
|
-
|
|
1590
|
-
*
|
|
1591
|
-
*
|
|
1592
|
-
* isObjectLoose({});
|
|
1593
|
-
* // ➔ true
|
|
1594
|
-
* isObjectLoose(
|
|
1595
|
-
* // ➔
|
|
1596
|
-
* isObjectLoose(
|
|
1597
|
-
* // ➔
|
|
1598
|
-
|
|
1599
|
-
* // ➔ false
|
|
1600
|
-
* isObjectLoose(undefined);
|
|
1601
|
-
* // ➔ false
|
|
1602
|
-
*/
|
|
1582
|
+
* * ***Type guard: `isObjectLoose`.***
|
|
1583
|
+
* ----------------------------------------------------------
|
|
1584
|
+
* **Checks if a value is the
|
|
1585
|
+
* [ECMAScript language type **Object**](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types).**
|
|
1586
|
+
* - **✅ Returns `true` for:**
|
|
1587
|
+
* - Plain objects (`{}`)
|
|
1588
|
+
* - Arrays (`[]`)
|
|
1589
|
+
* - Functions
|
|
1590
|
+
* - Regexes (`/abc/`)
|
|
1591
|
+
* - Boxed primitives:
|
|
1592
|
+
* - `new Number(0)`
|
|
1593
|
+
* - `new String("")`
|
|
1594
|
+
* - `new Boolean(false)`
|
|
1595
|
+
* - **❌ Returns `false` for:**
|
|
1596
|
+
* - `null`
|
|
1597
|
+
* - `undefined`
|
|
1598
|
+
* - Primitives:
|
|
1599
|
+
* - `string`
|
|
1600
|
+
* - `number`
|
|
1601
|
+
* - `boolean`
|
|
1602
|
+
* - `symbol`
|
|
1603
|
+
* - `bigint`
|
|
1604
|
+
* - **ℹ️ Note:**
|
|
1605
|
+
* - **For More Strict Object Use {@link isObject} or {@link isPlainObject} instead.**
|
|
1606
|
+
* @template T - The type of the value being checked.
|
|
1607
|
+
* @param {*} value The value to check.
|
|
1608
|
+
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
1609
|
+
* @example
|
|
1610
|
+
* isObjectLoose({});
|
|
1611
|
+
* // ➔ true
|
|
1612
|
+
* isObjectLoose([1, 2, 3]);
|
|
1613
|
+
* // ➔ true
|
|
1614
|
+
* isObjectLoose(()=> {});
|
|
1615
|
+
* // ➔ true
|
|
1616
|
+
* isObjectLoose(null);
|
|
1617
|
+
* // ➔ false
|
|
1618
|
+
* isObjectLoose(undefined);
|
|
1619
|
+
* // ➔ false
|
|
1620
|
+
*/
|
|
1603
1621
|
declare function isObjectLoose<T=object>(value:unknown):value is T;type HasKeys<T>=keyof T extends never?false:true;type IsObjectOrArray<T>=OrArr<[ IsNever<T>,Extends<T,Record<PropertyKey,unknown>>,Extends<unknown,T>]>extends true?T & Record<PropertyKey,unknown>& unknown[]:T extends object?T extends unknown[]?T:T extends AnObjectNonArray?T:HasKeys<T>extends false?T & Record<PropertyKey,unknown>:T:Extract<T,Record<PropertyKey,unknown>& unknown[]>;
|
|
1604
1622
|
/** ---------------------------------------------------------
|
|
1605
|
-
* * ***Type guard: `isObjectOrArray`.***
|
|
1606
|
-
* ----------------------------------------------------------
|
|
1607
|
-
*
|
|
1608
|
-
*
|
|
1609
|
-
*
|
|
1610
|
-
*
|
|
1611
|
-
* -
|
|
1612
|
-
*
|
|
1613
|
-
* -
|
|
1614
|
-
*
|
|
1615
|
-
*
|
|
1616
|
-
*
|
|
1617
|
-
*
|
|
1618
|
-
*
|
|
1619
|
-
* - `
|
|
1620
|
-
* - `
|
|
1621
|
-
*
|
|
1622
|
-
*
|
|
1623
|
-
*
|
|
1624
|
-
*
|
|
1625
|
-
*
|
|
1626
|
-
*
|
|
1627
|
-
|
|
1628
|
-
*
|
|
1629
|
-
*
|
|
1630
|
-
*
|
|
1631
|
-
|
|
1632
|
-
* isObjectOrArray([1,2,3]); // ➔ true
|
|
1633
|
-
* isObjectOrArray(null); // ➔ false
|
|
1634
|
-
* isObjectOrArray(undefined); // ➔ false
|
|
1635
|
-
* isObjectOrArray("hello"); // ➔ false
|
|
1636
|
-
*/
|
|
1623
|
+
* * ***Type guard: `isObjectOrArray`.***
|
|
1624
|
+
* ----------------------------------------------------------
|
|
1625
|
+
* **Checks if a value is an **object** or an **array**.**
|
|
1626
|
+
* - **✅ Returns `true` for:**
|
|
1627
|
+
* - Plain objects (`{}`, `Object.create(null)`)
|
|
1628
|
+
* - Custom objects
|
|
1629
|
+
* - Arrays (`[]`, `[1,2,3]`)
|
|
1630
|
+
* - **❌ Returns `false` for:**
|
|
1631
|
+
* - `null`
|
|
1632
|
+
* - `undefined`
|
|
1633
|
+
* - Primitives:
|
|
1634
|
+
* - `string`
|
|
1635
|
+
* - `number`
|
|
1636
|
+
* - `boolean`
|
|
1637
|
+
* - `symbol`
|
|
1638
|
+
* - `bigint`
|
|
1639
|
+
* - Functions
|
|
1640
|
+
* @template T - The type of the value being checked.
|
|
1641
|
+
* @param {*} value - The value to check.
|
|
1642
|
+
* @returns {boolean} Returns `true` if the value is an `object` or `array`.
|
|
1643
|
+
* @example
|
|
1644
|
+
* isObjectOrArray({ name: "Alice" }); // ➔ true
|
|
1645
|
+
* isObjectOrArray([1,2,3]); // ➔ true
|
|
1646
|
+
* isObjectOrArray(null); // ➔ false
|
|
1647
|
+
* isObjectOrArray(undefined); // ➔ false
|
|
1648
|
+
* isObjectOrArray("hello"); // ➔ false
|
|
1649
|
+
*/
|
|
1637
1650
|
declare function isObjectOrArray(value:[]):value is [];declare function isObjectOrArray<T>(value:T):value is IsObjectOrArray<T>;
|
|
1638
1651
|
/** ----------------------------------------------------------
|
|
1639
|
-
* * ***Type guard: `
|
|
1640
|
-
* ----------------------------------------------------------
|
|
1641
|
-
*
|
|
1642
|
-
*
|
|
1643
|
-
|
|
1644
|
-
*
|
|
1645
|
-
*
|
|
1646
|
-
*
|
|
1647
|
-
*
|
|
1648
|
-
*
|
|
1649
|
-
*
|
|
1650
|
-
|
|
1652
|
+
* * ***Type guard: `PropertyKey`.***
|
|
1653
|
+
* ----------------------------------------------------------
|
|
1654
|
+
* **Checks if a value is a valid `PropertyKey`.**
|
|
1655
|
+
* - **In JavaScript/TypeScript, a **`PropertyKey`** is any of:**
|
|
1656
|
+
* - **`string`**
|
|
1657
|
+
* - **`number`**
|
|
1658
|
+
* - **`symbol`**
|
|
1659
|
+
* - **This function ensures the given `value` is one of these types.**
|
|
1660
|
+
* - Narrows type to {@link PropertyKey | ***`PropertyKey`***} when true.
|
|
1661
|
+
* - Useful for working with dynamic object keys.
|
|
1662
|
+
* - Strictly rejects `null`, `undefined`, `boolean`, `object`, `function`, etc.
|
|
1663
|
+
* @param {*} value - The value to check.
|
|
1664
|
+
* @returns {boolean} Return `true` if `value` is a valid property key, otherwise `false`.
|
|
1665
|
+
* @example
|
|
1666
|
+
* isPropertyKey("foo");
|
|
1667
|
+
* // ➔ true
|
|
1668
|
+
* isPropertyKey(123);
|
|
1669
|
+
* // ➔ true
|
|
1670
|
+
* isPropertyKey(Symbol("id"));
|
|
1671
|
+
* // ➔ true
|
|
1672
|
+
* isPropertyKey({});
|
|
1673
|
+
* // ➔ false
|
|
1674
|
+
* isPropertyKey(null);
|
|
1675
|
+
* // ➔ false
|
|
1676
|
+
*/
|
|
1677
|
+
declare function isPropertyKey(value:unknown):value is PropertyKey;
|
|
1678
|
+
/** ----------------------------------------------------------
|
|
1679
|
+
* * ***Type guard: `isRegExp`.***
|
|
1680
|
+
* ----------------------------------------------------------
|
|
1681
|
+
* **Checks if a value is a RegExp instance.**
|
|
1682
|
+
* @param {*} value - The value to check.
|
|
1683
|
+
* @returns {boolean} Return `true` if value is an instance of **[RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)**.
|
|
1684
|
+
* @example
|
|
1685
|
+
* isRegExp(/abc/); // ➔ true
|
|
1686
|
+
* isRegExp(new RegExp("abc")); // ➔ true
|
|
1687
|
+
* isRegExp("abc"); // ➔ false
|
|
1688
|
+
*/
|
|
1651
1689
|
declare const isRegExp:(value:unknown)=>value is RegExp;
|
|
1652
1690
|
/** --------------------------------------------------
|
|
1653
|
-
* * ***
|
|
1654
|
-
* --------------------------------------------------
|
|
1655
|
-
*
|
|
1656
|
-
* -
|
|
1657
|
-
*
|
|
1658
|
-
* -
|
|
1659
|
-
*
|
|
1660
|
-
*
|
|
1661
|
-
*
|
|
1662
|
-
|
|
1663
|
-
*
|
|
1664
|
-
* @
|
|
1665
|
-
*
|
|
1666
|
-
*
|
|
1667
|
-
* isSafeInteger(
|
|
1668
|
-
* // ➔
|
|
1669
|
-
* isSafeInteger(
|
|
1670
|
-
* // ➔ false
|
|
1671
|
-
* isSafeInteger(
|
|
1672
|
-
* // ➔ false
|
|
1673
|
-
|
|
1691
|
+
* * ***Type guard: `isSafeInteger`.***
|
|
1692
|
+
* --------------------------------------------------
|
|
1693
|
+
* **Checks if `value` is a **[`Safe-Integer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)**.**
|
|
1694
|
+
* - **Behavior:**
|
|
1695
|
+
* - Narrows type to `number` when true.
|
|
1696
|
+
* - **An integer is considered *safe* if:**
|
|
1697
|
+
* - It is an `IEEE-754` **double precision number**.
|
|
1698
|
+
* - It can be exactly represented without rounding errors.
|
|
1699
|
+
* - It lies within the range **-(2^53 - 1) to 2^53 - 1**.
|
|
1700
|
+
* - **Note:**
|
|
1701
|
+
* - This method is based on **{@link Number.isSafeInteger}**.
|
|
1702
|
+
* @param {*} value - The value to check.
|
|
1703
|
+
* @returns {boolean} Return `true` if `value` is a safe integer, otherwise `false`.
|
|
1704
|
+
* @example
|
|
1705
|
+
* isSafeInteger(3);
|
|
1706
|
+
* // ➔ true
|
|
1707
|
+
* isSafeInteger(Number.MIN_VALUE);
|
|
1708
|
+
* // ➔ false
|
|
1709
|
+
* isSafeInteger(Infinity);
|
|
1710
|
+
* // ➔ false
|
|
1711
|
+
* isSafeInteger('3');
|
|
1712
|
+
* // ➔ false
|
|
1713
|
+
*/
|
|
1674
1714
|
declare function isSafeInteger(value:unknown):value is number;
|
|
1675
1715
|
/** ---------------------------------------------------------
|
|
1676
|
-
* * ***Type guard: `isSet`.***
|
|
1677
|
-
* ----------------------------------------------------------
|
|
1678
|
-
*
|
|
1679
|
-
*
|
|
1680
|
-
*
|
|
1681
|
-
*
|
|
1682
|
-
*
|
|
1683
|
-
* @
|
|
1684
|
-
* @
|
|
1685
|
-
* @
|
|
1686
|
-
*
|
|
1687
|
-
*
|
|
1688
|
-
*
|
|
1689
|
-
*
|
|
1690
|
-
|
|
1691
|
-
*/
|
|
1716
|
+
* * ***Type guard: `isSet`.***
|
|
1717
|
+
* ----------------------------------------------------------
|
|
1718
|
+
* **Checks if a value is a **[`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/Set)** object.**
|
|
1719
|
+
* - **Behavior:**
|
|
1720
|
+
* - Narrows type to `Set<T>` when true.
|
|
1721
|
+
* - Excludes `WeakSet`, arrays, plain objects, and other non-Set values.
|
|
1722
|
+
* @template T - The type of the value being checked.
|
|
1723
|
+
* @param {*} value - The value to check.
|
|
1724
|
+
* @returns {boolean} Returns `true` if the value is a `Set`, otherwise `false`.
|
|
1725
|
+
* @example
|
|
1726
|
+
* isSet(new Set);
|
|
1727
|
+
* // ➔ true
|
|
1728
|
+
* isSet(new WeakSet);
|
|
1729
|
+
* // ➔ false
|
|
1730
|
+
*/
|
|
1692
1731
|
declare function isSet<T=unknown>(value:Set<T>):value is Set<T>;declare function isSet(value:unknown):value is Set<unknown>;
|
|
1693
1732
|
/** ---------------------------------------------------------
|
|
1694
|
-
* * ***Type guard: `isString`.***
|
|
1695
|
-
* ----------------------------------------------------------
|
|
1696
|
-
*
|
|
1697
|
-
* **[`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
|
|
1698
|
-
*
|
|
1699
|
-
*
|
|
1700
|
-
*
|
|
1701
|
-
*
|
|
1702
|
-
* @
|
|
1703
|
-
* @
|
|
1704
|
-
*
|
|
1705
|
-
*
|
|
1706
|
-
*
|
|
1707
|
-
*
|
|
1708
|
-
*
|
|
1709
|
-
*
|
|
1710
|
-
*
|
|
1711
|
-
*
|
|
1712
|
-
*
|
|
1713
|
-
|
|
1714
|
-
* }
|
|
1715
|
-
*/
|
|
1733
|
+
* * ***Type guard: `isString`.***
|
|
1734
|
+
* ----------------------------------------------------------
|
|
1735
|
+
* **Checks if a value is of type
|
|
1736
|
+
* **[`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**.**
|
|
1737
|
+
* - **Behavior:**
|
|
1738
|
+
* - Narrows type to `string` when true.
|
|
1739
|
+
* - Uses the `typeof` operator for strict checking.
|
|
1740
|
+
* @param {*} value - The value to check.
|
|
1741
|
+
* @returns {boolean} Returns `true` if the value is a string, otherwise `false`.
|
|
1742
|
+
* @example
|
|
1743
|
+
* isString("hello"); // ➔ true
|
|
1744
|
+
* isString(123); // ➔ false
|
|
1745
|
+
*
|
|
1746
|
+
* // Usage in type narrowing
|
|
1747
|
+
* const value: unknown = getValue();
|
|
1748
|
+
* if (isString(value)) {
|
|
1749
|
+
* // TypeScript now knows `value` is a string
|
|
1750
|
+
* console.log(value.toUpperCase());
|
|
1751
|
+
* }
|
|
1752
|
+
*/
|
|
1716
1753
|
declare const isString:(value:unknown)=>value is string;
|
|
1717
1754
|
/** ----------------------------------------------------------
|
|
1718
|
-
* * ***Type guard: `isSymbol`.***
|
|
1719
|
-
* ----------------------------------------------------------
|
|
1720
|
-
*
|
|
1721
|
-
* **[`symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/Symbol)
|
|
1722
|
-
*
|
|
1723
|
-
*
|
|
1724
|
-
*
|
|
1725
|
-
*
|
|
1726
|
-
* @
|
|
1727
|
-
* @
|
|
1728
|
-
*
|
|
1729
|
-
*
|
|
1730
|
-
* isSymbol(
|
|
1731
|
-
* isSymbol(
|
|
1732
|
-
|
|
1733
|
-
* isSymbol(undefined); // ➔ false
|
|
1734
|
-
*/
|
|
1755
|
+
* * ***Type guard: `isSymbol`.***
|
|
1756
|
+
* ----------------------------------------------------------
|
|
1757
|
+
* **Checks if a value is of type
|
|
1758
|
+
* **[`symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/Symbol)**.**
|
|
1759
|
+
* - **Behavior:**
|
|
1760
|
+
* - Narrows type to `symbol` when true.
|
|
1761
|
+
* - Uses the `typeof` operator for strict checking.
|
|
1762
|
+
* @param {*} value - The value to check.
|
|
1763
|
+
* @returns {boolean} Returns `true` if the value is a symbol, otherwise `false`.
|
|
1764
|
+
* @example
|
|
1765
|
+
* isSymbol(Symbol("id")); // ➔ true
|
|
1766
|
+
* isSymbol("not a symbol"); // ➔ false
|
|
1767
|
+
* isSymbol(123); // ➔ false
|
|
1768
|
+
* isSymbol(undefined); // ➔ false
|
|
1769
|
+
*/
|
|
1735
1770
|
declare const isSymbol:(value:unknown)=>value is symbol;
|
|
1736
1771
|
/** --------------------------------------------------
|
|
1737
|
-
* * ***Type guard: `isTypedArray`.***
|
|
1738
|
-
* ----------------------------------------------------------
|
|
1739
|
-
*
|
|
1740
|
-
* **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
|
|
1741
|
-
*
|
|
1742
|
-
*
|
|
1743
|
-
*
|
|
1744
|
-
*
|
|
1745
|
-
*
|
|
1746
|
-
* @
|
|
1747
|
-
* @
|
|
1748
|
-
*
|
|
1749
|
-
* isTypedArray(new Uint8Array);
|
|
1750
|
-
* isTypedArray(new
|
|
1751
|
-
* isTypedArray(new
|
|
1752
|
-
* isTypedArray(
|
|
1753
|
-
* isTypedArray(
|
|
1754
|
-
|
|
1755
|
-
*/
|
|
1772
|
+
* * ***Type guard: `isTypedArray`.***
|
|
1773
|
+
* ----------------------------------------------------------
|
|
1774
|
+
* **Checks if `value` is classified as a
|
|
1775
|
+
* **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)**.**
|
|
1776
|
+
* - **Behavior:**
|
|
1777
|
+
* - Validates that `value` is a non-null object.
|
|
1778
|
+
* - Uses `Object.prototype.toString` tag matching against known typed array tags.
|
|
1779
|
+
* - Narrows type to **{@link TypedArray}** when true.
|
|
1780
|
+
* @param {*} value - The value to check.
|
|
1781
|
+
* @returns {boolean} Returns `true` if the value is a typed array, otherwise `false`.
|
|
1782
|
+
* @example
|
|
1783
|
+
* isTypedArray(new Uint8Array); // ➔ true
|
|
1784
|
+
* isTypedArray(new Uint8Array()); // ➔ true
|
|
1785
|
+
* isTypedArray(new Float32Array()); // ➔ true
|
|
1786
|
+
* isTypedArray(new Uint8ClampedArray()); // ➔ true
|
|
1787
|
+
* isTypedArray([]); // ➔ false
|
|
1788
|
+
* isTypedArray(Buffer.from("hi")); // ➔ false
|
|
1789
|
+
*/
|
|
1756
1790
|
declare function isTypedArray(value:unknown):value is TypedArray;
|
|
1757
1791
|
/** ---------------------------------------------------------
|
|
1758
|
-
* * ***Type guard: `isURL`.***
|
|
1759
|
-
* ----------------------------------------------------------
|
|
1760
|
-
*
|
|
1761
|
-
* **[`URL`](https://developer.mozilla.org/docs/Web/API/URL)** class
|
|
1762
|
-
*
|
|
1763
|
-
*
|
|
1764
|
-
*
|
|
1765
|
-
*
|
|
1766
|
-
* @
|
|
1767
|
-
* @
|
|
1768
|
-
*
|
|
1769
|
-
*
|
|
1770
|
-
* isURL(
|
|
1771
|
-
* // ➔
|
|
1772
|
-
|
|
1773
|
-
* // ➔ false
|
|
1774
|
-
*/
|
|
1792
|
+
* * ***Type guard: `isURL`.***
|
|
1793
|
+
* ----------------------------------------------------------
|
|
1794
|
+
* **Checks if a value is an instance of the
|
|
1795
|
+
* **[`URL`](https://developer.mozilla.org/docs/Web/API/URL)** class.**
|
|
1796
|
+
* - **Behavior:**
|
|
1797
|
+
* - Narrows type to `URL` when true.
|
|
1798
|
+
* - Excludes `strings`, `plain-objects`, and `other non-URL values`.
|
|
1799
|
+
* @param {*} value - The value to check.
|
|
1800
|
+
* @returns {boolean} Returns `true` if the value is an instance of `URL`, otherwise `false`.
|
|
1801
|
+
* @example
|
|
1802
|
+
* isURL(new URL("https://example.com"));
|
|
1803
|
+
* // ➔ true
|
|
1804
|
+
* isURL("https://example.com");
|
|
1805
|
+
* // ➔ false
|
|
1806
|
+
*/
|
|
1775
1807
|
declare const isURL:(value:unknown)=>value is URL;
|
|
1776
1808
|
/** ---------------------------------------------------------
|
|
1777
|
-
* * ***Type guard: `isUndefined`.***
|
|
1778
|
-
* ----------------------------------------------------------
|
|
1779
|
-
*
|
|
1780
|
-
* **[`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)
|
|
1781
|
-
*
|
|
1782
|
-
*
|
|
1783
|
-
*
|
|
1784
|
-
*
|
|
1785
|
-
* @param {*} value - The value to check.
|
|
1786
|
-
* @returns {
|
|
1787
|
-
* @example
|
|
1788
|
-
* isUndefined(undefined); // ➔ true
|
|
1789
|
-
* isUndefined([]); // ➔ false
|
|
1790
|
-
* isUndefined(123); // ➔ false
|
|
1791
|
-
* isUndefined(null); // ➔ false
|
|
1792
|
-
* isUndefined("abc"); // ➔ false
|
|
1793
|
-
*/
|
|
1809
|
+
* * ***Type guard: `isUndefined`.***
|
|
1810
|
+
* ----------------------------------------------------------
|
|
1811
|
+
* **Checks if a value is
|
|
1812
|
+
* **[`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**.**
|
|
1813
|
+
* - **Behavior:**
|
|
1814
|
+
* - Narrows type to `undefined` when true.
|
|
1815
|
+
* - Excludes `null`, `objects`, `arrays`, `strings`, `numbers`, and
|
|
1816
|
+
* `all other values`.
|
|
1817
|
+
* @param {*} value - The value to check.
|
|
1818
|
+
* @returns {boolean} Returns `true` if the value is `undefined`, otherwise `false`.
|
|
1819
|
+
* @example
|
|
1820
|
+
* isUndefined(undefined); // ➔ true
|
|
1821
|
+
* isUndefined([]); // ➔ false
|
|
1822
|
+
* isUndefined(123); // ➔ false
|
|
1823
|
+
* isUndefined(null); // ➔ false
|
|
1824
|
+
* isUndefined("abc"); // ➔ false
|
|
1825
|
+
*/
|
|
1794
1826
|
declare const isUndefined:(value:unknown)=>value is undefined;
|
|
1795
|
-
/**
|
|
1796
|
-
* * ***
|
|
1797
|
-
* ---------------------------------------------------------
|
|
1798
|
-
*
|
|
1799
|
-
* Ensures that the input is
|
|
1800
|
-
*
|
|
1801
|
-
*
|
|
1802
|
-
*
|
|
1803
|
-
*
|
|
1804
|
-
*
|
|
1805
|
-
*
|
|
1806
|
-
*
|
|
1807
|
-
* @
|
|
1808
|
-
*
|
|
1809
|
-
*
|
|
1810
|
-
* isValidURL("
|
|
1811
|
-
* // ➔
|
|
1812
|
-
*
|
|
1813
|
-
*
|
|
1814
|
-
|
|
1815
|
-
*
|
|
1816
|
-
* isValidURL("not-a-url");
|
|
1817
|
-
* // ➔ false
|
|
1818
|
-
*/
|
|
1827
|
+
/** ---------------------------------------------------------
|
|
1828
|
+
* * ***Predicate: `isValidURL`.***
|
|
1829
|
+
* ---------------------------------------------------------
|
|
1830
|
+
* **Validates whether a given string is a properly formatted URL.**
|
|
1831
|
+
* - **Ensures that the input is:**
|
|
1832
|
+
* - A non-empty string.
|
|
1833
|
+
* - A valid **[URL](https://developer.mozilla.org/docs/Web/API/URL)** with `http://` or `https://` scheme.
|
|
1834
|
+
* - **Behavior:**
|
|
1835
|
+
* - ✅ Includes decoding for percent-encoded URLs (e.g., `https%3A%2F%2F...`).
|
|
1836
|
+
* - ❌ Rejects invalid strings, unsupported schemes, and malformed domains.
|
|
1837
|
+
* @param {*} url - The value to validate.
|
|
1838
|
+
* @returns {boolean} Return `true` if the value is a **valid URL string**, otherwise `false`.
|
|
1839
|
+
* @example
|
|
1840
|
+
* isValidURL("https://example.com");
|
|
1841
|
+
* // ➔ true
|
|
1842
|
+
* isValidURL("ftp://example.com");
|
|
1843
|
+
* // ➔ false
|
|
1844
|
+
* isValidURL("not-a-url");
|
|
1845
|
+
* // ➔ false
|
|
1846
|
+
*/
|
|
1819
1847
|
declare const isValidURL:(url:unknown)=>boolean;
|
|
1820
1848
|
/** --------------------------------------------------
|
|
1821
|
-
* * ***Type guard: `isWeakMap`.***
|
|
1822
|
-
* ----------------------------------------------------------
|
|
1823
|
-
*
|
|
1824
|
-
*
|
|
1825
|
-
*
|
|
1826
|
-
*
|
|
1827
|
-
*
|
|
1828
|
-
* @template
|
|
1829
|
-
* @
|
|
1830
|
-
* @
|
|
1831
|
-
* @
|
|
1832
|
-
*
|
|
1833
|
-
*
|
|
1834
|
-
* isWeakMap(new
|
|
1835
|
-
* // ➔
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
*/
|
|
1839
|
-
declare function isWeakMap<K extends object=object,V=unknown>(value:unknown):value is WeakMap<K,V>;export{type IsArrayResult,IsPlainObjectResult,areArraysEqual,areObjectsEqual,areURLsEqualPath,areURLsIdentical,arrayHasAnyMatch,doesKeyExist,hasOwnProp,isArguments,isArray,isArrayBuffer,isArrayLike,isArrayLikeObject,isBigInt,isBoolean,isBuffer,isCurrencyLike,isDate,isDeepEqual,isElement,isEmpty,isEmptyArray,isEmptyDeep,isEmptyObject,isEmptyString,isEmptyValue,isEqual,isEqualWith,isError,isFinite,isFunction,isInteger,isLength,isMap,isMatch,isMatchWith,isNaN,isNative,isNil,isNonEmptyArray,isNonEmptyString,isNonEmptyValue,isNull,isObject,isObjectLoose,isObjectOrArray,isRegExp,isSafeInteger,isSet,isString,isSymbol,isTypedArray,isURL,isUndefined,isValidURL,isWeakMap,textContainsAll,textContainsAny};
|
|
1849
|
+
* * ***Type guard: `isWeakMap`.***
|
|
1850
|
+
* ----------------------------------------------------------
|
|
1851
|
+
* **Checks if a value is a **[`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/WeakMap)** object.**
|
|
1852
|
+
* - **Behavior:**
|
|
1853
|
+
* - Narrows type to `WeakMap<K, V>` when true.
|
|
1854
|
+
* - Excludes `Map`, `arrays`, `plain-objects,` and `other non-WeakMap values`.
|
|
1855
|
+
* @template K - Keys must be objects.
|
|
1856
|
+
* @template V - Type of values stored in the WeakMap.
|
|
1857
|
+
* @param {*} value - The value to check.
|
|
1858
|
+
* @returns {boolean} Returns `true` if the value is a `WeakMap`, otherwise `false`.
|
|
1859
|
+
* @example
|
|
1860
|
+
* isWeakMap(new WeakMap);
|
|
1861
|
+
* // ➔ true
|
|
1862
|
+
* isWeakMap(new Map);
|
|
1863
|
+
* // ➔ false
|
|
1864
|
+
*/
|
|
1865
|
+
declare function isWeakMap<K extends object=object,V=unknown>(value:unknown):value is WeakMap<K,V>;export{type IsArrayResult,IsPlainObjectResult,areArraysEqual,areObjectsEqual,areURLsEqualPath,areURLsIdentical,arrayHasAnyMatch,doesKeyExist,hasOwnProp,isArguments,isArray,isArrayBuffer,isArrayLike,isArrayLikeObject,isBigInt,isBoolean,isBuffer,isCurrencyLike,isDate,isDeepEqual,isElement,isEmpty,isEmptyArray,isEmptyDeep,isEmptyObject,isEmptyString,isEmptyValue,isEqual,isEqualWith,isError,isFinite,isFunction,isInteger,isLength,isMap,isMatch,isMatchWith,isNaN,isNative,isNil,isNonEmptyArray,isNonEmptyString,isNonEmptyValue,isNull,isObject,isObjectLoose,isObjectOrArray,isPropertyKey,isRegExp,isSafeInteger,isSet,isString,isSymbol,isTypedArray,isURL,isUndefined,isValidURL,isWeakMap,textContainsAll,textContainsAny};
|