Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.          * Parse given string to slug friendly
  3.          * @param  {String} string
  4.          * @return {String}
  5.          */
  6.         parseTextToSlug(string) {
  7.             return (
  8.                 removeDiacritics(string)
  9.                     .toLowerCase()
  10.                     .trim()
  11.                     // remove everything that's not letter, digit, hyphen or whitespace
  12.                     .replace(/[^a-z0-9\-\s]/g, '')
  13.                     // remove leading digits and consecutive whitespaces or hyphens
  14.                     .replace(/^[0-9\s|-]+/g, '')
  15.                     // replace whitespaces with hyphens
  16.                     .replace(/\s+/g, '-')
  17.                     // remove multiple hyphens
  18.                     .replace(/-+/g, '-')
  19.                     //  remove leading hyphens
  20.                     .replace(/^-|-$/g, '')
  21.             )
  22.         },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement