validate.js
Advanced tools
Comparing version 0.8.0 to 0.9.0
{ | ||
"name": "validate", | ||
"main": "validate.js", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"ignore": [ | ||
@@ -6,0 +6,0 @@ "**/.*", |
@@ -8,5 +8,5 @@ { | ||
"scripts" : ["validate.js"], | ||
"version" : "0.8.0", | ||
"version" : "0.9.0", | ||
"license" : "MIT" | ||
} | ||
@@ -99,6 +99,8 @@ module.exports = function(grunt) { | ||
report: 'gzip', | ||
banner: '// <%= pkg.name %> <%= pkg.version %>\n' + | ||
'// http://validatejs.org/\n' + | ||
'// (c) 2013-2015 Nicklas Ansman, 2013 Wrapp\n' + | ||
'// <%= pkg.name %> may be freely distributed under the MIT license.\n' | ||
banner: '/*!\n' + | ||
' * <%= pkg.name %> <%= pkg.version %>\n' + | ||
' * http://validatejs.org/\n' + | ||
' * (c) 2013-2015 Nicklas Ansman, 2013 Wrapp\n' + | ||
' * <%= pkg.name %> may be freely distributed under the MIT license.\n' + | ||
'*/\n' | ||
}, | ||
@@ -105,0 +107,0 @@ dist: { |
{ | ||
"name": "validate.js", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"author": "Nicklas Ansman <nicklas@ansman.se>", | ||
@@ -5,0 +5,0 @@ "description": "Declarative validations for JavaScript", |
@@ -42,3 +42,3 @@ validate.js | ||
If your site, library or application uses validate.js and would like to be shown | ||
here please feel free to email <a href="mailto:validate@ansman.se">validate@ansman.se</a> | ||
here please feel free to email <a href="mailto:info@validatejs.org">info@validatejs.org</a> | ||
with the name and optionally a URL to the project and it will be added here. |
@@ -29,9 +29,17 @@ beforeEach(function() { | ||
} | ||
return { | ||
pass: actual.every(function(a) { | ||
return expected.some(function(item) { | ||
return JSON.stringify(item) === JSON.stringify(a); | ||
}); | ||
}) | ||
}; | ||
var ret = {}; | ||
ret.pass = actual.every(function(a) { | ||
var passed = expected.some(function(e) { | ||
return util.equals(a, e, customEqualityTesters); | ||
}); | ||
if (!passed) { | ||
ret.message = "Object wasn't found:\n" + | ||
JSON.stringify(a, null, 2) + "\n\nExpected:\n" + | ||
JSON.stringify(expected, null, 2); | ||
} | ||
return passed; | ||
}); | ||
return ret; | ||
} | ||
@@ -38,0 +46,0 @@ }; |
@@ -128,2 +128,7 @@ describe("validate", function() { | ||
}); | ||
it("handles non strings as the message", function() { | ||
var obj = {foo: "bar"}; | ||
expect(validate.format(obj, {attr: "value"})).toBe(obj); | ||
}); | ||
}); | ||
@@ -769,3 +774,2 @@ | ||
it("returns false for non dates", function() { | ||
expect(validate.isDate(new XDate())).toBe(false); | ||
expect(validate.isDate(Date.now())).toBe(false); | ||
@@ -941,2 +945,14 @@ expect(validate.isDate({})).toBe(false); | ||
}); | ||
it("handles empty and invalid numeric inputs", function() { | ||
var form = document.createElement("form"); | ||
form.innerHTML = '' + | ||
'<input type="number" name="emptyNumber">' + | ||
'<input type="number" name="invalidNumber" value="abc">'; | ||
expect(validate.collectFormValues(form)).toEqual({ | ||
emptyNumber: null, | ||
invalidNumber: null | ||
}); | ||
}); | ||
}); | ||
@@ -943,0 +959,0 @@ |
@@ -103,11 +103,13 @@ describe("validate", function() { | ||
it("calls the validator with the val, opts, key and attributes", function() { | ||
it("calls the validator with the val, opts, key, attributes and global options", function() { | ||
var options = {someOption: true} | ||
, attributes = {someAttribute: 'some value'} | ||
, constraints = {someAttribute: {pass: options}}; | ||
validate.runValidations(attributes, constraints, {}); | ||
, constraints = {someAttribute: {pass: options}} | ||
, globalOptions = {someOption: 'some value'}; | ||
validate.runValidations(attributes, constraints, globalOptions); | ||
expect(pass).toHaveBeenCalledWith('some value', | ||
options, | ||
'someAttribute', | ||
attributes); | ||
attributes, | ||
globalOptions); | ||
}); | ||
@@ -121,4 +123,6 @@ | ||
var options = {someOption: true} | ||
, constraints = {name: {fail: options, fail2: true, pass: true}}; | ||
var result = validate.runValidations({name: "test"}, constraints, {}); | ||
, globalOptions = {globalOption: "globalValue"} | ||
, constraints = {name: {fail: options, fail2: true, pass: true}} | ||
, attributes = {name: "test"}; | ||
var result = validate.runValidations(attributes, constraints, globalOptions); | ||
@@ -130,2 +134,4 @@ expect(result).toHaveItems([{ | ||
options: options, | ||
attributes: attributes, | ||
globalOptions: globalOptions, | ||
error: "foobar" | ||
@@ -137,2 +143,4 @@ }, { | ||
options: true, | ||
attributes: attributes, | ||
globalOptions: globalOptions, | ||
error: ["foo", "bar"] | ||
@@ -144,2 +152,4 @@ }, { | ||
options: true, | ||
attributes: attributes, | ||
globalOptions: globalOptions, | ||
error: null | ||
@@ -162,2 +172,4 @@ }]); | ||
options: {foo: "bar"}, | ||
attributes: {}, | ||
globalOptions: {}, | ||
error: undefined | ||
@@ -169,2 +181,4 @@ }, { | ||
options: true, | ||
attributes: {}, | ||
globalOptions: {}, | ||
error: "error" | ||
@@ -176,2 +190,4 @@ }, { | ||
options: true, | ||
attributes: {}, | ||
globalOptions: {}, | ||
error: "error" | ||
@@ -190,3 +206,3 @@ } | ||
expect(spy).toHaveBeenCalledWith("Nicklas", attrs, "name", globalOptions, constraints); | ||
expect(pass).toHaveBeenCalledWith("Nicklas", options.pass, "name", attrs); | ||
expect(pass).toHaveBeenCalledWith("Nicklas", options.pass, "name", attrs, globalOptions); | ||
}); | ||
@@ -202,3 +218,3 @@ | ||
expect(spy).toHaveBeenCalledWith("Nicklas", attrs, "name", globalOptions, constraints); | ||
expect(pass).toHaveBeenCalledWith("Nicklas", options, "name", attrs); | ||
expect(pass).toHaveBeenCalledWith("Nicklas", options, "name", attrs, globalOptions); | ||
}); | ||
@@ -226,3 +242,4 @@ | ||
"foo", | ||
{foo: "bar"} | ||
{foo: "bar"}, | ||
{} | ||
); | ||
@@ -236,3 +253,4 @@ | ||
"foo", | ||
{foo: "bar"} | ||
{foo: "bar"}, | ||
{} | ||
); | ||
@@ -290,3 +308,4 @@ }); | ||
}; | ||
expect(validate(attributes, c, {format: "detailed"})).toHaveItems([{ | ||
var options = {format: "detailed"}; | ||
expect(validate(attributes, c, options)).toHaveItems([{ | ||
attribute: "foo", | ||
@@ -300,2 +319,4 @@ value: "foo", | ||
}, | ||
attributes: attributes, | ||
globalOptions: options, | ||
error: "foobar" | ||
@@ -310,2 +331,4 @@ }, { | ||
}, | ||
attributes: attributes, | ||
globalOptions: options, | ||
error: "Bar must be greater than 15" | ||
@@ -320,2 +343,4 @@ }, { | ||
}, | ||
attributes: attributes, | ||
globalOptions: options, | ||
error: "Bar must be less than 5" | ||
@@ -327,2 +352,28 @@ }]); | ||
it("allows validators to return functions as messages", function() { | ||
var message = jasmine.createSpy("message").and.returnValue("some message") | ||
, validatorOptions = {validatorOption: "validatorValue"} | ||
, options = {option: "value"} | ||
, constraints = { foo: { fail: validatorOptions } } | ||
, attributes = {foo: "bar"}; | ||
fail.and.returnValue(message); | ||
expect(validate(attributes, constraints, options)).toEqual({ | ||
foo: ["Foo some message"] | ||
}); | ||
expect(message).toHaveBeenCalledWith( | ||
"bar", | ||
"foo", | ||
validatorOptions, | ||
attributes, | ||
options); | ||
}); | ||
it("allows validators to return objects as messages", function() { | ||
var message = {foo: "bar"}; | ||
fail.and.returnValue(message); | ||
expect(validate({}, {foo: {fail: true}})).toEqual({ | ||
foo: [message] | ||
}); | ||
}); | ||
it("allows default options", function() { | ||
@@ -329,0 +380,0 @@ var constraints = {foo: {presence: true}} |
describe('validators.datetime', function() { | ||
var datetime = validate.validators.datetime.bind(validate.validators.datetime) | ||
, XDate = validate.XDate | ||
, moment = validate.moment; | ||
, parse = validate.validators.datetime.parse | ||
, format = validate.validators.datetime.format; | ||
beforeEach(function() { | ||
validate.validators.datetime.parse = function(value) { | ||
return +moment.utc(value); | ||
}; | ||
validate.validators.datetime.format = function(value, options) { | ||
return moment.utc(value).format("YYYY-MM-DD HH:mm:ss"); | ||
}; | ||
}); | ||
afterEach(function() { | ||
@@ -11,148 +20,34 @@ delete validate.validators.datetime.notValid; | ||
delete validate.validators.datetime.options; | ||
validate.XDate = XDate; | ||
validate.moment = moment; | ||
validate.validators.datetime.parse = parse; | ||
validate.validators.datetime.format = parse; | ||
}); | ||
it("allows empty values", function() { | ||
expect(datetime(null, {})).not.toBeDefined(); | ||
expect(datetime(undefined, {})).not.toBeDefined(); | ||
expect(datetime("", {})).not.toBeDefined(); | ||
expect(datetime(" ", {})).not.toBeDefined(); | ||
}); | ||
it("throws an exception if format and parse isn't set", function() { | ||
var p = validate.validators.datetime.parse | ||
, f = validate.validators.datetime.format; | ||
validate.validators.datetime.parse = parse; | ||
validate.validators.datetime.format = format; | ||
describe("parse", function() { | ||
var parse = validate.validators.datetime.parse; | ||
expect(function() { datetime(null, {}); }).toThrow(); | ||
beforeEach(function() { | ||
delete validate.XDate; | ||
delete validate.moment; | ||
}); | ||
validate.validators.datetime.parse = p; | ||
expect(function() { datetime(null, {}); }).toThrow(); | ||
it("throws an error if neither XDate or moment.js is found", function() { | ||
expect(function() { | ||
parse("2014-09-02"); | ||
}).toThrow(); | ||
}); | ||
validate.validators.datetime.parse = parse; | ||
validate.validators.datetime.format = f; | ||
expect(function() { datetime(null, {}); }).toThrow(); | ||
function runParseTestsForValidDates() { | ||
// 2013-10-25 00:00:00 UTC | ||
expect(parse("2013-10-26", {})).toEqual(1382745600000); | ||
// 1000-01-01 00:00:00 UTC | ||
expect(parse("1000-01-01", {})).toEqual(-30610224000000); | ||
// UTC | ||
expect(parse("2013-10-26T10:35:24", {})).toEqual(1382783724000); | ||
// PDT | ||
expect(parse("2013-10-26T10:35:24-0700", {})).toEqual(1382808924000); | ||
// PDT | ||
var date = new Date("2013-10-26T10:35:24-0700"); | ||
expect(parse(date, {})).toEqual(date.getTime()); | ||
} | ||
function runNaNTests() { | ||
expect(parse("foobar", {})).toBeNaN(); | ||
} | ||
describe("with XDate", function() { | ||
beforeEach(function() { | ||
validate.XDate = XDate; | ||
}); | ||
it("returns the millis since epoch for valid strings", function() { | ||
runParseTestsForValidDates(); | ||
}); | ||
it("returns NaN for invalid dates", function() { | ||
runNaNTests(); | ||
}); | ||
}); | ||
describe("with moment.js", function() { | ||
beforeEach(function() { | ||
validate.moment = moment; | ||
spyOn(moment, "utc").and.callThrough(); | ||
}); | ||
it("returns the millis since epoch for valid strings", function() { | ||
runParseTestsForValidDates(); | ||
expect(moment.utc).toHaveBeenCalled(); | ||
}); | ||
it("returns NaN for invalid dates", function() { | ||
runNaNTests(); | ||
expect(moment.utc).toHaveBeenCalled(); | ||
}); | ||
}); | ||
validate.validators.datetime.parse = p; | ||
expect(function() { datetime(null, {}); }).not.toThrow(); | ||
}); | ||
describe("format", function() { | ||
var format = validate.validators.datetime.format; | ||
beforeEach(function() { | ||
delete validate.XDate; | ||
delete validate.moment; | ||
}); | ||
it("throws and error if neither XDate or moment.js is found", function() { | ||
expect(function() { | ||
format(1382808924000, {}); | ||
}).toThrow(); | ||
}); | ||
function runDatetimeTest() { | ||
var expected = "2013-10-26 17:35:24"; | ||
expect(format(1382808924000, {})).toBe(expected); | ||
} | ||
function runDateTest() { | ||
var expected = "2013-10-26"; | ||
expect(format(1382745600000, {dateOnly: true})).toBe(expected); | ||
} | ||
function runOverrideTest(dateFormat) { | ||
var expected = "10/26/13"; | ||
expect(format(1382808924000, {dateFormat: dateFormat})).toBe(expected); | ||
} | ||
describe("with XDate", function() { | ||
beforeEach(function() { | ||
validate.XDate = XDate; | ||
}); | ||
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() { | ||
validate.moment = moment; | ||
spyOn(moment, "utc").and.callThrough(); | ||
}); | ||
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(); | ||
}); | ||
}); | ||
it("allows empty values", function() { | ||
spyOn(validate.validators.datetime, "parse"); | ||
spyOn(validate.validators.datetime, "format"); | ||
expect(datetime(null, {})).not.toBeDefined(); | ||
expect(datetime(undefined, {})).not.toBeDefined(); | ||
expect(datetime("", {})).not.toBeDefined(); | ||
expect(datetime(" ", {})).not.toBeDefined(); | ||
expect(validate.validators.datetime.parse).not.toHaveBeenCalled(); | ||
expect(validate.validators.datetime.format).not.toHaveBeenCalled(); | ||
}); | ||
@@ -164,6 +59,2 @@ | ||
it("allows date objects", function() { | ||
expect(datetime(new Date(), {})).not.toBeDefined(); | ||
}); | ||
it("doesn't allow invalid dates", function() { | ||
@@ -174,12 +65,6 @@ var expected = "must be a valid date"; | ||
it("uses the parse function to validate dates", function() { | ||
var spy = spyOn(validate.validators.datetime, 'parse').and.returnValue(NaN) | ||
, options = {foo: "bar"}; | ||
expect(datetime("2013-06-27", options)).toBeDefined(); | ||
expect(spy).toHaveBeenCalledWith("2013-06-27", options); | ||
}); | ||
it("doesn't allow h, m or s when dateOnly is true", function() { | ||
var expected = "must be a valid date" | ||
, opts = {dateOnly: true}; | ||
expect(datetime("2013-10-26 13:47:00", opts)).toEqual(expected); | ||
@@ -217,3 +102,4 @@ expect(datetime("2013-10-26", opts)).not.toBeDefined(); | ||
, value = "2013-10-25 00:00:00" | ||
, spy = spyOn(validate.validators.datetime, 'format').and.returnValue("foobar") | ||
, spy = spyOn(validate.validators.datetime, 'format') | ||
.and.returnValue("foobar") | ||
, expected = ["must be no earlier than foobar"]; | ||
@@ -225,3 +111,3 @@ expect(datetime(value, options)).toEqual(expected); | ||
var options = {earliest: 'foobar'} | ||
, value = XDate.today() | ||
, value = moment.utc().startOf('day') | ||
, spy = spyOn(validate.validators.datetime, 'parse').and.returnValue(value); | ||
@@ -271,3 +157,3 @@ datetime(value, options); | ||
var options = {latest: 'foobar'} | ||
, value = XDate.today() | ||
, value = moment.utc().startOf('day') | ||
, spy = spyOn(validate.validators.datetime, 'parse').and.returnValue(value); | ||
@@ -296,3 +182,6 @@ datetime(value, options); | ||
, value = "2013-10-25 00:00:00"; | ||
expect(datetime(value, options)).toHaveLength(2); | ||
expect(datetime(value, options)).toHaveItems([ | ||
"must be no later than 2013-10-24 00:00:00", | ||
"must be no earlier than 2013-10-26 00:00:00" | ||
]); | ||
}); | ||
@@ -321,2 +210,13 @@ | ||
}); | ||
it("allows functions as messages", function() { | ||
var message = function() { return "foo"; }; | ||
var options = { | ||
earliest: '2013-10-26 00:00:00', | ||
latest: '2013-10-24 00:00:00', | ||
message: message | ||
} | ||
, value = "2013-10-25 00:00:00"; | ||
expect(datetime(value, options)).toBe(message); | ||
}); | ||
}); | ||
@@ -323,0 +223,0 @@ |
@@ -64,2 +64,9 @@ describe('validators.email', function() { | ||
}); | ||
it("allows functions as messages", function() { | ||
var message = function() { return "foo"; }; | ||
var options = {message: message} | ||
, value = "foo"; | ||
expect(email(value, options)).toBe(message); | ||
}); | ||
}); |
@@ -97,2 +97,9 @@ describe('validators.equality', function() { | ||
}); | ||
it("allows functions as messages", function() { | ||
var message = function() { return "foo"; }; | ||
var options = {message: message, attribute: "bar"} | ||
, value = "foo"; | ||
expect(equality(value, options)).toBe(message); | ||
}); | ||
}); |
@@ -64,2 +64,9 @@ describe("validators.exclusion", function() { | ||
}); | ||
it("allows functions as messages", function() { | ||
var message = function() { return "foo"; }; | ||
var options = {message: message, within: ["foo"]} | ||
, value = "foo"; | ||
expect(exclusion(value, options)).toBe(message); | ||
}); | ||
}); |
@@ -81,2 +81,9 @@ describe("validators.format", function() { | ||
}); | ||
it("allows functions as messages", function() { | ||
var message = function() { return "foo"; }; | ||
var options = {message: message, pattern: /bar/} | ||
, value = "foo"; | ||
expect(format(value, options)).toBe(message); | ||
}); | ||
}); |
@@ -64,2 +64,9 @@ describe("validators.inclusion", function() { | ||
}); | ||
it("allows functions as messages", function() { | ||
var message = function() { return "foo"; }; | ||
var options = {message: message, within: ["bar"]} | ||
, value = "foo"; | ||
expect(inclusion(value, options)).toBe(message); | ||
}); | ||
}); |
@@ -175,2 +175,9 @@ describe('validator.length', function() { | ||
}); | ||
it("allows functions as messages", function() { | ||
var message = function() { return "foo"; }; | ||
var options = {message: message, minimum: 10} | ||
, value = "foo"; | ||
expect(length(value, options)).toBe(message); | ||
}); | ||
}); |
@@ -50,2 +50,8 @@ describe("validators.numericality", function() { | ||
it("uses the custom message if specified", function() { | ||
var expected = "default message"; | ||
expect(numericality("foo", {notValid: expected})).toEqual("default message"); | ||
expect(numericality("foo", {message: "my message"})).toEqual("my message"); | ||
}); | ||
describe("onlyInteger", function() { | ||
@@ -70,2 +76,7 @@ it("allows integers", function() { | ||
}); | ||
it("uses the custom message if specified", function() { | ||
var opts = {onlyInteger: true, notInteger: "default message" }; | ||
expect(numericality(3.14, opts)).toEqual("default message"); | ||
}); | ||
}); | ||
@@ -84,2 +95,7 @@ | ||
it("allows for a custom message", function() { | ||
var expected = "custom message"; | ||
expect(numericality(3.14, {greaterThan: 3.14, notGreaterThan: expected})).toEqual([expected]); | ||
}); | ||
it("allows for a default message", function() { | ||
@@ -103,2 +119,7 @@ var expected = "default message"; | ||
it("allows for a custom message", function() { | ||
var expected = "custom message"; | ||
expect(numericality(3.13, {greaterThanOrEqualTo: 3.14, notGreaterThanOrEqualTo: expected})).toEqual([expected]); | ||
}); | ||
it("allows for a default message", function() { | ||
@@ -126,2 +147,7 @@ var expected = "default message"; | ||
}); | ||
it("allows for a custom message", function() { | ||
var expected = "custom message"; | ||
expect(numericality(3.13, {equalTo: 3.14, notEqualTo:expected})).toEqual([expected]); | ||
}); | ||
}); | ||
@@ -145,2 +171,7 @@ | ||
}); | ||
it("allows for a custom message", function() { | ||
var expected = "custom message"; | ||
expect(numericality(3.14, {lessThan: 3.14, notLessThan: expected})).toEqual([expected]); | ||
}); | ||
}); | ||
@@ -164,2 +195,7 @@ | ||
}); | ||
it("allows for a custom message", function() { | ||
var expected = "custom message"; | ||
expect(numericality(3.15, {lessThanOrEqualTo: 3.14, notLessThanOrEqualTo: expected})).toEqual([expected]); | ||
}); | ||
}); | ||
@@ -186,2 +222,7 @@ | ||
}); | ||
it("allows for a custom message", function() { | ||
var expected = "custom message"; | ||
expect(numericality(2, {odd: true, notOdd: expected})).toEqual([expected]); | ||
}); | ||
}); | ||
@@ -208,2 +249,7 @@ | ||
}); | ||
it("allows for a custom message", function() { | ||
var expected = "custom message"; | ||
expect(numericality(3, {even: true, notEven: expected})).toEqual([expected]); | ||
}); | ||
}); | ||
@@ -252,2 +298,9 @@ | ||
}); | ||
it("allows functions as messages", function() { | ||
var message = function() { return "foo"; }; | ||
var options = {message: message} | ||
, value = "foo"; | ||
expect(numericality(value, options)).toBe(message); | ||
}); | ||
}); |
@@ -46,2 +46,9 @@ describe('validator.presence', function() { | ||
}); | ||
it("allows functions as messages", function() { | ||
var message = function() { return "foo"; }; | ||
var options = {message: message} | ||
, value = null; | ||
expect(presence(value, options)).toBe(message); | ||
}); | ||
}); |
168
validate.js
@@ -1,8 +0,10 @@ | ||
// Validate.js 0.7.1 | ||
/*! | ||
* validate.js 0.9.0 | ||
* | ||
* (c) 2013-2015 Nicklas Ansman, 2013 Wrapp | ||
* Validate.js may be freely distributed under the MIT license. | ||
* For all details and documentation: | ||
* http://validatejs.org/ | ||
*/ | ||
// (c) 2013-2015 Nicklas Ansman, 2013 Wrapp | ||
// Validate.js may be freely distributed under the MIT license. | ||
// For all details and documentation: | ||
// http://validatejs.org/ | ||
(function(exports, module, define) { | ||
@@ -57,5 +59,5 @@ "use strict"; | ||
major: 0, | ||
minor: 8, | ||
minor: 9, | ||
patch: 0, | ||
metadata: "", | ||
metadata: null, | ||
toString: function() { | ||
@@ -78,7 +80,2 @@ var version = v.format("%{major}.%{minor}.%{patch}", v.version); | ||
// If moment is used in node, browserify etc please set this attribute | ||
// like this: `validate.moment = require("moment"); | ||
moment: typeof moment !== "undefined" ? moment : /* istanbul ignore next */ null, | ||
XDate: typeof XDate !== "undefined" ? XDate : /* istanbul ignore next */ null, | ||
EMPTY_STRING_REGEXP: /^\s*$/, | ||
@@ -135,5 +132,11 @@ | ||
validator: validatorName, | ||
globalOptions: options, | ||
attributes: attributes, | ||
options: validatorOptions, | ||
error: validator.call(validator, value, validatorOptions, attr, | ||
attributes) | ||
error: validator.call(validator, | ||
value, | ||
validatorOptions, | ||
attr, | ||
attributes, | ||
options) | ||
}); | ||
@@ -240,3 +243,2 @@ } | ||
} | ||
console.log("Foo"); | ||
v.error("Rejecting promises with the result is deprecated. Please use the resolve callback instead."); | ||
@@ -381,2 +383,5 @@ result.error = error; | ||
format: v.extend(function(str, vals) { | ||
if (!v.isString(str)) { | ||
return str; | ||
} | ||
return str.replace(v.format.FORMAT_REGEXP, function(m0, m1, m2) { | ||
@@ -539,3 +544,3 @@ if (m1 === '%') { | ||
if (input.type === "number") { | ||
value = +value; | ||
value = value ? +value : null; | ||
} else if (input.type === "checkbox") { | ||
@@ -621,4 +626,14 @@ if (input.attributes.value) { | ||
errors.forEach(function(errorInfo) { | ||
var error = errorInfo.error; | ||
var error = v.result(errorInfo.error, | ||
errorInfo.value, | ||
errorInfo.attribute, | ||
errorInfo.options, | ||
errorInfo.attributes, | ||
errorInfo.globalOptions); | ||
if (!v.isString(error)) { | ||
ret.push(errorInfo); | ||
return; | ||
} | ||
if (error[0] === '^') { | ||
@@ -820,3 +835,3 @@ error = error.slice(1); | ||
if (!v.isNumber(value)) { | ||
return options.message || this.notValid || "is not a number"; | ||
return options.message || options.notValid || this.notValid || "is not a number"; | ||
} | ||
@@ -827,3 +842,3 @@ | ||
if (options.onlyInteger && !v.isInteger(value)) { | ||
return options.message || this.notInteger || "must be an integer"; | ||
return options.message || options.notInteger || this.notInteger || "must be an integer"; | ||
} | ||
@@ -837,4 +852,4 @@ | ||
// this.notGreaterThan so we capitalize the name and prepend "not" | ||
var msg = this["not" + v.capitalize(name)] || | ||
"must be %{type} %{count}"; | ||
var key = "not" + v.capitalize(name); | ||
var msg = options[key] || this[key] || "must be %{type} %{count}"; | ||
@@ -849,6 +864,6 @@ errors.push(v.format(msg, { | ||
if (options.odd && value % 2 !== 1) { | ||
errors.push(this.notOdd || "must be odd"); | ||
errors.push(options.notOdd || this.notOdd || "must be odd"); | ||
} | ||
if (options.even && value % 2 !== 0) { | ||
errors.push(this.notEven || "must be even"); | ||
errors.push(options.notEven || this.notEven || "must be even"); | ||
} | ||
@@ -861,2 +876,6 @@ | ||
datetime: v.extend(function(value, options) { | ||
if (!v.isFunction(this.parse) || !v.isFunction(this.format)) { | ||
throw new Error("Both the parse and format functions needs to be set to use the datetime/date validator"); | ||
} | ||
// Empty values are fine | ||
@@ -898,34 +917,4 @@ if (v.isEmpty(value)) { | ||
}, { | ||
// This is the function that will be used to convert input to the number | ||
// of millis since the epoch. | ||
// It should return NaN if it's not a valid date. | ||
parse: function(value, options) { | ||
if (v.isFunction(v.XDate)) { | ||
return new v.XDate(value, true).getTime(); | ||
} | ||
if (v.isDefined(v.moment)) { | ||
return +v.moment.utc(value); | ||
} | ||
throw new Error("Neither XDate or moment.js was found"); | ||
}, | ||
// Formats the given timestamp. Uses ISO8601 to format them. | ||
// If options.dateOnly is true then only the year, month and day will be | ||
// output. | ||
format: function(date, options) { | ||
var format = options.dateFormat; | ||
if (v.isFunction(v.XDate)) { | ||
format = format || (options.dateOnly ? "yyyy-MM-dd" : "yyyy-MM-dd HH:mm:ss"); | ||
return new v.XDate(date, true).toString(format); | ||
} | ||
if (v.isDefined(v.moment)) { | ||
format = format || (options.dateOnly ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm:ss"); | ||
return v.moment.utc(date).format(format); | ||
} | ||
throw new Error("Neither XDate or moment.js was found"); | ||
} | ||
parse: null, | ||
format: null | ||
}), | ||
@@ -1036,2 +1025,69 @@ date: function(value, options) { | ||
} | ||
}, | ||
// A URL validator that is used to validate URLs with the ability to | ||
// restrict schemes and some domains. | ||
url: function(value, options) { | ||
if (v.isEmpty(value)) { | ||
return; | ||
} | ||
options = v.extend({}, this.options, options); | ||
var message = options.message || this.message || "is not a valid url" | ||
, schemes = options.schemes || this.schemes || ['http', 'https'] | ||
, allowLocal = options.allowLocal || this.allowLocal || false; | ||
if (!v.isString(value)) { | ||
return message; | ||
} | ||
// https://gist.github.com/dperini/729294 | ||
var regex = | ||
"^" + | ||
// schemes | ||
"(?:(?:" + schemes.join("|") + "):\\/\\/)" + | ||
// credentials | ||
"(?:\\S+(?::\\S*)?@)?"; | ||
regex += "(?:"; | ||
var hostname = | ||
"(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" + | ||
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" + | ||
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))"; | ||
// This ia a special case for the localhost hostname | ||
if (allowLocal) { | ||
hostname = "(?:localhost|" + hostname + ")"; | ||
} else { | ||
// private & local addresses | ||
regex += | ||
"(?!10(?:\\.\\d{1,3}){3})" + | ||
"(?!127(?:\\.\\d{1,3}){3})" + | ||
"(?!169\\.254(?:\\.\\d{1,3}){2})" + | ||
"(?!192\\.168(?:\\.\\d{1,3}){2})" + | ||
"(?!172" + | ||
"\\.(?:1[6-9]|2\\d|3[0-1])" + | ||
"(?:\\.\\d{1,3})" + | ||
"{2})"; | ||
} | ||
// reserved addresses | ||
regex += | ||
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" + | ||
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" + | ||
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" + | ||
"|" + | ||
hostname + | ||
// port number | ||
"(?::\\d{2,5})?" + | ||
// path | ||
"(?:\\/[^\\s]*)?" + | ||
"$"; | ||
var PATTERN = new RegExp(regex, 'i'); | ||
if (!PATTERN.exec(value)) { | ||
return message; | ||
} | ||
} | ||
@@ -1038,0 +1094,0 @@ }; |
@@ -1,7 +0,9 @@ | ||
// validate.js 0.8.0 | ||
// http://validatejs.org/ | ||
// (c) 2013-2015 Nicklas Ansman, 2013 Wrapp | ||
// validate.js may be freely distributed under the MIT license. | ||
/*! | ||
* validate.js 0.9.0 | ||
* http://validatejs.org/ | ||
* (c) 2013-2015 Nicklas Ansman, 2013 Wrapp | ||
* validate.js may be freely distributed under the MIT license. | ||
*/ | ||
(function(a,b,c){"use strict";var d=function(a,b,c){c=e.extend({},e.options,c);var f,g,h=e.runValidations(a,b,c);for(f in h)for(g in h[f])if(e.isPromise(h[f][g]))throw new Error("Use validate.async if you want support for promises");return d.processValidationResults(h,c)},e=d;e.extend=function(a){return[].slice.call(arguments,1).forEach(function(b){for(var c in b)a[c]=b[c]}),a},e.extend(d,{version:{major:0,minor:8,patch:0,metadata:"",toString:function(){var a=e.format("%{major}.%{minor}.%{patch}",e.version);return e.isEmpty(e.version.metadata)||(a+="+"+e.version.metadata),a}},Promise:"undefined"!=typeof Promise?Promise:null,moment:"undefined"!=typeof moment?moment:null,XDate:"undefined"!=typeof XDate?XDate:null,EMPTY_STRING_REGEXP:/^\s*$/,runValidations:function(a,b,c){var d,f,g,h,i,j,k,l=[];(e.isDomElement(a)||e.isJqueryElement(a))&&(a=e.collectFormValues(a));for(d in b){g=e.getDeepObjectValue(a,d),h=e.result(b[d],g,a,d,c,b);for(f in h){if(i=e.validators[f],!i)throw k=e.format("Unknown validator %{name}",{name:f}),new Error(k);j=h[f],j=e.result(j,g,a,d,c,b),j&&l.push({attribute:d,value:g,validator:f,options:j,error:i.call(i,g,j,d,a)})}}return l},processValidationResults:function(a,b){var c;switch(a=e.pruneEmptyErrors(a,b),a=e.expandMultipleErrors(a,b),a=e.convertErrorMessages(a,b),b.format||"grouped"){case"detailed":break;case"flat":a=e.flattenErrorsToArray(a);break;case"grouped":a=e.groupErrorsByAttribute(a);for(c in a)a[c]=e.flattenErrorsToArray(a[c]);break;default:throw new Error(e.format("Unknown format %{format}",b))}return e.isEmpty(a)?void 0:a},async:function(a,b,c){c=e.extend({},e.async.options,c);var d=c.wrapErrors||function(a){return a};c.cleanAttributes!==!1&&(a=e.cleanAttributes(a,b));var f=e.runValidations(a,b,c);return new e.Promise(function(g,h){e.waitForResults(f).then(function(){var i=e.processValidationResults(f,c);i?h(new d(i,c,a,b)):g(a)},function(a){h(a)})})},single:function(a,b,c){return c=e.extend({},e.single.options,c,{format:"flat",fullMessages:!1}),e({single:a},{single:b},c)},waitForResults:function(a){return a.reduce(function(a,b){return e.isPromise(b.error)?a.then(function(){return b.error.then(function(a){b.error=a||null},function(a){if(a instanceof Error)throw a;console.log("Foo"),e.error("Rejecting promises with the result is deprecated. Please use the resolve callback instead."),b.error=a})}):a},new e.Promise(function(a){a()}))},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 e.isNumber(a)&&a%1===0},isObject:function(a){return a===Object(a)},isDate:function(a){return a instanceof Date},isDefined:function(a){return null!==a&&void 0!==a},isPromise:function(a){return!!a&&e.isFunction(a.then)},isJqueryElement:function(a){return a&&e.isString(a.jquery)},isDomElement:function(a){return a&&e.isFunction(a.querySelectorAll)&&e.isFunction(a.querySelector)?e.isObject(document)&&a===document?!0:"object"==typeof HTMLElement?a instanceof HTMLElement:a&&"object"==typeof a&&null!==a&&1===a.nodeType&&"string"==typeof a.nodeName:!1},isEmpty:function(a){var b;if(!e.isDefined(a))return!0;if(e.isFunction(a))return!1;if(e.isString(a))return e.EMPTY_STRING_REGEXP.test(a);if(e.isArray(a))return 0===a.length;if(e.isDate(a))return!1;if(e.isObject(a)){for(b in a)return!1;return!0}return!1},format:e.extend(function(a,b){return a.replace(e.format.FORMAT_REGEXP,function(a,c,d){return"%"===c?"%{"+d+"}":String(b[d])})},{FORMAT_REGEXP:/(%?)%\{([^\}]+)\}/g}),prettify:function(a){return e.isNumber(a)?100*a%1===0?""+a:parseFloat(Math.round(100*a)/100).toFixed(2):e.isArray(a)?a.map(function(a){return e.prettify(a)}).join(", "):e.isObject(a)?a.toString():(a=""+a,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())},stringifyValue:function(a){return e.prettify(a)},isString:function(a){return"string"==typeof a},isArray:function(a){return"[object Array]"==={}.toString.call(a)},contains:function(a,b){return e.isDefined(a)?e.isArray(a)?-1!==a.indexOf(b):b in a:!1},forEachKeyInKeypath:function(a,b,c){if(!e.isString(b))return void 0;var d,f="",g=!1;for(d=0;d<b.length;++d)switch(b[d]){case".":g?(g=!1,f+="."):(a=c(a,f,!1),f="");break;case"\\":g?(g=!1,f+="\\"):g=!0;break;default:g=!1,f+=b[d]}return c(a,f,!0)},getDeepObjectValue:function(a,b){return e.isObject(a)?e.forEachKeyInKeypath(a,b,function(a,b){return e.isObject(a)?a[b]:void 0}):void 0},collectFormValues:function(a,b){var c,d,f,g,h={};if(e.isJqueryElement(a)&&(a=a[0]),!a)return h;for(b=b||{},f=a.querySelectorAll("input[name], textarea[name]"),c=0;c<f.length;++c)d=f.item(c),e.isDefined(d.getAttribute("data-ignored"))||(g=e.sanitizeFormValue(d.value,b),"number"===d.type?g=+g:"checkbox"===d.type?d.attributes.value?d.checked||(g=h[d.name]||null):g=d.checked:"radio"===d.type&&(d.checked||(g=h[d.name]||null)),h[d.name]=g);for(f=a.querySelectorAll("select[name]"),c=0;c<f.length;++c)d=f.item(c),g=e.sanitizeFormValue(d.options[d.selectedIndex].value,b),h[d.name]=g;return h},sanitizeFormValue:function(a,b){return b.trim&&e.isString(a)&&(a=a.trim()),b.nullify!==!1&&""===a?null:a},capitalize:function(a){return e.isString(a)?a[0].toUpperCase()+a.slice(1):a},pruneEmptyErrors:function(a){return a.filter(function(a){return!e.isEmpty(a.error)})},expandMultipleErrors:function(a){var b=[];return a.forEach(function(a){e.isArray(a.error)?a.error.forEach(function(c){b.push(e.extend({},a,{error:c}))}):b.push(a)}),b},convertErrorMessages:function(a,b){b=b||{};var c=[];return a.forEach(function(a){var d=a.error;"^"===d[0]?d=d.slice(1):b.fullMessages!==!1&&(d=e.capitalize(e.prettify(a.attribute))+" "+d),d=d.replace(/\\\^/g,"^"),d=e.format(d,{value:e.stringifyValue(a.value)}),c.push(e.extend({},a,{error:d}))}),c},groupErrorsByAttribute:function(a){var b={};return a.forEach(function(a){var c=b[a.attribute];c?c.push(a):b[a.attribute]=[a]}),b},flattenErrorsToArray:function(a){return a.map(function(a){return a.error})},cleanAttributes:function(a,b){function c(a,b,c){return e.isObject(a[b])?a[b]:a[b]=c?!0:{}}function d(a){var b,d={};for(b in a)a[b]&&e.forEachKeyInKeypath(d,b,c);return d}function f(a,b){if(!e.isObject(a))return a;var c,d,g=e.extend({},a);for(d in a)c=b[d],e.isObject(c)?g[d]=f(g[d],c):c||delete g[d];return g}return e.isObject(b)&&e.isObject(a)?(b=d(b),f(a,b)):{}},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([],function(){return a}))},warn:function(a){"undefined"!=typeof console&&console.warn&&console.warn("[validate.js] "+a)},error:function(a){"undefined"!=typeof console&&console.error&&console.error("[validate.js] "+a)}}),d.validators={presence:function(a,b){return b=e.extend({},this.options,b),e.isEmpty(a)?b.message||this.message||"can't be blank":void 0},length:function(a,b,c){if(!e.isEmpty(a)){b=e.extend({},this.options,b);var d,f=b.is,g=b.maximum,h=b.minimum,i=b.tokenizer||function(a){return a},j=[];a=i(a);var k=a.length;return e.isNumber(k)?(e.isNumber(f)&&k!==f&&(d=b.wrongLength||this.wrongLength||"is the wrong length (should be %{count} characters)",j.push(e.format(d,{count:f}))),e.isNumber(h)&&h>k&&(d=b.tooShort||this.tooShort||"is too short (minimum is %{count} characters)",j.push(e.format(d,{count:h}))),e.isNumber(g)&&k>g&&(d=b.tooLong||this.tooLong||"is too long (maximum is %{count} characters)",j.push(e.format(d,{count:g}))),j.length>0?b.message||j:void 0):(e.error(e.format("Attribute %{attr} has a non numeric value for `length`",{attr:c})),b.message||this.notValid||"has an incorrect length")}},numericality:function(a,b){if(!e.isEmpty(a)){b=e.extend({},this.options,b);var c,d,f=[],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&&e.isString(a)&&(a=+a),!e.isNumber(a))return b.message||this.notValid||"is not a number";if(b.onlyInteger&&!e.isInteger(a))return b.message||this.notInteger||"must be an integer";for(c in g)if(d=b[c],e.isNumber(d)&&!g[c](a,d)){var h=this["not"+e.capitalize(c)]||"must be %{type} %{count}";f.push(e.format(h,{count:d,type:e.prettify(c)}))}return b.odd&&a%2!==1&&f.push(this.notOdd||"must be odd"),b.even&&a%2!==0&&f.push(this.notEven||"must be even"),f.length?b.message||f:void 0}},datetime:e.extend(function(a,b){if(!e.isEmpty(a)){b=e.extend({},this.options,b);var c,d=[],f=b.earliest?this.parse(b.earliest,b):0/0,g=b.latest?this.parse(b.latest,b):0/0;return a=this.parse(a,b),isNaN(a)||b.dateOnly&&a%864e5!==0?b.message||this.notValid||"must be a valid date":(!isNaN(f)&&f>a&&(c=this.tooEarly||"must be no earlier than %{date}",c=e.format(c,{date:this.format(f,b)}),d.push(c)),!isNaN(g)&&a>g&&(c=this.tooLate||"must be no later than %{date}",c=e.format(c,{date:this.format(g,b)}),d.push(c)),d.length?b.message||d:void 0)}},{parse:function(a,b){if(e.isFunction(e.XDate))return new e.XDate(a,!0).getTime();if(e.isDefined(e.moment))return+e.moment.utc(a);throw new Error("Neither XDate or moment.js was found")},format:function(a,b){var c=b.dateFormat;if(e.isFunction(e.XDate))return c=c||(b.dateOnly?"yyyy-MM-dd":"yyyy-MM-dd HH:mm:ss"),new e.XDate(a,!0).toString(c);if(e.isDefined(e.moment))return c=c||(b.dateOnly?"YYYY-MM-DD":"YYYY-MM-DD HH:mm:ss"),e.moment.utc(a).format(c);throw new Error("Neither XDate or moment.js was found")}}),date:function(a,b){return b=e.extend({},b,{dateOnly:!0}),e.validators.datetime.call(e.validators.datetime,a,b)},format:function(a,b){(e.isString(b)||b instanceof RegExp)&&(b={pattern:b}),b=e.extend({},this.options,b);var c,d=b.message||this.message||"is invalid",f=b.pattern;return e.isEmpty(a)?void 0:e.isString(a)?(e.isString(f)&&(f=new RegExp(b.pattern,b.flags)),c=f.exec(a),c&&c[0].length==a.length?void 0:d):d},inclusion:function(a,b){if(!e.isEmpty(a)&&(e.isArray(b)&&(b={within:b}),b=e.extend({},this.options,b),!e.contains(b.within,a))){var c=b.message||this.message||"^%{value} is not included in the list";return e.format(c,{value:a})}},exclusion:function(a,b){if(!e.isEmpty(a)&&(e.isArray(b)&&(b={within:b}),b=e.extend({},this.options,b),e.contains(b.within,a))){var c=b.message||this.message||"^%{value} is restricted";return e.format(c,{value:a})}},email:e.extend(function(a,b){b=e.extend({},this.options,b);var c=b.message||this.message||"is not a valid email";if(!e.isEmpty(a))return e.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}),equality:function(a,b,c,d){if(!e.isEmpty(a)){e.isString(b)&&(b={attribute:b}),b=e.extend({},this.options,b);var f=b.message||this.message||"is not equal to %{attribute}";if(e.isEmpty(b.attribute)||!e.isString(b.attribute))throw new Error("The attribute must be a non empty string");var g=e.getDeepObjectValue(d,b.attribute),h=b.comparator||function(a,b){return a===b};return h(a,g,b,c,d)?void 0:e.format(f,{attribute:e.prettify(b.attribute)})}}},d.exposeModule(d,this,a,b,c)}).call(this,"undefined"!=typeof exports?exports:null,"undefined"!=typeof module?module:null,"undefined"!=typeof define?define:null); | ||
(function(a,b,c){"use strict";var d=function(a,b,c){c=e.extend({},e.options,c);var f,g,h=e.runValidations(a,b,c);for(f in h)for(g in h[f])if(e.isPromise(h[f][g]))throw new Error("Use validate.async if you want support for promises");return d.processValidationResults(h,c)},e=d;e.extend=function(a){return[].slice.call(arguments,1).forEach(function(b){for(var c in b)a[c]=b[c]}),a},e.extend(d,{version:{major:0,minor:9,patch:0,metadata:null,toString:function(){var a=e.format("%{major}.%{minor}.%{patch}",e.version);return e.isEmpty(e.version.metadata)||(a+="+"+e.version.metadata),a}},Promise:"undefined"!=typeof Promise?Promise:null,EMPTY_STRING_REGEXP:/^\s*$/,runValidations:function(a,b,c){var d,f,g,h,i,j,k,l=[];(e.isDomElement(a)||e.isJqueryElement(a))&&(a=e.collectFormValues(a));for(d in b){g=e.getDeepObjectValue(a,d),h=e.result(b[d],g,a,d,c,b);for(f in h){if(i=e.validators[f],!i)throw k=e.format("Unknown validator %{name}",{name:f}),new Error(k);j=h[f],j=e.result(j,g,a,d,c,b),j&&l.push({attribute:d,value:g,validator:f,globalOptions:c,attributes:a,options:j,error:i.call(i,g,j,d,a,c)})}}return l},processValidationResults:function(a,b){var c;switch(a=e.pruneEmptyErrors(a,b),a=e.expandMultipleErrors(a,b),a=e.convertErrorMessages(a,b),b.format||"grouped"){case"detailed":break;case"flat":a=e.flattenErrorsToArray(a);break;case"grouped":a=e.groupErrorsByAttribute(a);for(c in a)a[c]=e.flattenErrorsToArray(a[c]);break;default:throw new Error(e.format("Unknown format %{format}",b))}return e.isEmpty(a)?void 0:a},async:function(a,b,c){c=e.extend({},e.async.options,c);var d=c.wrapErrors||function(a){return a};c.cleanAttributes!==!1&&(a=e.cleanAttributes(a,b));var f=e.runValidations(a,b,c);return new e.Promise(function(g,h){e.waitForResults(f).then(function(){var i=e.processValidationResults(f,c);i?h(new d(i,c,a,b)):g(a)},function(a){h(a)})})},single:function(a,b,c){return c=e.extend({},e.single.options,c,{format:"flat",fullMessages:!1}),e({single:a},{single:b},c)},waitForResults:function(a){return a.reduce(function(a,b){return e.isPromise(b.error)?a.then(function(){return b.error.then(function(a){b.error=a||null},function(a){if(a instanceof Error)throw a;e.error("Rejecting promises with the result is deprecated. Please use the resolve callback instead."),b.error=a})}):a},new e.Promise(function(a){a()}))},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 e.isNumber(a)&&a%1===0},isObject:function(a){return a===Object(a)},isDate:function(a){return a instanceof Date},isDefined:function(a){return null!==a&&void 0!==a},isPromise:function(a){return!!a&&e.isFunction(a.then)},isJqueryElement:function(a){return a&&e.isString(a.jquery)},isDomElement:function(a){return a&&e.isFunction(a.querySelectorAll)&&e.isFunction(a.querySelector)?e.isObject(document)&&a===document?!0:"object"==typeof HTMLElement?a instanceof HTMLElement:a&&"object"==typeof a&&null!==a&&1===a.nodeType&&"string"==typeof a.nodeName:!1},isEmpty:function(a){var b;if(!e.isDefined(a))return!0;if(e.isFunction(a))return!1;if(e.isString(a))return e.EMPTY_STRING_REGEXP.test(a);if(e.isArray(a))return 0===a.length;if(e.isDate(a))return!1;if(e.isObject(a)){for(b in a)return!1;return!0}return!1},format:e.extend(function(a,b){return e.isString(a)?a.replace(e.format.FORMAT_REGEXP,function(a,c,d){return"%"===c?"%{"+d+"}":String(b[d])}):a},{FORMAT_REGEXP:/(%?)%\{([^\}]+)\}/g}),prettify:function(a){return e.isNumber(a)?100*a%1===0?""+a:parseFloat(Math.round(100*a)/100).toFixed(2):e.isArray(a)?a.map(function(a){return e.prettify(a)}).join(", "):e.isObject(a)?a.toString():(a=""+a,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())},stringifyValue:function(a){return e.prettify(a)},isString:function(a){return"string"==typeof a},isArray:function(a){return"[object Array]"==={}.toString.call(a)},contains:function(a,b){return e.isDefined(a)?e.isArray(a)?-1!==a.indexOf(b):b in a:!1},forEachKeyInKeypath:function(a,b,c){if(!e.isString(b))return void 0;var d,f="",g=!1;for(d=0;d<b.length;++d)switch(b[d]){case".":g?(g=!1,f+="."):(a=c(a,f,!1),f="");break;case"\\":g?(g=!1,f+="\\"):g=!0;break;default:g=!1,f+=b[d]}return c(a,f,!0)},getDeepObjectValue:function(a,b){return e.isObject(a)?e.forEachKeyInKeypath(a,b,function(a,b){return e.isObject(a)?a[b]:void 0}):void 0},collectFormValues:function(a,b){var c,d,f,g,h={};if(e.isJqueryElement(a)&&(a=a[0]),!a)return h;for(b=b||{},f=a.querySelectorAll("input[name], textarea[name]"),c=0;c<f.length;++c)d=f.item(c),e.isDefined(d.getAttribute("data-ignored"))||(g=e.sanitizeFormValue(d.value,b),"number"===d.type?g=g?+g:null:"checkbox"===d.type?d.attributes.value?d.checked||(g=h[d.name]||null):g=d.checked:"radio"===d.type&&(d.checked||(g=h[d.name]||null)),h[d.name]=g);for(f=a.querySelectorAll("select[name]"),c=0;c<f.length;++c)d=f.item(c),g=e.sanitizeFormValue(d.options[d.selectedIndex].value,b),h[d.name]=g;return h},sanitizeFormValue:function(a,b){return b.trim&&e.isString(a)&&(a=a.trim()),b.nullify!==!1&&""===a?null:a},capitalize:function(a){return e.isString(a)?a[0].toUpperCase()+a.slice(1):a},pruneEmptyErrors:function(a){return a.filter(function(a){return!e.isEmpty(a.error)})},expandMultipleErrors:function(a){var b=[];return a.forEach(function(a){e.isArray(a.error)?a.error.forEach(function(c){b.push(e.extend({},a,{error:c}))}):b.push(a)}),b},convertErrorMessages:function(a,b){b=b||{};var c=[];return a.forEach(function(a){var d=e.result(a.error,a.value,a.attribute,a.options,a.attributes,a.globalOptions);return e.isString(d)?("^"===d[0]?d=d.slice(1):b.fullMessages!==!1&&(d=e.capitalize(e.prettify(a.attribute))+" "+d),d=d.replace(/\\\^/g,"^"),d=e.format(d,{value:e.stringifyValue(a.value)}),void c.push(e.extend({},a,{error:d}))):void c.push(a)}),c},groupErrorsByAttribute:function(a){var b={};return a.forEach(function(a){var c=b[a.attribute];c?c.push(a):b[a.attribute]=[a]}),b},flattenErrorsToArray:function(a){return a.map(function(a){return a.error})},cleanAttributes:function(a,b){function c(a,b,c){return e.isObject(a[b])?a[b]:a[b]=c?!0:{}}function d(a){var b,d={};for(b in a)a[b]&&e.forEachKeyInKeypath(d,b,c);return d}function f(a,b){if(!e.isObject(a))return a;var c,d,g=e.extend({},a);for(d in a)c=b[d],e.isObject(c)?g[d]=f(g[d],c):c||delete g[d];return g}return e.isObject(b)&&e.isObject(a)?(b=d(b),f(a,b)):{}},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([],function(){return a}))},warn:function(a){"undefined"!=typeof console&&console.warn&&console.warn("[validate.js] "+a)},error:function(a){"undefined"!=typeof console&&console.error&&console.error("[validate.js] "+a)}}),d.validators={presence:function(a,b){return b=e.extend({},this.options,b),e.isEmpty(a)?b.message||this.message||"can't be blank":void 0},length:function(a,b,c){if(!e.isEmpty(a)){b=e.extend({},this.options,b);var d,f=b.is,g=b.maximum,h=b.minimum,i=b.tokenizer||function(a){return a},j=[];a=i(a);var k=a.length;return e.isNumber(k)?(e.isNumber(f)&&k!==f&&(d=b.wrongLength||this.wrongLength||"is the wrong length (should be %{count} characters)",j.push(e.format(d,{count:f}))),e.isNumber(h)&&h>k&&(d=b.tooShort||this.tooShort||"is too short (minimum is %{count} characters)",j.push(e.format(d,{count:h}))),e.isNumber(g)&&k>g&&(d=b.tooLong||this.tooLong||"is too long (maximum is %{count} characters)",j.push(e.format(d,{count:g}))),j.length>0?b.message||j:void 0):(e.error(e.format("Attribute %{attr} has a non numeric value for `length`",{attr:c})),b.message||this.notValid||"has an incorrect length")}},numericality:function(a,b){if(!e.isEmpty(a)){b=e.extend({},this.options,b);var c,d,f=[],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&&e.isString(a)&&(a=+a),!e.isNumber(a))return b.message||b.notValid||this.notValid||"is not a number";if(b.onlyInteger&&!e.isInteger(a))return b.message||b.notInteger||this.notInteger||"must be an integer";for(c in g)if(d=b[c],e.isNumber(d)&&!g[c](a,d)){var h="not"+e.capitalize(c),i=b[h]||this[h]||"must be %{type} %{count}";f.push(e.format(i,{count:d,type:e.prettify(c)}))}return b.odd&&a%2!==1&&f.push(b.notOdd||this.notOdd||"must be odd"),b.even&&a%2!==0&&f.push(b.notEven||this.notEven||"must be even"),f.length?b.message||f:void 0}},datetime:e.extend(function(a,b){if(!e.isFunction(this.parse)||!e.isFunction(this.format))throw new Error("Both the parse and format functions needs to be set to use the datetime/date validator");if(!e.isEmpty(a)){b=e.extend({},this.options,b);var c,d=[],f=b.earliest?this.parse(b.earliest,b):0/0,g=b.latest?this.parse(b.latest,b):0/0;return a=this.parse(a,b),isNaN(a)||b.dateOnly&&a%864e5!==0?b.message||this.notValid||"must be a valid date":(!isNaN(f)&&f>a&&(c=this.tooEarly||"must be no earlier than %{date}",c=e.format(c,{date:this.format(f,b)}),d.push(c)),!isNaN(g)&&a>g&&(c=this.tooLate||"must be no later than %{date}",c=e.format(c,{date:this.format(g,b)}),d.push(c)),d.length?b.message||d:void 0)}},{parse:null,format:null}),date:function(a,b){return b=e.extend({},b,{dateOnly:!0}),e.validators.datetime.call(e.validators.datetime,a,b)},format:function(a,b){(e.isString(b)||b instanceof RegExp)&&(b={pattern:b}),b=e.extend({},this.options,b);var c,d=b.message||this.message||"is invalid",f=b.pattern;return e.isEmpty(a)?void 0:e.isString(a)?(e.isString(f)&&(f=new RegExp(b.pattern,b.flags)),c=f.exec(a),c&&c[0].length==a.length?void 0:d):d},inclusion:function(a,b){if(!e.isEmpty(a)&&(e.isArray(b)&&(b={within:b}),b=e.extend({},this.options,b),!e.contains(b.within,a))){var c=b.message||this.message||"^%{value} is not included in the list";return e.format(c,{value:a})}},exclusion:function(a,b){if(!e.isEmpty(a)&&(e.isArray(b)&&(b={within:b}),b=e.extend({},this.options,b),e.contains(b.within,a))){var c=b.message||this.message||"^%{value} is restricted";return e.format(c,{value:a})}},email:e.extend(function(a,b){b=e.extend({},this.options,b);var c=b.message||this.message||"is not a valid email";if(!e.isEmpty(a))return e.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}),equality:function(a,b,c,d){if(!e.isEmpty(a)){e.isString(b)&&(b={attribute:b}),b=e.extend({},this.options,b);var f=b.message||this.message||"is not equal to %{attribute}";if(e.isEmpty(b.attribute)||!e.isString(b.attribute))throw new Error("The attribute must be a non empty string");var g=e.getDeepObjectValue(d,b.attribute),h=b.comparator||function(a,b){return a===b};return h(a,g,b,c,d)?void 0:e.format(f,{attribute:e.prettify(b.attribute)})}},url:function(a,b){if(!e.isEmpty(a)){b=e.extend({},this.options,b);var c=b.message||this.message||"is not a valid url",d=b.schemes||this.schemes||["http","https"],f=b.allowLocal||this.allowLocal||!1;if(!e.isString(a))return c;var g="^(?:(?:"+d.join("|")+"):\\/\\/)(?:\\S+(?::\\S*)?@)?";g+="(?:";var h="(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))";f?h="(?:localhost|"+h+")":g+="(?!10(?:\\.\\d{1,3}){3})(?!127(?:\\.\\d{1,3}){3})(?!169\\.254(?:\\.\\d{1,3}){2})(?!192\\.168(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})",g+="(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|"+h+"(?::\\d{2,5})?(?:\\/[^\\s]*)?$";var i=new RegExp(g,"i");return i.exec(a)?void 0:c}}},d.exposeModule(d,this,a,b,c)}).call(this,"undefined"!=typeof exports?exports:null,"undefined"!=typeof module?module:null,"undefined"!=typeof define?define: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
963736
8220