Utils
boldkit/utilsFreeUtility
Utility functions for className merging
Live preview
live · rendered by the registry
Rendered by boldkit on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://boldkit.dev/r/utils.jsonSource
1import { type ClassValue, clsx } from 'clsx'2import { twMerge } from 'tailwind-merge'34export function cn(...inputs: ClassValue[]) {5 return twMerge(clsx(inputs))6}78const SAFE_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'tel:'])910/** Sanitize a URL to prevent javascript: protocol injection. Returns '#' for unsafe values. */11export function safeHref(url: string | undefined): string {12 if (!url) return '#'13 if (url.startsWith('/') || url.startsWith('#')) return url14 try {15 const parsed = new URL(url, 'https://placeholder.invalid')16 return SAFE_URL_PROTOCOLS.has(parsed.protocol) ? url : '#'17 } catch {18 return '#'19 }20}2122/** Sanitize a CSS value by stripping characters that could break out of a CSS declaration. */23export function sanitizeCssValue(value: string): string {24 return value.replace(/[{}<>;"'\\]/g, '')25}
What it pulls in
npm packages
Files it writes
More from boldkit
All 94 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Chart Exportchart-export | boldkit | Utilities | Free | no deps | |
| Math Curvesmath-curves | boldkit | Utilities | Free | no deps | |
| Motion Coremotion-core | boldkit | Utilities | Free | no deps |
