-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrans.pipe.ts
39 lines (34 loc) · 1.06 KB
/
trans.pipe.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Georgian names translate
*
* Copyright (c) 2018 Devsullo
* Influenced from GeoKBD
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
*/
import { Pipe, PipeTransform } from '@angular/core';
const symbols = 'abgdevzTiklmnopJrstufqRySCcZwWxjh',
specSymbols = ['zh', 'gh', 'sh', 'ch', 'ts', 'dz', 'ts', 'ch', 'kh'],
specSymbolsMatch = ['ჟ', 'ღ', 'შ', 'ჩ', 'ც', 'ძ', 'წ', 'ჭ', 'ხ'];
@Pipe({
name: 'trans'
})
export class TransPipe implements PipeTransform {
transform(value: string): string {
const _value = value.toLocaleLowerCase();
const text = [];
let indexI, indexK;
for (let i = 0; i < _value.length; i++) {
const chr = _value.substr(i, 1);
const chr2 = _value.substr(i, 2);
if ((indexI = specSymbols.indexOf(chr2)) >= 0) {
text.push(specSymbolsMatch[indexI]);
i += 1;
} else if ((indexK = symbols.indexOf(chr)) >= 0) {
text.push(String.fromCharCode(indexK + 4304));
} else {
text.push(chr);
}
}
return text.join('');
}
}