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/18/2026
The sindresorhus/slugify library handles transliteration of non-ASCII characters through a configurable option that leverages an external dependency.
Default Behavior
By default, the library transliterates Unicode characters to ASCII. It uses the @sindresorhus/transliterate package [package.json:L26-L55] to convert non-ASCII characters to their ASCII equivalents. For example:
slugify('Déjà Vu');
//=> 'deja-vu'
The accented characters é and à are converted to their ASCII counterparts e and a.
Transliteration Option
You can disable transliteration by setting transliterate: false in the options [index.d.ts:L176-L205]:
slugify('Déjà Vu', {transliterate: false});
//=> 'déjà-vu'
When disabled, non-ASCII characters are preserved in the slug instead of being converted. This can improve performance when transliteration isn't needed [readme.md:L226-L255].
Pattern Building
In the implementation, when transliteration is disabled, the library adjusts its regex pattern to preserve Unicode letters and numbers. The buildPatternSlug function [index.js:L26-L55] adds \p{L}\p{N} to the negation set pattern when transliterate === false, allowing Unicode letter and number characters to be kept in the output.
Additionally, you can use the locale option to specify language-specific transliteration rules [index.d.ts:L151-L180], which is passed through to the @sindresorhus/transliterate package.
FOLLOW_UPS:
- What does the
localeoption control? - How are custom character replacements processed?
- What regex flags are used for pattern matching?
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.