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/1/2026
The sindresorhus/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 their ASCII equivalents. For example [readme.md:L226-L241]:
slugify('Déjà Vu');
//=> 'deja-vu'
The library uses the @sindresorhus/transliterate package as a dependency [package.json:L38] to handle this conversion. This supports most major languages including German umlauts, Vietnamese, Arabic, Russian, and more.
The transliteration respects locale settings. You can specify a locale for language-specific transliteration behavior [index.d.ts:L151-L180]:
slugify('Räksmörgås');
//=> 'raeksmoergas'
slugify('Räksmörgås', {locale: 'sv'});
//=> 'raksmorgas'
When Transliteration is Disabled (transliterate: false)
When you set transliterate: false, non-ASCII characters are preserved instead of being transliterated [readme.md:L226-L241]:
slugify('Déjà Vu', {transliterate: false});
//=> 'déjà-vu'
The tests demonstrate this behavior across various scripts [test.js:L226-L255]:
- French:
'Déjà Vu'→'déjà-vu' - Swedish:
'Räksmörgås'→'räksmörgås' - Chinese:
'你好世界'→'你好世界' - Arabic:
'مرحبا'→'مرحبا'
In the implementation [index.js:L26-L55], the regex pattern used for character filtering changes based on the transliterate option: when disabled, it includes Unicode letter and number categories (\p{L}\p{N}) to preserve these characters.
FOLLOW_UPS:
- What does the
localeoption affect in transliteration? - How does
preserveCharactersoption interact with transliteration? - What custom replacements does the library apply by default?
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.