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

@pcg/predicates

v2.0.0

Published

Type predicate utilities and assertions

Readme

@pcg/predicates

Type guards and small helpers for checking values at runtime: primitives, objects, arrays and empty containers. Each guard narrows the TypeScript type of its argument.

Installation

pnpm add @pcg/predicates

The package has no peer dependencies.

Requirements

  • Node.js 26 or later.
  • ESM only: the package is published as an ES module ("type": "module") with its own TypeScript declarations.

Usage

import {
  entriesOf,
  isEmptyContainer,
  isNullOrUndefined,
  isPlainObject,
  isString,
  type Maybe,
} from '@pcg/predicates';

const describe = (value: unknown): string => {
  if (isNullOrUndefined(value)) {
    return 'nothing';
  }

  if (isString(value)) {
    return value.toUpperCase(); // value is string here
  }

  if (isPlainObject(value)) {
    return Object.keys(value).join(', '); // value is Record<string, unknown> here
  }

  return String(value);
};

describe({ name: 'Jane Doe', company: 'Acme' }); // 'name, company'

isEmptyContainer({}); // true
isEmptyContainer([1, 2, 3]); // false

// Typed alternative to Object.entries()
const limits = { daily: 10, monthly: 200 };
for (const [key, value] of entriesOf(limits)) {
  // key: 'daily' | 'monthly', value: number
}

const nickname: Maybe<string> = undefined;

API

Primitives

  • isString(value) – true for a string.
  • isNumber(value) – true for a number.
  • isCallable(value) – true for a function.
  • isNullOrUndefined(value) – true for null and undefined.
  • isIndex(value) – true for a non-negative number or a string that converts to one (2, '2'); used to tell array indexes from object keys.

Objects and arrays

  • isObject(value) – true for any non-null object except an array (class instances and Date included).
  • isPlainObject(value) – true for an object created by {}, new Object() or Object.create(null).
  • isContainerValue(value) – true for an object or an array.
  • isEmptyArray(value) – true for an array of length 0.
  • isEmptyContainer(value) – true for an empty array or an object without own keys.
  • keysOf(object) – Object.keys() typed as (keyof T)[].
  • entriesOf(object) – Object.entries() typed with Entries<T> from type-fest.

Types

  • Maybe<T> – T | undefined.
  • MaybeNull<T> – T | null.

License

MIT