Gathering detailed insights and metrics for @sindresorhus/slugify
Gathering detailed insights and metrics for @sindresorhus/slugify
Gathering detailed insights and metrics for @sindresorhus/slugify
Gathering detailed insights and metrics for @sindresorhus/slugify
@cvpcasada/slugify
sindresorhus' slugify packaged for the browser
@types/sindresorhus__slugify
Stub TypeScript definitions entry for @sindresorhus/slugify, which provides its own types definitions
sindresorhus__slugify
@gaiama/slugger
Opinionated slugger - handles duplicates & pre-configures @sindresorhus/slugify
npm install @sindresorhus/slugify
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.6
Supply Chain
99.5
Quality
75.9
Maintenance
100
Vulnerability
100
License
JavaScript (94.5%)
TypeScript (5.5%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2,627 Stars
67 Commits
80 Forks
18 Watchers
1 Branches
18 Contributors
Updated on Jul 13, 2025
Latest Version
2.2.1
Package Id
@sindresorhus/slugify@2.2.1
Unpacked Size
14.95 kB
Size
4.51 kB
File Count
6
NPM Version
9.2.0
Node Version
20.1.0
Published on
May 17, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
Slugify a string
Useful for URLs, filenames, and IDs.
It handles most major languages, including German (umlauts), Vietnamese, Arabic, Russian, and more.
$ npm install @sindresorhus/slugify
1import slugify from '@sindresorhus/slugify'; 2 3slugify('I ♥ Dogs'); 4//=> 'i-love-dogs' 5 6slugify(' Déjà Vu! '); 7//=> 'deja-vu' 8 9slugify('fooBar 123 $#%'); 10//=> 'foo-bar-123' 11 12slugify('я люблю единорогов'); 13//=> 'ya-lyublyu-edinorogov'
Type: string
String to slugify.
Type: object
Type: string
Default: '-'
1import slugify from '@sindresorhus/slugify'; 2 3slugify('BAR and baz'); 4//=> 'bar-and-baz' 5 6slugify('BAR and baz', {separator: '_'}); 7//=> 'bar_and_baz' 8 9slugify('BAR and baz', {separator: ''}); 10//=> 'barandbaz'
Type: boolean
Default: true
Make the slug lowercase.
1import slugify from '@sindresorhus/slugify'; 2 3slugify('Déjà Vu!'); 4//=> 'deja-vu' 5 6slugify('Déjà Vu!', {lowercase: false}); 7//=> 'Deja-Vu'
Type: boolean
Default: true
Convert camelcase to separate words. Internally it does fooBar
→ foo bar
.
1import slugify from '@sindresorhus/slugify'; 2 3slugify('fooBar'); 4//=> 'foo-bar' 5 6slugify('fooBar', {decamelize: false}); 7//=> 'foobar'
Type: Array<string[]>
Default: [ ['&', ' and '], ['🦄', ' unicorn '], ['♥', ' love '] ]
Add your own custom replacements.
The replacements are run on the original string before any other transformations.
This only overrides a default replacement if you set an item with the same key, like &
.
1import slugify from '@sindresorhus/slugify'; 2 3slugify('Foo@unicorn', { 4 customReplacements: [ 5 ['@', 'at'] 6 ] 7}); 8//=> 'fooatunicorn'
Add a leading and trailing space to the replacement to have it separated by dashes:
1import slugify from '@sindresorhus/slugify'; 2 3slugify('foo@unicorn', { 4 customReplacements: [ 5 ['@', ' at '] 6 ] 7}); 8//=> 'foo-at-unicorn'
Another example:
1import slugify from '@sindresorhus/slugify'; 2 3slugify('I love 🐶', { 4 customReplacements: [ 5 ['🐶', 'dogs'] 6 ] 7}); 8//=> 'i-love-dogs'
Type: boolean
Default: false
If your string starts with an underscore, it will be preserved in the slugified string.
Sometimes leading underscores are intentional, for example, filenames representing hidden paths on a website.
1import slugify from '@sindresorhus/slugify'; 2 3slugify('_foo_bar'); 4//=> 'foo-bar' 5 6slugify('_foo_bar', {preserveLeadingUnderscore: true}); 7//=> '_foo-bar'
Type: boolean
Default: false
If your string ends with a dash, it will be preserved in the slugified string.
For example, using slugify on an input field would allow for validation while not preventing the user from writing a slug.
1import slugify from '@sindresorhus/slugify'; 2 3slugify('foo-bar-'); 4//=> 'foo-bar' 5 6slugify('foo-bar-', {preserveTrailingDash: true}); 7//=> 'foo-bar-'
Type: string[]
Default: []
Preserve certain characters.
It cannot contain the separator
.
For example, if you want to slugify URLs, but preserve the HTML fragment #
character.
1import slugify from '@sindresorhus/slugify'; 2 3slugify('foo_bar#baz', {preserveCharacters: ['#']}); 4//=> 'foo-bar#baz'
Returns a new instance of slugify(string, options?)
with a counter to handle multiple occurrences of the same string.
1import {slugifyWithCounter} from '@sindresorhus/slugify'; 2 3const slugify = slugifyWithCounter(); 4 5slugify('foo bar'); 6//=> 'foo-bar' 7 8slugify('foo bar'); 9//=> 'foo-bar-2' 10 11slugify.reset(); 12 13slugify('foo bar'); 14//=> 'foo-bar'
If, for example, you have a document with multiple sections where each subsection has an example.
1## Section 1 2 3### Example 4 5## Section 2 6 7### Example
You can then use slugifyWithCounter()
to generate unique HTML id
's to ensure anchors will link to the right headline.
Reset the counter
1import {slugifyWithCounter} from '@sindresorhus/slugify'; 2 3const slugify = slugifyWithCounter(); 4 5slugify('foo bar'); 6//=> 'foo-bar' 7 8slugify('foo bar'); 9//=> 'foo-bar-2' 10 11slugify.reset(); 12 13slugify('foo bar'); 14//=> 'foo-bar'
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 13/30 approved changesets -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More