Package Exports
- unist-util-find-all-before
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (unist-util-find-all-before) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
unist-util-find-all-before

Unist utility to find nodes before another node. Useful when working with mdast or retext.
Installation
npm:
npm install unist-util-find-all-beforeunist-util-find-all-before is also available for bower and duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.
Usage
var mdast = require('mdast');
var findAllBefore = require('unist-util-find-all-before');
var inspect = require('unist-util-inspect');
function log(nodes) {
console.log(nodes && inspect(nodes));
console.log();
}
mdast.use(function () {
return function (ast) {
var paragraph = ast.children[0];
var children = paragraph.children;
log(findAllBefore(paragraph, 4));
log(findAllBefore(paragraph, children[4]));
log(findAllBefore(paragraph, children[4], 'emphasis'));
};
}).process('Some _emphasis_, **strongness**, and `code`.');Yields (note the order of nodes):
strong[1]
└─ text: 'strongness'
text: ', '
emphasis[1]
└─ text: 'emphasis'
text: 'Some '
strong[1]
└─ text: 'strongness'
text: ', '
emphasis[1]
└─ text: 'emphasis'
text: 'Some '
emphasis[1]
└─ text: 'emphasis'API
findAllBefore(parent, index|node[, test])
Find the nodes before index (or node), that pass test (when given).
Parameters:
parent(Node) — Parent to search in;node(Node) — Node to search before;index(number) — Position of child to search before;test(Function,string, orNode; optional) — Seeis().
Returns: Array.<node>?. Child nodes of parent which pass test.