{"library":"node-contains","title":"Node.prototype.contains() Polyfill","description":"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.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install node-contains"],"cli":null},"imports":["import 'node-contains';","require('node-contains');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import 'node-contains'; // Apply the polyfill (though likely unnecessary in modern browsers)\n\nfunction checkContains() {\n  const parentDiv = document.createElement('div');\n  parentDiv.id = 'parent';\n  const childSpan = document.createElement('span');\n  childSpan.id = 'child';\n  parentDiv.appendChild(childSpan);\n\n  document.body.appendChild(parentDiv);\n\n  // Using Node.prototype.contains() after the polyfill (or native support)\n  const isContained = parentDiv.contains(childSpan);\n  const selfContained = parentDiv.contains(parentDiv); // Node is considered to contain itself\n  const notContained = document.body.contains(document.createElement('p'));\n\n  console.log('Is childSpan contained in parentDiv?', isContained); // Expected: true\n  console.log('Is parentDiv contained in itself?', selfContained); // Expected: true\n  console.log('Is new P not contained in body?', notContained); // Expected: false (unless appended)\n\n  document.body.removeChild(parentDiv);\n}\n\n// Run the check when the DOM is ready\nif (document.readyState === 'loading') {\n  document.addEventListener('DOMContentLoaded', checkContains);\n} else {\n  checkContains();\n}","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}