Socket
Socket
Sign inDemoInstall

github-slugger

Package Overview
Dependencies
Maintainers
5
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github-slugger

Generate a slug just like GitHub does for markdown headings.


Version published
Weekly downloads
6.2M
decreased by-0.59%
Maintainers
5
Weekly downloads
 
Created

What is github-slugger?

The github-slugger npm package generates GitHub-style slugs from strings. These slugs are often used in URLs, markdown headers, and anywhere else where a simplified, URL-friendly identifier for a string is useful. It ensures uniqueness of the slugs within the same document or context by appending incrementing numbers when duplicates are generated.

What are github-slugger's main functionalities?

Generate a slug from a string

This feature allows you to convert any string into a slug that is URL-friendly and resembles the slugs GitHub generates for markdown headers.

"const GithubSlugger = require('github-slugger');
const slugger = new GithubSlugger();
console.log(slugger.slug('Hello World')); // Outputs: 'hello-world'"

Generate unique slugs within the same instance

This demonstrates how github-slugger ensures uniqueness by appending incrementing numbers to slugs generated from identical strings within the same instance.

"const GithubSlugger = require('github-slugger');
const slugger = new GithubSlugger();
console.log(slugger.slug('Hello World')); // Outputs: 'hello-world'
console.log(slugger.slug('Hello World')); // Outputs: 'hello-world-1'"

Resetting the slugger

This feature shows how to reset the internal state of the slugger instance, allowing for the reuse of slugs that were previously incremented.

"const GithubSlugger = require('github-slugger');
const slugger = new GithubSlugger();
slugger.slug('Hello World');
slugger.reset();
console.log(slugger.slug('Hello World')); // Outputs: 'hello-world' again, after reset"

Other packages similar to github-slugger

Keywords

FAQs

Package last updated on 08 Jan 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc