Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on Dec 26, 2023 via pnpm

github-slugger 1.1.0

Generate a slug just like GitHub does for markdown headings.
Package summary
Share
0
issues
0
licenses
Package created
22 Sep 2015
Version published
22 Apr 2016
Maintainers
5
Total deps
0
Direct deps
0
License
ISC

Issues

0
This package has no issues

Frequently Asked Questions

What does github-slugger do?

Github-slugger is an npm package designed to generate slugs similar to how GitHub does for markdown headings. Its function is not limited to slug generation but it also ensures the uniqueness of these slugs, paralleling the way GitHub does it. It's worth noting that github-slugger is not a markdown or HTML parser, therefore, it operates on the plain text value of the heading and not on encoded text. Its primary objective is to replicate the way GitHub manages the creation of markdown heading anchors as meticulously as possible.

How do you use github-slugger?

To use github-slugger, first install the package in your project by running npm install github-slugger. You can then import it into your JavaScript files using import GithubSlugger from 'github-slugger'. To generate a slug, instantiate GithubSlugger and use the slug() function of the instance.

Here's how:

import GithubSlugger from 'github-slugger'

const slugger = new GithubSlugger()

slugger.slug('foo') // returns 'foo'
slugger.slug('foo') // returns 'foo-1' (as it ensures uniqueness)
slugger.slug('bar') // returns 'bar'
slugger.slug('Привет non-latin 你好') // returns 'привет-non-latin-你好' (handles non-latin texts)
slugger.slug('😄 emoji') // returns '-emoji' (handles emojis)

This instance will remember the slugs it has generated. If you want to reset it, simply call the reset() function. Here's an example:

slugger.reset()
slugger.slug('foo') // now it returns 'foo' again

One can also use the underlying slug function, which does not keep track of previous entries. However, this is not recommended, and should be done as follows:

import GithubSlugger, {slug} from 'github-slugger'
slug('foo bar baz') // returns 'foo-bar-baz'

Where are the github-slugger docs?

The documentation for github-slugger is found in its readme file on GitHub. Visit GithubSlugger's GitHub repository for detailed usage instructions and examples. The test/fixtures.json file, within the same repository, contains more examples on usage. Please refer to this documentation for any further clarification or information.