epiphany/node_modules/@sindresorhus/transliterate
2023-12-09 22:19:03 -08:00
..
node_modules/escape-string-regexp install 11ty 2023-12-09 22:19:03 -08:00
index.d.ts install 11ty 2023-12-09 22:19:03 -08:00
index.js install 11ty 2023-12-09 22:19:03 -08:00
license install 11ty 2023-12-09 22:19:03 -08:00
package.json install 11ty 2023-12-09 22:19:03 -08:00
readme.md install 11ty 2023-12-09 22:19:03 -08:00
replacements.js install 11ty 2023-12-09 22:19:03 -08:00

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

const transliterate = require('@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.

const transliterate = require('@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.