npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xylabs/object

v5.0.87

Published

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

Readme

@xylabs/object

logo

main-build npm-badge npm-downloads-badge jsdelivr-badge npm-license-badge codacy-badge codeclimate-badge snyk-badge socket-badge

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

Reference

@xylabs/object


Modules

| Module | Description | | ------ | ------ | | index-deprecated | - | | index-un-deprecated | - | | index | - |

index

index-deprecated

classes

### <a id="IsObjectFactory"></a>IsObjectFactory

@xylabs/object


Factory class for creating type-guard functions that validate objects against a given shape and optional additional checks.

Type Parameters

| Type Parameter | | ------ | | T extends TypedObject |

Constructors

Constructor

new IsObjectFactory<T>(): IsObjectFactory<T>;

Returns

IsObjectFactory<T>

Methods

create()

create(shape?: ObjectTypeShape, additionalChecks?: TypeCheck<TypedObject>[]): TypeCheck<T>;

Creates a type-guard function that validates an object matches the given shape and passes additional checks.

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | shape? | ObjectTypeShape | An optional map of property names to expected types. | | additionalChecks? | TypeCheck<TypedObject>[] | Optional extra type-check functions to run after shape validation. |

Returns

TypeCheck<T>

A type-guard function for type T.

### <a id="ObjectWrapper"></a>ObjectWrapper

@xylabs/object


Abstract base class that wraps an object and provides typed access to it.

Extended by

Type Parameters

| Type Parameter | Default type | | ------ | ------ | | T extends EmptyObject | EmptyObject |

Constructors

Constructor

new ObjectWrapper<T>(obj: T): ObjectWrapper<T>;

Parameters

| Parameter | Type | | ------ | ------ | | obj | T |

Returns

ObjectWrapper<T>

Properties

| Property | Modifier | Type | | ------ | ------ | ------ | | obj | readonly | T |

Accessors

stringKeyObj

Get Signature

get protected stringKeyObj(): StringKeyObject;

Returns

StringKeyObject

### <a id="ValidatorBase"></a>ValidatorBase

@xylabs/object


Abstract base class for validators that wraps a partial object and provides a validation method.

Extends

Type Parameters

| Type Parameter | Default type | | ------ | ------ | | T extends EmptyObject | AnyObject |

Implements

Constructors

Constructor

new ValidatorBase<T>(obj: T): ValidatorBase<T>;

Parameters

| Parameter | Type | | ------ | ------ | | obj | T |

Returns

ValidatorBase<T>

Inherited from

ObjectWrapper.constructor

Properties

| Property | Modifier | Type | Inherited from | | ------ | ------ | ------ | ------ | | obj | readonly | T | ObjectWrapper.obj |

Accessors

stringKeyObj

Get Signature

get protected stringKeyObj(): StringKeyObject;

Returns

StringKeyObject

Inherited from

ObjectWrapper.stringKeyObj

Methods

validate()

abstract validate(payload: T): Promisable<Error[]>;

Parameters

| Parameter | Type | | ------ | ------ | | payload | T |

Returns

Promisable<Error[]>

Implementation of

Validator.validate

functions

### <a id="createDeepMerge"></a>createDeepMerge

@xylabs/object


function createDeepMerge(options: MergeOptions): <T>(...objects: T) => MergeAll<T>;

Creates a deep merge function with the specified options.

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | options | MergeOptions | Options for merging. |

Returns

A deep merge function configured for the specified options.

<T>(...objects: T): MergeAll<T>;

Type Parameters

| Type Parameter | | ------ | | T extends AnyObject[] |

Parameters

| Parameter | Type | | ------ | ------ | | ...objects | T |

Returns

MergeAll<T>

### <a id="isObject"></a>isObject

@xylabs/object


Call Signature

function isObject(value: unknown): value is object;

Type guard that checks whether a value is a plain object (not null and not an array).

Parameters

| Parameter | Type | | ------ | ------ | | value | unknown |

Returns

value is object

Call Signature

function isObject<T>(value: T): value is Extract<T, object>;

Type guard that checks whether a value is a plain object (not null and not an array).

Type Parameters

| Type Parameter | | ------ | | T extends object |

Parameters

| Parameter | Type | | ------ | ------ | | value | T |

Returns

value is Extract<T, object>

### <a id="isType"></a>isType

@xylabs/object


function isType(value: unknown, expectedType: FieldType): boolean;

Parameters

| Parameter | Type | | ------ | ------ | | value | unknown | | expectedType | FieldType |

Returns

boolean

Deprecated

use from @xylabs/typeof instead

### <a id="omitBy"></a>omitBy

@xylabs/object


function omitBy<T>(
   obj: T, 
   predicate: OmitByPredicate, 
maxDepth?: number): Partial<T>;

Creates a new object excluding properties that satisfy the predicate, with optional recursive depth.

Type Parameters

| Type Parameter | | ------ | | T extends object |

Parameters

| Parameter | Type | Default value | Description | | ------ | ------ | ------ | ------ | | obj | T | undefined | The source object to omit properties from. | | predicate | OmitByPredicate | undefined | A function that returns true for properties to exclude. | | maxDepth | number | 1 | Maximum recursion depth for nested objects. |

Returns

Partial<T>

A partial copy of the object without matching properties.

### <a id="omitByPrefix"></a>omitByPrefix

@xylabs/object


function omitByPrefix<T, P>(
   payload: T, 
   prefix: P, 
maxDepth?: number): DeepOmitStartsWith<T, P>;

Omits all properties whose keys start with the given prefix, recursively through nested objects.

Type Parameters

| Type Parameter | | ------ | | T extends object | | P extends string |

Parameters

| Parameter | Type | Default value | Description | | ------ | ------ | ------ | ------ | | payload | T | undefined | The source object. | | prefix | P | undefined | The string prefix to match keys against. | | maxDepth | number | 100 | Maximum recursion depth. |

Returns

DeepOmitStartsWith<T, P>

A new object without properties that have matching prefixed keys.

### <a id="pickBy"></a>pickBy

@xylabs/object


function pickBy<T>(
   obj: T, 
   predicate: PickByPredicate, 
maxDepth?: number): Partial<T>;

Creates a new object containing only the properties that satisfy the predicate, with optional recursive depth.

Type Parameters

| Type Parameter | | ------ | | T extends object |

Parameters

| Parameter | Type | Default value | Description | | ------ | ------ | ------ | ------ | | obj | T | undefined | The source object to pick properties from. | | predicate | PickByPredicate | undefined | A function that returns true for properties to include. | | maxDepth | number | 1 | Maximum recursion depth for nested objects. |

Returns

Partial<T>

A partial copy of the object with only matching properties.

### <a id="pickByPrefix"></a>pickByPrefix

@xylabs/object


function pickByPrefix<T, P>(
   payload: T, 
   prefix: P, 
maxDepth?: number): DeepPickStartsWith<T, P>;

Picks all properties whose keys start with the given prefix, recursively through nested objects.

Type Parameters

| Type Parameter | | ------ | | T extends object | | P extends string |

Parameters

| Parameter | Type | Default value | Description | | ------ | ------ | ------ | ------ | | payload | T | undefined | The source object. | | prefix | P | undefined | The string prefix to match keys against. | | maxDepth | number | 100 | Maximum recursion depth. |

Returns

DeepPickStartsWith<T, P>

A new object containing only properties with matching prefixed keys.

### <a id="removeFields"></a>removeFields

@xylabs/object


function removeFields<T, K>(obj: T, fields: K[]): Omit<T, K>;

Returns a shallow copy of the object with the specified fields removed.

Type Parameters

| Type Parameter | | ------ | | T extends object | | K extends string | number | symbol |

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | obj | T | The source object. | | fields | K[] | An array of keys to remove. |

Returns

Omit<T, K>

A new object without the specified fields.

### <a id="toSafeJson"></a>toSafeJson

@xylabs/object


function toSafeJson(value: unknown, maxDepth?: number): unknown;

Converts a value to a JSON-safe representation, handling circular references and non-serializable types.

Parameters

| Parameter | Type | Default value | Description | | ------ | ------ | ------ | ------ | | value | unknown | undefined | The value to convert. | | maxDepth | number | 3 | Maximum recursion depth. |

Returns

unknown

A JSON-safe value.

### <a id="toSafeJsonArray"></a>toSafeJsonArray

@xylabs/object


function toSafeJsonArray(
   value: unknown[], 
   cycleList?: unknown[], 
   maxDepth?: number): unknown[];

Converts an array to a JSON-safe array, handling circular references and depth limits.

Parameters

| Parameter | Type | Default value | Description | | ------ | ------ | ------ | ------ | | value | unknown[] | undefined | The array to convert. | | cycleList? | unknown[] | undefined | Tracks visited objects to detect circular references. | | maxDepth? | number | 3 | Maximum recursion depth before truncating. |

Returns

unknown[]

A JSON-safe array representation.

### <a id="toSafeJsonObject"></a>toSafeJsonObject

@xylabs/object


function toSafeJsonObject(
   value: object, 
   cycleList?: unknown[], 
   maxDepth?: number): JsonObject;

Converts an object to a JSON-safe object, handling circular references and depth limits.

Parameters

| Parameter | Type | Default value | Description | | ------ | ------ | ------ | ------ | | value | object | undefined | The object to convert. | | cycleList? | unknown[] | undefined | Tracks visited objects to detect circular references. | | maxDepth? | number | 3 | Maximum recursion depth before truncating. |

Returns

JsonObject

A JSON-safe object representation.

### <a id="toSafeJsonString"></a>toSafeJsonString

@xylabs/object


function toSafeJsonString(value: unknown, maxDepth?: number): string;

Converts a value to a pretty-printed JSON string, safely handling circular references and non-JSON types.

Parameters

| Parameter | Type | Default value | Description | | ------ | ------ | ------ | ------ | | value | unknown | undefined | The value to serialize. | | maxDepth | number | 3 | Maximum recursion depth. |

Returns

string

A formatted JSON string.

### <a id="toSafeJsonValue"></a>toSafeJsonValue

@xylabs/object


function toSafeJsonValue(
   value: unknown, 
   cycleList?: unknown[], 
   maxDepth?: number): unknown;

Converts an unknown value to a JSON-safe value, replacing circular references with '[Circular]' and non-JSON types with descriptive placeholder strings.

Parameters

| Parameter | Type | Default value | Description | | ------ | ------ | ------ | ------ | | value | unknown | undefined | The value to convert. | | cycleList? | unknown[] | undefined | Tracks visited objects to detect circular references. | | maxDepth? | number | 3 | Maximum recursion depth before truncating with '[MaxDepth]'. |

Returns

unknown

A JSON-safe representation of the value.

interfaces

### <a id="ObjectTypeConfig"></a>ObjectTypeConfig

@xylabs/object


Configuration options for object type checking.

Extends

Properties

| Property | Type | Inherited from | | ------ | ------ | ------ | | log? | boolean | Logger | TypeCheckConfig.log |

### <a id="TypeCheckConfig"></a>TypeCheckConfig

@xylabs/object


Configuration options for type check functions, with optional logging.

Extended by

Properties

| Property | Type | | ------ | ------ | | log? | boolean | Logger |

### <a id="TypeCheckOptionalConfig"></a>TypeCheckOptionalConfig

@xylabs/object


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 | - |

### <a id="TypeCheckRequiredConfig"></a>TypeCheckRequiredConfig

@xylabs/object


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 | - |

### <a id="Validator"></a>Validator

@xylabs/object


Interface for validating objects and returning any errors found.

Type Parameters

| Type Parameter | Default type | | ------ | ------ | | T extends EmptyObject | AnyObject |

Methods

validate()

validate(payload: T): Promisable<Error[]>;

Parameters

| Parameter | Type | | ------ | ------ | | payload | T |

Returns

Promisable<Error[]>

type-aliases

### <a id="AnyObject"></a>AnyObject

@xylabs/object


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

### <a id="AsOptionalTypeFunction"></a>AsOptionalTypeFunction

@xylabs/object


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

### <a id="AsTypeFunction"></a>AsTypeFunction

@xylabs/object


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

### <a id="Compare"></a>Compare

@xylabs/object


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

### <a id="DeepOmitStartsWith"></a>DeepOmitStartsWith

@xylabs/object


type DeepOmitStartsWith<T, Prefix> = T extends infer U[] ? DeepOmitStartsWith<U, Prefix>[] : T extends object ? { [K in keyof T as K extends string ? K extends `${Prefix}${string}` ? never : K : K]: DeepOmitStartsWith<T[K], Prefix> } : T;

Recursively omits keys that start with the given prefix, including in nested objects and arrays.

Type Parameters

| Type Parameter | | ------ | | T | | Prefix extends string |

### <a id="DeepPickStartsWith"></a>DeepPickStartsWith

@xylabs/object


type DeepPickStartsWith<T, Prefix> = T extends infer U[] ? DeepPickStartsWith<U, Prefix>[] : T extends object ? { [K in keyof T as K extends string ? K extends `${Prefix}${string}` ? K : never : K]: DeepPickStartsWith<T[K], Prefix> } : T;

Recursively picks only the keys that start with the given prefix, including in nested objects and arrays.

Type Parameters

| Type Parameter | | ------ | | T | | Prefix extends string |

### <a id="DeepRestrictToJson"></a>DeepRestrictToJson

@xylabs/object


type DeepRestrictToJson<T> = { [K in keyof T as K extends string ? K : never]: T[K] extends (infer U)[] ? DeepRestrictToJson<U>[] : T[K] extends object ? DeepRestrictToJson<T[K]> : T[K] extends JsonValue ? T[K] : never };

Recursively restricts an object type to only JSON-compatible values, excluding non-serializable types.

Type Parameters

| Type Parameter | | ------ | | T |

### <a id="DeepRestrictToStringKeys"></a>DeepRestrictToStringKeys

@xylabs/object


type DeepRestrictToStringKeys<T> = { [K in keyof T as K extends string ? K : never]: T[K] extends (infer U)[] ? DeepRestrictToStringKeys<U>[] : T[K] extends object ? DeepRestrictToStringKeys<T[K]> : T[K] };

Recursively removes all non-string keys from an object type, including in nested objects and arrays.

Type Parameters

| Type Parameter | | ------ | | T |

### <a id="EmptyObject"></a>EmptyObject

@xylabs/object


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 |

### <a id="JsonArray"></a>JsonArray

@xylabs/object


type JsonArray = z.infer<typeof JsonArrayZod>;

A JSON array containing JSON values.

### <a id="JsonObject"></a>JsonObject

@xylabs/object


type JsonObject = z.infer<typeof JsonObjectZod>;

A JSON object with string keys and JSON values.

### <a id="JsonValue"></a>JsonValue

@xylabs/object


type JsonValue = z.infer<typeof JsonValueZod>;

A recursive JSON value: string, number, boolean, null, array, or object.

### <a id="OmitByPredicate"></a>OmitByPredicate

@xylabs/object


type OmitByPredicate<T> = (value: T[keyof T], key: keyof T) => boolean;

A predicate function used to determine which properties to omit from an object.

Type Parameters

| Type Parameter | Default type | | ------ | ------ | | T extends EmptyObject | Record<string, unknown> |

Parameters

| Parameter | Type | | ------ | ------ | | value | T[keyof T] | | key | keyof T |

Returns

boolean

### <a id="OmitStartsWith"></a>OmitStartsWith

@xylabs/object


type OmitStartsWith<T, Prefix> = { [K in keyof T as K extends `${Prefix}${string}` ? never : K]: T[K] };

Omits the keys of T that start with the given prefix.

Type Parameters

| Type Parameter | | ------ | | T | | Prefix extends string |

### <a id="Optional"></a>Optional

@xylabs/object


type Optional<T, F> = Omit<T, F> & Partial<Pick<T, F>>;

Makes the specified fields of T optional while keeping the rest required.

Type Parameters

| Type Parameter | | ------ | | T extends object | | F extends keyof T |

### <a id="Override"></a>Override

@xylabs/object


type Override<T1, T2> = Omit<T1, keyof T2> & T2;

Overrides properties of T1 with those from T2.

Type Parameters

| Type Parameter | | ------ | | T1 | | T2 |

### <a id="PartialRecord"></a>PartialRecord

@xylabs/object


type PartialRecord<K, T> = { [P in K]?: T };

Type Parameters

| Type Parameter | | ------ | | K extends keyof any | | T |

Deprecated

use Partial<Record<>> instead

### <a id="PickByPredicate"></a>PickByPredicate

@xylabs/object


type PickByPredicate<T> = (value: T[keyof T], key: keyof T) => boolean;

A predicate function used to determine which properties to pick from an object.

Type Parameters

| Type Parameter | Default type | | ------ | ------ | | T extends EmptyObject | Record<string, unknown> |

Parameters

| Parameter | Type | | ------ | ------ | | value | T[keyof T] | | key | keyof T |

Returns

boolean

### <a id="PickStartsWith"></a>PickStartsWith

@xylabs/object


type PickStartsWith<T, Prefix> = { [K in keyof T as K extends `${Prefix}${string}` ? K : never]: T[K] };

Picks only the keys of T that start with the given prefix.

Type Parameters

| Type Parameter | | ------ | | T | | Prefix extends string |

### <a id="Simplify"></a>Simplify

@xylabs/object


type Simplify<T> = { [K in keyof T]: T[K] } & {
};

Flattens an intersection or complex mapped type into a single object type for better readability.

Type Parameters

| Type Parameter | | ------ | | T |

### <a id="StringKeyObject"></a>StringKeyObject

@xylabs/object


type StringKeyObject<T> = {
[key: string]: T;
};

An object type with string keys and values of type T.

Type Parameters

| Type Parameter | Default type | | ------ | ------ | | T | unknown |

Index Signature

[key: string]: T
### <a id="StringOrAlertFunction"></a>StringOrAlertFunction

@xylabs/object


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 |

### <a id="TypeCheck"></a>TypeCheck

@xylabs/object


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

### <a id="WithAdditional"></a>WithAdditional

@xylabs/object


type WithAdditional<T, TAdditional> = TAdditional extends EmptyObject ? T & TAdditional : T;

Intersects T with TAdditional if TAdditional is an object, otherwise returns T unchanged.

Type Parameters

| Type Parameter | Default type | | ------ | ------ | | T extends EmptyObject | void | - | | TAdditional extends EmptyObject | void | void |

variables

### <a id="AsObjectFactory"></a>AsObjectFactory

@xylabs/object


const AsObjectFactory: {
  create: <T>(typeCheck: TypeCheck<T>) => AsTypeFunction<T>;
  createOptional: <T>(typeCheck: TypeCheck<T>) => (value: AnyNonPromise) => T | undefined;
};

Factory for creating type-narrowing functions for TypedObject types.

Type Declaration

| Name | Type | | ------ | ------ | | create() | <T>(typeCheck: TypeCheck<T>) => AsTypeFunction<T> | | createOptional() | <T>(typeCheck: TypeCheck<T>) => (value: AnyNonPromise) => T | undefined |

### <a id="AsTypeFactory"></a>AsTypeFactory

@xylabs/object


const AsTypeFactory: {
  create: <T>(typeCheck: TypeCheck<T>) => AsTypeFunction<T>;
  createOptional: <T>(typeCheck: TypeCheck<T>) => (value: AnyNonPromise) => T | undefined;
};

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.

Type Declaration

| Name | Type | | ------ | ------ | | create() | <T>(typeCheck: TypeCheck<T>) => AsTypeFunction<T> | | createOptional() | <T>(typeCheck: TypeCheck<T>) => (value: AnyNonPromise) => T | undefined |

### <a id="JsonObjectZod"></a>JsonObjectZod

@xylabs/object


const JsonObjectZod: ZodRecord<ZodString, ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>;

Zod schema for a JSON object with string keys and recursive JSON values.

### <a id="asAnyObject"></a>asAnyObject

@xylabs/object


const asAnyObject: AsTypeFunction<AnyObject>;

Type-narrowing function that casts a value to AnyObject if it is a plain object, or returns undefined.

### <a id="asJsonArray"></a>asJsonArray

@xylabs/object


const asJsonArray: {
<T>  (value: T): T & unknown[] | undefined;
<T>  (value: T, assert: ZodFactoryConfig): T & unknown[];
};

Casts a value to JsonArray or returns undefined if it does not conform.

Call Signature

<T>(value: T): T & unknown[] | undefined;

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T |

Returns

T & unknown[] | undefined

Call Signature

<T>(value: T, assert: ZodFactoryConfig): T & unknown[];

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T | | assert | ZodFactoryConfig |

Returns

T & unknown[]

### <a id="asJsonObject"></a>asJsonObject

@xylabs/object


const asJsonObject: {
<T>  (value: T): T & Record<string, unknown> | undefined;
<T>  (value: T, assert: ZodFactoryConfig): T & Record<string, unknown>;
};

Casts a value to JsonObject or returns undefined if it does not conform.

Call Signature

<T>(value: T): T & Record<string, unknown> | undefined;

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T |

Returns

T & Record<string, unknown> | undefined

Call Signature

<T>(value: T, assert: ZodFactoryConfig): T & Record<string, unknown>;

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T | | assert | ZodFactoryConfig |

Returns

T & Record<string, unknown>

### <a id="asJsonValue"></a>asJsonValue

@xylabs/object


const asJsonValue: {
<T>  (value: T): T | undefined;
<T>  (value: T, assert: ZodFactoryConfig): T;
};

Casts a value to JsonValue or returns undefined if it does not conform.

Call Signature

<T>(value: T): T | undefined;

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T |

Returns

T | undefined

Call Signature

<T>(value: T, assert: ZodFactoryConfig): T;

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T | | assert | ZodFactoryConfig |

Returns

T

### <a id="deepMerge"></a>deepMerge

@xylabs/object


const deepMerge: <T>(...objects: T) => MergeAll<T>;

Deeply merges multiple objects into a new object.

Type Parameters

| Type Parameter | | ------ | | T extends AnyObject[] |

Parameters

| Parameter | Type | Description | | ------ | ------ | ------ | | ...objects | T | Multiple objects to merge deeply. The function merges properties from all objects into a new object. If a property exists in multiple objects, the last object's value will be used. If a property is an object, it will be merged recursively. If a property is an array, it will be overwritten by the last object's value. If a property is a primitive value, it will be overwritten by the last object's value. If a property is undefined in the source, it will be skipped. If a property is a symbol, it will be merged as well. |

Returns

MergeAll<T>

A new object with the merged properties.

### <a id="isJsonArray"></a>isJsonArray

@xylabs/object


const isJsonArray: <T>(value: T) => value is T & unknown[];

Type guard that checks if a value is a valid JSON array.

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T |

Returns

value is T & unknown[]

### <a id="isJsonObject"></a>isJsonObject

@xylabs/object


const isJsonObject: <T>(value: T) => value is T & Record<string, unknown>;

Type guard that checks if a value is a valid JSON object.

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T |

Returns

value is T & Record<string, unknown>

### <a id="isJsonValue"></a>isJsonValue

@xylabs/object


const isJsonValue: <T>(value: T) => value is T;

Type guard that checks if a value is a valid JSON value.

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T |

Returns

value is T

### <a id="toJsonArray"></a>toJsonArray

@xylabs/object


const toJsonArray: {
<T>  (value: T): T & unknown[] | undefined;
<T>  (value: T, assert: ZodFactoryConfig): T & unknown[];
};

Parses a value into a JsonArray, throwing if it does not conform.

Call Signature

<T>(value: T): T & unknown[] | undefined;

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T |

Returns

T & unknown[] | undefined

Call Signature

<T>(value: T, assert: ZodFactoryConfig): T & unknown[];

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T | | assert | ZodFactoryConfig |

Returns

T & unknown[]

### <a id="toJsonObject"></a>toJsonObject

@xylabs/object


const toJsonObject: {
<T>  (value: T): T & Record<string, unknown> | undefined;
<T>  (value: T, assert: ZodFactoryConfig): T & Record<string, unknown>;
};

Parses a value into a JsonObject, throwing if it does not conform.

Call Signature

<T>(value: T): T & Record<string, unknown> | undefined;

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T |

Returns

T & Record<string, unknown> | undefined

Call Signature

<T>(value: T, assert: ZodFactoryConfig): T & Record<string, unknown>;

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T | | assert | ZodFactoryConfig |

Returns

T & Record<string, unknown>

### <a id="toJsonValue"></a>toJsonValue

@xylabs/object


const toJsonValue: {
<T>  (value: T): T | undefined;
<T>  (value: T, assert: ZodFactoryConfig): T;
};

Parses a value into a JsonValue, throwing if it does not conform.

Call Signature

<T>(value: T): T | undefined;

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T |

Returns

T | undefined

Call Signature

<T>(value: T, assert: ZodFactoryConfig): T;

Type Parameters

| Type Parameter | | ------ | | T |

Parameters

| Parameter | Type | | ------ | ------ | | value | T | | assert | ZodFactoryConfig |

Returns

T

index-un-deprecated

Part of sdk-js

Maintainers

License

See the LICENSE file for license details

Credits

Made with 🔥 and ❄️ by XYLabs