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 7/13/2026
The slugify library handles transliteration of non-ASCII characters through the @sindresorhus/transliterate dependency [package.json:L40], which is a separate package that provides language-specific character mappings.
Default Behavior
By default, the library enables transliteration to convert Unicode characters to ASCII equivalents. For example:
'Déjà Vu'becomes'deja-vu''Räksmörgås'becomes'raeksmoergas'(using default transliteration)- Russian
'я люблю единорогов'becomes'ya-lyublyu-edinorogov'
The library supports many major languages including German umlauts, Vietnamese, Arabic, Russian, Persian, Turkish, Romanian, and more [test.js:L106-L145].
Locale-Specific Transliteration
You can control transliteration behavior through the locale option. Different locales may produce different results:
slugify('Räksmörgås'); // 'raeksmoergas' (default)
slugify('Räksmörgås', {locale: 'sv'}); // 'raksmorgas' (Swedish)
[test.js:L211-L225]
Disabling Transliteration
The transliterate option (default: true) lets you preserve non-ASCII characters instead:
slugify('Déjà Vu', {transliterate: false}); // 'déjà-vu'
When disabled, the regex pattern is modified to preserve Unicode letters and numbers using the \p{L} and \p{N} Unicode property escapes [index.js:L28-L29].
FOLLOW_UPS:
- How does the decamelize option work internally?
- What are the default custom replacements for symbols?
- How does the preserveCharacters option work?
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.