Last active
November 22, 2017 13:18
-
-
Save kalkulus/7cecc00140754746c55771ed45611091 to your computer and use it in GitHub Desktop.
js slugify text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from https://gist.github.com/kalkulus/5d536faba9a6d4d8c0413a5989cd46ac | |
const utf2ascii = (text) => { | |
const combining = /[\u0300-\u036F]/g; | |
return str.normalize('NFKD').replace(combining, '')); | |
}; | |
const slugify = (text) => { | |
let st = text.toLowerCase(); | |
st = utf2ascii(st); | |
st = st.replace(/[^a-z0-9 ]+/gi,''); | |
st = st.trim().replace(/ /g,'-'); | |
st = st.replace(/[\-]{2,}/g,'-'); | |
return (st.replace(/[^a-z\- ]*/gi,'')); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment