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/15/2026
The slugify library handles transliteration of non-ASCII characters through the transliterate option, which defaults to true [index.d.ts:L176-L180].
When transliteration is enabled (the default), the library uses the @sindresorhus/transliterate dependency [index.js:L2] to convert Unicode characters to their ASCII equivalents. For example:
slugify('Déjà Vu');
//=> 'deja-vu'
When transliteration is disabled by setting transliterate: false, non-ASCII characters are preserved instead:
slugify('Déjà Vu', {transliterate: false});
//=> 'déjà-vu'
Behind the scenes, the library adjusts its character pattern matching based on this setting. When transliterate is false, the regex pattern includes \p{L}\p{N} (Unicode letters and numbers) in the negation set [index.js:L26-L28], allowing those characters to pass through unchanged. This also provides a performance benefit when transliteration isn't needed.
Additionally, the library supports a locale option to customize language-specific transliteration behavior [index.d.ts:L151-L165], which gets passed to the underlying @sindresorhus/transliterate package.
FOLLOW_UPS:
- What does the preserveCharacters option do exactly?
- How does the decamelize feature work internally?
- What are the default customReplacements included?
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.