11 lines
264 B
TypeScript
11 lines
264 B
TypeScript
|
|
/** Derive a URL-friendly slug from a display name. */
|
||
|
|
export function toSlug(name: string): string {
|
||
|
|
return name
|
||
|
|
.toLowerCase()
|
||
|
|
.trim()
|
||
|
|
.replace(/[^a-z0-9\s-]/g, '')
|
||
|
|
.replace(/[\s]+/g, '-')
|
||
|
|
.replace(/-+/g, '-')
|
||
|
|
.replace(/^-|-$/g, '');
|
||
|
|
}
|