19 lines
626 B
TypeScript
19 lines
626 B
TypeScript
export const UUID_RE =
|
|
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
|
|
export function slugify(title: string): string {
|
|
const slug = title
|
|
.toLowerCase()
|
|
.normalize("NFD")
|
|
.replace(/[\u0300-\u036f]/g, "") // strip diacritics
|
|
.replace(/[^a-z0-9]+/g, "-") // non-alphanumeric → dash
|
|
.replace(/^-+|-+$/g, "") // trim leading/trailing dashes
|
|
.substring(0, 60);
|
|
return slug || "untitled";
|
|
}
|
|
|
|
/** Stable slug tied to the record's id — unique by construction. */
|
|
export function makeSlug(title: string, id: string): string {
|
|
return `${slugify(title)}-${id.substring(0, 8)}`;
|
|
}
|