Skip to content

Instantly share code, notes, and snippets.

@ktquez
Last active June 3, 2016 17:53
Show Gist options
  • Save ktquez/ed78b7cedd33b239bd37fcce8a5d4455 to your computer and use it in GitHub Desktop.
Save ktquez/ed78b7cedd33b239bd37fcce8a5d4455 to your computer and use it in GitHub Desktop.
slug (value) {
const mapLetters = {
a: /(á|ã|â|à)/g,
e: /(é|ê)/g,
i: /(í)/g,
o: /(ó|ô|õ)/g,
u: /(ú)/g,
c: /(ç)/g,
n: /(ñ)/g
}
for (let letter in mapLetters) {
let rexp = mapLetters[letter]
value = value.toLowerCase() // :) Avoid include capital letters in regex
.replace(rexp, letter)
.replace(/(\s|\.)/g, '-') // Replace space by delimiter '-'
}
return value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment