-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
30 lines (27 loc) · 967 Bytes
/
index.js
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
var chars = [
'AaÁáÀàÂâÄäAĄąȺⱥǍǎȦȧẠạĀāÃãå',
'CcĆćĈĉÇçȻȼČčĊċ',
'EeÉéÈèÊêËëȨȩĘęɆɇĚěĖėẸẹĒēẼẽ',
'IiÍíÌìÎîÏïĮįƗɨǏǐİiỊịĪīĨĩ',
'JjĴĵɈɉǰ',
'LlĹĺĻļŁłȽƚĽľḶḷ',
'NnŃńǸǹŅņꞤꞥŇňṅṆṇÑñ',
'OoÓóÒòÔôÖöǪǫØøƟɵǑǒȮȯỌọŌōÕõ',
'SsŚśŜŝŞşꞨꞩŠšṠṡṢṣ',
'TtẗŢţȾⱦŦŧŤťṪṫṬṭ',
'UuÚúÙùÛûÜüŲųɄʉǓǔỤụŪūŨũ',
'YyÝýỲỳŶŷŸÿɎɏẎẏỴỵȲȳỸỹ',
'ZzŹźẐẑƵƶŽžŻżẒẓ'
];
function escapeRegExp(string) {
return string.replace(/([.*+?^${}()|\[\]\/\\])/g, "\\$1");
}
var diacritic = function(text) {
if (!text) return '';
var result = escapeRegExp(text);
for (var i = 0; i < chars.length; i++) {
result = result.replace(new RegExp('[' + chars[i] + ']', 'gi'), '[' + chars[i] + ']');
}
return result;
};
module.exports = diacritic;