-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
index.ts
56 lines (53 loc) · 1.09 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* Locale character mapping rules.
*/
interface Locale {
regexp: RegExp;
map: Record<string, string>;
}
/**
* Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
*/
const SUPPORTED_LOCALE: Record<string, Locale> = {
tr: {
regexp: /\u0130|\u0049|\u0049\u0307/g,
map: {
İ: "\u0069",
I: "\u0131",
İ: "\u0069"
}
},
az: {
regexp: /\u0130/g,
map: {
İ: "\u0069",
I: "\u0131",
İ: "\u0069"
}
},
lt: {
regexp: /\u0049|\u004A|\u012E|\u00CC|\u00CD|\u0128/g,
map: {
I: "\u0069\u0307",
J: "\u006A\u0307",
Į: "\u012F\u0307",
Ì: "\u0069\u0307\u0300",
Í: "\u0069\u0307\u0301",
Ĩ: "\u0069\u0307\u0303"
}
}
};
/**
* Localized lower case.
*/
export function localeLowerCase(str: string, locale: string) {
const lang = SUPPORTED_LOCALE[locale.toLowerCase()];
if (lang) return lowerCase(str.replace(lang.regexp, m => lang.map[m]));
return lowerCase(str);
}
/**
* Lower case as a function.
*/
export function lowerCase(str: string) {
return str.toLowerCase();
}