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

@jakobkg/shapes-ts

v0.4.0

Published

Toy library to create runtime safe types in TS.

Readme

shapes-ts

Toy library to create runtime safe types in TS.

When describing the shape of your data in shapes-ts, you get the corresponding TS type and a validation utility for free!

const CreditCategory = Shapes.enum(["director", "writer", "actor/actress"]);

const Credits = Shapes.object({
  category: CreditCategory,
  name: Shapes.string(),
});

const Movie = Shapes.object({
  title: Shapes.string(),
  rating: Shapes.number().where(
    (n) => n >= 0 && n <= 5,
    "rating must be in range 0.0-5.0",
  ),
  credits: Shapes.array(Credits),
});

// This infers as
// {
//   title: string,
//   rating: number,
//   credits: {
//     category: "director" | "writer" | "actor/actress",
//     name: string
//   }[]
// }
type Movie = Shapes.Type<typeof Movie>;

const movieData: unknown = getFromIMDB("tt23289160");

if (!Movie.check(movieData)) {
  throw new Error("Unexpected data from API");
}

// Past this point, movieData is typed as Movie

for (const credit of movieData.credits) {
  console.log(`${credit.name}: ${credit.category}`);
}

Supported types

Primitives

  • string
  • number
  • boolean

...and literals of these

Composite types

  • object
  • array
  • tuple
  • enum

Modified types

  • Nullable types (T | null)
  • Optional types (T | undefined)
  • Unions (A | B)
  • Intersections (A & B)

Predicates

Shapes can have additional validation checks added to them. These do not affect the inferred type, but are still ran as part of a shape's .check() method to help enforce constraints that are not easily modeled using the type system.

const Username = Shapes.string().where(
  (str) => str.length < 10,
  "must be less than 10 characters long",
);

Username.check("jakob :)"); // true
Username.check("CptAmericaFan207"); // false

Predicates can be used with all types of shapes, and they may be combined both by stacking them on a single shape and by combining shapes that already have predicates on them.

const Fizz = Shapes.number().where(
  (n) => n % 3 === 0,
  "must be divisible by 3",
);

const Buzz = Shapes.number().where(
  (n) => n % 5 === 0,
  "must be divisible by 5",
);

const FizzBuzz = Fizz.and(Buzz);

Fizz.check(3); // true
FizzBuzz.check(3); // false
Fizz.check(5); // false
Buzz.check(5); // true
FizzBuzz.check(15); //true