Skip to content

Instantly share code, notes, and snippets.

@manhnguyenv
Created July 19, 2019 06:58
Show Gist options
  • Save manhnguyenv/f081ea9d6478f437940e233ba8342469 to your computer and use it in GitHub Desktop.
Save manhnguyenv/f081ea9d6478f437940e233ba8342469 to your computer and use it in GitHub Desktop.

Revisions

  1. manhnguyenv created this gist Jul 19, 2019.
    13 changes: 13 additions & 0 deletions toSlug.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    String.prototype.toSlug = function(){
    st = this.toLowerCase();
    st = st.replace(/[\u00C0-\u00C5]/ig,'a')
    st = st.replace(/[\u00C8-\u00CB]/ig,'e')
    st = st.replace(/[\u00CC-\u00CF]/ig,'i')
    st = st.replace(/[\u00D2-\u00D6]/ig,'o')
    st = st.replace(/[\u00D9-\u00DC]/ig,'u')
    st = st.replace(/[\u00D1]/ig,'n')
    st = st.replace(/[^a-z0-9 ]+/gi,'')
    st = st.trim().replace(/ /g,'-');
    st = st.replace(/[\-]{2}/g,'');
    return (st.replace(/[^a-z\- ]*/gi,''));
    }