hast utility to check if a node is a (certain) element

Downloads in past


802.1.2a year ago7 years agoMinified + gzip package size for hast-util-is-element in KB


!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
hasthast utility to check if a nodenode is a (certain) elementelement.


This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.
npm install hast-util-is-element
## Use

import {isElement} from 'hast-util-is-element'

isElement({type: 'text', value: 'foo'}) // => false

isElement({type: 'element', tagName: 'a'}, 'a') // => true

isElement({type: 'element', tagName: 'a'}, ['a', 'area']) // => true


This package exports the following identifiers: isElement, convertElement. There is no default export.

isElement(node[, test[, index, parent[, context]]])

Check if the given value is a (certain) elementelement.
— When `array`, checks if any one of the subtests pass.
When `string`, checks that the element has that tag name.
When `function`, see [`test`][test]
  • index (number, optional) — Index of node in parent
  • parent (Nodenode, optional) — Parent of node
  • context (*, optional) — Context object to invoke test with
boolean — Whether test passed and node is an Elementelement.
Error — When an incorrect test, index, or parent is given. A node that is not a node, or not an element, does not throw.

function test(element[, index, parent])

* — The to is given context.
boolean? — Whether element matches.


Create a test function from test, that can later be called with a node, index, and parent. Useful if you’re going to test many nodes, for example when creating a utility where something else passes a compatible test.
The created function is slightly faster because it expects valid input only. Therefore, passing invalid input, yields unexpected results.


hast-util-is-element does not change the syntax tree so there are no openings for cross-site scripting (XSS)xss attacks.


— check if a node has a property
— check if a node is “Body OK” link element
— check if a node is a conditional comment
— check if a node is a CSS link element
— check if a node is a CSS style element
— check if a node is an embedded element
— check if a node is a heading element
— check if a node is interactive
— check if a node is a JavaScript script element
— check whether a node is labelable
— check if a node is phrasing content
— check if a node is a script-supporting element
— check if a node is a sectioning element
— check if a node is a transparent element
— check if a node is inter-element whitespace


See contributing.md in syntax-tree/.githubcontributing for ways to get started. See support.mdsupport for ways to get help.
This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.


MITlicense © Titus Wormerauthor