@xylabs/object-model
v5.0.86
Published
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
Downloads
31,127
Keywords
Readme
@xylabs/object-model
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
Reference
@xylabs/object-model
Interfaces
| Interface | Description | | ------ | ------ | | TypeCheckConfig | Configuration options for type check functions, with optional logging. | | TypeCheckRequiredConfig | Type check configuration that marks the value as required, causing assertions on failure. | | TypeCheckOptionalConfig | Type check configuration that marks the value as optional, returning undefined on failure. |
Type Aliases
| Type Alias | Description | | ------ | ------ | | 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 | | AsTypeFunction | A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads. | | AsOptionalTypeFunction | A simplified type-narrowing function that returns T or undefined, without assertion support. | | Compare | A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b. | | 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 | | StringOrAlertFunction | A string message or function that produces an assertion error message for a failed type check. | | TypeCheck | A type guard function that checks whether a value conforms to type T, with optional configuration. |
interfaces
TypeCheckConfig
Configuration options for type check functions, with optional logging.
Extended by
Properties
| Property | Type |
| ------ | ------ |
| log? | boolean | Logger |
TypeCheckOptionalConfig
Type check configuration that marks the value as optional, returning undefined on failure.
Extends
Properties
| Property | Type | Inherited from |
| ------ | ------ | ------ |
| log? | boolean | Logger | TypeCheckConfig.log |
| required | false | - |
TypeCheckRequiredConfig
Type check configuration that marks the value as required, causing assertions on failure.
Extends
Properties
| Property | Type | Inherited from |
| ------ | ------ | ------ |
| log? | boolean | Logger | TypeCheckConfig.log |
| required | true | - |
type-aliases
AnyObject
type AnyObject = EmptyObject & Partial<Record<TypedKey, unknown>>;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
AsOptionalTypeFunction
type AsOptionalTypeFunction<T> = <TType>(value: AnyNonPromise) => TType | undefined;A simplified type-narrowing function that returns T or undefined, without assertion support.
Type Parameters
| Type Parameter | Default type |
| ------ | ------ |
| T extends AnyNonPromise | AnyNonPromise |
Type Parameters
| Type Parameter |
| ------ |
| TType extends AnyNonPromise |
Parameters
| Parameter | Type |
| ------ | ------ |
| value | AnyNonPromise |
Returns
TType | undefined
AsTypeFunction
type AsTypeFunction<T> = {
<TType> (value: AnyNonPromise): TType | undefined;
<TType> (value: AnyNonPromise, config: TypeCheckRequiredConfig): TType;
<TType> (value: AnyNonPromise, config:
| TypeCheckConfig
| TypeCheckOptionalConfig): TType | undefined;
<TType> (value: AnyNonPromise, assert: StringOrAlertFunction<TType>): TType | undefined;
<TType> (value: AnyNonPromise, assert: StringOrAlertFunction<TType>, config: TypeCheckRequiredConfig): TType;
<TType> (value: AnyNonPromise, assert: StringOrAlertFunction<TType>, config:
| TypeCheckConfig
| TypeCheckOptionalConfig): TType | undefined;
};A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.
Type Parameters
| Type Parameter | Default type |
| ------ | ------ |
| T extends AnyNonPromise | AnyNonPromise |
Call Signature
<TType>(value: AnyNonPromise): TType | undefined;Type Parameters
| Type Parameter |
| ------ |
| TType extends AnyNonPromise |
Parameters
| Parameter | Type |
| ------ | ------ |
| value | AnyNonPromise |
Returns
TType | undefined
Call Signature
<TType>(value: AnyNonPromise, config: TypeCheckRequiredConfig): TType;Type Parameters
| Type Parameter |
| ------ |
| TType extends AnyNonPromise |
Parameters
| Parameter | Type |
| ------ | ------ |
| value | AnyNonPromise |
| config | TypeCheckRequiredConfig |
Returns
TType
Call Signature
<TType>(value: AnyNonPromise, config:
| TypeCheckConfig
| TypeCheckOptionalConfig): TType | undefined;Type Parameters
| Type Parameter |
| ------ |
| TType extends AnyNonPromise |
Parameters
| Parameter | Type |
| ------ | ------ |
| value | AnyNonPromise |
| config | | TypeCheckConfig | TypeCheckOptionalConfig |
Returns
TType | undefined
Call Signature
<TType>(value: AnyNonPromise, assert: StringOrAlertFunction<TType>): TType | undefined;Type Parameters
| Type Parameter |
| ------ |
| TType extends AnyNonPromise |
Parameters
| Parameter | Type |
| ------ | ------ |
| value | AnyNonPromise |
| assert | StringOrAlertFunction<TType> |
Returns
TType | undefined
Call Signature
<TType>(
value: AnyNonPromise,
assert: StringOrAlertFunction<TType>,
config: TypeCheckRequiredConfig): TType;Type Parameters
| Type Parameter |
| ------ |
| TType extends AnyNonPromise |
Parameters
| Parameter | Type |
| ------ | ------ |
| value | AnyNonPromise |
| assert | StringOrAlertFunction<TType> |
| config | TypeCheckRequiredConfig |
Returns
TType
Call Signature
<TType>(
value: AnyNonPromise,
assert: StringOrAlertFunction<TType>,
config:
| TypeCheckConfig
| TypeCheckOptionalConfig): TType | undefined;Type Parameters
| Type Parameter |
| ------ |
| TType extends AnyNonPromise |
Parameters
| Parameter | Type |
| ------ | ------ |
| value | AnyNonPromise |
| assert | StringOrAlertFunction<TType> |
| config | | TypeCheckConfig | TypeCheckOptionalConfig |
Returns
TType | undefined
Compare
type Compare<T> = (a: T, b: T) => number;A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b.
Type Parameters
| Type Parameter |
| ------ |
| T |
Parameters
| Parameter | Type |
| ------ | ------ |
| a | T |
| b | T |
Returns
number
EmptyObject
type EmptyObject<T> = Exclude<{ [K in keyof T]?: never }, unknown[] | (...args: unknown[]) => unknown | null>;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
Type Parameters
| Type Parameter | Default type |
| ------ | ------ |
| T extends object | object |
StringOrAlertFunction
type StringOrAlertFunction<T> = string | AssertExMessageFunc<T>;A string message or function that produces an assertion error message for a failed type check.
Type Parameters
| Type Parameter |
| ------ |
| T extends AnyNonPromise |
TypeCheck
type TypeCheck<T> = {
(obj: AnyNonPromise): obj is T;
(obj: AnyNonPromise, config: TypeCheckConfig): obj is T;
(obj: AnyNonPromise, config:
| number
| TypeCheckConfig
| undefined): obj is T;
};A type guard function that checks whether a value conforms to type T, with optional configuration.
Type Parameters
| Type Parameter |
| ------ |
| T extends TypedValue |
Call Signature
(obj: AnyNonPromise): obj is T;Parameters
| Parameter | Type |
| ------ | ------ |
| obj | AnyNonPromise |
Returns
obj is T
Call Signature
(obj: AnyNonPromise, config: TypeCheckConfig): obj is T;Parameters
| Parameter | Type |
| ------ | ------ |
| obj | AnyNonPromise |
| config | TypeCheckConfig |
Returns
obj is T
Call Signature
(obj: AnyNonPromise, config:
| number
| TypeCheckConfig
| undefined): obj is T;Parameters
| Parameter | Type |
| ------ | ------ |
| obj | AnyNonPromise |
| config | | number | TypeCheckConfig | undefined |
Returns
obj is T
Part of sdk-js
Maintainers
License
See the LICENSE file for license details
