Package Exports
- unist-util-find
- unist-util-find/index.js
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) 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 
Unist node finder utility. Useful for working with remark, rehype and retext.
Installation
npm install --save unist-util-find
Usage
Example
var remark = require('remark')
var find = require('unist-util-find')
remark()
.use(function () {
return function (tree) {
// string condition
console.log(find(tree, 'value'))
// object condition
console.log(find(tree, { value: 'emphasis' }))
// function condition
console.log(find(tree, function (node) {
return node.type === 'inlineCode'
}))
}
})
.processSync('Some _emphasis_, **strongness**, and `code`.')
Result:
// string condition: 'value'
{ type: 'text',
value: 'Some ',
position:
Position {
start: { line: 1, column: 1, offset: 0 },
end: { line: 1, column: 6, offset: 5 },
indent: [] } }
// object condition: { value: 'emphasis' }
{ type: 'text',
value: 'emphasis',
position:
Position {
start: { line: 1, column: 7, offset: 6 },
end: { line: 1, column: 15, offset: 14 },
indent: [] } }
// function condition: function (node) { return node.type === 'inlineCode' }
{ type: 'inlineCode',
value: 'code',
position:
Position {
start: { line: 1, column: 38, offset: 37 },
end: { line: 1, column: 44, offset: 43 },
indent: [] } }
API
find(node, condition)
Return the first node that matches condition
, or undefined
if no node matches.
node
(Node
) - Node to searchcondition
(string
,object
orfunction
) - Condition used to test each node. Behaviour depends on the type of the condition:string
finds first node with a truthy property matchingstring
object
finds first node that has matching values for all properties ofobject
function
finds first node for whichfunction
returns true when passednode
as argument
License
MIT