Skip to content

Instantly share code, notes, and snippets.

@eek eek/slugify.js
Last active Apr 30, 2018

Embed
What would you like to do?
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 '-'
}
@exside

This comment has been minimized.

Copy link

exside commented Oct 30, 2017

Wont work in IE...because (as expected) it doesn't support normalize(), otherwise nice to know =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.