flatiron / revalidator

A cross-browser / node.js validator powered by JSON Schema
http://github.com/flatiron/revalidator
Apache License 2.0
589 stars 82 forks source link

docs: clarify behavior of `conform` function #127

Closed zeke closed 3 years ago

zeke commented 5 years ago

This PR updates the documentation for the conform function to clarify that it doesn't specifically require a true or false return value. Any truthy or falsy value will also validate.

Example:

const revalidator = require('revalidator')

const schema1 = {
  properties: {
    name: {
      conform: function (input) {
        return input
      }
    }
  }
}

const schema2 = {
  properties: {
    name: {
      conform: function (input) {
        return null
      }
    }
  }
}

const obj = {
  name: 'jane'
}

console.log(revalidator.validate(obj, schema1))
// { valid: true, errors: [] }

console.log(revalidator.validate(obj, schema2))
// {
//   valid: false,
//   errors: [
//     {
//       attribute: 'conform',
//       property: 'name',
//       expected: [Function: conform],
//       actual: 'jane',
//       message: 'must conform to given constraint'
//     }
//   ]
// }