npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rokt33r/unist-util-is

v3.0.1-1

Published

Utility to check if a node passes a test

Downloads

4

Readme

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

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({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 not given, 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.

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, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer