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 5/25/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, the library converts Unicode characters to ASCII equivalents. For example [readme.md:L226-L255]:
slugify('Déjà Vu');
//=> 'deja-vu'
This works by leveraging the @sindresorhus/transliterate dependency [package.json:L26-L55], which handles language-specific transliteration including German umlauts, Vietnamese, Arabic, Russian, and more.
The library also supports locale-specific transliteration through the locale option [index.d.ts:L151-L180]:
slugify('Räksmörgås');
//=> 'raeksmoergas'
slugify('Räksmörgås', {locale: 'sv'});
//=> 'raksmorgas'
Disabling Transliteration (transliterate: false)
When transliteration is disabled, non-ASCII characters are preserved instead of converted [readme.md:L226-L255]:
slugify('Déjà Vu', {transliterate: false});
//=> 'déjà-vu'
The implementation handles this by adjusting the regex pattern used to process characters. When transliterate === false, Unicode letter and number categories are preserved in the pattern [index.js:L26-L55]:
if (options.transliterate === false) {
negationSetPattern += String.raw`\p{L}\p{N}`;
}
FOLLOW_UPS:
- What's the difference between transliterate and lowercase options?
- How do custom replacements interact with transliteration?
- Does locale affect transliteration for all languages supported?
Want to ask your own question?
Open chat for sindresorhus/slugify →Public Q&A. Generated by RepoPilot from the actual source of sindresorhus/slugify. AI answers can be incomplete or stale — verify before relying on them.