Skip to content

Instantly share code, notes, and snippets.

@nathanbowser
Created October 22, 2014 16:04
Show Gist options
  • Save nathanbowser/430e6e96345a69901ddf to your computer and use it in GitHub Desktop.
Save nathanbowser/430e6e96345a69901ddf to your computer and use it in GitHub Desktop.
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