Advertisement
Guest User

Untitled

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