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

@srhazi/shape

v1.4.0

Published

Composable runtime value checks that play well with TypeScript's type narrowing

Readme

@srhazi/shape

Composable runtime value checks that play well with TypeScript's type narrowing.

A shape is an assertion function that narrows a type.

Think of it like a schema checker for unknown values.

API

The @srhazi/shape package exports the following types and values:

  • AssertFn<T> = (val: unknown) => val is T - the type of an assertion function

Given an assertion function, you can get the type of it with AssertFnType<typeof myAssertionFunction>.

There are some self-describing assertion functions:

  • isString: AssertFn<string>
  • isNumber: AssertFn<string>
  • isNumber: AssertFn<number>
  • isBigint: AssertFn<bigint>
  • isBoolean: AssertFn<boolean>
  • isSymbol: AssertFn<symbol>
  • isUndefined: AssertFn<undefined>
  • isUnknown: AssertFn<unknown>
  • isNull: AssertFn<null>
  • isArray: AssertFn<unknown[]>
  • isFunction: AssertFn<() => unknown>

And some helpful assertion function factories:

  • isExact(value: T): AssertFn<T> - make a function asserting strict equality (===) to a specific value
  • is(value: T): AssertFn<T> - (alias for isExact)
  • isEnum(values...: T[]): AssertFn<T> - make a function asserting strict equality (===) to one of many values

Assertion functions can be combined together with:

  • isShape({ foo: isNumber, bar: isString }): AssertFn<{ foo: number, bar: string }> - make a function asserting an object whose keys match the corresponding assertion functions
  • isEither(isString, isNumber, ...etc) - make a function asserting one of many assertion functions (via OR)
  • isArrayOf: <T>(shape: AssertFn<T>) => AssertFn<T[]> - make a function asserting an array whose values all match an assertion function
  • isTuple: <T extends AssertFn<any>[]>(...fns: T) => AssertFn<{ [P in keyof T]: AssertFnType<T[P]>; }> - make a function asserting a tuple (fixed-length array) whose values each match the assertion functions
  • isRecordOf: <T>(shape: AssertFn<T>) => AssertFn<Record<string, T>> - make a function asserting an object whose values all match an assertion function
  • isRecordWith: <K extends string | number | symbol, V>(isEntry: AssertFn<[K, V]>): AssertFn<Record<K, V>> - make a function asserting an object whose entries all match an assertion function

And there's one hard-to-describe, but easy-to-use assertion function:

  • function isTruthy<T>(val: T): val is Exclude<T, 0 | -0 | 0n | "" | null | undefined> - make a function asserting just like how if works

And if you want a shape with an optional property, mark the assertion function with optional:

  • optional<T>(fn: AssertFn<T>): AssertFn<T | undefined> - make a property optional

Installation

npm install --save @srhazi/shape