{"id":13716918,"url":"https://github.com/syntax-tree/hast-util-is-element","last_synced_at":"2025-07-12T07:38:09.766Z","repository":{"id":45649271,"uuid":"56441012","full_name":"syntax-tree/hast-util-is-element","owner":"syntax-tree","description":"utility to check if a node is a (certain) element","archived":false,"fork":false,"pushed_at":"2023-07-31T15:08:59.000Z","size":149,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-28T07:05:20.289Z","etag":null,"topics":["element","hast","hast-util","html","syntax-tree","util"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","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/syntax-tree.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},"funding":{"github":"unifiedjs","open_collective":"unified"}},"created_at":"2016-04-17T14:35:08.000Z","updated_at":"2024-04-28T08:47:11.000Z","dependencies_parsed_at":"2024-01-14T22:03:41.960Z","dependency_job_id":"6d16c444-ec41-47e7-98eb-7729b0a0d808","html_url":"https://github.com/syntax-tree/hast-util-is-element","commit_stats":{"total_commits":93,"total_committers":3,"mean_commits":31.0,"dds":"0.021505376344086002","last_synced_commit":"225375e056ec51fc6374b5039470de57cdcd2ac3"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/hast-util-is-element","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-is-element","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-is-element/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-is-element/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-is-element/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/hast-util-is-element/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-is-element/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263040965,"owners_count":23404444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["element","hast","hast-util","html","syntax-tree","util"],"created_at":"2024-08-03T00:01:15.648Z","updated_at":"2025-07-12T07:38:09.725Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","readme":"# hast-util-is-element\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[hast][] utility to check if a node is a (certain) element.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`isElement(element[, test[, index, parent[, context]]])`](#iselementelement-test-index-parent-context)\n    *   [`convertElement(test)`](#convertelementtest)\n    *   [`Check`](#check)\n    *   [`Test`](#test)\n    *   [`TestFunction`](#testfunction)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package is a small utility that checks that a node is a certain element.\n\n## When should I use this?\n\nUse this small utility if you find yourself repeating code for checking what\nelements nodes are.\n\nA similar package, [`unist-util-is`][unist-util-is], works on any unist node.\n\nFor more advanced tests, [`hast-util-select`][hast-util-select] can be used\nto match against CSS selectors.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install hast-util-is-element\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {isElement} from 'https://esm.sh/hast-util-is-element@3'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {isElement} from 'https://esm.sh/hast-util-is-element@3?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {isElement} from 'hast-util-is-element'\n\nisElement({type: 'text', value: 'foo'}) // =\u003e false\nisElement({type: 'element', tagName: 'a', properties: {}, children: []}) // =\u003e true\nisElement({type: 'element', tagName: 'a', properties: {}, children: []}, 'a') // =\u003e true\nisElement({type: 'element', tagName: 'a', properties: {}, children: []}, 'b') // =\u003e false\nisElement({type: 'element', tagName: 'a', properties: {}, children: []}, ['a', 'area']) // =\u003e true\n```\n\n## API\n\nThis package exports the identifiers\n[`convertElement`][api-convert-element] and\n[`isElement`][api-is-element].\nThere is no default export.\n\n### `isElement(element[, test[, index, parent[, context]]])`\n\nCheck if `element` is an `Element` and whether it passes the given test.\n\n###### Parameters\n\n*   `element` (`unknown`, optional)\n    — thing to check, typically [`Node`][hast-node]\n*   `test` ([`Test`][api-test], optional)\n    — check for a specific element\n*   `index` (`number`, optional)\n    — position of `element` in its parent\n*   `parent` ([`Parent`][hast-parent], optional)\n    — parent of `element`\n*   `context` (`unknown`, optional)\n    — context object (`this`) to call `test` with\n\n###### Returns\n\nWhether `element` is an `Element` and passes a test (`boolean`).\n\n###### Throws\n\nWhen an incorrect `test`, `index`, or `parent` is given.\nThere is no error thrown when `element` is not a node or not an element.\n\n### `convertElement(test)`\n\nGenerate a check from a test.\n\nUseful if you’re going to test many nodes, for example when creating a\nutility where something else passes a compatible test.\n\nThe created function is a bit faster because it expects valid input only:\na `element`, `index`, and `parent`.\n\n###### Parameters\n\n*   `test` ([`Test`][api-test], optional)\n    — a test for a specific element\n\n###### Returns\n\nA check ([`Check`][api-check]).\n\n### `Check`\n\nCheck that an arbitrary value is an element (TypeScript type).\n\n###### Parameters\n\n*   `this` (`unknown`, optional)\n    — context object (`this`) to call `test` with\n*   `element` (`unknown`)\n    — anything (typically an element)\n*   `index` (`number`, optional)\n    — position of `element` in its parent\n*   `parent` ([`Parent`][hast-parent], optional)\n    — parent of `element`\n\n###### Returns\n\nWhether this is an element and passes a test (`boolean`).\n\n### `Test`\n\nCheck for an arbitrary element (TypeScript type).\n\n*   when `string`, checks that the element has that tag name\n*   when `function`, see  [`TestFunction`][api-test-function]\n*   when `Array`, checks if one of the subtests pass\n\n###### Type\n\n```ts\ntype Test =\n  | Array\u003cTestFunction | string\u003e\n  | TestFunction\n  | string\n  | null\n  | undefined\n```\n\n### `TestFunction`\n\nCheck if an element passes a test (TypeScript type).\n\n###### Parameters\n\n*   `element` ([`Element`][hast-element])\n    — an element\n*   `index` (`number` or `undefined`)\n    — position of `element` in its parent\n*   `parent` ([`Parent`][hast-parent] or `undefined`)\n    — parent of `element`\n\n###### Returns\n\nWhether this element passes the test (`boolean`, optional).\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Check`][api-check],\n[`Test`][api-test], and\n[`TestFunction`][api-test-function].\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `hast-util-is-element@^3`,\ncompatible with Node.js 16.\n\n## Security\n\n`hast-util-is-element` does not change the syntax tree so there are no openings\nfor [cross-site scripting (XSS)][xss] attacks.\n\n## Related\n\n*   [`hast-util-has-property`](https://github.com/syntax-tree/hast-util-has-property)\n    — check if a node has a property\n*   [`hast-util-is-body-ok-link`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-is-body-ok-link)\n    — check if a node is “Body OK” link element\n*   [`hast-util-is-conditional-comment`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-is-conditional-comment)\n    — check if a node is a conditional comment\n*   [`hast-util-is-css-link`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-is-css-link)\n    — check if a node is a CSS link element\n*   [`hast-util-is-css-style`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-is-css-style)\n    — check if a node is a CSS style element\n*   [`hast-util-embedded`](https://github.com/syntax-tree/hast-util-embedded)\n    — check if a node is an embedded element\n*   [`hast-util-heading`](https://github.com/syntax-tree/hast-util-heading)\n    — check if a node is a heading element\n*   [`hast-util-interactive`](https://github.com/syntax-tree/hast-util-interactive)\n    — check if a node is interactive\n*   [`hast-util-is-javascript`](https://github.com/rehypejs/rehype-minify/tree/main/packages/hast-util-is-javascript)\n    — check if a node is a JavaScript script element\n*   [`hast-util-labelable`](https://github.com/syntax-tree/hast-util-labelable)\n    — check whether a node is labelable\n*   [`hast-util-phrasing`](https://github.com/syntax-tree/hast-util-phrasing)\n    — check if a node is phrasing content\n*   [`hast-util-script-supporting`](https://github.com/syntax-tree/hast-util-script-supporting)\n    — check if a node is a script-supporting element\n*   [`hast-util-sectioning`](https://github.com/syntax-tree/hast-util-sectioning)\n    — check if a node is a sectioning element\n*   [`hast-util-transparent`](https://github.com/syntax-tree/hast-util-transparent)\n    — check if a node is a transparent element\n*   [`hast-util-whitespace`](https://github.com/syntax-tree/hast-util-whitespace)\n    — check if a node is inter-element whitespace\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definition --\u003e\n\n[build-badge]: https://github.com/syntax-tree/hast-util-is-element/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/hast-util-is-element/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-is-element.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/hast-util-is-element\n\n[downloads-badge]: https://img.shields.io/npm/dm/hast-util-is-element.svg\n\n[downloads]: https://www.npmjs.com/package/hast-util-is-element\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=hast-util-is-element\n\n[size]: https://bundlejs.com/?q=hast-util-is-element\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[hast]: https://github.com/syntax-tree/hast\n\n[hast-node]: https://github.com/syntax-tree/hast#nodes\n\n[hast-parent]: https://github.com/syntax-tree/hast#parent\n\n[hast-element]: https://github.com/syntax-tree/hast#element\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[unist-util-is]: https://github.com/syntax-tree/unist-util-is\n\n[hast-util-select]: https://github.com/syntax-tree/hast-util-select\n\n[api-is-element]: #iselementelement-test-index-parent-context\n\n[api-convert-element]: #convertelementtest\n\n[api-check]: #check\n\n[api-test]: #test\n\n[api-test-function]: #testfunction\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":["hast utilities"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fhast-util-is-element","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fhast-util-is-element","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fhast-util-is-element/lists"}