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

vschema

v0.0.17

Published

A JSON schema validation library

Readme

vschema

Schema validation can be used to validate data coming from forms, HTTPS requests and basically anything that needs to match a specific schema.

Usage

var vschema = require('vschema');
var mySchema = {
	name: {
      type: 'alpha',
    },
    email: {
      type: 'email',
      required: true
    },
    phone: {
      type: 'number',
    },
    birthdate: {
      type: 'date',
    },
    gender: {
      type: 'radio',
      options: {
      	male: 'Male',
      	female: 'Female'
      }
    },
    favoriteColors: [{ // An array of elements
      type: 'string',
      validators: [ // Custom validation
        function(val){ // Hex Color
          return val.startsWith('#') && val.length === 7;
        }
      ],
      filters: [ // Custom filters
        function(val){
          return val.toLowerCase();
        }
      ]
    }]
};

var myData = {
	name: 'John',
    email: '[email protected]',
    phone: '001122334455',
    birthdate: '1985-01-01',
    favoriteColors: ['#AAAAAA', '#bbbbbb', '#cccccc']
};

// Validate myData against mySchema
vschema.validate(mySchema, myData)
.then(function(values){
	console.log(values); // Final values after applying filters on them
}, function(errors){
	console.log(errors);
});


// You can also validate a single field like this:
/*
vschema.validateField({
	name: 'fieldname',
	type: 'email'
}, 'invalidEmailAddress').then(...);
*/

Built in data types

  • string
  • number
  • integer
  • float
  • select
  • radio
  • checkbox
  • bool
  • date
  • color
  • email
  • alpha
  • alnum
  • decimal
  • mongoid
  • url
  • uuid
  • schema

Built in filters

  • escape: replace <, >, &, ', " and / with HTML entities
  • unescape: replaces HTML encoded entities with <, >, &, ', " and /
  • ltrim: trim characters from the left-side of the input
  • normalizeEmail: canonicalizes an email address
  • rtrim: trim characters from the right-side of the input
  • stripLow: remove characters with a numerical value < 32 and 127, mostly control characters
  • toBoolean: convert the input string to a boolean. Everything except for '0', 'false' and '' returns true
  • toDate: convert the input string to a date, or null if the input is not a date
  • toFloat: convert the input string to a float, or NaN if the input is not a float
  • toInt: convert the input string to an integer, or NaN if the input is not an integer
  • trim: trim characters (whitespace by default) from both sides of the input

Custom validators

In addition to built in validators, you can also use your own either synchronously or asynchronously:

vschema.validateField({
	name: 'myfield',
	type: 'string',
	validators: [
	  function(val){ // Synchronous validation: either return true or anything else describing the error
	  	return true;
	  },
	  function(val){ // To do async validation, simply return a promise
	    return new Promise(function(resolve, reject){
	      setTimeout(function(){
	        reject('Invalid');
	      }, 200);
	    });
	  }
]
}, 'hello');

Custom filters

Please see the usage section