-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisHTMLCollection.js
35 lines (33 loc) · 1.01 KB
/
isHTMLCollection.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import _type from './utils/_type'
import isObject from './isObject'
import TYPES from './enum/types'
/**
* 检测数据的是否为 HTMLNodeList 对象
* ========================================================================
* @method isHTMLCollection
* @since 0.2.0
* @category Element
* @param {*} val - 要检测的数据
* @returns {Boolean} 'val' 是 HTMLNodeList 对象,返回 true,否则返回 false
* @example
*
* const $list = document.getElementById('list')
* const $div = document.createElement('div')
* const $text = document.createTextNode('text')
* const $items = document.querySelectorAll('.item')
* const $fragment = document.createDocumentFragment()
*
* isHTMLCollection($list) // -> false
*
* isHTMLCollection($div) // -> false
*
* isHTMLCollection($text) // -> false
*
* isHTMLCollection($items) // -> true
*
* isHTMLCollection($items) // -> false
*/
const isHTMLCollection = (val) => {
return !!(isObject(val) && _type(val) === TYPES.COLLECTION)
}
export default isHTMLCollection