object.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _rule = require('../rule/');
  6. var _rule2 = _interopRequireDefault(_rule);
  7. var _util = require('../util');
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  9. /**
  10. * Validates an object.
  11. *
  12. * @param rule The validation rule.
  13. * @param value The value of the field on the source object.
  14. * @param callback The callback function.
  15. * @param source The source object being validated.
  16. * @param options The validation options.
  17. * @param options.messages The validation messages.
  18. */
  19. function object(rule, value, callback, source, options) {
  20. var errors = [];
  21. var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
  22. if (validate) {
  23. if ((0, _util.isEmptyValue)(value) && !rule.required) {
  24. return callback();
  25. }
  26. _rule2['default'].required(rule, value, source, errors, options);
  27. if (value !== undefined) {
  28. _rule2['default'].type(rule, value, source, errors, options);
  29. }
  30. }
  31. callback(errors);
  32. }
  33. exports['default'] = object;
  34. module.exports = exports['default'];