Files
site/node_modules/@sindresorhus/transliterate/index.d.ts
T
site-admin 3ac81d5a52
deploy / build-and-publish (push) Successful in 1m37s
the editable site (validation-lab)
2026-11-21 08:03:55 +01:00

88 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export type Options = {
/**
Add your own custom replacements.
The replacements are run on the original string before any other transformations. Both the string and the keys are normalized to NFC first, so a key matches canonically equivalent text.
This only overrides a default replacement if you set an item with the same key.
@default []
@example
```
import transliterate from '@sindresorhus/transliterate';
transliterate('Я люблю единорогов', {
customReplacements: [
['единорогов', '🦄']
]
})
//=> 'Ya lyublyu 🦄'
```
@example
```
import transliterate from '@sindresorhus/transliterate';
transliterate('foo & bar', {
customReplacements: new Map([
['&', 'and']
])
})
//=> 'foo and bar'
```
*/
readonly customReplacements?: ReadonlyArray<[string, string]> | Map<string, string>;
/**
[BCP-47](https://developer.mozilla.org/en-US/docs/Glossary/BCP_47_language_tag) language tag for language-specific transliteration.
When specified, uses language-specific replacement rules for characters that have different transliterations in different languages.
The `no` and `nn` language codes are aliases for `nb`.
@example
```
import transliterate from '@sindresorhus/transliterate';
// Swedish: ä→a, ö→o, å→a
transliterate('Räksmörgås', {locale: 'sv'});
//=> 'Raksmorgas'
// German: ä→ae, ö→oe
transliterate('Räksmörgås', {locale: 'de'});
//=> 'Raeksmoergas'
```
*/
readonly locale?: string;
};
/**
Convert Unicode characters to Latin characters using [transliteration](https://en.wikipedia.org/wiki/Transliteration).
Throws a `RangeError` if any string being normalized contains more than 100 consecutive Unicode combining marks. This includes the input, custom replacement keys, and intermediate results. The total string length is not limited.
@param string - String to transliterate.
@example
```
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'
transliterate('En–dashes and em—dashes are normalized');
//=> 'En-dashes and em-dashes are normalized'
```
*/
export default function transliterate(string: string, options?: Options): string;