Skip to content

Instantly share code, notes, and snippets.

View edgvi10's full-sized avatar

Eduardo Vieira edgvi10

  • Amora Sistemas, Link Informática RJ
  • Rio de Janeiro
View GitHub Profile
@edgvi10
edgvi10 / slugify.js
Last active August 25, 2020 17:39 — forked from codeguy/slugify.js
Create slug from string in Javascript
String.prototype.slugify = function (separator = "-") {
return this
.toString()
.normalize('NFD') // split an accented letter in the base letter and the acent
.replace(/[\u0300-\u036f]/g, '') // remove all previously split accents
.toLowerCase()
.trim()
.replace(/[^a-z0-9 ]/g, '') // remove all chars not letters, numbers and spaces (to be replaced)
.replace(/\s+/g, separator);
};