Registry / http-networking / is-dom

is-dom

JSON →
library1.1.0jsnpmunverified

The `is-dom` package provides a minimalist utility function to determine if a given JavaScript object is a DOM node. It offers a single export, `isDom`, which returns `true` for valid DOM nodes (like `document`, `HTMLElement` instances, `Text` nodes, etc.) and `false` otherwise. This library is currently at version 1.1.0 and, given its focused scope, typically experiences a very slow release cadence, with updates primarily for bug fixes or compatibility adjustments rather than new features. Its key differentiator is its extreme simplicity and singular purpose, avoiding larger DOM manipulation libraries when only a type check is required. It's often used in environments where direct DOM access is available, such as browsers or Node.js with a JSDOM environment, to ensure operations are performed on actual DOM elements.

npm install is-dom
INSTALL
IMPORT
SIG · IS-DOM
I
is-dom
http-networkingjavascriptv1.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

isDom
import isDom from 'is-dom'
import { isDom } from 'is-dom'
The library primarily exports a default function. While Node.js's CJS interop for ESM might allow `import { default as isDom }` or even `import { isDom }` in some bundlers, the most reliable and direct translation of its CommonJS default export is `import isDom from 'is-dom'`.
isDom
const isDom = require('is-dom')
This is the original and intended CommonJS usage as shown in the package's README.
isDom (Type)
import type isDom from 'is-dom'
If only type information is needed in TypeScript, `import type` can be used to prevent bundle bloat or side effects.

This quickstart demonstrates how to use the 'is-dom' function to accurately check if various JavaScript values are recognized as DOM nodes, showcasing its utility in both browser and potentially JSDOM environments.

import isDom from 'is-dom'; // Example 1: With a real DOM node (browser context) if (typeof document !== 'undefined') { const body = document.body; console.log('Is document.body a DOM node?', isDom(body)); // true const div = document.createElement('div'); console.log('Is a created div a DOM node?', isDom(div)); // true const textNode = document.createTextNode('Hello'); console.log('Is a text node a DOM node?', isDom(textNode)); // true } else { console.log('Running in a non-browser environment. Skipping DOM-specific tests.'); } // Example 2: Non-DOM objects console.log('Is a plain object a DOM node?', isDom({})); // false console.log('Is a string a DOM node?', isDom('hello')); // false console.log('Is null a DOM node?', isDom(null)); // false console.log('Is undefined a DOM node?', isDom(undefined)); // false
Debug
Known issues
gotchaThe `is-dom` package is primarily distributed as a CommonJS module. While modern bundlers and Node.js often handle ESM interoperability, direct ESM usage might require specific import syntax (`import isDom from 'is-dom'`) or bundler configuration if issues arise with named imports.
fix
Ensure you are using the correct default import syntax: `import isDom from 'is-dom';` in ESM environments.
affects: >=1.0.0
gotchaThis library is designed for environments with a Document Object Model (DOM) available (e.g., browsers, JSDOM in Node.js). Using `isDom` in a pure Node.js environment without a DOM implementation will always return `false` for objects that would otherwise be considered DOM nodes in a browser.
fix
Run your code in a browser environment or integrate a DOM emulation library like JSDOM for Node.js testing: `const { JSDOM } = require('jsdom'); global.document = new JSDOM().window.document;`
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: document is not defined
Attempting to test or access DOM elements (like `document.body`) in a pure Node.js environment without a JSDOM setup.
fix
Ensure your code is running in a browser environment or use a library like JSDOM in Node.js to simulate the DOM for testing purposes. Example: `const { JSDOM } = require('jsdom'); global.document = new JSDOM().window.document;`
TypeError: isDom is not a function
Incorrect import statement when using ESM, trying to destructure a default export.
fix
If importing in an ESM context, use `import isDom from 'is-dom';` instead of `import { isDom } from 'is-dom';`.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
is-dom — npm install is-dom · libregistry