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

@coderrob/typescript-type-guards

v1.0.1

Published

Reusable TypeScript type guards for narrowing unknown values in application and library code.

Downloads

169

Readme

@coderrob/typescript-type-guards

Reusable TypeScript type guards for narrowing unknown values in application and library code.

Installation

npm install @coderrob/typescript-type-guards

The package and its development tooling require Node.js ^20, ^22, or ^24.

Usage

import {
  createEnumGuard,
  createTypeGuard,
  isArrayOf,
  isDefined,
  isNonEmptyString,
  isNumber,
  isPlainObject,
  isString,
} from '@coderrob/typescript-type-guards';

const values: unknown[] = ['a', 'b', 'c'];

if (isArrayOf(isString)(values)) {
  values.map((value) => value.toUpperCase());
}

const maybeName: string | null | undefined = 'Ada';

if (isDefined(maybeName) && isNonEmptyString(maybeName)) {
  console.log(maybeName);
}

enum Status {
  Active = 'ACTIVE',
  Inactive = 'INACTIVE',
}

const isStatus = createEnumGuard(Status, 'Status');

if (isStatus('ACTIVE')) {
  console.log('valid enum value');
}

class User {
  constructor(public readonly id: number) {}
}

const isUser = createTypeGuard(User);
const input: unknown = new User(1);

if (isUser(input) && isNumber(input.id)) {
  console.log(input.id);
}

const maybeConfig: unknown = { retries: 3 };

if (isPlainObject(maybeConfig)) {
  console.log(maybeConfig.retries);
}

Included guards

  • Primitive guards: isString, isNumber, isBoolean, isBigInt, isSymbol, isNull, isUndefined, isNullish, isNullOrUndefined
  • Numeric guards: isFiniteNumber, isInteger, isNaN
  • Collection guards: isArray, isNonEmptyArray, isArrayOf, isNonEmptyArrayOf, isMap, isSet
  • Object-like guards: isObject, isPlainObject, isFunction, isError, isRegExp, isDate, isValidDate, isPromise, isThenable
  • Utility guards: isDefined, isNonEmptyString, createTypeGuard, createEnumGuard

Package output

The published package exposes a single public entrypoint with both ESM and CommonJS support:

import { isString } from '@coderrob/typescript-type-guards';
const { isString } = require('@coderrob/typescript-type-guards');

Package metadata can also be resolved explicitly when needed:

const packageMetadata = require('@coderrob/typescript-type-guards/package.json');
import packageMetadata from '@coderrob/typescript-type-guards/package.json' with { type: 'json' };

Type declarations are emitted during build and included in the published package.

The published tarball also includes the root README.md, LICENSE, and package.json. Those top-level files are included automatically by npm and are not copied into dist/.

Benchmarks

Run the local micro-benchmarks with:

npm run bench

Latest local run on Windows 11 (10.0.26200.0) with Node.js v22.19.0:

| Guard | Average latency | Average throughput | | -------------------------------------- | --------------: | -----------------: | | isString on string | 39.02 ns | 19,608,415 ops/s | | isNumber on number | 37.68 ns | 20,371,720 ops/s | | isPlainObject on object | 37.85 ns | 20,250,036 ops/s | | createEnumGuard result on enum value | 39.55 ns | 19,332,792 ops/s |

These are indicative micro-benchmark results from a single local machine. They are useful for relative comparisons inside this repository, not as a guarantee of identical performance in other runtimes or workloads.

Development

See also:

  • CONTRIBUTING.md for local setup, verification, and contribution expectations
  • CHANGELOG.md for release history
npm run verify
npm run test:coverage
npm run build
npm run bench
npm run changeset
npm run release:version
npm run release:changesets
npm run publish:package

Verification

npm run format:check
npm run lint
npm run typecheck
npm test
npm run build
npm run test:package
npm run package:quality
npm run test:coverage

Releases

  • npm run changeset creates a release note entry for a package change.
  • npm run release:version applies pending changesets and updates the changelog.
  • npm run release:changesets runs the full verification stack, coverage, and then publishes through Changesets. In GitHub Actions, this release path also publishes with provenance.
  • npm run publish:package performs a direct npm publish with a dry-run pack check first.
  • .github/workflows/release.yml is a manual workflow_dispatch workflow for optional release publishing.