@@ -148,22 +148,18 @@ export const truncate = (text: string, maxLength = 80, ellipses = true) => {
148
148
}
149
149
150
150
export const slugify = ( text : string ) => {
151
- const slug = text
151
+ return text
152
152
. normalize ( 'NFKD' ) // The normalize() using NFKD method returns the Unicode Normalization Form of a given string.
153
153
. toLowerCase ( ) // Convert the string to lowercase letters
154
- . trim ( ) // Remove whitespace from both sides of a string (optional)
155
- . replace ( / [ ^ a - z 0 - 9 \s _ ] / g, '' ) // Remove characters that are NOT alphanumeric (a-z, 0-9), whitespace, or underscores
156
- . replace ( / \s + / g, '-' ) // Replace spaces with -
157
- . replace ( / _ / g, '-' ) // Replace _ with -
158
- . replace ( / - { 2 , } / g, '-' ) // Replace multiple - with single -
159
- . replace ( / - $ / g, '' ) // Remove trailing -
160
-
161
- return slug
154
+ . trim ( ) // Remove whitespace from both sides of a string
155
+ . replace ( / [ ^ a - z 0 - 9 \s _ - ] / g, '' ) // Remove characters that are NOT alphanumeric (a-z, 0-9), whitespace, hyphens, or underscores
156
+ . replace ( / [ \s _ ] + / g, '-' ) // Replace sequences of one or more whitespace characters and/or underscores with a single hyphen
157
+ . replace ( / - { 2 , } / g, '-' ) // Replace multiple consecutive hyphens with a single hyphen
158
+ . replace ( / ^ - + | - + $ / g, '' ) // Remove any leading or trailing hyphens
162
159
}
163
160
164
161
export const unslugify = ( text : string ) => {
165
- const unslug = text . replace ( / - / g, ' ' ) // Replace - with spaces
166
- return unslug
162
+ return text . replace ( / - / g, ' ' ) // Replace hyphens with spaces
167
163
}
168
164
169
165
// Not inspired by this, but useful reference for corner cases:
0 commit comments