vanillajs-browser-helpers
Version:
Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser
29 lines (28 loc) • 919 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var isDOMNode_1 = __importDefault(require("./isDOMNode"));
/**
* Is the given object a DOM element node and optionally of a given type
*
* @param obj - The object to check
* @param tags - Tag name to match
* @return Is it a DOM element node or not and optionally of the right type
*/
function isDOMElement(obj, tags) {
if (!isDOMNode_1.default(obj)) {
return false;
}
var isElm = obj.nodeType === Node.ELEMENT_NODE;
if (!isElm || !tags) {
return isElm;
}
if (!Array.isArray(tags)) {
tags = [tags];
}
var tagName = obj.tagName;
return tags.some(function (tag) { return tag.toUpperCase() === tagName; });
}
exports.default = isDOMElement;