New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

validate.js

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validate.js - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

RELEASING.txt

2

bower.json
{
"name": "validate.js",
"main": ["validate.js", "validate.min.js"],
"version": "0.2.0",
"version": "0.3.0",
"ignore": [

@@ -6,0 +6,0 @@ "**/.*",

@@ -12,3 +12,4 @@ module.exports = function(grunt) {

ignores: ['specs/vendor/**/*.js'],
laxcomma: true
laxcomma: true,
curly: true
}

@@ -19,3 +20,4 @@ },

options: {
laxcomma: true
laxcomma: true,
curly: true
}

@@ -22,0 +24,0 @@ }

{
"name": "validate.js",
"version": "0.2.0",
"version": "0.3.0",
"author": "Nicklas Ansman <nicklas@ansman.se>",

@@ -5,0 +5,0 @@ "description": "Declarative validations for JavaScript",

@@ -12,3 +12,5 @@ beforeEach(function() {

toHaveItems: function(items) {
if (this.actual.length != items.length) return false;
if (this.actual.length != items.length) {
return false;
}
return this.actual.every(function(a) {

@@ -15,0 +17,0 @@ return items.some(function(item) {

@@ -48,3 +48,3 @@ describe("validate.async", function() {

it.promise("handles validators returning an promise", function() {
it.promise("handles validators returning a promise", function() {
var c = {

@@ -89,3 +89,2 @@ name: {

expect(validate.tryRequire).toHaveBeenCalledWith("q");
console.log(validate.tryRequire.calls);
});

@@ -103,4 +102,7 @@

spyOn(validate, "tryRequire").andCallFake(function(module) {
if (module === "es6-promise") return {Promise: store.Promise};
else return null;
if (module === "es6-promise") {
return {Promise: store.Promise};
} else {
return null;
}
});

@@ -120,4 +122,7 @@ expect(validate.Promise(function() {})).toBeAPromise();

spyOn(validate, "tryRequire").andCallFake(function(module) {
if (module === "rsvp") return store.RSVP;
else return null;
if (module === "rsvp") {
return store.RSVP;
} else {
return null;
}
});

@@ -138,4 +143,7 @@ expect(validate.Promise(function() {})).toBeAPromise();

console.log(module);
if (module === "when") return store.when;
else return null;
if (module === "when") {
return store.when;
} else {
return null;
}
});

@@ -155,4 +163,7 @@ expect(validate.Promise(function() {})).toBeAPromise();

spyOn(validate, "tryRequire").andCallFake(function(module) {
if (module === "q") return store.Q;
else return null;
if (module === "q") {
return store.Q;
} else {
return null;
}
});

@@ -159,0 +170,0 @@ expect(validate.Promise(function() {})).toBeAPromise();

@@ -141,2 +141,14 @@ describe("validate", function() {

});
it("replaces periods with spaces if no space follows", function() {
expect(validate.prettify("foo.bar.baz")).toEqual("foo bar baz");
expect(validate.prettify("foo. bar")).toEqual("foo. bar");
expect(validate.prettify("foo .bar")).toEqual("foo .bar");
expect(validate.prettify("foo.bar.")).toEqual("foo bar.");
});
it("replaces backslashes with nothing", function() {
expect(validate.prettify("foo\\.bar\\.baz")).toEqual("foo bar baz");
expect(validate.prettify("foo\\\\.bar")).toEqual("foo bar");
});
});

@@ -445,2 +457,70 @@

});
describe("getDeepObjectValue", function() {
it("supports multiple keys separated using a period", function() {
var attributes = {
foo: {
bar: {
baz: 3
}
}
};
expect(validate.getDeepObjectValue(attributes, "foo.bar.baz")).toBe(3);
});
it("returns undefined if any key is not found", function() {
var attributes = {
foo: {
bar: {
baz: 3
}
}
};
expect(validate.getDeepObjectValue(attributes, "bar.foo")).toBe(undefined);
expect(validate.getDeepObjectValue(attributes, "foo.baz")).toBe(undefined);
});
it("handles the object being non objects", function() {
expect(validate.getDeepObjectValue(null, "foo")).toBe(undefined);
expect(validate.getDeepObjectValue("foo", "foo")).toBe(undefined);
expect(validate.getDeepObjectValue(3, "foo")).toBe(undefined);
expect(validate.getDeepObjectValue([], "foo")).toBe(undefined);
expect(validate.getDeepObjectValue(true, "foo")).toBe(undefined);
});
it("handles the keypath being non strings", function() {
expect(validate.getDeepObjectValue({}, null)).toBe(undefined);
expect(validate.getDeepObjectValue({}, 3)).toBe(undefined);
expect(validate.getDeepObjectValue({}, {})).toBe(undefined);
expect(validate.getDeepObjectValue({}, [])).toBe(undefined);
expect(validate.getDeepObjectValue({}, true)).toBe(undefined);
});
it("handles escapes properly", function() {
var attributes = {
"foo.bar": {
baz: 3
},
"foo\\": {
bar: {
baz: 5
}
}
};
expect(validate.getDeepObjectValue(attributes, "foo.bar.baz"))
.toBe(undefined);
expect(validate.getDeepObjectValue(attributes, "foo\\.bar.baz"))
.toBe(3);
expect(validate.getDeepObjectValue(attributes, "foo\\\\.bar.baz"))
.toBe(5);
expect(validate.getDeepObjectValue(attributes, "\\foo\\\\.bar.baz"))
.toBe(5);
});
});
});

@@ -35,3 +35,9 @@ describe("validate", function() {

name: "Nicklas Ansman",
email: "nicklas@ansman.se"
email: "nicklas@ansman.se",
addresses: {
work: {
street: "Drottninggatan 98",
city: "Stockholm"
}
}
};

@@ -46,3 +52,10 @@ var constraints = {

fail2: true
}
},
"addresses.work.street": {
pass: true,
fail2: true,
},
"addresses.work.city": {
pass: true
},
};

@@ -57,2 +70,5 @@

"Email is simply not good enough"
],
"addresses.work.street": [
"Addresses work street is simply not good enough"
]

@@ -63,3 +79,4 @@ });

"Email must be a valid email address",
"Email is simply not good enough"
"Email is simply not good enough",
"Addresses work street is simply not good enough"
]);

@@ -105,3 +122,3 @@ });

attribute: "name",
error: ["foo", "bar"],
error: ["foo", "bar"]
}, {

@@ -197,2 +214,8 @@ attribute: "name",

});
describe("works with flatten: true and fullMessages: false", function() {
var constraints = {foo: {presence: true}}
, options = {flatten: true, fullMessages: false};
expect(validate({}, constraints, options)).toEqual(["can't be blank"]);
});
});
describe('validators.datetime', function() {
var datetime = validate.validators.datetime.bind(validate.validators.datetime);
var datetime = validate.validators.datetime.bind(validate.validators.datetime)
, XDate = window.XDate;
afterEach(function() {
window.XDate = XDate;
});
it("allows non defined values", function() {

@@ -12,18 +17,58 @@ expect(datetime(null, {})).not.toBeDefined();

it("returns the millis since epoch for valid strings", function() {
// 2013-10-25 00:00:00 UTC
expect(parse("2013-10-26", {})).toEqual(1382745600000);
it("throws and error if neither XDate or moment.js is found", function() {
expect(function() {
delete window.XDate;
spyOn(validate.tryRequire).andReturn(null);
parse("2014-09-02");
}).toThrow();
});
// 1000-01-01 00:00:00 UTC
expect(parse("1000-01-01", {})).toEqual(-30610224000000);
function runParseTestsForValidStrings() {
// 2013-10-25 00:00:00 UTC
expect(parse("2013-10-26", {})).toEqual(1382745600000);
// UTC
expect(parse("2013-10-26T10:35:24", {})).toEqual(1382783724000);
// PDT
expect(parse("2013-10-26T10:35:24-0700", {})).toEqual(1382808924000);
});
// 1000-01-01 00:00:00 UTC
expect(parse("1000-01-01", {})).toEqual(-30610224000000);
it("returns NaN for invalid dates", function() {
// UTC
expect(parse("2013-10-26T10:35:24", {})).toEqual(1382783724000);
// PDT
expect(parse("2013-10-26T10:35:24-0700", {})).toEqual(1382808924000);
}
function runNaNTests() {
expect(parse("foobar", {})).toBeNaN();
}
describe("with XDate", function() {
beforeEach(function() {
spyOn(validate, "tryRequire").andReturn(null);
});
it("returns the millis since epoch for valid strings", function() {
runParseTestsForValidStrings();
});
it("returns NaN for invalid dates", function() {
runNaNTests();
});
});
describe("with moment.js", function() {
beforeEach(function() {
window.XDate = undefined;
spyOn(moment, "utc").andCallThrough();
spyOn(validate, "tryRequire").andReturn(moment);
});
it("returns the millis since epoch for valid strings", function() {
runParseTestsForValidStrings();
expect(moment.utc).toHaveBeenCalled();
});
it("returns NaN for invalid dates", function() {
runNaNTests();
expect(moment.utc).toHaveBeenCalled();
});
});
});

@@ -34,16 +79,57 @@

it("formats as ISO8601 in errors", function() {
var expected = "2013-10-26T17:35:24Z";
function runDatetimeTest() {
var expected = "2013-10-26 17:35:24";
expect(format(1382808924000, {})).toBe(expected);
});
}
it("only includes the date part it dateOnly is set", function() {
function runDateTest() {
var expected = "2013-10-26";
expect(format(1382745600000, {dateOnly: true})).toBe(expected);
});
}
it("allows you to override the format string", function() {
function runOverrideTest(dateFormat) {
var expected = "10/26/13";
expect(format(1382808924000, {dateFormat: "MM/dd/yy"})).toBe(expected);
expect(format(1382808924000, {dateFormat: dateFormat})).toBe(expected);
}
describe("with XDate", function() {
beforeEach(function() {
spyOn(validate, "tryRequire").andReturn(null);
});
it("formats as ISO8601 in errors", function() {
runDatetimeTest();
});
it("only includes the date part it dateOnly is set", function() {
runDateTest();
});
it("allows you to override the format string", function() {
runOverrideTest("MM/dd/yy");
});
});
describe("with moment.js", function() {
beforeEach(function() {
window.XDate = undefined;
spyOn(moment, "utc").andCallThrough();
spyOn(validate, "tryRequire").andReturn(moment);
});
it("formats as ISO8601 in errors", function() {
runDatetimeTest();
expect(moment.utc).toHaveBeenCalled();
});
it("only includes the date part it dateOnly is set", function() {
runDateTest();
expect(moment.utc).toHaveBeenCalled();
});
it("allows you to override the format string", function() {
runOverrideTest("MM/DD/YY");
expect(moment.utc).toHaveBeenCalled();
});
});
});

@@ -83,3 +169,3 @@

, value = "2013-10-25 23:59:59"
, expected = ["must be no earlier than 2013-10-26T00:00:00Z"];
, expected = ["must be no earlier than 2013-10-26 00:00:00"];

@@ -118,3 +204,3 @@ expect(datetime(value, options)).toEqual(expected);

, value = "2013-10-26 00:00:01"
, expected = ["must be no later than 2013-10-26T00:00:00Z"];
, expected = ["must be no later than 2013-10-26 00:00:00"];

@@ -121,0 +207,0 @@ expect(datetime(value, options)).toEqual(expected);

@@ -17,2 +17,3 @@ describe('validators.email', function() {

expect(email('nicklas@ansman.se', {})).not.toBeDefined();
expect(email('NiCkLaS@AnSmAn.Se', {})).not.toBeDefined();
// Source: https://en.wikipedia.org/wiki/Email_address#Valid_email_addresses

@@ -19,0 +20,0 @@ expect(email('niceandsimple@example.com', {})).not.toBeDefined();

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

// Validate.js 0.2.0
// (c) 2013 Wrapp
// Validate.js 0.3.0
// (c) 2014 Wrapp
// Validate.js may be freely distributed under the MIT license.

@@ -24,4 +24,5 @@ // For all details and documentation:

for (validator in results[attr]) {
if (v.isPromise(results[attr][validator]))
if (v.isPromise(results[attr][validator])) {
throw new Error("Use validate.async if you want support for promises");
}
}

@@ -34,3 +35,2 @@ }

, root = this
, XDate = root.XDate
// Finds %{key} style patterns in the given string

@@ -45,3 +45,5 @@ , FORMAT_REGEXP = /%\{([^\}]+)\}/g;

[].slice.call(arguments, 1).forEach(function(source) {
for (var attr in source) obj[attr] = source[attr];
for (var attr in source) {
obj[attr] = source[attr];
}
});

@@ -67,3 +69,3 @@ return obj;

for (attr in constraints) {
value = attributes[attr];
value = v.getDeepObjectValue(attributes, attr);
validators = v.result(constraints[attr], value, attributes, attr);

@@ -85,3 +87,5 @@

validatorOptions = v.result(validatorOptions, value, attributes, attr);
if (!validatorOptions) continue;
if (!validatorOptions) {
continue;
}
results.push({

@@ -108,6 +112,9 @@ attribute: attr,

if (v.isString(error)) error = [error];
if (v.isString(error)) {
error = [error];
}
if (error)
if (error) {
errors[attribute] = (errors[attribute] || []).concat(error);
}
});

@@ -117,4 +124,5 @@

// them and short circuit when something is found.
for (var _ in errors)
for (var _ in errors) {
return v.fullMessages(errors, options);
}
},

@@ -133,4 +141,7 @@

var errors = v.processValidationResults(results);
if (errors) reject(errors);
else resolve();
if (errors) {
reject(errors);
} else {
resolve();
}
}).then(undefined, v.error);

@@ -149,3 +160,5 @@ });

// If this result isn't a promise skip it in the sequence.
if (!v.isPromise(result.error)) return memo;
if (!v.isPromise(result.error)) {
return memo;
}

@@ -160,4 +173,5 @@ return memo.then(function() {

// error was specified.
if (!error)
if (!error) {
v.warn("Validator promise was rejected but didn't return an error");
}
result.error = error;

@@ -182,3 +196,5 @@ }

var args = [].slice.call(arguments, 1);
if (typeof value === 'function') value = value.apply(null, args);
if (typeof value === 'function') {
value = value.apply(null, args);
}
return value;

@@ -231,8 +247,12 @@ },

// "Prettifies" the given string.
// Prettifying means replacing - and _ with spaces as well as splitting
// Prettifying means replacing [.\_-] with spaces as well as splitting
// camel case words.
prettify: function(str) {
return str
// Replaces - and _ with spaces
.replace(/[_\-]/g, ' ')
// Splits keys separated by periods
.replace(/([^\s])\.([^\s])/g, '$1 $2')
// Removes backslashes
.replace(/\\+/g, '')
// Replaces - and - with space
.replace(/[_-]/g, ' ')
// Splits camel cased words

@@ -254,9 +274,61 @@ .replace(/([a-z])([A-Z])/g, function(m0, m1, m2) {

contains: function(obj, value) {
if (!v.isDefined(obj)) return false;
if (v.isArray(obj)) return obj.indexOf(value) !== -1;
if (!v.isDefined(obj)) {
return false;
}
if (v.isArray(obj)) {
return obj.indexOf(value) !== -1;
}
return value in obj;
},
getDeepObjectValue: function(obj, keypath) {
if (!v.isObject(obj) || !v.isString(keypath)) {
return undefined;
}
var key = ""
, i
, escape = false;
for (i = 0; i < keypath.length; ++i) {
switch (keypath[i]) {
case '.':
if (escape) {
escape = false;
key += '.';
} else if (key in obj) {
obj = obj[key];
key = "";
} else {
return undefined;
}
break;
case '\\':
if (escape) {
escape = false;
key += '\\';
} else {
escape = true;
}
break;
default:
escape = false;
key += keypath[i];
break;
}
}
if (key in obj) {
return obj[key];
} else {
return undefined;
}
},
capitalize: function(str) {
if (!v.isString(str)) return str;
if (!v.isString(str)) {
return str;
}
return str[0].toUpperCase() + str.slice(1);

@@ -271,8 +343,11 @@ },

if (!errors) return ret;
if (!errors) {
return ret;
}
function processErrors(attr, errors) {
errors.forEach(function(error) {
if (error[0] === '^') error = error.slice(1);
else if (options.fullMessages !== false) {
if (error[0] === '^') {
error = error.slice(1);
} else if (options.fullMessages !== false) {
error = v.format("%{attr} %{message}", {

@@ -285,4 +360,8 @@ attr: v.capitalize(v.prettify(attr)),

// If flatten is true a flat array is returned.
if (options.flatten) ret.push(error);
else (ret[attr] || (ret[attr] = [])).push(error);
if (options.flatten) {
ret.push(error);
}
else {
(ret[attr] || (ret[attr] = [])).push(error);
}
});

@@ -293,3 +372,5 @@ }

// {attr: [<error>, <error>, ...]} to contain the attribute name.
for (attr in errors) processErrors(attr, errors[attr]);
for (attr in errors) {
processErrors(attr, errors[attr]);
}
return ret;

@@ -316,3 +397,5 @@ },

if (!promise) throw new Error("No promises could be detected");
if (!promise) {
throw new Error("No promises could be detected");
}

@@ -323,39 +406,55 @@ return promise;

var Promise_, module;
if (typeof Promise !== "undefined")
if (typeof Promise !== "undefined") {
Promise_ = Promise;
else {
} else {
module = v.tryRequire("es6-promise");
if (module) Promise_ = module.Promise;
if (module) {
Promise_ = module.Promise;
}
}
if (Promise_) return new Promise_(callback);
if (Promise_) {
return new Promise_(callback);
}
},
RSVPPromise: function(callback) {
var Promise, module;
if (typeof RSVP !== "undefined")
if (typeof RSVP !== "undefined") {
Promise = RSVP.Promise;
else {
} else {
module = v.tryRequire("rsvp");
if (module) Promise = module.Promise;
if (module) {
Promise = module.Promise;
}
}
if (Promise) return new Promise(callback);
if (Promise) {
return new Promise(callback);
}
},
whenPromise: function(callback) {
var promise, module;
if (typeof when !== "undefined")
if (typeof when !== "undefined") {
promise = when.promise;
else {
} else {
module = v.tryRequire("when");
if (module) promise = module.promise;
if (module) {
promise = module.promise;
}
}
if (promise) return promise(callback);
if (promise) {
return promise(callback);
}
},
QPromise: function(callback) {
var promise, module;
if (typeof Q !== "undefined")
if (typeof Q !== "undefined") {
promise = Q.promise;
else {
} else {
module = v.tryRequire("q");
if (module) promise = module.promise;
if (module) {
promise = module.promise;
}
}
if (promise) return promise(callback);
if (promise) {
return promise(callback);
}
}

@@ -365,3 +464,5 @@ }),

tryRequire: function(moduleName) {
if (!v.require) return null;
if (!v.require) {
return null;
}
try {

@@ -378,3 +479,5 @@ return v.require(moduleName);

if (exports) {
if (module && module.exports) exports = module.exports = validate;
if (module && module.exports) {
exports = module.exports = validate;
}
exports.validate = validate;

@@ -384,5 +487,5 @@ }

root.validate = validate;
if (validate.isFunction(define) && define.amd)
if (validate.isFunction(define) && define.amd) {
define("validate", [], function () { return validate; });
}
}

@@ -392,7 +495,11 @@ },

warn: function(msg) {
if (typeof console !== "undefined" && console.warn) console.warn(msg);
if (typeof console !== "undefined" && console.warn) {
console.warn(msg);
}
},
error: function(msg) {
if (typeof console !== "undefined" && console.error) console.error(msg);
if (typeof console !== "undefined" && console.error) {
console.error(msg);
}
}

@@ -408,18 +515,28 @@ });

// Null and undefined aren't allowed
if (!v.isDefined(value)) return message;
if (!v.isDefined(value)) {
return message;
}
// functions are ok
if (v.isFunction(value)) return;
if (v.isFunction(value)) {
return;
}
if (typeof value === 'string') {
// Tests if the string contains only whitespace (tab, newline, space etc)
if ((/^\s*$/).test(value)) return message;
if ((/^\s*$/).test(value)) {
return message;
}
}
else if (v.isArray(value)) {
// For arrays we use the length property
if (value.length === 0) return message;
if (value.length === 0) {
return message;
}
}
else if (v.isObject(value)) {
// If we find at least one property we consider it non empty
for (attr in value) return;
for (attr in value) {
return;
}
return message;

@@ -430,3 +547,5 @@ }

// Null and undefined are fine
if (!v.isDefined(value)) return;
if (!v.isDefined(value)) {
return;
}

@@ -461,6 +580,10 @@ var is = options.is

if (errors.length > 0) return options.message || errors;
if (errors.length > 0) {
return options.message || errors;
}
},
numericality: function(value, options) {
if (!v.isDefined(value)) return;
if (!v.isDefined(value)) {
return;
}

@@ -479,11 +602,16 @@ var errors = []

// Coerce the value to a number unless we're being strict.
if (options.noStrings !== true && v.isString(value)) value = +value;
if (options.noStrings !== true && v.isString(value)) {
value = +value;
}
// If it's not a number we shouldn't continue since it will compare it.
if (!v.isNumber(value)) return options.message || "is not a number";
if (!v.isNumber(value)) {
return options.message || "is not a number";
}
// Same logic as above, sort of. Don't bother with comparisons if this
// doesn't pass.
if (options.onlyInteger && !v.isInteger(value))
if (options.onlyInteger && !v.isInteger(value)) {
return options.message || "must be an integer";
}

@@ -500,9 +628,17 @@ for (name in checks) {

if (options.odd && value % 2 !== 1) errors.push("must be odd");
if (options.even && value % 2 !== 0) errors.push("must be even");
if (options.odd && value % 2 !== 1) {
errors.push("must be odd");
}
if (options.even && value % 2 !== 0) {
errors.push("must be even");
}
if (errors.length) return options.message || errors;
if (errors.length) {
return options.message || errors;
}
},
datetime: v.extend(function(value, options) {
if (!v.isDefined(value)) return;
if (!v.isDefined(value)) {
return;
}

@@ -517,4 +653,5 @@ var err

if (isNaN(value) || options.dateOnly && value % 86400000 !== 0)
if (isNaN(value) || options.dateOnly && value % 86400000 !== 0) {
return message || "must be a valid date";
}

@@ -533,3 +670,5 @@ if (!isNaN(earliest) && value < earliest) {

if (errors.length) return options.message || errors;
if (errors.length) {
return options.message || errors;
}
}, {

@@ -540,3 +679,12 @@ // This is the function that will be used to convert input to the number

parse: function(value, options) {
return new XDate(value, true).getTime();
if (v.isFunction(root.XDate)) {
return new root.XDate(value, true).getTime();
}
var moment = v.tryRequire("moment");
if (v.isDefined(moment)) {
return +moment.utc(value);
}
throw new Error("Neither XDate or moment.js was found");
},

@@ -547,4 +695,16 @@ // Formats the given timestamp. Uses ISO8601 to format them.

format: function(date, options) {
var format = options.dateFormat || (options.dateOnly ? "yyyy-MM-dd" : "u");
return new XDate(date, true).toString(format);
var format = options.dateFormat;
if (v.isFunction(root.XDate)) {
format = format || (options.dateOnly ? "yyyy-MM-dd" : "yyyy-MM-dd HH:mm:ss");
return new XDate(date, true).toString(format);
}
var moment = v.tryRequire("moment");
if (v.isDefined(moment)) {
format = format || (options.dateOnly ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss");
return moment.utc(date).format(format);
}
throw new Error("Neither XDate or moment.js was found");
}

@@ -557,4 +717,5 @@ }),

format: function(value, options) {
if (v.isString(options) || (options instanceof RegExp))
if (v.isString(options) || (options instanceof RegExp)) {
options = {pattern: options};
}

@@ -565,14 +726,27 @@ var message = options.message || "is invalid"

if (!v.isDefined(value)) return;
if (!v.isString(value)) return message;
if (!v.isDefined(value)) {
return;
}
if (!v.isString(value)) {
return message;
}
if (v.isString(pattern))
if (v.isString(pattern)) {
pattern = new RegExp(options.pattern, options.flags);
}
match = pattern.exec(value);
if (!match || match[0].length != value.length) return message;
if (!match || match[0].length != value.length) {
return message;
}
},
inclusion: function(value, options) {
if (v.isArray(options)) options = {within: options};
if (!v.isDefined(value)) return;
if (v.contains(options.within, value)) return;
if (v.isArray(options)) {
options = {within: options};
}
if (!v.isDefined(value)) {
return;
}
if (v.contains(options.within, value)) {
return;
}
var message = options.message || "^%{value} is not included in the list";

@@ -582,5 +756,11 @@ return v.format(message, {value: value});

exclusion: function(value, options) {
if (v.isArray(options)) options = {within: options};
if (!v.isDefined(value)) return;
if (!v.contains(options.within, value)) return;
if (v.isArray(options)) {
options = {within: options};
}
if (!v.isDefined(value)) {
return;
}
if (!v.contains(options.within, value)) {
return;
}
var message = options.message || "^%{value} is restricted";

@@ -591,7 +771,13 @@ return v.format(message, {value: value});

var message = options.message || "is not a valid email";
if (!v.isDefined(value)) return;
if (!v.isString(value)) return message;
if (!this.PATTERN.exec(value)) return message;
if (!v.isDefined(value)) {
return;
}
if (!v.isString(value)) {
return message;
}
if (!this.PATTERN.exec(value)) {
return message;
}
}, {
PATTERN: /^[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/
PATTERN: /^[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i
})

@@ -601,3 +787,2 @@ };

validate.exposeModule(validate, root, exports, module, define);
}).call(this,

@@ -604,0 +789,0 @@ typeof exports !== 'undefined' ? exports : null,

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

// validate.js 0.2.0
// validate.js 0.3.0
// http://validatejs.org/

@@ -6,3 +6,3 @@ // (c) 2013 Wrapp

(function(a,b,c,d){"use strict";var e=function(a,b,c){c=c||{};var d,g,h=f.runValidations(a,b,c);for(d in h)for(g in h[d])if(f.isPromise(h[d][g]))throw new Error("Use validate.async if you want support for promises");return e.processValidationResults(h,c)},f=e,g=this,h=g.XDate,i=/%\{([^\}]+)\}/g;f.extend=function(a){return[].slice.call(arguments,1).forEach(function(b){for(var c in b)a[c]=b[c]}),a},f.extend(e,{runValidations:function(a,b){var c,d,e,g,h,i,j,k=[];for(c in b){e=a[c],g=f.result(b[c],e,a,c);for(d in g){if(h=f.validators[d],!h)throw j=f.format("Unknown validator %{name}",{name:d}),new Error(j);i=g[d],i=f.result(i,e,a,c),i&&k.push({attribute:c,error:h.call(h,e,i,c,a)})}}return k},processValidationResults:function(a,b){var c={};a.forEach(function(a){var b=a.error,d=a.attribute;f.isString(b)&&(b=[b]),b&&(c[d]=(c[d]||[]).concat(b))});for(var d in c)return f.fullMessages(c,b)},async:function(a,b,c){c=c||{};var d=f.runValidations(a,b,c);return f.Promise(function(a,b){f.waitForResults(d).then(function(){var c=f.processValidationResults(d);c?b(c):a()}).then(void 0,f.error)})},waitForResults:function(a){var b=a.reduce(function(a,b){return f.isPromise(b.error)?a.then(function(){return b.error.then(function(){b.error=null},function(a){a||f.warn("Validator promise was rejected but didn't return an error"),b.error=a}).then(void 0,f.error)}).then(void 0,f.error):a},f.Promise(function(a){a()}));return b.then(void 0,f.error)},result:function(a){var b=[].slice.call(arguments,1);return"function"==typeof a&&(a=a.apply(null,b)),a},isNumber:function(a){return"number"==typeof a&&!isNaN(a)},isFunction:function(a){return"function"==typeof a},isInteger:function(a){return f.isNumber(a)&&a%1===0},isObject:function(a){return a===Object(a)},isDefined:function(a){return null!==a&&void 0!==a},isPromise:function(a){return!!a&&"function"==typeof a.then},format:function(a,b){return a.replace(i,function(a,c){return String(b[c])})},prettify:function(a){return a.replace(/[_\-]/g," ").replace(/([a-z])([A-Z])/g,function(a,b,c){return""+b+" "+c.toLowerCase()}).toLowerCase()},isString:function(a){return"string"==typeof a},isArray:function(a){return"[object Array]"==={}.toString.call(a)},contains:function(a,b){return f.isDefined(a)?f.isArray(a)?-1!==a.indexOf(b):b in a:!1},capitalize:function(a){return f.isString(a)?a[0].toUpperCase()+a.slice(1):a},fullMessages:function(a,b){function c(a,c){c.forEach(function(c){"^"===c[0]?c=c.slice(1):b.fullMessages!==!1&&(c=f.format("%{attr} %{message}",{attr:f.capitalize(f.prettify(a)),message:c})),c=c.replace(/\\\^/g,"^"),b.flatten?e.push(c):(e[a]||(e[a]=[])).push(c)})}b=b||{};var d,e=b.flatten?[]:{};if(!a)return e;for(d in a)c(d,a[d]);return e},Promise:f.extend(function(a){var b=f.Promise.nativePromise(a)||f.Promise.RSVPPromise(a)||f.Promise.whenPromise(a)||f.Promise.QPromise(a);if(!b)throw new Error("No promises could be detected");return b},{nativePromise:function(a){var b,c;return"undefined"!=typeof Promise?b=Promise:(c=f.tryRequire("es6-promise"),c&&(b=c.Promise)),b?new b(a):void 0},RSVPPromise:function(a){var b,c;return"undefined"!=typeof RSVP?b=RSVP.Promise:(c=f.tryRequire("rsvp"),c&&(b=c.Promise)),b?new b(a):void 0},whenPromise:function(a){var b,c;return"undefined"!=typeof when?b=when.promise:(c=f.tryRequire("when"),c&&(b=c.promise)),b?b(a):void 0},QPromise:function(a){var b,c;return"undefined"!=typeof Q?b=Q.promise:(c=f.tryRequire("q"),c&&(b=c.promise)),b?b(a):void 0}}),tryRequire:function(a){if(!f.require)return null;try{return f.require(a)}catch(b){return null}},require:d,exposeModule:function(a,b,c,d,e){c?(d&&d.exports&&(c=d.exports=a),c.validate=a):(b.validate=a,a.isFunction(e)&&e.amd&&e("validate",[],function(){return a}))},warn:function(a){"undefined"!=typeof console&&console.warn&&console.warn(a)},error:function(a){"undefined"!=typeof console&&console.error&&console.error(a)}}),e.validators={presence:function(a,b){var c,d=b.message||"can't be blank";if(!f.isDefined(a))return d;if(!f.isFunction(a))if("string"==typeof a){if(/^\s*$/.test(a))return d}else if(f.isArray(a)){if(0===a.length)return d}else if(f.isObject(a)){for(c in a)return;return d}},length:function(a,b){if(f.isDefined(a)){var c,d=b.is,e=b.maximum,g=b.minimum,h=b.tokenizer||function(a){return a},i=[];return a=h(a),f.isNumber(d)&&a.length!==d&&(c=b.wrongLength||"is the wrong length (should be %{count} characters)",i.push(f.format(c,{count:d}))),f.isNumber(g)&&a.length<g&&(c=b.tooShort||"is too short (minimum is %{count} characters)",i.push(f.format(c,{count:g}))),f.isNumber(e)&&a.length>e&&(c=b.tooLong||"is too long (maximum is %{count} characters)",i.push(f.format(c,{count:e}))),i.length>0?b.message||i:void 0}},numericality:function(a,b){if(f.isDefined(a)){var c,d,e=[],g={greaterThan:function(a,b){return a>b},greaterThanOrEqualTo:function(a,b){return a>=b},equalTo:function(a,b){return a===b},lessThan:function(a,b){return b>a},lessThanOrEqualTo:function(a,b){return b>=a}};if(b.noStrings!==!0&&f.isString(a)&&(a=+a),!f.isNumber(a))return b.message||"is not a number";if(b.onlyInteger&&!f.isInteger(a))return b.message||"must be an integer";for(c in g)d=b[c],f.isNumber(d)&&!g[c](a,d)&&e.push(f.format("must be %{type} %{count}",{count:d,type:f.prettify(c)}));return b.odd&&a%2!==1&&e.push("must be odd"),b.even&&a%2!==0&&e.push("must be even"),e.length?b.message||e:void 0}},datetime:f.extend(function(a,b){if(f.isDefined(a)){var c,d=[],e=b.message,g=b.earliest?this.parse(b.earliest,b):0/0,h=b.latest?this.parse(b.latest,b):0/0;return a=this.parse(a,b),isNaN(a)||b.dateOnly&&a%864e5!==0?e||"must be a valid date":(!isNaN(g)&&g>a&&(c="must be no earlier than %{date}",c=f.format(c,{date:this.format(g,b)}),d.push(c)),!isNaN(h)&&a>h&&(c="must be no later than %{date}",c=f.format(c,{date:this.format(h,b)}),d.push(c)),d.length?b.message||d:void 0)}},{parse:function(a){return new h(a,!0).getTime()},format:function(a,b){var c=b.dateFormat||(b.dateOnly?"yyyy-MM-dd":"u");return new h(a,!0).toString(c)}}),date:function(a,b){return b=f.extend({},b,{onlyDate:!0}),f.validators.datetime(a,b)},format:function(a,b){(f.isString(b)||b instanceof RegExp)&&(b={pattern:b});var c,d=b.message||"is invalid",e=b.pattern;if(f.isDefined(a))return f.isString(a)?(f.isString(e)&&(e=new RegExp(b.pattern,b.flags)),c=e.exec(a),c&&c[0].length==a.length?void 0:d):d},inclusion:function(a,b){if(f.isArray(b)&&(b={within:b}),f.isDefined(a)&&!f.contains(b.within,a)){var c=b.message||"^%{value} is not included in the list";return f.format(c,{value:a})}},exclusion:function(a,b){if(f.isArray(b)&&(b={within:b}),f.isDefined(a)&&f.contains(b.within,a)){var c=b.message||"^%{value} is restricted";return f.format(c,{value:a})}},email:f.extend(function(a,b){var c=b.message||"is not a valid email";if(f.isDefined(a))return f.isString(a)?this.PATTERN.exec(a)?void 0:c:c},{PATTERN:/^[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/})},e.exposeModule(e,g,a,b,c)}).call(this,"undefined"!=typeof exports?exports:null,"undefined"!=typeof module?module:null,"undefined"!=typeof define?define:null,"undefined"!=typeof require?require:null);
(function(a,b,c,d){"use strict";var e=function(a,b,c){c=c||{};var d,g,h=f.runValidations(a,b,c);for(d in h)for(g in h[d])if(f.isPromise(h[d][g]))throw new Error("Use validate.async if you want support for promises");return e.processValidationResults(h,c)},f=e,g=this,h=/%\{([^\}]+)\}/g;f.extend=function(a){return[].slice.call(arguments,1).forEach(function(b){for(var c in b)a[c]=b[c]}),a},f.extend(e,{runValidations:function(a,b){var c,d,e,g,h,i,j,k=[];for(c in b){e=f.getDeepObjectValue(a,c),g=f.result(b[c],e,a,c);for(d in g){if(h=f.validators[d],!h)throw j=f.format("Unknown validator %{name}",{name:d}),new Error(j);i=g[d],i=f.result(i,e,a,c),i&&k.push({attribute:c,error:h.call(h,e,i,c,a)})}}return k},processValidationResults:function(a,b){var c={};a.forEach(function(a){var b=a.error,d=a.attribute;f.isString(b)&&(b=[b]),b&&(c[d]=(c[d]||[]).concat(b))});for(var d in c)return f.fullMessages(c,b)},async:function(a,b,c){c=c||{};var d=f.runValidations(a,b,c);return f.Promise(function(a,b){f.waitForResults(d).then(function(){var c=f.processValidationResults(d);c?b(c):a()}).then(void 0,f.error)})},waitForResults:function(a){var b=a.reduce(function(a,b){return f.isPromise(b.error)?a.then(function(){return b.error.then(function(){b.error=null},function(a){a||f.warn("Validator promise was rejected but didn't return an error"),b.error=a}).then(void 0,f.error)}).then(void 0,f.error):a},f.Promise(function(a){a()}));return b.then(void 0,f.error)},result:function(a){var b=[].slice.call(arguments,1);return"function"==typeof a&&(a=a.apply(null,b)),a},isNumber:function(a){return"number"==typeof a&&!isNaN(a)},isFunction:function(a){return"function"==typeof a},isInteger:function(a){return f.isNumber(a)&&a%1===0},isObject:function(a){return a===Object(a)},isDefined:function(a){return null!==a&&void 0!==a},isPromise:function(a){return!!a&&"function"==typeof a.then},format:function(a,b){return a.replace(h,function(a,c){return String(b[c])})},prettify:function(a){return a.replace(/([^\s])\.([^\s])/g,"$1 $2").replace(/\\+/g,"").replace(/[_-]/g," ").replace(/([a-z])([A-Z])/g,function(a,b,c){return""+b+" "+c.toLowerCase()}).toLowerCase()},isString:function(a){return"string"==typeof a},isArray:function(a){return"[object Array]"==={}.toString.call(a)},contains:function(a,b){return f.isDefined(a)?f.isArray(a)?-1!==a.indexOf(b):b in a:!1},getDeepObjectValue:function(a,b){if(!f.isObject(a)||!f.isString(b))return void 0;var c,d="",e=!1;for(c=0;c<b.length;++c)switch(b[c]){case".":if(e)e=!1,d+=".";else{if(!(d in a))return void 0;a=a[d],d=""}break;case"\\":e?(e=!1,d+="\\"):e=!0;break;default:e=!1,d+=b[c]}return d in a?a[d]:void 0},capitalize:function(a){return f.isString(a)?a[0].toUpperCase()+a.slice(1):a},fullMessages:function(a,b){function c(a,c){c.forEach(function(c){"^"===c[0]?c=c.slice(1):b.fullMessages!==!1&&(c=f.format("%{attr} %{message}",{attr:f.capitalize(f.prettify(a)),message:c})),c=c.replace(/\\\^/g,"^"),b.flatten?e.push(c):(e[a]||(e[a]=[])).push(c)})}b=b||{};var d,e=b.flatten?[]:{};if(!a)return e;for(d in a)c(d,a[d]);return e},Promise:f.extend(function(a){var b=f.Promise.nativePromise(a)||f.Promise.RSVPPromise(a)||f.Promise.whenPromise(a)||f.Promise.QPromise(a);if(!b)throw new Error("No promises could be detected");return b},{nativePromise:function(a){var b,c;return"undefined"!=typeof Promise?b=Promise:(c=f.tryRequire("es6-promise"),c&&(b=c.Promise)),b?new b(a):void 0},RSVPPromise:function(a){var b,c;return"undefined"!=typeof RSVP?b=RSVP.Promise:(c=f.tryRequire("rsvp"),c&&(b=c.Promise)),b?new b(a):void 0},whenPromise:function(a){var b,c;return"undefined"!=typeof when?b=when.promise:(c=f.tryRequire("when"),c&&(b=c.promise)),b?b(a):void 0},QPromise:function(a){var b,c;return"undefined"!=typeof Q?b=Q.promise:(c=f.tryRequire("q"),c&&(b=c.promise)),b?b(a):void 0}}),tryRequire:function(a){if(!f.require)return null;try{return f.require(a)}catch(b){return null}},require:d,exposeModule:function(a,b,c,d,e){c?(d&&d.exports&&(c=d.exports=a),c.validate=a):(b.validate=a,a.isFunction(e)&&e.amd&&e("validate",[],function(){return a}))},warn:function(a){"undefined"!=typeof console&&console.warn&&console.warn(a)},error:function(a){"undefined"!=typeof console&&console.error&&console.error(a)}}),e.validators={presence:function(a,b){var c,d=b.message||"can't be blank";if(!f.isDefined(a))return d;if(!f.isFunction(a))if("string"==typeof a){if(/^\s*$/.test(a))return d}else if(f.isArray(a)){if(0===a.length)return d}else if(f.isObject(a)){for(c in a)return;return d}},length:function(a,b){if(f.isDefined(a)){var c,d=b.is,e=b.maximum,g=b.minimum,h=b.tokenizer||function(a){return a},i=[];return a=h(a),f.isNumber(d)&&a.length!==d&&(c=b.wrongLength||"is the wrong length (should be %{count} characters)",i.push(f.format(c,{count:d}))),f.isNumber(g)&&a.length<g&&(c=b.tooShort||"is too short (minimum is %{count} characters)",i.push(f.format(c,{count:g}))),f.isNumber(e)&&a.length>e&&(c=b.tooLong||"is too long (maximum is %{count} characters)",i.push(f.format(c,{count:e}))),i.length>0?b.message||i:void 0}},numericality:function(a,b){if(f.isDefined(a)){var c,d,e=[],g={greaterThan:function(a,b){return a>b},greaterThanOrEqualTo:function(a,b){return a>=b},equalTo:function(a,b){return a===b},lessThan:function(a,b){return b>a},lessThanOrEqualTo:function(a,b){return b>=a}};if(b.noStrings!==!0&&f.isString(a)&&(a=+a),!f.isNumber(a))return b.message||"is not a number";if(b.onlyInteger&&!f.isInteger(a))return b.message||"must be an integer";for(c in g)d=b[c],f.isNumber(d)&&!g[c](a,d)&&e.push(f.format("must be %{type} %{count}",{count:d,type:f.prettify(c)}));return b.odd&&a%2!==1&&e.push("must be odd"),b.even&&a%2!==0&&e.push("must be even"),e.length?b.message||e:void 0}},datetime:f.extend(function(a,b){if(f.isDefined(a)){var c,d=[],e=b.message,g=b.earliest?this.parse(b.earliest,b):0/0,h=b.latest?this.parse(b.latest,b):0/0;return a=this.parse(a,b),isNaN(a)||b.dateOnly&&a%864e5!==0?e||"must be a valid date":(!isNaN(g)&&g>a&&(c="must be no earlier than %{date}",c=f.format(c,{date:this.format(g,b)}),d.push(c)),!isNaN(h)&&a>h&&(c="must be no later than %{date}",c=f.format(c,{date:this.format(h,b)}),d.push(c)),d.length?b.message||d:void 0)}},{parse:function(a){if(f.isFunction(g.XDate))return new g.XDate(a,!0).getTime();var b=f.tryRequire("moment");if(f.isDefined(b))return+b.utc(a);throw new Error("Neither XDate or moment.js was found")},format:function(a,b){var c=b.dateFormat;if(f.isFunction(g.XDate))return c=c||(b.dateOnly?"yyyy-MM-dd":"yyyy-MM-dd HH:mm:ss"),new XDate(a,!0).toString(c);var d=f.tryRequire("moment");if(f.isDefined(d))return c=c||(b.dateOnly?"YYYY-MM-DD":"YYYY-MM-DD HH:mm:ss"),d.utc(a).format(c);throw new Error("Neither XDate or moment.js was found")}}),date:function(a,b){return b=f.extend({},b,{onlyDate:!0}),f.validators.datetime(a,b)},format:function(a,b){(f.isString(b)||b instanceof RegExp)&&(b={pattern:b});var c,d=b.message||"is invalid",e=b.pattern;if(f.isDefined(a))return f.isString(a)?(f.isString(e)&&(e=new RegExp(b.pattern,b.flags)),c=e.exec(a),c&&c[0].length==a.length?void 0:d):d},inclusion:function(a,b){if(f.isArray(b)&&(b={within:b}),f.isDefined(a)&&!f.contains(b.within,a)){var c=b.message||"^%{value} is not included in the list";return f.format(c,{value:a})}},exclusion:function(a,b){if(f.isArray(b)&&(b={within:b}),f.isDefined(a)&&f.contains(b.within,a)){var c=b.message||"^%{value} is restricted";return f.format(c,{value:a})}},email:f.extend(function(a,b){var c=b.message||"is not a valid email";if(f.isDefined(a))return f.isString(a)&&this.PATTERN.exec(a)?void 0:c},{PATTERN:/^[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9\u007F-\uffff!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i})},e.exposeModule(e,g,a,b,c)}).call(this,"undefined"!=typeof exports?exports:null,"undefined"!=typeof module?module:null,"undefined"!=typeof define?define:null,"undefined"!=typeof require?require:null);
//# sourceMappingURL=validate.min.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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