initial tags api
This commit is contained in:
1 parent
11d628fd50
commit
ec2609e900
6 files changed
+156
-9
No files matched your search
@@ -0,0 +1,5 @@
|
||||
export function unique<T>(items: T[], key: (item: T) => string): T[]{
|
||||
const map = new Map(items.map(x => [key(x), x]))
|
||||
|
||||
return [...map.values()]
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
const map = new Map<string, string>([
|
||||
['', '_'],
|
||||
|
||||
['А', 'A'],
|
||||
['а', 'a'],
|
||||
['Б', 'B'],
|
||||
['б', 'b'],
|
||||
['В', 'V'],
|
||||
['в', 'v'],
|
||||
['Г', 'G'],
|
||||
['г', 'g'],
|
||||
['Д', 'D'],
|
||||
['д', 'd'],
|
||||
['Е', 'E'],
|
||||
['е', 'e'],
|
||||
['Ё', 'E'],
|
||||
['ё', 'e'],
|
||||
['Ж', 'Zh'],
|
||||
['ж', 'zh'],
|
||||
['З', 'Z'],
|
||||
['з', 'z'],
|
||||
['И', 'I'],
|
||||
['и', 'i'],
|
||||
['Й', 'Y'],
|
||||
['й', 'y'],
|
||||
['К', 'K'],
|
||||
['к', 'k'],
|
||||
['Л', 'L'],
|
||||
['л', 'l'],
|
||||
['М', 'M'],
|
||||
['м', 'm'],
|
||||
['Н', 'N'],
|
||||
['н', 'n'],
|
||||
['О', 'O'],
|
||||
['о', 'o'],
|
||||
['П', 'P'],
|
||||
['п', 'p'],
|
||||
['Р', 'R'],
|
||||
['р', 'r'],
|
||||
['С', 'S'],
|
||||
['с', 's'],
|
||||
['Т', 'T'],
|
||||
['т', 't'],
|
||||
['У', 'U'],
|
||||
['у', 'u'],
|
||||
['Ф', 'F'],
|
||||
['ф', 'f'],
|
||||
['Х', 'Kh'],
|
||||
['х', 'kh'],
|
||||
['Ц', 'Ts'],
|
||||
['ц', 'ts'],
|
||||
['Ч', 'Ch'],
|
||||
['ч', 'ch'],
|
||||
['Ш', 'Sh'],
|
||||
['ш', 'sh'],
|
||||
['Щ', 'Sch'],
|
||||
['щ', 'sch'],
|
||||
['ь', ''],
|
||||
['Ы', 'Y'],
|
||||
['ы', 'y'],
|
||||
['ъ', ''],
|
||||
['Э', 'E'],
|
||||
['э', 'e'],
|
||||
['Ю', 'Yu'],
|
||||
['ю', 'yu'],
|
||||
['Я', 'Ya'],
|
||||
['я', 'ya'],
|
||||
])
|
||||
|
||||
export function translit(sample: string): string {
|
||||
return [...sample]
|
||||
.map(char => {
|
||||
if (map.has(char)) {
|
||||
return map.get(char)
|
||||
}
|
||||
|
||||
return ''
|
||||
})
|
||||
.join('')
|
||||
}
|
||||
Reference in new issue
Block a user