import type { Attributes, BglFormSchemaT, Path } from '../types/BagelForm' const debouncers = new Map<() => void, ReturnType>() export function debounce(fn: () => void, wait: number = 500) { clearTimeout(debouncers.get(fn)) const timeout = setTimeout(() => { fn() debouncers.delete(fn) }, wait) debouncers.set(fn, timeout) } export function slugify(str: string) { return str .toLowerCase() .replace(/[^a-z0-9-\s]/g, '') .split(/[\s-]+/) .join('-') } export function keyToLabel(key?: string): string | undefined { if (key === undefined) { return key } return ( key .split('_') .map(k => k.charAt(0).toUpperCase() + k.slice(1)) .join(' ') || key ) } export async function copyText(text: string, cb?: (msg: string) => void) { await navigator.clipboard.writeText(text) if (cb) { cb('Copied to clipboard') } } export function initials(...strArr: string[]) { strArr = strArr.flatMap(str => str.split(/\s/)) return strArr.map(str => str.charAt(0)).join('') } /** * Strip script-capable content from an HTML string so it is safe for v-html. * Removes