Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

iz

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iz - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

4

app.js

@@ -1,2 +0,3 @@

/*global require, module, window */
/*global require, module */
(function() {

@@ -6,3 +7,2 @@ 'use strict';

// serves as our bootstrap into other node apps
// let's not clutter up the .bin folder
var iz = require('../iz/src/iz'),

@@ -9,0 +9,0 @@ are = require('../iz/src/are'),

/*!
* iz - v0.2.0 https://github.com/parris/iz
* Built: 2013-05-21
* Copyright (c) 2013 Parris Khachi;
* Built: 2013-08-28
* Copyright (c) 2013-08-28 Parris Khachi
* Licensed under the MIT license
*/
var izBundle = function() {
var pkgmap = {}, global = {}, nativeRequire = typeof require != "undefined" && require, lib, ties, main, async;
function exports() {
return main();
}
exports.main = exports;
exports.module = module;
exports.packages = pkgmap;
exports.pkg = pkg;
exports.require = function require(uri) {
return pkgmap.main.index.require(uri);
};
ties = {};
aliases = {};
return exports;
function join() {
return normalize(Array.prototype.join.call(arguments, "/"));
}
function normalize(path) {
var ret = [], parts = path.split("/"), cur, prev;
var i = 0, l = parts.length - 1;
for (;i <= l; i++) {
cur = parts[i];
if (cur === "." && prev !== undefined) continue;
if (cur === ".." && ret.length && prev !== ".." && prev !== "." && prev !== undefined) {
ret.pop();
prev = ret.slice(-1)[0];
} else {
if (prev === ".") ret.pop();
ret.push(cur);
prev = cur;
}
}
return ret.join("/");
}
function dirname(path) {
return path && path.substr(0, path.lastIndexOf("/")) || ".";
}
function findModule(workingModule, uri) {
var moduleId = join(dirname(workingModule.id), /\.\/$/.test(uri) ? uri + "index" : uri).replace(/\.js$/, ""), moduleIndexId = join(moduleId, "index"), pkg = workingModule.pkg, module;
var i = pkg.modules.length, id;
while (i-- > 0) {
id = pkg.modules[i].id;
if (id == moduleId || id == moduleIndexId) {
module = pkg.modules[i];
break;
}
}
return module;
}
function newRequire(callingModule) {
function require(uri) {
var module, pkg;
if (/^\./.test(uri)) {
module = findModule(callingModule, uri);
} else if (ties && ties.hasOwnProperty(uri)) {
return ties[uri];
} else if (aliases && aliases.hasOwnProperty(uri)) {
return require(aliases[uri]);
} else {
pkg = pkgmap[uri];
if (!pkg && nativeRequire) {
try {
pkg = nativeRequire(uri);
} catch (nativeRequireError) {}
if (pkg) return pkg;
}
if (!pkg) {
throw new Error('Cannot find module "' + uri + '" @[module: ' + callingModule.id + " package: " + callingModule.pkg.name + "]");
}
module = pkg.index;
}
if (!module) {
throw new Error('Cannot find module "' + uri + '" @[module: ' + callingModule.id + " package: " + callingModule.pkg.name + "]");
}
module.parent = callingModule;
return module.call();
}
return require;
}
function module(parent, id, wrapper) {
var mod = {
pkg: parent,
id: id,
wrapper: wrapper
}, cached = false;
mod.exports = {};
mod.require = newRequire(mod);
mod.call = function() {
if (cached) {
return mod.exports;
}
cached = true;
global.require = mod.require;
mod.wrapper(mod, mod.exports, global, global.require);
return mod.exports;
};
if (parent.mainModuleId == mod.id) {
parent.index = mod;
parent.parents.length === 0 && (main = mod.call);
}
parent.modules.push(mod);
}
function pkg() {
var wrapper = arguments[arguments.length - 1], parents = Array.prototype.slice.call(arguments, 0, arguments.length - 1), ctx = wrapper(parents);
pkgmap[ctx.name] = ctx;
arguments.length == 1 && (pkgmap.main = ctx);
return function(modules) {
var id;
for (id in modules) {
module(ctx, id, modules[id]);
}
};
}
}(this);
izBundle.pkg(function(parents) {
return {
name: "iz",
mainModuleId: "web",
modules: [],
parents: parents
};
})({
are: function(module, exports, global, require, undefined) {
(function() {
"use strict";
var are;
function Are(rules) {
var self = this;
self._rules = rules;
this.valid = function() {
for (var key in self._rules) {
self._rules[key].revalidate();
if (!self._rules[key].valid) {
return false;
}
}
return true;
};
}
are = function(rules) {
return new Are(rules);
};
if (typeof exports !== "undefined") {
if (typeof module !== "undefined" && module.exports) {
exports = module.exports = are;
}
exports.are = are;
}
})();
},
iz: function(module, exports, global, require, undefined) {
(function() {
"use strict";
var iz, validators = require("./validators");
function Iz(value, error_messages) {
var self = this;
if (typeof error_messages === "object") {
this.error_messages = error_messages;
} else {
this.error_messages = {};
}
this._not = false;
this._calledValidations = {};
function not() {
self._not = true;
return self;
}
function revalidate() {
var args = [], i = 0;
self.errors = [];
self.valid = true;
for (var key in self._calledValidations) {
var rule = self._calledValidations[key];
if (self._calledValidations.hasOwnProperty(key)) {
if (rule.not) {
self.not();
}
validator_partial(rule.validation).apply(self, rule.args);
}
}
return self;
}
function setValue(value) {
self.value = value;
self.revalidate();
return self;
}
this.not = not;
this.value = value;
this.setValue = setValue;
this.revalidate = revalidate;
this.errors = [];
this.valid = true;
function validator_partial(fn) {
var fnName = Array.prototype.slice.call(arguments)[0], args = Array.prototype.slice.call(arguments, 1);
args.unshift(value);
return function() {
var argArray = Array.prototype.slice.call(arguments), allArguments = [ self.value ].concat(argArray), result = validators[fn].apply(null, allArguments), key = (self._not ? "not_" : "") + fnName;
self._calledValidations[key] = {
not: self._not,
validation: fn,
args: argArray
};
if (!this._not && !result || this._not && result) {
if (!this._not && typeof this.error_messages[fn] !== "undefined") {
this.errors.push(this.error_messages[fn]);
} else if (this._not && typeof this.error_messages["not_" + fn] !== "undefined") {
this.errors.push(this.error_messages["not_" + fn]);
} else if (this._not) {
this.errors.push("Not " + fn);
} else {
this.errors.push(fn);
}
this.valid = false;
}
this._not = false;
return this;
};
}
for (var fn in validators) {
if (validators.hasOwnProperty(fn)) {
this[fn] = validator_partial(fn);
}
}
}
iz = function(value, error_messages) {
return new Iz(value, error_messages);
};
for (var fn in validators) {
if (validators.hasOwnProperty(fn)) {
iz[fn] = validators[fn];
}
}
if (typeof exports !== "undefined") {
if (typeof module !== "undefined" && module.exports) {
exports = module.exports = iz;
}
exports.iz = iz;
}
})();
},
validators: function(module, exports, global, require, undefined) {
(function() {
var validators = {};
function iz_alphaNumeric(value) {
return /^[a-z0-9]+$/i.test(value);
}
function iz_number(val) {
if ((typeof val === "string" || typeof val === "number") && !isNaN(val % 1)) {
return true;
}
return false;
}
function iz_between(val, start, end) {
if (typeof val === "object" || typeof val === "function" || typeof start === "object" || typeof start === "function" || typeof end === "object" || typeof end === "function") {
return false;
}
if (val >= start && val <= end) {
return true;
}
return false;
}
function iz_boolean(value) {
if (typeof value === "boolean" || typeof value === "number" && (value === 0 || value === 1)) {
return true;
}
return false;
}
function iz_int(value, allowDecimal) {
if (typeof allowDecimal !== "boolean") {
allowDecimal = false;
}
if (!allowDecimal) {
return /^\s*(\+|-)?\d+\s*$/.test(value);
} else if (iz_number(value) && value % 1 === 0) {
return true;
}
return false;
}
function luhnChk(luhn) {
var len = luhn.length, mul = 0, prodArr = [ [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], [ 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 ] ], sum = 0;
while (len--) {
sum += prodArr[mul][parseInt(luhn.charAt(len), 10)];
mul ^= 1;
}
return sum % 10 === 0 && sum > 0;
}
function iz_getObjectClass(obj) {
if (obj && obj.constructor && obj.constructor.toString) {
var arr = obj.constructor.toString().match(/function\s*(\w+)/);
if (arr && arr.length === 2) {
return arr[1];
}
}
return undefined;
}
function iz_cc(value) {
if (typeof value !== "string" && typeof value !== "number") {
return false;
}
value = value.replace(/[ \-]/g, "");
if (iz_int(value)) {
return luhnChk(value);
}
return false;
}
function iz_date(value) {
return iz_getObjectClass(value) === "Date" || new Date(value).toString() !== "Invalid Date" || !isNaN(new Date(value));
}
function iz_decimal(value) {
return iz_number(value) && Math.floor(value) != value;
}
function iz_email(value) {
return !(typeof value !== "string") && /\S+@\S+/.test(value);
}
function iz_empty(value) {
var type = typeof value, key;
if (value.hasOwnProperty("length") && type !== "function" && value.length > 0) {
return false;
} else if (type === "function" || type === "object") {
for (key in value) {
if (value.hasOwnProperty(key)) {
return false;
}
}
}
return true;
}
function iz_blank(value) {
if (typeof value === "string") {
return iz_empty(value);
}
return false;
}
function iz_equal(value, value2) {
var valueType = typeof value, value2Type = typeof value2, key;
if ((valueType === "object" || valueType === "function") && typeof value.equals === "function") {
if (value2Type === "object" || value2Type === "function") {
return value.equals(value2);
}
} else if (valueType === "object" || valueType === "function") {
for (key in value) {
if (value.hasOwnProperty(key) && !value2.hasOwnProperty(key) && key !== "equals") {
if (typeof value[key] === "object" || typeof value[key] === "function" && !iz_equal(value[key], value2[key])) {
return false;
} else if (value[key] !== value2[key]) {
return false;
}
}
}
return true;
}
return value === value2;
}
function iz_extension(obj1, obj2) {
var key;
if (typeof obj1 !== "object" || typeof obj2 !== "object") {
return false;
}
for (key in obj2) {
if (obj2.hasOwnProperty(key) && typeof obj1[key] === "undefined") {
return false;
}
}
return true;
}
function iz_fileExtension(value, validExtensions) {
var ext;
if (typeof validExtensions !== "object" || typeof validExtensions.indexOf === "undefined" || typeof value !== "string") {
return false;
}
ext = value.split(".").pop().toLowerCase();
if (validExtensions.indexOf(ext) !== -1) {
return true;
}
return false;
}
function iz_fileExtensionAudio(value) {
var validExtensions = [ "mp3", "ogg", "aac", "wav" ];
return iz_fileExtension(value, validExtensions);
}
function iz_fileExtensionImage(value) {
var validExtensions = [ "gif", "png", "jpeg", "jpg", "svg", "bmp" ];
return iz_fileExtension(value, validExtensions);
}
function iz_fileExtensionVideo(value) {
var validExtensions = [ "mp4", "ogv", "m4v", "mov", "avi" ];
return iz_fileExtension(value, validExtensions);
}
function iz_inArray(value, arr) {
if (typeof arr !== "object" || typeof arr.indexOf === "undefined") {
return false;
}
if (arr.indexOf(value) !== -1) {
return true;
}
return false;
}
function iz_ip(str) {
var re = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$|^(?:(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-fA-F]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,1}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,2}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,3}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:[0-9a-fA-F]{1,4})):)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,4}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,5}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,6}(?:(?:[0-9a-fA-F]{1,4})))?::))))$/;
return re.test(str);
}
function iz_minLength(val, len) {
if ((typeof val === "string" || typeof val === "object") && typeof val.length !== "undefined" && iz_int(len) && val.length >= len) {
return true;
}
return false;
}
function iz_maxLength(val, len) {
if ((typeof val === "string" || typeof val === "object") && typeof val.length !== "undefined" && iz_int(len) && val.length <= len) {
return true;
}
return false;
}
function iz_multiple(num, multiple) {
if (typeof num !== "number" || typeof multiple !== "number") {
return false;
}
if (num % multiple === 0) {
return true;
}
return false;
}
function iz_ofType(obj, type) {
if (typeof obj === "object" && typeof obj.length === "undefined" && typeof type === "string") {
if (iz_getObjectClass(obj) === type) {
return true;
}
}
return false;
}
function iz_phone(str) {
var cleanedStr = "", numbers = [];
if (typeof str === "string") {
cleanedStr = str.replace(/[^x0-9]/g, "");
numbers = cleanedStr.split("x");
if (numbers.length > 0 && iz_int(numbers[0]) && (numbers[0].length === 10 || numbers[0].length === 11) && iz_int(numbers.pop())) {
return true;
}
}
return false;
}
function iz_postal(str) {
var cleanedStr = "";
if (typeof str === "string") {
cleanedStr = str.replace(/[^0-9]/g, "");
if (iz_int(cleanedStr) && (cleanedStr.length === 5 || cleanedStr.length === 9)) {
return true;
}
}
return false;
}
function iz_ssn(str) {
var cleanedStr = "";
if (typeof str === "string") {
cleanedStr = str.replace(/[^0-9]/g, "");
if (iz_int(cleanedStr) && cleanedStr.length === 9) {
return true;
}
}
return false;
}
validators.alphaNumeric = iz_alphaNumeric;
validators.between = iz_between;
validators.blank = iz_blank;
validators.boolean = iz_boolean;
validators.cc = iz_cc;
validators.date = iz_date;
validators.decimal = iz_decimal;
validators.email = iz_email;
validators.empty = iz_empty;
validators.equal = iz_equal;
validators.extension = iz_extension;
validators.fileExtension = iz_fileExtension;
validators.fileExtensionAudio = iz_fileExtensionAudio;
validators.fileExtensionImage = iz_fileExtensionImage;
validators.fileExtensionVideo = iz_fileExtensionVideo;
validators.inArray = iz_inArray;
validators.int = iz_int;
validators.ip = iz_ip;
validators.minLength = iz_minLength;
validators.maxLength = iz_maxLength;
validators.multiple = iz_multiple;
validators.number = iz_number;
validators.ofType = iz_ofType;
validators.phone = iz_phone;
validators.postal = iz_postal;
validators.ssn = iz_ssn;
if (typeof exports !== "undefined") {
if (typeof module !== "undefined" && module.exports) {
exports = module.exports = validators;
}
exports.validators = validators;
}
})();
},
web: function(module, exports, global, require, undefined) {
(function() {
"use strict";
var iz = require("./iz"), are = require("./are"), validators = require("./validators");
iz.are = are;
iz.validators = validators;
module.exports = iz;
})();
}
});
if (typeof module != "undefined" && module.exports) {
module.exports = izBundle;
if (!module.parent) {
izBundle();
}
}
define("validators",["require","exports","module"],function(t,e,n){!function(){function t(t){return/^[a-z0-9]+$/i.test(t)}function r(t){return"string"!=typeof t&&"number"!=typeof t||isNaN(t%1)?!1:!0}function o(t,e,n){return"object"==typeof t||"function"==typeof t||"object"==typeof e||"function"==typeof e||"object"==typeof n||"function"==typeof n?!1:t>=e&&n>=t?!0:!1}function i(t){return"boolean"==typeof t||"number"==typeof t&&(0===t||1===t)?!0:!1}function f(t,e){return"boolean"!=typeof e&&(e=!1),e?r(t)&&0===t%1?!0:!1:/^\s*(\+|-)?\d+\s*$/.test(t)}function a(t){for(var e=t.length,n=0,r=[[0,1,2,3,4,5,6,7,8,9],[0,2,4,6,8,1,3,5,7,9]],o=0;e--;)o+=r[n][parseInt(t.charAt(e),10)],n^=1;return 0===o%10&&o>0}function u(t){if(t&&t.constructor&&t.constructor.toString){var e=t.constructor.toString().match(/function\s*(\w+)/);if(e&&2===e.length)return e[1]}return void 0}function s(t){return"string"!=typeof t&&"number"!=typeof t?!1:(t=t.replace(/[ \-]/g,""),f(t)?a(t):!1)}function p(t){return"Date"===u(t)||"Invalid Date"!==new Date(t).toString()||!isNaN(new Date(t))}function l(t){return r(t)&&!f(t,!1)}function c(t){return!("string"!=typeof t)&&/\S+@\S+/.test(t)}function d(t){var e,n=typeof t;if(t.hasOwnProperty("length")&&"function"!==n&&t.length>0)return!1;if("function"===n||"object"===n)for(e in t)if(t.hasOwnProperty(e))return!1;return!0}function y(t){return"string"==typeof t?d(t):!1}function h(t,e){var n,r=typeof t,o=typeof e;if("object"!==r&&"function"!==r||"function"!=typeof t.equals){if("object"===r||"function"===r){for(n in t)if(t.hasOwnProperty(n)&&!e.hasOwnProperty(n)&&"equals"!==n){if("object"==typeof t[n]||"function"==typeof t[n]&&!h(t[n],e[n]))return!1;if(t[n]!==e[n])return!1}return!0}}else if("object"===o||"function"===o)return t.equals(e);return t===e}function g(t,e){var n;if("object"!=typeof t||"object"!=typeof e)return!1;for(n in e)if(e.hasOwnProperty(n)&&"undefined"==typeof t[n])return!1;return!0}function v(t,e){var n;return"object"!=typeof e||"undefined"==typeof e.indexOf||"string"!=typeof t?!1:(n=t.split(".").pop().toLowerCase(),-1!==e.indexOf(n)?!0:!1)}function A(t){var e=["mp3","ogg","aac","wav"];return v(t,e)}function _(t){var e=["gif","png","jpeg","jpg","svg","bmp"];return v(t,e)}function F(t){var e=["mp4","ogv","m4v","mov","avi"];return v(t,e)}function m(t,e){return"object"!=typeof e||"undefined"==typeof e.indexOf?!1:-1!==e.indexOf(t)?!0:!1}function b(t){var e=/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$|^(?:(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-fA-F]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,1}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,2}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,3}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:[0-9a-fA-F]{1,4})):)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,4}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,5}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,6}(?:(?:[0-9a-fA-F]{1,4})))?::))))$/;return e.test(t)}function x(t,e){return("string"==typeof t||"object"==typeof t)&&"undefined"!=typeof t.length&&f(e)&&t.length>=e?!0:!1}function w(t,e){return("string"==typeof t||"object"==typeof t)&&"undefined"!=typeof t.length&&f(e)&&t.length<=e?!0:!1}function j(t,e){return"number"!=typeof t||"number"!=typeof e?!1:0===t%e?!0:!1}function O(t,e){return"object"==typeof t&&"undefined"==typeof t.length&&"string"==typeof e&&u(t)===e?!0:!1}function z(t){var e="",n=[];return"string"==typeof t&&(e=t.replace(/[^x0-9]/g,""),n=e.split("x"),n.length>0&&f(n[0])&&(10===n[0].length||11===n[0].length)&&f(n.pop()))?!0:!1}function P(t){var e="";return"string"!=typeof t||(e=t.replace(/[^0-9]/g,""),!f(e)||5!==e.length&&9!==e.length)?!1:!0}function q(t){var e="";return"string"==typeof t&&(e=t.replace(/[^0-9]/g,""),f(e)&&9===e.length)?!0:!1}function V(t){return void 0!==t&&null!==t&&""!==t}function Z(t){return function(e){return!V(e)||t.apply(this,Array.prototype.slice.call(arguments))}}var N={};N.alphaNumeric=Z(t),N.between=Z(o),N.blank=Z(y),N.boolean=Z(i),N.cc=Z(s),N.date=Z(p),N.decimal=Z(l),N.email=Z(c),N.empty=Z(d),N.equal=Z(h),N.extension=g,N.fileExtension=Z(v),N.fileExtensionAudio=Z(A),N.fileExtensionImage=Z(_),N.fileExtensionVideo=Z(F),N.inArray=m,N.int=Z(f),N.ip=Z(b),N.minLength=Z(x),N.maxLength=Z(w),N.multiple=Z(j),N.number=Z(r),N.ofType=Z(O),N.phone=Z(z),N.postal=Z(P),N.required=V,N.ssn=Z(q),"undefined"!=typeof e&&("undefined"!=typeof n&&n.exports&&(e=n.exports=N),e.validators=N)}()}),define("iz",["require","exports","module","./validators"],function(t,e,n){var r=t("./validators");!function(){function t(t,e){function n(){return a._not=!0,a}function o(){a.errors=[],a.valid=!0;for(var t in a._calledValidations){var e=a._calledValidations[t];a._calledValidations.hasOwnProperty(t)&&(e.not&&a.not(),f(e.validation).apply(a,e.args))}return a}function i(t){return a.value=t,a.revalidate(),a}function f(e){var n=Array.prototype.slice.call(arguments)[0],o=Array.prototype.slice.call(arguments,1);return o.unshift(t),function(){var t=Array.prototype.slice.call(arguments),o=[a.value].concat(t),i=r[e].apply(null,o),f=(a._not?"not_":"")+n;return a._calledValidations[f]={not:a._not,validation:e,args:t},(!this._not&&!i||this._not&&i)&&(this._not||"undefined"==typeof this.error_messages[e]?this._not&&"undefined"!=typeof this.error_messages["not_"+e]?this.errors.push(this.error_messages["not_"+e]):this._not?this.errors.push("Not "+e):this.errors.push(e):this.errors.push(this.error_messages[e]),this.valid=!1),this._not=!1,this}}var a=this;this.error_messages="object"==typeof e?e:{},this._not=!1,this._calledValidations={},this.not=n,this.value=t,this.setValue=i,this.revalidate=o,this.errors=[],this.valid=!0;for(var u in r)r.hasOwnProperty(u)&&(this[u]=f(u))}var o;o=function(e,n){return new t(e,n)};for(var i in r)r.hasOwnProperty(i)&&(o[i]=r[i]);"undefined"!=typeof e&&("undefined"!=typeof n&&n.exports&&(e=n.exports=o),e.iz=o)}()}),define("are",["require","exports","module","./iz"],function(t,e,n){var r=t("./iz");!function(){function t(t){var e,n,o,i,f=this;f._fields={};for(i in t)if(t.hasOwnProperty(i))if("undefined"!=typeof t[i].revalidate)f._fields[i]=t[i];else{o={};for(n in t[i])t[i].hasOwnProperty(n)&&t[i][n].error&&(o[t[i][n].rule]=t[i][n].error);e=r(0,o);for(n in t[i])t[i].hasOwnProperty(n)&&(t[i][n].rule.indexOf("not_")>-1&&e.not(),e[t[i][n].rule.replace("not_","")].apply(e,t[i][n].args||[]));f._fields[i]=e}this.valid=function(){for(var t in f._fields)if(f._fields[t].hasOwnProperty(t)&&(f._fields[t].revalidate(),!f._fields[t].valid))return!1;return!0},this.validFor=function(t){var e,n,r,o=0;for(e in f._fields)if(f._fields.hasOwnProperty(e)){for(n=e.split("."),r=t[n[0]],o=1;o<n.length;o++)r=r[n[o]];if(f._fields[e].setValue(r),!f._fields[e].valid)return!1}return!0}}var o;o=function(e){return new t(e)},"undefined"!=typeof e&&("undefined"!=typeof n&&n.exports&&(e=n.exports=o),e.are=o)}()});

@@ -0,11 +1,15 @@

/*global module */
module.exports = function(grunt) {
'use strict';
var bannerTemplate =
'/*!\n' +
' * <%= pkg.title || pkg.name %> - v<%= pkg.version %> <%= pkg.homepage %>\n' +
' * Built: <%= grunt.template.today("yyyy-mm-dd") %>\n' +
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>;\n' +
' * Licensed under the <%= pkg.license %> license\n' +
' */\n',
pkg = grunt.file.readJSON('package.json');
var pkg = grunt.file.readJSON('package.json'),
bannerTemplate =
'/*!\n' +
' * ' + pkg.name + ' - v' + pkg.version + ' ' + pkg.homepage + '\n' +
' * Built: ' + grunt.template.today('yyyy-mm-dd') + '\n' +
' * Copyright (c) ' + grunt.template.today('yyyy-mm-dd') + ' ' + pkg.author + '\n' +
' * Licensed under the ' + pkg.license + ' license\n' +
' */\n',
requirejs = require('requirejs');

@@ -24,42 +28,23 @@ grunt.initConfig({

all: { src: 'spec/**/*.js' }
},
shell: {
one: {
command: './node_modules/one/bin/onejs build webpackage.json'
}
},
uglify: {
iz: {
options: {
banner: bannerTemplate,
beautify: true,
width: 100,
mangle: false,
compress: false
},
files: {
//reading from browserify bundle
'dist/iz.js': ['dist/iz.js']
}
},
izMin: {
options: {
banner: bannerTemplate,
compress: false,
mangle: {
except: ['Iz']
}
},
files: {
'dist/iz.min.js': ['dist/iz.js']
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-shell');
grunt.registerTask('build', ['shell', 'uglify']);
grunt.registerTask('requirejs', function() {
requirejs.optimize({
baseUrl: 'src/',
out: 'dist/iz.js',
include: ['are', 'validators', 'iz'],
cjsTranslate: true,
optimize: 'uglify2',
wrap: {
start: bannerTemplate,
end: ''
}
});
});
grunt.registerTask('build', ['requirejs']);
grunt.registerTask('test', ['simplemocha']);

@@ -66,0 +51,0 @@

{
"name": "iz",
"version": "0.2.0",
"version": "0.3.0",
"description": "Validation for node and the web.",

@@ -20,9 +20,7 @@ "main": "app.js",

"should": "~0.6.3",
"uglify-js": "~1.3.3",
"grunt": "~0.4.1",
"grunt-contrib-uglify": "~0.2.0",
"grunt-shell": "~0.2.2",
"one": "~3.0.13",
"grunt-simple-mocha": "~0.3.2",
"grunt-cli": "~0.1.7"
"requirejs": "2.1.6",
"grunt-cli": "~0.1.9"
},

@@ -29,0 +27,0 @@ "scripts": {

[![Build Status](https://secure.travis-ci.org/parris/iz.png)](http://travis-ci.org/parris/iz)
Goals/Info
What is it?
====
This package's goals are really simple. Just looking for a lightweight manner to validate common things. It is user
centric and ensures that they don't make typos. It does not require them to enter things in "some right way", but
rather "a right way". In other words if they like to put "." instead of "-" in their phone numbers it should let them.
We should just make sure they don't mess up and only put 8 numbers instead of 10. If we need our data in some other
format that is our job to normalize! In fact that might be a good next project... "norm.js" sounds fairly sexy to me :).
It also provides validation for required fields and separates it from whether what a user has entered is valid.
A validation library written for client/server side needs in javascript. Oh and awesome syntax is important to us too.

@@ -15,3 +10,3 @@ Setup

Node
Server side (Node/CommonJS)
----

@@ -29,52 +24,122 @@

----
Simply include `iz.js` or `iz.min.js` like so:
This depends on situation. If you are using CommonJS modules use the server side syntax.
<script src="iz.min.js"></script>
<script>
var iz = izBundle(),
are = iz.are,
validators = iz.validators;
</script>
If you are using AMD modules, you can run `npm build` or grab the latest dist/iz.js. You can include it on your page; however, you wish then:
require(['iz', 'are', 'validators'], function(iz, are, validators) {
});
If you are **not** using a module system you may want to take a look at OneJS/Browserify, and how we did client side builds in v0.2.0 (just view the tag on github).
API
====
Chaining:
----
iz(10).between(2, 15).int().multiple(5); //why yes, yes it is
iz(10).between(2, 15).not().between(1, 5).int().multiple(5); // the fancy not operator will cause the opposite result to happen next... this is also true!
iz(10).not().between(1, 5); // the fancy not operator will cause the opposite result to happen next. This is also true!
When using the chained notation an object containing an errors{array} and valid{bool} is returned. You could take the
returned object and run more validations on it later as well. This function also accepts an object with error names. If you `.not()` something
then you can provide not_* in the error_messages object to return a custom error.
iz(), and all validation commands return an Iz object. An iz object always contains an `errors`{array} and `valid`{bool}. `errors` will be filled with a default error messsage for each incorrect field. To provide custom error messages you can do the following:
var errors = {
between: "Is not between, please fix",
not_between: "Value must be between!",
int: "Not an int!!!",
multiple: "This is terrible and you should fix it"
between: 'Is not between, please fix',
not_between: 'Value must be between!',
int: 'Not an int!!!',
multiple: 'This is terrible and you should fix it'
}
iz("Bob", errors).between(2, 15).int().multiple(5);
iz('Bob', errors).between(2, 15).int().multiple(5);
You don't need to use the chained notation. Alternatively you could call the functions more simply:
Simple Checks
----
You don't need to use the chained notation. The following will return true or false:
iz.between(3, 2, 5); //is 3, between 2 and 5?
Required Fields:
JSON
----
It is often useful to get a list of validations from your server for a given model. Nested objects work to!
When using iz.required(*) it can be used alone or chained with other validators to cover the following scenarios:
var rules = {
'cost': [
{
'rule': 'between',
'args': [17, 1000],
'error': 'The cost must be between 17, 1000'
},
{
'rule': 'required',
'error': 'You must specify a cost'
},
],
'producer.id': [
{
'rule': 'int',
'error': 'Producer ID must be an int'
}
],
'producer.name.first': [
{
'rule': 'alphaNumeric',
'error': 'Must be names and numbers'
}
]
};
iz(value).required() //value is required
iz(value).required().email() //value is required and is a valid email
iz(value).date() //value is not required but must be a date if provided
are(rules).validFor({
cost: 20,
producer: {
id: 1,
name: {
first: 'bob'
}
}
});
This behaviour is great for validating user input or payloads sent to an api where validation of required fields is a common need.
Are/Multiple rules
----
`are` doesn't just force you to use json validations. You could also check if any number of chained or json rules are valid.
N.B. However, it means that iz(null).date(), iz(undefined).email() and iz('').int() will all return true!!! While this seems counter intuitive, it is important to realise that iz validates only if a value is actually provided. Whether a value is required or not is a separate concern altogether and is covered by iz.required(*);
var wine = new Bottle({age: 30, cost: 1000.01}),
costErrors = {
number: 'Cost must be given as a number'
},
ageErrors = {
int: 'Must be an whole number',
between: 'This wine is too young, it's no good'
},
rules = {
cost: iz(wine.cost, costErrors).decimal(),
age: iz(wine.age, ageErrors)
.int().between(17, 10000)
},
areRules = are(rules);
areRules.valid(); // true
rules.cost.setValue(2000.00);
areRules.valid(); // true, setValue revalidates, as does are.valid
rules.cost('hi'); // we didn't use setValue on the Iz cost object
rules.cost.valid; // and valid is still true
are(rules).valid() // but `valid()` will revalidate, false
rules.cost.valid // and `valid` is now in the correct state again
// or you can use this and just give null values in the rules object
areRules.validFor(wine)
Required Fields:
----
In most cases, you'll only want to validate values when they exist. By default iz functions in this way. If you want to force the presence of a value you can use the `required` method.
iz(value).required() //a value is required
iz(value).required().email() //value is required and is a valid email
iz(value).date() //value is not required but must be a date if provided
Validators:
----
All validators (apart from iz.required) return true if no value is provided (e.g. null, undefined or '').
Possible validations so far (true case in comments):
Validations (true case in comments):

@@ -87,3 +152,3 @@ iz.alphaNumeric(*); // Is number or string(contains only numbers or strings)

iz.date(*); // Is a date obj or is a string that is easily converted to a date
iz.decimal(*); // Contains 1 decimal point and potentially can have a - at the beginning
iz.decimal(*); // int or float
iz.email(*); // Seems like a valid email address

@@ -99,4 +164,4 @@ iz.empty(*); // If an object, array or function contains no properties true. All primitives return true.

iz.ip(str); // str resembles an IPV4 or IPV6 address
iz.minLen(val, min); // val (str or arr) is greater than min
iz.maxLen(val, max); // val (str or arr) is shorter than max
iz.minLength(val, min); // val (str or arr) is greater than min
iz.maxLength(val, max); // val (str or arr) is shorter than max
iz.multiple(num, mult); // Number is multiple of another number

@@ -112,54 +177,9 @@ iz.number(*); // Is either an int or decimal

Group/Saved Validations
====
You can now validate multiple fields at once!
var iz = require("iz"),
are = iz.are,
validators = iz.validators
// Bottle, is the name of the model
wine = new Bottle({age: 30, cost: 1000.00}),
// How I want to output my errors
costErrors = {
decimal: "Cost must be given as a decimal"
},
ageErrors = {
int: "Must be an whole number",
between: "This wine is too young, it's no good"
},
// My rules, I can look at the keys and inspect the errors
rules = {
cost: iz(wine.cost, costErrors).decimal(),
age: iz(wine.age, ageErrors)
.int().between(17, 10000)
};
are(rules).valid();
// true
rules.cost.setValue(2000.00);
are(rules).valid();
// true, setValue revalidates, as does are.valid
rules.cost(100);
rules.cost.valid;
// still true
are(rules).valid()
// false, revalidate was called
rules.cost.valid
// false
Omissions
Ommissions
====
Lastly, I omitted a few typical validations (temporarily maybe) for these reasons:
- Uniqueness: I may eventually write some sort of interface for uniqueness checks within some db, but for now this is non-trivial. First up would be mongodb.
- Uniqueness: This is non-trivial since it requires db/server side/client side knowledge.
- File: Not sure what the scope should be yet. Mime types? Existence on the web?
- Email (more in depth): Right now we check for the @ symbol. This accepts all email address. Some more hard regex would be cool, but a real valid email regex is overly complicated and doesn't accept everything. The other option is an in depth check with an email provider (sbcglobal comes to mind).
- Money: The scope is really large. Thinking about having localized settings. Perhaps specifying some simple format. Not sure yet!
- Email (more in depth): Right now we check for the @ symbol. There are extremely complicated regex out there. I haven't really found the need. If you have an idea send a pull request!
- Money: The scope is really large. I am thinking about having localized settings.
- URL: No real non-crazy regex exists. Checking for http:// at the front is lame, why force your user to type that in?

@@ -169,14 +189,14 @@

Thoughts
====
- A ton of "checking" done, but the library doesn't expose calculated values (even though it finds them). For example the library doesn't tell you what type something is, it simply tells you if the type matches some string. It might be useful to provide checking methods along with calculation and sanitization.
- Getters could be used instead of the "not()" function. All it does is set _not to true and then return Iz; however, the check done to see if getters are available in the environment is the same check that would need to be done when running the validations. Since we are trying to make this tool relatively cross-platform I decided to omit this functionality.
Change Log
====
Next: Validator mixins, add source map, and refactor Iz class a bit.
Experimental: Client side include method system. Let me know what you think about it.
Note: I am creating an integration for backbone in another repo.
Next: Refactor Iz class a bit. Add support for custom validations.
0.3.0
----
- Added JSON based validations
- Replaced previous build system with requirejs.
- Doc simplification
- Code style reformatting
0.2.0

@@ -190,3 +210,3 @@ ----

- Fixed loading of iz, are and validator modules
- Added missing "blank" validator
- Added missing 'blank' validator
- Added build/test system via grunt

@@ -193,0 +213,0 @@ - Removed versions in bin

/*global describe, it, xit, xdescribe, before, require */
/*jshint expr:true*/
var iz = require("../src/iz"),
are = require("../src/are");
var iz = require('../src/iz'),
are = require('../src/are');
describe("Are", function() {
describe('Are', function() {
'use strict';
beforeEach(function() {
this.costErrors = {
decimal: "Must be a decimal!"
};
this.ageErrors = {
not_decimal: "Shouldn't be a decimal!",
int: "Must be an integer",
between: "This movie is rated R, you are too young!"
};
this.rules = {
cost: iz(5.00, this.costErrors).decimal(),
age: iz(20, this.ageErrors)
.not().decimal()
.int().between(17, 10000)
};
describe('group validations', function() {
beforeEach(function() {
this.costErrors = {
decimal: 'Must be a decimal!'
};
this.ageErrors = {
not_decimal: 'Shouldn\'t be a decimal!',
int: 'Must be an integer',
between: 'This movie is rated R, you are too young!'
};
this.rules = {
cost: iz(5.00, this.costErrors).number(),
age: iz(20, this.ageErrors)
.not().decimal()
.int().between(17, 10000)
};
});
it('allows you to validate multiple things at once', function () {
are(this.rules).valid().should.be.ok;
});
});
it("allows you to validate multiple things at once", function () {
are(this.rules).valid().should.not.be.ok;
describe('JSON group validations', function() {
beforeEach(function() {
this.rules = {
'cost': [
{
'rule': 'between',
'args': [17, 1000],
'error': 'The cost must be between 17, 1000'
},
{
'rule': 'decimal',
'error': 'The cost must be a decimal'
},
{
'rule': 'required',
'error': 'You must specify a cost'
},
],
'producer.id': [
{
'rule': 'int',
'error': 'Producer ID must be an int'
}
],
'producer.name.first': [
{
'rule': 'alphaNumeric',
'error': 'Must be names and numbers'
}
]
};
this.validObject = {
cost: 90.3,
producer: {
id: 5,
name: {
first: 'steve'
}
}
};
this.invalidObject = {
cost: 90.3,
producer: {
id: 'bob', //invalid
name: {
first: 'steve'
}
}
};
});
it('correctly validates', function() {
are(this.rules).validFor(this.validObject).should.be.ok;
are(this.rules).validFor(this.invalidObject).should.not.be.ok;
});
describe('with required fields', function() {
beforeEach(function() {
this.rules['producer.name.first'].push({
rule: 'required'
});
this.validObject = {
cost: 40.3,
producer: {
name: {
first: 'steve'
}
}
};
this.invalidObject = {
producer: {}
};
this.validations = are(this.rules);
});
it('correctly validates', function() {
this.validations.validFor(this.validObject).should.be.ok;
this.validations.validFor(this.invalidObject).should.not.be.ok;
});
});
});
});
/*global describe, it, xit, xdescribe, before, require */
/*jshint expr:true*/
var iz = require("../src/iz");
describe("Iz", function () {
var iz = require('../src/iz');
describe('Iz', function () {
'use strict';
it("can be created", function () {
it('can be created', function () {
//some value
(typeof (iz(5)) === "object").should.be.ok;
(typeof iz === "function").should.be.ok;
(typeof (iz(5)) === 'object').should.be.ok;
(typeof iz === 'function').should.be.ok;
});
it("has prototyped methods and can call one", function () {
(typeof iz(5).alphaNumeric === "function").should.be.ok;
it('has prototyped methods and can call one', function () {
(typeof iz(5).alphaNumeric === 'function').should.be.ok;
(iz(5).alphaNumeric().valid).should.be.ok;

@@ -21,17 +21,17 @@ //with parameters

it("allows methods to be chained together", function () {
it('allows methods to be chained together', function () {
iz(5).alphaNumeric().between(3, 5).int().valid.should.be.ok;
});
it("tells you what fails when you chain", function () {
it('tells you what fails when you chain', function () {
var result = iz(5).between(1, 2).boolean();
result.valid.should.not.be.ok;
result.errors.should.include("between");
result.errors.should.include("boolean");
result.errors.should.include('between');
result.errors.should.include('boolean');
});
it("accepts an error message list", function () {
it('accepts an error message list', function () {
var errors = {
between: "Is not between",
boolean: "Is not Boolean"
between: 'Is not between',
boolean: 'Is not Boolean'
},

@@ -44,21 +44,21 @@ result = iz(5, errors).between(1, 2).boolean();

it("allows to .not validations", function () {
it('allows to .not validations', function () {
iz(5).not().between(10, 20).valid.should.be.ok;
iz(5).not().email().valid.should.be.ok;
iz("bob@yahoo").not().email().valid.should.not.be.ok;
iz('bob@yahoo').not().email().valid.should.not.be.ok;
});
it("accepts errors for .not'd validations", function () {
it('accepts errors for .not\'d validations', function () {
var error_messages = {
not_between: "Your value needs to not be between!"
not_between: 'Your value needs to not be between!'
};
iz(5, error_messages).not().between(4, 6).errors.should.include(error_messages.not_between);
iz(5).not().between(4, 6).errors.should.include("Not between");
iz(5).not().between(4, 6).errors.should.include('Not between');
});
it("allows switching between .not and normal validations", function () {
it('allows switching between .not and normal validations', function () {
iz(5).between(4, 6).not().ip().int().valid.should.be.ok;
});
it("allows for revalidation when the value is changed", function() {
it('allows for revalidation when the value is changed', function() {
var rule = iz(5).between(2, 8);

@@ -65,0 +65,0 @@ rule.valid.should.be.ok;

/*global describe, it, xit, xdescribe, before, require */
/*jshint expr:true*/
var iz = require("../src/iz");
describe("Validation", function () {
var iz = require('../src/iz');
describe('Validation', function () {
'use strict';
it("can validate alpha numeric values", function () {
iz.alphaNumeric("a2d1kf0v9r9fje9fdgnsdksdf9240uyjsdfgkj").should.be.ok;
iz.alphaNumeric("aaaaaaa").should.be.ok;
iz.alphaNumeric("999999").should.be.ok;
it('can validate alpha numeric values', function () {
iz.alphaNumeric('a2d1kf0v9r9fje9fdgnsdksdf9240uyjsdfgkj').should.be.ok;
iz.alphaNumeric('aaaaaaa').should.be.ok;
iz.alphaNumeric('999999').should.be.ok;
iz.alphaNumeric(9999999).should.be.ok;
iz.alphaNumeric("_3423423").should.not.be.ok;
iz.alphaNumeric("342 3423").should.not.be.ok;
iz.alphaNumeric("alals*fd").should.not.be.ok;
iz.alphaNumeric('_3423423').should.not.be.ok;
iz.alphaNumeric('342 3423').should.not.be.ok;
iz.alphaNumeric('alals*fd').should.not.be.ok;
iz.alphaNumeric({}).should.not.be.ok;

@@ -24,3 +24,3 @@ iz.alphaNumeric(function () {}).should.not.be.ok;

it("can validate that a primitive is between 2 other primitives", function () {
it('can validate that a primitive is between 2 other primitives', function () {
iz.between(5, 5, 6).should.be.ok;

@@ -31,5 +31,5 @@ iz.between(6, 5, 6).should.be.ok;

iz.between(7, 4, 5).should.not.be.ok;
iz.between("abc", "aaa", "bbb").should.be.ok;
iz.between("aaa", "abc", "bbb").should.not.be.ok;
iz.between("aaa", "aaa", "bbb").should.be.ok;
iz.between('abc', 'aaa', 'bbb').should.be.ok;
iz.between('aaa', 'abc', 'bbb').should.not.be.ok;
iz.between('aaa', 'aaa', 'bbb').should.be.ok;
iz.between([1, 2], [1], [1, 4]).should.not.be.ok; //default array comparison... this is false.

@@ -43,3 +43,3 @@ iz.between({},{},{}).should.not.be.ok; //it hates objects

it("can validate boolean values", function () {
it('can validate boolean values', function () {
iz.boolean(true).should.be.ok;

@@ -50,4 +50,4 @@ iz.boolean(false).should.be.ok;

iz.boolean(-1).should.not.be.ok;
iz.boolean("deadbeef").should.not.be.ok;
iz.boolean("*").should.not.be.ok;
iz.boolean('deadbeef').should.not.be.ok;
iz.boolean('*').should.not.be.ok;
iz.boolean(/[ \-]/g).should.not.be.ok;

@@ -60,4 +60,4 @@

it('can validate blank values', function() {
iz.blank("").should.be.ok;
iz.blank("hi").should.not.be.ok;
iz.blank('').should.be.ok;
iz.blank('hi').should.not.be.ok;
iz.blank([]).should.not.be.ok;

@@ -72,29 +72,29 @@

*/
it("can validate credit card numbers", function () {
iz.cc("371449635398431").should.be.ok; //amex
iz.cc("343434343434343").should.be.ok; //amex
iz.cc("371144371144376").should.be.ok; //amex corp
iz.cc("5610591081018250").should.be.ok; //aus bankcard
iz.cc("30569309025904").should.be.ok; //diners club
iz.cc("38520000023237").should.be.ok; //diners club
iz.cc("6011111111111117").should.be.ok; //discover
iz.cc("6011000990139424").should.be.ok; //discover
iz.cc("3530111333300000").should.be.ok; //jcb
iz.cc("3566002020360505").should.be.ok; //jcb
iz.cc("5555555555554444").should.be.ok; //mc
iz.cc("5105105105105100").should.be.ok; //mc
iz.cc("4111111111111111").should.be.ok; //visa
iz.cc("4012888888881881").should.be.ok; //visa
iz.cc("4222222222222").should.be.ok; //visa
//iz.cc("76009244561").should.be.ok; //dankort (pbs) currently fails... anyone know why?
iz.cc("5019717010103742").should.be.ok; //dankort (pbs)
iz.cc("6331101999990016").should.be.ok; //switch/solo (paymentech)
it('can validate credit card numbers', function () {
iz.cc('371449635398431').should.be.ok; //amex
iz.cc('343434343434343').should.be.ok; //amex
iz.cc('371144371144376').should.be.ok; //amex corp
iz.cc('5610591081018250').should.be.ok; //aus bankcard
iz.cc('30569309025904').should.be.ok; //diners club
iz.cc('38520000023237').should.be.ok; //diners club
iz.cc('6011111111111117').should.be.ok; //discover
iz.cc('6011000990139424').should.be.ok; //discover
iz.cc('3530111333300000').should.be.ok; //jcb
iz.cc('3566002020360505').should.be.ok; //jcb
iz.cc('5555555555554444').should.be.ok; //mc
iz.cc('5105105105105100').should.be.ok; //mc
iz.cc('4111111111111111').should.be.ok; //visa
iz.cc('4012888888881881').should.be.ok; //visa
iz.cc('4222222222222').should.be.ok; //visa
//iz.cc('76009244561').should.be.ok; //dankort (pbs) currently fails... anyone know why?
iz.cc('5019717010103742').should.be.ok; //dankort (pbs)
iz.cc('6331101999990016').should.be.ok; //switch/solo (paymentech)
iz.cc("0000000000000000").should.not.be.ok;
iz.cc('0000000000000000').should.not.be.ok;
iz.cc("4012 8888 8888 1881").should.be.ok; //visa with spaces
iz.cc("4012-8888-8888-1881").should.be.ok; //visa with dashes
iz.cc('4012 8888 8888 1881').should.be.ok; //visa with spaces
iz.cc('4012-8888-8888-1881').should.be.ok; //visa with dashes
iz.cc({}).should.not.be.ok;
iz.cc(function () {}).should.not.be.ok;
iz.cc(["5"]).should.not.be.ok;
iz.cc(['5']).should.not.be.ok;

@@ -105,9 +105,9 @@ iz.cc(null).should.be.ok;

it("can validated dates", function () {
it('can validated dates', function () {
iz.date(new Date()).should.be.ok;
iz.date(0).should.be.ok; //assumed milliseconds from epoch
iz.date("09/23/2012").should.be.ok;
iz.date("09-23-2012 21:27:00").should.be.ok;
iz.date("January 5th, 2012").should.not.be.ok;
iz.date("Pizza").should.not.be.ok;
iz.date('09/23/2012').should.be.ok;
iz.date('09-23-2012 21:27:00').should.be.ok;
iz.date('January 5th, 2012').should.not.be.ok;
iz.date('Pizza').should.not.be.ok;
iz.date({}).should.not.be.ok;

@@ -121,10 +121,10 @@ iz.date(function () {}).should.not.be.ok;

it("can validate decimals", function () {
iz.decimal("5.5").should.be.ok;
it('can validate decimals', function () {
iz.decimal('5.5').should.be.ok;
iz.decimal(5.5).should.be.ok;
iz.decimal("340298.3234234").should.be.ok;
iz.decimal('340298.3234234').should.be.ok;
iz.decimal(5).should.not.be.ok;
iz.decimal("5").should.not.be.ok;
iz.decimal("5.5.5").should.not.be.ok;
iz.decimal('5').should.not.be.ok;
iz.decimal('5.5.5').should.not.be.ok;
iz.decimal({}).should.not.be.ok;

@@ -138,6 +138,6 @@ iz.decimal(function () {}).should.not.be.ok;

it("can validate email address", function () {
iz.email("bob@bob").should.be.ok;
iz.email("bob@bob.com").should.be.ok;
iz.email("bob").should.not.be.ok;
it('can validate email address', function () {
iz.email('bob@bob').should.be.ok;
iz.email('bob@bob.com').should.be.ok;
iz.email('bob').should.not.be.ok;
iz.email({}).should.not.be.ok;

@@ -152,3 +152,3 @@ iz.email(function () {}).should.not.be.ok;

it("can validate that something is empty", function () {
it('can validate that something is empty', function () {
iz.empty([]).should.be.ok;

@@ -160,3 +160,3 @@ iz.empty({}).should.be.ok;

iz.empty({bob: true}).should.not.be.ok;
iz.empty(["hi"]).should.not.be.ok;
iz.empty(['hi']).should.not.be.ok;

@@ -167,5 +167,5 @@ iz.empty(null).should.be.ok;

it("can validate that 2 things are strictly equal", function () {
it('can validate that 2 things are strictly equal', function () {
var obj1 = {
bob: "cheese",
bob: 'cheese',
equals : function(obj2) {

@@ -180,3 +180,3 @@ if (this.bob === obj2.bob) {

obj2 = {
bob: "cheese",
bob: 'cheese',
equals : function () {}

@@ -186,10 +186,10 @@ },

obj3 = {
bob: "cheese"
bob: 'cheese'
},
obj4 = {
bob: "pizza"
bob: 'pizza'
};
iz.equal("bob", "bob").should.be.ok;
iz.equal('bob', 'bob').should.be.ok;
iz.equal({},{}).should.be.ok;
iz.equal({},{"bob": true}).should.be.ok;
iz.equal({},{'bob': true}).should.be.ok;
iz.equal(obj1, obj2).should.be.ok;

@@ -200,11 +200,11 @@ iz.equal(obj1, obj3).should.be.ok;

it("can validate that an object is an extension of another object", function () {
iz.extension({},"5").should.not.be.ok;
it('can validate that an object is an extension of another object', function () {
iz.extension({},'5').should.not.be.ok;
iz.extension({
bob: 10,
something: "hi",
somethingElse: "bye"
something: 'hi',
somethingElse: 'bye'
},{
bob: "912dfinn",
something: "yes!"
bob: '912dfinn',
something: 'yes!'
}).should.be.ok;

@@ -214,18 +214,18 @@ iz.extension([],[]).should.be.ok;

bob: 10,
something: "hi"
something: 'hi'
},{
bob: "912dfinn",
something: "yes!",
somethingElse: "bye"
bob: '912dfinn',
something: 'yes!',
somethingElse: 'bye'
}).should.not.be.ok;
iz.extension([],["hello"]).should.not.be.ok;
iz.extension([],['hello']).should.not.be.ok;
});
it("can validate that a file extension is valid", function () {
iz.fileExtension("apple_pie.pizza", ["pizza"]).should.be.ok;
iz.fileExtension("hello.png", ["png"]).should.be.ok;
iz.fileExtension("hello.PNG", ["png"]).should.be.ok;
iz.fileExtension("hello.png", ["PNG"]).should.not.be.ok;
iz.fileExtension("hello.png", [".png"]).should.not.be.ok;
iz.fileExtension("hello.mp3", ["png"]).should.not.be.ok;
it('can validate that a file extension is valid', function () {
iz.fileExtension('apple_pie.pizza', ['pizza']).should.be.ok;
iz.fileExtension('hello.png', ['png']).should.be.ok;
iz.fileExtension('hello.PNG', ['png']).should.be.ok;
iz.fileExtension('hello.png', ['PNG']).should.not.be.ok;
iz.fileExtension('hello.png', ['.png']).should.not.be.ok;
iz.fileExtension('hello.mp3', ['png']).should.not.be.ok;
iz.fileExtension({},{}).should.not.be.ok;

@@ -237,5 +237,5 @@

it("can validate audio file extensions", function () {
iz.fileExtensionAudio("apple.mp3").should.be.ok;
iz.fileExtensionAudio("apple.png").should.not.be.ok;
it('can validate audio file extensions', function () {
iz.fileExtensionAudio('apple.mp3').should.be.ok;
iz.fileExtensionAudio('apple.png').should.not.be.ok;

@@ -246,5 +246,5 @@ iz.fileExtensionAudio(null).should.be.ok;

it("can validate image file extensions", function () {
iz.fileExtensionImage("apple.png").should.be.ok;
iz.fileExtensionImage("apple.mp3").should.not.be.ok;
it('can validate image file extensions', function () {
iz.fileExtensionImage('apple.png').should.be.ok;
iz.fileExtensionImage('apple.mp3').should.not.be.ok;

@@ -255,5 +255,5 @@ iz.fileExtensionImage(null).should.be.ok;

it("can validate video file extensions", function () {
iz.fileExtensionVideo("apple.mp4").should.be.ok;
iz.fileExtensionVideo("apple.mp3").should.not.be.ok;
it('can validate video file extensions', function () {
iz.fileExtensionVideo('apple.mp4').should.be.ok;
iz.fileExtensionVideo('apple.mp3').should.not.be.ok;

@@ -264,5 +264,5 @@ iz.fileExtensionVideo(null).should.be.ok;

it("can tell if something is in an array", function () {
iz.inArray("tofu", ["pizza","chicken","tofu","turkey"]).should.be.ok;
iz.inArray("lizard", ["pizza","chicken","tofu","turkey"]).should.not.be.ok;
it('can tell if something is in an array', function () {
iz.inArray('tofu', ['pizza','chicken','tofu','turkey']).should.be.ok;
iz.inArray('lizard', ['pizza','chicken','tofu','turkey']).should.not.be.ok;
iz.inArray(5,6).should.not.be.ok;

@@ -273,11 +273,11 @@ iz.inArray({},[]).should.not.be.ok;

it("can validate integers", function () {
iz.int("1000").should.be.ok;
it('can validate integers', function () {
iz.int('1000').should.be.ok;
iz.int(1000).should.be.ok;
iz.int(999).should.be.ok;
iz.int("11.0", true).should.be.ok;
iz.int('11.0', true).should.be.ok;
iz.int("11.0").should.not.be.ok;
iz.int('11.0').should.not.be.ok;
iz.int(11.2).should.not.be.ok;
iz.int("bob").should.not.be.ok;
iz.int('bob').should.not.be.ok;
iz.int({}).should.not.be.ok;

@@ -291,17 +291,17 @@ iz.int([]).should.not.be.ok;

it("can validate IPv4, IPv6 and host names", function () {
iz.ip("pizza").should.be.ok;
it('can validate IPv4, IPv6 and host names', function () {
iz.ip('pizza').should.be.ok;
//ipv6
iz.ip("3ffe:1900:4545:3:200:f8ff:fe21:67cf").should.be.ok;
iz.ip("fe80:0:0:0:200:f8ff:fe21:67cf").should.be.ok;
iz.ip("fe80::200:f8ff:fe21:67cf").should.be.ok;
iz.ip('3ffe:1900:4545:3:200:f8ff:fe21:67cf').should.be.ok;
iz.ip('fe80:0:0:0:200:f8ff:fe21:67cf').should.be.ok;
iz.ip('fe80::200:f8ff:fe21:67cf').should.be.ok;
//ipv4
iz.ip("0.0.0.0").should.be.ok;
iz.ip("192.0.2.235").should.be.ok;
iz.ip('0.0.0.0').should.be.ok;
iz.ip('192.0.2.235').should.be.ok;
//technically valid (citing wikipedia), but doesn't pass, but I don't think it is expected:
iz.ip("0xC0.0x00.0x02.0xEB").should.not.be.ok;
iz.ip("0300.0000.0002.0353").should.not.be.ok;
iz.ip("0xC00002EB").should.not.be.ok;
iz.ip("3221226219").should.not.be.ok;
iz.ip("030000001353").should.not.be.ok;
iz.ip('0xC0.0x00.0x02.0xEB').should.not.be.ok;
iz.ip('0300.0000.0002.0353').should.not.be.ok;
iz.ip('0xC00002EB').should.not.be.ok;
iz.ip('3221226219').should.not.be.ok;
iz.ip('030000001353').should.not.be.ok;

@@ -312,8 +312,8 @@ iz.ip(null).should.be.ok;

it("can require a string to have some min length", function () {
iz.minLength("Pizza", 5).should.be.ok;
iz.minLength("pizza", 4).should.be.ok;
iz.minLength("pizza", 6).should.not.be.ok;
it('can require a string to have some min length', function () {
iz.minLength('Pizza', 5).should.be.ok;
iz.minLength('pizza', 4).should.be.ok;
iz.minLength('pizza', 6).should.not.be.ok;
iz.minLength({}, 5).should.not.be.ok;
iz.minLength("lizard", {}).should.not.be.ok;
iz.minLength('lizard', {}).should.not.be.ok;

@@ -324,3 +324,3 @@ iz.minLength(null).should.be.ok;

it("can require an array to have some min length", function () {
it('can require an array to have some min length', function () {
iz.minLength([1, 2, 3, 4, 5, 6], 6).should.be.ok;

@@ -334,8 +334,8 @@ iz.minLength([1, 2, 3, 4, 5, 6], 5).should.be.ok;

it("can require a string to have some max length", function () {
iz.maxLength("Pizza", 5).should.be.ok;
iz.maxLength("pizza", 6).should.be.ok;
iz.maxLength("pizza", 4).should.not.be.ok;
it('can require a string to have some max length', function () {
iz.maxLength('Pizza', 5).should.be.ok;
iz.maxLength('pizza', 6).should.be.ok;
iz.maxLength('pizza', 4).should.not.be.ok;
iz.maxLength({}, 5).should.not.be.ok;
iz.maxLength("lizard", {}).should.not.be.ok;
iz.maxLength('lizard', {}).should.not.be.ok;

@@ -346,3 +346,3 @@ iz.maxLength(null).should.be.ok;

it("can require an array to have some max length", function () {
it('can require an array to have some max length', function () {
iz.maxLength([1, 2, 3, 4, 5, 6], 6).should.be.ok;

@@ -356,3 +356,3 @@ iz.maxLength([1, 2, 3, 4, 5, 6], 7).should.be.ok;

it("can tell if a number is multiple of another number", function () {
it('can tell if a number is multiple of another number', function () {
iz.multiple(10, 5).should.be.ok;

@@ -367,8 +367,8 @@ iz.multiple(10, 2).should.be.ok;

it("can tell if something is a number", function () {
it('can tell if something is a number', function () {
iz.number({}).should.not.be.ok;
iz.number("5").should.be.ok;
iz.number("5.32342").should.be.ok;
iz.number('5').should.be.ok;
iz.number('5.32342').should.be.ok;
iz.number(23123).should.be.ok;
iz.number("bob").should.not.be.ok;
iz.number('bob').should.not.be.ok;

@@ -379,3 +379,3 @@ iz.number(null).should.be.ok;

it("can tell if the name of an object is equal to some string", function () {
it('can tell if the name of an object is equal to some string', function () {
var obj = {};

@@ -385,5 +385,5 @@

iz.ofType(new Car(), "Car").should.be.ok;
iz.ofType(new Car(), "Object").should.not.be.ok;
iz.ofType(obj, "Object").should.be.ok;
iz.ofType(new Car(), 'Car').should.be.ok;
iz.ofType(new Car(), 'Object').should.not.be.ok;
iz.ofType(obj, 'Object').should.be.ok;

@@ -394,16 +394,16 @@ iz.ofType(null).should.be.ok;

it("can validate a north american phone number", function () {
it('can validate a north american phone number', function () {
iz.phone(1231231).should.not.be.ok;
iz.phone({}).should.not.be.ok;
iz.phone("1-415-222-2222").should.be.ok;
iz.phone("1.415.555.5555 extension 422").should.be.ok;
iz.phone("1415.323.3242 extension x422").should.be.ok;
iz.phone("11231234567").should.be.ok;
iz.phone('1-415-222-2222').should.be.ok;
iz.phone('1.415.555.5555 extension 422').should.be.ok;
iz.phone('1415.323.3242 extension x422').should.be.ok;
iz.phone('11231234567').should.be.ok;
iz.phone("123").should.not.be.ok;
iz.phone("123456789012").should.not.be.ok;
iz.phone('123').should.not.be.ok;
iz.phone('123456789012').should.not.be.ok;
iz.phone("1234567890").should.be.ok;
iz.phone("12345678901").should.be.ok;
iz.phone('1234567890').should.be.ok;
iz.phone('12345678901').should.be.ok;

@@ -414,11 +414,11 @@ iz.phone(null).should.be.ok;

it("can validate a US zip-code", function () {
it('can validate a US zip-code', function () {
iz.postal(1231231).should.not.be.ok;
iz.postal({}).should.not.be.ok;
iz.postal("94117").should.be.ok;
iz.postal("94117 3333").should.be.ok;
iz.postal("94117-3333").should.be.ok;
iz.postal("94117 33333").should.not.be.ok;
iz.postal("9411").should.not.be.ok;
iz.postal('94117').should.be.ok;
iz.postal('94117 3333').should.be.ok;
iz.postal('94117-3333').should.be.ok;
iz.postal('94117 33333').should.not.be.ok;
iz.postal('9411').should.not.be.ok;

@@ -429,11 +429,11 @@ iz.postal(null).should.be.ok;

it("can validate a US SSN", function () {
it('can validate a US SSN', function () {
iz.ssn(123).should.not.be.ok;
iz.ssn({}).should.not.be.ok;
iz.ssn("123456789").should.be.ok;
iz.ssn("123-45-6789").should.be.ok;
iz.ssn('123456789').should.be.ok;
iz.ssn('123-45-6789').should.be.ok;
iz.ssn("1234567890").should.not.ok;
iz.ssn("123-45-678").should.not.be.ok;
iz.ssn('1234567890').should.not.ok;
iz.ssn('123-45-678').should.not.be.ok;

@@ -444,6 +444,6 @@ iz.ssn(null).should.be.ok;

it("can validate required", function() {
it('can validate required', function() {
iz.required(null).should.not.be.ok;
iz.required(undefined).should.not.be.ok;
iz.required("").should.not.be.ok;
iz.required('').should.not.be.ok;
iz.required({}).should.be.ok;

@@ -450,0 +450,0 @@ iz.required(function () {}).should.be.ok;

@@ -1,3 +0,5 @@

/*global module, exports, window*/
/*global module, exports */
var iz = require('./iz');
(function () {

@@ -8,9 +10,63 @@ 'use strict';

function Are(rules) {
var self = this;
self._rules = rules;
var self = this,
currentRule,
rule,
errors,
key;
self._fields = {};
for (key in rules) {
if (!rules.hasOwnProperty(key)) {
continue;
}
// if is an iz object just add rule directly, if not assemble an iz object
if (typeof rules[key].revalidate !== 'undefined') {
self._fields[key] = rules[key];
} else {
errors = {};
// make errors dictionary
for (rule in rules[key]) {
if (!rules[key].hasOwnProperty(rule)) {
continue;
}
if (rules[key][rule].error) {
errors[rules[key][rule].rule] = rules[key][rule].error;
}
}
currentRule = iz(0, errors);
// call rule
for (rule in rules[key]) {
if (!rules[key].hasOwnProperty(rule)) {
continue;
}
// handle 'not_'
if (rules[key][rule].rule.indexOf('not_') > -1) {
currentRule.not();
}
currentRule[rules[key][rule].rule.replace('not_', '')].apply(
currentRule,
rules[key][rule].args || []
);
}
self._fields[key] = currentRule;
}
}
this.valid = function() {
for(var key in self._rules) {
self._rules[key].revalidate();
if (!self._rules[key].valid) {
for (var key in self._fields) {
if (!self._fields[key].hasOwnProperty(key)) {
continue;
}
self._fields[key].revalidate();
if (!self._fields[key].valid) {
return false;

@@ -22,2 +78,31 @@ }

};
this.validFor = function(values) {
var field,
i = 0,
fieldKeys,
currentValue;
for (field in self._fields) {
if (!self._fields.hasOwnProperty(field)) {
continue;
}
fieldKeys = field.split('.');
currentValue = values[fieldKeys[0]];
// account for chained field names
for (i = 1; i < fieldKeys.length; i++) {
currentValue = currentValue[fieldKeys[i]];
}
self._fields[field].setValue(currentValue);
if (!self._fields[field].valid) {
return false;
}
}
return true;
};
}

@@ -24,0 +109,0 @@

/*global module, exports, require */
var validators = require('./validators');
(function () {
'use strict';
var iz,
validators = require('./validators');
var iz;
/**

@@ -16,3 +17,3 @@ * @param value

if (typeof error_messages === "object") {
if (typeof error_messages === 'object') {
this.error_messages = error_messages;

@@ -32,6 +33,2 @@ } else {

function revalidate() {
var args = [],
i = 0;
// reset
self.errors = [];

@@ -95,8 +92,8 @@ self.valid = true;

//change error message based on not and if an error message is specified
if (!this._not && typeof this.error_messages[fn] !== "undefined") {
if (!this._not && typeof this.error_messages[fn] !== 'undefined') {
this.errors.push(this.error_messages[fn]);
} else if (this._not && typeof this.error_messages["not_" + fn] !== "undefined") {
this.errors.push(this.error_messages["not_" + fn]);
} else if (this._not && typeof this.error_messages['not_' + fn] !== 'undefined') {
this.errors.push(this.error_messages['not_' + fn]);
} else if (this._not) {
this.errors.push("Not " + fn);
this.errors.push('Not ' + fn);
} else {

@@ -103,0 +100,0 @@ this.errors.push(fn);

@@ -0,10 +1,13 @@

/*global module, exports */
(function() {
'use strict';
var validators = {};
function iz_alphaNumeric(value) {
function izAlphaNumeric(value) {
return (/^[a-z0-9]+$/i).test(value);
}
function iz_number(val) {
if ((typeof val === "string" || typeof val === "number") && !isNaN(val % 1)) {
function izNumber(val) {
if ((typeof val === 'string' || typeof val === 'number') && !isNaN(val % 1)) {
return true;

@@ -15,6 +18,6 @@ }

function iz_between(val, start, end) {
if ((typeof val === "object" || typeof val === "function") ||
(typeof start === "object" || typeof start === "function") ||
(typeof end === "object" || typeof end === "function")) {
function izBetween(val, start, end) {
if ((typeof val === 'object' || typeof val === 'function') ||
(typeof start === 'object' || typeof start === 'function') ||
(typeof end === 'object' || typeof end === 'function')) {
return false;

@@ -29,4 +32,4 @@ }

function iz_boolean(value) {
if (typeof value === "boolean" || (typeof value === "number" && (value === 0 || value === 1))) {
function izBoolean(value) {
if (typeof value === 'boolean' || (typeof value === 'number' && (value === 0 || value === 1))) {
return true;

@@ -37,4 +40,4 @@ }

function iz_int(value, allowDecimal) {
if (typeof allowDecimal !== "boolean") {
function izInt(value, allowDecimal) {
if (typeof allowDecimal !== 'boolean') {
allowDecimal = false;

@@ -45,3 +48,3 @@ }

return (/^\s*(\+|-)?\d+\s*$/).test(value);
} else if (iz_number(value) && value % 1 === 0) {
} else if (izNumber(value) && value % 1 === 0) {
return true;

@@ -75,3 +78,3 @@ }

*/
function iz_getObjectClass(obj) {
function izGetObjectClass(obj) {
if (obj && obj.constructor && obj.constructor.toString) {

@@ -88,9 +91,9 @@ var arr = obj.constructor.toString().match(/function\s*(\w+)/);

function iz_cc(value) {
if (typeof value !== "string" && typeof value !== "number") {
function izCc(value) {
if (typeof value !== 'string' && typeof value !== 'number') {
return false;
}
value = value.replace(/[ \-]/g, ""); // normalizing
if (iz_int(value)) {
value = value.replace(/[ \-]/g, ''); // normalizing
if (izInt(value)) {
return luhnChk(value);

@@ -107,9 +110,9 @@ }

*/
function iz_date(value) {
return iz_getObjectClass(value) === "Date" ||
new Date(value).toString() !== "Invalid Date" || !isNaN(new Date(value));
function izDate(value) {
return izGetObjectClass(value) === 'Date' ||
new Date(value).toString() !== 'Invalid Date' || !isNaN(new Date(value));
}
function iz_decimal(value) {
return iz_number(value) && Math.floor(value) != value;
function izDecimal(value) {
return izNumber(value) && !izInt(value, false);
}

@@ -125,4 +128,4 @@

*/
function iz_email(value) {
return !(typeof value !== "string") && (/\S+@\S+/).test(value);
function izEmail(value) {
return !(typeof value !== 'string') && (/\S+@\S+/).test(value);
}

@@ -136,9 +139,9 @@

*/
function iz_empty(value) {
function izEmpty(value) {
var type = typeof value,
key;
//arrays and objects with length properties
if(value.hasOwnProperty("length") && type !== "function" && value.length > 0) {
if(value.hasOwnProperty('length') && type !== 'function' && value.length > 0) {
return false;
} else if(type === "function" || type === "object") {
} else if(type === 'function' || type === 'object') {
for (key in value) {

@@ -155,5 +158,5 @@ if(value.hasOwnProperty(key)) {

function iz_blank(value) {
if (typeof value === "string") {
return iz_empty(value);
function izBlank(value) {
if (typeof value === 'string') {
return izEmpty(value);
}

@@ -170,3 +173,3 @@

*/
function iz_equal(value, value2) {
function izEqual(value, value2) {
var valueType = typeof value,

@@ -176,4 +179,4 @@ value2Type = typeof value2,

if ((valueType === "object" || valueType === "function") && typeof value.equals === "function") {
if ((value2Type === "object" || value2Type === "function")) {
if ((valueType === 'object' || valueType === 'function') && typeof value.equals === 'function') {
if ((value2Type === 'object' || value2Type === 'function')) {
//value2 does not need the equals method, if an exception is thrown here that is the implementor

@@ -183,7 +186,7 @@ //catching it returning false might result in a bug that is hard to track

}
} else if(valueType === "object" || valueType === "function") {
} else if(valueType === 'object' || valueType === 'function') {
for(key in value) {
if (value.hasOwnProperty(key) && !value2.hasOwnProperty(key) && key !== "equals") {
if (value.hasOwnProperty(key) && !value2.hasOwnProperty(key) && key !== 'equals') {
//if property is an object then recursively check
if (typeof value[key] === "object" || typeof value[key] === "function" && !iz_equal(value[key], value2[key])) {
if (typeof value[key] === 'object' || typeof value[key] === 'function' && !izEqual(value[key], value2[key])) {
return false;

@@ -207,5 +210,5 @@ } else if (value[key] !== value2[key]) { //if not object or function

*/
function iz_extension(obj1, obj2) {
function izExtension(obj1, obj2) {
var key;
if (typeof obj1 !== "object" || typeof obj2 !== "object") {
if (typeof obj1 !== 'object' || typeof obj2 !== 'object') {
return false;

@@ -215,3 +218,3 @@ }

for (key in obj2) {
if (obj2.hasOwnProperty(key) && typeof obj1[key] === "undefined") {
if (obj2.hasOwnProperty(key) && typeof obj1[key] === 'undefined') {
return false;

@@ -228,11 +231,11 @@ }

*/
function iz_fileExtension(value, validExtensions) {
function izFileExtension(value, validExtensions) {
var ext;
if (typeof validExtensions !== "object" ||
typeof validExtensions.indexOf === "undefined" || typeof value !== "string") {
if (typeof validExtensions !== 'object' ||
typeof validExtensions.indexOf === 'undefined' || typeof value !== 'string') {
return false;
}
ext = value.split(".").pop().toLowerCase(); //split by '.' and get me the last thing, then lowercase it
ext = value.split('.').pop().toLowerCase(); //split by '.' and get me the last thing, then lowercase it
if (validExtensions.indexOf(ext) !== -1) {

@@ -244,19 +247,19 @@ return true;

function iz_fileExtensionAudio(value) {
var validExtensions = ["mp3", "ogg", "aac", "wav"];
return iz_fileExtension(value, validExtensions);
function izFileExtensionAudio(value) {
var validExtensions = ['mp3', 'ogg', 'aac', 'wav'];
return izFileExtension(value, validExtensions);
}
function iz_fileExtensionImage(value) {
var validExtensions = ["gif", "png", "jpeg", "jpg", "svg", "bmp"];
return iz_fileExtension(value, validExtensions);
function izFileExtensionImage(value) {
var validExtensions = ['gif', 'png', 'jpeg', 'jpg', 'svg', 'bmp'];
return izFileExtension(value, validExtensions);
}
function iz_fileExtensionVideo(value) {
var validExtensions = ["mp4", "ogv", "m4v", "mov", "avi"];
return iz_fileExtension(value, validExtensions);
function izFileExtensionVideo(value) {
var validExtensions = ['mp4', 'ogv', 'm4v', 'mov', 'avi'];
return izFileExtension(value, validExtensions);
}
function iz_inArray(value, arr) {
if (typeof arr !== "object" || typeof arr.indexOf === "undefined") {
function izInArray(value, arr) {
if (typeof arr !== 'object' || typeof arr.indexOf === 'undefined') {
return false;

@@ -277,3 +280,3 @@ }

*/
function iz_ip(str) {
function izIp(str) {
var re = (/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$|^(?:(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-fA-F]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,1}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,2}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:(?:[0-9a-fA-F]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,3}(?:(?:[0-9a-fA-F]{1,4})))?::(?:(?:[0-9a-fA-F]{1,4})):)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,4}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,5}(?:(?:[0-9a-fA-F]{1,4})))?::)(?:(?:[0-9a-fA-F]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-fA-F]{1,4})):){0,6}(?:(?:[0-9a-fA-F]{1,4})))?::))))$/);

@@ -283,5 +286,5 @@ return re.test(str);

function iz_minLength(val, len) {
if ((typeof val === "string" || typeof val === "object") &&
typeof val.length !== "undefined" && iz_int(len) && val.length >= len) {
function izMinLength(val, len) {
if ((typeof val === 'string' || typeof val === 'object') &&
typeof val.length !== 'undefined' && izInt(len) && val.length >= len) {
return true;

@@ -293,5 +296,5 @@ }

function iz_maxLength(val, len) {
if ((typeof val === "string" || typeof val === "object") &&
typeof val.length !== "undefined" && iz_int(len) && val.length <= len) {
function izMaxLength(val, len) {
if ((typeof val === 'string' || typeof val === 'object') &&
typeof val.length !== 'undefined' && izInt(len) && val.length <= len) {
return true;

@@ -303,4 +306,4 @@ }

function iz_multiple(num, multiple) {
if (typeof num !== "number" || typeof multiple !== "number") {
function izMultiple(num, multiple) {
if (typeof num !== 'number' || typeof multiple !== 'number') {
return false;

@@ -315,6 +318,6 @@ }

function iz_ofType(obj, type) {
if (typeof obj === "object" && typeof obj.length === "undefined" && typeof type === "string") {
function izOfType(obj, type) {
if (typeof obj === 'object' && typeof obj.length === 'undefined' && typeof type === 'string') {
//is truly an object
if (iz_getObjectClass(obj) === type) {
if (izGetObjectClass(obj) === type) {
return true;

@@ -326,12 +329,12 @@ }

function iz_phone(str) {
var cleanedStr = "",
function izPhone(str) {
var cleanedStr = '',
numbers = [];
if (typeof str === "string") {
if (typeof str === 'string') {
cleanedStr = str.replace(/[^x0-9]/g, '');
numbers = cleanedStr.split("x");
numbers = cleanedStr.split('x');
//first and last array elements are numbers, this allows for multiple x's between the phone number and extension (if exists)
if (numbers.length > 0 && iz_int(numbers[0]) && // has at least 1 value in the array and it is an integer
if (numbers.length > 0 && izInt(numbers[0]) && // has at least 1 value in the array and it is an integer
(numbers[0].length === 10 || numbers[0].length === 11) && // it has an extension with or without country code
iz_int(numbers.pop())) { //if it is has an extension it is a valid number
izInt(numbers.pop())) { //if it is has an extension it is a valid number
return true;

@@ -343,9 +346,9 @@ }

function iz_postal(str) {
var cleanedStr = "";
if (typeof str === "string") {
function izPostal(str) {
var cleanedStr = '';
if (typeof str === 'string') {
//removing everything but numbers
cleanedStr = str.replace(/[^0-9]/g, '');
//is either a 5 or 9 digit zip code...
if (iz_int(cleanedStr) &&
if (izInt(cleanedStr) &&
(cleanedStr.length === 5 || cleanedStr.length === 9)) {

@@ -358,8 +361,8 @@ return true;

function iz_ssn(str) {
var cleanedStr = "";
if (typeof str === "string") {
function izSsn(str) {
var cleanedStr = '';
if (typeof str === 'string') {
cleanedStr = str.replace(/[^0-9]/g, '');
//There are varying rules depending on date of issuance. I will say that having 9 digits is all that is needed for now.
if (iz_int(cleanedStr) && (cleanedStr.length === 9)) {
if (izInt(cleanedStr) && (cleanedStr.length === 9)) {
return true;

@@ -371,3 +374,3 @@ }

function iz_required(obj) {
function izRequired(obj) {
return obj !== undefined && obj !== null && obj !== '';

@@ -377,5 +380,5 @@ }

function iz_required_or(validator) {
function izRequiredOr(validator) {
return function(val) {
return !iz_required(val) || validator.apply(this, Array.prototype.slice.call(arguments));
return !izRequired(val) || validator.apply(this, Array.prototype.slice.call(arguments));
};

@@ -385,29 +388,29 @@ }

//Expose some methods, this is done to preserve function names in all browsers
validators.alphaNumeric = iz_required_or(iz_alphaNumeric);
validators.between = iz_required_or(iz_between);
validators.blank = iz_required_or(iz_blank);
validators.boolean = iz_required_or(iz_boolean);
validators.cc = iz_required_or(iz_cc);
validators.date = iz_required_or(iz_date);
validators.decimal = iz_required_or(iz_decimal);
validators.email = iz_required_or(iz_email);
validators.empty = iz_required_or(iz_empty);
validators.equal = iz_required_or(iz_equal);
validators.extension = iz_extension;
validators.fileExtension = iz_required_or(iz_fileExtension);
validators.fileExtensionAudio = iz_required_or(iz_fileExtensionAudio);
validators.fileExtensionImage = iz_required_or(iz_fileExtensionImage);
validators.fileExtensionVideo = iz_required_or(iz_fileExtensionVideo);
validators.inArray = iz_inArray;
validators.int = iz_required_or(iz_int);
validators.ip = iz_required_or(iz_ip);
validators.minLength = iz_required_or(iz_minLength);
validators.maxLength = iz_required_or(iz_maxLength);
validators.multiple = iz_required_or(iz_multiple);
validators.number = iz_required_or(iz_number);
validators.ofType = iz_required_or(iz_ofType);
validators.phone = iz_required_or(iz_phone);
validators.postal = iz_required_or(iz_postal);
validators.required = iz_required;
validators.ssn = iz_required_or(iz_ssn);
validators.alphaNumeric = izRequiredOr(izAlphaNumeric);
validators.between = izRequiredOr(izBetween);
validators.blank = izRequiredOr(izBlank);
validators.boolean = izRequiredOr(izBoolean);
validators.cc = izRequiredOr(izCc);
validators.date = izRequiredOr(izDate);
validators.decimal = izRequiredOr(izDecimal);
validators.email = izRequiredOr(izEmail);
validators.empty = izRequiredOr(izEmpty);
validators.equal = izRequiredOr(izEqual);
validators.extension = izExtension;
validators.fileExtension = izRequiredOr(izFileExtension);
validators.fileExtensionAudio = izRequiredOr(izFileExtensionAudio);
validators.fileExtensionImage = izRequiredOr(izFileExtensionImage);
validators.fileExtensionVideo = izRequiredOr(izFileExtensionVideo);
validators.inArray = izInArray;
validators.int = izRequiredOr(izInt);
validators.ip = izRequiredOr(izIp);
validators.minLength = izRequiredOr(izMinLength);
validators.maxLength = izRequiredOr(izMaxLength);
validators.multiple = izRequiredOr(izMultiple);
validators.number = izRequiredOr(izNumber);
validators.ofType = izRequiredOr(izOfType);
validators.phone = izRequiredOr(izPhone);
validators.postal = izRequiredOr(izPostal);
validators.required = izRequired;
validators.ssn = izRequiredOr(izSsn);

@@ -414,0 +417,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc