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

schematized-fun

v0.1.0

Published

Bring strict types to runtime! Define complex function signatures and overloads using any Standard Schema library and enjoy full TypeScript inference.

Readme

schematized-fun

Bring strict types to runtime! Define complex function signatures and overloads using any Standard Schema library and enjoy full TypeScript inference.


NPM version License: MIT

Motivation

TypeScript provides excellent static safety, but this protection vanishes at runtime, often forcing developers to write manual validation logic for external inputs. Additionally, implementing function overloads is cumbersome, typically requiring a single broad signature with complex control flow to determine which overload was invoked.

This package addresses these challenges by using Standard Schema V1 definitions. It ensures that arguments strictly match their expected types before the function runs and automatically dispatches calls to the correct implementation based on the validated input, seamlessly supporting function overloads.

Installation

# npm
npm install schematized-fun

# bun
bun add schematized-fun

# yarn
yarn add schematized-fun

# pnpm
pnpm add schematized-fun

Reference Documentation

SchematizedFunction<This, Args, Return>

Represents a function wrapper that automatically validates its arguments using Standard Schema V1 schemas before execution.

  • Constructor: private constructor()

Static Methods

  • create(schema, implementation)

    Creates a new SchematizedFunction instance.

    | Parameter | Type | Description | | ---------------- | --------------------------- | ------------------------------------------------------------------------------------------------------ | | schema | SchematizedArgsDefinition | The definition of the arguments schemas. To define a rest parameter, wrap the last schema in an array. | | implementation | SchematizedImplementation | The implementation of the function. |

    Returns: SchematizedFunction

Instance Methods

  • apply(thisArg, args)

    Executes the function with the provided arguments and this context, performing synchronous validation.

    | Parameter | Type | Description | | ------------- | ---------------------------- | --------------------------------------------------------- | | thisArg | ThisArg<This> | The this context for the function execution. | | args | SchematizedInputArgs<Args> | The input arguments to validate and pass to the function. |

    Returns: The return value of the implemented function.

    Throws:

  • applyAsync(thisArg, args)

    Executes the function with the provided arguments and this context, performing asynchronous validation.

    | Parameter | Type | Description | | ------------- | ---------------------------- | --------------------------------------------------------- | | thisArg | ThisArg<This> | The this context for the function execution. | | args | SchematizedInputArgs<Args> | The input arguments to validate and pass to the function. |

    Returns: A promise resolving to the return value of the implemented function.

    Throws:

  • call(thisArg, ...args)

    Calls the function with the provided arguments and this context (spread syntax), performing synchronous validation.

    | Parameter | Type | Description | | ------------- | ------------------------------- | -------------------- | | thisArg | ThisArg<This> | The this context. | | args | ...SchematizedInputArgs<Args> | The input arguments. |

    Returns: The return value of the function.

    Throws:

  • callAsync(thisArg, ...args)

    Calls the function with the provided arguments and this context (spread syntax), performing asynchronous validation.

    | Parameter | Type | Description | | ------------- | ------------------------------- | -------------------- | | thisArg | ThisArg<This> | The this context. | | args | ...SchematizedInputArgs<Args> | The input arguments. |

    Returns: A promise resolving to the return value.

    Throws:

  • toFunction()

    Bundles the validation schemas and the implementation into a single synchronous closure.

    Returns: A function that can be called directly.

  • toAsyncFunction()

    Bundles the validation schemas and the implementation into a single asynchronous closure.

    Returns: An async function that can be called directly.

SchematizedOverloads<This, Overloads>

Represents a function that supports multiple signatures (overloads), validating arguments against Standard Schema V1 definitions to determine the correct implementation to execute.

  • Constructor: private constructor()

Static Methods

Instance Methods

  • prepend(schema, implementation)

    Registers a new overload signature with higher priority (it will be checked before existing overloads).

    | Parameter | Type | Description | | ---------------- | --------------------------- | -------------------------------------------------------------- | | schema | SchematizedArgsDefinition | The definition of the arguments schemas. | | implementation | SchematizedImplementation | The implementation of the function for this specific overload. |

    Returns: A new instance with the added overload at the beginning.

  • append(schema, implementation)

    Registers a new overload signature with lower priority (it will be checked after existing overloads).

    | Parameter | Type | Description | | ---------------- | --------------------------- | -------------------------------------------------------------- | | schema | SchematizedArgsDefinition | The definition of the arguments schemas. | | implementation | SchematizedImplementation | The implementation of the function for this specific overload. |

    Returns: A new instance with the added overload at the end.

  • apply(thisArg, args)

    Executes the function by finding the first matching overload for the provided arguments synchronously.

    | Parameter | Type | Description | | ------------- | --------------------------- | -------------------- | | thisArg | ThisArg<This> | The this context. | | args | SchematizedOverloadedArgs | The input arguments. |

    Returns: The return value of the matched overload implementation.

    Throws:

  • applyAsync(thisArg, args)

    Executes the function by finding the first matching overload for the provided arguments asynchronously.

    | Parameter | Type | Description | | ------------- | --------------------------- | -------------------- | | thisArg | ThisArg<This> | The this context. | | args | SchematizedOverloadedArgs | The input arguments. |

    Returns: The return value of the matched overload implementation.

    Throws:

  • call(thisArg, ...args)

    Calls the function synchronously with the provided arguments (spread syntax).

    | Parameter | Type | Description | | ------------- | ------------------------------ | -------------------- | | thisArg | ThisArg<This> | The this context. | | args | ...SchematizedOverloadedArgs | The input arguments. |

    Returns: The return value of the matched overload.

    Throws:

  • callAsync(thisArg, ...args)

    Calls the function asynchronously with the provided arguments (spread syntax).

    | Parameter | Type | Description | | ------------- | ------------------------------ | -------------------- | | thisArg | ThisArg<This> | The this context. | | args | ...SchematizedOverloadedArgs | The input arguments. |

    Returns: The return value of the matched overload.

    Throws:

  • toFunction()

    Bundles the registered overloads into a single closure that handles dispatching.

    Returns: A function that can be called directly.

  • toAsyncFunction()

    Bundles the registered overloads into a single asynchronous closure that handles dispatching.

    Returns: An async function that can be called directly.

SchematizedArgs<Args>

A utility class for validating a list of arguments against a defined tuple of Standard Schema V1 schemas.

  • Constructor: private constructor()

Static Methods

  • create(schema)

    Creates a new SchematizedArgs instance.

    | Parameter | Type | Description | | ------------- | --------------------------- | ------------------------------------------------------------------------------------------------------ | | schema | SchematizedArgsDefinition | The definition of the arguments schemas. To define a rest parameter, wrap the last schema in an array. |

    Returns: SchematizedArgs

Instance Methods

  • parse(args)

    Validates the provided arguments against the defined schemas synchronously.

    | Parameter | Type | Description | | ------------- | ---------------------------- | -------------------------------- | | args | SchematizedInputArgs<Args> | The input arguments to validate. |

    Returns: The validated and transformed output arguments.

    Throws:

  • parseAsync(args)

    Validates the provided arguments against the defined schemas asynchronously.

    | Parameter | Type | Description | | ------------- | ---------------------------- | -------------------------------- | | args | SchematizedInputArgs<Args> | The input arguments to validate. |

    Returns: A promise that resolves to the validated and transformed output arguments.

    Throws:

SchematizedError

Base error class for all errors thrown by schematized-fun package.

ArgumentsError

Error thrown when arguments fail validation against a schema.

  • Extends: SchematizedError

  • Constructor: constructor(issues)

    | Parameter | Type | Description | | ------------- | --------------------- | ------------------------------------------ | | issues | StdSchemaV1.Issue[] | The list of validation issues encountered. |

Properties

| Property | Type | Description | | ----------------- | ------------------------------ | ------------------------------------------ | | readonly issues | readonly StdSchemaV1.Issue[] | The list of validation issues encountered. |

NoMatchingOverloadError

Error thrown when no overload signature matches the provided arguments.

  • Extends: SchematizedError

  • Constructor: constructor(failures)

    | Parameter | Type | Description | | ------------- | -------------------------------------------------- | --------------------------------------------------------------------- | | failures | (ArgumentsError \| SynchronousValidationError)[] | The list of errors encountered for each overload signature attempted. |

Properties

| Property | Type | Description | | ---------------- | -------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | | readonly cause | (ArgumentsError \| SynchronousValidationError)[] | The list of errors encountered for each overload signature attempted. The index of the error corresponds to the index of the overload in the definition order. |

SynchronousValidationError

Error thrown when a synchronous validation method (e.g., parse, apply) is called, but the underlying schema implementation requires asynchronous validation (returns a Promise).