JSFiddle - React, Tailwind, and code Playground

by kinduff

JavaScript

console.log(
slugify("/2013/04/02/entendiendo-la-transformacion-3d-con-css3/")
)
console.log("2013-04-02-entendiendo-la-transformacion-3d-con-css3")

function slugify(text) {
  return text.toString().toLowerCase()
    .replace(/\s+/g, '-')           // Replace spaces with -
    .replace(/\.|:|\//g, '-')       // Replace . : / with -
    .replace(/[^\w\-]+/g, '')       // Remove all non-word chars
    .replace(/\-\-+/g, '-')         // Replace multiple - with single -
    .replace(/^-+/, '')             // Trim - from start of text
    .replace(/-+$/, '');            // Trim - from end of text
}