Skip to content

Commit 1eddcd9

Browse files
committed
Simplify kebab case
1 parent e157c74 commit 1eddcd9

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

packages/base/src/utils/setMetaTag.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
/// <reference lib="dom" />
22

3+
// Courtesy of https://stackoverflow.com/a/67243723.
34
function kebabCase(value: string): string {
4-
return value
5-
.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/gu, '$1-$2')
6-
.toLowerCase()
7-
.replace(/[^a-z0-9]+/gu, '-')
8-
.replace(/^-+|-+$/gu, '');
5+
return value.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
96
}
107

118
export default function setMetaTag(name: string, content: string): void;

0 commit comments

Comments
 (0)