import arrayFrom from './array-from'; /** * @param {NodeList} nodes * @param {Function} [matcher] * @return {Attr[]} */ export default function selectAttributes(nodes, matcher) { const attrs = arrayFrom(nodes).reduce((acc, node) => { if (!node.attributes) { return acc; } const arrayfied = arrayFrom(node.attributes); const matched = matcher ? arrayfied.filter(matcher) : arrayfied; return acc.concat(matched); }, []); return attrs; }