Skip to content

Commit 22d878b

Browse files
committed
Update unist-util-is
1 parent 1088c8f commit 22d878b

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

lib/search.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ module.exports = search
44

55
var toString = require('mdast-util-to-string')
66
var visit = require('unist-util-visit')
7-
var is = require('unist-util-is')
7+
var convert = require('unist-util-is/convert')
88
var slugs = require('github-slugger')()
99

10-
var HEADING = 'heading'
10+
var heading = convert('heading')
1111

1212
// Search a node for a location.
1313
function search(root, expression, settings) {
1414
var length = root.children.length
1515
var depth = null
1616
var lookingForToc = expression !== null
1717
var maxDepth = settings.maxDepth || 6
18-
var parents = settings.parents || root
18+
var parents = convert(settings.parents || root)
1919
var map = []
2020
var headingIndex
2121
var closingIndex
@@ -28,7 +28,7 @@ function search(root, expression, settings) {
2828

2929
// Visit all headings in `root`. We `slug` all headings (to account for
3030
// duplicates), but only create a TOC from top-level headings.
31-
visit(root, HEADING, onheading)
31+
visit(root, 'heading', onheading)
3232

3333
if (headingIndex && !closingIndex) {
3434
closingIndex = length + 1
@@ -46,7 +46,7 @@ function search(root, expression, settings) {
4646
var value = toString(child)
4747
var id = child.data && child.data.hProperties && child.data.hProperties.id
4848

49-
if (!is(parents, parent)) {
49+
if (!parents(parent)) {
5050
return
5151
}
5252

@@ -74,15 +74,10 @@ function search(root, expression, settings) {
7474

7575
// Check if `node` is the main heading.
7676
function isOpeningHeading(node, depth, expression) {
77-
return (
78-
depth === null &&
79-
node &&
80-
node.type === HEADING &&
81-
expression.test(toString(node))
82-
)
77+
return depth === null && heading(node) && expression.test(toString(node))
8378
}
8479

8580
// Check if `node` is the next heading.
8681
function isClosingHeading(node, depth) {
87-
return depth && node && node.type === HEADING && node.depth <= depth
82+
return depth && heading(node) && node.depth <= depth
8883
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"extend": "^3.0.2",
2424
"github-slugger": "^1.2.1",
2525
"mdast-util-to-string": "^1.0.5",
26-
"unist-util-is": "^2.1.2",
26+
"unist-util-is": "^3.0.0",
2727
"unist-util-visit": "^1.1.0"
2828
},
2929
"devDependencies": {

0 commit comments

Comments
 (0)