async-validate
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -9,4 +9,7 @@ /** | ||
whitespace: '%s cannot be empty', | ||
dateformat: "%s date %s is invalid for format %s", | ||
date: "%s date %s is invalid", | ||
date: { | ||
format: "%s date %s is invalid for format %s", | ||
parse: "%s date could not be parsed, %s is invalid ", | ||
invalid: "%s date %s is invalid" | ||
}, | ||
types: { | ||
@@ -13,0 +16,0 @@ string: '%s is not a %s', |
@@ -17,10 +17,17 @@ var util = require('util'); | ||
var date = function(rule, value, source, errors, options) { | ||
var dt = rule.format ? moment(value, rule.format) : moment(value); | ||
if(!dt.isValid()) { | ||
if(!rule.required | ||
&& (value == undefined || value == "")) { | ||
return false; | ||
} | ||
var dt = moment(value, rule.format); | ||
if(!dt) { | ||
errors.push(error(rule, | ||
util.format(options.messages.date.parse, rule.field, value))); | ||
}else if(!dt.isValid()) { | ||
if(rule.format) { | ||
errors.push(error(rule, | ||
util.format(options.messages.dateformat, rule.field, value, rule.format))); | ||
util.format(options.messages.date.format, rule.field, value, rule.format))); | ||
}else{ | ||
errors.push(error(rule, | ||
util.format(options.messages.date, rule.field, value))); | ||
util.format(options.messages.date.invalid, rule.field, value))); | ||
} | ||
@@ -27,0 +34,0 @@ } |
@@ -16,4 +16,5 @@ var rules = require('../rule'); | ||
var validate = rule.required | ||
|| (!rule.required && source.hasOwnProperty(rule.field)); | ||
|| (!rule.required && source.hasOwnProperty(rule.field) && source[rule.field]); | ||
if(validate) { | ||
console.log("Validating date %s with value: %s", rule.field, value); | ||
rules.required(rule, value, source, errors, options); | ||
@@ -20,0 +21,0 @@ rules.pattern(rule, value, source, errors, options); |
{ | ||
"name": "async-validate", | ||
"description": "Asynchronous validation for object properties.", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"author": "muji <noop@xpm.io>", | ||
@@ -6,0 +6,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74372
1714