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
12 lines (9 loc) • 356 B
text/typescript
import isDocument from './isDocument';
import isDOMNode from './isDOMNode';
import isWindow from './isWindow';
export default function getCurrentDocument(obj: unknown): Document | null {
if (isDocument(obj)) { return obj as Document; }
if (isWindow(obj)) { return obj.document; }
if (!isDOMNode(obj)) { return null; }
return obj.ownerDocument;
}