[go: up one dir, main page]

@stream-io/transliterate
TypeScript icon, indicating that this package has built-in type declarations

1.5.5 • Public • Published

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 @sindresorhus/transliterate

Usage

import transliterate from '@sindresorhus/transliterate';

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.

import transliterate from '@sindresorhus/transliterate';

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

Package Sidebar

Install

npm i @stream-io/transliterate

Weekly Downloads

60,710

Version

1.5.5

License

MIT

Unpacked Size

374 kB

Total Files

15

Last publish

Collaborators

  • vangalilea88
  • martincupela
  • stream-release-bot
  • caleb.murphy
  • zita.szupera
  • tbarbugli
  • tschellenbach
  • vishtree