@xylabs/assert 5.0.84 → 5.0.86
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 +40 -82
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
17
17
|
|
|
18
|
+
|
|
19
|
+
|
|
18
20
|
## Reference
|
|
19
21
|
|
|
20
22
|
**@xylabs/assert**
|
|
@@ -23,8 +25,10 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
23
25
|
|
|
24
26
|
## Functions
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
| Function | Description |
|
|
29
|
+
| ------ | ------ |
|
|
30
|
+
| [assertDefinedEx](#functions/assertDefinedEx) | Implementation of assertDefinedEx that handles all overloads. |
|
|
31
|
+
| [assertEx](#functions/assertEx) | Implementation of assertEx that handles all overloads. |
|
|
28
32
|
|
|
29
33
|
### functions
|
|
30
34
|
|
|
@@ -39,7 +43,7 @@ Implementation of assertDefinedEx that handles all overloads.
|
|
|
39
43
|
## Call Signature
|
|
40
44
|
|
|
41
45
|
```ts
|
|
42
|
-
function assertDefinedEx<T>(expr, messageFunc
|
|
46
|
+
function assertDefinedEx<T>(expr: T | undefined, messageFunc?: AssertExMessageFunc<T>): T;
|
|
43
47
|
```
|
|
44
48
|
|
|
45
49
|
Asserts that a value is defined (not undefined) and returns the value.
|
|
@@ -47,25 +51,16 @@ Throws an error if the value is undefined.
|
|
|
47
51
|
|
|
48
52
|
### Type Parameters
|
|
49
53
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
`T`
|
|
53
|
-
|
|
54
|
-
The type of value to check
|
|
54
|
+
| Type Parameter | Description |
|
|
55
|
+
| ------ | ------ |
|
|
56
|
+
| `T` | The type of value to check |
|
|
55
57
|
|
|
56
58
|
### Parameters
|
|
57
59
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
Expression to be evaluated for being defined
|
|
61
|
-
|
|
62
|
-
`T` | `undefined`
|
|
63
|
-
|
|
64
|
-
### messageFunc?
|
|
65
|
-
|
|
66
|
-
`AssertExMessageFunc`\<`T`\>
|
|
67
|
-
|
|
68
|
-
Function that returns a message for the error if expression is undefined
|
|
60
|
+
| Parameter | Type | Description |
|
|
61
|
+
| ------ | ------ | ------ |
|
|
62
|
+
| `expr` | `T` \| `undefined` | Expression to be evaluated for being defined |
|
|
63
|
+
| `messageFunc?` | `AssertExMessageFunc`\<`T`\> | Function that returns a message for the error if expression is undefined |
|
|
69
64
|
|
|
70
65
|
### Returns
|
|
71
66
|
|
|
@@ -92,7 +87,7 @@ const safeConfig = assertDefinedEx(config, () => 'Config failed to load')
|
|
|
92
87
|
## Call Signature
|
|
93
88
|
|
|
94
89
|
```ts
|
|
95
|
-
function assertDefinedEx<T, R>(expr, errorFunc
|
|
90
|
+
function assertDefinedEx<T, R>(expr: T | undefined, errorFunc?: AssertExErrorFunc<T, R>): T;
|
|
96
91
|
```
|
|
97
92
|
|
|
98
93
|
Asserts that a value is defined (not undefined) and returns the value.
|
|
@@ -100,31 +95,17 @@ Throws a custom error if the value is undefined.
|
|
|
100
95
|
|
|
101
96
|
### Type Parameters
|
|
102
97
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
`T`
|
|
106
|
-
|
|
107
|
-
The type of value to check
|
|
108
|
-
|
|
109
|
-
### R
|
|
110
|
-
|
|
111
|
-
`R` *extends* `Error`
|
|
112
|
-
|
|
113
|
-
The type of error to throw
|
|
98
|
+
| Type Parameter | Description |
|
|
99
|
+
| ------ | ------ |
|
|
100
|
+
| `T` | The type of value to check |
|
|
101
|
+
| `R` *extends* `Error` | The type of error to throw |
|
|
114
102
|
|
|
115
103
|
### Parameters
|
|
116
104
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
Expression to be evaluated for being defined
|
|
120
|
-
|
|
121
|
-
`T` | `undefined`
|
|
122
|
-
|
|
123
|
-
### errorFunc?
|
|
124
|
-
|
|
125
|
-
`AssertExErrorFunc`\<`T`, `R`\>
|
|
126
|
-
|
|
127
|
-
Function that returns a custom error instance if expression is undefined
|
|
105
|
+
| Parameter | Type | Description |
|
|
106
|
+
| ------ | ------ | ------ |
|
|
107
|
+
| `expr` | `T` \| `undefined` | Expression to be evaluated for being defined |
|
|
108
|
+
| `errorFunc?` | `AssertExErrorFunc`\<`T`, `R`\> | Function that returns a custom error instance if expression is undefined |
|
|
128
109
|
|
|
129
110
|
### Returns
|
|
130
111
|
|
|
@@ -154,7 +135,7 @@ Implementation of assertEx that handles all overloads.
|
|
|
154
135
|
## Call Signature
|
|
155
136
|
|
|
156
137
|
```ts
|
|
157
|
-
function assertEx<T>(expr, messageFunc
|
|
138
|
+
function assertEx<T>(expr: T | null | undefined, messageFunc?: AssertExMessageFunc<T>): T;
|
|
158
139
|
```
|
|
159
140
|
|
|
160
141
|
Asserts that an expression is truthy and returns the value.
|
|
@@ -162,25 +143,16 @@ Throws an error if the expression is falsy.
|
|
|
162
143
|
|
|
163
144
|
### Type Parameters
|
|
164
145
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
`T`
|
|
168
|
-
|
|
169
|
-
The type of value to check
|
|
146
|
+
| Type Parameter | Description |
|
|
147
|
+
| ------ | ------ |
|
|
148
|
+
| `T` | The type of value to check |
|
|
170
149
|
|
|
171
150
|
### Parameters
|
|
172
151
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
Expression to be evaluated for truthiness
|
|
176
|
-
|
|
177
|
-
`T` | `null` | `undefined`
|
|
178
|
-
|
|
179
|
-
### messageFunc?
|
|
180
|
-
|
|
181
|
-
`AssertExMessageFunc`\<`T`\>
|
|
182
|
-
|
|
183
|
-
Function that returns a message for the error if expression is falsy
|
|
152
|
+
| Parameter | Type | Description |
|
|
153
|
+
| ------ | ------ | ------ |
|
|
154
|
+
| `expr` | `T` \| `null` \| `undefined` | Expression to be evaluated for truthiness |
|
|
155
|
+
| `messageFunc?` | `AssertExMessageFunc`\<`T`\> | Function that returns a message for the error if expression is falsy |
|
|
184
156
|
|
|
185
157
|
### Returns
|
|
186
158
|
|
|
@@ -207,7 +179,7 @@ const safeConfig = assertEx(config, () => 'Config failed to load')
|
|
|
207
179
|
## Call Signature
|
|
208
180
|
|
|
209
181
|
```ts
|
|
210
|
-
function assertEx<T, R>(expr, errorFunc
|
|
182
|
+
function assertEx<T, R>(expr: T | null | undefined, errorFunc?: AssertExErrorFunc<T, R>): T;
|
|
211
183
|
```
|
|
212
184
|
|
|
213
185
|
Asserts that an expression is truthy and returns the value.
|
|
@@ -215,31 +187,17 @@ Throws a custom error if the expression is falsy.
|
|
|
215
187
|
|
|
216
188
|
### Type Parameters
|
|
217
189
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
`T`
|
|
221
|
-
|
|
222
|
-
The type of value to check
|
|
223
|
-
|
|
224
|
-
### R
|
|
225
|
-
|
|
226
|
-
`R` *extends* `Error`
|
|
227
|
-
|
|
228
|
-
The type of error to throw
|
|
190
|
+
| Type Parameter | Description |
|
|
191
|
+
| ------ | ------ |
|
|
192
|
+
| `T` | The type of value to check |
|
|
193
|
+
| `R` *extends* `Error` | The type of error to throw |
|
|
229
194
|
|
|
230
195
|
### Parameters
|
|
231
196
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
Expression to be evaluated for truthiness
|
|
235
|
-
|
|
236
|
-
`T` | `null` | `undefined`
|
|
237
|
-
|
|
238
|
-
### errorFunc?
|
|
239
|
-
|
|
240
|
-
`AssertExErrorFunc`\<`T`, `R`\>
|
|
241
|
-
|
|
242
|
-
Function that returns a custom error instance if expression is falsy
|
|
197
|
+
| Parameter | Type | Description |
|
|
198
|
+
| ------ | ------ | ------ |
|
|
199
|
+
| `expr` | `T` \| `null` \| `undefined` | Expression to be evaluated for truthiness |
|
|
200
|
+
| `errorFunc?` | `AssertExErrorFunc`\<`T`, `R`\> | Function that returns a custom error instance if expression is falsy |
|
|
243
201
|
|
|
244
202
|
### Returns
|
|
245
203
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/assert",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.86",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xylabs",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"!**/*.test.*"
|
|
42
42
|
],
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
45
|
-
"@xylabs/tsconfig": "~7.4.
|
|
44
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.16",
|
|
45
|
+
"@xylabs/tsconfig": "~7.4.16",
|
|
46
46
|
"typescript": "~5.9.3",
|
|
47
47
|
"vitest": "^4.0.18"
|
|
48
48
|
},
|