/**
* 检查value是否是DOM元素
* Checks if `value` is likely a DOM element
*
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a DOM element, else `false`
* @example
* isElement(document.body)
* // => true
* isElement('<body>')
* // -> false
*/
const objectTag = "[object Object]"
function isObjectLike(value) {
return typeof value == "object" && value !== null;
}
function isPlainObject(value) {
if (
!isObjectLike(value) ||
Object.prototype.toString.call(value) !== objectTag
) {
return false
}
const proto = Object.getPrototypeOf(value)
if (proto === null) {
return true
}
const Ctor =
Object.prototype.hasOwnProperty.call(proto, "constructor") &&
proto.constructor
return (
typeof Ctor === "function" &&
Ctor instanceof Ctor &&
Function.prototype.toString.call(Ctor) ===
Function.prototype.toString.call(Object)
)
}
function isElement(value) {
return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value)
}
export default isElement