Skip to content

Instantly share code, notes, and snippets.

@tarciozemel
Forked from eek/slugify.js
Created January 22, 2018 17:17
Show Gist options
  • Save tarciozemel/ab483d44fb5333b866220a861d7114d3 to your computer and use it in GitHub Desktop.
Save tarciozemel/ab483d44fb5333b866220a861d7114d3 to your computer and use it in GitHub Desktop.
Vanilla JavaScript Slugify + Accent removal - Just another JavaScript Slugifier with an extra line for Accent Removal
function slugify(text) {
return text.toString().toLowerCase().trim()
.normalize('NFD') // separate accent from letter
.replace(/[\u0300-\u036f]/g, '') // remove all separated accents
.replace(/\s+/g, '-') // replace spaces with -
.replace(/&/g, '-and-') // replace & with 'and'
.replace(/[^\w\-]+/g, '') // remove all non-word chars
.replace(/\-\-+/g, '-') // replace multiple '-' with single '-'
}
@junajan
Copy link

junajan commented Apr 12, 2020

nice 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment