Skip to content

Instantly share code, notes, and snippets.

@kalkulus
Last active November 22, 2017 13:18
Show Gist options
  • Save kalkulus/7cecc00140754746c55771ed45611091 to your computer and use it in GitHub Desktop.
Save kalkulus/7cecc00140754746c55771ed45611091 to your computer and use it in GitHub Desktop.
js slugify text
// 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