validator-es5
A data validation utility, can be used to validate e.g. function arguments. Do argument validation improves code quality.
Browser support
Desktop: Chrome, Safari, Firefox, Opera, IE6+
Installation
npm install validator-es5 or jspm install npm:validator-es5
Usage
Some examples :
var Validator = ; Validator; // true Validator; // false Validator; // throw error. Validator; // true Validator; // false Validator; // true Validator; // false Validator; // false Validator; // true Validator; // true Validator; // true Validator; // true Validator; // true Validator; // true Validator; // false Validator; // throw error. /** * Must provide a 3rd argument. */ Validator; // throw error. Validator; // true Validator; // false Validator; // 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 * @param val - Any type. * @param valTxt * @param throwErr * - Set this argument to 'false' it will always return a Boolean. * @return */ /** * Check whether a given property is in the object. * * @param val * @param obj * @param objTxt * @param throwErr * - Set this argument to 'false' it will always return a Boolean. * @return */ isInObj: function (val, obj, objTxt, throwErr) /** * Check integer. * * @param val - Any type. * @param valTxt * @param throwErr * - Set this argument to 'false' it will always return a Boolean. * @return */ isInt: function (val, valTxt, throwErr) /** * Check positive integer. * * @param val - Any type. * @param valTxt * @param throwErr * - Set this argument to 'false' it will always return a Boolean. * @return */ isPosInt: function (val, valTxt, throwErr) /** * Check non-empty string. * * @param val - Any type. * @param valTxt * @param throwErr * - Set this argument to 'false' it will always return a Boolean. * @return */ isNonEmptyStr: function (val, valTxt, throwErr)
Tests
npm test