silfverorg / duns.js

Javascript schema validator
5 stars 2 forks source link

Added 'invalid' method to Duns.any(). closes #40. #46

Closed silfverstrom closed 9 years ago

silfverstrom commented 9 years ago

The invalid method invokes 'validate()', but returns true if schema could not be validated. This is nice as a shorthand when checking for incorrect schemas, like so:

function test(param) {
  if (Duns.number().invalid(param) ) throw new Error('Not a number');
}

// Without invalid this would look like this, which I think is a little more verbose.
function test(param) {
  if (Duns.number().validate(param) === false) throw new Error('Not a number');
}