forked from liweijie/education
21 lines
474 B
JavaScript
21 lines
474 B
JavaScript
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;
|
|
}
|