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

watsons.js

v0.1.5

Published

JavaScript parameter validation inspired by prop-types.

Readme

watsons build status

JavaScript parameter validation inspired by prop-types.

Requirements

watsons.js requires node.js v6 and above.

Installation

npm install watsons.js

Usage

Normal usage

const watsons = require('watsons.js')
const obj = {
  s: "string value",
  n: 3,
  a: [1, 2, 3, 4],
  e: "female",
  shape: {
    a: 100,
    b: [1, 2, true]
  },
  nullableString: null,
  place: "New York"
}
const checker = {
  s: watsons.string,
  b: watsons.bool,
  n: watsons.number.required,
  a: watsons.arrayOf(
    watsons.number
  ),
  e: watsons.oneOf(["male", "female"]),
  shape: watsons.shape({
    a: watsons.number.required,
    b: watsons.array.required
  }),
  nullableString: watsons.oneOfType([
    watsons.string,
    watsons.null
  ]).required,
  place: watsons.validateWith((v) => v === "New York")
}
watsons.validate(obj, checker) // will not throw
watsons.valid(obj, checker) // returns true

Extending watsons

watsons.addValidator("match", function(s, keyPath, root, regexp) {
  if (s === undefined) return;
  if (!regexp.test(s)) {
    throw new WatsonsError(`String value at keyPath \
'${formatKeyPath(keyPath)}' does not match ${regexp.toString()}.`);
  }
}, true, ["string"]);

const obj = {
  a: "a"
};
const checker = {
  a: watsons.string.match(/a/)
};

watsons.validate(obj, checker); // will not throw

Configuration

By default, watsons checks validator dependencies, it's useful during development process. However, in production environment, it's unnecessary and not efficiency.

watsons.config({checkDeps: false})

Documentation

Watsons is designed to be extensible.

Builtin validators

  • shape

the default one for shaped object, works in the way similar to prop-types.

  • objectOf

object which values should passing the provided validator. similar to prop-types.

  • arrayOf

similar to objectOf but the object being validated should be array.

  • instanceOf

object which is instance of provided class. similar to prop-types.

  • array

array type.

  • bool

boolean type.

  • func

function type.

  • number

number type.

  • object

object type.

  • string

string type.

  • symbol

symbol type.

  • date

date type.

  • regexp

regular expression type.

  • null

null type.

  • required

value is required.

  • any

any value, null validator.

  • oneOf

enum validator.

  • oneOfType

combined validator.

  • validateWith

validate with custom function.

  • rule

validate with custom message, useful for form data validation.

  • rules

validate with rule entries, useful for form data validation.

Extending with new validators

watsons.addvalidator(name, validatorFunc, acceptParams, dependencies)

Parameters:

name: validator name string,

validatorFunc: (value, keyPath, root, params)

acceptParams: whether accepts params or not

dependencies: required chained validators before this validator