Created
October 22, 2014 16:04
-
-
Save nathanbowser/430e6e96345a69901ddf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var revalidator = require('revalidator') | |
var obj = { | |
title: 'Abe', | |
value: '10' | |
} | |
var schema = { | |
properties: { | |
title: { | |
type: 'string' | |
}, | |
value: { | |
type: 'number' | |
} | |
} | |
} | |
console.dir(revalidator.validate(obj, schema, {cast: true})) // true | |
obj.value = 10 | |
console.dir(revalidator.validate(obj, schema, {cast: true})) // true | |
schema.properties.value.type = ['number'] | |
console.dir(revalidator.validate(obj, schema, {cast: true})) // true | |
obj.value = '10' | |
console.dir(revalidator.validate(obj, schema, {cast: true})) // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment