attr-non-space-content-evaluate.js 674 B

12345678910111213141516171819202122232425262728
  1. import { sanitize } from '../../commons/text';
  2. function attrNonSpaceContentEvaluate(node, options = {}, vNode) {
  3. if (!options.attribute || typeof options.attribute !== 'string') {
  4. throw new TypeError(
  5. 'attr-non-space-content requires options.attribute to be a string'
  6. );
  7. }
  8. if (!vNode.hasAttr(options.attribute)) {
  9. this.data({
  10. messageKey: 'noAttr'
  11. });
  12. return false;
  13. }
  14. const attribute = vNode.attr(options.attribute);
  15. const attributeIsEmpty = !sanitize(attribute);
  16. if (attributeIsEmpty) {
  17. this.data({
  18. messageKey: 'emptyAttr'
  19. });
  20. return false;
  21. }
  22. return true;
  23. }
  24. export default attrNonSpaceContentEvaluate;