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

propertype

v1.6.0

Published

a struct constructor/validator for javascript

Readme

propertype

a struct constructor/validator library. propertype is a tool to check if an object has the proper type on its properties. as a constructor, it will extract properties defined in its type out of the payload it has been given.

installation

$ npm i propertype --save

possible types

  • any: anything
    • required: boolean - default: false - error: propertype-required
  • boolean: boolean or string of 'true' or 'false'
    • required: boolean - default: false - error: propertype-required
  • number: number or a string of a number
    • required: boolean - default: false - error: propertype-required
    • min: minimum value - error: propertype-number-min
    • max: maximum value - error: propertype-number-max
  • string: a string
    • required: boolean - default: false - error: propertype-required
    • min: minimum string length - error: propertype-string-min
    • max: maximum string length - error: propertype-string-max
    • pattern: a regex pattern to test against - default: .* - error: propertype-string-pattern
  • object: any object without caring about its properties
    • required: boolean - default: false - error: propertype-required
  • oneOf: the value should equal one of the values in its options key
    • required: boolean - default: false - error: propertype-required
    • options: array of possible values - error: propertype-oneof-options
  • arrayOf: an array of a specific type
    • required: boolean - default: false - error: propertype-required
    • min: minimum array length - error: propertype-array-min
    • max: maximum array length - error: propertype-array-max
    • type: the specific type that all values in the array should be - default: any
  • shape: shape is like a nested propertype config
    • required: boolean - default: false - error: propertype-required
    • types: an object of property configurations, just like its top level one

usage example

const Propertype = require('propertype');

// define a struct
const Person = Propertype({
  name: Propertype.string({ required: true, min: 3, max: 255 }),
  gender: Propertype.oneOf({ required: true, options: [ 'male', 'female' ] }),
  married: Propertype.boolean,
  age: Propertype.number, // you can skip parens if the default type config is good for you (required: false)
  skills: Propertype.arrayOf({ required: true, type: Propertype.string }),
  email: Propertype.email.required, // that's right! you can do this just like prop-types allows you
  outfit: Propertype.shape({ types: {
    shirtColor: Propertype.string,
    jeansColor: Propertype.string,
    sneakerSize: Propertype.number({ min: 30, max: 50 }),
  }}),
  extras: Propertype.any,
});

const payload = {
  name: 'Dariush Alipour',
  gender: 'male',
  married: true,
  age: 26,
  skills: ['js', 'golang'],
  email: '[email protected]',
  outfit: {
    shirtColor: 'black',
    jeansColor: 'blue',
    sneakerSize: 55,
  },
};

// only check/validate types
const errors = Person.validate(payload); // return: { outfit: { sneakerSize: 'propertype-number-max' } }

// explain type rules
const rules = Person.explain();

// construct one
let person;
try {
  person = Person(payload);
} catch(err) {
  /*
    err equals ValidationError {
      code: 400,
      name: 'ValidationError',
      message: 'There are one or more errors in pre-construct validation',
      info: {
        outfit: {
          sneakerSize: 'propertype-number-max',
        },
      },
    }
  */
}