mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 07:02:49 +00:00
19 lines
412 B
TypeScript
19 lines
412 B
TypeScript
/**
|
|
* Return a slugified copy of a string.
|
|
*
|
|
* @param {string} str The string to be slugified
|
|
* @return {string} The slugified string.
|
|
*/
|
|
export function toSlug(str: string): string {
|
|
let s = str;
|
|
if (!s) {
|
|
return "";
|
|
}
|
|
s = s.toLowerCase().trim();
|
|
s = s.replace(/ & /g, " and ");
|
|
s = s.replace(/[ ]+/g, "-");
|
|
s = s.replace(/[-]+/g, "-");
|
|
s = s.replace(/[^a-z0-9-]+/g, "");
|
|
return s;
|
|
}
|