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 🙏

© 2025 – Pkg Stats / Ryan Hefner

types-verifier

v1.0.0-alpha.2

Published

A super tiny library that verifies types

Readme

types-verifier

Build Status codecov

A super lightweight runtime type checking for javascript values ands objects. Very similar to prop-types, expect that this package solves this issue with prop-types.

You can use types-verifier verify against the type definitions, and return an error if they don’t match.

Installation

npm install --save types-verifier

Importing

import Types from 'types-verifier'; // ES6
var Types = require('types-verifier'); // ES5 with npm

Usage

Here is an example usage of types-verifier which also documents the different validators provided.

import Types from 'types-verifier';

const UserType = {
  // You can declare that a prop is a specific JS primitive. By default, these
  // are all optional. To make it required just add .isRequired to any validator
  array: Types.array,
  bool: Types.bool,
  func: Types.func,
  number: Types.number,
  object: Types.object,
  string: Types.string,

  // You can ensure that your prop is limited to specific values by treating
  // it as an enum.
  enum: Types.oneOf(['News', 'Photos']),

  // An array of a certain type
  arrayOf: Types.arrayOf(Types.number),


  
  // An object taking on a particular shape
  objectWithShape: Types.shape({
    property: Types.string,
    requiredProperty: Types.number.isRequired
  }),


  //
  requiredFunc: Types.func.isRequired,

  // A value of any data type
  requiredAny: Types.any.isRequired,


  // You can also specify a custom verifier. It should return an Error
  // object if the validation fails. Don't `console.warn` or throw;
  // it should return null if verification succeeds.
  customProp: Types.create function(value, propName) {
    if (!/matchme/.test(value)) {
      return new TypeError(`${propName} must matchme, but you supplied ${String(value)}`);
    }

    return null;
  }
};

const result = Types.checkTypes(UserType, {
  hello: 'world'
});

// result will be a TypeError with a message of ALL the errors describing why
// the object does not match the type definition

Motivation

I would love to use prop-types from facebook because it's a very solid peice of code. The main issue that that it cannot be easily used outside for react - see the issue here. In a nutshell, prop-types returns "shims" (no-op functions that don't do anything) when in production mode, which is does not support all use cases.

There are plenty of other libraries that are trying to solve the same problem as prop-types, but none of them quite fit my needs. Here are the projects I found:

https://github.com/hustcc/variable-type https://github.com/dbrekalo/validate-types https://github.com/andnp/ValidTyped https://github.com/david-martin/types-validator

Those projects are great, but I really need a validator like prop-types that will return ALL the error messages when I check on object againts a type definition. When debugging and finding out what is wrong with your software, it is VERY helpful to have really good error messages, which is why I love prop-types so much. None of the libraries above give you all the errors. That is why i decided to create this package.

Tech Stack