Skip to content

Commit

Permalink
Refactor to improve bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 11, 2020
1 parent e6d4059 commit 040f01c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
'use strict'

var slugs = require('github-slugger')()
var visit = require('unist-util-visit')
var toString = require('hast-util-to-string')
var is = require('hast-util-is-element')
var has = require('hast-util-has-property')
var rank = require('hast-util-heading-rank')
var toString = require('hast-util-to-string')
var visit = require('unist-util-visit')

module.exports = slug

var headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']

function slug() {
return transformer
}
Expand All @@ -18,7 +16,7 @@ function transformer(tree) {
slugs.reset()

visit(tree, 'element', function (node) {
if (is(node, headings) && !has(node, 'id')) {
if (rank(node) && !has(node, 'id')) {
node.properties.id = slugs.slug(toString(node))
}
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"github-slugger": "^1.1.1",
"hast-util-has-property": "^1.0.0",
"hast-util-is-element": "^1.0.0",
"hast-util-heading-rank": "^1.0.0",
"hast-util-to-string": "^1.0.0",
"unist-util-visit": "^2.0.0"
},
Expand Down

0 comments on commit 040f01c

Please sign in to comment.