unist-util-is

WebJar for unist-util-is

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

unist-util-is
Last Version

Last Version

4.0.4
Release Date

Release Date

Type

Type

jar
Description

Description

unist-util-is
WebJar for unist-util-is
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/syntax-tree/unist-util-is

Download unist-util-is

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/unist-util-is/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>unist-util-is</artifactId>
    <version>4.0.4</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/unist-util-is/
implementation 'org.webjars.npm:unist-util-is:4.0.4'
// https://jarcasting.com/artifacts/org.webjars.npm/unist-util-is/
implementation ("org.webjars.npm:unist-util-is:4.0.4")
'org.webjars.npm:unist-util-is:jar:4.0.4'
<dependency org="org.webjars.npm" name="unist-util-is" rev="4.0.4">
  <artifact name="unist-util-is" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='unist-util-is', version='4.0.4')
)
libraryDependencies += "org.webjars.npm" % "unist-util-is" % "4.0.4"
[org.webjars.npm/unist-util-is "4.0.4"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

unist-util-is

Build Coverage Downloads Size Sponsors Backers Chat

unist utility to check if a node passes a test.

Install

npm:

npm install unist-util-is

Use

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({children: []}) // => false
is(node) // => true
is(node, 'strong') // => true
is(node, 'emphasis') // => false

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

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

API

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

Parameters
  • node (Node) — Node to check.
  • test (Function, string, Object, or Array.<Test>, optional) — When nullish, checks if node is a Node. When string, works like passing node => node.type === test. When array, checks if any one of the subtests pass. When object, checks that all keys in test are in node, and that they have strictly equal values
  • index (number, optional) — Index 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 a non-empty string).

function test(node[, index, parent])

Parameters
  • node (Node) — Node to check
  • index (number?) — Index of node in parent
  • parent (Node?) — Parent of node
Context

* — The to is given context.

Returns

boolean? — Whether node matches.

is.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 an is-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('unist-util-is/convert').

For example:

var u = require('unist-builder')
var convert = require('unist-util-is/convert')

var test = convert('leaf')

var tree = u('tree', [
  u('node', [u('leaf', '1')]),
  u('leaf', '2'),
  u('node', [u('leaf', '3'), u('leaf', '4')]),
  u('leaf', '5')
])

var leafs = tree.children.filter((child, index) => test(child, index, tree))

console.log(leafs)

Yields:

[{type: 'leaf', value: '2'}, {type: 'leaf', value: '5'}]

Related

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.

License

MIT © Titus Wormer

org.webjars.npm
🌲🌲🌲🌳🌲🌳🌲🌲🌲🌳🌳🌲🌲🌳🌲🌲🎄🌲🌳🌲🌲🌳🐻🌳🌳🌳🌲🌲🌳🌲🎄🌲🌳🌲🌲🌳🌳🌳

Versions

Version
4.0.4
4.0.2
4.0.0
3.0.0
2.1.3
2.1.2
2.1.1