| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- 'use strict'
- module.exports = isElement
- // Check if if `node` is an `element` and, if `tagNames` is given, `node`
- // matches them `tagNames`.
- function isElement(node, tagNames) {
- var name
- if (
- !(
- tagNames === null ||
- tagNames === undefined ||
- typeof tagNames === 'string' ||
- (typeof tagNames === 'object' && tagNames.length !== 0)
- )
- ) {
- throw new Error(
- 'Expected `string` or `Array.<string>` for `tagNames`, not `' +
- tagNames +
- '`'
- )
- }
- if (
- !node ||
- typeof node !== 'object' ||
- node.type !== 'element' ||
- typeof node.tagName !== 'string'
- ) {
- return false
- }
- if (tagNames === null || tagNames === undefined) {
- return true
- }
- name = node.tagName
- if (typeof tagNames === 'string') {
- return name === tagNames
- }
- return tagNames.indexOf(name) !== -1
- }
|