reslug
v1.0.0
Published
Context-aware slugger
Downloads
3
Readme
Reslug
A library for generating unique slugs from strings. It's useful for generating URL slugs from titles, Markdown headings, etc. Zero dependencies, written in TypeScript, and works in Node.js (also Bun!) and the browser.
Installation
npm install reslug
Usage
import Reslug, { slug } from 'reslug';
const slugger = new Reslug();
slugger.slug('Hello, world!'); // hello-world
slugger.slug('Hello, world!'); // hello-world-1
slugger.slug('Hello, world!'); // hello-world-2
slugger.reset();
slugger.slug('Hello, world!'); // hello-world
// You can also use slug() function to generate
// slugs without context.
slug('Hello, world!'); // hello-world
slug('Hello, world!'); // hello-world
Acknowledgements
This library is a rewrite of github-slugger, made by Flet. You should check his project!