JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3379407
  • Score
    100M100P100Q222677F
  • License MIT

Check if a node is a (certain) element

Package Exports

  • hast-util-is-element

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hast-util-is-element) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

hast-util-is-element Build Status Coverage Status

Check if a node is a (certain) HAST element.

Installation

npm:

npm install hast-util-is-element

hast-util-is-element is also available as an AMD, CommonJS, and globals module, uncompressed and compressed.

Usage

Dependencies:

var isElement = require('hast-util-is-element');

Given a non-element:

var result = isElement({
    'type': 'text',
    'value': 'foo'
});

Yields:

false

Given a matching element:

result = isElement({
    'type': 'element',
    'tagName': 'a'
}, 'a');

Yields:

true

Given multiple tagNames:

result = isElement({
    'type': 'element',
    'tagName': 'a'
}, ['a', 'area']);

Yields:

true

API

isElement(node[, tagName|tagNames])

Check if a node is a (certain) HAST element.

When not given a second parameter, asserts if node is an element, otherwise asserts node is an element whose tagName matches / is included in the second parameter.

Parameters:

  • node (*) — Value to check;
  • tagName (string, optional) — Value nodes tagName must match;
  • tagNames (string, optional) — Value including nodes tagName.

Returns: boolean, whether node passes the test.

Throws: when the second parameter is given but invalid.

License

MIT © Titus Wormer