findAllDOMElements.js 452 B

123456789101112131415161718
  1. const isDOMElement = require('./isDOMElement')
  2. /**
  3. * Find one or more DOM elements.
  4. *
  5. * @param {string} element
  6. * @return {Array|null}
  7. */
  8. module.exports = function findAllDOMElements (element) {
  9. if (typeof element === 'string') {
  10. const elements = [].slice.call(document.querySelectorAll(element))
  11. return elements.length > 0 ? elements : null
  12. }
  13. if (typeof element === 'object' && isDOMElement(element)) {
  14. return [element]
  15. }
  16. }