revalidator
Advanced tools
Comparing version 0.1.3 to 0.1.5
@@ -197,7 +197,7 @@ (function (exports) { | ||
// see 5.4 | ||
if (schema.additionalProperties) { | ||
if (undefined !== schema.additionalProperties) { | ||
var i, l; | ||
var unvisitedProps = allProps.filter(function(k){ | ||
return (visitedProps.indexOf(k) > 0); | ||
return -1 === visitedProps.indexOf(k); | ||
}); | ||
@@ -241,2 +241,18 @@ | ||
if (options.cast) { | ||
if (('integer' === schema.type || 'number' === schema.type) && value == +value) { | ||
value = +value; | ||
} | ||
if ('boolean' === schema.type) { | ||
if ('true' === value || '1' === value || 1 === value) { | ||
value = true; | ||
} | ||
if ('false' === value || '0' === value || 0 === value) { | ||
value = false; | ||
} | ||
} | ||
} | ||
if (schema.format && options.validateFormats) { | ||
@@ -297,2 +313,3 @@ format = schema.format; | ||
break; | ||
case 'integer': | ||
case 'number': | ||
@@ -299,0 +316,0 @@ constrain('minimum', value, function (a, e) { return a >= e }); |
{ | ||
"name": "revalidator", | ||
"version": "0.1.3", | ||
"version": "0.1.5", | ||
"description": "A cross-browser / node.js validator used by resourceful", | ||
@@ -5,0 +5,0 @@ "author": "Nodejitsu Inc. <info@nodejitsu.com>", |
@@ -76,2 +76,3 @@ # revalidator [![Build Status](https://secure.travis-ci.org/flatiron/revalidator.png)](http://travis-ci.org/flatiron/revalidator) | ||
* __validateFormatExtensions__: When `validateFormats` is _true_ also validate formats defined in `validate.formatExtensions` (_default true_) | ||
* __cast__: Enforce casting of some types (for integers/numbers are only supported) when it's possible, e.g. `"42" => 42`, but `"forty2" => "forty2"` for the `integer` type. | ||
@@ -114,3 +115,3 @@ ### Schema | ||
```js | ||
{ maxLenght: 8 } | ||
{ maxLength: 8 } | ||
``` | ||
@@ -122,3 +123,3 @@ | ||
```js | ||
{ minLenght: 8 } | ||
{ minLength: 8 } | ||
``` | ||
@@ -125,0 +126,0 @@ |
@@ -169,2 +169,27 @@ var assert = require('assert'), | ||
} | ||
}, | ||
"with <type>:'integer' and": { | ||
"<minimum> constraints": assertValidates ( 512, 43, { minimum: 473, type: 'integer' }), | ||
"<maximum> constraints": assertValidates ( 512, 1949, { maximum: 678, type: 'integer' }), | ||
"<divisibleBy> constraints": assertValidates ( 10, 9, { divisibleBy: 5, type: 'integer' }) | ||
}, | ||
"with <additionalProperties>:false": { | ||
topic: { | ||
properties: { | ||
town: { type: 'string' } | ||
}, | ||
additionalProperties: false | ||
}, | ||
"when the object conforms": { | ||
topic: function (schema) { | ||
return revalidator.validate({ town: "luna" }, schema); | ||
}, | ||
"return an object with `valid` set to true": assertValid | ||
}, | ||
"when the object does not conform": { | ||
topic: function (schema) { | ||
return revalidator.validate({ town: "luna", area: 'park' }, schema); | ||
}, | ||
"return an object with `valid` set to false": assertInvalid | ||
} | ||
} | ||
@@ -319,4 +344,58 @@ } | ||
} | ||
}, | ||
"with <cast> option": { | ||
topic: { | ||
properties: { | ||
answer: { type: "integer" }, | ||
is_ready: { type: "boolean" } | ||
} | ||
}, | ||
"and <integer> property": { | ||
"is castable string": { | ||
topic: function (schema) { | ||
return revalidator.validate({ answer: "42" }, schema, { cast: true }); | ||
}, | ||
"return an object with `valid` set to true": assertValid | ||
}, | ||
"is uncastable string": { | ||
topic: function (schema) { | ||
return revalidator.validate({ answer: "forty2" }, schema, { cast: true }); | ||
}, | ||
"return an object with `valid` set to false": assertInvalid | ||
} | ||
}, | ||
"and <boolean> property": { | ||
"is castable 'true/false' string": { | ||
topic: function (schema) { | ||
return revalidator.validate({ is_ready: "true" }, schema, { cast: true }); | ||
}, | ||
"return an object with `valid` set to true": assertValid | ||
}, | ||
"is castable '1/0' string": { | ||
topic: function (schema) { | ||
return revalidator.validate({ is_ready: "1" }, schema, { cast: true }); | ||
}, | ||
"return an object with `valid` set to true": assertValid | ||
}, | ||
"is castable `1/0` integer": { | ||
topic: function (schema) { | ||
return revalidator.validate({ is_ready: 1 }, schema, { cast: true }); | ||
}, | ||
"return an object with `valid` set to true": assertValid | ||
}, | ||
"is uncastable string": { | ||
topic: function (schema) { | ||
return revalidator.validate({ is_ready: "not yet" }, schema, { cast: true }); | ||
}, | ||
"return an object with `valid` set to false": assertInvalid | ||
}, | ||
"is uncastable number": { | ||
topic: function (schema) { | ||
return revalidator.validate({ is_ready: 42 }, schema, { cast: true }); | ||
}, | ||
"return an object with `valid` set to false": assertInvalid | ||
} | ||
} | ||
} | ||
} | ||
}).export(module); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
52487
9
937
288
1