Ai
1 Star 0 Fork 12

NextZero/dom.js

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
filter.js 959 Bytes
Copy Edit Raw Blame History
import isFunction from './utils/types/isFunction'
import isString from './utils/types/isString'
import isCollection from './isCollection'
import matches from './matches'
/**
* 返回 NodeList 的元素中与 selector 过滤条件匹配的 DOM 元素(数组)
* ========================================================================
* @method filter
* @since 1.2.0
* @param {NodeList} collection
* @param {String|Function} selector
* @return {Array}
*/
const filter = (collection, selector) => {
let callback
let items
if (
!isCollection(collection) ||
(!isString(selector) && !isFunction(selector))
) {
return []
}
items = [...collection]
if (isString(selector)) {
callback = (item) => {
return matches(item, selector)
}
} else {
callback = (item, i) => {
return selector(item, i)
}
}
return items.filter(callback)
}
export default filter
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/nextzero/dom.js.git
git@gitee.com:nextzero/dom.js.git
nextzero
dom.js
dom.js
main

Search