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

@motiro/guard

v0.1.1

Published

Composable TypeScript type guards and runtime validation for the Motiro toolkit — small, well-typed predicates you can compose.

Readme

@motiro/guard

Composable TypeScript type guards and runtime validation for the Motiro toolkit — small, well-typed predicates you can compose.

npm version license

A collection of small, focused type guards that narrow unknown values at runtime while giving you precise TypeScript types. Every guard is fully tree-shakeable, has zero dependencies, and pairs with a set of combinators (isOneOf, isArrayOf, isShape, optional, …) for building larger validators out of small pieces.

Features

  • 🎯 Precise narrowing — every guard is a value is T predicate, so TypeScript narrows correctly.
  • 🧩 Composable — combine primitives with isOneOf, isArrayOf, isShape, not, optional, and nullable.
  • 🌳 Tree-shakeable — import only what you use; ESM-only, side-effect free.
  • 📦 Zero dependencies — nothing but the guards themselves.
  • 🔒 Type-safe by default — inputs are unknown; you decide what passes.

Installation

# bun
bun add @motiro/guard

# npm
npm install @motiro/guard

# pnpm
pnpm add @motiro/guard

# yarn
yarn add @motiro/guard

Usage

import { isString, isNumber, isDefined, isShape, isArrayOf, optional } from '@motiro/guard';

isString('hello'); // => true
isNumber(NaN); // => false, NaN is rejected by design

// Filter out null/undefined, keeping the narrowed type
[1, null, 2, undefined].filter(isDefined); // => number[]

// Validate the shape of an object
const isUser = isShape({
  id: isNumber,
  name: isString,
  email: optional(isString),
});

if (isUser(payload)) {
  // payload is { id: number; name: string; email: string | undefined }
}

// Validate arrays element by element
const isStringArray = isArrayOf(isString);
isStringArray(['a', 'b']); // => true

API

Primitives

| Guard | Narrows to | Notes | | --- | --- | --- | | isString(value) | string | | | isNumber(value) | number | Rejects NaN; Infinity passes. | | isBoolean(value) | boolean | Strictly true / false. | | isBigInt(value) | bigint | | | isSymbol(value) | symbol | | | isNull(value) | null | | | isUndefined(value) | undefined | | | isNil(value) | null \| undefined | Matches both. | | isDefined(value) | NonNullable<T> | Ideal as an array filter. |

Numeric

| Guard | Narrows to | Notes | | --- | --- | --- | | isInteger(value) | number | No fractional part. | | isSafeInteger(value) | number | Within [-(2^53 - 1), 2^53 - 1]. | | isNumberFinite(value) | number | Excludes Infinity and NaN; no coercion. | | isPositive(value) | number | > 0. | | isNegative(value) | number | < 0. | | isZero(value) | 0 | Matches -0 too. |

Objects & built-ins

| Guard | Narrows to | Notes | | --- | --- | --- | | isObjectLike(value) | Record<PropertyKey, unknown> | Any non-null object (arrays included). | | isObject(value) | Record<PropertyKey, unknown> | Non-null object, excludes arrays. | | isPlainObject(value) | Record<PropertyKey, unknown> | Object literals & Object.create(null) only. | | isArray(value) | unknown[] | | | isFunction(value) | (...args) => unknown | | | isDate(value) | Date | Validity not checked. | | isRegExp(value) | RegExp | | | isError(value) | Error | Subclasses included. | | isPromise(value) | Promise<T> | Native promises only. | | isThenable(value) | PromiseLike<T> | Any object with a callable then. | | isMap(value) | Map<K, V> | | | isSet(value) | Set<T> | | | isWeakMap(value) | WeakMap<K, V> | | | isWeakSet(value) | WeakSet<T> | |

Emptiness

| Guard | Narrows to | Notes | | --- | --- | --- | | isEmptyString(value) | '' | | | isEmptyArray(value) | [] | | | isEmptyObject(value) | Record<PropertyKey, never> | Counts own string & symbol keys. |

Combinators

| Combinator | Returns | Description | | --- | --- | --- | | isOneOf(...guards) | Guard<union> | Passes if any guard passes (union narrowing). | | isArrayOf(guard) | Guard<T[]> | Array whose every element satisfies guard. Empty array passes. | | isNonEmptyArray(guard?) | Guard<[T, ...T[]]> | Non-empty array, optionally validating each element. | | isShape(shape) | Guard<InferShape<S>> | Validates an object against a map of guards. Extra keys ignored. | | isLiteral(...values) | Guard<T[number]> | Strict equality against literal values. | | isInstanceOf(ctor) | Guard<T> | value instanceof ctor. | | not(guard) | Guard<unknown> | Passes when the input guard fails. | | optional(guard) | Guard<T \| undefined> | Also accepts undefined. | | nullable(guard) | Guard<T \| null> | Also accepts null. |

Exported types

import type { Guard, GuardType, GuardShape, InferShape } from '@motiro/guard';
  • Guard<T>(value: unknown) => value is T.
  • GuardType<G> — extracts T from a Guard<T>.
  • GuardShapeRecord<PropertyKey, Guard<unknown>>.
  • InferShape<S> — the object type inferred from a GuardShape.

License

MIT © meluiz