whitespace.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _util = require('../util');
  6. var util = _interopRequireWildcard(_util);
  7. 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; } }
  8. /**
  9. * Rule for validating whitespace.
  10. *
  11. * @param rule The validation rule.
  12. * @param value The value of the field on the source object.
  13. * @param source The source object being validated.
  14. * @param errors An array of errors that this rule may add
  15. * validation errors to.
  16. * @param options The validation options.
  17. * @param options.messages The validation messages.
  18. */
  19. function whitespace(rule, value, source, errors, options) {
  20. if (/^\s+$/.test(value) || value === '') {
  21. errors.push(util.format(options.messages.whitespace, rule.fullField));
  22. }
  23. }
  24. exports['default'] = whitespace;
  25. module.exports = exports['default'];