whitespace.js 1.0 KB

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _util = require('../util');
  4. var util = _interopRequireWildcard(_util);
  5. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
  6. /**
  7. * Rule for validating whitespace.
  8. *
  9. * @param rule The validation rule.
  10. * @param value The value of the field on the source object.
  11. * @param source The source object being validated.
  12. * @param errors An array of errors that this rule may add
  13. * validation errors to.
  14. * @param options The validation options.
  15. * @param options.messages The validation messages.
  16. */
  17. function whitespace(rule, value, source, errors, options) {
  18. if (/^\s+$/.test(value) || value === '') {
  19. errors.push(util.format(options.messages.whitespace, rule.fullField));
  20. }
  21. }
  22. exports['default'] = whitespace;
  23. module.exports = exports['default'];