Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am khairaf on github.
  • I am fitra_ (https://keybase.io/fitra_) on keybase.
  • I have a public key ASBaGRQtuRFrK1s7lRyKrilZbt8_HlL6yZvW24TvZHoJdwo

To claim this, I am signing this object:

@khairaf
khairaf / slugify.js
Created June 30, 2020 04:02 — forked from hagemann/slugify.js
Slugify makes a string URI-friendly
function slugify(string) {
const a = 'àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/_,:;'
const b = 'aaaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnoooooooooprrsssssttuuuuuuuuuwxyyzzz------'
const p = new RegExp(a.split('').join('|'), 'g')
return string.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w\-]+/g, '') // Remove all non-word characters