Created
May 23, 2022 14:46
Revisions
-
dtw revised this gist
May 23, 2022 . No changes.There are no files selected for viewing
-
dtw created this gist
May 23, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ function slugify(text) { // from https://gist.github.com/codeguy/6684588?permalink_comment_id=3243980#gistcomment-3243980 return text .toString() // Cast to string (optional) .normalize('NFKD') // The normalize() using NFKD method returns the Unicode Normalization Form of a given string. .toLowerCase() // Convert the string to lowercase letters .trim() // Remove whitespace from both sides of a string (optional) .replace(/\s+/g, '-') // Replace spaces with - .replace(/[^\w\-]+/g, '') // Remove all non-word chars .replace(/\-\-+/g, '-') // Replace multiple - with single - .replace(/\-$/g, ''); // Remove trailing - }