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

v5.0.87

Published

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

Downloads

26,895

Readme

@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

| Interface | Description | | ------ | ------ | | ZodFactoryConfigObject | Configuration object for zod factory functions, providing a name for error messages. |

Type Aliases

| Type Alias | Description | | ------ | ------ | | ZodFactoryConfig | Configuration for zod factory assertion behavior, either an AssertConfig or a named config object. | | AllZodFactories | - |

Functions

| Function | Description | | ------ | ------ | | zodAllFactory | Creates a bundle of is, as, and to factory functions for a given zod schema. | | zodAsAsyncFactory | 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. | | zodAsFactory | 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. | | zodIsFactory | Creates a type guard function that checks if a value matches a zod schema. | | zodToAsyncFactory | 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. | | zodToFactory | 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. |

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

| Parameter | Type | Description | | ------ | ------ | ------ | | zod | ZodType<T> | The zod schema to validate against | | name | TName | The 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

| Parameter | Type | Description | | ------ | ------ | ------ | | zod | ZodType<TZod> | The zod schema to validate against | | name | string | A 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

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

Returns

Promise<T & TZod | undefined>

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

Type Parameters

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

Parameters

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

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

| Parameter | Type | Description | | ------ | ------ | ------ | | zod | ZodType<TZod> | The zod schema to validate against | | name | string | A 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

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

Returns

T & TZod | undefined

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

Type Parameters

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

Parameters

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

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

| Parameter | Type | Description | | ------ | ------ | ------ | | zod | ZodType<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

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

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

| Parameter | Type | Description | | ------ | ------ | ------ | | zod | ZodType<TZod> | The zod schema to validate against | | name | string | A 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

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

Returns

Promise<T & TZod | undefined>

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

Type Parameters

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

Parameters

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

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

| Parameter | Type | Description | | ------ | ------ | ------ | | zod | ZodType<TZod> | The zod schema to validate against | | name | string | A 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

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

Returns

T & TZod | undefined

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

Type Parameters

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

Parameters

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

Returns

T & TZod

interfaces

ZodFactoryConfigObject

@xylabs/zod


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

Properties

| Property | Type | | ------ | ------ | | name | string |

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