Skip to content

Latest commit

 

History

History
89 lines (57 loc) · 2.41 KB

readme.md

File metadata and controls

89 lines (57 loc) · 2.41 KB

unist-util-find-before Build Status Coverage Status

Unist utility to find a node before another node.

Installation

npm:

npm install unist-util-find-before

Usage

var remark = require('remark');
var findBefore = require('unist-util-find-before');

var tree = remark().parse('Some _emphasis_, **importance**, and `code`.');
var paragraph = tree.children[0];
var code = paragraph.children[paragraph.children.length - 1];

console.log(findBefore(paragraph, code, 'emphasis'));

Yields:

{ type: 'emphasis',
  children: [ { type: 'text', value: 'emphasis' } ] }

API

findBefore(parent, node|index[, test])

Find the first child before index (or node) in parent, that passes test (when given).

Parameters
  • parent (Node) — Context node
  • node (Node) — Node in parent
  • index (number, optional) — Position of a node in parent
  • test (Function, string, or Node, optional) — See unist-util-is
Returns

Node? — Child node of parent passing test.

Related

License

MIT © Titus Wormer