defuddle
Version:
Extract article content and metadata from web pages.
38 lines • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isElement = isElement;
exports.getComputedStyle = getComputedStyle;
exports.getWindow = getWindow;
exports.logDebug = logDebug;
const constants_1 = require("./constants");
// Type guard
function isElement(node) {
return node.nodeType === constants_1.NODE_TYPE.ELEMENT_NODE;
}
function getComputedStyle(element) {
const win = getWindow(element.ownerDocument);
if (!win)
return null;
return win.getComputedStyle(element);
}
function getWindow(doc) {
// First try defaultView
if (doc.defaultView) {
return doc.defaultView;
}
// Then try ownerWindow
if (doc.ownerWindow) {
return doc.ownerWindow;
}
// Finally try to get window from document
if (doc.window) {
return doc.window;
}
return null;
}
function logDebug(message, ...args) {
if (typeof window !== 'undefined' && window.defuddleDebug) {
console.log('Defuddle:', message, ...args);
}
}
//# sourceMappingURL=utils.js.map