Package detail

get-dom-document

ocavue159.6kMIT0.1.3

Get a DOM document in both Node.js and the browser environment.

readme

get-dom-document

Get a DOM document in both Node.js and the browser environment.

getDomDocument will firstly try to get the DOM document from the global document object. If it is not available, it will try to create a new DOM document using jsdom in Node.js environment. If jsdom is not available or it's not running in Node.js environment, it will return null.

This package use the browser field in package.json and conditional exports to provide different implementations for Node.js and the browser environment.

Install

npm install get-dom-document

Usage

CommonJS:

const { getDomDocument } = require("get-dom-document");

const document = getDomDocument();

ES module:

import { getDomDocument } from "get-dom-document";

const document = getDomDocument();