Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static friendlyUrl(input = null, ligature = null) {
- if (input === null) return;
- const withAccent =
- 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝŔÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿŕ';
- const withoutAccent =
- 'AAAAAAACEEEEIIIIDNOOOOOOUUUUYRsBaaaaaaaceeeeiiiionoooooouuuuybyr';
- const specialCharactere = ` !"#$%&'()*+,-./:;<=>?@[\\]^_\`{|}~`;
- let newString = '';
- for (let i = 0; i < input.length; i++) {
- let change = false;
- for (let a = 0; a < withAccent.length; a++) {
- if (input.substr(i, 1) === withAccent.substr(a, 1)) {
- newString += withoutAccent.substr(a, 1);
- change = true;
- break;
- }
- }
- for (let b = 0; b < specialCharactere.length; b++) {
- if (input.substr(i, 1) === specialCharactere.substr(b, 1)) {
- newString += ' ';
- change = true;
- break;
- }
- }
- if (change === false) {
- newString += input.substr(i, 1);
- }
- }
- newString = newString.toLowerCase().split(' ');
- newString = newString.filter(el => {
- return el !== '';
- });
- const slug = ligature !== null ? ligature : '-';
- return newString.join(slug);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement