Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Parse given string to slug friendly
- * @param {String} string
- * @return {String}
- */
- parseTextToSlug(string) {
- return (
- removeDiacritics(string)
- .toLowerCase()
- .trim()
- // remove everything that's not letter, digit, hyphen or whitespace
- .replace(/[^a-z0-9\-\s]/g, '')
- // remove leading digits and consecutive whitespaces or hyphens
- .replace(/^[0-9\s|-]+/g, '')
- // replace whitespaces with hyphens
- .replace(/\s+/g, '-')
- // remove multiple hyphens
- .replace(/-+/g, '-')
- // remove leading hyphens
- .replace(/^-|-$/g, '')
- )
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement