Unist utility to find a node before another node.
npm:
npm install unist-util-find-before
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' } ] }
Find the first child before index
(or node
) in parent
, that passes test
(when given).
parent
(Node
) — Context nodenode
(Node
) — Node inparent
index
(number
, optional) — Position of anode
inparent
test
(Function
,string
, orNode
, optional) — Seeunist-util-is
Node?
— Child node of parent
passing test
.
unist-util-find-after
— Find a node after another nodeunist-util-find-all-after
— Find all nodes after another nodeunist-util-find-all-before
— Find all nodes before another nodeunist-util-find-all-between
— Find all nodes between two nodesunist-util-find
— Find nodes matching a predicate