matches.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import fromDefinition from './from-definition';
  2. /**
  3. * Check if a virtual node matches a definition
  4. *
  5. * Example:
  6. * ```js
  7. * // Match a single nodeName:
  8. * axe.commons.matches(vNode, 'div')
  9. *
  10. * // Match one of multiple nodeNames:
  11. * axe.commons.matches(vNode, ['ul', 'ol'])
  12. *
  13. * // Match a node with nodeName 'button' and with aria-hidden: true:
  14. * axe.commons.matches(vNode, {
  15. * nodeName: 'button',
  16. * attributes: { 'aria-hidden': 'true' }
  17. * })
  18. *
  19. * // Mixed input. Match button nodeName, input[type=button] and input[type=reset]
  20. * axe.commons.matches(vNode, ['button', {
  21. * nodeName: 'input', // nodeName match isn't case sensitive
  22. * properties: { type: ['button', 'reset'] }
  23. * }])
  24. * ```
  25. *
  26. * @deprecated HTMLElement is deprecated, use VirtualNode instead
  27. *
  28. * @namespace matches
  29. * @memberof axe.commons
  30. * @param {HTMLElement|VirtualNode} vNode virtual node to verify attributes against constraints
  31. * @param {Array<ElementDefinition>|String|Object|Function|Regex} definition
  32. * @return {Boolean} true/ false based on if vNode passes the constraints expected
  33. */
  34. function matches(vNode, definition) {
  35. return fromDefinition(vNode, definition);
  36. }
  37. export default matches;