@xylabs/object-model 5.0.83 → 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 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/object-model**
@@ -23,19 +25,23 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
23
25
 
24
26
  ## Interfaces
25
27
 
26
- - [TypeCheckConfig](#interfaces/TypeCheckConfig)
27
- - [TypeCheckRequiredConfig](#interfaces/TypeCheckRequiredConfig)
28
- - [TypeCheckOptionalConfig](#interfaces/TypeCheckOptionalConfig)
28
+ | Interface | Description |
29
+ | ------ | ------ |
30
+ | [TypeCheckConfig](#interfaces/TypeCheckConfig) | Configuration options for type check functions, with optional logging. |
31
+ | [TypeCheckRequiredConfig](#interfaces/TypeCheckRequiredConfig) | Type check configuration that marks the value as required, causing assertions on failure. |
32
+ | [TypeCheckOptionalConfig](#interfaces/TypeCheckOptionalConfig) | Type check configuration that marks the value as optional, returning undefined on failure. |
29
33
 
30
34
  ## Type Aliases
31
35
 
32
- - [AnyObject](#type-aliases/AnyObject)
33
- - [AsTypeFunction](#type-aliases/AsTypeFunction)
34
- - [AsOptionalTypeFunction](#type-aliases/AsOptionalTypeFunction)
35
- - [Compare](#type-aliases/Compare)
36
- - [EmptyObject](#type-aliases/EmptyObject)
37
- - [StringOrAlertFunction](#type-aliases/StringOrAlertFunction)
38
- - [TypeCheck](#type-aliases/TypeCheck)
36
+ | Type Alias | Description |
37
+ | ------ | ------ |
38
+ | [AnyObject](#type-aliases/AnyObject) | Any object, which means that it does not enforce the set of fields that it has. Extending from AnyObject will result in a type that includes the universal set of field names |
39
+ | [AsTypeFunction](#type-aliases/AsTypeFunction) | A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads. |
40
+ | [AsOptionalTypeFunction](#type-aliases/AsOptionalTypeFunction) | A simplified type-narrowing function that returns T or undefined, without assertion support. |
41
+ | [Compare](#type-aliases/Compare) | A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b. |
42
+ | [EmptyObject](#type-aliases/EmptyObject) | An empty object, which means that it does enforce the set of field names, defaulting to an empty set until extended from, which then adds only those additional fields |
43
+ | [StringOrAlertFunction](#type-aliases/StringOrAlertFunction) | A string message or function that produces an assertion error message for a failed type check. |
44
+ | [TypeCheck](#type-aliases/TypeCheck) | A type guard function that checks whether a value conforms to type T, with optional configuration. |
39
45
 
40
46
  ### interfaces
41
47
 
@@ -45,6 +51,8 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
45
51
 
46
52
  ***
47
53
 
54
+ Configuration options for type check functions, with optional logging.
55
+
48
56
  ## Extended by
49
57
 
50
58
  - [`TypeCheckRequiredConfig`](#TypeCheckRequiredConfig)
@@ -52,11 +60,9 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
52
60
 
53
61
  ## Properties
54
62
 
55
- ### log?
56
-
57
- ```ts
58
- optional log: boolean | Logger;
59
- ```
63
+ | Property | Type |
64
+ | ------ | ------ |
65
+ | <a id="log"></a> `log?` | `boolean` \| `Logger` |
60
66
 
61
67
  ### <a id="TypeCheckOptionalConfig"></a>TypeCheckOptionalConfig
62
68
 
@@ -64,29 +70,18 @@ optional log: boolean | Logger;
64
70
 
65
71
  ***
66
72
 
73
+ Type check configuration that marks the value as optional, returning undefined on failure.
74
+
67
75
  ## Extends
68
76
 
69
77
  - [`TypeCheckConfig`](#TypeCheckConfig)
70
78
 
71
79
  ## Properties
72
80
 
73
- ### log?
74
-
75
- ```ts
76
- optional log: boolean | Logger;
77
- ```
78
-
79
- ### Inherited from
80
-
81
- [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log)
82
-
83
- ***
84
-
85
- ### required
86
-
87
- ```ts
88
- required: false;
89
- ```
81
+ | Property | Type | Inherited from |
82
+ | ------ | ------ | ------ |
83
+ | <a id="log"></a> `log?` | `boolean` \| `Logger` | [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log) |
84
+ | <a id="required"></a> `required` | `false` | - |
90
85
 
91
86
  ### <a id="TypeCheckRequiredConfig"></a>TypeCheckRequiredConfig
92
87
 
@@ -94,29 +89,18 @@ required: false;
94
89
 
95
90
  ***
96
91
 
92
+ Type check configuration that marks the value as required, causing assertions on failure.
93
+
97
94
  ## Extends
98
95
 
99
96
  - [`TypeCheckConfig`](#TypeCheckConfig)
100
97
 
101
98
  ## Properties
102
99
 
103
- ### log?
104
-
105
- ```ts
106
- optional log: boolean | Logger;
107
- ```
108
-
109
- ### Inherited from
110
-
111
- [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log)
112
-
113
- ***
114
-
115
- ### required
116
-
117
- ```ts
118
- required: true;
119
- ```
100
+ | Property | Type | Inherited from |
101
+ | ------ | ------ | ------ |
102
+ | <a id="log"></a> `log?` | `boolean` \| `Logger` | [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log) |
103
+ | <a id="required"></a> `required` | `true` | - |
120
104
 
121
105
  ### type-aliases
122
106
 
@@ -140,26 +124,28 @@ will result in a type that includes the universal set of field names
140
124
  ***
141
125
 
142
126
  ```ts
143
- type AsOptionalTypeFunction<T> = <TType>(value) => TType | undefined;
127
+ type AsOptionalTypeFunction<T> = <TType>(value: AnyNonPromise) => TType | undefined;
144
128
  ```
145
129
 
146
- ## Type Parameters
130
+ A simplified type-narrowing function that returns T or undefined, without assertion support.
147
131
 
148
- ### T
132
+ ## Type Parameters
149
133
 
150
- `T` *extends* `AnyNonPromise` = `AnyNonPromise`
134
+ | Type Parameter | Default type |
135
+ | ------ | ------ |
136
+ | `T` *extends* `AnyNonPromise` | `AnyNonPromise` |
151
137
 
152
138
  ## Type Parameters
153
139
 
154
- ### TType
155
-
156
- `TType` *extends* `AnyNonPromise`
140
+ | Type Parameter |
141
+ | ------ |
142
+ | `TType` *extends* `AnyNonPromise` |
157
143
 
158
144
  ## Parameters
159
145
 
160
- ### value
161
-
162
- `AnyNonPromise`
146
+ | Parameter | Type |
147
+ | ------ | ------ |
148
+ | `value` | `AnyNonPromise` |
163
149
 
164
150
  ## Returns
165
151
 
@@ -173,38 +159,44 @@ type AsOptionalTypeFunction<T> = <TType>(value) => TType | undefined;
173
159
 
174
160
  ```ts
175
161
  type AsTypeFunction<T> = {
176
- <TType> (value): TType | undefined;
177
- <TType> (value, config): TType;
178
- <TType> (value, config): TType | undefined;
179
- <TType> (value, assert): TType | undefined;
180
- <TType> (value, assert, config): TType;
181
- <TType> (value, assert, config): TType | undefined;
162
+ <TType> (value: AnyNonPromise): TType | undefined;
163
+ <TType> (value: AnyNonPromise, config: TypeCheckRequiredConfig): TType;
164
+ <TType> (value: AnyNonPromise, config:
165
+ | TypeCheckConfig
166
+ | TypeCheckOptionalConfig): TType | undefined;
167
+ <TType> (value: AnyNonPromise, assert: StringOrAlertFunction<TType>): TType | undefined;
168
+ <TType> (value: AnyNonPromise, assert: StringOrAlertFunction<TType>, config: TypeCheckRequiredConfig): TType;
169
+ <TType> (value: AnyNonPromise, assert: StringOrAlertFunction<TType>, config:
170
+ | TypeCheckConfig
171
+ | TypeCheckOptionalConfig): TType | undefined;
182
172
  };
183
173
  ```
184
174
 
185
- ## Type Parameters
175
+ A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.
186
176
 
187
- ### T
177
+ ## Type Parameters
188
178
 
189
- `T` *extends* `AnyNonPromise` = `AnyNonPromise`
179
+ | Type Parameter | Default type |
180
+ | ------ | ------ |
181
+ | `T` *extends* `AnyNonPromise` | `AnyNonPromise` |
190
182
 
191
183
  ## Call Signature
192
184
 
193
185
  ```ts
194
- <TType>(value): TType | undefined;
186
+ <TType>(value: AnyNonPromise): TType | undefined;
195
187
  ```
196
188
 
197
189
  ### Type Parameters
198
190
 
199
- ### TType
200
-
201
- `TType` *extends* `AnyNonPromise`
191
+ | Type Parameter |
192
+ | ------ |
193
+ | `TType` *extends* `AnyNonPromise` |
202
194
 
203
195
  ### Parameters
204
196
 
205
- ### value
206
-
207
- `AnyNonPromise`
197
+ | Parameter | Type |
198
+ | ------ | ------ |
199
+ | `value` | `AnyNonPromise` |
208
200
 
209
201
  ### Returns
210
202
 
@@ -213,24 +205,21 @@ type AsTypeFunction<T> = {
213
205
  ## Call Signature
214
206
 
215
207
  ```ts
216
- <TType>(value, config): TType;
208
+ <TType>(value: AnyNonPromise, config: TypeCheckRequiredConfig): TType;
217
209
  ```
218
210
 
219
211
  ### Type Parameters
220
212
 
221
- ### TType
222
-
223
- `TType` *extends* `AnyNonPromise`
213
+ | Type Parameter |
214
+ | ------ |
215
+ | `TType` *extends* `AnyNonPromise` |
224
216
 
225
217
  ### Parameters
226
218
 
227
- ### value
228
-
229
- `AnyNonPromise`
230
-
231
- ### config
232
-
233
- [`TypeCheckRequiredConfig`](#../interfaces/TypeCheckRequiredConfig)
219
+ | Parameter | Type |
220
+ | ------ | ------ |
221
+ | `value` | `AnyNonPromise` |
222
+ | `config` | [`TypeCheckRequiredConfig`](#../interfaces/TypeCheckRequiredConfig) |
234
223
 
235
224
  ### Returns
236
225
 
@@ -239,24 +228,23 @@ type AsTypeFunction<T> = {
239
228
  ## Call Signature
240
229
 
241
230
  ```ts
242
- <TType>(value, config): TType | undefined;
231
+ <TType>(value: AnyNonPromise, config:
232
+ | TypeCheckConfig
233
+ | TypeCheckOptionalConfig): TType | undefined;
243
234
  ```
244
235
 
245
236
  ### Type Parameters
246
237
 
247
- ### TType
248
-
249
- `TType` *extends* `AnyNonPromise`
238
+ | Type Parameter |
239
+ | ------ |
240
+ | `TType` *extends* `AnyNonPromise` |
250
241
 
251
242
  ### Parameters
252
243
 
253
- ### value
254
-
255
- `AnyNonPromise`
256
-
257
- ### config
258
-
259
- [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) | [`TypeCheckOptionalConfig`](#../interfaces/TypeCheckOptionalConfig)
244
+ | Parameter | Type |
245
+ | ------ | ------ |
246
+ | `value` | `AnyNonPromise` |
247
+ | `config` | \| [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) \| [`TypeCheckOptionalConfig`](#../interfaces/TypeCheckOptionalConfig) |
260
248
 
261
249
  ### Returns
262
250
 
@@ -265,24 +253,21 @@ type AsTypeFunction<T> = {
265
253
  ## Call Signature
266
254
 
267
255
  ```ts
268
- <TType>(value, assert): TType | undefined;
256
+ <TType>(value: AnyNonPromise, assert: StringOrAlertFunction<TType>): TType | undefined;
269
257
  ```
270
258
 
271
259
  ### Type Parameters
272
260
 
273
- ### TType
274
-
275
- `TType` *extends* `AnyNonPromise`
261
+ | Type Parameter |
262
+ | ------ |
263
+ | `TType` *extends* `AnyNonPromise` |
276
264
 
277
265
  ### Parameters
278
266
 
279
- ### value
280
-
281
- `AnyNonPromise`
282
-
283
- ### assert
284
-
285
- [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\>
267
+ | Parameter | Type |
268
+ | ------ | ------ |
269
+ | `value` | `AnyNonPromise` |
270
+ | `assert` | [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\> |
286
271
 
287
272
  ### Returns
288
273
 
@@ -292,30 +277,24 @@ type AsTypeFunction<T> = {
292
277
 
293
278
  ```ts
294
279
  <TType>(
295
- value,
296
- assert,
297
- config): TType;
280
+ value: AnyNonPromise,
281
+ assert: StringOrAlertFunction<TType>,
282
+ config: TypeCheckRequiredConfig): TType;
298
283
  ```
299
284
 
300
285
  ### Type Parameters
301
286
 
302
- ### TType
303
-
304
- `TType` *extends* `AnyNonPromise`
287
+ | Type Parameter |
288
+ | ------ |
289
+ | `TType` *extends* `AnyNonPromise` |
305
290
 
306
291
  ### Parameters
307
292
 
308
- ### value
309
-
310
- `AnyNonPromise`
311
-
312
- ### assert
313
-
314
- [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\>
315
-
316
- ### config
317
-
318
- [`TypeCheckRequiredConfig`](#../interfaces/TypeCheckRequiredConfig)
293
+ | Parameter | Type |
294
+ | ------ | ------ |
295
+ | `value` | `AnyNonPromise` |
296
+ | `assert` | [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\> |
297
+ | `config` | [`TypeCheckRequiredConfig`](#../interfaces/TypeCheckRequiredConfig) |
319
298
 
320
299
  ### Returns
321
300
 
@@ -325,30 +304,26 @@ type AsTypeFunction<T> = {
325
304
 
326
305
  ```ts
327
306
  <TType>(
328
- value,
329
- assert,
330
- config): TType | undefined;
307
+ value: AnyNonPromise,
308
+ assert: StringOrAlertFunction<TType>,
309
+ config:
310
+ | TypeCheckConfig
311
+ | TypeCheckOptionalConfig): TType | undefined;
331
312
  ```
332
313
 
333
314
  ### Type Parameters
334
315
 
335
- ### TType
336
-
337
- `TType` *extends* `AnyNonPromise`
316
+ | Type Parameter |
317
+ | ------ |
318
+ | `TType` *extends* `AnyNonPromise` |
338
319
 
339
320
  ### Parameters
340
321
 
341
- ### value
342
-
343
- `AnyNonPromise`
344
-
345
- ### assert
346
-
347
- [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\>
348
-
349
- ### config
350
-
351
- [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) | [`TypeCheckOptionalConfig`](#../interfaces/TypeCheckOptionalConfig)
322
+ | Parameter | Type |
323
+ | ------ | ------ |
324
+ | `value` | `AnyNonPromise` |
325
+ | `assert` | [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\> |
326
+ | `config` | \| [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) \| [`TypeCheckOptionalConfig`](#../interfaces/TypeCheckOptionalConfig) |
352
327
 
353
328
  ### Returns
354
329
 
@@ -361,24 +336,23 @@ type AsTypeFunction<T> = {
361
336
  ***
362
337
 
363
338
  ```ts
364
- type Compare<T> = (a, b) => number;
339
+ type Compare<T> = (a: T, b: T) => number;
365
340
  ```
366
341
 
367
- ## Type Parameters
342
+ A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b.
368
343
 
369
- ### T
344
+ ## Type Parameters
370
345
 
371
- `T`
346
+ | Type Parameter |
347
+ | ------ |
348
+ | `T` |
372
349
 
373
350
  ## Parameters
374
351
 
375
- ### a
376
-
377
- `T`
378
-
379
- ### b
380
-
381
- `T`
352
+ | Parameter | Type |
353
+ | ------ | ------ |
354
+ | `a` | `T` |
355
+ | `b` | `T` |
382
356
 
383
357
  ## Returns
384
358
 
@@ -391,7 +365,7 @@ type Compare<T> = (a, b) => number;
391
365
  ***
392
366
 
393
367
  ```ts
394
- type EmptyObject<T> = Exclude<{ [K in keyof T]?: never }, unknown[] | (...args) => unknown | null>;
368
+ type EmptyObject<T> = Exclude<{ [K in keyof T]?: never }, unknown[] | (...args: unknown[]) => unknown | null>;
395
369
  ```
396
370
 
397
371
  An empty object, which means that it does enforce the set of field names, defaulting to an empty set until
@@ -399,9 +373,9 @@ extended from, which then adds only those additional fields
399
373
 
400
374
  ## Type Parameters
401
375
 
402
- ### T
403
-
404
- `T` *extends* `object` = `object`
376
+ | Type Parameter | Default type |
377
+ | ------ | ------ |
378
+ | `T` *extends* `object` | `object` |
405
379
 
406
380
  ### <a id="StringOrAlertFunction"></a>StringOrAlertFunction
407
381
 
@@ -413,11 +387,13 @@ extended from, which then adds only those additional fields
413
387
  type StringOrAlertFunction<T> = string | AssertExMessageFunc<T>;
414
388
  ```
415
389
 
416
- ## Type Parameters
390
+ A string message or function that produces an assertion error message for a failed type check.
417
391
 
418
- ### T
392
+ ## Type Parameters
419
393
 
420
- `T` *extends* `AnyNonPromise`
394
+ | Type Parameter |
395
+ | ------ |
396
+ | `T` *extends* `AnyNonPromise` |
421
397
 
422
398
  ### <a id="TypeCheck"></a>TypeCheck
423
399
 
@@ -427,29 +403,34 @@ type StringOrAlertFunction<T> = string | AssertExMessageFunc<T>;
427
403
 
428
404
  ```ts
429
405
  type TypeCheck<T> = {
430
- (obj): obj is T;
431
- (obj, config): obj is T;
432
- (obj, config): obj is T;
406
+ (obj: AnyNonPromise): obj is T;
407
+ (obj: AnyNonPromise, config: TypeCheckConfig): obj is T;
408
+ (obj: AnyNonPromise, config:
409
+ | number
410
+ | TypeCheckConfig
411
+ | undefined): obj is T;
433
412
  };
434
413
  ```
435
414
 
436
- ## Type Parameters
415
+ A type guard function that checks whether a value conforms to type T, with optional configuration.
437
416
 
438
- ### T
417
+ ## Type Parameters
439
418
 
440
- `T` *extends* `TypedValue`
419
+ | Type Parameter |
420
+ | ------ |
421
+ | `T` *extends* `TypedValue` |
441
422
 
442
423
  ## Call Signature
443
424
 
444
425
  ```ts
445
- (obj): obj is T;
426
+ (obj: AnyNonPromise): obj is T;
446
427
  ```
447
428
 
448
429
  ### Parameters
449
430
 
450
- ### obj
451
-
452
- `AnyNonPromise`
431
+ | Parameter | Type |
432
+ | ------ | ------ |
433
+ | `obj` | `AnyNonPromise` |
453
434
 
454
435
  ### Returns
455
436
 
@@ -458,18 +439,15 @@ type TypeCheck<T> = {
458
439
  ## Call Signature
459
440
 
460
441
  ```ts
461
- (obj, config): obj is T;
442
+ (obj: AnyNonPromise, config: TypeCheckConfig): obj is T;
462
443
  ```
463
444
 
464
445
  ### Parameters
465
446
 
466
- ### obj
467
-
468
- `AnyNonPromise`
469
-
470
- ### config
471
-
472
- [`TypeCheckConfig`](#../interfaces/TypeCheckConfig)
447
+ | Parameter | Type |
448
+ | ------ | ------ |
449
+ | `obj` | `AnyNonPromise` |
450
+ | `config` | [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) |
473
451
 
474
452
  ### Returns
475
453
 
@@ -478,18 +456,18 @@ type TypeCheck<T> = {
478
456
  ## Call Signature
479
457
 
480
458
  ```ts
481
- (obj, config): obj is T;
459
+ (obj: AnyNonPromise, config:
460
+ | number
461
+ | TypeCheckConfig
462
+ | undefined): obj is T;
482
463
  ```
483
464
 
484
465
  ### Parameters
485
466
 
486
- ### obj
487
-
488
- `AnyNonPromise`
489
-
490
- ### config
491
-
492
- `number` | [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) | `undefined`
467
+ | Parameter | Type |
468
+ | ------ | ------ |
469
+ | `obj` | `AnyNonPromise` |
470
+ | `config` | \| `number` \| [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) \| `undefined` |
493
471
 
494
472
  ### Returns
495
473
 
@@ -1,6 +1,10 @@
1
1
  import type { AnyNonPromise } from '@xylabs/promise';
2
2
  import type { AsTypeFunction } from './AsTypeFunction.ts';
3
3
  import type { TypeCheck } from './types.ts';
4
+ /**
5
+ * Factory for creating type-narrowing 'as' functions that cast a value to T or return undefined.
6
+ * Supports optional assertion messages and configuration for required/optional behavior.
7
+ */
4
8
  export declare const AsTypeFactory: {
5
9
  create: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => AsTypeFunction<T>;
6
10
  createOptional: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => (value: AnyNonPromise) => T | undefined;
@@ -1,5 +1,6 @@
1
1
  import type { AnyNonPromise } from '@xylabs/promise';
2
2
  import type { StringOrAlertFunction, TypeCheckConfig, TypeCheckOptionalConfig, TypeCheckRequiredConfig } from './types.ts';
3
+ /** A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads. */
3
4
  export type AsTypeFunction<T extends AnyNonPromise = AnyNonPromise> = {
4
5
  <TType extends T>(value: AnyNonPromise): TType | undefined;
5
6
  <TType extends T>(value: AnyNonPromise, config: TypeCheckRequiredConfig): TType;
@@ -8,6 +9,7 @@ export type AsTypeFunction<T extends AnyNonPromise = AnyNonPromise> = {
8
9
  <TType extends T>(value: AnyNonPromise, assert: StringOrAlertFunction<TType>, config: TypeCheckRequiredConfig): TType;
9
10
  <TType extends T>(value: AnyNonPromise, assert: StringOrAlertFunction<TType>, config: TypeCheckConfig | TypeCheckOptionalConfig): TType | undefined;
10
11
  };
12
+ /** A simplified type-narrowing function that returns T or undefined, without assertion support. */
11
13
  export type AsOptionalTypeFunction<T extends AnyNonPromise = AnyNonPromise> = {
12
14
  <TType extends T>(value: AnyNonPromise): TType | undefined;
13
15
  };
@@ -1 +1,2 @@
1
+ /** A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b. */
1
2
  export type Compare<T> = (a: T, b: T) => number;
@@ -2,16 +2,21 @@ import type { AssertExMessageFunc } from '@xylabs/assert';
2
2
  import type { Logger } from '@xylabs/logger';
3
3
  import type { AnyNonPromise } from '@xylabs/promise';
4
4
  import type { TypedValue } from '@xylabs/typeof';
5
+ /** Configuration options for type check functions, with optional logging. */
5
6
  export interface TypeCheckConfig {
6
7
  log?: boolean | Logger;
7
8
  }
9
+ /** Type check configuration that marks the value as required, causing assertions on failure. */
8
10
  export interface TypeCheckRequiredConfig extends TypeCheckConfig {
9
11
  required: true;
10
12
  }
13
+ /** Type check configuration that marks the value as optional, returning undefined on failure. */
11
14
  export interface TypeCheckOptionalConfig extends TypeCheckConfig {
12
15
  required: false;
13
16
  }
17
+ /** A string message or function that produces an assertion error message for a failed type check. */
14
18
  export type StringOrAlertFunction<T extends AnyNonPromise> = string | AssertExMessageFunc<T>;
19
+ /** A type guard function that checks whether a value conforms to type T, with optional configuration. */
15
20
  export type TypeCheck<T extends TypedValue> = {
16
21
  (obj: AnyNonPromise): obj is T;
17
22
  (obj: AnyNonPromise, config: TypeCheckConfig): obj is T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/object-model",
3
- "version": "5.0.83",
3
+ "version": "5.0.86",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -35,14 +35,14 @@
35
35
  "!**/*.test.*"
36
36
  ],
37
37
  "dependencies": {
38
- "@xylabs/assert": "~5.0.83",
39
- "@xylabs/logger": "~5.0.83",
40
- "@xylabs/promise": "~5.0.83",
41
- "@xylabs/typeof": "~5.0.83"
38
+ "@xylabs/assert": "~5.0.86",
39
+ "@xylabs/logger": "~5.0.86",
40
+ "@xylabs/promise": "~5.0.86",
41
+ "@xylabs/typeof": "~5.0.86"
42
42
  },
43
43
  "devDependencies": {
44
- "@xylabs/ts-scripts-yarn3": "~7.4.11",
45
- "@xylabs/tsconfig": "~7.4.11",
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
  },