@n1k1t/transliterate-cjs
v1.6.2
Published
Fork of @sindresorhus/transliterate with CommonJS module resolution
Downloads
1
Maintainers
Readme
Forked
This package has CommonJS module resolution instead ESM in original
transliterate
Convert Unicode characters to Latin characters using transliteration
Can be useful for slugification purposes and other times you cannot use Unicode.
Install
$ npm install @n1k1t/transliterate-cjs
Usage
// For JS (Node/CommonJS)
const transliterate = require('@n1k1t/transliterate-cjs');
// For Typescript with CommonJS module resolution
import transliterate from '@n1k1t/transliterate-cjs';
transliterate('Fußgängerübergänge');
//=> 'Fussgaengeruebergaenge'
transliterate('Я люблю единорогов');
//=> 'Ya lyublyu edinorogov'
transliterate('أنا أحب حيدات');
//=> 'ana ahb hydat'
transliterate('tôi yêu những chú kỳ lân');
//=> 'toi yeu nhung chu ky lan'
API
transliterate(string, options?)
string
Type: string
String to transliterate.
options
Type: object
customReplacements
Type: Array<string[]>
Default: []
Add your own custom replacements.
The replacements are run on the original string before any other transformations.
This only overrides a default replacement if you set an item with the same key.
transliterate('Я люблю единорогов', {
customReplacements: [
['единорогов', '🦄']
]
})
//=> 'Ya lyublyu 🦄'
Supported languages
Most major languages are supported.
This includes special handling for:
- Arabic
- Armenian
- Czech
- Danish
- Dhivehi
- Georgian
- German (umlauts)
- Greek
- Hungarian
- Latin
- Latvian
- Lithuanian
- Macedonian
- Pashto
- Persian
- Polish
- Romanian
- Russian
- Serbian
- Slovak
- Swedish
- Turkish
- Ukrainian
- Urdu
- Vietnamese
However, Chinese is currently not supported.
Related
- slugify - Slugify a string