11 lines
289 B
TypeScript
11 lines
289 B
TypeScript
const SAFE = /[^a-z0-9]+/g;
|
|
|
|
export function slug(input: string): string {
|
|
return input.trim().toLowerCase().replace(SAFE, "-").replace(/^-+|-+$/g, "");
|
|
}
|
|
|
|
export function makeId(prefix: string, input: string): string {
|
|
const s = slug(input);
|
|
return `${prefix}:${s || "unknown"}`;
|
|
}
|