Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save marcelo-ribeiro/abd651b889e4a20e0bab558a05d38d77 to your computer and use it in GitHub Desktop.

Select an option

Save marcelo-ribeiro/abd651b889e4a20e0bab558a05d38d77 to your computer and use it in GitHub Desktop.

Revisions

  1. marcelo-ribeiro revised this gist Aug 18, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion javascript-slugify.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // Example: https://codepen.io/marcelo-ribeiro/pen/PomqOvE

    const accentsMap = new Map([
    ["-", "\\s|_"],
    ["-", "\\s|\\.|_"],
    ["a", "á|à|ã|â|ä"],
    ["e", "é|è|ê|ë"],
    ["i", "í|ì|î|ï"],
  2. marcelo-ribeiro revised this gist Jul 1, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion javascript-slugify-normalize.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    export const removeAccents = text => text
    export const slugify = text => text
    .replace(/\s|_|\(|\)/g, "-")
    .normalize("NFD").replace(/\p{Diacritic}/gu, "")
    .toLowerCase()
  3. marcelo-ribeiro revised this gist Jul 1, 2021. 2 changed files with 5 additions and 6 deletions.
    7 changes: 4 additions & 3 deletions javascript-slugify-normalize.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    export const slugify = text => text
    .replace(/\\s|_|(|)/g, "-")
    .normalize("NFD").replace(/\p{Diacritic}/gu, "")
    export const removeAccents = text => text
    .replace(/\s|_|\(|\)/g, "-")
    .normalize("NFD").replace(/\p{Diacritic}/gu, "")
    .toLowerCase()
    4 changes: 1 addition & 3 deletions javscript-remove-accents-normalize.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1 @@
    export const removeAccents = text => text
    .replace(/\s|_|\(|\)/g, "-")
    .normalize("NFD").replace(/\p{Diacritic}/gu, "")
    export const removeAccents = text => text.normalize("NFD").replace(/\p{Diacritic}/gu, "")
  4. marcelo-ribeiro revised this gist Jul 1, 2021. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion javscript-remove-accents-normalize.js
    Original file line number Diff line number Diff line change
    @@ -1 +1,3 @@
    export const removeAccents = text => text.normalize("NFD").replace(/\p{Diacritic}/gu, "")
    export const removeAccents = text => text
    .replace(/\s|_|\(|\)/g, "-")
    .normalize("NFD").replace(/\p{Diacritic}/gu, "")
  5. marcelo-ribeiro revised this gist Jul 1, 2021. 2 changed files with 4 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions javascript-slugify-normalize.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    export const slugify = text => text
    .replace(/\\s|_|(|)/g, "-")
    .normalize("NFD").replace(/\p{Diacritic}/gu, "")
    1 change: 1 addition & 0 deletions javscript-remove-accents-normalize.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    export const removeAccents = text => text.normalize("NFD").replace(/\p{Diacritic}/gu, "")
  6. marcelo-ribeiro revised this gist Jul 1, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // Example: https://codepen.io/marcelo-ribeiro/pen/PomqOvE
    // Example: https://codepen.io/marcelo-ribeiro/pen/OJmVOyW

    const accentsMap = new Map([
    ["A", "Á|À|Ã|Â|Ä"],
  7. marcelo-ribeiro revised this gist Jul 1, 2021. 2 changed files with 6 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    // Example: https://codepen.io/marcelo-ribeiro/pen/PomqOvE

    const accentsMap = new Map([
    ["A", "Á|À|ã|Ã|Â|Ä"],
    ["A", "Á|À|Ã|Â|Ä"],
    ["a", "á|à|ã|â|ä"],
    ["E", "É|È|Ê|Ë"],
    ["e", "é|è|ê|ë"],
    @@ -11,7 +13,7 @@ const accentsMap = new Map([
    ["u", "ú|ù|û|ü"],
    ["C", "Ç"],
    ["c", "ç"],
    ["N", "Ñ"]
    ["N", "Ñ"],
    ["n", "ñ"]
    ]);

    2 changes: 2 additions & 0 deletions javascript-slugify.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    // Example: https://codepen.io/marcelo-ribeiro/pen/PomqOvE

    const accentsMap = new Map([
    ["-", "\\s|_"],
    ["a", "á|à|ã|â|ä"],
  8. marcelo-ribeiro revised this gist Jul 1, 2021. 2 changed files with 23 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,20 @@
    const accentsMap = new Map([
    ["-", "\\s|_"],
    ["A", "Á|À|ã|Ã|Â|Ä"],
    ["a", "á|à|ã|â|ä"],
    ["E", "É|È|Ê|Ë"],
    ["e", "é|è|ê|ë"],
    ["I", "Í|Ì|Î|Ï"],
    ["i", "í|ì|î|ï"],
    ["O", "Ó|Ò|Ô|Õ|Ö"],
    ["o", "ó|ò|ô|õ|ö"],
    ["U", "Ú|Ù|Û|Ü"],
    ["u", "ú|ù|û|ü"],
    ["C", "Ç"],
    ["c", "ç"],
    ["N", "Ñ"]
    ["n", "ñ"]
    ]);

    const reducer = (acc, [key]) => acc.replace(new RegExp(accentsMap.get(key), "gi"), key);
    const reducer = (acc, [key]) => acc.replace(new RegExp(accentsMap.get(key), "g"), key);

    export const slugify = (text) => [...accentsMap].reduce(reducer, text.toLowerCase());
    export const removeAccents = (text) => [...accentsMap].reduce(reducer, text);
    14 changes: 14 additions & 0 deletions javascript-slugify.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    const accentsMap = new Map([
    ["-", "\\s|_"],
    ["a", "á|à|ã|â|ä"],
    ["e", "é|è|ê|ë"],
    ["i", "í|ì|î|ï"],
    ["o", "ó|ò|ô|õ|ö"],
    ["u", "ú|ù|û|ü"],
    ["c", "ç"],
    ["n", "ñ"]
    ]);

    const reducer = (acc, [key]) => acc.replace(new RegExp(accentsMap.get(key), "gi"), key);

    export const slugify = (text) => [...accentsMap].reduce(reducer, text.toLowerCase());
  9. marcelo-ribeiro revised this gist Jul 1, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -11,4 +11,4 @@ const accentsMap = new Map([

    const reducer = (acc, [key]) => acc.replace(new RegExp(accentsMap.get(key), "gi"), key);

    export const slugify = (text) => [...accentsMap].reduce(reducer, text.toLowerCase());
    export const slugify = (text) => [...accentsMap].reduce(reducer, text.toLowerCase());
  10. marcelo-ribeiro revised this gist Jul 1, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,6 @@ const accentsMap = new Map([
    ["n", "ñ"]
    ]);

    const reducer = (acc, key) => acc.replace(new RegExp(accentsMap.get(key), "gi"), key);
    const reducer = (acc, [key]) => acc.replace(new RegExp(accentsMap.get(key), "gi"), key);

    export const slugify = (text) => [...accentsMap.keys()].reduce(reducer, text.toLowerCase());
    export const slugify = (text) => [...accentsMap].reduce(reducer, text.toLowerCase());
  11. marcelo-ribeiro revised this gist Jul 1, 2021. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -9,8 +9,6 @@ const accentsMap = new Map([
    ["n", "ñ"]
    ]);

    const reducer = (acc, key) =>
    acc.replace(new RegExp(accentsMap.get(key), "gi"), key);
    const reducer = (acc, key) => acc.replace(new RegExp(accentsMap.get(key), "gi"), key);

    export const slugify = (text) =>
    [...accentsMap.keys()].reduce(reducer, text.toLowerCase());
    export const slugify = (text) => [...accentsMap.keys()].reduce(reducer, text.toLowerCase());
  12. marcelo-ribeiro revised this gist Jul 1, 2021. 1 changed file with 14 additions and 17 deletions.
    31 changes: 14 additions & 17 deletions javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,16 @@
    const slugify = str => {
    const map = {
    '-' : ' ',
    '-' : '_',
    'a' : 'á|à|ã|â|ä|À|Á|Ã|Â|Ä',
    'e' : 'é|è|ê|ë|É|È|Ê|Ë',
    'i' : 'í|ì|î|ï|Í|Ì|Î|Ï',
    'o' : 'ó|ò|ô|õ|ö|Ó|Ò|Ô|Õ|Ö',
    'u' : 'ú|ù|û|ü|Ú|Ù|Û|Ü',
    'c' : 'ç|Ç',
    'n' : 'ñ|Ñ'
    };
    const accentsMap = new Map([
    ["-", "\\s|_"],
    ["a", "á|à|ã|â|ä"],
    ["e", "é|è|ê|ë"],
    ["i", "í|ì|î|ï"],
    ["o", "ó|ò|ô|õ|ö"],
    ["u", "ú|ù|û|ü"],
    ["c", "ç"],
    ["n", "ñ"]
    ]);

    for (var pattern in map) {
    str = str.replace(new RegExp(map[pattern], 'g'), pattern);
    }
    const reducer = (acc, key) =>
    acc.replace(new RegExp(accentsMap.get(key), "gi"), key);

    return str;
    }
    export const slugify = (text) =>
    [...accentsMap.keys()].reduce(reducer, text.toLowerCase());
  13. marcelo-ribeiro revised this gist Apr 9, 2021. 1 changed file with 10 additions and 10 deletions.
    20 changes: 10 additions & 10 deletions javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,18 @@
    const slugify = str => {
    const map = {
    '-' : ' ',
    '-' : '_',
    'a' : 'á|à|ã|â|ä|À|Á|Ã|Â|Ä',
    'e' : 'é|è|ê|ë|É|È|Ê|Ë',
    'i' : 'í|ì|î|ï|Í|Ì|Î|Ï',
    'o' : 'ó|ò|ô|õ|ö|Ó|Ò|Ô|Õ|Ö',
    'u' : 'ú|ù|û|ü|Ú|Ù|Û|Ü',
    'c' : 'ç|Ç',
    'n' : 'ñ|Ñ'
    '-' : ' ',
    '-' : '_',
    'a' : 'á|à|ã|â|ä|À|Á|Ã|Â|Ä',
    'e' : 'é|è|ê|ë|É|È|Ê|Ë',
    'i' : 'í|ì|î|ï|Í|Ì|Î|Ï',
    'o' : 'ó|ò|ô|õ|ö|Ó|Ò|Ô|Õ|Ö',
    'u' : 'ú|ù|û|ü|Ú|Ù|Û|Ü',
    'c' : 'ç|Ç',
    'n' : 'ñ|Ñ'
    };

    for (var pattern in map) {
    str = str.replace(new RegExp(map[pattern], 'g'), pattern);
    str = str.replace(new RegExp(map[pattern], 'g'), pattern);
    }

    return str;
  14. marcelo-ribeiro revised this gist Apr 9, 2021. 1 changed file with 16 additions and 16 deletions.
    32 changes: 16 additions & 16 deletions javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,19 @@
    const slugify = str => {
    const map = {
    '-' : ' ',
    '-' : '_',
    'a' : 'á|à|ã|â|ä|À|Á|Ã|Â|Ä',
    'e' : 'é|è|ê|ë|É|È|Ê|Ë',
    'i' : 'í|ì|î|ï|Í|Ì|Î|Ï',
    'o' : 'ó|ò|ô|õ|ö|Ó|Ò|Ô|Õ|Ö',
    'u' : 'ú|ù|û|ü|Ú|Ù|Û|Ü',
    'c' : 'ç|Ç',
    'n' : 'ñ|Ñ'
    };

    for (var pattern in map) {
    str = str.replace(new RegExp(map[pattern], 'g'), pattern);
    }
    const map = {
    '-' : ' ',
    '-' : '_',
    'a' : 'á|à|ã|â|ä|À|Á|Ã|Â|Ä',
    'e' : 'é|è|ê|ë|É|È|Ê|Ë',
    'i' : 'í|ì|î|ï|Í|Ì|Î|Ï',
    'o' : 'ó|ò|ô|õ|ö|Ó|Ò|Ô|Õ|Ö',
    'u' : 'ú|ù|û|ü|Ú|Ù|Û|Ü',
    'c' : 'ç|Ç',
    'n' : 'ñ|Ñ'
    };

    return str;
    for (var pattern in map) {
    str = str.replace(new RegExp(map[pattern], 'g'), pattern);
    }

    return str;
    }
  15. marcelo-ribeiro revised this gist Apr 9, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    function slugify (str) {
    var map = {
    const slugify = str => {
    const map = {
    '-' : ' ',
    '-' : '_',
    'a' : 'á|à|ã|â|ä|À|Á|Ã|Â|Ä',
  16. marcelo-ribeiro revised this gist Apr 9, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ function slugify (str) {

    for (var pattern in map) {
    str = str.replace(new RegExp(map[pattern], 'g'), pattern);
    };
    }

    return str;
    };
    }
  17. marcelo-ribeiro revised this gist Mar 11, 2021. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -2,10 +2,10 @@ function slugify (str) {
    var map = {
    '-' : ' ',
    '-' : '_',
    'a' : 'á|à|ã|â|À|Á|Ã|Â',
    'e' : 'é|è|ê|É|È|Ê',
    'i' : 'í|ì|î|Í|Ì|Î',
    'o' : 'ó|ò|ô|õ|Ó|Ò|Ô|Õ',
    'a' : 'á|à|ã|â|ä|À|Á|Ã|Â',
    'e' : 'é|è|ê|ë|É|È|Ê',
    'i' : 'í|ì|î|ï|Í|Ì|Î',
    'o' : 'ó|ò|ô|õ|ö|Ó|Ò|Ô|Õ',
    'u' : 'ú|ù|û|ü|Ú|Ù|Û|Ü',
    'c' : 'ç|Ç',
    'n' : 'ñ|Ñ'
  18. marcelo-ribeiro revised this gist Jul 28, 2020. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,6 @@ function slugify (str) {
    'n' : 'ñ|Ñ'
    };

    str = str.toLowerCase();

    for (var pattern in map) {
    str = str.replace(new RegExp(map[pattern], 'g'), pattern);
    };
  19. marcelo-ribeiro revised this gist Feb 10, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ function slugify (str) {
    '-' : '_',
    'a' : 'á|à|ã|â|À|Á|Ã|Â',
    'e' : 'é|è|ê|É|È|Ê',
    'i' : 'í|ì|î',
    'i' : 'í|ì|î|Í|Ì|Î',
    'o' : 'ó|ò|ô|õ|Ó|Ò|Ô|Õ',
    'u' : 'ú|ù|û|ü|Ú|Ù|Û|Ü',
    'c' : 'ç|Ç',
  20. marcelo-ribeiro revised this gist Feb 10, 2017. No changes.
  21. marcelo-ribeiro revised this gist Feb 10, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    function slugify (str) {
    var map = {
    '-' : ' ',
    '-' : '_',
    'a' : 'á|à|ã|â|À|Á|Ã|Â',
    'e' : 'é|è|ê|É|È|Ê',
    'i' : 'í|ì|î',
  22. marcelo-ribeiro renamed this gist Feb 10, 2017. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions angularJS_removeAccents.js → javascript-remove-accents.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    function removeAccents (str) {
    map = {
    function slugify (str) {
    var map = {
    'a' : 'á|à|ã|â|À|Á|Ã|Â',
    'e' : 'é|è|ê|É|È|Ê',
    'i' : 'í|ì|î',
    @@ -9,9 +9,11 @@ function removeAccents (str) {
    'n' : 'ñ|Ñ'
    };

    angular.forEach(map, function (pattern, newValue) {
    str = str.replace(new RegExp(pattern, 'g'), newValue);
    });
    str = str.toLowerCase();

    for (var pattern in map) {
    str = str.replace(new RegExp(map[pattern], 'g'), pattern);
    };

    return str;
    };
  23. Fábio Santos revised this gist Dec 10, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions angularJS_removeAccents.js
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,9 @@ function removeAccents (str) {
    'e' : 'é|è|ê|É|È|Ê',
    'i' : 'í|ì|î',
    'o' : 'ó|ò|ô|õ|Ó|Ò|Ô|Õ',
    'u' : 'ú|ù|û|Ú|Ù|Û',
    'c' : 'ç|Ç'
    'u' : 'ú|ù|û|ü|Ú|Ù|Û|Ü',
    'c' : 'ç|Ç',
    'n' : 'ñ|Ñ'
    };

    angular.forEach(map, function (pattern, newValue) {
  24. Fábio Santos created this gist Dec 10, 2015.
    16 changes: 16 additions & 0 deletions angularJS_removeAccents.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    function removeAccents (str) {
    map = {
    'a' : 'á|à|ã|â|À|Á|Ã|Â',
    'e' : 'é|è|ê|É|È|Ê',
    'i' : 'í|ì|î',
    'o' : 'ó|ò|ô|õ|Ó|Ò|Ô|Õ',
    'u' : 'ú|ù|û|Ú|Ù|Û',
    'c' : 'ç|Ç'
    };

    angular.forEach(map, function (pattern, newValue) {
    str = str.replace(new RegExp(pattern, 'g'), newValue);
    });

    return str;
    };