@rzl-zone/utils-js 3.0.2-beta.2 → 3.1.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/NumberRangeUnion-DC-C3_Kq.d.ts +23 -23
- package/dist/any-BmdI8UbK.d.ts +56 -56
- package/dist/arrays-normalize-recursive-CnjYJ9xg.d.ts +66 -66
- package/dist/assertions/index.cjs +1 -1
- package/dist/assertions/index.d.ts +398 -418
- package/dist/assertions/index.js +1 -1
- package/dist/chunk-26W3VZIK.cjs +1 -0
- package/dist/chunk-2KRCHXFG.cjs +2 -0
- package/dist/chunk-33ZLH266.js +1 -0
- package/dist/{chunk-EXZ47NOW.js → chunk-4L4EJTNZ.js} +1 -1
- package/dist/chunk-5Q37AP7P.js +1 -0
- package/dist/chunk-7CHFAMS2.js +1 -0
- package/dist/chunk-7MMJZ6HS.js +1 -0
- package/dist/chunk-7TC6DE3J.cjs +1 -0
- package/dist/{chunk-XH6MCRLP.js → chunk-7VX33E3V.js} +1 -1
- package/dist/chunk-BEZPD44N.cjs +1 -0
- package/dist/chunk-BI263OHW.js +1 -0
- package/dist/chunk-CII6WWLO.cjs +1 -0
- package/dist/chunk-D5TYPCWU.cjs +1 -0
- package/dist/chunk-EEQY5QUG.js +1 -0
- package/dist/chunk-ESJYBIYH.js +1 -0
- package/dist/chunk-EWYPSKKM.js +1 -0
- package/dist/chunk-EXCOQLWX.cjs +1 -0
- package/dist/chunk-FWQVTMYA.cjs +1 -0
- package/dist/chunk-G4EWCRKS.js +1 -0
- package/dist/chunk-G7R5XZRM.cjs +1 -0
- package/dist/chunk-GGEV7LXX.cjs +1 -0
- package/dist/chunk-HJOZOENU.cjs +1 -0
- package/dist/{chunk-BYZAD3XN.cjs → chunk-IRDZVLNZ.cjs} +1 -1
- package/dist/chunk-IW73G523.cjs +1 -0
- package/dist/chunk-IY5OZAB3.cjs +1 -0
- package/dist/chunk-J4NCYYGS.js +1 -0
- package/dist/chunk-J7JAZAJD.js +1 -0
- package/dist/{chunk-FF76ISQ2.js → chunk-JYNSO7ZY.js} +1 -1
- package/dist/chunk-K3UVKYEU.js +1 -0
- package/dist/chunk-LQ76EDZG.js +1 -0
- package/dist/chunk-MROH35V3.cjs +1 -0
- package/dist/chunk-NJSAV73S.js +1 -0
- package/dist/chunk-NR44SNYE.js +1 -0
- package/dist/chunk-NXMTWY77.js +1 -0
- package/dist/chunk-OZCQZO2V.cjs +4 -0
- package/dist/chunk-Q3NTKN5I.cjs +1 -0
- package/dist/chunk-QDNSC57Z.js +4 -0
- package/dist/chunk-QGXTL5ZH.js +2 -0
- package/dist/{chunk-JWHM3WZQ.cjs → chunk-QSQDP7L2.cjs} +1 -1
- package/dist/{chunk-RN3TP3S3.js → chunk-S5M33A4O.js} +1 -1
- package/dist/chunk-SGTHOQQ2.js +1 -0
- package/dist/chunk-SL3RQOWA.js +1 -0
- package/dist/chunk-SZPWZZYG.cjs +1 -0
- package/dist/chunk-UA4B7JBO.cjs +1 -0
- package/dist/chunk-UQDJF5RR.cjs +1 -0
- package/dist/chunk-UTQUYABU.cjs +1 -0
- package/dist/chunk-VPW3DRV5.js +1 -0
- package/dist/chunk-W32WALNU.js +1 -0
- package/dist/chunk-XGZ6K753.cjs +1 -0
- package/dist/chunk-YFTR64N5.cjs +1 -0
- package/dist/chunk-ZFDS7W6B.cjs +1 -0
- package/dist/chunk-ZQOLZE6Z.cjs +1 -0
- package/dist/conversions/index.cjs +1 -1
- package/dist/conversions/index.d.ts +1307 -1504
- package/dist/conversions/index.js +1 -1
- package/dist/env/index.d.ts +14 -17
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.d.ts +111 -108
- package/dist/events/index.js +1 -1
- package/dist/extends-Bk_SBGdT.d.ts +367 -0
- package/dist/formatting/index.cjs +1 -1
- package/dist/formatting/index.d.ts +878 -840
- package/dist/formatting/index.js +1 -1
- package/dist/generator/index.cjs +1 -1
- package/dist/generator/index.d.ts +173 -150
- package/dist/generator/index.js +1 -1
- package/dist/if-CvT4R7Kh.d.ts +16 -16
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/is-array--YjXV-Wx.d.ts +1207 -0
- package/dist/isPlainObject-BVhBAPHX.d.ts +169 -0
- package/dist/never-BfayMBF9.d.ts +64 -64
- package/dist/next/index.cjs +6 -6
- package/dist/next/index.d.ts +196 -176
- package/dist/next/index.js +5 -5
- package/dist/next/server/index.cjs +1 -1
- package/dist/next/server/index.d.ts +26 -40
- package/dist/next/server/index.js +1 -1
- package/dist/nils-DMz3kU7M.d.ts +155 -155
- package/dist/omit-VvmIsZmX.d.ts +25 -25
- package/dist/operations/index.cjs +1 -1
- package/dist/operations/index.d.ts +121 -176
- package/dist/operations/index.js +1 -1
- package/dist/parsers/index.cjs +1 -1
- package/dist/parsers/index.d.ts +35 -36
- package/dist/parsers/index.js +1 -1
- package/dist/predicates/index.cjs +1 -1
- package/dist/predicates/index.d.ts +1701 -1675
- package/dist/predicates/index.js +1 -1
- package/dist/prettify-C4xLcYOP.d.ts +328 -328
- package/dist/promise/index.cjs +1 -1
- package/dist/promise/index.d.ts +29 -38
- package/dist/promise/index.js +1 -1
- package/dist/rzl-utils.global.js +3 -3
- package/dist/string-XA-til3C.d.ts +351 -0
- package/dist/strings/index.cjs +1 -1
- package/dist/strings/index.d.ts +712 -787
- package/dist/strings/index.js +1 -1
- package/dist/stylings/index.cjs +1 -1
- package/dist/stylings/index.d.ts +37 -45
- package/dist/stylings/index.js +1 -1
- package/dist/type-data-DDs-u2kq.d.ts +241 -241
- package/dist/types/index.d.ts +3266 -3266
- package/dist/urls/index.cjs +1 -1
- package/dist/urls/index.d.ts +384 -409
- package/dist/urls/index.js +1 -1
- package/package.json +53 -11
- package/dist/array-CIZRbqTF.d.ts +0 -223
- package/dist/chunk-2TRAPBZ7.cjs +0 -1
- package/dist/chunk-3D74QO5D.cjs +0 -1
- package/dist/chunk-4DK3RCC4.js +0 -2
- package/dist/chunk-4JOQ45HL.js +0 -1
- package/dist/chunk-55CZALRS.js +0 -1
- package/dist/chunk-5JFV3GDE.cjs +0 -4
- 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-JFRL7NKU.js +0 -4
- package/dist/chunk-KCQDDZJE.cjs +0 -1
- package/dist/chunk-L54ZPSYJ.js +0 -1
- package/dist/chunk-LVKAYEZ4.js +0 -1
- package/dist/chunk-MBDWTK54.cjs +0 -1
- package/dist/chunk-MNGGDB2G.js +0 -1
- package/dist/chunk-MY7BA4GI.cjs +0 -1
- package/dist/chunk-N2IJPIND.cjs +0 -1
- package/dist/chunk-NIMNTEGV.js +0 -1
- package/dist/chunk-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-XCFIOTCV.js +0 -1
- package/dist/chunk-XE27XPJR.js +0 -1
- package/dist/chunk-XVB3ZZEB.js +0 -1
- package/dist/chunk-ZBSIGJFO.cjs +0 -1
- package/dist/chunk-ZYAML74V.js +0 -1
- package/dist/extends-Mp81Hq9-.d.ts +0 -145
- package/dist/is-array-Ckm_47hw.d.ts +0 -1557
- package/dist/isPlainObject-BKYaI6a8.d.ts +0 -182
|
@@ -1,428 +1,408 @@
|
|
|
1
|
-
import{G as GetPreciseTypeOptions,I as IsNumberOptions,a as IsPlainObjectResult}from'../isPlainObject-
|
|
1
|
+
import{G as GetPreciseTypeOptions,I as IsNumberOptions,a as IsPlainObjectResult}from'../isPlainObject-BVhBAPHX.js';import'../type-data-DDs-u2kq.js';
|
|
2
2
|
/** -------------------------------------------------------
|
|
3
|
-
* * ***Shape of the object passed to custom error message functions.***
|
|
4
|
-
* -------------------------------------------------------
|
|
5
|
-
* This type describes the parameters received when `options.message`
|
|
6
|
-
* is defined as a function in `
|
|
7
|
-
*
|
|
8
|
-
* - `currentType` ➔ the actual detected runtime type of the value.
|
|
9
|
-
* - `validType` ➔ the required/expected type name that the value must match.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* const options:
|
|
14
|
-
* message: ({ currentType, validType }) =>
|
|
15
|
-
* `Expected ${validType} but got ${currentType}`
|
|
16
|
-
* };
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
type
|
|
3
|
+
* * ***Shape of the object passed to custom error message functions.***
|
|
4
|
+
* -------------------------------------------------------
|
|
5
|
+
* This type describes the parameters received when `options.message`
|
|
6
|
+
* is defined as a function in `OptionsAssertIs`.
|
|
7
|
+
*
|
|
8
|
+
* - `currentType` ➔ the actual detected runtime type of the value.
|
|
9
|
+
* - `validType` ➔ the required/expected type name that the value must match.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const options: OptionsAssertIs = {
|
|
14
|
+
* message: ({ currentType, validType }) =>
|
|
15
|
+
* `Expected ${validType} but got ${currentType}`
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
type OptionsMessageFunctionAssertIs={
|
|
20
20
|
/** The actual runtime type of the value being checked.
|
|
21
|
-
*
|
|
22
|
-
* - Example: `"number"`, `"big-int"`, `"plain-object"`, (depends `formatCase` options).
|
|
23
|
-
*/
|
|
21
|
+
*
|
|
22
|
+
* - Example: `"number"`, `"big-int"`, `"plain-object"`, (depends `formatCase` options).
|
|
23
|
+
*/
|
|
24
24
|
currentType:string;
|
|
25
25
|
/** The required/expected type that the value must conform to.
|
|
26
|
-
*
|
|
27
|
-
* - Example: `"boolean"`, `"string"`, `"big-int"`, `"plain-object"`, (will force format to `kebab-case`).
|
|
28
|
-
*/
|
|
29
|
-
validType:string;};type
|
|
30
|
-
/** Custom error message for assertion failures.
|
|
31
|
-
*
|
|
32
|
-
* This option allows overriding the **default error message** when a value
|
|
33
|
-
* does not match the required type.
|
|
34
|
-
*
|
|
35
|
-
* - If a **string** is provided:
|
|
36
|
-
* - Must be non-empty after trimming.
|
|
37
|
-
* - Will be used directly as the error message.
|
|
38
|
-
*
|
|
39
|
-
* - If a **function** is provided:
|
|
40
|
-
* - Receives an object containing:
|
|
41
|
-
* - `currentType` ➔ the detected runtime type of the value (depends `formatCase` options, e.g., `"number"`).
|
|
42
|
-
* - `validType` ➔ the expected type name (with format `kebab-case`, e.g., `"boolean"`, `"big-int"`, `"plain-object"`).
|
|
43
|
-
* - Must return a string. If the returned string is empty or whitespace,
|
|
44
|
-
* the default message will be used instead.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* // Static message
|
|
49
|
-
* { message: "Must be a boolean!" }
|
|
50
|
-
*
|
|
51
|
-
* // Dynamic message
|
|
52
|
-
* {
|
|
53
|
-
* message: ({ currentType, validType }) =>
|
|
54
|
-
* `Expected ${validType} but got ${currentType}`
|
|
55
|
-
* }
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
message?:string|(({currentType,validType}:AssertIsOptionsMessageFunction)=>string);}& GetPreciseTypeOptions;
|
|
26
|
+
*
|
|
27
|
+
* - Example: `"boolean"`, `"string"`, `"big-int"`, `"plain-object"`, (will force format to `kebab-case`).
|
|
28
|
+
*/
|
|
29
|
+
validType:string;};type OptionsAssertIs={
|
|
59
30
|
/** -------------------------------------------------------
|
|
60
|
-
* * ***
|
|
61
|
-
* -------------------------------------------------------
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* @
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
* assertIsBoolean(42, { message: "Must be boolean!" });
|
|
92
|
-
* // ➔ TypeError: "Must be boolean!"
|
|
93
|
-
*
|
|
94
|
-
* // ❌ Throws with custom function message + case formatting
|
|
95
|
-
* assertIsBoolean(123n, {
|
|
96
|
-
* message: ({ currentType, validType }) =>
|
|
97
|
-
* `Expected ${validType} but got (${currentType}).`,
|
|
98
|
-
* formatCase: "toKebabCase"
|
|
99
|
-
* });
|
|
100
|
-
* // ➔ TypeError: "Expected boolean but got (big-int)."
|
|
101
|
-
* ```
|
|
102
|
-
*
|
|
103
|
-
* -------------------------------------------------------
|
|
104
|
-
* ✅ ***Real-world usage example***:
|
|
105
|
-
* ```ts
|
|
106
|
-
* type User = { name: string; email: string };
|
|
107
|
-
*
|
|
108
|
-
* const mixedValue: string | User | boolean | number | undefined = getUserInput();
|
|
109
|
-
*
|
|
110
|
-
* // ❌ Throws if not boolean
|
|
111
|
-
* // ⚠️ Code below after this call, will NOT be executed if TypeError is thrown
|
|
112
|
-
* assertIsBoolean(mixedValue, { message: "Must be boolean!" });
|
|
113
|
-
*
|
|
114
|
-
* // ✅ After this call, TypeScript knows `mixedValue` is boolean
|
|
115
|
-
* const result: boolean = mixedValue; // ➔ Safe to use
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
declare const assertIsBoolean:(value:unknown,options?:AssertIsOptions)=>asserts value is boolean;
|
|
31
|
+
* * ***Custom error message for assertion failures.***
|
|
32
|
+
* -------------------------------------------------------
|
|
33
|
+
*
|
|
34
|
+
* @description
|
|
35
|
+
* This option allows overriding the **default error message** when a value
|
|
36
|
+
* does not match the required type.
|
|
37
|
+
*
|
|
38
|
+
* - If a **string** is provided:
|
|
39
|
+
* - Must be non-empty after trimming.
|
|
40
|
+
* - Will be used directly as the error message.
|
|
41
|
+
*
|
|
42
|
+
* - If a **function** is provided:
|
|
43
|
+
* - Receives an object containing:
|
|
44
|
+
* - `currentType` ➔ the detected runtime type of the value (depends `formatCase` options, e.g., `"number"`).
|
|
45
|
+
* - `validType` ➔ the expected type name (with format `kebab-case`, e.g., `"boolean"`, `"big-int"`, `"plain-object"`).
|
|
46
|
+
* - Must return a string. If the returned string is empty or whitespace,
|
|
47
|
+
* the default message will be used instead.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* // Static message
|
|
52
|
+
* { message: "Must be a boolean!" }
|
|
53
|
+
*
|
|
54
|
+
* // Dynamic message
|
|
55
|
+
* {
|
|
56
|
+
* message: ({ currentType, validType }) =>
|
|
57
|
+
* `Expected ${validType} but got ${currentType}`
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
message?:string|(({currentType,validType}:OptionsMessageFunctionAssertIs)=>string);}& GetPreciseTypeOptions;
|
|
119
62
|
/** -------------------------------------------------------
|
|
120
|
-
* * ***
|
|
121
|
-
* -------------------------------------------------------
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* -
|
|
126
|
-
* -
|
|
127
|
-
* -
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* //
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* ```
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
* // ❌ Throws if not bigint
|
|
174
|
-
* // ⚠️ Code below after this call, will NOT be executed if TypeError is thrown
|
|
175
|
-
* assertIsBigInt(mixedValue, { message: "Must be a bigint!" });
|
|
176
|
-
*
|
|
177
|
-
* // ✅ After this call, TypeScript knows `mixedValue` is bigint
|
|
178
|
-
* const result: bigint = mixedValue; // ➔ Safe to use
|
|
179
|
-
* console.log(result + 100n);
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
declare const assertIsBigInt:(value:unknown,options?:AssertIsOptions)=>asserts value is bigint;type AssertIsNumberOptions=AssertIsOptions & IsNumberOptions;
|
|
63
|
+
* * ***Type guard assertion: `assertIsBoolean`.***
|
|
64
|
+
* -------------------------------------------------------
|
|
65
|
+
* **This function is an **assertion function**.**
|
|
66
|
+
* - Validates that the given `value` is a **boolean**.
|
|
67
|
+
* - After it returns successfully, TypeScript narrows the type of `value` to `boolean`.
|
|
68
|
+
* - **Behavior:**
|
|
69
|
+
* - ✅ If `value` is a `boolean` ➔ execution continues normally.
|
|
70
|
+
* - ❌ If `value` is not a `boolean` ➔ throws a `TypeError` with either:
|
|
71
|
+
* - A custom error message (`options.message`), or
|
|
72
|
+
* - A default message including the actual type.
|
|
73
|
+
* @param {*} value - The value to validate.
|
|
74
|
+
* @param {OptionsAssertIs} [options] - Optional configuration:
|
|
75
|
+
* - `message`: A custom error message (`string` or `function`).
|
|
76
|
+
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
77
|
+
* @returns {boolean} Narrows `value` to `boolean` if no error is thrown.
|
|
78
|
+
* @throws {TypeError} If the value is not a boolean.
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* // ✅ Simple usage
|
|
82
|
+
* assertIsBoolean(true);
|
|
83
|
+
* // No error, value is boolean
|
|
84
|
+
*
|
|
85
|
+
* // ❌ Throws TypeError with default message
|
|
86
|
+
* assertIsBoolean(42);
|
|
87
|
+
* // ➔ TypeError: "Parameter input (`value`) must be of type `boolean`, but received: `number`."
|
|
88
|
+
*
|
|
89
|
+
* // ❌ Throws with custom string message
|
|
90
|
+
* assertIsBoolean(42, { message: "Must be boolean!" });
|
|
91
|
+
* // ➔ TypeError: "Must be boolean!"
|
|
92
|
+
*
|
|
93
|
+
* // ❌ Throws with custom function message + case formatting
|
|
94
|
+
* assertIsBoolean(123n, {
|
|
95
|
+
* message: ({ currentType, validType }) =>
|
|
96
|
+
* `Expected ${validType} but got (${currentType}).`,
|
|
97
|
+
* formatCase: "toKebabCase"
|
|
98
|
+
* });
|
|
99
|
+
* // ➔ TypeError: "Expected boolean but got (big-int)."
|
|
100
|
+
* ```
|
|
101
|
+
* -------------------------------------------------------
|
|
102
|
+
* ✅ ***Real-world usage example***:
|
|
103
|
+
* ```ts
|
|
104
|
+
* type User = { name: string; email: string };
|
|
105
|
+
* const mixedValue: string | User | boolean | number | undefined = getUserInput();
|
|
106
|
+
*
|
|
107
|
+
* // ❌ Throws if not boolean
|
|
108
|
+
* // ⚠️ Code below after this call, will NOT be executed if TypeError is thrown
|
|
109
|
+
* assertIsBoolean(mixedValue, { message: "Must be boolean!" });
|
|
110
|
+
*
|
|
111
|
+
* // ✅ After this call, TypeScript knows `mixedValue` is boolean
|
|
112
|
+
* const result: boolean = mixedValue; // ➔ Safe to use
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
declare const assertIsBoolean:(value:unknown,options?:OptionsAssertIs)=>asserts value is boolean;
|
|
183
116
|
/** -------------------------------------------------------
|
|
184
|
-
* * ***
|
|
185
|
-
* -------------------------------------------------------
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* -
|
|
189
|
-
* -
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* @
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* //
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
* // No error
|
|
241
|
-
* ```
|
|
242
|
-
*
|
|
243
|
-
* -------------------------------------------------------
|
|
244
|
-
* ✅ ***Real-world usage example***:
|
|
245
|
-
* ```ts
|
|
246
|
-
* const mixedValue: string | number | undefined = getUserInput();
|
|
247
|
-
*
|
|
248
|
-
* // ❌ Throws if not number
|
|
249
|
-
* // ⚠️ Code below after this call, will NOT be executed if TypeError is thrown
|
|
250
|
-
* assertIsNumber(mixedValue, { message: "Must be a number!" });
|
|
251
|
-
*
|
|
252
|
-
* // ✅ After this call, TypeScript knows `mixedValue` is number
|
|
253
|
-
* const result: number = mixedValue; // ➔ Safe to use
|
|
254
|
-
* console.log(result + 100);
|
|
255
|
-
* ```
|
|
256
|
-
*/
|
|
257
|
-
declare const assertIsNumber:(value:unknown,options?:AssertIsNumberOptions)=>asserts value is number;
|
|
117
|
+
* * ***Type guard assertion: `assertIsBigInt`.***
|
|
118
|
+
* -------------------------------------------------------
|
|
119
|
+
* **This function is an **assertion function**.**
|
|
120
|
+
* - Validates that the given `value` is a **bigint**.
|
|
121
|
+
* - After it returns successfully, TypeScript narrows the type of `value` to `bigint`.
|
|
122
|
+
* - **Behavior:**
|
|
123
|
+
* - ✅ If `value` is a `bigint` ➔ execution continues normally.
|
|
124
|
+
* - ❌ If `value` is not a `bigint` ➔ throws a `TypeError` with either:
|
|
125
|
+
* - A custom error message (`options.message`), or
|
|
126
|
+
* - A default message including the actual type.
|
|
127
|
+
* - **ℹ️ Note:**
|
|
128
|
+
* - A `bigint` refers strictly to the JavaScript `bigint` primitive type (e.g., `123n`, `0n`, `-999999999999999999999n`).
|
|
129
|
+
* - This excludes `BigInt` objects created with `Object(BigInt(123))`.
|
|
130
|
+
* @param {*} value - The value to validate.
|
|
131
|
+
* @param {OptionsAssertIs} [options] - Optional configuration:
|
|
132
|
+
* - `message`: A custom error message (`string` or `function`).
|
|
133
|
+
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
134
|
+
* @returns {boolean} Narrows `value` to `bigint` if no error is thrown.
|
|
135
|
+
* @throws {TypeError} If the value is not a bigint.
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* // ✅ Simple usage
|
|
139
|
+
* assertIsBigInt(123n);
|
|
140
|
+
* // No error, value is bigint
|
|
141
|
+
*
|
|
142
|
+
* // ❌ Throws TypeError with default message
|
|
143
|
+
* assertIsBigInt(42);
|
|
144
|
+
* // ➔ TypeError: "Parameter input (`value`) must be of type `bigint`, but received: `number`."
|
|
145
|
+
*
|
|
146
|
+
* // ❌ Throws with custom string message
|
|
147
|
+
* assertIsBigInt("123", { message: "Must be a bigint!" });
|
|
148
|
+
* // ➔ TypeError: "Must be a bigint!"
|
|
149
|
+
*
|
|
150
|
+
* // ❌ Throws with custom function message + case formatting
|
|
151
|
+
* assertIsBigInt(42, {
|
|
152
|
+
* message: ({ currentType, validType }) =>
|
|
153
|
+
* `Expected ${validType} but got (${currentType}).`,
|
|
154
|
+
* formatCase: "toKebabCase"
|
|
155
|
+
* });
|
|
156
|
+
* // ➔ TypeError: "Expected bigint but got (number)."
|
|
157
|
+
* ```
|
|
158
|
+
* -------------------------------------------------------
|
|
159
|
+
* ✅ ***Real-world usage example***:
|
|
160
|
+
* ```ts
|
|
161
|
+
* const mixedValue: string | bigint | undefined = getUserInput();
|
|
162
|
+
*
|
|
163
|
+
* // ❌ Throws if not bigint
|
|
164
|
+
* // ⚠️ Code below after this call, will NOT be executed if TypeError is thrown
|
|
165
|
+
* assertIsBigInt(mixedValue, { message: "Must be a bigint!" });
|
|
166
|
+
*
|
|
167
|
+
* // ✅ After this call, TypeScript knows `mixedValue` is bigint
|
|
168
|
+
* const result: bigint = mixedValue; // ➔ Safe to use
|
|
169
|
+
* console.log(result + 100n);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
declare const assertIsBigInt:(value:unknown,options?:OptionsAssertIs)=>asserts value is bigint;type OptionsAssertIsNumber=OptionsAssertIs & IsNumberOptions;
|
|
258
173
|
/** -------------------------------------------------------
|
|
259
|
-
* * ***
|
|
260
|
-
* -------------------------------------------------------
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* -
|
|
264
|
-
* -
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* to `
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
* @param
|
|
275
|
-
*
|
|
276
|
-
* - `
|
|
277
|
-
* - `
|
|
278
|
-
*
|
|
279
|
-
* @
|
|
280
|
-
* @
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
* //
|
|
285
|
-
*
|
|
286
|
-
* //
|
|
287
|
-
*
|
|
288
|
-
* //
|
|
289
|
-
*
|
|
290
|
-
* //
|
|
291
|
-
*
|
|
292
|
-
* //
|
|
293
|
-
*
|
|
294
|
-
* //
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
* //
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* ✅
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
|
|
319
|
-
|
|
174
|
+
* * ***Type guard assertion: `assertIsNumber`.***
|
|
175
|
+
* -------------------------------------------------------
|
|
176
|
+
* **This function is an **assertion function**.**
|
|
177
|
+
* - Validates that the given `value` is a **number**.
|
|
178
|
+
* - After it returns successfully, TypeScript narrows the type of `value` to `number`.
|
|
179
|
+
* - **Behavior:**
|
|
180
|
+
* - ✅ If `value` is a `number` ➔ execution continues normally.
|
|
181
|
+
* - ❌ If `value` is not a `number` ➔ throws a `TypeError` with either:
|
|
182
|
+
* - A custom error message (`options.message`), or
|
|
183
|
+
* - A default message including the actual type.
|
|
184
|
+
* - **ℹ️ Note:**
|
|
185
|
+
* - A `number` refers strictly to the JavaScript `number` primitive type (e.g., `42`, `3.14`, `-1`, `0`).
|
|
186
|
+
* - This excludes `Number` objects created with `new Number(123)`.
|
|
187
|
+
* - By default, `NaN` is **not considered** valid, you can allow it with `{ includeNaN: true }`.
|
|
188
|
+
* @param {*} value - The value to validate.
|
|
189
|
+
* @param {OptionsAssertIsNumber} [options] - Optional configuration:
|
|
190
|
+
* - `message`: A custom error message (`string` or `function`).
|
|
191
|
+
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
192
|
+
* - `includeNaN`: Whether to treat `NaN` as valid.
|
|
193
|
+
* @returns {boolean} Narrows `value` to `number` if no error is thrown.
|
|
194
|
+
* @throws {TypeError} If the value is not a number (or is `NaN` when `includeNaN` is `false`).
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* // ✅ Simple usage
|
|
198
|
+
* assertIsNumber(123);
|
|
199
|
+
* // No error, value is number
|
|
200
|
+
*
|
|
201
|
+
* // ❌ Throws TypeError with default message
|
|
202
|
+
* assertIsNumber("42");
|
|
203
|
+
* // ➔ TypeError: "Parameter input (`value`) must be of type `number`, but received: `string`."
|
|
204
|
+
*
|
|
205
|
+
* // ❌ Throws with custom string message
|
|
206
|
+
* assertIsNumber(true, { message: "Must be a number!" });
|
|
207
|
+
* // ➔ TypeError: "Must be a number!"
|
|
208
|
+
*
|
|
209
|
+
* // ❌ Throws with custom function message + case formatting
|
|
210
|
+
* assertIsNumber("hello", {
|
|
211
|
+
* message: ({ currentType, validType }) =>
|
|
212
|
+
* `Expected ${validType} but got (${currentType}).`,
|
|
213
|
+
* formatCase: "toKebabCase"
|
|
214
|
+
* });
|
|
215
|
+
* // ➔ TypeError: "Expected number but got (string)."
|
|
216
|
+
*
|
|
217
|
+
* // ⚠️ NaN is invalid by default
|
|
218
|
+
* assertIsNumber(NaN);
|
|
219
|
+
* // ➔ TypeError: "Parameter input (`value`) must be of type `number`, but received: `NaN`."
|
|
220
|
+
*
|
|
221
|
+
* // ✅ Allow NaN explicitly
|
|
222
|
+
* assertIsNumber(NaN, { includeNaN: true });
|
|
223
|
+
* // No error
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* -------------------------------------------------------
|
|
227
|
+
* ✅ ***Real-world usage example***:
|
|
228
|
+
* ```ts
|
|
229
|
+
* const mixedValue: string | number | undefined = getUserInput();
|
|
230
|
+
*
|
|
231
|
+
* // ❌ Throws if not number
|
|
232
|
+
* // ⚠️ Code below after this call, will NOT be executed if TypeError is thrown
|
|
233
|
+
* assertIsNumber(mixedValue, { message: "Must be a number!" });
|
|
234
|
+
*
|
|
235
|
+
* // ✅ After this call, TypeScript knows `mixedValue` is number
|
|
236
|
+
* const result: number = mixedValue; // ➔ Safe to use
|
|
237
|
+
* console.log(result + 100);
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
declare const assertIsNumber:(value:unknown,options?:OptionsAssertIsNumber)=>asserts value is number;
|
|
320
241
|
/** -------------------------------------------------------
|
|
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
|
-
|
|
242
|
+
* * ***Type guard assertion: `assertIsArray`.***
|
|
243
|
+
* -------------------------------------------------------
|
|
244
|
+
* **This function is an **assertion function**.**
|
|
245
|
+
* - Validates that the given `value` is a **array**.
|
|
246
|
+
* - After it returns successfully, TypeScript narrows the type of `value` to `array` **(generic support)**.
|
|
247
|
+
* - **Behavior:**
|
|
248
|
+
* - ✅ If `value` is an `array` ➔ execution continues normally.
|
|
249
|
+
* - ❌ If `value` is not an `array` ➔ throws a `TypeError` with either:
|
|
250
|
+
* - A custom error message (`options.message`), or
|
|
251
|
+
* - A default message including the actual type.
|
|
252
|
+
* @template T - The input type being asserted.
|
|
253
|
+
* @param {*} value - The value to validate.
|
|
254
|
+
* @param {OptionsAssertIs} [options] - Optional configuration:
|
|
255
|
+
* - `message`: A custom error message (`string` or `function`).
|
|
256
|
+
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
257
|
+
* @returns {boolean} Narrows `value` to an `array` **(generic support)** if no error is thrown.
|
|
258
|
+
* @throws {TypeError} If the value is not an array.
|
|
259
|
+
* @example
|
|
260
|
+
* ```ts
|
|
261
|
+
* // ✅ Simple usage
|
|
262
|
+
* assertIsArray([1, 2, 3]);
|
|
263
|
+
* // No error, value is array
|
|
264
|
+
*
|
|
265
|
+
* // ❌ Throws TypeError with default message
|
|
266
|
+
* assertIsArray({ a: 1 });
|
|
267
|
+
* // ➔ TypeError: "Parameter input (`value`) must be of type `array`, but received: `plain-object`."
|
|
268
|
+
*
|
|
269
|
+
* // ❌ Throws with custom string message
|
|
270
|
+
* assertIsArray(42, { message: "Must be an array!" });
|
|
271
|
+
* // ➔ TypeError: "Must be an array!"
|
|
272
|
+
*
|
|
273
|
+
* // ❌ Throws with custom function message + case formatting
|
|
274
|
+
* assertIsArray(42n, {
|
|
275
|
+
* message: ({ currentType, validType }) =>
|
|
276
|
+
* `Expected ${validType} but got (${currentType}).`,
|
|
277
|
+
* formatCase: "toKebabCase"
|
|
278
|
+
* });
|
|
279
|
+
* // ➔ TypeError: "Expected array but got (big-int)."
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* -------------------------------------------------------
|
|
283
|
+
* ✅ ***Real-world usage with generic narrowing***:
|
|
284
|
+
* ```ts
|
|
285
|
+
* const mixedValue: string | number[] | undefined = getUserInput();
|
|
286
|
+
*
|
|
287
|
+
* // ❌ Throws if not array
|
|
288
|
+
* // ⚠️ Code below after this call, will NOT be executed if TypeError is thrown
|
|
289
|
+
* assertIsArray(mixedValue, { message: "Must be an array!" });
|
|
290
|
+
*
|
|
291
|
+
* // ✅ After this call, TypeScript knows `mixedValue` is narrowed to number[]
|
|
292
|
+
* const result: number[] = mixedValue; // ➔ Safe to use
|
|
293
|
+
* console.log(result.length);
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
declare function assertIsArray<T extends unknown[]>(value:T,options?:OptionsAssertIs):value is Extract<T,unknown[]>;declare function assertIsArray<T extends readonly unknown[]>(value:T,options?:OptionsAssertIs):value is Extract<T,readonly unknown[]>;declare function assertIsArray(value:unknown,options?:OptionsAssertIs):value is unknown[];
|
|
374
297
|
/** -------------------------------------------------------
|
|
375
|
-
* * ***
|
|
376
|
-
* -------------------------------------------------------
|
|
377
|
-
*
|
|
378
|
-
* -
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
* @
|
|
386
|
-
* @param {
|
|
387
|
-
* @
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* @
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
* })
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
* //
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
* // After this call, TypeScript knows `mixedValue` is
|
|
424
|
-
* const
|
|
425
|
-
* console.log(
|
|
426
|
-
* ```
|
|
427
|
-
*/
|
|
428
|
-
declare
|
|
298
|
+
* * ***Type guard assertion: `assertIsPlainObject`.***
|
|
299
|
+
* -------------------------------------------------------
|
|
300
|
+
* **This function is an **assertion function**.**
|
|
301
|
+
* - Validates that the given `value` is a **plain-object**.
|
|
302
|
+
* - After it returns successfully, TypeScript narrows the type of `value` to `plain-object` **(generic support)**.
|
|
303
|
+
* - **Behavior:**
|
|
304
|
+
* - ✅ If `value` is a `plain-object` ➔ execution continues normally.
|
|
305
|
+
* - ❌ If `value` is not a `plain-object` ➔ throws a `TypeError` with either:
|
|
306
|
+
* - A custom error message (`options.message`), or
|
|
307
|
+
* - A default message including the actual type.
|
|
308
|
+
* @template T - The input type being asserted.
|
|
309
|
+
* @param {*} value - The value to validate.
|
|
310
|
+
* @param {OptionsAssertIs} [options] - Optional configuration:
|
|
311
|
+
* - `message`: A custom error message (`string` or `function`).
|
|
312
|
+
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
313
|
+
* @returns {boolean} Narrows `value` to a `plain-object` **(generic support)** if no error is thrown.
|
|
314
|
+
* @throws {TypeError} If `value` is not a `plain-object`.
|
|
315
|
+
* @example
|
|
316
|
+
* ```ts
|
|
317
|
+
* // ✅ Simple usage
|
|
318
|
+
* assertIsPlainObject({ a: 1, b: 2 });
|
|
319
|
+
* // ➔ ok, value is plain object
|
|
320
|
+
*
|
|
321
|
+
* // ❌ Throws TypeError with default message
|
|
322
|
+
* assertIsPlainObject([1, 2, 3]);
|
|
323
|
+
* // ➔ TypeError: "Parameter input (`value`) must be of type `plain-object`, but received: `array`."
|
|
324
|
+
*
|
|
325
|
+
* // ❌ Throws with custom string message
|
|
326
|
+
* assertIsPlainObject("hello", { message: "Must be plain object!" });
|
|
327
|
+
* // ➔ TypeError: "Must be plain object!"
|
|
328
|
+
*
|
|
329
|
+
* // ❌ Throws with custom message function and formatCase
|
|
330
|
+
* assertIsPlainObject(42n, {
|
|
331
|
+
* message: ({ currentType, validType }) =>
|
|
332
|
+
* `Expected ${validType} but got (${currentType}).`,
|
|
333
|
+
* formatCase: "toKebabCase"
|
|
334
|
+
* });
|
|
335
|
+
* // ➔ TypeError: "Expected plain-object but got (big-int)."
|
|
336
|
+
* ```
|
|
337
|
+
* -------------------------------------------------------
|
|
338
|
+
* ✅ ***Real-world usage with generic narrowing***:
|
|
339
|
+
* ```ts
|
|
340
|
+
* type User = { name: string; email: string };
|
|
341
|
+
* const mixedValue: string | User | boolean | number | undefined = getUserInput();
|
|
342
|
+
*
|
|
343
|
+
* // Throws TypeError if not plain object
|
|
344
|
+
* assertIsPlainObject(mixedValue, { message: "Must be plain object!" });
|
|
345
|
+
*
|
|
346
|
+
* // After this call, TypeScript knows `mixedValue` is narrowed to User
|
|
347
|
+
* const user: User = mixedValue; // ➔ safe
|
|
348
|
+
* console.log(user.email); // ➔ type-safe
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
declare function assertIsPlainObject<T>(value:T,options?:OptionsAssertIs):asserts value is IsPlainObjectResult<T>;
|
|
352
|
+
/** -------------------------------------------------------
|
|
353
|
+
* * ***Type guard assertion: `assertIsString`.***
|
|
354
|
+
* -------------------------------------------------------
|
|
355
|
+
* **This function is an **assertion function**.**
|
|
356
|
+
* - Validates that the given `value` is a **primitive-string**.
|
|
357
|
+
* - After it returns successfully, TypeScript narrows the type of `value` to `primitive-string`.
|
|
358
|
+
* - **Behavior:**
|
|
359
|
+
* - ✅ If `value` is a `primitive-string` ➔ execution continues normally.
|
|
360
|
+
* - ❌ If `value` is not a `primitive-string` ➔ throws a `TypeError` with either:
|
|
361
|
+
* - A custom error message (`options.message`), or
|
|
362
|
+
* - A default message including the actual type.
|
|
363
|
+
* - **ℹ️ Note:**
|
|
364
|
+
* - A "string" refers strictly to a JavaScript `primitive-string` type (e.g., `"hello"`, `""`, `"123"`).
|
|
365
|
+
* - This function excludes `String` objects created with `new String()`.
|
|
366
|
+
* @param {*} value - The value to validate.
|
|
367
|
+
* @param {OptionsAssertIs} [options] - Optional configuration:
|
|
368
|
+
* - `message`: A custom error message (`string` or `function`).
|
|
369
|
+
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
370
|
+
* @returns {boolean} Narrows `value` to `string` if no error is thrown.
|
|
371
|
+
* @throws {TypeError} If the value is not a string.
|
|
372
|
+
* @example
|
|
373
|
+
* ```ts
|
|
374
|
+
* // ✅ Simple usage
|
|
375
|
+
* assertIsString("hello");
|
|
376
|
+
* // ➔ ✅ ok value is string, no error
|
|
377
|
+
*
|
|
378
|
+
* // ❌ Throws TypeError with default message
|
|
379
|
+
* assertIsString(42);
|
|
380
|
+
* // ➔ TypeError: "Parameter input (`value`) must be of type `string`, but received: `number`."
|
|
381
|
+
*
|
|
382
|
+
* // ❌ Throws with custom string message
|
|
383
|
+
* assertIsString(42, { message: "Must be a string!" });
|
|
384
|
+
* // ➔ TypeError: "Must be a string!"
|
|
385
|
+
*
|
|
386
|
+
* // ❌ Throws with custom message function and formatCase
|
|
387
|
+
* assertIsString(42n, {
|
|
388
|
+
* message: ({ currentType, validType }) => `Expected ${currentType} but got (${currentType}).`,
|
|
389
|
+
* formatCase: "toKebabCase"
|
|
390
|
+
* });
|
|
391
|
+
* // ➔ TypeError: "Expected string but got (big-int)."
|
|
392
|
+
* ```
|
|
393
|
+
* -------------------------------------------------------
|
|
394
|
+
* ✅ ***Real-world usage with generic narrowing***:
|
|
395
|
+
* ```ts
|
|
396
|
+
* type User = { name: string; email: string };
|
|
397
|
+
* const mixedValue: string | User | undefined = getUserInput();
|
|
398
|
+
*
|
|
399
|
+
* // Throws TypeError if the value is not string
|
|
400
|
+
* // ⚠️ Code below after this call, will NOT be executed if TypeError is thrown
|
|
401
|
+
* assertIsString(mixedValue, { message: "Must be a string!" });
|
|
402
|
+
*
|
|
403
|
+
* // After this call, TypeScript knows `mixedValue` is string
|
|
404
|
+
* const result: string = mixedValue; // ➔ ✅ safe to use
|
|
405
|
+
* console.log(result.toUpperCase()); // ➔ ✅ type-safe
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
declare const assertIsString:(value:unknown,options?:OptionsAssertIs)=>asserts value is string;export{assertIsArray,assertIsBigInt,assertIsBoolean,assertIsNumber,assertIsPlainObject,assertIsString};
|