GithubHelp home page GithubHelp logo

kryndex / unist-util-is Goto Github PK

View Code? Open in Web Editor NEW

This project forked from syntax-tree/unist-util-is

0.0 2.0 0.0 20 KB

Utility to check if a node passes a test

License: MIT License

JavaScript 100.00%

unist-util-is's Introduction

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, or Node, optional) — When not given, checks if node is a Node. When string, works like passing function (node) {return node.type === test}. 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 (*, optiona) — 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

unist-util-is's People

Contributors

wooorm avatar greenkeeperio-bot avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.