How does this library handle transliteration of non-ASCII characters?
How does this library handle transliteration of non-ASCII characters?
About sindresorhus/slugify · 2 messages · last activity 6/29/2026
The slugify library handles transliteration of non-ASCII characters through the transliterate option, which is enabled by default.
Default Behavior (transliterate: true)
When transliteration is enabled, Unicode characters are converted to ASCII equivalents. This is done using the @sindresorhus/transliterate dependency [package.json:L26-L55]. For example:
slugify('Déjà Vu');
//=> 'deja-vu'
The transliteration process is locale-aware. You can specify a locale via the locale option to get language-specific transliteration results [index.d.ts:L151-L180]:
slugify('Räksmörgås');
//=> 'raeksmoergas'
slugify('Räksmörgås', {locale: 'sv'});
//=> 'raksmorgas'
Disabling Transliteration (transliterate: false)
When you set transliterate: false, non-ASCII characters are preserved instead of being transliterated. This improves performance if you don't need ASCII conversion [index.d.ts:L176-L205]:
slugify('Déjà Vu', {transliterate: false});
//=> 'déjà-vu'
Implementation Details
In the code, when transliteration is disabled, Unicode letter and number patterns are added to the character preservation pattern [index.js:L26-L55]:
if (options.transliterate === false) {
negationSetPattern += String.raw`\p{L}\p{N}`;
}
The regex flags also change based on this setting—'gu' (with Unicode flag) when transliteration is off, and 'g' when it's on [index.js:L26-L55].
FOLLOW_UPS:
- What locales does transliterate support?
- How are custom replacements applied to transliteration?
- Can you preserve specific characters while transliterating others?
Want to ask your own question?
Open chat for sindresorhus/slugifyPublic Q&A. Generated by RepoPilot from the actual source of sindresorhus/slugify. AI answers can be incomplete or stale — verify before relying on them.