@se-oss/slugify is a high-performance, strictly typed slugification library with support for Unicode transliteration, smart casing, and custom character preservation.
npm install @se-oss/slugifyInstall using your favorite package manager
pnpm
pnpm install @se-oss/slugifyyarn
yarn add @se-oss/slugifyimport slugify from '@se-oss/slugify';
slugify('I ♥ Cats');
//=> 'i-love-cats'
slugify(' Déjà Vu! ');
//=> 'deja-vu'
slugify('я люблю единорогов');
//=> 'ya-lyublyu-edinorogov'- Smart Decamelization: Automatically handles camelCase and PascalCase.
- Character Preservation: Keep specific symbols like
#or@as-is. - Collision Handling: Generate unique slugs using a counter.
- Transliteration: Powered by
@se-oss/transliteratefor robust script support.
import { slugifyWithCounter } from '@se-oss/slugify';
slugify('fooBar 123 $#%', { decamelize: true });
//=> 'foo-bar-123'
const slug = slugifyWithCounter();
slug('foo bar'); //=> 'foo-bar'
slug('foo bar'); //=> 'foo-bar-2'For more information, please see the API docs.
| Library | hz | min | max | mean | p99 | rme |
|---|---|---|---|---|---|---|
| @se-oss/slugify | 336,028.90 | 0.0027 | 2.4412 | 0.0030 | 0.0048 | ±0.98% |
| simov/slugify | 323,177.82 | 0.0028 | 0.2437 | 0.0031 | 0.0038 | ±0.21% |
| @sindresorhus/slugify | 1,936.71 | 0.4814 | 3.0069 | 0.5163 | 0.8098 | ±1.22% |
Result: @se-oss/slugify is 173x faster than @sindresorhus/slugify.
Benchmark script: bench/index.bench.ts
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub.
Thanks again for your support, it is much appreciated! 🙏
MIT © Shahrad Elahi and contributors.