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

polyprint

v1.0.0

Published

A dead simple schema builder.

Readme

Polyprint

A dead simple schema builder.

There are certainly better alternatives (namely Zod) that provide actual type validation in TypeScript, but Polyprint is dependency free, lightweight, and small. By forgoing typecasting, Polyprint is far simpler and more JavaScript focused. It provides a basic syntax to ensure forms and objects have the right structure, and that's it.

Installation

>>> pnpm install polyprint
import { p } from "polyprint";

Usage

This is a schema.

Schemas are great when you know the structure of your data, and you can use them for form validation. With polyprint,

You can use schemas to better define your data, which can be useful in form validation. In general, PolySchemas are composed of a dictionary with keys and values equal to some PolyType, PolySchema, or another dictionary.

const schema = new PolySchema("Document Schema", {
  _createdAt: PolyTypes.instanceOf(Date),
  _updatedAt: PolyTypes.instanceOf(Date),
  title: PolyTypes.string,
  body: PolyTypes.string,

  // nested schema
  user: new PolySchema("Document Schema Child", {
    name: PolyTypes.string,
  }),

  // this will also work (but will not instantiate a new PolySchema)
  user: {
    name: PolyTypes.string,
  },
});

We also provide an alternative export p, which provides methods to instantiate PolySchema, PolyType, and PolyCondition using a single namespace. This can result in more concise code at the cost of readability.

const schema = new p.Schema("Document Schema", {
  _createdAt: p.instanceOf(Date),
  _updatedAt: p.instanceOf(Date),
  title: p.string,
  body: p.string,

  // nested schema
  user: new PolySchema("Document Schema Child", {
    name: p.string,
  }),

  // this will also work (but will not instantiate a new PolySchema)
  user: {
    name: p.string,
  },
});

Validating data

validate allows you to validate some data. It also accepts several arguments beyond a data structure, including verbose and strict.

  • verbose: Will return an array of errors instead of true or false (defaults to false)
  • strict: Enable strict mode (discussed below, defaults to schema value)
schema.validate({
  title: "Hello World",
}); // => true

schema.validate({
  title: 0,
}); // => false

schema.validate(
  {
    title: 0,
  },
  {
    strict: true,
  }
); // => false because strict mode is enabled

Strict Mode

By default, schemas are NOT in strict mode, which means it will ignore extra or missing keys. You can easily enable or disable strict mode, or override your choice when you call validate.

Method 1: Create a new schema with strict mode by default

new PolySchema("Untitled Schema", {}, { strict: true });

Method 2: Change strict mode later

schema.strict = true;

Method 3: Override in validate

schema.validate({}, { strict: true });

Flexible Types

In addition to basic primitives like number and string, you can "compose" types with enum and union.

Union is like "or", so flexibleType can either be a string or a number.

{
  flexibleType: PolyTypes.union(PolyTypes.string, PolyTypes.number);
}

Enums are for literal values, so enumType can be "RED", "BLUE", or "GREEN" (but nothing else).

{
  enumType: PolyTypes.enum("RED", "BLUE", "GREEN");
}

You can also create custom types (perhaps for a more custom situation) with PolyCondition.

import { PolyCondition } from "polyprint";

new PolyCondition(
  "String of length 3",
  (value: any) => typeof value === "string" && value.length === 3
);