github-slugger
Generate a slug just like GitHub does for markdown headings.
Last updated 7 months ago by flet .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install github-slugger 
SYNC missed versions from official npm registry.

github-slugger

npm travis

Generate a slug just like GitHub does for markdown headings. It also ensures slugs are unique in the same way GitHub does it. The overall goal of this package is to emulate the way GitHub handles generating markdown heading anchors as close as possible.

Install

npm install github-slugger

Usage

var GithubSlugger = require('github-slugger')
var slugger = new GithubSlugger()

slugger.slug('foo')
// returns 'foo'

slugger.slug('foo')
// returns 'foo-1'

slugger.slug('bar')
// returns 'bar'

slugger.slug('foo')
// returns 'foo-2'

slugger.reset()

slugger.slug('foo')
// returns 'foo'

Check test/index.js for more examples.

If you need, you can also use the underlying implementation which does not keep track of the previously slugged strings (not recommended):

var slugger = require('github-slugger').slug;

slug('foo bar baz')
// returns 'foo-bar-baz'

slug('foo bar baz')
// returns the same slug 'foo-bar-baz' because it does not keep track

Contributing

Contributions welcome! Please read the contributing guidelines first.

License

ISC

Current Tags

  • 1.3.0                                ...           latest (7 months ago)

9 Versions

  • 1.3.0                                ...           7 months ago
  • 1.2.1                                ...           2 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.3                                ...           3 years ago
  • 1.1.2                                ...           3 years ago
  • 1.1.1                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Downloads
Today 178
This Week 2,754
This Month 9,863
Last Day 638
Last Week 3,698
Last Month 17,334
Dependencies (1)
Dev Dependencies (4)
Dependents (182)

Copyright 2014 - 2017 © taobao.org |