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
15 lines (11 loc) • 356 B
text/typescript
import getCurrentDocument from './getCurrentDocument';
/**
* Is the given object root node of the DOM
*
* @param obj - The object to check
* @return Is it the root node of the DOM or not
*/
export default function isDOMRoot(obj: unknown): obj is HTMLElement {
const doc = getCurrentDocument(obj);
return !!doc && obj === doc.documentElement;
}