Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function slugify (text) {
  2.   const a = 'àáäâèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;'
  3.   const b = 'aaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------'
  4.   const p = new RegExp(a.split('').join('|'), 'g')
  5.  
  6.   return text.toString().toLowerCase()
  7.     .replace(/\s+/g, '-')           // Replace spaces with -
  8.     .replace(p, c =>
  9.         b.charAt(a.indexOf(c)))     // Replace special chars
  10.     .replace(/&/g, '-and-')         // Replace & with 'and'
  11.     .replace(/[^\w\-]+/g, '')       // Remove all non-word chars
  12.     .replace(/\-\-+/g, '-')         // Replace multiple - with single -
  13.     .replace(/^-+/, '')             // Trim - from start of text
  14.     .replace(/-+$/, '')             // Trim - from end of text
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement