Skip to content

Commit 0b78050

Browse files
committed
reverting changes to slugify function to be on the safe side as there are no unit tests yet. seems as if some of the escapes could be removed in the future
1 parent 8531ace commit 0b78050

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/utils/slugify.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
/* eslint-disable no-useless-escape */
12
export const slugify = (string: string, separator = "-") => {
23
return string
34
.toString() // Cast to string (optional)
45
.toLowerCase() // Convert the string to lowercase letters
56
.trim() // Remove whitespace from both sides of a string (optional)
67
.replace(/\s+/g, separator) // Replace spaces with {separator}
7-
.replace(/[^\w-]+/g, "") // Remove all non-word chars
8-
.replace(/_/g, separator) // Replace _ with {separator}
9-
.replace(/--+/g, separator) // Replace multiple - with single {separator}
10-
.replace(/-$/g, ""); // Remove trailing -
8+
.replace(/[^\w\-]+/g, "") // Remove all non-word chars
9+
.replace(/\_/g, separator) // Replace _ with {separator}
10+
.replace(/\-\-+/g, separator) // Replace multiple - with single {separator}
11+
.replace(/\-$/g, ""); // Remove trailing -
1112
};

0 commit comments

Comments
 (0)