validate-strict.js 807 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * Module dependencies
  3. */
  4. var validateRecursive = require('./helpers/validate-recursive');
  5. var consolidateErrors = require('./helpers/consolidate-errors');
  6. /**
  7. * Like `validate()`, but doesn't tolerate and coerce minor
  8. * type incompatibilities such as '1'=>1, 'true'=>true, etc.
  9. *
  10. * @param {~Schema} expected type schema
  11. * @param {===} actual "mystery meat"
  12. */
  13. module.exports = function validateStrict (expected, actual) {
  14. var errors = [];
  15. validateRecursive(expected, actual, errors, [], true);
  16. // ( `true` => `strict` -- i.e. don't ignore minor type errors)
  17. // If there are still errors, coallesce the remaining list of errors into a single
  18. // Error object we can throw.
  19. var err = consolidateErrors(errors, 'validating value');
  20. if (err) {
  21. throw err;
  22. }
  23. };