JSPM

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

Utility to check if a node passes a test

Package Exports

  • unist-util-is

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 (unist-util-is) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

unist-util-is Build Status Coverage Status

Unist utility to check if a node passes a test.

Installation

npm:

npm install unist-util-is

Usage

var is = require('unist-util-is');

var node = {type: 'strong'};
var parent = {type: 'paragraph', children: [node]};

function test(node, n) { return n === 5 }

is(); // false
is(null, {children: []}); // false
is(null, node); // true
is('strong', node); // true
is('emphasis', node); // false

is(node, node) // true
is({type: 'paragraph'}, parent) // true
is({type: 'strong'}, parent) // false

is(test, node); // false
is(test, node, 4, parent); // false
is(test, node, 5, parent); // true

API

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

Parameters
  • test (Function, string, Object, or Array.<Test>, optional) — When not given, checks if node is a Node. When string, works like passing function (node) {return node.type === test}. When array, checks any one of the subtests pass. When object, checks that all keys in test are in node, and that they have (strictly) equal values.
  • node (Node) — Node to check. false is returned;
  • index (number, optional) — Position of node in parent;
  • parent (Node, optional) — Parent of node;
  • context (*, optional) — Context object to invoke test with.
Returns

boolean — Whether test passed and node is a Node (object with type set to non-empty string).

function test(node[, index, parent])

Parameters
  • node (Node) — Node to test;
  • index (number?) — Position of node in parent;
  • parent (Node?) — Parent of node.
Context

* — The to is given context.

Returns

boolean? — Whether node matches.

License

MIT © Titus Wormer