koa-validator
Advanced tools
Comparing version 0.5.0 to 0.5.2
@@ -62,3 +62,3 @@ var validator = require('validator') | ||
// validator.js will convert the first param to string | ||
if(d === ''){ | ||
if(d === '' && value !== undefined){ | ||
return value; | ||
@@ -65,0 +65,0 @@ }else{ |
{ | ||
"name": "koa-validator", | ||
"version": "0.5.0", | ||
"version": "0.5.2", | ||
"description": "a koa port of express-validator", | ||
@@ -16,3 +16,2 @@ "main": "index.js", | ||
"devDependencies": { | ||
"async": "^0.9.0", | ||
"chai": "^1.9.1", | ||
@@ -19,0 +18,0 @@ "koa": "^0.10.0", |
@@ -5,3 +5,2 @@ var koa = require('koa') | ||
, router = require('koa-router') | ||
, async = require('async') | ||
@@ -20,3 +19,5 @@ , validator = require('..') | ||
it("these validates should be to ok" , function(done){ | ||
var app = createApp(); | ||
var app = createApp() | ||
, errors | ||
; | ||
app.post('/validate',function*(){ | ||
@@ -72,4 +73,4 @@ this.checkBody('name').notEmpty().len(3,20); | ||
this.checkBody('sp').isSurrogatePair(); | ||
if(this._validationErrors){ | ||
this.body = this._validationErrors; | ||
if(errors = this.validationErrors()){ | ||
this.body = errors; | ||
return; | ||
@@ -132,3 +133,5 @@ } | ||
it("these validates fail tests should be to ok" , function(done){ | ||
var app = createApp(); | ||
var app = createApp() | ||
, errors | ||
; | ||
app.post('/validate',function*(){ | ||
@@ -183,8 +186,16 @@ this.checkBody('name').notEmpty().len(3,20); | ||
this.checkBody('sp').isSurrogatePair(); | ||
if(this._validationErrors.length === 48){ | ||
this.body = this._validationErrors; | ||
this.body = 'ok'; | ||
return ; | ||
errors = this.validationErrors(); | ||
if(errors){ | ||
if(errors.length === 48){ | ||
this.body = 'ok'; | ||
return; | ||
}else{ | ||
this.body = 'only ' + errors.length + ' errors'; | ||
return; | ||
} | ||
}else{ | ||
this.body = 'there is no error'; | ||
return; | ||
} | ||
this.body= 'only '+this._validationErrors.length+' errors'; | ||
}); | ||
@@ -244,8 +255,10 @@ var req = request(app.listen()); | ||
it('there validate query should be to okay' , function(done){ | ||
var app = createApp(); | ||
var app = createApp() | ||
, errors | ||
; | ||
app.get('/query',function*(){ | ||
this.checkQuery('name').notEmpty(); | ||
this.checkQuery('password').len(3,20); | ||
if(this.errors){ | ||
this.body = this.errors; | ||
if(errors = this.validationErrors()){ | ||
this.body = errors; | ||
return; | ||
@@ -265,7 +278,9 @@ } | ||
it('there validate params should be to okay' , function(done){ | ||
var app = createApp(); | ||
var app = createApp() | ||
, errors | ||
; | ||
app.get('/:id',function*(){ | ||
this.checkParams('id').isInt(); | ||
if(this._validationErrors){ | ||
this.body = this._validationErrors; | ||
if(errors = this.validationErrors()){ | ||
this.body = errors; | ||
return; | ||
@@ -272,0 +287,0 @@ } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
26091
6
720
0