debut des details de la page. Vu que c'est le troisieme (euh quatrieme?) composant, c'etait un peu plus rapide, mais heureusement que claude est la pour repasser derriere mes erreurs prcq en solo je n'y arriverais pas du tout!
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
'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;
|
||||
Reference in New Issue
Block a user