hast-util-is-element
hast utility to check if a node is a (certain) element.
Install
npm:
npm install hast-util-is-element
Use
var is = require('hast-util-is-element')
is({type: 'text', value: 'foo'}) // => false
is({type: 'element', tagName: 'a'}, 'a') // => true
is({type: 'element', tagName: 'a'}, ['a', 'area']) // => true
API
isElement(node[, test[, index, parent[, context]]])
Check if the given value is a (certain) element.
node(Node) — Node to check.test(Function,string, orArray.<Test>, optional) — Whenarray, checks if any one of the subtests pass. Whenstring, checks that the element has that tag name. Whenfunction, seetestindex(number, optional) — Index ofnodeinparentparent(Node, optional) — Parent ofnodecontext(*, optional) — Context object to invoketestwith
Returns
boolean — Whether test passed and node is an Element.
Throws
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])
Parameters
element(Element) — Element to checkindex(number?) — Index ofnodeinparentparent(Node?) — Parent ofnode
Context
* — The to is given context.
Returns
boolean? — Whether element matches.
isElement.convert(test)
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.
Can also be accessed with require('hast-util-is-element/convert').
Security
hast-util-is-element does not change the syntax tree so there are no openings for cross-site scripting (XSS) attacks.
Related
hast-util-has-property— check if a node has a propertyhast-util-is-body-ok-link— check if a node is “Body OK” link elementhast-util-is-conditional-comment— check if a node is a conditional commenthast-util-is-css-link— check if a node is a CSS link elementhast-util-is-css-style— check if a node is a CSS style elementhast-util-embedded— check if a node is an embedded elementhast-util-heading— check if a node is a heading elementhast-util-interactive— check if a node is interactivehast-util-is-javascript— check if a node is a JavaScript script elementhast-util-labelable— check whether a node is labelablehast-util-phrasing— check if a node is phrasing contenthast-util-script-supporting— check if a node is a script-supporting elementhast-util-sectioning— check if a node is a sectioning elementhast-util-transparent— check if a node is a transparent elementhast-util-whitespace— check if a node is inter-element whitespace
Contribute
See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.