MultiLoader-Template/node_modules/es-toolkit/dist/string/deburr.mjs
3944Realms 768f38fc97 feat: 可使用的构建模板
修改了脚本,使其可以推给Maven仓库
2026-05-03 13:02:19 +08:00

46 lines
905 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const deburrMap = new Map([
['Æ', 'Ae'],
['Ð', 'D'],
['Ø', 'O'],
['Þ', 'Th'],
['ß', 'ss'],
['æ', 'ae'],
['ð', 'd'],
['ø', 'o'],
['þ', 'th'],
['Đ', 'D'],
['đ', 'd'],
['Ħ', 'H'],
['ħ', 'h'],
['ı', 'i'],
['IJ', 'IJ'],
['ij', 'ij'],
['ĸ', 'k'],
['Ŀ', 'L'],
['ŀ', 'l'],
['Ł', 'L'],
['ł', 'l'],
['ʼn', "'n"],
['Ŋ', 'N'],
['ŋ', 'n'],
['Œ', 'Oe'],
['œ', 'oe'],
['Ŧ', 'T'],
['ŧ', 't'],
['ſ', 's'],
]);
function deburr(str) {
str = str.normalize('NFD');
let result = '';
for (let i = 0; i < str.length; i++) {
const char = str[i];
if ((char >= '\u0300' && char <= '\u036f') || (char >= '\ufe20' && char <= '\ufe23')) {
continue;
}
result += deburrMap.get(char) ?? char;
}
return result;
}
export { deburr };