Files
zitadel/packages/zitadel-utils/src/toSlug.ts
Max Peintner c1c9ccbf03 initial setup
2023-04-03 11:45:27 +02:00

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;
}