attributes.js 956 B

1234567891011121314151617181920212223242526272829303132
  1. import fromFunction from './from-function';
  2. import AbstractVirtualNode from '../../core/base/virtual-node/abstract-virtual-node';
  3. import { getNodeFromTree } from '../../core/utils';
  4. /**
  5. * Check if a virtual node matches some attribute(s)
  6. *
  7. * Note: matches.attributes(vNode, matcher) can be indirectly used through
  8. * matches(vNode, { attributes: matcher })
  9. *
  10. * Example:
  11. * ```js
  12. * matches.attributes(vNode, {
  13. * 'aria-live': 'assertive', // Simple string match
  14. * 'aria-expanded': /true|false/i, // either boolean, case insensitive
  15. * })
  16. * ```
  17. *
  18. * @deprecated HTMLElement is deprecated, use VirtualNode instead
  19. *
  20. * @param {HTMLElement|VirtualNode} vNode
  21. * @param {Object} Attribute matcher
  22. * @returns {Boolean}
  23. */
  24. function attributes(vNode, matcher) {
  25. if (!(vNode instanceof AbstractVirtualNode)) {
  26. vNode = getNodeFromTree(vNode);
  27. }
  28. return fromFunction(attrName => vNode.attr(attrName), matcher);
  29. }
  30. export default attributes;