{"id":13343,"library":"is-dom","title":"is-dom DOM Node Check","description":"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.","status":"maintenance","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/npm-dom/is-dom","tags":["javascript","dom","html","is dom","dom node","dom object"],"install":[{"cmd":"npm install is-dom","lang":"bash","label":"npm"},{"cmd":"yarn add is-dom","lang":"bash","label":"yarn"},{"cmd":"pnpm add is-dom","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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'`.","wrong":"import { isDom } from 'is-dom'","symbol":"isDom","correct":"import isDom from 'is-dom'"},{"note":"This is the original and intended CommonJS usage as shown in the package's README.","symbol":"isDom","correct":"const isDom = require('is-dom')"},{"note":"If only type information is needed in TypeScript, `import type` can be used to prevent bundle bloat or side effects.","symbol":"isDom (Type)","correct":"import type isDom from 'is-dom'"}],"quickstart":{"code":"import isDom from 'is-dom';\n\n// Example 1: With a real DOM node (browser context)\nif (typeof document !== 'undefined') {\n  const body = document.body;\n  console.log('Is document.body a DOM node?', isDom(body)); // true\n\n  const div = document.createElement('div');\n  console.log('Is a created div a DOM node?', isDom(div)); // true\n\n  const textNode = document.createTextNode('Hello');\n  console.log('Is a text node a DOM node?', isDom(textNode)); // true\n} else {\n  console.log('Running in a non-browser environment. Skipping DOM-specific tests.');\n}\n\n// Example 2: Non-DOM objects\nconsole.log('Is a plain object a DOM node?', isDom({})); // false\nconsole.log('Is a string a DOM node?', isDom('hello')); // false\nconsole.log('Is null a DOM node?', isDom(null)); // false\nconsole.log('Is undefined a DOM node?', isDom(undefined)); // false\n","lang":"typescript","description":"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."},"warnings":[{"fix":"Ensure you are using the correct default import syntax: `import isDom from 'is-dom';` in ESM environments.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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;`","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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;`","cause":"Attempting to test or access DOM elements (like `document.body`) in a pure Node.js environment without a JSDOM setup.","error":"ReferenceError: document is not defined"},{"fix":"If importing in an ESM context, use `import isDom from 'is-dom';` instead of `import { isDom } from 'is-dom';`.","cause":"Incorrect import statement when using ESM, trying to destructure a default export.","error":"TypeError: isDom is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}