parcoursup/node_modules/bianco.dom-to-array/index.js
lalBi94 7bc56c09b5 $
2023-03-05 13:23:23 +01:00

28 lines
726 B
JavaScript

'use strict';
/**
* Converts any DOM node/s to a loopable array
* @param { HTMLElement|NodeList } els - single html element or a node list
* @returns { Array } always a loopable object
*/
function domToArray(els) {
// can this object be already looped?
if (!Array.isArray(els)) {
// is it a node list?
if (
/^\[object (HTMLCollection|NodeList|Object)\]$/
.test(Object.prototype.toString.call(els))
&& typeof els.length === 'number'
)
return Array.from(els)
else
// if it's a single node
// it will be returned as "array" with one single entry
return [els]
}
// this object could be looped out of the box
return els
}
module.exports = domToArray;