@rickosborne/guard 2024.12.28 → 2024.12.29

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 CHANGED
@@ -1,4 +1,4 @@
1
- **@rickosborne/guard v2024.12.28**
1
+ **@rickosborne/guard v2024.12.29**
2
2
 
3
3
  ***
4
4
 
@@ -8,19 +8,371 @@ Basic type guards building on [@rickosborne/typical](https://www.npmjs.com/packa
8
8
 
9
9
  ## Type Aliases
10
10
 
11
- - [MessageOrError](type-aliases/MessageOrError.md)
11
+ ### MessageOrError
12
+
13
+ ```ts
14
+ type MessageOrError = string | Error | () => string | Error;
15
+ ```
16
+
17
+ A message, an error, or something which can generate one of those.
12
18
 
13
19
  ## Functions
14
20
 
15
- - [assertDefined](functions/assertDefined.md)
16
- - [assertInt](functions/assertInt.md)
17
- - [errorFromMessageOrError](functions/errorFromMessageOrError.md)
18
- - [expectInt](functions/expectInt.md)
19
- - [hasArray](functions/hasArray.md)
20
- - [hasNumber](functions/hasNumber.md)
21
- - [hasOwn](functions/hasOwn.md)
22
- - [isInt](functions/isInt.md)
23
- - [isListOf](functions/isListOf.md)
24
- - [isObject](functions/isObject.md)
25
- - [isPlainObject](functions/isPlainObject.md)
26
- - [isUnaryPredicate](functions/isUnaryPredicate.md)
21
+ ### assertDefined()
22
+
23
+ ```ts
24
+ function assertDefined<T>(value, messageOrError): asserts value is NonNullable<T>
25
+ ```
26
+
27
+ #### Type Parameters
28
+
29
+ **T**
30
+
31
+ #### Parameters
32
+
33
+ ##### value
34
+
35
+ `T`
36
+
37
+ ##### messageOrError
38
+
39
+ [`MessageOrError`](README.md#messageorerror)
40
+
41
+ #### Returns
42
+
43
+ `asserts value is NonNullable<T>`
44
+
45
+ ***
46
+
47
+ ### assertInt()
48
+
49
+ ```ts
50
+ function assertInt(value, messageOrError): asserts value is number
51
+ ```
52
+
53
+ #### Parameters
54
+
55
+ ##### value
56
+
57
+ `unknown`
58
+
59
+ ##### messageOrError
60
+
61
+ [`MessageOrError`](README.md#messageorerror)
62
+
63
+ #### Returns
64
+
65
+ `asserts value is number`
66
+
67
+ ***
68
+
69
+ ### errorFromMessageOrError()
70
+
71
+ ```ts
72
+ function errorFromMessageOrError(messageOrError, defaultConstructor): Error
73
+ ```
74
+
75
+ Helper for guards which expect text or an error, or
76
+ can generate one when needed.
77
+
78
+ #### Parameters
79
+
80
+ ##### messageOrError
81
+
82
+ [`MessageOrError`](README.md#messageorerror)
83
+
84
+ ##### defaultConstructor
85
+
86
+ (`message`) => `Error`
87
+
88
+ #### Returns
89
+
90
+ `Error`
91
+
92
+ ***
93
+
94
+ ### expectInt()
95
+
96
+ ```ts
97
+ function expectInt(obj, messageOrError): number
98
+ ```
99
+
100
+ #### Parameters
101
+
102
+ ##### obj
103
+
104
+ `unknown`
105
+
106
+ ##### messageOrError
107
+
108
+ [`MessageOrError`](README.md#messageorerror)
109
+
110
+ #### Returns
111
+
112
+ `number`
113
+
114
+ ***
115
+
116
+ ### hasArray()
117
+
118
+ Guard for whether the given value is an object which has a property with its own array value.
119
+
120
+ #### Call Signature
121
+
122
+ ```ts
123
+ function hasArray<Name>(
124
+ obj,
125
+ name,
126
+ predicate?): obj is { [K in string]: unknown[] }
127
+ ```
128
+
129
+ Guard for whether the given value is an object which has a property with its own array value.
130
+ This variant does not exhaustively check the items of the array.
131
+
132
+ ##### Type Parameters
133
+
134
+ • **Name** *extends* `string`
135
+
136
+ ##### Parameters
137
+
138
+ ###### obj
139
+
140
+ `unknown`
141
+
142
+ ###### name
143
+
144
+ `Name`
145
+
146
+ ###### predicate?
147
+
148
+ `undefined`
149
+
150
+ ##### Returns
151
+
152
+ `obj is { [K in string]: unknown[] }`
153
+
154
+ #### Call Signature
155
+
156
+ ```ts
157
+ function hasArray<Name, Item>(
158
+ obj,
159
+ name,
160
+ predicate?): obj is { [K in string]: Item[] }
161
+ ```
162
+
163
+ Guard for whether the given value is an object which has a property with its own array value.
164
+ This variant exhaustively checks the items of the array against the given predicate.
165
+
166
+ ##### Type Parameters
167
+
168
+ • **Name** *extends* `string`
169
+
170
+ • **Item**
171
+
172
+ ##### Parameters
173
+
174
+ ###### obj
175
+
176
+ `unknown`
177
+
178
+ ###### name
179
+
180
+ `Name`
181
+
182
+ ###### predicate?
183
+
184
+ (`item`, `index`, `items`) => `item is Item`
185
+
186
+ ##### Returns
187
+
188
+ `obj is { [K in string]: Item[] }`
189
+
190
+ ***
191
+
192
+ ### hasNumber()
193
+
194
+ ```ts
195
+ function hasNumber<Name>(obj, name): obj is { [k in string]: string }
196
+ ```
197
+
198
+ #### Type Parameters
199
+
200
+ • **Name** *extends* `string`
201
+
202
+ #### Parameters
203
+
204
+ ##### obj
205
+
206
+ `unknown`
207
+
208
+ ##### name
209
+
210
+ `Name`
211
+
212
+ #### Returns
213
+
214
+ `obj is { [k in string]: string }`
215
+
216
+ ***
217
+
218
+ ### hasOwn()
219
+
220
+ #### Call Signature
221
+
222
+ ```ts
223
+ function hasOwn<Name>(obj, name): obj is { [K in string]: unknown }
224
+ ```
225
+
226
+ ##### Type Parameters
227
+
228
+ • **Name** *extends* `string`
229
+
230
+ ##### Parameters
231
+
232
+ ###### obj
233
+
234
+ `unknown`
235
+
236
+ ###### name
237
+
238
+ `Name`
239
+
240
+ ##### Returns
241
+
242
+ `obj is { [K in string]: unknown }`
243
+
244
+ #### Call Signature
245
+
246
+ ```ts
247
+ function hasOwn<Name, T>(
248
+ obj,
249
+ name,
250
+ predicate): obj is { [K in string]: T }
251
+ ```
252
+
253
+ ##### Type Parameters
254
+
255
+ • **Name** *extends* `string`
256
+
257
+ • **T**
258
+
259
+ ##### Parameters
260
+
261
+ ###### obj
262
+
263
+ `unknown`
264
+
265
+ ###### name
266
+
267
+ `Name`
268
+
269
+ ###### predicate
270
+
271
+ (`value`) => `value is T`
272
+
273
+ ##### Returns
274
+
275
+ `obj is { [K in string]: T }`
276
+
277
+ ***
278
+
279
+ ### isInt()
280
+
281
+ ```ts
282
+ function isInt(obj): obj is number
283
+ ```
284
+
285
+ #### Parameters
286
+
287
+ ##### obj
288
+
289
+ `unknown`
290
+
291
+ #### Returns
292
+
293
+ `obj is number`
294
+
295
+ ***
296
+
297
+ ### isListOf()
298
+
299
+ ```ts
300
+ function isListOf<T>(list, predicate): list is T[]
301
+ ```
302
+
303
+ #### Type Parameters
304
+
305
+ • **T**
306
+
307
+ #### Parameters
308
+
309
+ ##### list
310
+
311
+ `unknown`
312
+
313
+ ##### predicate
314
+
315
+ (`item`, `index`, `items`) => `item is T`
316
+
317
+ #### Returns
318
+
319
+ `list is T[]`
320
+
321
+ ***
322
+
323
+ ### isObject()
324
+
325
+ ```ts
326
+ function isObject(obj): obj is object
327
+ ```
328
+
329
+ #### Parameters
330
+
331
+ ##### obj
332
+
333
+ `unknown`
334
+
335
+ #### Returns
336
+
337
+ `obj is object`
338
+
339
+ ***
340
+
341
+ ### isPlainObject()
342
+
343
+ ```ts
344
+ function isPlainObject(obj): obj is Record<never, never>
345
+ ```
346
+
347
+ #### Parameters
348
+
349
+ ##### obj
350
+
351
+ `unknown`
352
+
353
+ #### Returns
354
+
355
+ `obj is Record<never, never>`
356
+
357
+ ***
358
+
359
+ ### isUnaryPredicate()
360
+
361
+ ```ts
362
+ function isUnaryPredicate(obj): obj is UnaryPredicate<unknown>
363
+ ```
364
+
365
+ Tests whether the given object is a function and takes at
366
+ least one parameter, and could maybe act as a unary predicate.
367
+ Warning! Since no type information is available at runtime,
368
+ it may not actually act as a predicate!
369
+
370
+ #### Parameters
371
+
372
+ ##### obj
373
+
374
+ `unknown`
375
+
376
+ #### Returns
377
+
378
+ `obj is UnaryPredicate<unknown>`
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "url": "https://rickosborne.org"
5
5
  },
6
6
  "dependencies": {
7
- "@rickosborne/typical": "2024.12.28"
7
+ "@rickosborne/typical": "2024.12.29"
8
8
  },
9
9
  "description": "Rick Osborne's collection of type guards.",
10
10
  "engines": {
@@ -27,8 +27,9 @@
27
27
  "access": "public"
28
28
  },
29
29
  "repository": {
30
+ "directory": "guard",
30
31
  "type": "git",
31
32
  "url": "git+https://github.com/rickosborne/es-js-ts.git"
32
33
  },
33
- "version": "2024.12.28"
34
+ "version": "2024.12.29"
34
35
  }
@@ -1,31 +0,0 @@
1
- [**@rickosborne/guard v2024.12.28**](../README.md)
2
-
3
- ***
4
-
5
- [@rickosborne/guard](../README.md) / assertDefined
6
-
7
- # Function: assertDefined()
8
-
9
- > **assertDefined**\<`T`\>(`value`, `messageOrError`): `asserts value is NonNullable<T>`
10
-
11
- ## Type Parameters
12
-
13
- • **T**
14
-
15
- ## Parameters
16
-
17
- ### value
18
-
19
- `T`
20
-
21
- ### messageOrError
22
-
23
- [`MessageOrError`](../type-aliases/MessageOrError.md)
24
-
25
- ## Returns
26
-
27
- `asserts value is NonNullable<T>`
28
-
29
- ## Defined in
30
-
31
- [assert-defined.ts:3](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/assert-defined.ts#L3)
@@ -1,27 +0,0 @@
1
- [**@rickosborne/guard v2024.12.28**](../README.md)
2
-
3
- ***
4
-
5
- [@rickosborne/guard](../README.md) / assertInt
6
-
7
- # Function: assertInt()
8
-
9
- > **assertInt**(`value`, `messageOrError`): `asserts value is number`
10
-
11
- ## Parameters
12
-
13
- ### value
14
-
15
- `unknown`
16
-
17
- ### messageOrError
18
-
19
- [`MessageOrError`](../type-aliases/MessageOrError.md)
20
-
21
- ## Returns
22
-
23
- `asserts value is number`
24
-
25
- ## Defined in
26
-
27
- [is-int.ts:5](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/is-int.ts#L5)
@@ -1,30 +0,0 @@
1
- [**@rickosborne/guard v2024.12.28**](../README.md)
2
-
3
- ***
4
-
5
- [@rickosborne/guard](../README.md) / errorFromMessageOrError
6
-
7
- # Function: errorFromMessageOrError()
8
-
9
- > **errorFromMessageOrError**(`messageOrError`, `defaultConstructor`): `Error`
10
-
11
- Helper for guards which expect text or an error, or
12
- can generate one when needed.
13
-
14
- ## Parameters
15
-
16
- ### messageOrError
17
-
18
- [`MessageOrError`](../type-aliases/MessageOrError.md)
19
-
20
- ### defaultConstructor
21
-
22
- (`message`) => `Error`
23
-
24
- ## Returns
25
-
26
- `Error`
27
-
28
- ## Defined in
29
-
30
- [error-from-message.ts:10](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/error-from-message.ts#L10)
@@ -1,27 +0,0 @@
1
- [**@rickosborne/guard v2024.12.28**](../README.md)
2
-
3
- ***
4
-
5
- [@rickosborne/guard](../README.md) / expectInt
6
-
7
- # Function: expectInt()
8
-
9
- > **expectInt**(`obj`, `messageOrError`): `number`
10
-
11
- ## Parameters
12
-
13
- ### obj
14
-
15
- `unknown`
16
-
17
- ### messageOrError
18
-
19
- [`MessageOrError`](../type-aliases/MessageOrError.md)
20
-
21
- ## Returns
22
-
23
- `number`
24
-
25
- ## Defined in
26
-
27
- [is-int.ts:11](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/is-int.ts#L11)
@@ -1,77 +0,0 @@
1
- [**@rickosborne/guard v2024.12.28**](../README.md)
2
-
3
- ***
4
-
5
- [@rickosborne/guard](../README.md) / hasArray
6
-
7
- # Function: hasArray()
8
-
9
- Guard for whether the given value is an object which has a property with its own array value.
10
-
11
- ## Call Signature
12
-
13
- > **hasArray**\<`Name`\>(`obj`, `name`, `predicate`?): `obj is { [K in string]: unknown[] }`
14
-
15
- Guard for whether the given value is an object which has a property with its own array value.
16
- This variant does not exhaustively check the items of the array.
17
-
18
- ### Type Parameters
19
-
20
- • **Name** *extends* `string`
21
-
22
- ### Parameters
23
-
24
- #### obj
25
-
26
- `unknown`
27
-
28
- #### name
29
-
30
- `Name`
31
-
32
- #### predicate?
33
-
34
- `undefined`
35
-
36
- ### Returns
37
-
38
- `obj is { [K in string]: unknown[] }`
39
-
40
- ### Defined in
41
-
42
- [has-array.ts:8](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/has-array.ts#L8)
43
-
44
- ## Call Signature
45
-
46
- > **hasArray**\<`Name`, `Item`\>(`obj`, `name`, `predicate`?): `obj is { [K in string]: Item[] }`
47
-
48
- Guard for whether the given value is an object which has a property with its own array value.
49
- This variant exhaustively checks the items of the array against the given predicate.
50
-
51
- ### Type Parameters
52
-
53
- • **Name** *extends* `string`
54
-
55
- • **Item**
56
-
57
- ### Parameters
58
-
59
- #### obj
60
-
61
- `unknown`
62
-
63
- #### name
64
-
65
- `Name`
66
-
67
- #### predicate?
68
-
69
- (`item`, `index`, `items`) => `item is Item`
70
-
71
- ### Returns
72
-
73
- `obj is { [K in string]: Item[] }`
74
-
75
- ### Defined in
76
-
77
- [has-array.ts:13](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/has-array.ts#L13)
@@ -1,31 +0,0 @@
1
- [**@rickosborne/guard v2024.12.28**](../README.md)
2
-
3
- ***
4
-
5
- [@rickosborne/guard](../README.md) / hasNumber
6
-
7
- # Function: hasNumber()
8
-
9
- > **hasNumber**\<`Name`\>(`obj`, `name`): `obj is { [k in string]: string }`
10
-
11
- ## Type Parameters
12
-
13
- • **Name** *extends* `string`
14
-
15
- ## Parameters
16
-
17
- ### obj
18
-
19
- `unknown`
20
-
21
- ### name
22
-
23
- `Name`
24
-
25
- ## Returns
26
-
27
- `obj is { [k in string]: string }`
28
-
29
- ## Defined in
30
-
31
- [has-number.ts:3](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/has-number.ts#L3)
@@ -1,65 +0,0 @@
1
- [**@rickosborne/guard v2024.12.28**](../README.md)
2
-
3
- ***
4
-
5
- [@rickosborne/guard](../README.md) / hasOwn
6
-
7
- # Function: hasOwn()
8
-
9
- ## Call Signature
10
-
11
- > **hasOwn**\<`Name`\>(`obj`, `name`): `obj is { [K in string]: unknown }`
12
-
13
- ### Type Parameters
14
-
15
- • **Name** *extends* `string`
16
-
17
- ### Parameters
18
-
19
- #### obj
20
-
21
- `unknown`
22
-
23
- #### name
24
-
25
- `Name`
26
-
27
- ### Returns
28
-
29
- `obj is { [K in string]: unknown }`
30
-
31
- ### Defined in
32
-
33
- [has-own.ts:3](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/has-own.ts#L3)
34
-
35
- ## Call Signature
36
-
37
- > **hasOwn**\<`Name`, `T`\>(`obj`, `name`, `predicate`): `obj is { [K in string]: T }`
38
-
39
- ### Type Parameters
40
-
41
- • **Name** *extends* `string`
42
-
43
- • **T**
44
-
45
- ### Parameters
46
-
47
- #### obj
48
-
49
- `unknown`
50
-
51
- #### name
52
-
53
- `Name`
54
-
55
- #### predicate
56
-
57
- (`value`) => `value is T`
58
-
59
- ### Returns
60
-
61
- `obj is { [K in string]: T }`
62
-
63
- ### Defined in
64
-
65
- [has-own.ts:4](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/has-own.ts#L4)
@@ -1,23 +0,0 @@
1
- [**@rickosborne/guard v2024.12.28**](../README.md)
2
-
3
- ***
4
-
5
- [@rickosborne/guard](../README.md) / isInt
6
-
7
- # Function: isInt()
8
-
9
- > **isInt**(`obj`): `obj is number`
10
-
11
- ## Parameters
12
-
13
- ### obj
14
-
15
- `unknown`
16
-
17
- ## Returns
18
-
19
- `obj is number`
20
-
21
- ## Defined in
22
-
23
- [is-int.ts:3](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/is-int.ts#L3)
@@ -1,31 +0,0 @@
1
- [**@rickosborne/guard v2024.12.28**](../README.md)
2
-
3
- ***
4
-
5
- [@rickosborne/guard](../README.md) / isListOf
6
-
7
- # Function: isListOf()
8
-
9
- > **isListOf**\<`T`\>(`list`, `predicate`): `list is T[]`
10
-
11
- ## Type Parameters
12
-
13
- • **T**
14
-
15
- ## Parameters
16
-
17
- ### list
18
-
19
- `unknown`
20
-
21
- ### predicate
22
-
23
- (`item`, `index`, `items`) => `item is T`
24
-
25
- ## Returns
26
-
27
- `list is T[]`
28
-
29
- ## Defined in
30
-
31
- [is-list-of.ts:1](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/is-list-of.ts#L1)
@@ -1,23 +0,0 @@
1
- [**@rickosborne/guard v2024.12.28**](../README.md)
2
-
3
- ***
4
-
5
- [@rickosborne/guard](../README.md) / isObject
6
-
7
- # Function: isObject()
8
-
9
- > **isObject**(`obj`): `obj is object`
10
-
11
- ## Parameters
12
-
13
- ### obj
14
-
15
- `unknown`
16
-
17
- ## Returns
18
-
19
- `obj is object`
20
-
21
- ## Defined in
22
-
23
- [is-object.ts:1](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/is-object.ts#L1)
@@ -1,23 +0,0 @@
1
- [**@rickosborne/guard v2024.12.28**](../README.md)
2
-
3
- ***
4
-
5
- [@rickosborne/guard](../README.md) / isPlainObject
6
-
7
- # Function: isPlainObject()
8
-
9
- > **isPlainObject**(`obj`): `obj is Record<never, never>`
10
-
11
- ## Parameters
12
-
13
- ### obj
14
-
15
- `unknown`
16
-
17
- ## Returns
18
-
19
- `obj is Record<never, never>`
20
-
21
- ## Defined in
22
-
23
- [is-object.ts:5](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/is-object.ts#L5)
@@ -1,28 +0,0 @@
1
- [**@rickosborne/guard v2024.12.28**](../README.md)
2
-
3
- ***
4
-
5
- [@rickosborne/guard](../README.md) / isUnaryPredicate
6
-
7
- # Function: isUnaryPredicate()
8
-
9
- > **isUnaryPredicate**(`obj`): `obj is UnaryPredicate<unknown>`
10
-
11
- Tests whether the given object is a function and takes at
12
- least one parameter, and could maybe act as a unary predicate.
13
- Warning! Since no type information is available at runtime,
14
- it may not actually act as a predicate!
15
-
16
- ## Parameters
17
-
18
- ### obj
19
-
20
- `unknown`
21
-
22
- ## Returns
23
-
24
- `obj is UnaryPredicate<unknown>`
25
-
26
- ## Defined in
27
-
28
- [is-predicate.ts:9](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/is-predicate.ts#L9)
@@ -1,15 +0,0 @@
1
- [**@rickosborne/guard v2024.12.28**](../README.md)
2
-
3
- ***
4
-
5
- [@rickosborne/guard](../README.md) / MessageOrError
6
-
7
- # Type Alias: MessageOrError
8
-
9
- > **MessageOrError**: `string` \| `Error` \| () => `string` \| `Error`
10
-
11
- A message, an error, or something which can generate one of those.
12
-
13
- ## Defined in
14
-
15
- [error-from-message.ts:4](https://github.com/rickosborne/es-js-ts/blob/b9df3c6eb00a5aca153cd4895e7af44eeb074ddb/guard/ts/error-from-message.ts#L4)