-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlowerCase.ts
65 lines (58 loc) · 1.19 KB
/
lowerCase.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
57
58
59
60
61
62
63
64
65
/**
* via: https://github.com/blakeembrey/lower-case
*/
import { LanguageSpecific } from "./types.ts";
/**
* Special language-specific overrides.
* Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt
*/
const LANGUAGES: LanguageSpecific = {
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",
},
},
};
/**
* Convert a `string` to lower case.
*
* Example:
*
* ```ts
* lowerCase("TEST STRING");
* //=> "test string"
* ```
*/
export default function (str: string, locale?: string): string {
str = str == null ? "" : String(str);
if (!locale) {
return str.toLowerCase();
}
const lang = LANGUAGES[locale];
if (lang) {
str = str.replace(lang.regexp, (m: string): string => lang.map[m]);
}
return str.toLowerCase();
}