Skip to content

Commit f324fa5

Browse files
committed
refactor(tools): improve kebab case sanitization
1 parent 4ee73f8 commit f324fa5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tools/pfe-tools/dev-server/config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ async function renderURL(context: Context, options: PfeDevServerInternalConfig):
8888

8989
function kebabCase(string: string) {
9090
return string
91-
.replace(/([a-z])([A-Z])/g, '$1-$2') // Replace capital letters with lowercase
91+
.replace(/[^a-zA-Z0-9\s]/g, '') // Remove all characters not letters, numbers or spaces
9292
.replace(/[\s_]+/g, '-') // Replace spaces and underscores with -
93-
.replace(/[^-a-zA-Z]/g, '') // Remove all chars not letters, numbers or -
93+
.replace(/-+/g, '-') // Replace multiple - with single -
94+
.replace(/^-+|-+$/g, '') // Remove leading and trailing -
9495
.toLowerCase();
9596
}
9697

0 commit comments

Comments
 (0)