Launch Week Day 2: Introducing Reports: An Extensible Reporting Framework for Socket Data.Learn More
Socket
Book a DemoSign in
Socket

@xylabs/object

Package Overview
Dependencies
Maintainers
5
Versions
410
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xylabs/object

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

latest
Source
npmnpm
Version
5.0.100
Version published
Weekly downloads
1.7K
-75.18%
Maintainers
5
Weekly downloads
 
Created
Source

@xylabs/object

npm license

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

Install

Using npm:

npm install {{name}}

Using yarn:

yarn add {{name}}

Using pnpm:

pnpm add {{name}}

Using bun:

bun add {{name}}

License

See the LICENSE file for license rights and limitations (LGPL-3.0-only).

Reference

packages

object

### .temp-typedoc

  ### index

  ### index-deprecated

    ### functions

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

@xylabs/object

function isType(value, expectedType): boolean;

Parameters

value

unknown

expectedType

FieldType

Returns

boolean

Deprecated

use from @xylabs/typeof instead

  ### index-un-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

T

T extends TypedObject

Constructors

Constructor

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

Returns

IsObjectFactory<T>

Methods

create()

create(shape?, additionalChecks?): TypeCheck<T>;

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

Parameters

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

  • ValidatorBase

Type Parameters

T

T extends EmptyObject = EmptyObject

Constructors

Constructor

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

Parameters

obj

T

Returns

ObjectWrapper<T>

Properties

obj

readonly obj: 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

T

T extends EmptyObject = AnyObject

Implements

Constructors

Constructor

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

Parameters

obj

T

Returns

ValidatorBase<T>

Inherited from

ObjectWrapper.constructor

Properties

obj

readonly obj: T;

Inherited from

ObjectWrapper.obj

Accessors

stringKeyObj

Get Signature

get protected stringKeyObj(): StringKeyObject;

Returns

StringKeyObject

Inherited from

ObjectWrapper.stringKeyObj

Methods

validate()

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

Parameters

payload

T

Returns

Promisable<Error[]>

Implementation of

Validator.validate

    ### functions

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

@xylabs/object

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

Creates a deep merge function with the specified options.

Parameters

options

MergeOptions

Options for merging.

Returns

A deep merge function configured for the specified options.

<T>(...objects) => MergeAll<T>

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

@xylabs/object

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

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

Type Parameters

T

T extends object

Parameters

obj

T

The source object to omit properties from.

predicate

OmitByPredicate

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, 
   prefix, 
maxDepth?): DeepOmitStartsWith<T, P>;

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

Type Parameters

T

T extends object

P

P extends string

Parameters

payload

T

The source object.

prefix

P

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, 
   predicate, 
maxDepth?): Partial<T>;

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

Type Parameters

T

T extends object

Parameters

obj

T

The source object to pick properties from.

predicate

PickByPredicate

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, 
   prefix, 
maxDepth?): DeepPickStartsWith<T, P>;

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

Type Parameters

T

T extends object

P

P extends string

Parameters

payload

T

The source object.

prefix

P

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, fields): Omit<T, K>;

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

Type Parameters

T

T extends object

K

K extends string | number | symbol

Parameters

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, maxDepth?): unknown;

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

Parameters

value

unknown

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, 
   cycleList?, 
   maxDepth?): unknown[];

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

Parameters

value

unknown[]

The array to convert.

cycleList?

unknown[]

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, 
   cycleList?, 
   maxDepth?): JsonObject;

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

Parameters

value

object

The object to convert.

cycleList?

unknown[]

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, maxDepth?): string;

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

Parameters

value

unknown

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, 
   cycleList?, 
   maxDepth?): unknown;

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

Parameters

value

unknown

The value to convert.

cycleList?

unknown[]

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="AsTypeFunction"></a>AsTypeFunction

@xylabs/object

A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.

Type Parameters

T

T extends AnyNonPromise = AnyNonPromise

Call Signature

AsTypeFunction<TType>(value): TType | undefined;

A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.

Type Parameters

TType

TType extends AnyNonPromise

Parameters

value

AnyNonPromise

Returns

TType | undefined

Call Signature

AsTypeFunction<TType>(value, config): TType;

A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.

Type Parameters

TType

TType extends AnyNonPromise

Parameters

value

AnyNonPromise

config

TypeCheckRequiredConfig

Returns

TType

Call Signature

AsTypeFunction<TType>(value, config): TType | undefined;

A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.

Type Parameters

TType

TType extends AnyNonPromise

Parameters

value

AnyNonPromise

config

| TypeCheckConfig | TypeCheckOptionalConfig

Returns

TType | undefined

Call Signature

AsTypeFunction<TType>(value, assert): TType | undefined;

A type-narrowing function that attempts to cast a value to T, with optional assertion and configuration overloads.

Type Parameters

TType

TType extends AnyNonPromise

Parameters

value

AnyNonPromise

assert

StringOrAlertFunction<TType>

Returns

TType | undefined

Call Signature

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

TType

TType extends AnyNonPromise

Parameters

value

AnyNonPromise

assert

StringOrAlertFunction<TType>

config

TypeCheckRequiredConfig

Returns

TType

Call Signature

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

TType

TType extends AnyNonPromise

Parameters

value

AnyNonPromise

assert

StringOrAlertFunction<TType>

config

| TypeCheckConfig | TypeCheckOptionalConfig

Returns

TType | undefined

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

@xylabs/object

Configuration options for object type checking.

Extends

Properties

log?

optional log?: boolean | Logger;

Inherited from

TypeCheckConfig.log

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

@xylabs/object

A type guard function that checks whether a value conforms to type T, with optional configuration.

Type Parameters

T

T extends TypedValue

Call Signature

TypeCheck(obj): obj is T;

A type guard function that checks whether a value conforms to type T, with optional configuration.

Parameters

obj

AnyNonPromise

Returns

obj is T

Call Signature

TypeCheck(obj, config): obj is T;

A type guard function that checks whether a value conforms to type T, with optional configuration.

Parameters

obj

AnyNonPromise

config

TypeCheckConfig

Returns

obj is T

Call Signature

TypeCheck(obj, config): obj is T;

A type guard function that checks whether a value conforms to type T, with optional configuration.

Parameters

obj

AnyNonPromise

config

number | TypeCheckConfig | undefined

Returns

obj is T

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

@xylabs/object

Configuration options for type check functions, with optional logging.

Extended by

Properties

log?

optional 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

log?

optional log?: boolean | Logger;

Inherited from

TypeCheckConfig.log

required

required: false;
      ### <a id="TypeCheckRequiredConfig"></a>TypeCheckRequiredConfig

@xylabs/object

Type check configuration that marks the value as required, causing assertions on failure.

Extends

Properties

log?

optional log?: boolean | Logger;

Inherited from

TypeCheckConfig.log

required

required: true;
      ### <a id="Validator"></a>Validator

@xylabs/object

Interface for validating objects and returning any errors found.

Type Parameters

T

T extends EmptyObject = AnyObject

Methods

validate()

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

Parameters

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) => TType | undefined;

A simplified type-narrowing function that returns T or undefined, without assertion support.

Type Parameters

T

T extends AnyNonPromise = AnyNonPromise

Type Parameters

TType

TType extends T

Parameters

value

AnyNonPromise

Returns

TType | undefined

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

@xylabs/object

type Compare<T> = (a, b) => 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

T

T

Parameters

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

T

T

Prefix

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

T

T

Prefix

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

T

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

T

T

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

@xylabs/object

type EmptyObject<T> = Exclude<{ [K in keyof T]?: never }, unknown[] | ((...args) => 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

T

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, key) => boolean;

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

Type Parameters

T

T extends EmptyObject = Record<string, unknown>

Parameters

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

T

T

Prefix

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

T

T extends object

F

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

T1

T1

T2

T2

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

@xylabs/object

type PartialRecord<K, T> = Partial<Record<K, T>>;

Type Parameters

K

K extends keyof any

T

T

Deprecated

use Partial<Record<>> instead

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

@xylabs/object

type PickByPredicate<T> = (value, key) => boolean;

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

Type Parameters

T

T extends EmptyObject = Record<string, unknown>

Parameters

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

T

T

Prefix

Prefix extends string

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

@xylabs/object

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

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

Type Parameters

T

T

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

@xylabs/object

type StringKeyObject<T> = Record<string, T>;

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

Type Parameters

T

T = unknown

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

T

T extends AnyNonPromise

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

T

T extends EmptyObject | void

TAdditional

TAdditional extends EmptyObject | void = void

    ### variables

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

@xylabs/object

const AsObjectFactory: object;

Factory for creating type-narrowing functions for TypedObject types.

Type Declaration

create

create: <T>(typeCheck) => AsTypeFunction<T>;

Type Parameters

T

T extends TypedObject

Parameters

typeCheck

TypeCheck<T>

Returns

AsTypeFunction<T>

createOptional

createOptional: <T>(typeCheck) => (value) => T | undefined;

Type Parameters

T

T extends TypedObject

Parameters

typeCheck

TypeCheck<T>

Returns

(value) => T | undefined

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

@xylabs/object

const AsTypeFactory: object;

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

create

create: <T>(typeCheck) => AsTypeFunction<T>;

Type Parameters

T

T extends AnyNonPromise

Parameters

typeCheck

TypeCheck<T>

Returns

AsTypeFunction<T>

createOptional

createOptional: <T>(typeCheck) => (value) => T | undefined;

Type Parameters

T

T extends AnyNonPromise

Parameters

typeCheck

TypeCheck<T>

Returns

(value) => 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 & unknown[] | undefined;
<T>  (value, assert): T & unknown[];
};

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

Call Signature

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

Type Parameters

T

T

Parameters

value

T

Returns

T & unknown[] | undefined

Call Signature

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

Type Parameters

T

T

Parameters

value

T

assert

ZodFactoryConfig

Returns

T & unknown[]

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

@xylabs/object

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

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

Call Signature

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

Type Parameters

T

T

Parameters

value

T

Returns

T & Record<string, unknown> | undefined

Call Signature

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

Type Parameters

T

T

Parameters

value

T

assert

ZodFactoryConfig

Returns

T & Record<string, unknown>

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

@xylabs/object

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

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

Call Signature

<T>(value): T | undefined;

Type Parameters

T

T

Parameters

value

T

Returns

T | undefined

Call Signature

<T>(value, assert): T;

Type Parameters

T

T

Parameters

value

T

assert

ZodFactoryConfig

Returns

T

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

@xylabs/object

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

Deeply merges multiple objects into a new object.

Type Parameters

T

T extends AnyObject[]

Parameters

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) => value is T & unknown[];

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

Type Parameters

T

T

Parameters

value

T

Returns

value is T & unknown[]

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

@xylabs/object

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

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

Type Parameters

T

T

Parameters

value

T

Returns

value is T & Record<string, unknown>

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

@xylabs/object

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

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

Type Parameters

T

T

Parameters

value

T

Returns

value is T

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

@xylabs/object

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

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

Call Signature

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

Type Parameters

T

T

Parameters

value

T

Returns

T & unknown[] | undefined

Call Signature

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

Type Parameters

T

T

Parameters

value

T

assert

ZodFactoryConfig

Returns

T & unknown[]

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

@xylabs/object

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

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

Call Signature

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

Type Parameters

T

T

Parameters

value

T

Returns

T & Record<string, unknown> | undefined

Call Signature

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

Type Parameters

T

T

Parameters

value

T

assert

ZodFactoryConfig

Returns

T & Record<string, unknown>

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

@xylabs/object

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

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

Call Signature

<T>(value): T | undefined;

Type Parameters

T

T

Parameters

value

T

Returns

T | undefined

Call Signature

<T>(value, assert): T;

Type Parameters

T

T

Parameters

value

T

assert

ZodFactoryConfig

Returns

T

FAQs

Package last updated on 22 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts