Something went wrong. Try again.
Tools for building Offline-first Web Apps
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930/** * Replaces template variables in a string */export function replaceTemplateVars( template: string, vars: Record<string, string>,): string { let result = template for (const [key, value] of Object.entries(vars)) { // Tolerate inner whitespace (`{{ name }}`) — formatters add it. const regex = new RegExp(`\\{\\{\\s*${key}\\s*\\}\\}`, 'g') // Replacement function so `$&`/`$1` in the value are inserted literally // instead of being interpreted as replacement patterns. result = result.replace(regex, () => value) } return result}
/** * Converts a name into a URL-friendly directory slug */export function slugify(name: string): string { return name .toLowerCase() .trim() .replace(/[^\w\s-]/g, '') .replace(/[\s_]+/g, '-') .replace(/^-+|-+$/g, '')}