@rzl-zone/utils-js 3.8.0 → 3.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/assertions/index.cjs +11 -11
- package/dist/assertions/index.d.ts +168 -57
- package/dist/assertions/index.js +5 -5
- package/dist/{chunk-EK7FSI7F.cjs → chunk-2XGQQZ6A.cjs} +3 -3
- package/dist/{chunk-YS27V6LS.js → chunk-3LE6NX57.js} +5 -176
- package/dist/{chunk-PZQC3FZY.js → chunk-44X74C26.js} +4 -4
- package/dist/{chunk-4ACKNPL5.js → chunk-5KDVIEVO.js} +2 -2
- package/dist/{chunk-JY4HLZ4W.js → chunk-5O66AUEC.js} +2 -2
- package/dist/{chunk-SLP24LUV.js → chunk-5Y6JL47L.js} +3 -3
- package/dist/{chunk-ZW3VYES4.cjs → chunk-62FS7WMB.cjs} +31 -31
- package/dist/{chunk-VJVCXEH7.cjs → chunk-6AMDHVS2.cjs} +9 -181
- package/dist/{chunk-5IKZ3JDV.js → chunk-6WVOUVWD.js} +9 -9
- package/dist/{chunk-BYUT376O.cjs → chunk-76ATVDCR.cjs} +3 -3
- package/dist/{chunk-F3WBQKRI.cjs → chunk-7C7TQC5J.cjs} +29 -7
- package/dist/{chunk-I3IXLEEG.js → chunk-7EIFPHV3.js} +8 -8
- package/dist/{chunk-6RFNZ2ZZ.cjs → chunk-7NXFGJJE.cjs} +14 -14
- package/dist/{chunk-TFDXRT6D.cjs → chunk-ALRISPTL.cjs} +3 -3
- package/dist/chunk-BAV5T2E3.cjs +1 -1
- package/dist/{chunk-4ZOXSUXB.js → chunk-C7GC2PFX.js} +3 -3
- package/dist/chunk-DVMHRLKP.cjs +1 -1
- package/dist/{chunk-KVZ3HL2B.js → chunk-DXPM4NOU.js} +4 -4
- package/dist/{chunk-DPLL67OT.js → chunk-EJV5AF4L.js} +2 -2
- package/dist/{chunk-NREACG6M.cjs → chunk-FWWPEL7J.cjs} +3 -3
- package/dist/{chunk-LEX4TQW2.js → chunk-GHU356XQ.js} +4 -6
- package/dist/chunk-GKDSBOYE.js +209 -0
- package/dist/{chunk-YC7AK3KX.cjs → chunk-H44QVAZL.cjs} +31 -31
- package/dist/{chunk-AKKM6MOX.cjs → chunk-I33PB44Q.cjs} +15 -15
- package/dist/{chunk-LIU4S3JA.cjs → chunk-IX6PF5ZP.cjs} +4 -4
- package/dist/{chunk-3KTD3QDI.js → chunk-J4TT33ZX.js} +29 -7
- package/dist/{chunk-SZJ7OI4S.js → chunk-J6VLFVIL.js} +3 -3
- package/dist/{chunk-3JD53UUH.cjs → chunk-JI57K7D4.cjs} +161 -161
- package/dist/{chunk-OFBFGFVH.js → chunk-JYOCB6OV.js} +2 -2
- package/dist/chunk-KHO2SBNA.cjs +1 -1
- package/dist/{chunk-6NORJBI6.cjs → chunk-KUVRZ2JW.cjs} +50 -50
- package/dist/chunk-L5RDAVVH.js +1 -1
- package/dist/{chunk-VCVND6CH.js → chunk-M5QB2GM5.js} +2 -2
- package/dist/{chunk-RRJIRXHS.js → chunk-MBFVTGYS.js} +4 -4
- package/dist/{chunk-UKAUXY2U.cjs → chunk-MMRHKYT6.cjs} +12 -12
- package/dist/{chunk-U5VR4TJN.js → chunk-MS2KSKD7.js} +9 -9
- package/dist/{chunk-7ZNEUWYP.js → chunk-MZ3T6L7Z.js} +2 -2
- package/dist/{chunk-ATLFMKAF.cjs → chunk-NAOVH4OH.cjs} +7 -7
- package/dist/{chunk-HKJZ7K2K.cjs → chunk-NJ24M6ZH.cjs} +37 -37
- package/dist/chunk-OCTHWEZK.cjs +249 -0
- package/dist/chunk-ONZFBJVW.js +1 -1
- package/dist/{chunk-FI76UZRF.js → chunk-OSSFLQDD.js} +3 -4
- package/dist/{chunk-7WBMA2VE.cjs → chunk-OYFUBKEG.cjs} +4 -5
- package/dist/{chunk-B4SDEBN7.cjs → chunk-PWKOFPAH.cjs} +3 -3
- package/dist/{chunk-RJYWBVGD.cjs → chunk-QGTFQ7RO.cjs} +6 -6
- package/dist/chunk-QNKGP5DY.js +1 -1
- package/dist/chunk-QXTJVDWE.js +676 -0
- package/dist/{chunk-B6UIKBHR.cjs → chunk-QZI5PVCI.cjs} +4 -4
- package/dist/{chunk-PW2VMJLT.js → chunk-R2DR7SPJ.js} +99 -25
- package/dist/{chunk-TDYGYHSH.js → chunk-SN5HAK3Y.js} +4 -4
- package/dist/{chunk-P3ST4UZA.js → chunk-SRWL4YCP.js} +7 -7
- package/dist/{chunk-7QQV66RX.cjs → chunk-TJ5OY6MC.cjs} +10 -10
- package/dist/{chunk-6WMB5AJR.js → chunk-TXOVQZPU.js} +3 -4
- package/dist/chunk-UDA26MCU.cjs +1 -1
- package/dist/{chunk-LVFTN6DK.cjs → chunk-UFYMRRJH.cjs} +61 -61
- package/dist/{chunk-5NN4ZDE2.cjs → chunk-UV5BKAYW.cjs} +6 -8
- package/dist/{chunk-GAJBF6DR.js → chunk-UXT4XSUK.js} +2 -2
- package/dist/{chunk-6VA4F6VR.js → chunk-VBSLIIDB.js} +10 -10
- package/dist/chunk-VCYXNIZ2.cjs +678 -0
- package/dist/chunk-VJDDGRIK.cjs +1 -1
- package/dist/{chunk-JIROTDOU.js → chunk-WB3FT62A.js} +3 -3
- package/dist/{chunk-K63WO3XA.cjs → chunk-WKM6UVMG.cjs} +4 -5
- package/dist/{chunk-5PF7KRCP.cjs → chunk-WLEZ2KSG.cjs} +126 -126
- package/dist/{chunk-ZN53RM3R.js → chunk-WRGN6UBK.js} +2 -2
- package/dist/chunk-WVSPXFTY.js +1 -1
- package/dist/{chunk-2VO2CBTU.js → chunk-X6ULJZ3X.js} +2 -2
- package/dist/{chunk-CKUEZF4R.cjs → chunk-XYWC4EQ3.cjs} +71 -71
- package/dist/{chunk-A3YI6Y2P.js → chunk-YHFRCVTN.js} +3 -3
- package/dist/{chunk-A4H7474O.cjs → chunk-YQHJB7KR.cjs} +26 -26
- package/dist/{chunk-YGB2BQPB.cjs → chunk-YVRUY4EW.cjs} +8 -8
- package/dist/chunk-YWHHVDT4.js +1 -1
- package/dist/chunk-ZTHJQJ5F.cjs +211 -0
- package/dist/conversions/index.cjs +34 -34
- package/dist/conversions/index.d.ts +1 -1
- package/dist/conversions/index.js +15 -15
- package/dist/events/index.cjs +8 -8
- package/dist/events/index.d.ts +1 -1
- package/dist/events/index.js +4 -4
- package/dist/formatters/index.cjs +19 -19
- package/dist/formatters/index.d.ts +1 -1
- package/dist/formatters/index.js +9 -9
- package/dist/generators/index.cjs +9 -9
- package/dist/generators/index.d.ts +1 -1
- package/dist/generators/index.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/isPlainObject-BTPjv6zB.d.ts +1 -1
- package/dist/next/index.cjs +37 -36
- package/dist/next/index.d.ts +1 -1
- package/dist/next/index.js +9 -8
- package/dist/next/server/index.cjs +4 -4
- package/dist/next/server/index.d.ts +1 -1
- package/dist/next/server/index.js +2 -2
- package/dist/operations/index.cjs +11 -11
- package/dist/operations/index.d.ts +1 -1
- package/dist/operations/index.js +8 -8
- package/dist/parsers/index.cjs +6 -4
- package/dist/parsers/index.d.ts +224 -32
- package/dist/parsers/index.js +5 -3
- package/dist/predicates/index.cjs +77 -76
- package/dist/predicates/index.d.ts +1 -1
- package/dist/predicates/index.js +14 -13
- package/dist/promises/index.cjs +6 -6
- package/dist/promises/index.d.ts +2 -3
- package/dist/promises/index.js +4 -4
- package/dist/rzl-utils.global.js +2 -2
- package/dist/strings/index.cjs +23 -23
- package/dist/strings/index.d.ts +1 -1
- package/dist/strings/index.js +7 -7
- package/dist/tailwind/index.cjs +13 -13
- package/dist/tailwind/index.d.ts +1 -1
- package/dist/tailwind/index.js +5 -5
- package/dist/urls/index.cjs +23 -21
- package/dist/urls/index.d.ts +182 -114
- package/dist/urls/index.js +16 -14
- package/package.json +1 -1
- package/dist/chunk-KPCDDYTZ.js +0 -417
- package/dist/chunk-QAPYHLHC.cjs +0 -419
- package/dist/chunk-SGCN4ED4.cjs +0 -175
package/README.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
<div align="center">
|
|
1
|
+
<div align="center" style="display: flex; flex-direction: column; align-items: center;gap: 0.25rem">
|
|
2
|
+
<a target="_blank" rel="noopener noreferrer" href="https://raw.githubusercontent.com/rzl-zone/utils-js/main/logo-circle.png">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/rzl-zone/utils-js/main/logo-circle.png" align="middle" alt="RzlZone Logo" width="110" style="max-width: 100%;">
|
|
4
|
+
</a>
|
|
5
|
+
|
|
2
6
|
<h1><strong>⚡️ <code>@rzl-zone/utils-js</code> 🚀</strong></h1>
|
|
3
7
|
</div>
|
|
4
8
|
|
|
@@ -2,40 +2,40 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.9.1.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
12
|
+
var chunkUV5BKAYW_cjs = require('../chunk-UV5BKAYW.cjs');
|
|
13
|
+
var chunkWKM6UVMG_cjs = require('../chunk-WKM6UVMG.cjs');
|
|
14
|
+
var chunkOYFUBKEG_cjs = require('../chunk-OYFUBKEG.cjs');
|
|
15
15
|
require('../chunk-UDA26MCU.cjs');
|
|
16
|
-
var
|
|
16
|
+
var chunk7C7TQC5J_cjs = require('../chunk-7C7TQC5J.cjs');
|
|
17
17
|
|
|
18
18
|
Object.defineProperty(exports, "assertIsBigInt", {
|
|
19
19
|
enumerable: true,
|
|
20
|
-
get: function () { return
|
|
20
|
+
get: function () { return chunkUV5BKAYW_cjs.assertIsBigInt; }
|
|
21
21
|
});
|
|
22
22
|
Object.defineProperty(exports, "assertIsNumber", {
|
|
23
23
|
enumerable: true,
|
|
24
|
-
get: function () { return
|
|
24
|
+
get: function () { return chunkUV5BKAYW_cjs.assertIsNumber; }
|
|
25
25
|
});
|
|
26
26
|
Object.defineProperty(exports, "assertIsString", {
|
|
27
27
|
enumerable: true,
|
|
28
|
-
get: function () { return
|
|
28
|
+
get: function () { return chunkWKM6UVMG_cjs.assertIsString; }
|
|
29
29
|
});
|
|
30
30
|
Object.defineProperty(exports, "assertIsArray", {
|
|
31
31
|
enumerable: true,
|
|
32
|
-
get: function () { return
|
|
32
|
+
get: function () { return chunkOYFUBKEG_cjs.assertIsArray; }
|
|
33
33
|
});
|
|
34
34
|
Object.defineProperty(exports, "assertIsBoolean", {
|
|
35
35
|
enumerable: true,
|
|
36
|
-
get: function () { return
|
|
36
|
+
get: function () { return chunk7C7TQC5J_cjs.assertIsBoolean; }
|
|
37
37
|
});
|
|
38
38
|
Object.defineProperty(exports, "assertIsPlainObject", {
|
|
39
39
|
enumerable: true,
|
|
40
|
-
get: function () { return
|
|
40
|
+
get: function () { return chunk7C7TQC5J_cjs.assertIsPlainObject; }
|
|
41
41
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.9.1.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
@@ -81,7 +81,32 @@ type OptionsAssertIs=Prettify<{
|
|
|
81
81
|
* }
|
|
82
82
|
* ```
|
|
83
83
|
*/
|
|
84
|
-
message?:OptionsMessageAssertIs;
|
|
84
|
+
message?:OptionsMessageAssertIs;
|
|
85
|
+
/** -------------------------------------------------------
|
|
86
|
+
* * ***Custom error type for assertion failures.***
|
|
87
|
+
* -------------------------------------------------------
|
|
88
|
+
* **This option allows overriding the default error type** that will be thrown
|
|
89
|
+
* when a value does not match the required type.
|
|
90
|
+
*
|
|
91
|
+
* - **Behavior:**
|
|
92
|
+
* - Must be one of the standard JavaScript built-in error types:
|
|
93
|
+
* `"Error" | "EvalError" | "RangeError" | "ReferenceError" | "SyntaxError" | "TypeError" | "URIError"`
|
|
94
|
+
* - **Default:** `"TypeError"` if not provided or if an invalid value is passed.
|
|
95
|
+
* - The assertion function will **always throw a valid built-in error**, ensuring
|
|
96
|
+
* fallback to `TypeError` in case of an unknown or incorrect type.
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* // Valid: Throw a RangeError instead of TypeError
|
|
100
|
+
* { errorType: "RangeError" }
|
|
101
|
+
*
|
|
102
|
+
* // Valid: Throw a ReferenceError
|
|
103
|
+
* { errorType: "ReferenceError" }
|
|
104
|
+
*
|
|
105
|
+
* // Invalid value ➔ fallback to TypeError
|
|
106
|
+
* { errorType: "SomeUnknownError" as ErrorType }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
errorType?:ErrorType;}& PickStrict<GetPreciseTypeOptions,"formatCase">,{recursive:true;}>;type ErrorType="Error"|"EvalError"|"RangeError"|"ReferenceError"|"SyntaxError"|"TypeError"|"URIError";
|
|
85
110
|
/** -------------------------------------------------------
|
|
86
111
|
* * ***Type guard assertion: `assertIsBoolean`.***
|
|
87
112
|
* -------------------------------------------------------
|
|
@@ -90,16 +115,28 @@ message?:OptionsMessageAssertIs;}& PickStrict<GetPreciseTypeOptions,"formatCase"
|
|
|
90
115
|
* - Validates that the given `value` is a **boolean**.
|
|
91
116
|
* - After it returns successfully, TypeScript narrows the type of `value` to `boolean`.
|
|
92
117
|
* - ✅ If `value` is a `boolean` ➔ execution continues normally.
|
|
93
|
-
* - ❌ If `value` is not a `boolean` ➔ throws a
|
|
118
|
+
* - ❌ If `value` is not a `boolean` ➔ throws a built-in error with either:
|
|
94
119
|
* - A custom error message (`options.message`), or
|
|
95
120
|
* - A default message including the actual type.
|
|
121
|
+
* - **⚠️ Error type selection (`options.errorType`):**
|
|
122
|
+
* - You can override the type of error thrown when validation fails.
|
|
123
|
+
* - Must be one of the standard JavaScript built-in errors:
|
|
124
|
+
* - [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) |
|
|
125
|
+
* [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) |
|
|
126
|
+
* [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) |
|
|
127
|
+
* [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) |
|
|
128
|
+
* [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) |
|
|
129
|
+
* [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) |
|
|
130
|
+
* [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
|
|
131
|
+
* - **Default:** `"TypeError"` if not provided or invalid.
|
|
96
132
|
* @param {*} value - ***The value to validate.***
|
|
97
133
|
* @param {OptionsAssertIs} [options]
|
|
98
134
|
* ***Optional configuration:***
|
|
99
|
-
*
|
|
100
|
-
*
|
|
135
|
+
* - `message`: A custom error message (`string` or `function`).
|
|
136
|
+
* - `errorType`: A custom built-in JavaScript error type to throw.
|
|
137
|
+
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
101
138
|
* @returns {boolean} Narrows `value` to `boolean` if no error is thrown.
|
|
102
|
-
* @throws
|
|
139
|
+
* @throws [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) | [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) | [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) | [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) | [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) | [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) | [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError) if the value is not a boolean.
|
|
103
140
|
* @example
|
|
104
141
|
* ```ts
|
|
105
142
|
* // ✅ Simple usage
|
|
@@ -114,11 +151,13 @@ message?:OptionsMessageAssertIs;}& PickStrict<GetPreciseTypeOptions,"formatCase"
|
|
|
114
151
|
* assertIsBoolean(42, { message: "Must be boolean!" });
|
|
115
152
|
* // ➔ TypeError: "Must be boolean!"
|
|
116
153
|
*
|
|
154
|
+
* // ❌ Throws RangeError instead of TypeError
|
|
155
|
+
* assertIsBoolean(42, { errorType: "RangeError" });
|
|
156
|
+
* // ➔ RangeError: "Parameter input (`value`) must be of type `boolean`, but received: `number`."
|
|
157
|
+
*
|
|
117
158
|
* // ❌ Throws with custom function message + case formatting
|
|
118
159
|
* assertIsBoolean(123n, {
|
|
119
|
-
* message: ({ currentType, validType }) => {
|
|
120
|
-
* return `Expected ${validType} but got (${currentType}).`;
|
|
121
|
-
* },
|
|
160
|
+
* message: ({ currentType, validType }) => `Expected ${validType} but got (${currentType}).`,
|
|
122
161
|
* formatCase: "toKebabCase"
|
|
123
162
|
* });
|
|
124
163
|
* // ➔ TypeError: "Expected boolean but got (big-int)."
|
|
@@ -130,8 +169,8 @@ message?:OptionsMessageAssertIs;}& PickStrict<GetPreciseTypeOptions,"formatCase"
|
|
|
130
169
|
* const mixedValue: string | User | boolean | number | undefined = getUserInput();
|
|
131
170
|
*
|
|
132
171
|
* // ❌ Throws if not boolean
|
|
133
|
-
* // ⚠️ Code below after this call, will NOT be executed if
|
|
134
|
-
* assertIsBoolean(mixedValue, { message: "Must be boolean!" });
|
|
172
|
+
* // ⚠️ Code below after this call, will NOT be executed if the error is thrown
|
|
173
|
+
* assertIsBoolean(mixedValue, { message: "Must be boolean!", errorType: "RangeError" });
|
|
135
174
|
*
|
|
136
175
|
* // ✅ After this call, TypeScript knows `mixedValue` is boolean
|
|
137
176
|
* const result: boolean = mixedValue; // ➔ Safe to use
|
|
@@ -146,19 +185,31 @@ declare const assertIsBoolean:(value:unknown,options?:OptionsAssertIs)=>asserts
|
|
|
146
185
|
* - Validates that the given `value` is a **bigint**.
|
|
147
186
|
* - After it returns successfully, TypeScript narrows the type of `value` to `bigint`.
|
|
148
187
|
* - ✅ If `value` is a `bigint` ➔ execution continues normally.
|
|
149
|
-
* - ❌ If `value` is not a `bigint` ➔ throws a
|
|
188
|
+
* - ❌ If `value` is not a `bigint` ➔ throws a built-in error with either:
|
|
150
189
|
* - A custom error message (`options.message`), or
|
|
151
190
|
* - A default message including the actual type.
|
|
152
191
|
* - **ℹ️ Note:**
|
|
153
192
|
* - A `bigint` refers strictly to the JavaScript `bigint` primitive type (e.g., `123n`, `0n`, `-999999999999999999999n`).
|
|
154
193
|
* - This excludes `BigInt` objects created with `Object(BigInt(123))`.
|
|
194
|
+
* - **⚠️ Error type selection (`options.errorType`):**
|
|
195
|
+
* - You can override the type of error thrown when validation fails.
|
|
196
|
+
* - Must be one of the standard JavaScript built-in errors:
|
|
197
|
+
* - [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) |
|
|
198
|
+
* [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) |
|
|
199
|
+
* [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) |
|
|
200
|
+
* [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) |
|
|
201
|
+
* [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) |
|
|
202
|
+
* [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) |
|
|
203
|
+
* [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
|
|
204
|
+
* - **Default:** `"TypeError"` if not provided or invalid.
|
|
155
205
|
* @param {*} value - ***The value to validate.***
|
|
156
206
|
* @param {OptionsAssertIs} [options]
|
|
157
207
|
* ***Optional configuration:***
|
|
158
208
|
* - `message`: A custom error message (`string` or `function`).
|
|
209
|
+
* - `errorType`: Built-in JavaScript error type to throw on failure (default `"TypeError"`).
|
|
159
210
|
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
160
211
|
* @returns {boolean} Narrows `value` to `bigint` if no error is thrown.
|
|
161
|
-
* @throws
|
|
212
|
+
* @throws [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) | [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) | [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) | [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) | [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) | [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) | [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError) if the value is not a bigint.
|
|
162
213
|
* @example
|
|
163
214
|
* ```ts
|
|
164
215
|
* // ✅ Simple usage
|
|
@@ -175,12 +226,21 @@ declare const assertIsBoolean:(value:unknown,options?:OptionsAssertIs)=>asserts
|
|
|
175
226
|
*
|
|
176
227
|
* // ❌ Throws with custom function message + case formatting
|
|
177
228
|
* assertIsBigInt(42, {
|
|
178
|
-
* message: ({ currentType, validType }) => {
|
|
179
|
-
* return `Expected ${validType} but got (${currentType}).`;
|
|
180
|
-
* },
|
|
229
|
+
* message: ({ currentType, validType }) => `Expected ${validType} but got (${currentType}).`,
|
|
181
230
|
* formatCase: "toKebabCase"
|
|
182
231
|
* });
|
|
183
232
|
* // ➔ TypeError: "Expected bigint but got (number)."
|
|
233
|
+
*
|
|
234
|
+
* // ❌ Throws with custom function message + formatCase showing big-int
|
|
235
|
+
* assertIsBigInt(123, {
|
|
236
|
+
* message: ({ currentType, validType }) => `Expected ${validType} but got (${currentType}).`,
|
|
237
|
+
* formatCase: "toKebabCase"
|
|
238
|
+
* });
|
|
239
|
+
* // ➔ TypeError: "Expected bigint but got (number)."
|
|
240
|
+
*
|
|
241
|
+
* // ❌ Throws custom error type (e.g., RangeError)
|
|
242
|
+
* assertIsBigInt(42, { errorType: "RangeError" });
|
|
243
|
+
* // ➔ RangeError: "Parameter input (`value`) must be of type `bigint`, but received: `number`."
|
|
184
244
|
* ```
|
|
185
245
|
* -------------------------------------------------------
|
|
186
246
|
* ✅ ***Real-world usage example***:
|
|
@@ -188,11 +248,10 @@ declare const assertIsBoolean:(value:unknown,options?:OptionsAssertIs)=>asserts
|
|
|
188
248
|
* const mixedValue: string | bigint | undefined = getUserInput();
|
|
189
249
|
*
|
|
190
250
|
* // ❌ Throws if not bigint
|
|
191
|
-
*
|
|
192
|
-
* assertIsBigInt(mixedValue, { message: "Must be a bigint!" });
|
|
251
|
+
* assertIsBigInt(mixedValue, { message: "Must be a bigint!", errorType: "TypeError" });
|
|
193
252
|
*
|
|
194
253
|
* // ✅ After this call, TypeScript knows `mixedValue` is bigint
|
|
195
|
-
* const result: bigint = mixedValue;
|
|
254
|
+
* const result: bigint = mixedValue;
|
|
196
255
|
* console.log(result + 100n);
|
|
197
256
|
* ```
|
|
198
257
|
*/
|
|
@@ -205,21 +264,33 @@ declare const assertIsBigInt:(value:unknown,options?:OptionsAssertIs)=>asserts v
|
|
|
205
264
|
* - Validates that the given `value` is a **number**.
|
|
206
265
|
* - After it returns successfully, TypeScript narrows the type of `value` to `number`.
|
|
207
266
|
* - ✅ If `value` is a `number` ➔ execution continues normally.
|
|
208
|
-
* - ❌ If `value` is not a `number` ➔ throws a
|
|
267
|
+
* - ❌ If `value` is not a `number` ➔ throws a built-in error with either:
|
|
209
268
|
* - A custom error message (`options.message`), or
|
|
210
269
|
* - A default message including the actual type.
|
|
211
270
|
* - **ℹ️ Note:**
|
|
212
271
|
* - A `number` refers strictly to the JavaScript `number` primitive type (e.g., `42`, `3.14`, `-1`, `0`).
|
|
213
272
|
* - This excludes `Number` objects created with `new Number(123)`.
|
|
214
273
|
* - By default, `NaN` is **not considered** valid, you can allow it with `{ includeNaN: true }`.
|
|
274
|
+
* - **⚠️ Error type selection (`options.errorType`):**
|
|
275
|
+
* - You can override the type of error thrown when validation fails.
|
|
276
|
+
* - Must be one of the standard JavaScript built-in errors:
|
|
277
|
+
* - [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) |
|
|
278
|
+
* [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) |
|
|
279
|
+
* [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) |
|
|
280
|
+
* [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) |
|
|
281
|
+
* [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) |
|
|
282
|
+
* [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) |
|
|
283
|
+
* [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
|
|
284
|
+
* - **Default:** `"TypeError"` if not provided or invalid.
|
|
215
285
|
* @param {*} value - ***The value to validate.***
|
|
216
286
|
* @param {OptionsAssertIsNumber} [options]
|
|
217
287
|
* ***Optional configuration:***
|
|
218
288
|
* - `message`: A custom error message (`string` or `function`).
|
|
289
|
+
* - `errorType`: Built-in JavaScript error type to throw on failure (default `"TypeError"`).
|
|
219
290
|
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
220
291
|
* - `includeNaN`: Whether to treat `NaN` as valid.
|
|
221
292
|
* @returns {boolean} Narrows `value` to `number` if no error is thrown.
|
|
222
|
-
* @throws
|
|
293
|
+
* @throws [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) | [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) | [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) | [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) | [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) | [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) | [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError) if the value is not a number (or is `NaN` when `includeNaN` is `false`).
|
|
223
294
|
* @example
|
|
224
295
|
* ```ts
|
|
225
296
|
* // ✅ Simple usage
|
|
@@ -234,11 +305,13 @@ declare const assertIsBigInt:(value:unknown,options?:OptionsAssertIs)=>asserts v
|
|
|
234
305
|
* assertIsNumber(true, { message: "Must be a number!" });
|
|
235
306
|
* // ➔ TypeError: "Must be a number!"
|
|
236
307
|
*
|
|
308
|
+
* // ❌ Throws RangeError instead of TypeError
|
|
309
|
+
* assertIsNumber("42", { errorType: "RangeError" });
|
|
310
|
+
* // ➔ RangeError: "Parameter input (`value`) must be of type `number`, but received: `string`."
|
|
311
|
+
*
|
|
237
312
|
* // ❌ Throws with custom function message + case formatting
|
|
238
313
|
* assertIsNumber("hello", {
|
|
239
|
-
* message: ({ currentType, validType }) => {
|
|
240
|
-
* return `Expected ${validType} but got (${currentType}).`;
|
|
241
|
-
* },
|
|
314
|
+
* message: ({ currentType, validType }) => `Expected ${validType} but got (${currentType}).`,
|
|
242
315
|
* formatCase: "toKebabCase"
|
|
243
316
|
* });
|
|
244
317
|
* // ➔ TypeError: "Expected number but got (string)."
|
|
@@ -251,15 +324,13 @@ declare const assertIsBigInt:(value:unknown,options?:OptionsAssertIs)=>asserts v
|
|
|
251
324
|
* assertIsNumber(NaN, { includeNaN: true });
|
|
252
325
|
* // No error
|
|
253
326
|
* ```
|
|
254
|
-
*
|
|
255
327
|
* -------------------------------------------------------
|
|
256
328
|
* ✅ ***Real-world usage example***:
|
|
257
329
|
* ```ts
|
|
258
330
|
* const mixedValue: string | number | undefined = getUserInput();
|
|
259
331
|
*
|
|
260
332
|
* // ❌ Throws if not number
|
|
261
|
-
*
|
|
262
|
-
* assertIsNumber(mixedValue, { message: "Must be a number!" });
|
|
333
|
+
* assertIsNumber(mixedValue, { message: "Must be a number!", errorType: "RangeError" });
|
|
263
334
|
*
|
|
264
335
|
* // ✅ After this call, TypeScript knows `mixedValue` is number
|
|
265
336
|
* const result: number = mixedValue; // ➔ Safe to use
|
|
@@ -272,20 +343,32 @@ declare const assertIsNumber:(value:unknown,options?:OptionsAssertIsNumber)=>ass
|
|
|
272
343
|
* -------------------------------------------------------
|
|
273
344
|
* **This function is an **assertion function**.**
|
|
274
345
|
* - **Behavior:**
|
|
275
|
-
* - Validates that the given `value` is
|
|
346
|
+
* - Validates that the given `value` is an **array**.
|
|
276
347
|
* - After it returns successfully, TypeScript narrows the type of `value` to `array` **(generic support)**.
|
|
277
348
|
* - ✅ If `value` is an `array` ➔ execution continues normally.
|
|
278
|
-
* - ❌ If `value` is not an `array` ➔ throws a
|
|
349
|
+
* - ❌ If `value` is not an `array` ➔ throws a built-in error with either:
|
|
279
350
|
* - A custom error message (`options.message`), or
|
|
280
351
|
* - A default message including the actual type.
|
|
352
|
+
* - **⚠️ Error type selection (`options.errorType`):**
|
|
353
|
+
* - You can override the type of error thrown when validation fails.
|
|
354
|
+
* - Must be one of the standard JavaScript built-in errors:
|
|
355
|
+
* - [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) |
|
|
356
|
+
* [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) |
|
|
357
|
+
* [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) |
|
|
358
|
+
* [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) |
|
|
359
|
+
* [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) |
|
|
360
|
+
* [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) |
|
|
361
|
+
* [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
|
|
362
|
+
* - **Default:** `"TypeError"` if not provided or invalid.
|
|
281
363
|
* @template T - The input type being asserted.
|
|
282
364
|
* @param {*} value - ***The value to validate.***
|
|
283
365
|
* @param {OptionsAssertIs} [options]
|
|
284
366
|
* ***Optional configuration:***
|
|
285
367
|
* - `message`: A custom error message (`string` or `function`).
|
|
368
|
+
* - `errorType`: Built-in JavaScript error type to throw on failure (default `"TypeError"`).
|
|
286
369
|
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
287
370
|
* @returns {boolean} Narrows `value` to an `array` **(generic support)** if no error is thrown.
|
|
288
|
-
* @throws
|
|
371
|
+
* @throws [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) | [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) | [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) | [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) | [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) | [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) | [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError) if the value is not an array.
|
|
289
372
|
* @example
|
|
290
373
|
* ```ts
|
|
291
374
|
* // ✅ Simple usage
|
|
@@ -300,11 +383,13 @@ declare const assertIsNumber:(value:unknown,options?:OptionsAssertIsNumber)=>ass
|
|
|
300
383
|
* assertIsArray(42, { message: "Must be an array!" });
|
|
301
384
|
* // ➔ TypeError: "Must be an array!"
|
|
302
385
|
*
|
|
386
|
+
* // ❌ Throws RangeError instead of TypeError
|
|
387
|
+
* assertIsArray(42, { errorType: "RangeError" });
|
|
388
|
+
* // ➔ RangeError: "Parameter input (`value`) must be of type `array`, but received: `number`."
|
|
389
|
+
*
|
|
303
390
|
* // ❌ Throws with custom function message + case formatting
|
|
304
391
|
* assertIsArray(42n, {
|
|
305
|
-
* message: ({ currentType, validType }) => {
|
|
306
|
-
* return `Expected ${validType} but got (${currentType}).`;
|
|
307
|
-
* },
|
|
392
|
+
* message: ({ currentType, validType }) => `Expected ${validType} but got (${currentType}).`,
|
|
308
393
|
* formatCase: "toKebabCase"
|
|
309
394
|
* });
|
|
310
395
|
* // ➔ TypeError: "Expected array but got (big-int)."
|
|
@@ -315,8 +400,7 @@ declare const assertIsNumber:(value:unknown,options?:OptionsAssertIsNumber)=>ass
|
|
|
315
400
|
* const mixedValue: string | number[] | undefined = getUserInput();
|
|
316
401
|
*
|
|
317
402
|
* // ❌ Throws if not array
|
|
318
|
-
*
|
|
319
|
-
* assertIsArray(mixedValue, { message: "Must be an array!" });
|
|
403
|
+
* assertIsArray(mixedValue, { message: "Must be an array!", errorType: "RangeError" });
|
|
320
404
|
*
|
|
321
405
|
* // ✅ After this call, TypeScript knows `mixedValue` is narrowed to number[]
|
|
322
406
|
* const result: number[] = mixedValue; // ➔ Safe to use
|
|
@@ -332,17 +416,29 @@ declare function assertIsArray<T extends unknown[]>(value:T,options?:OptionsAsse
|
|
|
332
416
|
* - Validates that the given `value` is a **plain-object**.
|
|
333
417
|
* - After it returns successfully, TypeScript narrows the type of `value` to `plain-object` **(generic support)**.
|
|
334
418
|
* - ✅ If `value` is a `plain-object` ➔ execution continues normally.
|
|
335
|
-
* - ❌ If `value` is not a `plain-object` ➔ throws a
|
|
419
|
+
* - ❌ If `value` is not a `plain-object` ➔ throws a built-in error with either:
|
|
336
420
|
* - A custom error message (`options.message`), or
|
|
337
421
|
* - A default message including the actual type.
|
|
422
|
+
* - **⚠️ Error type selection (`options.errorType`):**
|
|
423
|
+
* - You can override the type of error thrown when validation fails.
|
|
424
|
+
* - Must be one of the standard JavaScript built-in errors:
|
|
425
|
+
* - [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) |
|
|
426
|
+
* [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) |
|
|
427
|
+
* [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) |
|
|
428
|
+
* [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) |
|
|
429
|
+
* [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) |
|
|
430
|
+
* [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) |
|
|
431
|
+
* [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
|
|
432
|
+
* - **Default:** `"TypeError"` if not provided or invalid.
|
|
338
433
|
* @template T - The input type being asserted.
|
|
339
434
|
* @param {*} value - ***The value to validate.***
|
|
340
435
|
* @param {OptionsAssertIs} [options]
|
|
341
436
|
* ***Optional configuration:***
|
|
342
437
|
* - `message`: A custom error message (`string` or `function`).
|
|
438
|
+
* - `errorType`: Built-in JavaScript error type to throw on failure (default `"TypeError"`).
|
|
343
439
|
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
344
440
|
* @returns {boolean} Narrows `value` to a `plain-object` **(generic support)** if no error is thrown.
|
|
345
|
-
* @throws
|
|
441
|
+
* @throws [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) | [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) | [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) | [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) | [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) | [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) | [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError) if `value` is not a plain-object.
|
|
346
442
|
* @example
|
|
347
443
|
* ```ts
|
|
348
444
|
* // ✅ Simple usage
|
|
@@ -357,11 +453,13 @@ declare function assertIsArray<T extends unknown[]>(value:T,options?:OptionsAsse
|
|
|
357
453
|
* assertIsPlainObject("hello", { message: "Must be plain object!" });
|
|
358
454
|
* // ➔ TypeError: "Must be plain object!"
|
|
359
455
|
*
|
|
360
|
-
* // ❌ Throws
|
|
456
|
+
* // ❌ Throws RangeError instead of TypeError
|
|
457
|
+
* assertIsPlainObject(42, { errorType: "RangeError" });
|
|
458
|
+
* // ➔ RangeError: "Parameter input (`value`) must be of type `plain-object`, but received: `number`."
|
|
459
|
+
*
|
|
460
|
+
* // ❌ Throws with custom message function + case formatting
|
|
361
461
|
* assertIsPlainObject(42n, {
|
|
362
|
-
* message: ({ currentType, validType }) => {
|
|
363
|
-
* return `Expected ${validType} but got (${currentType}).`;
|
|
364
|
-
* },
|
|
462
|
+
* message: ({ currentType, validType }) => `Expected ${validType} but got (${currentType}).`,
|
|
365
463
|
* formatCase: "toKebabCase"
|
|
366
464
|
* });
|
|
367
465
|
* // ➔ TypeError: "Expected plain-object but got (big-int)."
|
|
@@ -372,10 +470,10 @@ declare function assertIsArray<T extends unknown[]>(value:T,options?:OptionsAsse
|
|
|
372
470
|
* type User = { name: string; email: string };
|
|
373
471
|
* const mixedValue: string | User | boolean | number | undefined = getUserInput();
|
|
374
472
|
*
|
|
375
|
-
* // Throws
|
|
376
|
-
* assertIsPlainObject(mixedValue, { message: "Must be plain object!" });
|
|
473
|
+
* // ❌ Throws if not plain object
|
|
474
|
+
* assertIsPlainObject(mixedValue, { message: "Must be plain object!", errorType: "RangeError" });
|
|
377
475
|
*
|
|
378
|
-
* // After this call, TypeScript knows `mixedValue` is narrowed to User
|
|
476
|
+
* // ✅ After this call, TypeScript knows `mixedValue` is narrowed to User
|
|
379
477
|
* const user: User = mixedValue; // ➔ safe
|
|
380
478
|
* console.log(user.email); // ➔ type-safe
|
|
381
479
|
* ```
|
|
@@ -389,24 +487,36 @@ declare function assertIsPlainObject<T>(value:T,options?:OptionsAssertIs):assert
|
|
|
389
487
|
* - Validates that the given `value` is a **primitive-string**.
|
|
390
488
|
* - After it returns successfully, TypeScript narrows the type of `value` to `primitive-string`.
|
|
391
489
|
* - ✅ If `value` is a `primitive-string` ➔ execution continues normally.
|
|
392
|
-
* - ❌ If `value` is not a `primitive-string` ➔ throws a
|
|
490
|
+
* - ❌ If `value` is not a `primitive-string` ➔ throws a built-in error with either:
|
|
393
491
|
* - A custom error message (`options.message`), or
|
|
394
492
|
* - A default message including the actual type.
|
|
395
493
|
* - **ℹ️ Note:**
|
|
396
494
|
* - A "string" refers strictly to a JavaScript `primitive-string` type (e.g., `"hello"`, `""`, `"123"`).
|
|
397
495
|
* - This function excludes `String` objects created with `new String()`.
|
|
496
|
+
* - **⚠️ Error type selection (`options.errorType`):**
|
|
497
|
+
* - You can override the type of error thrown when validation fails.
|
|
498
|
+
* - Must be one of the standard JavaScript built-in errors:
|
|
499
|
+
* - [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) |
|
|
500
|
+
* [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) |
|
|
501
|
+
* [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) |
|
|
502
|
+
* [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) |
|
|
503
|
+
* [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) |
|
|
504
|
+
* [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) |
|
|
505
|
+
* [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
|
|
506
|
+
* - **Default:** `"TypeError"` if not provided or invalid.
|
|
398
507
|
* @param {*} value - ***The value to validate.***
|
|
399
508
|
* @param {OptionsAssertIs} [options]
|
|
400
509
|
* ***Optional configuration:***
|
|
401
510
|
* - `message`: A custom error message (`string` or `function`).
|
|
511
|
+
* - `errorType`: Built-in JavaScript error type to throw on failure (default `"TypeError"`).
|
|
402
512
|
* - `formatCase`: Controls type formatting (from `GetPreciseTypeOptions`).
|
|
403
513
|
* @returns {boolean} Narrows `value` to `string` if no error is thrown.
|
|
404
|
-
* @throws
|
|
514
|
+
* @throws [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) | [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) | [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) | [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) | [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) | [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) | [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError) if the value is not a primitive string.
|
|
405
515
|
* @example
|
|
406
516
|
* ```ts
|
|
407
517
|
* // ✅ Simple usage
|
|
408
518
|
* assertIsString("hello");
|
|
409
|
-
* // ➔
|
|
519
|
+
* // ➔ ok value is string, no error
|
|
410
520
|
*
|
|
411
521
|
* // ❌ Throws TypeError with default message
|
|
412
522
|
* assertIsString(42);
|
|
@@ -416,11 +526,13 @@ declare function assertIsPlainObject<T>(value:T,options?:OptionsAssertIs):assert
|
|
|
416
526
|
* assertIsString(42, { message: "Must be a string!" });
|
|
417
527
|
* // ➔ TypeError: "Must be a string!"
|
|
418
528
|
*
|
|
419
|
-
* // ❌ Throws
|
|
529
|
+
* // ❌ Throws RangeError instead of TypeError
|
|
530
|
+
* assertIsString(42, { errorType: "RangeError" });
|
|
531
|
+
* // ➔ RangeError: "Parameter input (`value`) must be of type `string`, but received: `number`."
|
|
532
|
+
*
|
|
533
|
+
* // ❌ Throws with custom message function + case formatting
|
|
420
534
|
* assertIsString(42n, {
|
|
421
|
-
* message: ({ currentType, validType }) => {
|
|
422
|
-
* return `Expected ${validType} but got (${currentType}).`;
|
|
423
|
-
* },
|
|
535
|
+
* message: ({ currentType, validType }) => `Expected ${validType} but got (${currentType}).`,
|
|
424
536
|
* formatCase: "toKebabCase"
|
|
425
537
|
* });
|
|
426
538
|
* // ➔ TypeError: "Expected string but got (big-int)."
|
|
@@ -431,13 +543,12 @@ declare function assertIsPlainObject<T>(value:T,options?:OptionsAssertIs):assert
|
|
|
431
543
|
* type User = { name: string; email: string };
|
|
432
544
|
* const mixedValue: string | User | undefined = getUserInput();
|
|
433
545
|
*
|
|
434
|
-
* // Throws
|
|
435
|
-
*
|
|
436
|
-
* assertIsString(mixedValue, { message: "Must be a string!" });
|
|
546
|
+
* // ❌ Throws if the value is not string
|
|
547
|
+
* assertIsString(mixedValue, { message: "Must be a string!", errorType: "RangeError" });
|
|
437
548
|
*
|
|
438
|
-
* // After this call, TypeScript knows `mixedValue` is string
|
|
439
|
-
* const result: string = mixedValue; // ➔
|
|
440
|
-
* console.log(result.toUpperCase()); // ➔
|
|
549
|
+
* // ✅ After this call, TypeScript knows `mixedValue` is string
|
|
550
|
+
* const result: string = mixedValue; // ➔ safe
|
|
551
|
+
* console.log(result.toUpperCase()); // ➔ type-safe
|
|
441
552
|
* ```
|
|
442
553
|
*/
|
|
443
554
|
declare const assertIsString:(value:unknown,options?:OptionsAssertIs)=>asserts value is string;export{assertIsArray,assertIsBigInt,assertIsBoolean,assertIsNumber,assertIsPlainObject,assertIsString};
|
package/dist/assertions/index.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.9.1.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
9
9
|
*/
|
|
10
|
-
export { assertIsBigInt, assertIsNumber } from '../chunk-
|
|
11
|
-
export { assertIsString } from '../chunk-
|
|
12
|
-
export { assertIsArray } from '../chunk-
|
|
10
|
+
export { assertIsBigInt, assertIsNumber } from '../chunk-GHU356XQ.js';
|
|
11
|
+
export { assertIsString } from '../chunk-OSSFLQDD.js';
|
|
12
|
+
export { assertIsArray } from '../chunk-TXOVQZPU.js';
|
|
13
13
|
import '../chunk-QNKGP5DY.js';
|
|
14
|
-
export { assertIsBoolean, assertIsPlainObject } from '../chunk-
|
|
14
|
+
export { assertIsBoolean, assertIsPlainObject } from '../chunk-J4TT33ZX.js';
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* ====================================================
|
|
3
3
|
* Rzl Utils-JS.
|
|
4
4
|
* ----------------------------------------------------
|
|
5
|
-
* Version: 3.
|
|
5
|
+
* Version: 3.9.1.
|
|
6
6
|
* Author: Rizalvin Dwiky.
|
|
7
7
|
* Repository: https://github.com/rzl-zone/utils-js.
|
|
8
8
|
* ====================================================
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var chunk7C7TQC5J_cjs = require('./chunk-7C7TQC5J.cjs');
|
|
13
13
|
|
|
14
14
|
var parseCurrencyString = (input) => {
|
|
15
|
-
if (!
|
|
15
|
+
if (!chunk7C7TQC5J_cjs.isNonEmptyString(input)) return 0;
|
|
16
16
|
let trimmed = input.trim().replace(/\u00A0/g, "").replace(/\u202F/g, "");
|
|
17
17
|
let isNegative = false;
|
|
18
18
|
if (/^\(.*\)$/.test(trimmed)) {
|