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

validator-es5

v0.1.4

Published

A data validation utility, is used to validate e.g. function arguments.

Readme

validator-es5

A data validation utility, can be used to validate e.g. function arguments. Do argument validation improves code quality.

NPM version Build Status Clean Code Dependency Status devDependency Status License

Browser support

Desktop: Chrome, Safari, Firefox, Opera, IE6+

Installation

    npm install validator-es5

    or 

    jspm install npm:validator-es5

Usage

Some examples :

    var Validator = require('validator-es5');


    Validator.isType('string', 'Singapore', 'city');            // true
    Validator.isType('string', 15, 'city', false);              // false
    Validator.isType('string', 15, 'city');                     // throw error.


    Validator.isType('object', {a:1}, 'data');                  // true
    Validator.isType('object', null,  'data', false);           // false


    Validator.isType('number', 15, 'width');                    // true
    Validator.isType('number', NaN, 'width', false);            // false
    Validator.isType('number', Infinity, 'width', false);       // false


    Validator.isType('function', function () {}, 'onclick');    // true
    Validator.isType('boolean', false, 'isTriggered');          // true


    Validator.isInt(-15, 'width');                              // true
    Validator.isInt(-15.0, 'width');                            // true
    Validator.isPosInt(15, 'width');                            // true

    Validator.isNonEmptyStr('James', 'name');                   // true
    Validator.isNonEmptyStr('', 'name', false);                 // false
    Validator.isNonEmptyStr(15, 'name');                        // throw error.

    /**
    * Must provide a 3rd argument.
    */
    Validator.isType('string', 'Singapore');                    // throw error.


    Validator.isInObj('a', {a:1, b:2}, 'state');                // true
    Validator.isInObj('x', {a:1, b:2}, 'state', false);         // false
    Validator.isInObj('x', {a:1, b:2}, 'state');                // throw error.

Public properties and methods :

    /**
    * Check whether a given value is a specified type.
    * 1. Null is treated as not `object` .
    * 2. NaN, infinite numbers are treated as not `number` .
    *
    * @param type {String} 
    * @param val                - Any type.
    * @param valTxt {String}    - Value text is used in thrown error message (if throws).
    * @param throwErr {Boolean} - optional - By default, it throws an error when validation fails,
    *                                      - Set this argument to 'false' it will always return a Boolean.
    * @return {Boolean} or throw error.
    */
    isType: function (type, val, valTxt, throwErr)


    /**
    * Check whether a given property is in the object.
    *
    * @param val {String}       - object property.
    * @param obj {Object}               
    * @param objTxt {String}    - Object text is used in thrown error message (if throws).
    * @param throwErr {Boolean} - optional - By default, it throws an error when validation fails,
    *                                      - Set this argument to 'false' it will always return a Boolean.
    * @return {Boolean} or throw error.
    */
    isInObj: function (val, obj, objTxt, throwErr)


    /**
    * Check integer.
    *
    * @param val                - Any type.
    * @param valTxt {String}    - Value text is used in thrown error message (if throws).
    * @param throwErr {Boolean} - optional - By default, it throws an error when validation fails,
    *                                      - Set this argument to 'false' it will always return a Boolean.
    * @return {Boolean} or throw error.
    */
    isInt: function (val, valTxt, throwErr)


    /**
    * Check positive integer.
    *
    * @param val                - Any type.
    * @param valTxt {String}    - Value text is used in thrown error message (if throws).
    * @param throwErr {Boolean} - optional - By default, it throws an error when validation fails,
    *                                      - Set this argument to 'false' it will always return a Boolean.
    * @return {Boolean} or throw error.
    */
    isPosInt: function (val, valTxt, throwErr)

    /**
    * Check non-empty string.
    *
    * @param val                - Any type.
    * @param valTxt {String}    - Value text is used in thrown error message (if throws).
    * @param throwErr {Boolean} - optional - By default, it throws an error when validation fails,
    *                                      - Set this argument to 'false' it will always return a Boolean.
    * @return {Boolean} or throw error.
    */
    isNonEmptyStr: function (val, valTxt, throwErr)

Tests

    npm test