@rzl-zone/utils-js 3.0.1-beta.0 → 3.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assertions/index.cjs +1 -1
- package/dist/assertions/index.d.ts +96 -116
- package/dist/assertions/index.js +1 -1
- package/dist/chunk-25G6B35W.js +1 -0
- package/dist/chunk-2AUUPGMN.js +1 -0
- package/dist/chunk-2JQQQ625.js +1 -0
- package/dist/chunk-445TAVT4.cjs +1 -0
- package/dist/chunk-467VEMJH.js +1 -0
- package/dist/chunk-6Q4I2RPC.cjs +1 -0
- package/dist/chunk-6SMJMZ7G.cjs +1 -0
- package/dist/chunk-BLCANGFS.js +1 -0
- package/dist/chunk-CK3BZGEU.js +1 -0
- package/dist/{chunk-JWHM3WZQ.cjs → chunk-D43GV6EF.cjs} +1 -1
- package/dist/chunk-DFSTVQFI.cjs +1 -0
- package/dist/chunk-DYRDBYPF.cjs +1 -0
- package/dist/chunk-EXXLUO7L.cjs +1 -0
- package/dist/chunk-G72VSVGO.js +1 -0
- package/dist/chunk-GAJTFCUA.js +1 -0
- package/dist/chunk-GOJNH55O.cjs +1 -0
- package/dist/chunk-HXST7RJB.js +1 -0
- package/dist/{chunk-BYZAD3XN.cjs → chunk-HXTACM3O.cjs} +1 -1
- package/dist/chunk-IJTZWWRJ.cjs +1 -0
- package/dist/chunk-ISJ33O2J.cjs +1 -0
- package/dist/chunk-JISH2VGG.js +1 -0
- package/dist/{chunk-FF76ISQ2.js → chunk-JQZUWBIX.js} +1 -1
- package/dist/{chunk-XH6MCRLP.js → chunk-K4PLGD7C.js} +1 -1
- package/dist/chunk-KZQB7H4E.cjs +1 -0
- package/dist/chunk-LUVV5KSD.cjs +2 -0
- package/dist/chunk-LVUSFXQS.cjs +1 -0
- package/dist/chunk-ME5OV5HN.js +1 -0
- package/dist/chunk-MF5Y5K4N.cjs +1 -0
- package/dist/chunk-MJAW5RAK.js +1 -0
- package/dist/chunk-MWLEM7ED.js +1 -0
- package/dist/chunk-NSVLG7NY.js +4 -0
- package/dist/chunk-NUHOOAUN.cjs +1 -0
- package/dist/chunk-NUVGETPD.js +2 -0
- package/dist/chunk-O5VXBNUQ.cjs +4 -0
- package/dist/chunk-O7SJR4CY.cjs +1 -0
- package/dist/chunk-OX6RLS2F.cjs +1 -0
- package/dist/chunk-PFLNHD4B.cjs +1 -0
- package/dist/chunk-PSWITZK5.js +1 -0
- package/dist/chunk-PYUVKHUF.cjs +1 -0
- package/dist/chunk-REFMEB4A.js +1 -0
- package/dist/chunk-RHE3M2NJ.cjs +1 -0
- package/dist/chunk-RHIBYOFQ.js +1 -0
- package/dist/chunk-S7GMG4TB.js +1 -0
- package/dist/chunk-TQMZ2LPI.js +1 -0
- package/dist/{chunk-RN3TP3S3.js → chunk-U4TZO7WV.js} +1 -1
- package/dist/chunk-UUMKL74S.js +1 -0
- package/dist/{chunk-EXZ47NOW.js → chunk-VQLAPEL3.js} +1 -1
- package/dist/chunk-VTR75UID.cjs +1 -0
- package/dist/chunk-XFCJDSB2.cjs +1 -0
- package/dist/chunk-XOYX4PLZ.cjs +1 -0
- package/dist/chunk-Z6FLCEN6.js +1 -0
- package/dist/chunk-ZO5364A6.cjs +1 -0
- package/dist/conversions/index.cjs +1 -1
- package/dist/conversions/index.d.ts +396 -593
- package/dist/conversions/index.js +1 -1
- package/dist/env/index.d.ts +5 -8
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.d.ts +80 -77
- package/dist/events/index.js +1 -1
- package/dist/{array-CIZRbqTF.d.ts → extends-Bk_SBGdT.d.ts} +145 -1
- package/dist/formatting/index.cjs +1 -1
- package/dist/formatting/index.d.ts +478 -440
- package/dist/formatting/index.js +1 -1
- package/dist/generator/index.cjs +1 -1
- package/dist/generator/index.d.ts +135 -112
- package/dist/generator/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{is-array-Ckm_47hw.d.ts → is-array--YjXV-Wx.d.ts} +2 -352
- package/dist/{isPlainObject-BKYaI6a8.d.ts → isPlainObject-BVhBAPHX.d.ts} +49 -62
- package/dist/next/index.cjs +6 -6
- package/dist/next/index.d.ts +125 -105
- package/dist/next/index.js +5 -5
- package/dist/next/server/index.cjs +1 -1
- package/dist/next/server/index.d.ts +8 -22
- package/dist/next/server/index.js +1 -1
- package/dist/operations/index.cjs +1 -1
- package/dist/operations/index.d.ts +72 -127
- package/dist/operations/index.js +1 -1
- package/dist/parsers/index.cjs +1 -1
- package/dist/parsers/index.d.ts +26 -27
- package/dist/parsers/index.js +1 -1
- package/dist/predicates/index.cjs +1 -1
- package/dist/predicates/index.d.ts +686 -660
- package/dist/predicates/index.js +1 -1
- package/dist/promise/index.cjs +1 -1
- package/dist/promise/index.d.ts +14 -23
- package/dist/promise/index.js +1 -1
- package/dist/rzl-utils.global.js +3 -3
- package/dist/string-XA-til3C.d.ts +351 -0
- package/dist/strings/index.cjs +1 -1
- package/dist/strings/index.d.ts +301 -376
- package/dist/strings/index.js +1 -1
- package/dist/stylings/index.cjs +1 -1
- package/dist/stylings/index.d.ts +15 -23
- package/dist/stylings/index.js +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/urls/index.cjs +1 -1
- package/dist/urls/index.d.ts +279 -302
- package/dist/urls/index.js +1 -1
- package/package.json +53 -11
- package/dist/chunk-2TRAPBZ7.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-62HX5Z45.cjs +0 -1
- package/dist/chunk-7NA6DUHR.cjs +0 -2
- package/dist/chunk-BVPMMWDL.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-FDITZ5C6.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-KBKYG3IY.cjs +0 -1
- package/dist/chunk-KCQDDZJE.cjs +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-POCPQYZS.js +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-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-X3GTRVVK.cjs +0 -4
- package/dist/chunk-XCFIOTCV.js +0 -1
- package/dist/chunk-XE27XPJR.js +0 -1
- package/dist/chunk-XVB3ZZEB.js +0 -1
- package/dist/chunk-YEERJDOF.js +0 -4
- package/dist/chunk-ZBSIGJFO.cjs +0 -1
- package/dist/chunk-ZYAML74V.js +0 -1
- package/dist/extends-Mp81Hq9-.d.ts +0 -145
|
@@ -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
|
-
* * ***
|
|
3
|
+
* * ***Predicate: `areArraysEqual`.***
|
|
4
4
|
* ----------------------------------------------------------
|
|
5
|
-
*
|
|
6
|
-
* Supports deep comparison of arrays containing nested arrays or objects
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* ----------------------------------------------------------
|
|
10
|
-
*
|
|
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.
|
|
11
8
|
* @param {unknown[]} array1
|
|
12
|
-
*
|
|
13
|
-
*
|
|
9
|
+
* The first array to compare. Can contain nested arrays or objects.
|
|
14
10
|
* @param {unknown[]} array2
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* If `true`, will sort both arrays recursively before comparing.
|
|
20
|
-
* Default is `false`.
|
|
21
|
-
*
|
|
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`.
|
|
22
15
|
* @returns {boolean}
|
|
23
16
|
* Returns `true` if both arrays are deeply equal, otherwise `false`.
|
|
24
|
-
*
|
|
25
17
|
* @throws {TypeError}
|
|
26
18
|
* Throws if `array1` or `array2` are not arrays, or if `ignoreOrder` is not a boolean.
|
|
27
|
-
*
|
|
28
19
|
* @example
|
|
29
20
|
* ```ts
|
|
30
21
|
* areArraysEqual([1, 2, 3], [1, 2, 3]);
|
|
31
|
-
* //
|
|
32
|
-
*
|
|
22
|
+
* // ➔ true
|
|
33
23
|
* areArraysEqual([1, 2, 3], [3, 2, 1]);
|
|
34
|
-
* //
|
|
35
|
-
*
|
|
24
|
+
* // ➔ false
|
|
36
25
|
* areArraysEqual([1, 2, 3], [3, 2, 1], true);
|
|
37
|
-
* //
|
|
38
|
-
*
|
|
26
|
+
* // ➔ true (order ignored)
|
|
39
27
|
* areArraysEqual([{ x: 1 }, { y: 2 }], [{ y: 2 }, { x: 1 }], true);
|
|
40
|
-
* //
|
|
28
|
+
* // ➔ true
|
|
41
29
|
* ```
|
|
42
30
|
*/
|
|
43
31
|
declare const areArraysEqual:(array1:unknown[],array2:unknown[],ignoreOrder?:boolean)=>boolean;
|
|
44
32
|
/** ---------------------------------
|
|
45
|
-
* * ***
|
|
33
|
+
* * ***Predicate: `areObjectsEqual`.***
|
|
46
34
|
* ---------------------------------
|
|
47
|
-
*
|
|
35
|
+
* **Compares two objects for deep equality.**
|
|
48
36
|
* @template T1 The type of the first object.
|
|
49
37
|
* @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
|
-
*
|
|
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`.
|
|
54
41
|
* @example
|
|
55
|
-
* areObjectsEqual({ a: 1, b: 2 }, { a: 1, b: 2 });
|
|
56
|
-
*
|
|
57
|
-
* areObjectsEqual(
|
|
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
|
|
58
48
|
*/
|
|
59
49
|
declare const areObjectsEqual:(object1:unknown,object2:unknown)=>boolean;
|
|
60
50
|
/** ---------------------------------
|
|
61
|
-
* * ***
|
|
51
|
+
* * ***Predicate: `areURLsEqualPath`.***
|
|
62
52
|
* ---------------------------------
|
|
63
|
-
*
|
|
64
|
-
* This function compares only the protocol, host, and pathname.
|
|
65
|
-
*
|
|
53
|
+
* **Checks if two URLs are the same, ignoring query parameters, this function compares only the protocol, host, and pathname.**
|
|
66
54
|
* @param {URL} urlA - The first URL to compare.
|
|
67
55
|
* @param {URL} urlB - The second URL to compare.
|
|
68
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
|
|
69
73
|
*/
|
|
70
74
|
declare const areURLsEqualPath:(urlA:URL,urlB:URL)=>boolean;
|
|
71
75
|
/** ---------------------------------
|
|
72
|
-
* * ***
|
|
76
|
+
* * ***Predicate: `areURLsIdentical`.***
|
|
73
77
|
* ---------------------------------
|
|
74
|
-
*
|
|
78
|
+
* **Checks if two URLs are exactly the same, including protocol, host, pathname, and query parameters.**
|
|
75
79
|
* @param {URL} urlA - The first URL to compare.
|
|
76
80
|
* @param {URL} urlB - The second URL to compare.
|
|
77
81
|
* @returns {boolean} Returns `true` if both URLs are identical, otherwise `false`.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*
|
|
82
|
-
* ----------------------------------------------------------
|
|
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
|
|
83
86
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* - ✅ **Supports exact word matching** (optional).
|
|
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
|
|
88
90
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* @param {string} [options.flags="i"] - Optional regex flags (default: `"i"` for case-insensitive).
|
|
93
|
-
* @returns {boolean} - `true` if all `searchWords` are found in `text`, otherwise `false`.
|
|
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
94
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
|
|
99
|
-
|
|
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
|
|
100
103
|
*/
|
|
101
|
-
declare const textContainsAll:<T extends string>(text:T,searchWords:T[]|string[],options?:{
|
|
102
|
-
/** If `true`, matches whole words only, defaultValue is `false`. */
|
|
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
|
-
* * ***
|
|
111
|
+
* * ***Predicate: `textContainsAll`.***
|
|
108
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`.
|
|
109
142
|
*
|
|
110
|
-
*
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*
|
|
115
|
-
* @param {string} text - The text to search within.
|
|
116
|
-
* @param {string[]} searchWords - An array of words/phrases to match against the text.
|
|
117
|
-
* @param {boolean} [options.exactMatch=false] - If `true`, matches whole words only, defaultValue is `false`.
|
|
118
|
-
* @param {string} [options.flags="i"] - Optional regex flags (default: `"i"` for case-insensitive).
|
|
119
|
-
* @returns {boolean} - `true` if at least one `searchWord` is found in `text`, otherwise `false`.
|
|
143
|
+
* @default false
|
|
144
|
+
*/
|
|
145
|
+
exactMatch?:boolean;
|
|
146
|
+
/** Optional regex flags (default: `"i"` for case-insensitive).
|
|
120
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`.
|
|
121
167
|
* @example
|
|
122
|
-
* textContainsAny("Hello world", ["hello", "test"]);
|
|
123
|
-
*
|
|
124
|
-
* textContainsAny("
|
|
125
|
-
*
|
|
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)
|
|
126
180
|
*/
|
|
127
|
-
declare const textContainsAny:<T extends string>(text
|
|
128
|
-
/** If `true`, matches whole words only, defaultValue is `false`. */
|
|
129
|
-
exactMatch?:boolean;
|
|
130
|
-
/** Optional regex flags (default: `"i"` for case-insensitive). */
|
|
131
|
-
flags?:string;})=>boolean;
|
|
181
|
+
declare const textContainsAny:<T extends string>(text?:T|null,searchWords?:T[]|string[]|null,options?:OptionsTextContainsAny)=>boolean;
|
|
132
182
|
/** ----------------------------------------------------------
|
|
133
|
-
* * ***
|
|
183
|
+
* * ***Predicate: `doesKeyExist`.***
|
|
134
184
|
* ----------------------------------------------------------
|
|
135
|
-
*
|
|
136
|
-
* -
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
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.
|
|
148
199
|
* @template T - The type of the input object or array.
|
|
149
200
|
* @param {T | Record<string, unknown> | unknown[]} object - The object or array to search.
|
|
150
201
|
* @param {PropertyKey} key - The key to look for (string, number, or symbol).
|
|
151
202
|
* @returns {boolean} Returns `true` if the key exists anywhere in the object or array (even with `null` / `undefined` value), otherwise `false`.
|
|
152
|
-
*
|
|
153
203
|
* @example
|
|
154
|
-
* doesKeyExist({ name: "John", age: 30 }, "age");
|
|
155
|
-
*
|
|
156
|
-
* doesKeyExist(
|
|
157
|
-
*
|
|
158
|
-
* doesKeyExist(
|
|
159
|
-
*
|
|
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
|
|
160
216
|
*
|
|
161
|
-
* @example
|
|
162
217
|
* // Key exists even if value is null or undefined:
|
|
163
|
-
* doesKeyExist({ a: null, b: undefined, c: { d: null } }, "a"); // true
|
|
164
|
-
* doesKeyExist({ a: null, b: undefined, c: { d: null } }, "b"); // true
|
|
165
|
-
* doesKeyExist({ a: null, b: undefined, c: { d: null } }, "d"); // true
|
|
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
|
|
166
221
|
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
* doesKeyExist({ a: 1 }, ["not", "valid"]);
|
|
222
|
+
* doesKeyExist({ a: 1 }, true);
|
|
223
|
+
* // ➔ ❌ Throws TypeError
|
|
224
|
+
* doesKeyExist({ a: 1 }, ["not", "valid"]);
|
|
225
|
+
* // ➔ ❌ Throws TypeError
|
|
170
226
|
*/
|
|
171
227
|
declare const doesKeyExist:(object:Record<string,unknown>|unknown[],key:PropertyKey)=>boolean;
|
|
172
228
|
/** ----------------------------------------------------------
|
|
173
|
-
* * ***
|
|
229
|
+
* * ***Predicate: `arrayHasAnyMatch`.***
|
|
174
230
|
* ----------------------------------------------------------
|
|
175
|
-
*
|
|
176
|
-
* -
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
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.
|
|
181
237
|
* @template T - The expected type of array elements.
|
|
182
|
-
*
|
|
183
|
-
* @param {T[]}
|
|
184
|
-
* @param {T[]} [targetArray] - The array containing elements to match.
|
|
185
|
-
*
|
|
238
|
+
* @param {T[] | null | undefined} sourceArray - The array to search within.
|
|
239
|
+
* @param {T[] | null | undefined} targetArray - The array containing elements to match.
|
|
186
240
|
* @returns {boolean}
|
|
187
|
-
*
|
|
241
|
+
* ***Return:***
|
|
242
|
+
* - `true` if **at least one element from `targetArray` is strictly found
|
|
243
|
+
* in `sourceArray`**.
|
|
188
244
|
* - Comparison uses:
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
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.
|
|
195
250
|
* @example
|
|
196
|
-
* arrayHasAnyMatch(["apple", "banana", "cherry"], ["banana", "grape"]);
|
|
197
|
-
*
|
|
198
|
-
* arrayHasAnyMatch([
|
|
199
|
-
*
|
|
200
|
-
* arrayHasAnyMatch([
|
|
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
|
|
201
261
|
*
|
|
202
|
-
* @example
|
|
203
262
|
* const obj = { x: 1 };
|
|
204
|
-
* arrayHasAnyMatch([obj], [obj]);
|
|
205
|
-
*
|
|
263
|
+
* arrayHasAnyMatch([obj], [obj]);
|
|
264
|
+
* // ➔ true (same reference)
|
|
265
|
+
* arrayHasAnyMatch([{ x: 1 }], [{ x: 1 }]);
|
|
266
|
+
* // ➔ false (different reference)
|
|
206
267
|
*
|
|
207
|
-
* @example
|
|
208
268
|
* const fn = () => "hello";
|
|
209
|
-
* arrayHasAnyMatch([fn], [fn]);
|
|
210
|
-
*
|
|
269
|
+
* arrayHasAnyMatch([fn], [fn]);
|
|
270
|
+
* // ➔ true
|
|
271
|
+
* arrayHasAnyMatch([() => "hello"], [() => "hello"]);
|
|
272
|
+
* // ➔ false (different function reference)
|
|
211
273
|
*
|
|
212
|
-
* @example
|
|
213
274
|
* const arr = [1, 2];
|
|
214
|
-
* arrayHasAnyMatch([arr], [arr]);
|
|
215
|
-
*
|
|
275
|
+
* arrayHasAnyMatch([arr], [arr]);
|
|
276
|
+
* // ➔ true
|
|
277
|
+
* arrayHasAnyMatch([[1, 2]], [[1, 2]]);
|
|
278
|
+
* // ➔ false (different array object)
|
|
216
279
|
*/
|
|
217
|
-
declare const arrayHasAnyMatch:<T>(sourceArray
|
|
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. */
|
|
@@ -282,180 +345,160 @@ type DeepRequiredSymbolHasOwnProp<Obj,Sym extends symbol,DU extends boolean=true
|
|
|
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
|
-
* If `true` (default), properties with `undefined` values are treated as non-existent.
|
|
348
|
+
/** If `true` ***(default)***, properties with `undefined` values are treated as non-existent.
|
|
287
349
|
*
|
|
288
|
-
* **Effects:**
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
* **Example:**
|
|
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:**
|
|
293
354
|
* ```ts
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
355
|
+
* const obj = { a: undefined, b: 123 };
|
|
356
|
+
* hasOwnProp(obj, "a"); // ➔ false
|
|
357
|
+
* hasOwnProp(obj, "a", { discardUndefined: false }); // ➔ true
|
|
297
358
|
* ```
|
|
298
359
|
*/
|
|
299
360
|
discardUndefined?:DiscardUndefined;
|
|
300
|
-
/**
|
|
301
|
-
* If `true` (default: `false`), properties with `null` values are treated as non-existent.
|
|
361
|
+
/** If `true` ***(default: `false`)***, properties with `null` values are treated as non-existent.
|
|
302
362
|
*
|
|
303
|
-
* **Effects:**
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
* **Example:**
|
|
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:**
|
|
308
367
|
* ```ts
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
368
|
+
* const obj = { a: null, b: 123 };
|
|
369
|
+
* hasOwnProp(obj, "a"); // ➔ true (default discardNull = false)
|
|
370
|
+
* hasOwnProp(obj, "a", { discardNull: true }); // ➔ false
|
|
312
371
|
* ```
|
|
313
372
|
*/
|
|
314
373
|
discardNull?:DiscardNull;};
|
|
315
374
|
/** -------------------------------------------------------
|
|
316
|
-
* * ***
|
|
317
|
-
* with runtime validation and **TypeScript-aware type narrowing**.***
|
|
375
|
+
* * ***Utility: `hasOwnProp`.***
|
|
318
376
|
* -------------------------------------------------------
|
|
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
|
-
* #### Options
|
|
378
|
-
* @param options.discardUndefined - Default `true`.
|
|
379
|
-
* If `true`, properties with `undefined` values are treated as **missing**.
|
|
380
|
-
*
|
|
381
|
-
* @param options.discardNull - Default `false`.
|
|
382
|
-
* If `true`, properties with `null` values are treated as **missing**.
|
|
383
|
-
*
|
|
384
|
-
* ---
|
|
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`.
|
|
385
433
|
* @example
|
|
386
434
|
*
|
|
387
|
-
* #### ✅ Objects
|
|
435
|
+
* - #### ✅ Objects:
|
|
388
436
|
* ```ts
|
|
389
|
-
*
|
|
437
|
+
* const obj: { name?: string | null } = {};
|
|
390
438
|
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
439
|
+
* if (hasOwnProp(obj, "name")) {
|
|
440
|
+
* // obj is now ➔ { name: string | null }
|
|
441
|
+
* console.log(obj.name); // string | null
|
|
442
|
+
* }
|
|
395
443
|
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
444
|
+
* if (hasOwnProp(obj, "name", { discardUndefined: true, discardNull: true })) {
|
|
445
|
+
* // obj is now ➔ { name: string }
|
|
446
|
+
* console.log(obj.name.toUpperCase()); // safe
|
|
447
|
+
* }
|
|
400
448
|
* ```
|
|
401
|
-
*
|
|
402
|
-
* #### ✅ Arrays
|
|
449
|
+
* - #### ✅ Arrays:
|
|
403
450
|
* ```ts
|
|
404
|
-
*
|
|
451
|
+
* const users = [{ id: 1 }, { id: 2 }];
|
|
405
452
|
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
453
|
+
* if (hasOwnProp(users, "[1].id")) {
|
|
454
|
+
* // ➔ users[1].id is guaranteed to exist
|
|
455
|
+
* console.log(users[1].id); // number
|
|
456
|
+
* }
|
|
410
457
|
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
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
|
+
* }
|
|
416
463
|
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
464
|
+
* // 👉 Solution: optional chaining
|
|
465
|
+
* console.log(users[1]?.id); // ➔ safe, even without narrowing
|
|
419
466
|
* ```
|
|
420
467
|
*
|
|
421
|
-
* #### ✅ Symbols
|
|
468
|
+
* - #### ✅ Symbols:
|
|
422
469
|
* ```ts
|
|
423
|
-
*
|
|
424
|
-
*
|
|
470
|
+
* const secret = Symbol("secret");
|
|
471
|
+
* const obj2 = { [secret]: 42 };
|
|
425
472
|
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
473
|
+
* if (hasOwnProp(obj2, secret)) {
|
|
474
|
+
* console.log(obj2[secret] + 1); // ➔ 43
|
|
475
|
+
* }
|
|
429
476
|
* ```
|
|
430
|
-
*
|
|
431
|
-
* #### ✅ Strings
|
|
477
|
+
* - #### ✅ Strings:
|
|
432
478
|
* ```ts
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
479
|
+
* if (hasOwnProp("hello", "length")) {
|
|
480
|
+
* console.log("hello".length); // ➔ 5
|
|
481
|
+
* }
|
|
436
482
|
*
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
483
|
+
* if (hasOwnProp("hello", 1)) {
|
|
484
|
+
* console.log("hello"[1]); // ➔ "e"
|
|
485
|
+
* }
|
|
440
486
|
* ```
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
* #### ✅ Functions
|
|
487
|
+
* - #### ✅ Functions:
|
|
444
488
|
* ```ts
|
|
445
|
-
*
|
|
446
|
-
*
|
|
489
|
+
* function fn() {}
|
|
490
|
+
* fn.extra = 123;
|
|
447
491
|
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
492
|
+
* if (hasOwnProp(fn, "extra")) {
|
|
493
|
+
* console.log(fn.extra); // ➔ 123
|
|
494
|
+
* }
|
|
451
495
|
* ```
|
|
452
|
-
*
|
|
453
|
-
* #### ❌ Empty key
|
|
496
|
+
* - #### ❌ Empty key:
|
|
454
497
|
* ```ts
|
|
455
|
-
*
|
|
498
|
+
* const obj = { a: 1 };
|
|
456
499
|
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
500
|
+
* hasOwnProp(obj, ""); // ➔ false (invalid key)
|
|
501
|
+
* hasOwnProp(obj, " "); // ➔ false (trimmed to empty)
|
|
459
502
|
* ```
|
|
460
503
|
*/
|
|
461
504
|
declare function hasOwnProp<Obj>(obj:IsAny<Obj>extends true?Obj:never,key:PropertyKey,options?:HasOwnPropOptions<boolean,boolean>
|
|
@@ -474,11 +517,9 @@ declare function hasOwnProp<Obj>(obj:IsAny<Obj>extends true?Obj:never,key:Proper
|
|
|
474
517
|
/** -------------------
|
|
475
518
|
* * ***Type guard: `isArguments`.***
|
|
476
519
|
* -------------------
|
|
477
|
-
*
|
|
478
|
-
*
|
|
520
|
+
* **Checks if `value` is likely an `arguments` object.**
|
|
479
521
|
* @param {*} value The value to check.
|
|
480
|
-
* @returns {boolean} Returns `true` if `value` is an
|
|
481
|
-
* else `false`.
|
|
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`.
|
|
482
523
|
* @example
|
|
483
524
|
* isArguments(function() { return arguments; }());
|
|
484
525
|
* // ➔ true
|
|
@@ -491,12 +532,11 @@ type IsArrayResult<T>=IsUnknown<T>extends true?unknown[] & T:IsNever<T>extends t
|
|
|
491
532
|
/** ----------------------------------------------------------
|
|
492
533
|
* * ***Type guard: `isArray`.***
|
|
493
534
|
* ----------------------------------------------------------
|
|
494
|
-
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
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.
|
|
500
540
|
* @template T - The expected type of array elements.
|
|
501
541
|
* @param {*} value - The value to check.
|
|
502
542
|
* @returns {boolean} Returns `true` if the value is an `array`, otherwise `false`.
|
|
@@ -518,9 +558,9 @@ declare function isArray<T extends unknown[]>(value:T):value is Extract<T,unknow
|
|
|
518
558
|
/** ----------------------------------------------------
|
|
519
559
|
* * ***Type guard: `isArrayBuffer`.***
|
|
520
560
|
* ----------------------------------------------------
|
|
521
|
-
*
|
|
561
|
+
* **Checks if `value` is classified as an `ArrayBuffer` object.**
|
|
522
562
|
* @param {*} value The value to check.
|
|
523
|
-
* @returns {boolean} Returns `true` if `value` is instance of
|
|
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`.
|
|
524
564
|
* @example
|
|
525
565
|
* isArrayBuffer(new ArrayBuffer(2));
|
|
526
566
|
* // ➔ true
|
|
@@ -531,10 +571,9 @@ declare function isArrayBuffer(value:unknown):value is ArrayBuffer;
|
|
|
531
571
|
/** ----------------------------------------------------
|
|
532
572
|
* * ***Type guard: `isArrayLike`.***
|
|
533
573
|
* ----------------------------------------------------
|
|
534
|
-
*
|
|
574
|
+
* **Checks if `value` is array-like, a value is considered array-like if it's
|
|
535
575
|
* 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
|
-
*
|
|
576
|
+
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.**
|
|
538
577
|
* @template T - The type of the value being checked.
|
|
539
578
|
* @param {*} value The value to check.
|
|
540
579
|
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
|
@@ -552,7 +591,8 @@ declare function isArrayLike<T extends{__anyHack:unknown;}>(value:T):boolean;dec
|
|
|
552
591
|
/** ----------------------------------------------------
|
|
553
592
|
* * ***Type guard: `isArrayLikeObject`.***
|
|
554
593
|
* ----------------------------------------------------
|
|
555
|
-
*
|
|
594
|
+
* **This method is like ***{@link isArrayLike | `isArrayLike`}*** except that
|
|
595
|
+
* it also checks if `value` is an object.**
|
|
556
596
|
* @template T - The type of the value being checked.
|
|
557
597
|
* @param {*} value The value to check.
|
|
558
598
|
* @returns {boolean} Returns `true` if `value` is `array-like object`, else `false`.
|
|
@@ -570,11 +610,12 @@ declare function isArrayLikeObject<T extends{__anyHack:unknown;}>(value:T):boole
|
|
|
570
610
|
/** ----------------------------------------------------------
|
|
571
611
|
* * ***Type guard: `isBigInt`.***
|
|
572
612
|
* ----------------------------------------------------------
|
|
573
|
-
*
|
|
574
|
-
* -
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
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))`.
|
|
578
619
|
* @param {*} value - The value to check.
|
|
579
620
|
* @returns {boolean} Return `true` if value is a primitive **[`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)**.
|
|
580
621
|
* @example
|
|
@@ -591,7 +632,7 @@ declare const isBigInt:(value:unknown)=>value is bigint;
|
|
|
591
632
|
/** ----------------------------------------------------------
|
|
592
633
|
* * ***Type guard: `isBoolean`.***
|
|
593
634
|
* ----------------------------------------------------------
|
|
594
|
-
*
|
|
635
|
+
* **Checks if a value is of type boolean.**
|
|
595
636
|
* @param {*} value - The value to check.
|
|
596
637
|
* @returns {boolean} Returns `true` if the value is a **[`boolean`](https://developer.mozilla.org/en-US/docs/Glossary/Boolean/JavaScript)**, otherwise `false`.
|
|
597
638
|
* @example
|
|
@@ -603,9 +644,9 @@ declare const isBoolean:(value:unknown)=>value is boolean;
|
|
|
603
644
|
/** ----------------------------------------------------
|
|
604
645
|
* * ***Type guard: `isBuffer`.***
|
|
605
646
|
* ----------------------------------------------------------
|
|
606
|
-
*
|
|
647
|
+
* **Checks if a value is a **Node.js Buffer** instance.**
|
|
607
648
|
* @param {*} value The value to check.
|
|
608
|
-
* @returns {boolean} Returns `true` if `value` is a
|
|
649
|
+
* @returns {boolean} Returns `true` if `value` is a ***{@link Buffer | `Buffer`}***, else `false`.
|
|
609
650
|
* @example
|
|
610
651
|
* isBuffer(new Buffer(2));
|
|
611
652
|
* // ➔ true
|
|
@@ -624,25 +665,22 @@ declare const isBuffer:(value:unknown)=>value is Buffer;
|
|
|
624
665
|
/** -----------------------------------------------------------
|
|
625
666
|
* * ***Checks whether a value looks like a currency or number string.***
|
|
626
667
|
* -----------------------------------------------------------
|
|
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
|
-
*
|
|
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.
|
|
642
682
|
* @param {*} input - The input value to check.
|
|
643
|
-
*
|
|
644
683
|
* @returns {boolean} Return `true` if it can be reasonably parsed into a currency-like number, `false` otherwise.
|
|
645
|
-
*
|
|
646
684
|
* @example
|
|
647
685
|
* isCurrencyLike(15300.95);
|
|
648
686
|
* // ➔ true
|
|
@@ -661,11 +699,12 @@ declare const isCurrencyLike:(input:unknown)=>boolean;
|
|
|
661
699
|
/** ----------------------------------------------------------
|
|
662
700
|
* * ***Type guard: `isDate`.***
|
|
663
701
|
* ----------------------------------------------------------
|
|
664
|
-
*
|
|
665
|
-
*
|
|
666
|
-
* -
|
|
667
|
-
*
|
|
668
|
-
*
|
|
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`.
|
|
669
708
|
* @param {*} value - The value to check.
|
|
670
709
|
* @returns {boolean} Return `true` if value is a valid Date object.
|
|
671
710
|
* @example
|
|
@@ -678,17 +717,21 @@ declare const isCurrencyLike:(input:unknown)=>boolean;
|
|
|
678
717
|
*/
|
|
679
718
|
declare const isDate:(value:unknown)=>value is Date;
|
|
680
719
|
/** ----------------------------------------------------------
|
|
681
|
-
* * ***
|
|
720
|
+
* * ***Predicate: `isDeepEqual`.***
|
|
682
721
|
* ----------------------------------------------------------
|
|
683
|
-
*
|
|
684
|
-
* -
|
|
685
|
-
* - `
|
|
686
|
-
*
|
|
687
|
-
* -
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
*
|
|
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.
|
|
692
735
|
* @param {*} a - First value to compare.
|
|
693
736
|
* @param {*} b - Second value to compare.
|
|
694
737
|
* @returns {boolean} `true` if both values are deeply equal, otherwise `false`.
|
|
@@ -733,7 +776,8 @@ declare const isDeepEqual:(a:unknown,b:unknown)=>boolean;
|
|
|
733
776
|
/** ----------------------------------------------------
|
|
734
777
|
* * ***Type guard: `isElement`.***
|
|
735
778
|
* ----------------------------------------------------------
|
|
736
|
-
*
|
|
779
|
+
* **Checks if `value` is likely a
|
|
780
|
+
* **[`DOM Element`](https://developer.mozilla.org/en-US/docs/Web/API/Element)**.**
|
|
737
781
|
* @template T - The type of the value being checked.
|
|
738
782
|
* @param {*} value The value to check.
|
|
739
783
|
* @returns {boolean} Returns `true` if `value` is extends instance of **[`Element`](https://developer.mozilla.org/en-US/docs/Web/API/Element)**, else `false`.
|
|
@@ -753,15 +797,18 @@ declare function isElement(value:[]):value is [];declare function isElement<T ex
|
|
|
753
797
|
/** ----------------------------------------------------
|
|
754
798
|
* * ***Utility: `isEmpty`.***
|
|
755
799
|
* ----------------------------------------------------------
|
|
756
|
-
*
|
|
757
|
-
* - **
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
*
|
|
763
|
-
*
|
|
764
|
-
*
|
|
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.
|
|
765
812
|
* @template T - The type of the value being checked.
|
|
766
813
|
* @param {*} value The value to check.
|
|
767
814
|
* @returns {boolean} Returns `true` if `value` is empty, else `false`.
|
|
@@ -793,12 +840,11 @@ declare function isEmpty<T extends{__trapAny:any;}>(value?:T):boolean;declare fu
|
|
|
793
840
|
/** ----------------------------------------------------------
|
|
794
841
|
* * ***Type guard: `isEmptyArray`.***
|
|
795
842
|
* ----------------------------------------------------------
|
|
796
|
-
*
|
|
797
|
-
* -
|
|
798
|
-
*
|
|
799
|
-
*
|
|
843
|
+
* **Checks whether a given value is an empty array.**
|
|
844
|
+
* - **Behavior:**
|
|
845
|
+
* - Non-array inputs are considered `"empty"` ***(defensive strategy)***.
|
|
800
846
|
* @param {*} [value] - The value to check.
|
|
801
|
-
* @returns {boolean} Returns `true` if it's not an array or an empty
|
|
847
|
+
* @returns {boolean} Returns `true` if it's ***not an array*** or ***an empty-array***.
|
|
802
848
|
* @example
|
|
803
849
|
* isEmptyArray([]); // ➔ true
|
|
804
850
|
* isEmptyArray([1, 2, 3]); // ➔ false
|
|
@@ -814,20 +860,16 @@ declare const isEmptyArray:(value:unknown)=>boolean;
|
|
|
814
860
|
/** ----------------------------------------------------------
|
|
815
861
|
* * ***Predicate: `isEmptyDeep`.***
|
|
816
862
|
* ----------------------------------------------------------
|
|
817
|
-
*
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
* - Returns `true` for:
|
|
863
|
+
* **Recursively checks whether a value is **deeply empty**.**
|
|
864
|
+
* - **Returns `true` for:**
|
|
821
865
|
* - Empty objects: `{}`
|
|
822
866
|
* - Empty arrays: `[]`
|
|
823
867
|
* - Nested empty structures: `{ a: [], b: {} }`
|
|
824
868
|
* - Falsy values (except numbers): `null`, `undefined`, `false`, `""`, `NaN`
|
|
825
|
-
*
|
|
826
|
-
* - Returns `false` for:
|
|
869
|
+
* - **Returns `false` for:**
|
|
827
870
|
* - Non-zero numbers
|
|
828
871
|
* - Objects or arrays containing non-empty values
|
|
829
872
|
* - Non-empty strings, `true`, functions, symbols, etc.
|
|
830
|
-
*
|
|
831
873
|
* @param {*} value - The value to deeply check.
|
|
832
874
|
* @returns {boolean} `true` if the value is deeply empty, otherwise `false`.
|
|
833
875
|
* @example
|
|
@@ -853,9 +895,7 @@ declare const isEmptyArray:(value:unknown)=>boolean;
|
|
|
853
895
|
* // ➔ true
|
|
854
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
|
-
* DefaultValue: `false`.
|
|
898
|
+
/** Whether to check for symbol properties in addition to string keys, defaultValue: `true`.
|
|
859
899
|
*
|
|
860
900
|
* @default false
|
|
861
901
|
*/
|
|
@@ -863,15 +903,14 @@ checkSymbols?:boolean;};
|
|
|
863
903
|
/** ----------------------------------------------------------
|
|
864
904
|
* * ***Predicate: `isEmptyObject`.***
|
|
865
905
|
* ----------------------------------------------------------
|
|
866
|
-
*
|
|
867
|
-
* and optionally **no own enumerable symbol-key properties** when `checkSymbols` is `true
|
|
868
|
-
*
|
|
869
|
-
*
|
|
870
|
-
*
|
|
871
|
-
*
|
|
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.
|
|
872
911
|
* @param {*} value - The value to check.
|
|
873
912
|
* @param {IsEmptyObjectOptions} [options] - Optional settings.
|
|
874
|
-
* @param {
|
|
913
|
+
* @param {IsEmptyObjectOptions["checkSymbols"]} [options.checkSymbols=false] - Whether to also check symbol properties.
|
|
875
914
|
* @returns {boolean} Return `true` if the value is considered empty or not an object, false otherwise.
|
|
876
915
|
* @example
|
|
877
916
|
* isEmptyObject({});
|
|
@@ -892,23 +931,21 @@ checkSymbols?:boolean;};
|
|
|
892
931
|
* // ➔ true (not object)
|
|
893
932
|
*/
|
|
894
933
|
declare function isEmptyObject(value:unknown,options?:IsEmptyObjectOptions):boolean;type IsEmptyStringOptions={
|
|
895
|
-
/** Whether to trim the string before checking
|
|
896
|
-
*
|
|
897
|
-
* DefaultValue: `true`.
|
|
934
|
+
/** Whether to trim the string before checking, defaultValue: `true`.
|
|
898
935
|
*
|
|
899
936
|
* @default `true` */
|
|
900
937
|
trim?:boolean;};
|
|
901
938
|
/** ----------------------------------------------------------
|
|
902
939
|
* * ***Predicate: `isEmptyString`.***
|
|
903
940
|
* ----------------------------------------------------------
|
|
904
|
-
*
|
|
905
|
-
*
|
|
906
|
-
*
|
|
907
|
-
*
|
|
908
|
-
*
|
|
909
|
-
* @param {*}
|
|
910
|
-
* @param {IsEmptyStringOptions
|
|
911
|
-
* @param {
|
|
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`.
|
|
912
949
|
* @returns {boolean} Returns `true` if the value is string not a string or value string is considered empty.
|
|
913
950
|
* @example
|
|
914
951
|
* isEmptyString("");
|
|
@@ -942,23 +979,20 @@ checkSymbols?:boolean;};
|
|
|
942
979
|
/** ----------------------------------------------------------
|
|
943
980
|
* * ***Predicate: `isEmptyValue`.***
|
|
944
981
|
* ----------------------------------------------------------
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
*
|
|
949
|
-
*
|
|
950
|
-
*
|
|
951
|
-
*
|
|
952
|
-
*
|
|
953
|
-
*
|
|
954
|
-
*
|
|
955
|
-
*
|
|
956
|
-
* - Functions, `true`, symbols, etc.
|
|
957
|
-
*
|
|
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`.
|
|
958
993
|
* @param {*} value - The value to evaluate.
|
|
959
|
-
* @param {IsEmptyValueOptions} options - Optional settings.
|
|
994
|
+
* @param {IsEmptyValueOptions} [options] - Optional settings.
|
|
960
995
|
* @returns {boolean} Return `true` if the value is considered empty, otherwise `false`.
|
|
961
|
-
*
|
|
962
996
|
* @example
|
|
963
997
|
* isEmptyValue({});
|
|
964
998
|
* // ➔ true
|
|
@@ -999,24 +1033,22 @@ checkSymbols?:boolean;};
|
|
|
999
1033
|
*/
|
|
1000
1034
|
declare const isEmptyValue:(value:unknown,options?:IsEmptyValueOptions)=>boolean;
|
|
1001
1035
|
/** ----------------------------------------------------
|
|
1002
|
-
* * ***
|
|
1036
|
+
* * ***Predicate: `isEqual`.***
|
|
1003
1037
|
* ----------------------------------------------------------
|
|
1038
|
+
* **Performs a deep comparison between two values to determine if they are equivalent.**
|
|
1004
1039
|
* @description
|
|
1005
1040
|
* Checks whether two values are **deeply equal**, not just reference-equal (`===`).
|
|
1006
|
-
*
|
|
1007
|
-
*
|
|
1008
|
-
*
|
|
1009
|
-
*
|
|
1010
|
-
*
|
|
1011
|
-
*
|
|
1012
|
-
*
|
|
1013
|
-
*
|
|
1014
|
-
*
|
|
1015
|
-
*
|
|
1016
|
-
*
|
|
1017
|
-
*
|
|
1018
|
-
* ❌ Functions and DOM nodes are **not supported**.
|
|
1019
|
-
*
|
|
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***.
|
|
1020
1052
|
* @param {*} value The value to compare.
|
|
1021
1053
|
* @param {*} other The other value to compare.
|
|
1022
1054
|
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
@@ -1041,23 +1073,25 @@ declare const isEmptyValue:(value:unknown,options?:IsEmptyValueOptions)=>boolean
|
|
|
1041
1073
|
*/
|
|
1042
1074
|
declare function isEqual(value:unknown,other:unknown):boolean;
|
|
1043
1075
|
/** ----------------------------------------------------
|
|
1044
|
-
* * ***
|
|
1076
|
+
* * ***Predicate: `isEqualWith`.***
|
|
1045
1077
|
* ----------------------------------------------------
|
|
1078
|
+
* **Performs a deep comparison between two values with support for a
|
|
1079
|
+
* customizer function.**
|
|
1046
1080
|
* @description
|
|
1047
|
-
* This method is like **{@link isEqual}** except that it
|
|
1048
|
-
* which is invoked to compare values.
|
|
1049
|
-
* -
|
|
1050
|
-
* the comparison is handled by
|
|
1051
|
-
*
|
|
1052
|
-
*
|
|
1053
|
-
*
|
|
1054
|
-
*
|
|
1055
|
-
*
|
|
1056
|
-
*
|
|
1057
|
-
*
|
|
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.
|
|
1058
1092
|
* @param {*} value The value to compare.
|
|
1059
1093
|
* @param {*} other The other value to compare.
|
|
1060
|
-
* @param {
|
|
1094
|
+
* @param {CustomizerIsEqualWith} [customizer] The function to customize comparisons.
|
|
1061
1095
|
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
1062
1096
|
* @example
|
|
1063
1097
|
* function isGreeting(value: unknown) {
|
|
@@ -1073,18 +1107,17 @@ declare function isEqual(value:unknown,other:unknown):boolean;
|
|
|
1073
1107
|
* const array = ["hello", "goodbye"];
|
|
1074
1108
|
* const other = ["hi", "goodbye"];
|
|
1075
1109
|
*
|
|
1076
|
-
*
|
|
1110
|
+
* isEqualWith(array, other, customizer);
|
|
1077
1111
|
* // ➔ true
|
|
1078
1112
|
*/
|
|
1079
|
-
declare function isEqualWith(value:unknown,other:unknown,customizer?:
|
|
1113
|
+
declare function isEqualWith(value:unknown,other:unknown,customizer?:CustomizerIsEqualWith):boolean;
|
|
1080
1114
|
/** ----------------------------------------------------------
|
|
1081
1115
|
* * ***Type guard: `isError`.***
|
|
1082
1116
|
* ----------------------------------------------------------
|
|
1083
|
-
*
|
|
1084
|
-
*
|
|
1085
|
-
*
|
|
1086
|
-
*
|
|
1087
|
-
*
|
|
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.
|
|
1088
1121
|
* @param {*} error - The value to check.
|
|
1089
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`.
|
|
1090
1123
|
* @example
|
|
@@ -1096,19 +1129,19 @@ declare function isEqualWith(value:unknown,other:unknown,customizer?:IsEqualCust
|
|
|
1096
1129
|
* // ➔ false
|
|
1097
1130
|
*/
|
|
1098
1131
|
declare const isError:(error:unknown)=>error is Error;
|
|
1099
|
-
/**
|
|
1100
|
-
* * ***
|
|
1101
|
-
*
|
|
1132
|
+
/** ----------------------------------------------------------
|
|
1133
|
+
* * ***Type guard: `isFinite`.***
|
|
1134
|
+
* -----------------------------------------------------------
|
|
1135
|
+
* **Checks if a value is a finite primitive number.**
|
|
1102
1136
|
* @description
|
|
1103
1137
|
* This function verifies that `value` is a **primitive number** and is **finite**
|
|
1104
1138
|
* (i.e., not `NaN`, `Infinity`, or `-Infinity`).
|
|
1105
|
-
*
|
|
1106
|
-
*
|
|
1107
|
-
*
|
|
1108
|
-
*
|
|
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**.
|
|
1109
1143
|
* @param {*} value - The value to check.
|
|
1110
1144
|
* @returns {boolean} Returns `true` if `value` is a finite primitive number, else `false`.
|
|
1111
|
-
*
|
|
1112
1145
|
* @example
|
|
1113
1146
|
* import * as RzlUtilsJs from "@rzl-zone/utils-js";
|
|
1114
1147
|
*
|
|
@@ -1135,15 +1168,14 @@ declare const isError:(error:unknown)=>error is Error;
|
|
|
1135
1168
|
declare function isFinite(value:unknown):value is number;
|
|
1136
1169
|
/** ----------------------------------------------------------
|
|
1137
1170
|
* * ***Type guard: `isFunction`.***
|
|
1138
|
-
*
|
|
1139
|
-
*
|
|
1140
|
-
* -
|
|
1141
|
-
*
|
|
1142
|
-
*
|
|
1143
|
-
*
|
|
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`.
|
|
1144
1177
|
* @param {*} value - The value to check.
|
|
1145
1178
|
* @returns {boolean} Return `true` if the value is a function.
|
|
1146
|
-
*
|
|
1147
1179
|
* @example
|
|
1148
1180
|
* isFunction(() => {});
|
|
1149
1181
|
* // ➔ true
|
|
@@ -1155,14 +1187,13 @@ declare function isFinite(value:unknown):value is number;
|
|
|
1155
1187
|
* // ➔ false
|
|
1156
1188
|
*/
|
|
1157
1189
|
declare const isFunction:(value:unknown)=>value is AnyFunction;
|
|
1158
|
-
/**
|
|
1190
|
+
/** ---------------------------------------------------------
|
|
1159
1191
|
* * ***Type guard: `isInteger`.***
|
|
1160
1192
|
* ----------------------------------------------------------
|
|
1161
|
-
*
|
|
1162
|
-
*
|
|
1163
|
-
*
|
|
1164
|
-
*
|
|
1165
|
-
*
|
|
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).
|
|
1166
1197
|
* @param {*} value The value to check.
|
|
1167
1198
|
* @returns {boolean} Returns `true` if `value` is an integer, else `false`.
|
|
1168
1199
|
* @example
|
|
@@ -1183,18 +1214,16 @@ declare function isInteger(value:unknown):value is number;
|
|
|
1183
1214
|
/** ----------------------------------------
|
|
1184
1215
|
* * ***Type guard: `isLength`.***
|
|
1185
1216
|
* ----------------------------------------------------------
|
|
1186
|
-
*
|
|
1187
|
-
*
|
|
1188
|
-
*
|
|
1189
|
-
*
|
|
1190
|
-
*
|
|
1191
|
-
*
|
|
1192
|
-
*
|
|
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`**.
|
|
1193
1226
|
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
|
|
1194
|
-
*
|
|
1195
|
-
* A valid length must be a non-negative integer
|
|
1196
|
-
* and **not greater than `Number.MAX_SAFE_INTEGER`**.
|
|
1197
|
-
*
|
|
1198
1227
|
* @param {*} value The value to check.
|
|
1199
1228
|
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
|
1200
1229
|
* @example
|
|
@@ -1221,11 +1250,10 @@ declare function isLength(value:unknown):boolean;
|
|
|
1221
1250
|
/** --------------------------------------------------
|
|
1222
1251
|
* * ***Type guard: `isMap`.***
|
|
1223
1252
|
* ----------------------------------------------------------
|
|
1224
|
-
*
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
1227
|
-
*
|
|
1228
|
-
*
|
|
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.
|
|
1229
1257
|
* @param {*} value The value to check.
|
|
1230
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`.
|
|
1231
1259
|
* @example
|
|
@@ -1238,19 +1266,20 @@ declare function isLength(value:unknown):boolean;
|
|
|
1238
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
|
-
* * ***
|
|
1269
|
+
* * ***Predicate: `isMatch`.***
|
|
1242
1270
|
* ----------------------------------------------------
|
|
1243
|
-
*
|
|
1244
|
-
*
|
|
1245
|
-
*
|
|
1246
|
-
* -
|
|
1247
|
-
*
|
|
1248
|
-
*
|
|
1249
|
-
*
|
|
1250
|
-
* -
|
|
1251
|
-
*
|
|
1252
|
-
*
|
|
1253
|
-
*
|
|
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`.
|
|
1254
1283
|
* @param {object} object - The object to inspect.
|
|
1255
1284
|
* @param {object} source - The object containing property values to match.
|
|
1256
1285
|
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
|
@@ -1266,25 +1295,25 @@ declare function isMap<K=unknown,V=unknown>(value:Map<K,V>):value is Map<K,V>;de
|
|
|
1266
1295
|
*/
|
|
1267
1296
|
declare function isMatch(object:object,source:object):boolean;
|
|
1268
1297
|
/** ----------------------------------------------------
|
|
1269
|
-
* * ***
|
|
1270
|
-
* like `isMatch`, but with a `customizer` function to control comparisons.***
|
|
1298
|
+
* * ***Predicate: `isMatchWith`.***
|
|
1271
1299
|
* ----------------------------------------------------
|
|
1300
|
+
* **Performs a partial deep comparison between `object` and `source`, like `isMatch`, but with a `customizer` function to control comparisons.**
|
|
1301
|
+
* @description
|
|
1272
1302
|
* If `customizer` returns a value other than `undefined`, that value is used
|
|
1273
1303
|
* as the result of the comparison for the current property. Otherwise,
|
|
1274
1304
|
* the comparison falls back to the default deep equality logic.
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1277
|
-
*
|
|
1278
|
-
*
|
|
1279
|
-
*
|
|
1280
|
-
*
|
|
1281
|
-
*
|
|
1282
|
-
*
|
|
1283
|
-
* @param {
|
|
1284
|
-
* @param {
|
|
1285
|
-
* @param {
|
|
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.
|
|
1286
1316
|
* @returns Returns `true` if `object` is a match, else `false`.
|
|
1287
|
-
*
|
|
1288
1317
|
* @example
|
|
1289
1318
|
* function isGreeting(value: unknown) {
|
|
1290
1319
|
* return typeof value === 'string' && /^h(?:i|ello)$/.test(value);
|
|
@@ -1302,16 +1331,17 @@ declare function isMatch(object:object,source:object):boolean;
|
|
|
1302
1331
|
* isMatchWith(object, source, customizer);
|
|
1303
1332
|
* // ➔ true
|
|
1304
1333
|
*/
|
|
1305
|
-
declare function isMatchWith(value:object,other:object,customizer?:
|
|
1334
|
+
declare function isMatchWith(value:object,other:object,customizer?:CustomizerIsMatchWith):boolean;
|
|
1306
1335
|
/** ----------------------------------------------------
|
|
1307
1336
|
* * ***Type guard: `isNaN`.***
|
|
1308
1337
|
* ----------------------------------------------------
|
|
1309
|
-
*
|
|
1310
|
-
*
|
|
1311
|
-
*
|
|
1312
|
-
*
|
|
1313
|
-
*
|
|
1314
|
-
*
|
|
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.
|
|
1315
1345
|
* @param {*} value The value to check.
|
|
1316
1346
|
* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
|
|
1317
1347
|
* @example
|
|
@@ -1332,19 +1362,16 @@ declare function isNaN(value:unknown):boolean;
|
|
|
1332
1362
|
/** ----------------------------------------------------
|
|
1333
1363
|
* * ***Type guard: `isNative`.***
|
|
1334
1364
|
* ----------------------------------------------------------
|
|
1335
|
-
*
|
|
1336
|
-
*
|
|
1337
|
-
* **Note:**
|
|
1365
|
+
* **Checks if a value is a **pristine native function**.**
|
|
1366
|
+
* - **ℹ️ Note:**
|
|
1338
1367
|
* - This method may not reliably detect native functions when using packages
|
|
1339
|
-
*
|
|
1340
|
-
* - Attempts to detect native functions
|
|
1341
|
-
*
|
|
1368
|
+
* like `core-js`, as they override native behavior.
|
|
1369
|
+
* - Attempts to detect native functions in such environments may fail or
|
|
1370
|
+
* throw errors.
|
|
1342
1371
|
* - This also affects packages like
|
|
1343
|
-
*
|
|
1344
|
-
*
|
|
1372
|
+
* **[`babel-polyfill`](https://www.npmjs.com/package/babel-polyfill).**
|
|
1345
1373
|
* @param {*} value The value to check.
|
|
1346
|
-
* @returns {boolean} Returns `true` if `value` is a native function,
|
|
1347
|
-
* else `false`.
|
|
1374
|
+
* @returns {boolean} Returns `true` if `value` is a native function, else `false`.
|
|
1348
1375
|
* @example
|
|
1349
1376
|
* isNative(Array.prototype.push);
|
|
1350
1377
|
* // ➔ true
|
|
@@ -1353,12 +1380,13 @@ declare function isNaN(value:unknown):boolean;
|
|
|
1353
1380
|
* isNative(RzlUtilsJs);
|
|
1354
1381
|
* // ➔ false
|
|
1355
1382
|
*/
|
|
1356
|
-
declare function isNative(value
|
|
1383
|
+
declare function isNative(value:unknown):value is AnyFunction;
|
|
1357
1384
|
/** ----------------------------------------------------
|
|
1358
1385
|
* * ***Type guard: `isNil`.***
|
|
1359
1386
|
* ----------------------------------------------------------
|
|
1360
|
-
*
|
|
1361
|
-
*
|
|
1387
|
+
* **Checks if a value is `null` or `undefined`.**
|
|
1388
|
+
* - **Behavior:**
|
|
1389
|
+
* - Narrows type to `null` or `undefined` when true.
|
|
1362
1390
|
* @param {*} value - The value to check.
|
|
1363
1391
|
* @returns {boolean} Returns `true` if the value is `null` or `undefined`, otherwise `false`.
|
|
1364
1392
|
* @example
|
|
@@ -1371,20 +1399,18 @@ declare function isNative(value?:unknown):value is AnyFunction;
|
|
|
1371
1399
|
* isNil(NaN);
|
|
1372
1400
|
* // ➔ false
|
|
1373
1401
|
*/
|
|
1374
|
-
declare function isNil(value
|
|
1402
|
+
declare function isNil(value:unknown):value is null|undefined;
|
|
1375
1403
|
/** ----------------------------------------------------------
|
|
1376
1404
|
* * ***Type guard: `isNonEmptyArray`.***
|
|
1377
1405
|
* ----------------------------------------------------------
|
|
1378
|
-
*
|
|
1379
|
-
*
|
|
1380
|
-
*
|
|
1381
|
-
*
|
|
1382
|
-
*
|
|
1383
|
-
*
|
|
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.
|
|
1384
1411
|
* @template T - The type of the value being checked.
|
|
1385
1412
|
* @param {*} value - The value to check.
|
|
1386
1413
|
* @returns {boolean} Return `true` if value is a non-empty array.
|
|
1387
|
-
*
|
|
1388
1414
|
* @example
|
|
1389
1415
|
* isNonEmptyArray([1, 2, 3]); // ➔ true
|
|
1390
1416
|
* isNonEmptyArray([]); // ➔ false
|
|
@@ -1400,20 +1426,17 @@ trim?:boolean;};
|
|
|
1400
1426
|
/** ----------------------------------------------------------
|
|
1401
1427
|
* * ***Type guard: `isNonEmptyString`.***
|
|
1402
1428
|
* ----------------------------------------------------------
|
|
1403
|
-
*
|
|
1404
|
-
*
|
|
1429
|
+
* **Checks if a value is a **non-empty string**.**
|
|
1430
|
+
* @description
|
|
1405
1431
|
* Determines whether the given `value` is a string containing at least one non-whitespace character, with optional trimming behavior.
|
|
1406
|
-
*
|
|
1407
|
-
*
|
|
1408
|
-
*
|
|
1409
|
-
*
|
|
1410
|
-
*
|
|
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.
|
|
1411
1436
|
* @param {*} value - The value to test.
|
|
1412
|
-
* @param {IsNonEmptyStringOptions} options - Optional settings.
|
|
1413
|
-
* @param {boolean} options.trim - If `true`, trims the string before checking
|
|
1414
|
-
*
|
|
1415
|
-
* @returns {boolean} `true` if `value` is a non-empty string, otherwise `false`.
|
|
1416
|
-
*
|
|
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`.
|
|
1417
1440
|
* @example
|
|
1418
1441
|
* isNonEmptyString("hello");
|
|
1419
1442
|
* // ➔ true
|
|
@@ -1435,28 +1458,34 @@ trim?:boolean;};
|
|
|
1435
1458
|
* // ➔ false
|
|
1436
1459
|
*/
|
|
1437
1460
|
declare const isNonEmptyString:(value:unknown,options?:IsNonEmptyStringOptions)=>value is string;type IsNonEmptyValueOptions={
|
|
1438
|
-
/**
|
|
1439
|
-
*
|
|
1461
|
+
/** Whether to check symbol properties when checking empty objects, default: `false`.
|
|
1462
|
+
*
|
|
1440
1463
|
* @default false
|
|
1441
1464
|
*/
|
|
1442
1465
|
checkSymbols?:boolean;};
|
|
1443
1466
|
/** ----------------------------------------------------------
|
|
1444
|
-
* * ***
|
|
1445
|
-
* or generally truthy.***
|
|
1467
|
+
* * ***Predicated: `isNonEmptyValue`.***
|
|
1446
1468
|
* ----------------------------------------------------------
|
|
1447
|
-
*
|
|
1448
|
-
* -
|
|
1449
|
-
*
|
|
1450
|
-
*
|
|
1451
|
-
*
|
|
1452
|
-
* -
|
|
1453
|
-
*
|
|
1454
|
-
*
|
|
1455
|
-
*
|
|
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.
|
|
1456
1486
|
* @param {*} value - The value to evaluate.
|
|
1457
|
-
* @param {IsNonEmptyValueOptions} options - Optional settings.
|
|
1458
|
-
* @returns `true` if the value is considered non-empty/truthy, otherwise `false`.
|
|
1459
|
-
*
|
|
1487
|
+
* @param {IsNonEmptyValueOptions} [options] - Optional settings.
|
|
1488
|
+
* @returns {boolean} Return `true` if the value is considered non-empty/truthy, otherwise `false`.
|
|
1460
1489
|
* @example
|
|
1461
1490
|
* isNonEmptyValue({});
|
|
1462
1491
|
* // ➔ false
|
|
@@ -1499,14 +1528,12 @@ declare const isNonEmptyValue:(value:unknown,options?:IsNonEmptyValueOptions)=>b
|
|
|
1499
1528
|
/** ---------------------------------------------------------
|
|
1500
1529
|
* * ***Type guard: `isNull`.***
|
|
1501
1530
|
* ----------------------------------------------------------
|
|
1502
|
-
*
|
|
1503
|
-
*
|
|
1504
|
-
*
|
|
1505
|
-
*
|
|
1506
|
-
*
|
|
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`.
|
|
1507
1535
|
* @param {*} val - The value to check.
|
|
1508
|
-
* @returns {
|
|
1509
|
-
*
|
|
1536
|
+
* @returns {boolean} Returns `true` if the value is `null`, otherwise `false`.
|
|
1510
1537
|
* @example
|
|
1511
1538
|
* isNull(null); // ➔ true
|
|
1512
1539
|
* isNull(0); // ➔ false
|
|
@@ -1516,32 +1543,27 @@ declare const isNull:(val:unknown)=>val is null;type HasKeys$1<T>=keyof T extend
|
|
|
1516
1543
|
/** ---------------------------------------------------------
|
|
1517
1544
|
* * ***Type guard: `isObject`.***
|
|
1518
1545
|
* ----------------------------------------------------------
|
|
1519
|
-
*
|
|
1520
|
-
*
|
|
1521
|
-
*
|
|
1522
|
-
* - ✅ Returns `true` for any non-null object (arrays excluded), including:
|
|
1523
|
-
* - Plain objects (`{}`, `Object.create(null)`)
|
|
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)`)
|
|
1524
1549
|
* - Custom class instances
|
|
1525
1550
|
* - Built-ins: `Date`, `RegExp`, `Error`, `URL`, `URLSearchParams`
|
|
1526
1551
|
* - Collections: `Map`, `Set`, `WeakMap`, `WeakSet`
|
|
1527
1552
|
* - Binary/typed data: `ArrayBuffer`, `DataView`, typed arrays (`Uint8Array`, `Int32Array`, etc.)
|
|
1528
1553
|
* - DOM/Node objects: `HTMLElement`, `DocumentFragment`, etc.
|
|
1529
1554
|
* - Proxies (wrapping any object type)
|
|
1530
|
-
*
|
|
1531
|
-
* - ❌ Returns `false` for:
|
|
1555
|
+
* - **❌ Returns `false` for:**
|
|
1532
1556
|
* - `null`
|
|
1533
1557
|
* - Arrays (`[]`, `new Array()`)
|
|
1534
1558
|
* - Functions (regular functions, arrow functions, class constructors)
|
|
1535
1559
|
* - Primitives: `string`, `number`, `boolean`, `symbol`, `bigint`
|
|
1536
1560
|
* - Boxed primitives: `new String()`, `new Number()`, `new Boolean()`
|
|
1537
1561
|
* - `undefined` (including `NaN`, which is a primitive number)
|
|
1538
|
-
*
|
|
1539
|
-
*
|
|
1540
|
-
*
|
|
1562
|
+
* - **ℹ️ Note:**
|
|
1563
|
+
* - If you specifically need to check for ***plain-objects***, use **{@link isPlainObject}** instead.
|
|
1541
1564
|
* @template T - The type of the value being checked.
|
|
1542
1565
|
* @param {*} value - The value to check.
|
|
1543
|
-
* @returns {boolean} Returns `true` if the value is a plain
|
|
1544
|
-
*
|
|
1566
|
+
* @returns {boolean} Returns `true` if the value is a ***plain-objects***, otherwise `false`.
|
|
1545
1567
|
* @example
|
|
1546
1568
|
* isObject({}); // ➔ true
|
|
1547
1569
|
* isObject(Object.create(null)); // ➔ true
|
|
@@ -1559,11 +1581,9 @@ declare function isObject<T extends object>(value:T):value is IsObject<T>;declar
|
|
|
1559
1581
|
/** ----------------------------------------------------------
|
|
1560
1582
|
* * ***Type guard: `isObjectLoose`.***
|
|
1561
1583
|
* ----------------------------------------------------------
|
|
1562
|
-
*
|
|
1563
|
-
*
|
|
1564
|
-
*
|
|
1565
|
-
*
|
|
1566
|
-
* - ✅ Returns `true` for:
|
|
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:**
|
|
1567
1587
|
* - Plain objects (`{}`)
|
|
1568
1588
|
* - Arrays (`[]`)
|
|
1569
1589
|
* - Functions
|
|
@@ -1572,8 +1592,7 @@ declare function isObject<T extends object>(value:T):value is IsObject<T>;declar
|
|
|
1572
1592
|
* - `new Number(0)`
|
|
1573
1593
|
* - `new String("")`
|
|
1574
1594
|
* - `new Boolean(false)`
|
|
1575
|
-
*
|
|
1576
|
-
* - ❌ Returns `false` for:
|
|
1595
|
+
* - **❌ Returns `false` for:**
|
|
1577
1596
|
* - `null`
|
|
1578
1597
|
* - `undefined`
|
|
1579
1598
|
* - Primitives:
|
|
@@ -1582,9 +1601,8 @@ declare function isObject<T extends object>(value:T):value is IsObject<T>;declar
|
|
|
1582
1601
|
* - `boolean`
|
|
1583
1602
|
* - `symbol`
|
|
1584
1603
|
* - `bigint`
|
|
1585
|
-
*
|
|
1586
|
-
*
|
|
1587
|
-
*
|
|
1604
|
+
* - **ℹ️ Note:**
|
|
1605
|
+
* - **For More Strict Object Use {@link isObject} or {@link isPlainObject} instead.**
|
|
1588
1606
|
* @template T - The type of the value being checked.
|
|
1589
1607
|
* @param {*} value The value to check.
|
|
1590
1608
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
@@ -1604,15 +1622,12 @@ declare function isObjectLoose<T=object>(value:unknown):value is T;type HasKeys<
|
|
|
1604
1622
|
/** ---------------------------------------------------------
|
|
1605
1623
|
* * ***Type guard: `isObjectOrArray`.***
|
|
1606
1624
|
* ----------------------------------------------------------
|
|
1607
|
-
*
|
|
1608
|
-
*
|
|
1609
|
-
*
|
|
1610
|
-
* - ✅ Returns `true` for:
|
|
1625
|
+
* **Checks if a value is an **object** or an **array**.**
|
|
1626
|
+
* - **✅ Returns `true` for:**
|
|
1611
1627
|
* - Plain objects (`{}`, `Object.create(null)`)
|
|
1612
1628
|
* - Custom objects
|
|
1613
1629
|
* - Arrays (`[]`, `[1,2,3]`)
|
|
1614
|
-
*
|
|
1615
|
-
* - ❌ Returns `false` for:
|
|
1630
|
+
* - **❌ Returns `false` for:**
|
|
1616
1631
|
* - `null`
|
|
1617
1632
|
* - `undefined`
|
|
1618
1633
|
* - Primitives:
|
|
@@ -1622,11 +1637,9 @@ declare function isObjectLoose<T=object>(value:unknown):value is T;type HasKeys<
|
|
|
1622
1637
|
* - `symbol`
|
|
1623
1638
|
* - `bigint`
|
|
1624
1639
|
* - Functions
|
|
1625
|
-
*
|
|
1626
1640
|
* @template T - The type of the value being checked.
|
|
1627
1641
|
* @param {*} value - The value to check.
|
|
1628
1642
|
* @returns {boolean} Returns `true` if the value is an `object` or `array`.
|
|
1629
|
-
*
|
|
1630
1643
|
* @example
|
|
1631
1644
|
* isObjectOrArray({ name: "Alice" }); // ➔ true
|
|
1632
1645
|
* isObjectOrArray([1,2,3]); // ➔ true
|
|
@@ -1636,13 +1649,38 @@ declare function isObjectLoose<T=object>(value:unknown):value is T;type HasKeys<
|
|
|
1636
1649
|
*/
|
|
1637
1650
|
declare function isObjectOrArray(value:[]):value is [];declare function isObjectOrArray<T>(value:T):value is IsObjectOrArray<T>;
|
|
1638
1651
|
/** ----------------------------------------------------------
|
|
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
|
+
/** ----------------------------------------------------------
|
|
1639
1679
|
* * ***Type guard: `isRegExp`.***
|
|
1640
1680
|
* ----------------------------------------------------------
|
|
1641
|
-
*
|
|
1642
|
-
*
|
|
1681
|
+
* **Checks if a value is a RegExp instance.**
|
|
1643
1682
|
* @param {*} value - The value to check.
|
|
1644
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)**.
|
|
1645
|
-
*
|
|
1646
1684
|
* @example
|
|
1647
1685
|
* isRegExp(/abc/); // ➔ true
|
|
1648
1686
|
* isRegExp(new RegExp("abc")); // ➔ true
|
|
@@ -1650,15 +1688,17 @@ declare function isObjectOrArray(value:[]):value is [];declare function isObject
|
|
|
1650
1688
|
*/
|
|
1651
1689
|
declare const isRegExp:(value:unknown)=>value is RegExp;
|
|
1652
1690
|
/** --------------------------------------------------
|
|
1653
|
-
* * ***
|
|
1691
|
+
* * ***Type guard: `isSafeInteger`.***
|
|
1654
1692
|
* --------------------------------------------------
|
|
1655
|
-
*
|
|
1656
|
-
* -
|
|
1657
|
-
*
|
|
1658
|
-
* -
|
|
1659
|
-
*
|
|
1660
|
-
*
|
|
1661
|
-
*
|
|
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}**.
|
|
1662
1702
|
* @param {*} value - The value to check.
|
|
1663
1703
|
* @returns {boolean} Return `true` if `value` is a safe integer, otherwise `false`.
|
|
1664
1704
|
* @example
|
|
@@ -1675,11 +1715,10 @@ declare function isSafeInteger(value:unknown):value is number;
|
|
|
1675
1715
|
/** ---------------------------------------------------------
|
|
1676
1716
|
* * ***Type guard: `isSet`.***
|
|
1677
1717
|
* ----------------------------------------------------------
|
|
1678
|
-
*
|
|
1679
|
-
*
|
|
1680
|
-
*
|
|
1681
|
-
*
|
|
1682
|
-
*
|
|
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.
|
|
1683
1722
|
* @template T - The type of the value being checked.
|
|
1684
1723
|
* @param {*} value - The value to check.
|
|
1685
1724
|
* @returns {boolean} Returns `true` if the value is a `Set`, otherwise `false`.
|
|
@@ -1693,15 +1732,13 @@ declare function isSet<T=unknown>(value:Set<T>):value is Set<T>;declare function
|
|
|
1693
1732
|
/** ---------------------------------------------------------
|
|
1694
1733
|
* * ***Type guard: `isString`.***
|
|
1695
1734
|
* ----------------------------------------------------------
|
|
1696
|
-
*
|
|
1697
|
-
* **[`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
|
|
1698
|
-
*
|
|
1699
|
-
*
|
|
1700
|
-
*
|
|
1701
|
-
*
|
|
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.
|
|
1702
1740
|
* @param {*} value - The value to check.
|
|
1703
1741
|
* @returns {boolean} Returns `true` if the value is a string, otherwise `false`.
|
|
1704
|
-
*
|
|
1705
1742
|
* @example
|
|
1706
1743
|
* isString("hello"); // ➔ true
|
|
1707
1744
|
* isString(123); // ➔ false
|
|
@@ -1717,15 +1754,13 @@ declare const isString:(value:unknown)=>value is string;
|
|
|
1717
1754
|
/** ----------------------------------------------------------
|
|
1718
1755
|
* * ***Type guard: `isSymbol`.***
|
|
1719
1756
|
* ----------------------------------------------------------
|
|
1720
|
-
*
|
|
1721
|
-
* **[`symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/Symbol)
|
|
1722
|
-
*
|
|
1723
|
-
*
|
|
1724
|
-
*
|
|
1725
|
-
*
|
|
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.
|
|
1726
1762
|
* @param {*} value - The value to check.
|
|
1727
1763
|
* @returns {boolean} Returns `true` if the value is a symbol, otherwise `false`.
|
|
1728
|
-
*
|
|
1729
1764
|
* @example
|
|
1730
1765
|
* isSymbol(Symbol("id")); // ➔ true
|
|
1731
1766
|
* isSymbol("not a symbol"); // ➔ false
|
|
@@ -1736,13 +1771,12 @@ declare const isSymbol:(value:unknown)=>value is symbol;
|
|
|
1736
1771
|
/** --------------------------------------------------
|
|
1737
1772
|
* * ***Type guard: `isTypedArray`.***
|
|
1738
1773
|
* ----------------------------------------------------------
|
|
1739
|
-
*
|
|
1740
|
-
* **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
|
|
1741
|
-
*
|
|
1742
|
-
*
|
|
1743
|
-
*
|
|
1744
|
-
*
|
|
1745
|
-
*
|
|
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.
|
|
1746
1780
|
* @param {*} value - The value to check.
|
|
1747
1781
|
* @returns {boolean} Returns `true` if the value is a typed array, otherwise `false`.
|
|
1748
1782
|
* @example
|
|
@@ -1757,15 +1791,13 @@ declare function isTypedArray(value:unknown):value is TypedArray;
|
|
|
1757
1791
|
/** ---------------------------------------------------------
|
|
1758
1792
|
* * ***Type guard: `isURL`.***
|
|
1759
1793
|
* ----------------------------------------------------------
|
|
1760
|
-
*
|
|
1761
|
-
* **[`URL`](https://developer.mozilla.org/docs/Web/API/URL)** class
|
|
1762
|
-
*
|
|
1763
|
-
*
|
|
1764
|
-
*
|
|
1765
|
-
*
|
|
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`.
|
|
1766
1799
|
* @param {*} value - The value to check.
|
|
1767
1800
|
* @returns {boolean} Returns `true` if the value is an instance of `URL`, otherwise `false`.
|
|
1768
|
-
*
|
|
1769
1801
|
* @example
|
|
1770
1802
|
* isURL(new URL("https://example.com"));
|
|
1771
1803
|
* // ➔ true
|
|
@@ -1776,14 +1808,14 @@ declare const isURL:(value:unknown)=>value is URL;
|
|
|
1776
1808
|
/** ---------------------------------------------------------
|
|
1777
1809
|
* * ***Type guard: `isUndefined`.***
|
|
1778
1810
|
* ----------------------------------------------------------
|
|
1779
|
-
*
|
|
1780
|
-
* **[`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)
|
|
1781
|
-
*
|
|
1782
|
-
*
|
|
1783
|
-
*
|
|
1784
|
-
*
|
|
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`.
|
|
1785
1817
|
* @param {*} value - The value to check.
|
|
1786
|
-
* @returns {
|
|
1818
|
+
* @returns {boolean} Returns `true` if the value is `undefined`, otherwise `false`.
|
|
1787
1819
|
* @example
|
|
1788
1820
|
* isUndefined(undefined); // ➔ true
|
|
1789
1821
|
* isUndefined([]); // ➔ false
|
|
@@ -1792,27 +1824,23 @@ declare const isURL:(value:unknown)=>value is URL;
|
|
|
1792
1824
|
* isUndefined("abc"); // ➔ false
|
|
1793
1825
|
*/
|
|
1794
1826
|
declare const isUndefined:(value:unknown)=>value is undefined;
|
|
1795
|
-
/**
|
|
1796
|
-
* * ***
|
|
1827
|
+
/** ---------------------------------------------------------
|
|
1828
|
+
* * ***Predicate: `isValidURL`.***
|
|
1797
1829
|
* ---------------------------------------------------------
|
|
1798
|
-
*
|
|
1799
|
-
* Ensures that the input is
|
|
1800
|
-
*
|
|
1801
|
-
*
|
|
1802
|
-
*
|
|
1803
|
-
*
|
|
1804
|
-
*
|
|
1805
|
-
* - ❌ Rejects invalid strings, unsupported schemes, and malformed domains.
|
|
1806
|
-
*
|
|
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.
|
|
1807
1837
|
* @param {*} url - The value to validate.
|
|
1808
1838
|
* @returns {boolean} Return `true` if the value is a **valid URL string**, otherwise `false`.
|
|
1809
1839
|
* @example
|
|
1810
1840
|
* isValidURL("https://example.com");
|
|
1811
1841
|
* // ➔ true
|
|
1812
|
-
*
|
|
1813
1842
|
* isValidURL("ftp://example.com");
|
|
1814
1843
|
* // ➔ false
|
|
1815
|
-
*
|
|
1816
1844
|
* isValidURL("not-a-url");
|
|
1817
1845
|
* // ➔ false
|
|
1818
1846
|
*/
|
|
@@ -1820,20 +1848,18 @@ declare const isValidURL:(url:unknown)=>boolean;
|
|
|
1820
1848
|
/** --------------------------------------------------
|
|
1821
1849
|
* * ***Type guard: `isWeakMap`.***
|
|
1822
1850
|
* ----------------------------------------------------------
|
|
1823
|
-
*
|
|
1824
|
-
*
|
|
1825
|
-
*
|
|
1826
|
-
*
|
|
1827
|
-
*
|
|
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`.
|
|
1828
1855
|
* @template K - Keys must be objects.
|
|
1829
1856
|
* @template V - Type of values stored in the WeakMap.
|
|
1830
1857
|
* @param {*} value - The value to check.
|
|
1831
1858
|
* @returns {boolean} Returns `true` if the value is a `WeakMap`, otherwise `false`.
|
|
1832
1859
|
* @example
|
|
1833
|
-
*
|
|
1834
1860
|
* isWeakMap(new WeakMap);
|
|
1835
1861
|
* // ➔ true
|
|
1836
1862
|
* isWeakMap(new Map);
|
|
1837
1863
|
* // ➔ false
|
|
1838
1864
|
*/
|
|
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};
|
|
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};
|