-
Notifications
You must be signed in to change notification settings - Fork 2
/
upperCase.ts
55 lines (49 loc) · 936 Bytes
/
upperCase.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
import { LanguageSpecific } from "./types.ts";
const LANGUAGES: LanguageSpecific = {
tr: {
regexp: /[\u0069]/g,
map: {
i: "\u0130",
},
},
az: {
regexp: /[\u0069]/g,
map: {
i: "\u0130",
},
},
lt: {
regexp: /[\u0069\u006A\u012F]\u0307|\u0069\u0307[\u0300\u0301\u0303]/g,
map: {
i̇: "\u0049",
j̇: "\u004A",
į̇: "\u012E",
i̇̀: "\u00CC",
i̇́: "\u00CD",
i̇̃: "\u0128",
},
},
};
/**
* Convert a `string` to upper case.
*
* Example:
*
* ```ts
* upperCase("test string");
* //=> "TEST STRING"
* ```
*/
export default function (str: string, locale?: string): string {
str = str == null ? "" : String(str);
if (!locale) {
return str.toUpperCase();
}
const lang = LANGUAGES[locale];
if (lang) {
str = str.replace(lang.regexp, function (m) {
return lang.map[m];
});
}
return str.toUpperCase();
}