schema-inspector
Advanced tools
Comparing version 1.5.4 to 1.5.5
@@ -1155,4 +1155,5 @@ /* | ||
this.result = function () { | ||
this.result = function (data) { | ||
return { | ||
data: data, | ||
reporting: _reporting, | ||
@@ -1177,10 +1178,10 @@ format: function () { | ||
var self = this; | ||
return this._asyncSanitize(this._schema, post, function (err) { | ||
return this._asyncSanitize(this._schema, post, function (err, data) { | ||
self.origin = null; | ||
callback(err, self.result()); | ||
callback(err, self.result(data)); | ||
}); | ||
} | ||
this._sanitize(this._schema, post); | ||
var data = this._sanitize(this._schema, post); | ||
this.origin = null; | ||
return this.result(); | ||
return this.result(data); | ||
}; | ||
@@ -1187,0 +1188,0 @@ |
{ | ||
"name": "schema-inspector", | ||
"description": "Schema-Inspector is a powerful tool to sanitize and validate JS objects.", | ||
"version": "1.5.4", | ||
"version": "1.5.5", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -762,3 +762,3 @@ [![schema-inspector logo](https://raw.githubusercontent.com/Atinux/schema-inspector/master/misc/schema-inspector.png)](http://atinux.github.io/schema-inspector/) | ||
/* | ||
c: [ '12.23', '-34', 'true', 'false', 'true', 'false', '123,234,345', '{"obj":"yes"}' ] | ||
r.data: [ '12.23', '-34', 'true', 'false', 'true', 'false', '123,234,345', '{"obj":"yes"}' ] | ||
*/ | ||
@@ -800,3 +800,3 @@ ``` | ||
/* | ||
c: { | ||
r.data: { | ||
lorem: 10, | ||
@@ -838,3 +838,3 @@ ipsum: 'NikitaJS', | ||
/* | ||
c: { | ||
r.data: { | ||
lorem: 12 // Only lorem is set to 12 because it is not optional. | ||
@@ -885,3 +885,3 @@ } | ||
/* | ||
c: { | ||
r.data: { | ||
lorem: ' THIS IS SPARTA! ', | ||
@@ -921,3 +921,3 @@ ipsum: 'This Is Sparta!' // has been trimed, then titled | ||
/* | ||
c: [10, 10, 15, 20, 20] | ||
r.data: [10, 10, 15, 20, 20] | ||
c[0] (5) was less than min (10), so it's been set to 10. | ||
@@ -954,3 +954,3 @@ c[4] (25) was greater than max (20), so it's been set to 20. | ||
/* | ||
c: ['short---', 'mediumSize', 'tooLongForT'] | ||
r.data: ['short---', 'mediumSize', 'tooLongForT'] | ||
*/ | ||
@@ -990,3 +990,3 @@ ``` | ||
/* | ||
c: { | ||
r.data: { | ||
good: 'yes' | ||
@@ -1035,3 +1035,3 @@ } | ||
/* | ||
c: [ 'Nikita', '_INVALID_', 'NIKITA', '_INVALID_' ] | ||
r.data: [ 'Nikita', '_INVALID_', 'NIKITA', '_INVALID_' ] | ||
*/ | ||
@@ -1038,0 +1038,0 @@ ``` |
@@ -140,2 +140,11 @@ var should = require('should'); | ||
test('candidate #4 | string -> integer', function () { | ||
var result = si.sanitize({ type: 'integer' }, '42'); | ||
result.should.be.an.Object; | ||
result.should.have.property('reporting').with.be.an.instanceof(Array) | ||
.and.be.lengthOf(1); | ||
result.reporting[0].property.should.be.equal('@'); | ||
result.data.should.be.eql(42); | ||
}); | ||
}); // suite "schema #2" | ||
@@ -361,2 +370,11 @@ | ||
test('candidate #2', function () { | ||
var result = si.sanitize({ type: 'array', optional: false, def: [], items: { type: 'object' } }, { prop: 'value' }); | ||
result.should.be.an.Object; | ||
result.should.have.property('reporting').with.be.an.instanceof(Array) | ||
.and.be.lengthOf(1); | ||
result.reporting[0].property.should.be.equal('@'); | ||
result.data.should.eql([ { prop: 'value' } ]); | ||
}); | ||
}); // suite "schema #7" | ||
@@ -917,2 +935,27 @@ | ||
}); | ||
test('candidate #4', function (done) { | ||
var customSchema = { | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
properties: { | ||
prop: { | ||
exec: function (schema, post, cb) { | ||
cb(null, 'coucou'); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
si.sanitize(customSchema, { prop: 'value' }, function (err, result) { | ||
should.not.exist(err); | ||
result.should.be.an.Object; | ||
result.should.have.property('reporting').with.be.an.instanceof(Array) | ||
.and.be.lengthOf(1); | ||
result.reporting[0].property.should.be.equal('@'); | ||
result.data.should.be.eql([ { prop: 'coucou' } ]); | ||
done(); | ||
}); | ||
}); | ||
}); // suite "schema #16" | ||
@@ -919,0 +962,0 @@ |
305086
5453