@xylabs/object-model
Advanced tools
| import type { AnyNonPromise } from '@xylabs/promise'; | ||
| import type { AsTypeFunction } from './AsTypeFunction.ts'; | ||
| import type { TypeCheck } from './types.ts'; | ||
| /** | ||
| * Factory for creating type-narrowing 'as' functions that cast a value to T or return undefined. | ||
| * Supports optional assertion messages and configuration for required/optional behavior. | ||
| */ | ||
| export declare const AsTypeFactory: { | ||
@@ -5,0 +9,0 @@ create: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => AsTypeFunction<T>; |
| 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> = { | ||
@@ -11,4 +12,5 @@ <TType extends T>(value: AnyNonPromise): 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; | ||
| }; |
@@ -0,1 +1,2 @@ | ||
| /** A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b. */ | ||
| export type Compare<T> = (a: T, b: T) => number; |
@@ -5,12 +5,17 @@ import type { AssertExMessageFunc } from '@xylabs/assert'; | ||
| import type { TypedValue } from '@xylabs/typeof'; | ||
| /** Configuration options for type check functions, with optional logging. */ | ||
| export interface TypeCheckConfig { | ||
| log?: boolean | Logger; | ||
| } | ||
| /** Type check configuration that marks the value as required, causing assertions on failure. */ | ||
| export interface TypeCheckRequiredConfig extends TypeCheckConfig { | ||
| required: true; | ||
| } | ||
| /** Type check configuration that marks the value as optional, returning undefined on failure. */ | ||
| export interface TypeCheckOptionalConfig extends TypeCheckConfig { | ||
| required: false; | ||
| } | ||
| /** A string message or function that produces an assertion error message for a failed type check. */ | ||
| export type StringOrAlertFunction<T extends AnyNonPromise> = string | AssertExMessageFunc<T>; | ||
| /** A type guard function that checks whether a value conforms to type T, with optional configuration. */ | ||
| export type TypeCheck<T extends TypedValue> = { | ||
@@ -17,0 +22,0 @@ (obj: AnyNonPromise): obj is T; |
+7
-7
| { | ||
| "name": "@xylabs/object-model", | ||
| "version": "5.0.83", | ||
| "version": "5.0.84", | ||
| "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries", | ||
@@ -38,10 +38,10 @@ "homepage": "https://xyo.network", | ||
| "dependencies": { | ||
| "@xylabs/assert": "~5.0.83", | ||
| "@xylabs/logger": "~5.0.83", | ||
| "@xylabs/promise": "~5.0.83", | ||
| "@xylabs/typeof": "~5.0.83" | ||
| "@xylabs/assert": "~5.0.84", | ||
| "@xylabs/logger": "~5.0.84", | ||
| "@xylabs/promise": "~5.0.84", | ||
| "@xylabs/typeof": "~5.0.84" | ||
| }, | ||
| "devDependencies": { | ||
| "@xylabs/ts-scripts-yarn3": "~7.4.11", | ||
| "@xylabs/tsconfig": "~7.4.11", | ||
| "@xylabs/ts-scripts-yarn3": "~7.4.13", | ||
| "@xylabs/tsconfig": "~7.4.13", | ||
| "typescript": "~5.9.3", | ||
@@ -48,0 +48,0 @@ "vitest": "~4.0.18" |
+16
-0
@@ -48,2 +48,4 @@ # @xylabs/object-model | ||
| Configuration options for type check functions, with optional logging. | ||
| ## Extended by | ||
@@ -68,2 +70,4 @@ | ||
| Type check configuration that marks the value as optional, returning undefined on failure. | ||
| ## Extends | ||
@@ -99,2 +103,4 @@ | ||
| Type check configuration that marks the value as required, causing assertions on failure. | ||
| ## Extends | ||
@@ -149,2 +155,4 @@ | ||
| A simplified type-narrowing function that returns T or undefined, without assertion support. | ||
| ## Type Parameters | ||
@@ -189,2 +197,4 @@ | ||
| A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads. | ||
| ## Type Parameters | ||
@@ -372,2 +382,4 @@ | ||
| A comparator function that returns a negative number if a < b, zero if a == b, and a positive number if a > b. | ||
| ## Type Parameters | ||
@@ -422,2 +434,4 @@ | ||
| A string message or function that produces an assertion error message for a failed type check. | ||
| ## Type Parameters | ||
@@ -443,2 +457,4 @@ | ||
| A type guard function that checks whether a value conforms to type T, with optional configuration. | ||
| ## Type Parameters | ||
@@ -445,0 +461,0 @@ |
57969
3.19%71
20.34%552
2.99%Updated
Updated
Updated
Updated