@xylabs/object-model
Advanced tools
| import type { AnyNonPromise } from '@xylabs/promise'; | ||
| import type { StringOrAlertFunction, TypeCheckConfig, TypeCheckOptionalConfig, TypeCheckRequiredConfig } from './types.ts'; | ||
| /** A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads. */ | ||
| export type AsTypeFunction<T extends AnyNonPromise = AnyNonPromise> = { | ||
| export interface AsTypeFunction<T extends AnyNonPromise = AnyNonPromise> { | ||
| <TType extends T>(value: AnyNonPromise): TType | undefined; | ||
@@ -11,6 +11,4 @@ <TType extends T>(value: AnyNonPromise, config: TypeCheckRequiredConfig): TType; | ||
| <TType extends T>(value: AnyNonPromise, assert: StringOrAlertFunction<TType>, config: TypeCheckConfig | TypeCheckOptionalConfig): TType | undefined; | ||
| }; | ||
| } | ||
| /** A simplified type-narrowing function that returns T or undefined, without assertion support. */ | ||
| export type AsOptionalTypeFunction<T extends AnyNonPromise = AnyNonPromise> = { | ||
| <TType extends T>(value: AnyNonPromise): TType | undefined; | ||
| }; | ||
| export type AsOptionalTypeFunction<T extends AnyNonPromise = AnyNonPromise> = <TType extends T>(value: AnyNonPromise) => TType | undefined; |
@@ -20,6 +20,6 @@ import type { AssertExMessageFunc } from '@xylabs/assert'; | ||
| /** A type guard function that checks whether a value conforms to type T, with optional configuration. */ | ||
| export type TypeCheck<T extends TypedValue> = { | ||
| export interface TypeCheck<T extends TypedValue> { | ||
| (obj: AnyNonPromise): obj is T; | ||
| (obj: AnyNonPromise, config: TypeCheckConfig): obj is T; | ||
| (obj: AnyNonPromise, config: TypeCheckConfig | number | undefined): obj is T; | ||
| }; | ||
| } |
+13
-13
| { | ||
| "name": "@xylabs/object-model", | ||
| "version": "5.0.95", | ||
| "version": "5.0.96", | ||
| "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries", | ||
@@ -25,3 +25,2 @@ "homepage": "https://xyo.network", | ||
| "types": "./dist/neutral/index.d.ts", | ||
| "import": "./dist/neutral/index.mjs", | ||
| "default": "./dist/neutral/index.mjs" | ||
@@ -31,3 +30,2 @@ }, | ||
| }, | ||
| "types": "./dist/neutral/index.d.ts", | ||
| "files": [ | ||
@@ -41,17 +39,19 @@ "dist", | ||
| "dependencies": { | ||
| "@xylabs/logger": "~5.0.95", | ||
| "@xylabs/assert": "~5.0.95", | ||
| "@xylabs/promise": "~5.0.95", | ||
| "@xylabs/typeof": "~5.0.95" | ||
| "@xylabs/assert": "~5.0.96", | ||
| "@xylabs/logger": "~5.0.96", | ||
| "@xylabs/promise": "~5.0.96", | ||
| "@xylabs/typeof": "~5.0.96" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^25.5.2", | ||
| "@xylabs/ts-scripts-common": "~7.8.4", | ||
| "@xylabs/ts-scripts-pnpm": "~7.8.4", | ||
| "@xylabs/tsconfig": "~7.8.4", | ||
| "@types/node": "^25.6.0", | ||
| "@xylabs/toolchain": "~7.10.4", | ||
| "@xylabs/tsconfig": "~7.10.4", | ||
| "esbuild": "^0.28.0", | ||
| "typescript": "^5", | ||
| "vite": "^8.0.5", | ||
| "vitest": "^4.1.2" | ||
| "vite": "^8.0.8", | ||
| "vitest": "^4.1.4" | ||
| }, | ||
| "engines": { | ||
| "node": ">=18" | ||
| }, | ||
| "publishConfig": { | ||
@@ -58,0 +58,0 @@ "access": "public" |
+298
-286
| # @xylabs/object-model | ||
| [![logo][]](https://xylabs.com) | ||
| [![npm][npm-badge]][npm-link] | ||
| [![license][license-badge]][license-link] | ||
| [![main-build][]][main-build-link] | ||
| [![npm-badge][]][npm-link] | ||
| [![npm-downloads-badge][]][npm-link] | ||
| [![jsdelivr-badge][]][jsdelivr-link] | ||
| [![npm-license-badge][]](LICENSE) | ||
| [![codacy-badge][]][codacy-link] | ||
| [![codeclimate-badge][]][codeclimate-link] | ||
| [![snyk-badge][]][snyk-link] | ||
| [![socket-badge][]][socket-link] | ||
| > Base functionality used throughout XY Labs TypeScript/JavaScript libraries | ||
| ## Install | ||
| Base functionality used throughout XY Labs TypeScript/JavaScript libraries | ||
| Using npm: | ||
| ```sh | ||
| npm install {{name}} | ||
| ``` | ||
| Using yarn: | ||
| ## Reference | ||
| ```sh | ||
| yarn add {{name}} | ||
| ``` | ||
| **@xylabs/object-model** | ||
| Using pnpm: | ||
| *** | ||
| ```sh | ||
| pnpm add {{name}} | ||
| ``` | ||
| ## Interfaces | ||
| Using bun: | ||
| | Interface | Description | | ||
| | ------ | ------ | | ||
| | [TypeCheckConfig](#interfaces/TypeCheckConfig) | Configuration options for type check functions, with optional logging. | | ||
| | [TypeCheckRequiredConfig](#interfaces/TypeCheckRequiredConfig) | Type check configuration that marks the value as required, causing assertions on failure. | | ||
| | [TypeCheckOptionalConfig](#interfaces/TypeCheckOptionalConfig) | Type check configuration that marks the value as optional, returning undefined on failure. | | ||
| ```sh | ||
| bun add {{name}} | ||
| ``` | ||
| ## Type Aliases | ||
| | Type Alias | Description | | ||
| | ------ | ------ | | ||
| | [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 | | ||
| | [AsTypeFunction](#type-aliases/AsTypeFunction) | A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads. | | ||
| | [AsOptionalTypeFunction](#type-aliases/AsOptionalTypeFunction) | A simplified type-narrowing function that returns T or undefined, without assertion support. | | ||
| | [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. | | ||
| | [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 | | ||
| | [StringOrAlertFunction](#type-aliases/StringOrAlertFunction) | A string message or function that produces an assertion error message for a failed type check. | | ||
| | [TypeCheck](#type-aliases/TypeCheck) | A type guard function that checks whether a value conforms to type T, with optional configuration. | | ||
| ## License | ||
| ### interfaces | ||
| See the [LICENSE](LICENSE) file for license rights and limitations (LGPL-3.0-only). | ||
| ### <a id="TypeCheckConfig"></a>TypeCheckConfig | ||
| ## Reference | ||
| ### packages | ||
| ### object-model | ||
| ### .temp-typedoc | ||
| ### interfaces | ||
| ### <a id="AsTypeFunction"></a>AsTypeFunction | ||
| [**@xylabs/object-model**](#../README) | ||
@@ -54,121 +55,95 @@ | ||
| Configuration options for type check functions, with optional logging. | ||
| A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads. | ||
| ## Extended by | ||
| ## Type Parameters | ||
| - [`TypeCheckRequiredConfig`](#TypeCheckRequiredConfig) | ||
| - [`TypeCheckOptionalConfig`](#TypeCheckOptionalConfig) | ||
| ### T | ||
| ## Properties | ||
| `T` *extends* `AnyNonPromise` = `AnyNonPromise` | ||
| | Property | Type | | ||
| | ------ | ------ | | ||
| | <a id="log"></a> `log?` | `boolean` \| `Logger` | | ||
| ## Call Signature | ||
| ### <a id="TypeCheckOptionalConfig"></a>TypeCheckOptionalConfig | ||
| ```ts | ||
| AsTypeFunction<TType>(value): TType | undefined; | ||
| ``` | ||
| [**@xylabs/object-model**](#../README) | ||
| A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads. | ||
| *** | ||
| ### Type Parameters | ||
| Type check configuration that marks the value as optional, returning undefined on failure. | ||
| ### TType | ||
| ## Extends | ||
| `TType` *extends* `AnyNonPromise` | ||
| - [`TypeCheckConfig`](#TypeCheckConfig) | ||
| ### Parameters | ||
| ## Properties | ||
| ### value | ||
| | Property | Type | Inherited from | | ||
| | ------ | ------ | ------ | | ||
| | <a id="log"></a> `log?` | `boolean` \| `Logger` | [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log) | | ||
| | <a id="required"></a> `required` | `false` | - | | ||
| `AnyNonPromise` | ||
| ### <a id="TypeCheckRequiredConfig"></a>TypeCheckRequiredConfig | ||
| ### Returns | ||
| [**@xylabs/object-model**](#../README) | ||
| `TType` \| `undefined` | ||
| *** | ||
| ## Call Signature | ||
| Type check configuration that marks the value as required, causing assertions on failure. | ||
| ```ts | ||
| AsTypeFunction<TType>(value, config): TType; | ||
| ``` | ||
| ## Extends | ||
| A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads. | ||
| - [`TypeCheckConfig`](#TypeCheckConfig) | ||
| ### Type Parameters | ||
| ## Properties | ||
| ### TType | ||
| | Property | Type | Inherited from | | ||
| | ------ | ------ | ------ | | ||
| | <a id="log"></a> `log?` | `boolean` \| `Logger` | [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log) | | ||
| | <a id="required"></a> `required` | `true` | - | | ||
| `TType` *extends* `AnyNonPromise` | ||
| ### type-aliases | ||
| ### Parameters | ||
| ### <a id="AnyObject"></a>AnyObject | ||
| ### value | ||
| [**@xylabs/object-model**](#../README) | ||
| `AnyNonPromise` | ||
| *** | ||
| ### config | ||
| ```ts | ||
| type AnyObject = EmptyObject & Partial<Record<TypedKey, unknown>>; | ||
| ``` | ||
| [`TypeCheckRequiredConfig`](#TypeCheckRequiredConfig) | ||
| 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 | ||
| ### Returns | ||
| ### <a id="AsOptionalTypeFunction"></a>AsOptionalTypeFunction | ||
| `TType` | ||
| [**@xylabs/object-model**](#../README) | ||
| ## Call Signature | ||
| *** | ||
| ```ts | ||
| type AsOptionalTypeFunction<T> = <TType>(value: AnyNonPromise) => TType | undefined; | ||
| AsTypeFunction<TType>(value, config): TType | undefined; | ||
| ``` | ||
| A simplified type-narrowing function that returns T or undefined, without assertion support. | ||
| A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads. | ||
| ## Type Parameters | ||
| ### Type Parameters | ||
| | Type Parameter | Default type | | ||
| | ------ | ------ | | ||
| | `T` *extends* `AnyNonPromise` | `AnyNonPromise` | | ||
| ### TType | ||
| ## Type Parameters | ||
| `TType` *extends* `AnyNonPromise` | ||
| | Type Parameter | | ||
| | ------ | | ||
| | `TType` *extends* `AnyNonPromise` | | ||
| ### Parameters | ||
| ## Parameters | ||
| ### value | ||
| | Parameter | Type | | ||
| | ------ | ------ | | ||
| | `value` | `AnyNonPromise` | | ||
| `AnyNonPromise` | ||
| ## Returns | ||
| ### config | ||
| `TType` \| `undefined` | ||
| \| [`TypeCheckConfig`](#TypeCheckConfig) | ||
| \| [`TypeCheckOptionalConfig`](#TypeCheckOptionalConfig) | ||
| ### <a id="AsTypeFunction"></a>AsTypeFunction | ||
| ### Returns | ||
| [**@xylabs/object-model**](#../README) | ||
| `TType` \| `undefined` | ||
| *** | ||
| ## Call Signature | ||
| ```ts | ||
| 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; | ||
| }; | ||
| AsTypeFunction<TType>(value, assert): TType | undefined; | ||
| ``` | ||
@@ -178,25 +153,17 @@ | ||
| ## Type Parameters | ||
| ### Type Parameters | ||
| | Type Parameter | Default type | | ||
| | ------ | ------ | | ||
| | `T` *extends* `AnyNonPromise` | `AnyNonPromise` | | ||
| ### TType | ||
| ## Call Signature | ||
| `TType` *extends* `AnyNonPromise` | ||
| ```ts | ||
| <TType>(value: AnyNonPromise): TType | undefined; | ||
| ``` | ||
| ### Parameters | ||
| ### Type Parameters | ||
| ### value | ||
| | Type Parameter | | ||
| | ------ | | ||
| | `TType` *extends* `AnyNonPromise` | | ||
| `AnyNonPromise` | ||
| ### Parameters | ||
| ### assert | ||
| | Parameter | Type | | ||
| | ------ | ------ | | ||
| | `value` | `AnyNonPromise` | | ||
| [`StringOrAlertFunction`](#../type-aliases/StringOrAlertFunction)\<`TType`\> | ||
@@ -210,18 +177,30 @@ ### Returns | ||
| ```ts | ||
| <TType>(value: AnyNonPromise, config: TypeCheckRequiredConfig): TType; | ||
| AsTypeFunction<TType>( | ||
| value, | ||
| assert, | ||
| config): TType; | ||
| ``` | ||
| A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads. | ||
| ### Type Parameters | ||
| | Type Parameter | | ||
| | ------ | | ||
| | `TType` *extends* `AnyNonPromise` | | ||
| ### TType | ||
| `TType` *extends* `AnyNonPromise` | ||
| ### Parameters | ||
| | Parameter | Type | | ||
| | ------ | ------ | | ||
| | `value` | `AnyNonPromise` | | ||
| | `config` | [`TypeCheckRequiredConfig`](#../interfaces/TypeCheckRequiredConfig) | | ||
| ### value | ||
| `AnyNonPromise` | ||
| ### assert | ||
| [`StringOrAlertFunction`](#../type-aliases/StringOrAlertFunction)\<`TType`\> | ||
| ### config | ||
| [`TypeCheckRequiredConfig`](#TypeCheckRequiredConfig) | ||
| ### Returns | ||
@@ -234,20 +213,31 @@ | ||
| ```ts | ||
| <TType>(value: AnyNonPromise, config: | ||
| | TypeCheckConfig | ||
| | TypeCheckOptionalConfig): TType | undefined; | ||
| AsTypeFunction<TType>( | ||
| value, | ||
| assert, | ||
| config): TType | undefined; | ||
| ``` | ||
| A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads. | ||
| ### Type Parameters | ||
| | Type Parameter | | ||
| | ------ | | ||
| | `TType` *extends* `AnyNonPromise` | | ||
| ### TType | ||
| `TType` *extends* `AnyNonPromise` | ||
| ### Parameters | ||
| | Parameter | Type | | ||
| | ------ | ------ | | ||
| | `value` | `AnyNonPromise` | | ||
| | `config` | \| [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) \| [`TypeCheckOptionalConfig`](#../interfaces/TypeCheckOptionalConfig) | | ||
| ### value | ||
| `AnyNonPromise` | ||
| ### assert | ||
| [`StringOrAlertFunction`](#../type-aliases/StringOrAlertFunction)\<`TType`\> | ||
| ### config | ||
| \| [`TypeCheckConfig`](#TypeCheckConfig) | ||
| \| [`TypeCheckOptionalConfig`](#TypeCheckOptionalConfig) | ||
| ### Returns | ||
@@ -257,24 +247,33 @@ | ||
| ### <a id="TypeCheck"></a>TypeCheck | ||
| [**@xylabs/object-model**](#../README) | ||
| *** | ||
| A type guard function that checks whether a value conforms to type T, with optional configuration. | ||
| ## Type Parameters | ||
| ### T | ||
| `T` *extends* `TypedValue` | ||
| ## Call Signature | ||
| ```ts | ||
| <TType>(value: AnyNonPromise, assert: StringOrAlertFunction<TType>): TType | undefined; | ||
| TypeCheck(obj): obj is T; | ||
| ``` | ||
| ### Type Parameters | ||
| A type guard function that checks whether a value conforms to type T, with optional configuration. | ||
| | Type Parameter | | ||
| | ------ | | ||
| | `TType` *extends* `AnyNonPromise` | | ||
| ### Parameters | ||
| | Parameter | Type | | ||
| | ------ | ------ | | ||
| | `value` | `AnyNonPromise` | | ||
| | `assert` | [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\> | | ||
| ### obj | ||
| `AnyNonPromise` | ||
| ### Returns | ||
| `TType` \| `undefined` | ||
| `obj is T` | ||
@@ -284,25 +283,20 @@ ## Call Signature | ||
| ```ts | ||
| <TType>( | ||
| value: AnyNonPromise, | ||
| assert: StringOrAlertFunction<TType>, | ||
| config: TypeCheckRequiredConfig): TType; | ||
| TypeCheck(obj, config): obj is T; | ||
| ``` | ||
| ### Type Parameters | ||
| A type guard function that checks whether a value conforms to type T, with optional configuration. | ||
| | Type Parameter | | ||
| | ------ | | ||
| | `TType` *extends* `AnyNonPromise` | | ||
| ### Parameters | ||
| | Parameter | Type | | ||
| | ------ | ------ | | ||
| | `value` | `AnyNonPromise` | | ||
| | `assert` | [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\> | | ||
| | `config` | [`TypeCheckRequiredConfig`](#../interfaces/TypeCheckRequiredConfig) | | ||
| ### obj | ||
| `AnyNonPromise` | ||
| ### config | ||
| [`TypeCheckConfig`](#TypeCheckConfig) | ||
| ### Returns | ||
| `TType` | ||
| `obj is T` | ||
@@ -312,29 +306,22 @@ ## Call Signature | ||
| ```ts | ||
| <TType>( | ||
| value: AnyNonPromise, | ||
| assert: StringOrAlertFunction<TType>, | ||
| config: | ||
| | TypeCheckConfig | ||
| | TypeCheckOptionalConfig): TType | undefined; | ||
| TypeCheck(obj, config): obj is T; | ||
| ``` | ||
| ### Type Parameters | ||
| A type guard function that checks whether a value conforms to type T, with optional configuration. | ||
| | Type Parameter | | ||
| | ------ | | ||
| | `TType` *extends* `AnyNonPromise` | | ||
| ### Parameters | ||
| | Parameter | Type | | ||
| | ------ | ------ | | ||
| | `value` | `AnyNonPromise` | | ||
| | `assert` | [`StringOrAlertFunction`](#StringOrAlertFunction)\<`TType`\> | | ||
| | `config` | \| [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) \| [`TypeCheckOptionalConfig`](#../interfaces/TypeCheckOptionalConfig) | | ||
| ### obj | ||
| `AnyNonPromise` | ||
| ### config | ||
| `number` \| [`TypeCheckConfig`](#TypeCheckConfig) \| `undefined` | ||
| ### Returns | ||
| `TType` \| `undefined` | ||
| `obj is T` | ||
| ### <a id="Compare"></a>Compare | ||
| ### <a id="TypeCheckConfig"></a>TypeCheckConfig | ||
@@ -345,64 +332,85 @@ [**@xylabs/object-model**](#../README) | ||
| Configuration options for type check functions, with optional logging. | ||
| ## Extended by | ||
| - [`TypeCheckRequiredConfig`](#TypeCheckRequiredConfig) | ||
| - [`TypeCheckOptionalConfig`](#TypeCheckOptionalConfig) | ||
| ## Properties | ||
| ### log? | ||
| ```ts | ||
| type Compare<T> = (a: T, b: T) => number; | ||
| optional log?: boolean | Logger; | ||
| ``` | ||
| A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b. | ||
| ### <a id="TypeCheckOptionalConfig"></a>TypeCheckOptionalConfig | ||
| ## Type Parameters | ||
| [**@xylabs/object-model**](#../README) | ||
| | Type Parameter | | ||
| | ------ | | ||
| | `T` | | ||
| *** | ||
| ## Parameters | ||
| Type check configuration that marks the value as optional, returning undefined on failure. | ||
| | Parameter | Type | | ||
| | ------ | ------ | | ||
| | `a` | `T` | | ||
| | `b` | `T` | | ||
| ## Extends | ||
| ## Returns | ||
| - [`TypeCheckConfig`](#TypeCheckConfig) | ||
| `number` | ||
| ## Properties | ||
| ### <a id="EmptyObject"></a>EmptyObject | ||
| ### log? | ||
| [**@xylabs/object-model**](#../README) | ||
| ```ts | ||
| optional log?: boolean | Logger; | ||
| ``` | ||
| ### Inherited from | ||
| [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log) | ||
| *** | ||
| ### required | ||
| ```ts | ||
| type EmptyObject<T> = Exclude<{ [K in keyof T]?: never }, unknown[] | (...args: unknown[]) => unknown | null>; | ||
| required: false; | ||
| ``` | ||
| 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 | ||
| ### <a id="TypeCheckRequiredConfig"></a>TypeCheckRequiredConfig | ||
| ## Type Parameters | ||
| [**@xylabs/object-model**](#../README) | ||
| | Type Parameter | Default type | | ||
| | ------ | ------ | | ||
| | `T` *extends* `object` | `object` | | ||
| *** | ||
| ### <a id="StringOrAlertFunction"></a>StringOrAlertFunction | ||
| Type check configuration that marks the value as required, causing assertions on failure. | ||
| [**@xylabs/object-model**](#../README) | ||
| ## Extends | ||
| *** | ||
| - [`TypeCheckConfig`](#TypeCheckConfig) | ||
| ## Properties | ||
| ### log? | ||
| ```ts | ||
| type StringOrAlertFunction<T> = string | AssertExMessageFunc<T>; | ||
| optional log?: boolean | Logger; | ||
| ``` | ||
| A string message or function that produces an assertion error message for a failed type check. | ||
| ### Inherited from | ||
| ## Type Parameters | ||
| [`TypeCheckConfig`](#TypeCheckConfig).[`log`](TypeCheckConfig.md#log) | ||
| | Type Parameter | | ||
| | ------ | | ||
| | `T` *extends* `AnyNonPromise` | | ||
| *** | ||
| ### <a id="TypeCheck"></a>TypeCheck | ||
| ### required | ||
| ```ts | ||
| required: true; | ||
| ``` | ||
| ### type-aliases | ||
| ### <a id="AnyObject"></a>AnyObject | ||
| [**@xylabs/object-model**](#../README) | ||
@@ -413,111 +421,115 @@ | ||
| ```ts | ||
| type TypeCheck<T> = { | ||
| (obj: AnyNonPromise): obj is T; | ||
| (obj: AnyNonPromise, config: TypeCheckConfig): obj is T; | ||
| (obj: AnyNonPromise, config: | ||
| | number | ||
| | TypeCheckConfig | ||
| | undefined): obj is T; | ||
| }; | ||
| type AnyObject = EmptyObject & Partial<Record<TypedKey, unknown>>; | ||
| ``` | ||
| A type guard function that checks whether a value conforms to type T, with optional configuration. | ||
| 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 | ||
| ## Type Parameters | ||
| ### <a id="AsOptionalTypeFunction"></a>AsOptionalTypeFunction | ||
| | Type Parameter | | ||
| | ------ | | ||
| | `T` *extends* `TypedValue` | | ||
| [**@xylabs/object-model**](#../README) | ||
| ## Call Signature | ||
| *** | ||
| ```ts | ||
| (obj: AnyNonPromise): obj is T; | ||
| type AsOptionalTypeFunction<T> = <TType>(value) => TType | undefined; | ||
| ``` | ||
| ### Parameters | ||
| A simplified type-narrowing function that returns T or undefined, without assertion support. | ||
| | Parameter | Type | | ||
| | ------ | ------ | | ||
| | `obj` | `AnyNonPromise` | | ||
| ## Type Parameters | ||
| ### Returns | ||
| ### T | ||
| `obj is T` | ||
| `T` *extends* `AnyNonPromise` = `AnyNonPromise` | ||
| ## Call Signature | ||
| ## Type Parameters | ||
| ### TType | ||
| `TType` *extends* `T` | ||
| ## Parameters | ||
| ### value | ||
| `AnyNonPromise` | ||
| ## Returns | ||
| `TType` \| `undefined` | ||
| ### <a id="Compare"></a>Compare | ||
| [**@xylabs/object-model**](#../README) | ||
| *** | ||
| ```ts | ||
| (obj: AnyNonPromise, config: TypeCheckConfig): obj is T; | ||
| type Compare<T> = (a, b) => number; | ||
| ``` | ||
| ### Parameters | ||
| A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b. | ||
| | Parameter | Type | | ||
| | ------ | ------ | | ||
| | `obj` | `AnyNonPromise` | | ||
| | `config` | [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) | | ||
| ## Type Parameters | ||
| ### Returns | ||
| ### T | ||
| `obj is T` | ||
| `T` | ||
| ## Call Signature | ||
| ## Parameters | ||
| ### a | ||
| `T` | ||
| ### b | ||
| `T` | ||
| ## Returns | ||
| `number` | ||
| ### <a id="EmptyObject"></a>EmptyObject | ||
| [**@xylabs/object-model**](#../README) | ||
| *** | ||
| ```ts | ||
| (obj: AnyNonPromise, config: | ||
| | number | ||
| | TypeCheckConfig | ||
| | undefined): obj is T; | ||
| type EmptyObject<T> = Exclude<{ [K in keyof T]?: never }, unknown[] | ((...args) => unknown) | null>; | ||
| ``` | ||
| ### Parameters | ||
| 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 | ||
| | Parameter | Type | | ||
| | ------ | ------ | | ||
| | `obj` | `AnyNonPromise` | | ||
| | `config` | \| `number` \| [`TypeCheckConfig`](#../interfaces/TypeCheckConfig) \| `undefined` | | ||
| ## Type Parameters | ||
| ### Returns | ||
| ### T | ||
| `obj is T` | ||
| `T` *extends* `object` = `object` | ||
| ### <a id="StringOrAlertFunction"></a>StringOrAlertFunction | ||
| Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js) | ||
| [**@xylabs/object-model**](#../README) | ||
| ## Maintainers | ||
| *** | ||
| - [Arie Trouw](https://github.com/arietrouw) ([arietrouw.com](https://arietrouw.com)) | ||
| - [Matt Jones](https://github.com/jonesmac) | ||
| - [Joel Carter](https://github.com/JoelBCarter) | ||
| - [Jordan Trouw](https://github.com/jordantrouw) | ||
| ```ts | ||
| type StringOrAlertFunction<T> = string | AssertExMessageFunc<T>; | ||
| ``` | ||
| ## License | ||
| A string message or function that produces an assertion error message for a failed type check. | ||
| > See the [LICENSE](LICENSE) file for license details | ||
| ## Type Parameters | ||
| ## Credits | ||
| ### T | ||
| [Made with 🔥 and ❄️ by XYLabs](https://xylabs.com) | ||
| `T` *extends* `AnyNonPromise` | ||
| [logo]: https://cdn.xy.company/img/brand/XYPersistentCompany_Logo_Icon_Colored.svg | ||
| [main-build]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml/badge.svg | ||
| [main-build-link]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml | ||
| [npm-badge]: https://img.shields.io/npm/v/@xylabs/object-model.svg | ||
| [npm-link]: https://www.npmjs.com/package/@xylabs/object-model | ||
| [codacy-badge]: https://app.codacy.com/project/badge/Grade/c8e15e14f37741c18cfb47ac7245c698 | ||
| [codacy-link]: https://www.codacy.com/gh/xylabs/sdk-js/dashboard?utm_source=github.com&utm_medium=referral&utm_content=xylabs/sdk-js&utm_campaign=Badge_Grade | ||
| [codeclimate-badge]: https://api.codeclimate.com/v1/badges/c5eb068f806f0b047ea7/maintainability | ||
| [codeclimate-link]: https://codeclimate.com/github/xylabs/sdk-js/maintainability | ||
| [snyk-badge]: https://snyk.io/test/github/xylabs/sdk-js/badge.svg?targetFile=package.json | ||
| [snyk-link]: https://snyk.io/test/github/xylabs/sdk-js?targetFile=package.json | ||
| [npm-downloads-badge]: https://img.shields.io/npm/dw/@xylabs/object-model | ||
| [npm-license-badge]: https://img.shields.io/npm/l/@xylabs/object-model | ||
| [jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xylabs/object-model/badge | ||
| [jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xylabs/object-model | ||
| [socket-badge]: https://socket.dev/api/badge/npm/package/@xylabs/object-model | ||
| [socket-link]: https://socket.dev/npm/package/@xylabs/object-model | ||
| [license-badge]: https://img.shields.io/npm/l/@xylabs/object-model.svg | ||
| [license-link]: https://github.com/xylabs/sdk-js/blob/main/LICENSE |
7
-12.5%527
2.53%56600
-7.68%69
-2.82%Updated
Updated
Updated
Updated