update shared utils
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// Name → handle / slug helpers shared by frontend + proxy.
|
||||
|
||||
// URL-safe family slug (hyphenated, lowercase): "The Smiths" → "the-smiths".
|
||||
export function slugify(name: string): string {
|
||||
return name
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/^-+|-+$/g, '');
|
||||
}
|
||||
|
||||
// Whitespace-free lowercase handle used for a member's URL segment and as the
|
||||
// per-family username suffix: "Jakey Boy" → "jakeyboy", "Joe Edhook" → "joeedhook".
|
||||
export function handle(name: string): string {
|
||||
return name.toLowerCase().replace(/[^a-z0-9]/g, '');
|
||||
}
|
||||
|
||||
// A member's PB username is namespaced by the family slug so it stays globally
|
||||
// unique (PB requires auth-identity usernames to be unique) even though the URL
|
||||
// segment is only unique within a family: "miss-fits:jakeyboy".
|
||||
export function famUsername(famSlug: string, handleName: string): string {
|
||||
return `${slugify(famSlug)}:${handleName}`;
|
||||
}
|
||||
|
||||
// Reverse of famUsername — the URL segment is the part after the last ":".
|
||||
export function handleOf(fullUsername: string): string {
|
||||
const i = fullUsername.lastIndexOf(':');
|
||||
return i >= 0 ? fullUsername.slice(i + 1) : fullUsername;
|
||||
}
|
||||
Reference in New Issue
Block a user