@samk-dev/astratto-ui
Version:
Yes, yet another UI library. Built on top of UIkit 3, it's exclusive to Nuxt
35 lines (34 loc) • 1.9 kB
JavaScript
export const useSlugify = (text) => {
text = text.toString().toLowerCase().trim();
const sets = [
{ to: "a", from: "[\xC0\xC1\xC2\xC3\xC4\xC5\xC6\u0100\u0102\u0104\u1EA0\u1EA2\u1EA4\u1EA6\u1EA8\u1EAA\u1EAC\u1EAE\u1EB0\u1EB2\u1EB4\u1EB6\u1F00]" },
{ to: "c", from: "[\xC7\u0106\u0108\u010C]" },
{ to: "d", from: "[\xD0\u010E\u0110\xDE]" },
{ to: "e", from: "[\xC8\xC9\xCA\xCB\u0112\u0114\u0116\u0118\u011A\u1EB8\u1EBA\u1EBC\u1EBE\u1EC0\u1EC2\u1EC4\u1EC6]" },
{ to: "g", from: "[\u011C\u011E\u0122\u01F4]" },
{ to: "h", from: "[\u0124\u1E26]" },
{ to: "i", from: "[\xCC\xCD\xCE\xCF\u0128\u012A\u012E\u0130\u1EC8\u1ECA]" },
{ to: "j", from: "[\u0134]" },
{ to: "ij", from: "[\u0132]" },
{ to: "k", from: "[\u0136]" },
{ to: "l", from: "[\u0139\u013B\u013D\u0141]" },
{ to: "m", from: "[\u1E3E]" },
{ to: "n", from: "[\xD1\u0143\u0145\u0147]" },
{ to: "o", from: "[\xD2\xD3\xD4\xD5\xD6\xD8\u014C\u014E\u0150\u1ECC\u1ECE\u1ED0\u1ED2\u1ED4\u1ED6\u1ED8\u1EDA\u1EDC\u1EDE\u1EE0\u1EE2\u01EA\u01EC\u01A0]" },
{ to: "oe", from: "[\u0152]" },
{ to: "p", from: "[\u1E55]" },
{ to: "r", from: "[\u0154\u0156\u0158]" },
{ to: "s", from: "[\xDF\u015A\u015C\u015E\u0160\u0218]" },
{ to: "t", from: "[\u0162\u0164]" },
{ to: "u", from: "[\xD9\xDA\xDB\xDC\u0168\u016A\u016C\u016E\u0170\u0172\u1EE4\u1EE6\u1EE8\u1EEA\u1EEC\u1EEE\u1EF0\u01AF]" },
{ to: "w", from: "[\u1E82\u0174\u1E80\u1E84]" },
{ to: "x", from: "[\u1E8D]" },
{ to: "y", from: "[\xDD\u0176\u0178\u1EF2\u1EF4\u1EF6\u1EF8]" },
{ to: "z", from: "[\u0179\u017B\u017D]" },
{ to: "-", from: "[\xB7/_,:;']" }
];
sets.forEach((set) => {
text = text.replace(new RegExp(set.from, "gi"), set.to);
});
return text.replace(/\s+/g, "-").replace(/[^-a-zа-я\u0370-\u03FF\u1F00-\u1FFF]+/g, "").replace(/--+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
};