{"id":15814256,"url":"https://github.com/stevenvachon/dom-predicates","last_synced_at":"2026-04-30T01:36:48.527Z","repository":{"id":66016690,"uuid":"219238941","full_name":"stevenvachon/dom-predicates","owner":"stevenvachon","description":"Functions for determining if an object is a DOM Node of various types (from any Realm) via duck typing.","archived":false,"fork":false,"pushed_at":"2019-11-22T23:56:06.000Z","size":11,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-17T00:37:27.908Z","etag":null,"topics":["attached","custom-element","detached","document","dom","element","html","isolated","node","orphan","self-closing","stray","svg","void","void-elements","xhtml","xml"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stevenvachon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-03T02:02:20.000Z","updated_at":"2019-11-22T23:56:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"58657458-a62c-4144-b45a-a13b900fcd85","html_url":"https://github.com/stevenvachon/dom-predicates","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"73091c59fcbd40c2445da1db22353e459e010d84"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stevenvachon/dom-predicates","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fdom-predicates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fdom-predicates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fdom-predicates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fdom-predicates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevenvachon","download_url":"https://codeload.github.com/stevenvachon/dom-predicates/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fdom-predicates/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32451475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"ssl_error","status_checked_at":"2026-04-29T22:10:49.234Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["attached","custom-element","detached","document","dom","element","html","isolated","node","orphan","self-closing","stray","svg","void","void-elements","xhtml","xml"],"created_at":"2024-10-05T04:23:53.297Z","updated_at":"2026-04-30T01:36:48.484Z","avatar_url":"https://github.com/stevenvachon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dom-predicates [![NPM Version][npm-image]][npm-url] ![File Size][filesize-image] ![Build Status][ci-image] [![Coverage Status][coveralls-image]][coveralls-url]\n\n\u003e Functions for determining if an object resembles a DOM [`Node`](https://mdn.io/Node) of various types (from any `Realm`) via [duck typing](https://wikipedia.org/wiki/Duck_typing).\n\nNote: [jsdom](https://npmjs.com/jsdom) nodes are *supported* and without having to define globals such as `window` and `document`.\n\n\n## Installation\n\n[Node.js](http://nodejs.org) `\u003e= 10` is required. To install, type this at the command line:\n```shell\nnpm install dom-predicates\n```\n\n\n## Importing\n\nES Module:\n```js\nimport {isHTMLElementNode} from 'dom-predicates';\n```\n\nCommonJS Module:\n```js\nconst {isHTMLElementNode} = require('dom-predicates');\n```\n\n\n## Functions\n\n### `isAttachedNode(node)`\nDetermine if `node` exists within any DOM tree.\n\n```js\nconst div = document.createElement('div');\nisAttachedNode(div); //-\u003e false\n\ndocument.body.append(div);\nisAttachedNode(div); //-\u003e true\n```\n\n### `isCustomElementNode(node[, registry])`\nDetermine if `node` is a custom [`HTMLElement`](https://mdn.io/HTMLElement) defined within `registry` (a [`CustomElementRegistry`](https://mdn.io/CustomElementRegistry)). The value of `registry` will default to `window.customElements` (for the `Realm` where this library was imported) within a web browser.\n\n```js\nisCustomElementNode(document.createElement('my-component'), customElements); //-\u003e true or false\nisCustomElementNode(document.createElement('div'), customElements); //-\u003e false\n```\n\n### `isCustomElementRegistry(registry)`\nDetermine if `registry` is a [`CustomElementRegistry`](https://mdn.io/CustomElementRegistry).\n\n```js\nisCustomElementRegistry(window.customElements); //-\u003e true\n```\n\n### `isDocumentFragmentNode(node)`\nDetermine if `node` is a [`DocumentFragment`](https://mdn.io/DocumentFragment).\n\n```js\nisDocumentFragmentNode(document.createDocumentFragment()); //-\u003e true\nisDocumentFragmentNode(document); //-\u003e false\n```\n\n### `isDocumentNode(node)`\nDetermine if `node` is a [`Document`](https://mdn.io/Document) (or subclass).\n\n```js\nisDocumentNode(document); //-\u003e true\nisDocumentNode(document.implementation.createDocument(null, 'xml')); //-\u003e true\nisDocumentNode(document.body); //-\u003e false\n```\n\n### `isDocumentTypeNode(node)`\nDetermine if `node` is a [`DocumentType`](https://mdn.io/DocumentType).\n\n```js\nisDocumentTypeNode(document.doctype); //-\u003e true or false\nisDocumentTypeNode(document.implementation.createDocumentType('html', '', '')); //-\u003e true\nisDocumentTypeNode(document); //-\u003e false\n```\n\n### `isElementNode(node)`\nDetermine if `node` is an [`Element`](https://mdn.io/Element) (or subclass).\n\n```js\nisElementNode(document.createElement('div')); //-\u003e true\nisElementNode(document.createElementNS('http://www.w3.org/2000/svg', 'path')); //-\u003e true\nisElementNode(document.createTextNode('content')); //-\u003e false\n```\n\n### `isHTMLDocumentNode(node)`\nDetermine if `node` is an [`HTMLDocument`](https://mdn.io/HTMLDocument).\n\n```js\nisHTMLDocumentNode(document); //-\u003e true or false\nisHTMLDocumentNode(document.implementation.createHTMLDocument()); //-\u003e true\nisHTMLDocumentNode(document.implementation.createDocument(null, 'xml')); //-\u003e false\nisHTMLDocumentNode(document.body); //-\u003e false\n```\n\n### `isHTMLElementNode(node[, tagName])`\nDetermine if `node` is an [`HTMLElement`](https://mdn.io/HTMLElement) (or subclass).\n\n```js\nisHTMLElementNode(document.createElement('div')); //-\u003e true\nisHTMLElementNode(document.createElementNS('http://www.w3.org/2000/svg', 'div')); //-\u003e false\n```\nWith the optional `tagName` argument:\n```js\nisHTMLElementNode(document.createElement('div'), 'div'); //-\u003e true\nisHTMLElementNode(document.createElement('div'), 'span'); //-\u003e false\n````\n\n### `isKnownElementNode(node)`\nDetermine if `node` has a known tag name in relation to its type ([`HTMLElement`](https://mdn.io/HTMLElement) or [`SVGElement`](https://mdn.io/SVGElement)). This does not include [`CustomElementRegistry`](https://mdn.io/CustomElementRegistry).\n\n```js\nisKnownElementNode(document.createElement('div')); //-\u003e true\nisKnownElementNode(document.createElementNS('http://www.w3.org/2000/svg', 'path')); //-\u003e true\nisKnownElementNode(document.createElement('non-existent')); //-\u003e false\n```\n\n### `isNode(node)`\nDetermine if `node` is a [`Node`](https://mdn.io/Node) (or subclass).\n\n```js\nisNode(document.createElement('div')); //-\u003e true\nisNode(document.createTextNode('content')); //-\u003e true\n```\n\n### `isProcessingInstructionNode(node)`\nDetermine if `node` is a [`ProcessingInstruction`](https://mdn.io/ProcessingInstruction).\n\n```js\nisProcessingInstructionNode(document.createProcessingInstruction('xml', '')); //-\u003e true\nisProcessingInstructionNode(document); //-\u003e false\n```\n\n### `isSelfClosingElementNode(node)`\nDetermine if `node` is a [void](https://www.w3.org/TR/html5/syntax.html#void-elements) [`HTMLElement`](https://mdn.io/HTMLElement) or a known self-closing [`SVGElement`](https://mdn.io/SVGElement).\n\n```js\nisSelfClosingElementNode(document.createElement('input')); //-\u003e true\nisSelfClosingElementNode(document.createElementNS('http://www.w3.org/2000/svg', 'input')); //-\u003e false\n\nisSelfClosingElementNode(document.createElementNS('http://www.w3.org/2000/svg', 'path')); //-\u003e true\nisSelfClosingElementNode(document.createElement('path')); //-\u003e false\n```\n\n### `isSVGDocumentNode(node)`\nDetermine if `node` is an [`XMLDocument`](https://mdn.io/XMLDocument) with an SVG namespace.\n\n```js\nisSVGDocumentNode(document); //-\u003e true or false\nisSVGDocumentNode(document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg')); //-\u003e true\n\nisSVGDocumentNode(document.implementation.createDocument(null, 'xml')); //-\u003e false\nisSVGDocumentNode(document.implementation.createHTMLDocument()); //-\u003e false\nisSVGDocumentNode(document.body); //-\u003e false\n```\n\n### `isSVGElementNode(node[, tagName])`\nDetermine if `node` is an [`SVGElement`](https://mdn.io/SVGElement) (or subclass).\n\n```js\nisSVGElementNode(document.createElementNS('http://www.w3.org/2000/svg', 'path')); //-\u003e true\nisSVGElementNode(document.createElement('path')); //-\u003e false\n```\nWith the optional `tagName` argument:\n```js\nisSVGElementNode(document.createElementNS('http://www.w3.org/2000/svg', 'path'), 'path'); //-\u003e true\nisSVGElementNode(document.createElementNS('http://www.w3.org/2000/svg', 'path'), 'circle'); //-\u003e false\n````\n\n### `isTextNode(node)`\nDetermine if `node` is a [`Text`](https://mdn.io/API/Text) (or subclass).\n\n```js\nisTextNode(document.createTextNode('')); //-\u003e true\nisTextNode(document.createCDATASection('')); //-\u003e true\nisTextNode(document.createElement('div')); //-\u003e false\n```\n\n### `isVoidHTMLElementNode(node)`\nDetermine if `node` is a [void](https://www.w3.org/TR/html5/syntax.html#void-elements) [`HTMLElement`](https://mdn.io/HTMLElement).\n\n```js\nisVoidHTMLElementNode(document.createElement('input')); //-\u003e true\nisVoidHTMLElementNode(document.createElementNS('http://www.w3.org/2000/svg', 'input')); //-\u003e false\nisVoidHTMLElementNode(document.createElement('div')); //-\u003e false\n```\n\n### `isXHTMLDocumentNode(node)`\nDetermine if `node` is an [`XMLDocument`](https://mdn.io/XMLDocument) with an XHTML namespace.\n\n```js\nisXHTMLDocumentNode(document); //-\u003e true or false\nisXHTMLDocumentNode(document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html')); //-\u003e true\nisXHTMLDocumentNode(document.implementation.createHTMLDocument()); //-\u003e false\nisXHTMLDocumentNode(document.body); //-\u003e false\n```\n\n### `isXMLDocumentNode(node)`\nDetermine if `node` is an [`XMLDocument`](https://mdn.io/XMLDocument) (with any namespace).\n\n```js\nisXMLDocumentNode(document); //-\u003e true or false\nisXMLDocumentNode(document.implementation.createDocument(null, 'xml')); //-\u003e true\nisXMLDocumentNode(document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html')); //-\u003e true\nisXMLDocumentNode(document.implementation.createHTMLDocument()); //-\u003e false\nisXMLDocumentNode(document.body); //-\u003e false\n```\n\n\n## Compatibility\n\nDepending on your target browsers, you may need polyfills/shims for the following:\n\n* [`globalThis`](https://mdn.io/globalThis)\n* [`Set`](https://mdn.io/Set)\n* [`String::endsWith`](https://mdn.io/String/endsWith)\n\n\n## FAQ\n\n1. **Why is there no `isXHTMLElementNode()`?**  \nBecause it's impossible to differentiate. All HTML elements (non-SVG, etc) within an XHTML document are still instances of `HTMLElement` and all HTML elements within HTML and XHTML documents (excluding HTML4 and below) have an XHTML namespace by default.\n\n2. **Why are HTML4 and DOM3 features not supported?**  \nBecause they're deprecated and shouldn't be used.\n\n\n[npm-image]: https://img.shields.io/npm/v/dom-predicates.svg\n[npm-url]: https://npmjs.com/package/dom-predicates\n[filesize-image]: https://img.shields.io/badge/size-2.2kB%20gzipped-blue.svg\n[ci-image]: https://github.com/stevenvachon/dom-predicates/workflows/tests/badge.svg\n[coveralls-image]: https://img.shields.io/coveralls/stevenvachon/dom-predicates.svg\n[coveralls-url]: https://coveralls.io/github/stevenvachon/dom-predicates\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenvachon%2Fdom-predicates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevenvachon%2Fdom-predicates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenvachon%2Fdom-predicates/lists"}