JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 23260504
  • Score
    100M100P100Q234564F
  • 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. Useful when working with mdast or retext.

Installation

npm:

npm install unist-util-is

unist-util-is is also available for bower, component, and duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.

Usage

var is = require('.');
var node = {
    'type': 'strong'
};
var parent = {
    'type': 'paragraph',
    'children': [node]
};

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

is(null, node); // true
is('strong', node); // true
is('emphasis', node); // false

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

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

API

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

Utility to check if a node passes a test.

Parameters:

  • test (Function, string, or Node, optional) — When not given, return is return true.

    Passing a string is equal to passing function (node) {return node.type === test}.

    Passing a node is equal to passing function (node) {return node === test}.

  • node (Node) — Node to test;

  • index (number, optional) — Position of node in parent;

  • parent (Node, optional) — Parent of node;

  • context (*, optional) — Parent of node.

Returns: boolean, whether test passed.

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 this iteration passes.

License

MIT © Titus Wormer