30 lines
1.4 KiB
JavaScript
30 lines
1.4 KiB
JavaScript
/**
|
|
* Verifies if a given node is an HTMLElement,
|
|
* this method works seamlessly with frames and elements from different documents
|
|
*
|
|
* This is preferred over simply using `instanceof`.
|
|
* Since `instanceof` might be problematic while operating with [multiple realms](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms)
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* isHTMLElement(event.target) && event.target.focus()
|
|
* isHTMLElement(event.target, {constructorName: 'HTMLInputElement'}) && event.target.value // some value
|
|
* ```
|
|
*
|
|
*/ "use strict";
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
Object.defineProperty(exports, "isHTMLElement", {
|
|
enumerable: true,
|
|
get: function() {
|
|
return isHTMLElement;
|
|
}
|
|
});
|
|
function isHTMLElement(element, options) {
|
|
var _typedElement_ownerDocument;
|
|
const typedElement = element;
|
|
var _options_constructorName;
|
|
return Boolean((typedElement === null || typedElement === void 0 ? void 0 : (_typedElement_ownerDocument = typedElement.ownerDocument) === null || _typedElement_ownerDocument === void 0 ? void 0 : _typedElement_ownerDocument.defaultView) && typedElement instanceof typedElement.ownerDocument.defaultView[(_options_constructorName = options === null || options === void 0 ? void 0 : options.constructorName) !== null && _options_constructorName !== void 0 ? _options_constructorName : 'HTMLElement']);
|
|
}
|