You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@xylabs/zod

Package Overview
Dependencies
Maintainers
5
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xylabs/zod

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

latest
Source
npmnpm
Version
5.0.86
Version published
Weekly downloads
2.1K
-81.95%
Maintainers
5
Weekly downloads
 
Created
Source

@xylabs/zod

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

Interfaces

InterfaceDescription
ZodFactoryConfigObjectConfiguration object for zod factory functions, providing a name for error messages.

Type Aliases

Type AliasDescription
ZodFactoryConfigConfiguration for zod factory assertion behavior, either an AssertConfig or a named config object.
AllZodFactories-

Functions

FunctionDescription
zodAllFactoryCreates a bundle of is, as, and to factory functions for a given zod schema.
zodAsAsyncFactoryCreates an async function that validates a value against a zod schema and returns it with a narrowed type. Uses safeParseAsync for schemas with async refinements. When called without an assert config, returns undefined on failure.
zodAsFactoryCreates a function that validates a value against a zod schema and returns it with a narrowed type. When called without an assert config, returns undefined on failure. When called with an assert config, throws on failure.
zodIsFactoryCreates a type guard function that checks if a value matches a zod schema.
zodToAsyncFactoryCreates an async function that converts a value to the zod schema type, delegating to zodAsAsyncFactory internally. Provides overloads for optional assertion: without assert config resolves to undefined on failure, with assert config throws on failure.
zodToFactoryCreates a function that converts a value to the zod schema type, delegating to zodAsFactory internally. Provides overloads for optional assertion: without assert config returns undefined on failure, with assert config throws on failure.

functions

zodAllFactory

@xylabs/zod

function zodAllFactory<T, TName>(zod: ZodType<T>, name: TName): {
[key: string]: {
<T>  (value: T): T & T | undefined;
<T>  (value: T, assert: ZodFactoryConfig): T & T;
};
};

Alpha

Creates a bundle of is, as, and to factory functions for a given zod schema.

Type Parameters

Type Parameter
T
TName extends string

Parameters

ParameterTypeDescription
zodZodType<T>The zod schema to validate against
nameTNameThe name used to suffix the generated function names (e.g. 'Address' produces isAddress, asAddress, toAddress)

Returns

{
[key: string]: {
<T>  (value: T): T & T | undefined;
<T>  (value: T, assert: ZodFactoryConfig): T & T;
};
}

An object containing is<Name>, as<Name>, and to<Name> functions

zodAsAsyncFactory

@xylabs/zod

function zodAsAsyncFactory<TZod>(zod: ZodType<TZod>, name: string): {
<T>  (value: T): Promise<T & TZod | undefined>;
<T>  (value: T, assert: ZodFactoryConfig): Promise<T & TZod>;
};

Creates an async function that validates a value against a zod schema and returns it with a narrowed type. Uses safeParseAsync for schemas with async refinements. When called without an assert config, returns undefined on failure.

Type Parameters

Type Parameter
TZod

Parameters

ParameterTypeDescription
zodZodType<TZod>The zod schema to validate against
namestringA name used in error messages for identification

Returns

An async function that validates and narrows the type of a value

<T>(value: T): Promise<T & TZod | undefined>;

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

Promise<T & TZod | undefined>

<T>(value: T, assert: ZodFactoryConfig): Promise<T & TZod>;

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT
assertZodFactoryConfig

Returns

Promise<T & TZod>

zodAsFactory

@xylabs/zod

function zodAsFactory<TZod>(zod: ZodType<TZod>, name: string): {
<T>  (value: T): T & TZod | undefined;
<T>  (value: T, assert: ZodFactoryConfig): T & TZod;
};

Creates a function that validates a value against a zod schema and returns it with a narrowed type. When called without an assert config, returns undefined on failure. When called with an assert config, throws on failure.

Type Parameters

Type Parameter
TZod

Parameters

ParameterTypeDescription
zodZodType<TZod>The zod schema to validate against
namestringA name used in error messages for identification

Returns

A function that validates and narrows the type of a value

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

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

T & TZod | undefined

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

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT
assertZodFactoryConfig

Returns

T & TZod

zodIsFactory

@xylabs/zod

function zodIsFactory<TZod>(zod: ZodType<TZod>): <T>(value: T) => value is T & TZod;

Creates a type guard function that checks if a value matches a zod schema.

Type Parameters

Type Parameter
TZod

Parameters

ParameterTypeDescription
zodZodType<TZod>The zod schema to validate against

Returns

A type guard function that returns true if the value passes validation

<T>(value: T): value is T & TZod;

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is T & TZod

zodToAsyncFactory

@xylabs/zod

function zodToAsyncFactory<TZod>(zod: ZodType<TZod>, name: string): {
<T>  (value: T): Promise<T & TZod | undefined>;
<T>  (value: T, assert: ZodFactoryConfig): Promise<T & TZod>;
};

Creates an async function that converts a value to the zod schema type, delegating to zodAsAsyncFactory internally. Provides overloads for optional assertion: without assert config resolves to undefined on failure, with assert config throws on failure.

Type Parameters

Type Parameter
TZod

Parameters

ParameterTypeDescription
zodZodType<TZod>The zod schema to validate against
namestringA name used in error messages for identification

Returns

An async function that validates and converts a value to the schema type

<T>(value: T): Promise<T & TZod | undefined>;

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

Promise<T & TZod | undefined>

<T>(value: T, assert: ZodFactoryConfig): Promise<T & TZod>;

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT
assertZodFactoryConfig

Returns

Promise<T & TZod>

zodToFactory

@xylabs/zod

function zodToFactory<TZod>(zod: ZodType<TZod>, name: string): {
<T>  (value: T): T & TZod | undefined;
<T>  (value: T, assert: ZodFactoryConfig): T & TZod;
};

Creates a function that converts a value to the zod schema type, delegating to zodAsFactory internally. Provides overloads for optional assertion: without assert config returns undefined on failure, with assert config throws on failure.

Type Parameters

Type Parameter
TZod

Parameters

ParameterTypeDescription
zodZodType<TZod>The zod schema to validate against
namestringA name used in error messages for identification

Returns

A function that validates and converts a value to the schema type

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

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

T & TZod | undefined

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

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT
assertZodFactoryConfig

Returns

T & TZod

interfaces

ZodFactoryConfigObject

@xylabs/zod

Configuration object for zod factory functions, providing a name for error messages.

Properties

PropertyType
namestring

type-aliases

AllZodFactories

@xylabs/zod

type AllZodFactories<TType, TName> = { [K in `is${TName}`]: ReturnType<typeof zodIsFactory> } & { [K in `as${TName}`]: ReturnType<typeof zodAsFactory> } & { [K in `to${TName}`]: ReturnType<typeof zodToFactory> };

Alpha

Type Parameters

Type Parameter
TType
TName extends string

ZodFactoryConfig

@xylabs/zod

type ZodFactoryConfig = 
  | AssertConfig
  | ZodFactoryConfigObject;

Configuration for zod factory assertion behavior, either an AssertConfig or a named config object.

Part of sdk-js

Maintainers

License

See the LICENSE file for license details

Credits

Made with 🔥 and ❄️ by XYLabs

FAQs

Package last updated on 11 Mar 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