async-validate
Advanced tools
Comparing version 0.2.2 to 0.2.4
@@ -5,2 +5,6 @@ /** | ||
function ValidationError(msg) { | ||
Error.call(this); | ||
//if(!(this instanceof ValidationError)) { | ||
//return new ValidationError(msg); | ||
//} | ||
this.message = msg || this.name; | ||
@@ -7,0 +11,0 @@ } |
var iterator = require('./iterator') | ||
, format = require('./format') | ||
, validators = require('./validator') | ||
, ValidationError = require('./error') | ||
, error = require('./rule').error; | ||
, Validator = require('./validator') | ||
, error = Validator.Type.error | ||
, ValidationError = require('./error'); | ||
@@ -175,3 +175,3 @@ /** | ||
function getValidationOptions(rule, data, options, cb) { | ||
return { | ||
return Validator({ | ||
callback: cb, | ||
@@ -185,3 +185,3 @@ rule: rule, | ||
messages: options.messages | ||
} | ||
}); | ||
} | ||
@@ -199,2 +199,5 @@ | ||
} | ||
// validator plugin functions are static methods | ||
var validators = Validator; | ||
if(typeof(rule.validator) !== 'function' | ||
@@ -213,2 +216,4 @@ && (!rule.type || !validators.hasOwnProperty(rule.type))) { | ||
function getValidationMethod(rule) { | ||
// validator plugin functions are static methods | ||
var validators = Validator; | ||
if(typeof rule.validator === 'function') { | ||
@@ -226,4 +231,2 @@ return rule.validator; | ||
module.exports = Schema; | ||
/** | ||
@@ -237,3 +240,3 @@ * Register a validator function for a type. | ||
*/ | ||
module.exports.register = function(type, validator) { | ||
function register(type, validator) { | ||
if(typeof validator !== 'function') { | ||
@@ -243,5 +246,13 @@ throw new Error( | ||
} | ||
// validator plugin functions are static methods | ||
var validators = Validator; | ||
validators[type] = validator; | ||
} | ||
module.exports.ValidationError = ValidationError; | ||
Schema.Validator = Validator; | ||
// simpler plugin access | ||
Schema.plugin = Validator.plugin; | ||
Schema.ValidationError = ValidationError; | ||
Schema.register = register; | ||
module.exports = Schema; |
{ | ||
"name": "async-validate", | ||
"description": "Asynchronous validation for object properties.", | ||
"version": "0.2.2", | ||
"version": "0.2.4", | ||
"author": "muji <noop@xpm.io>", | ||
"license": "MIT", | ||
"repository": { | ||
@@ -17,3 +18,3 @@ "type": "git", | ||
"dependencies": { | ||
"moment": "~2.10.6" | ||
"zephyr": "~1.3.2" | ||
}, | ||
@@ -25,2 +26,3 @@ "devDependencies": { | ||
"mocha": "~2.2.5", | ||
"moment": "~2.10.6", | ||
"validator": "~4.0.1" | ||
@@ -31,5 +33,5 @@ }, | ||
"clean": "rm -rf coverage", | ||
"test": "NODE_ENV=test mocha ${SPEC:-test/spec}", | ||
"cover": "NODE_ENV=test istanbul cover _mocha -- ${SPEC:-test/spec}" | ||
"test": "NODE_ENV=test mocha test/global ${SPEC:-test/spec}", | ||
"cover": "NODE_ENV=test istanbul cover _mocha -- test/global ${SPEC:-test/spec}" | ||
} | ||
} |
@@ -8,6 +8,6 @@ # async-validate | ||
``` | ||
npm install async-validate | ||
npm i async-validate | ||
``` | ||
## Unit Tests | ||
## Test | ||
@@ -26,2 +26,20 @@ ``` | ||
Note that as of the `0.2.x` series, this module no longer ships any built in type validators, you need to call `plugin()`, for example to load all plugins (backward compatibility): | ||
``` | ||
require('async-validate/plugin/all'); | ||
``` | ||
Otherwise only load the validators for the types you are using: | ||
``` | ||
var schema = require('async-validate'); | ||
schema.plugin([ | ||
require('async-validate/plugin/array'), | ||
require('async-validate/plugin/boolean'), | ||
require('async-validate/plugin/number'), | ||
require('async-validate/plugin/string') | ||
]) | ||
``` | ||
Basic usage involves defining a descriptor, assigning it to a schema and passing the object to be validated and a callback function to the `validate` method of the schema: | ||
@@ -28,0 +46,0 @@ |
Sorry, the diff of this file is not supported yet
81382
430
6
46
2053
+ Addedzephyr@~1.3.2
+ Addedzephyr@1.3.6(transitive)
- Removedmoment@~2.10.6
- Removedmoment@2.10.6(transitive)