• Stars
    star
    293
  • Rank 140,848 (Top 3 %)
  • Language
    JavaScript
  • License
    ISC License
  • Created almost 9 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

:octocat: Generate a slug just like GitHub does for markdown headings.

github-slugger

npm Build

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.

Install

npm install github-slugger

Usage

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

Contributing

Contributions welcome! Please read the contributing guidelines first.

License

ISC

More Repositories

1

rejected-github-profile-achievements

😵 GitHub achievements that did not make the cut.
416
star
2

prettier-bytes

💎 augment pretty-bytes to make the output a little more readable (and a little less precise)
JavaScript
98
star
3

SublimeLinter-contrib-standard

Python
71
star
4

tape-nock

📼 Automatically record and playback HTTP calls for each tape test.
JavaScript
62
star
5

doublestandard

‼️ feross/standard but with even more semicolon goodness
JavaScript
46
star
6

eslint-to-esformatter

JavaScript
30
star
7

HerpFortress

Notch's Herp Fortress
Java
29
star
8

clockmoji

🕗 Get an emoji clock representation of the current time.
JavaScript
23
star
9

markdown-it-github-headings

:octocat: Add anchors and links to headings just like Github does
JavaScript
23
star
10

SublimeLinter-contrib-semistandard

Python
13
star
11

spacewall

👾 Set your wallpaper to the latest NASA's Astronomy Photo of the Day
JavaScript
8
star
12

marky-deep-links

🔗 Make heading links work in marky-markdown generated HTML
JavaScript
6
star
13

episode.lol

📺 Pick a random episode of your favorite TV show!
Vue
6
star
14

eslint-plugin-double-semi

eslint rule to require double semicolons
JavaScript
6
star
15

spaceship-warrior-gradle

a gradle version of spaceship-warrior-redux
Java
5
star
16

jwst-hubble-compare

A quick image comparison between JWST first image and Hubble image of galaxy cluster SMACS 0723.
JavaScript
4
star
17

mixcoffee

☕ Dashboard and API for tracking coffee fund via google spreadsheet
JavaScript
4
star
18

spaceship-warrior-redux

Java
4
star
19

awesome-covfefe

Delightful and entertaining covfefe related resources
4
star
20

maybe-hugs-www

❔ Website for zkat/maybe-hugs
HTML
3
star
21

room-names

🏠 List of room names curated from Wikipedia
JavaScript
3
star
22

can-haz-package

🍔 Check if an npm package name is valid and does not currently exist.
JavaScript
3
star
23

dailyconnect

Node JavaScript API to access data from dailyconnect.
JavaScript
3
star
24

git-em-all

🐶 Clone/Pull an array of git repositories as fast as possible.
JavaScript
2
star
25

nice-api

🍦 A nice api that exposes a google sheet through a REST interface
JavaScript
2
star
26

slugger-unique

⚾ Create slugs using slugger while ensuring they are unique.
JavaScript
1
star
27

flet

📇 A fun digital business card
JavaScript
1
star
28

tape-nock-with-supertest-example

JavaScript
1
star
29

dotfiles

Shell
1
star
30

soundmix

Silly server to play sounds remotely
JavaScript
1
star
31

exitzero

Ensure a command always exist with zero status.
JavaScript
1
star
32

magictyper

JavaScript
1
star
33

yuslap

JavaScript
1
star
34

cursorfun

JavaScript
1
star
35

playground

a sample application that leverages the BestBuy/api-playground dataset
JavaScript
1
star
36

console

📺 JS Console Fun! https://flet.github.io/console
JavaScript
1
star
37

revisit-mutagen

A hapi plugin to easily expose a http://revisit.link glitch as a service that adheres to http://revisit.link/spec.html
JavaScript
1
star