Registry / node-contains

node-contains

JSON →
library1.0.0jsnpmunverified

The `node-contains` package, currently at version 1.0.0 and last published in September 2014, was designed to provide a cross-browser polyfill for the `Node.prototype.contains()` DOM method. Its original purpose was to ensure consistent behavior across older web browsers that lacked native support for this functionality. However, this method has been natively supported by all major web browsers since July 2015. Consequently, this package is now largely obsolete and considered abandoned for modern web development. While it might still be encountered in projects targeting extremely legacy environments, for any contemporary application, including `node-contains` introduces unnecessary overhead and potential compatibility issues. It does not follow a regular release cadence and offers no unique differentiators over native browser implementations.

npm install node-contains
INSTALL
IMPORT
SIG · NODE-CONTAINS
N
node-contains
javascriptv1.0.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.

Node.prototype.contains
import 'node-contains';
import { contains } from 'node-contains';
This is a polyfill that directly modifies `Node.prototype`. There are no named exports; the import is for its side-effects.
Node.prototype.contains (CommonJS)
require('node-contains');
const contains = require('node-contains');
For CommonJS environments, requiring the module applies the polyfill as a side-effect. It does not return an export.

This quickstart demonstrates how to include the `node-contains` polyfill and then use the `Node.prototype.contains()` method to check if a DOM node is a descendant of another.

import 'node-contains'; // Apply the polyfill (though likely unnecessary in modern browsers) function checkContains() { const parentDiv = document.createElement('div'); parentDiv.id = 'parent'; const childSpan = document.createElement('span'); childSpan.id = 'child'; parentDiv.appendChild(childSpan); document.body.appendChild(parentDiv); // Using Node.prototype.contains() after the polyfill (or native support) const isContained = parentDiv.contains(childSpan); const selfContained = parentDiv.contains(parentDiv); // Node is considered to contain itself const notContained = document.body.contains(document.createElement('p')); console.log('Is childSpan contained in parentDiv?', isContained); // Expected: true console.log('Is parentDiv contained in itself?', selfContained); // Expected: true console.log('Is new P not contained in body?', notContained); // Expected: false (unless appended) document.body.removeChild(parentDiv); } // Run the check when the DOM is ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', checkContains); } else { checkContains(); }
Debug
Known issues
breakingThis polyfill is effectively obsolete. The `Node.prototype.contains()` method has been natively supported by all major web browsers since July 2015, making this package redundant for nearly all modern web development environments. Including it introduces unnecessary bundle size and may lead to subtle compatibility issues or conflicts if other polyfills or libraries also modify `Node.prototype`.
fix
Remove `node-contains` from your project's dependencies and codebase. Rely on the native browser implementation of `Node.prototype.contains()`.
affects: >=1.0.0
gotchaThe package is unmaintained, with its last update in September 2014. Using unmaintained dependencies can expose projects to security vulnerabilities (e.g., supply chain attacks, unpatched bugs) as no further patches or updates are released for discovered issues.
fix
Migrate away from this package. If you absolutely need `Node.prototype.contains` in an ancient browser environment not covered by native support, consider a more modern, maintained polyfill or implement a minimal custom solution after careful consideration of risks.
affects: >=1.0.0
gotchaAs a polyfill, `node-contains` modifies the global `Node.prototype`. While this is its intended function, in complex applications or environments where multiple polyfills or libraries might attempt to patch or define the same method, this could lead to unexpected behavior, overwrites, or conflicts, making debugging difficult.
fix
Audit your dependency tree for other polyfills or libraries that might target `Node.prototype.contains`. Prioritize native browser functionality, and if polyfills are strictly necessary, ensure they are well-maintained and don't create conflicts. Use conditional polyfilling techniques if possible.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: Node is not defined
Attempting to include or execute this browser-specific polyfill in a non-browser (e.g., Node.js server-side) environment.
fix
This package is explicitly for client-side browser environments. Ensure it is only included in your client-side bundles and excluded from server-side Node.js code. Use appropriate build tool configurations (e.g., Webpack targets, browser field in package.json) to achieve this separation.
TypeError: undefined is not a function (evaluating 'element.contains(otherElement)')
This error typically occurs when `Node.prototype.contains` is invoked on an object that is not a valid DOM `Node` or if the polyfill (or native support) has not been loaded/executed before the method call in a very old browser context. In modern browsers, this indicates `element` is not a `Node`.
fix
Verify that the `element` variable is indeed a DOM `Node` (e.g., obtained via `document.getElementById()`). If targeting extremely old browsers, ensure `import 'node-contains';` (or `require('node-contains');`) is executed at the very beginning of your application's entry point before any DOM manipulation code that relies on `contains`.
Error: Module not found: Error: Can't resolve 'node-contains'
The `node-contains` package has not been installed as a dependency in your project, or there is a typo in the import/require statement or package name.
fix
Install the package using your package manager: `npm install node-contains` or `yarn add node-contains`. Then, double-check the import or require statement for any spelling errors and ensure it matches the package name exactly.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
node-contains — npm install node-contains · libregistry