
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
github-slugger
Advanced tools
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.
This project is not a markdown or HTML parser: passing alpha *bravo* charlie
or alpha <em>bravo</em> charlie doesn’t work.
Instead pass the plain text value of the heading: alpha bravo charlie.
npm install github-slugger
import GithubSlugger from 'github-slugger'
const 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.slug('Привет non-latin 你好')
// returns 'привет-non-latin-你好'
slugger.slug('😄 emoji')
// returns '-emoji'
slugger.reset()
slugger.slug('foo')
// returns 'foo'
Check test/fixtures.json 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):
import GithubSlugger, {slug} from 'github-slugger'
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
Contributions welcome! Please read the contributing guidelines first.
slugify is a similar package that converts strings into URL slugs. Compared to github-slugger, slugify offers more customization options, such as the ability to specify replacement characters, but it does not automatically handle uniqueness within the same context.
uslug is another package for generating slugs from strings. It focuses on creating slugs that are safe for URLs and readable. Unlike github-slugger, uslug does not automatically append numbers to ensure uniqueness, but it provides options for allowing certain special characters to be included.
FAQs
Generate a slug just like GitHub does for markdown headings.
The npm package github-slugger receives a total of 6,745,279 weekly downloads. As such, github-slugger popularity was classified as popular.
We found that github-slugger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.