Spaces:
Running
Running
Download apps/web/src/lib/utils.ts from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/web/src/lib/utils.ts
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/apps/web/src/lib/utils.ts
-
curl -L -o utils.ts https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/web/src/lib/utils.ts
1.44 kB
| import { type ClassValue, clsx } from "clsx"; | |
| import { twMerge } from "tailwind-merge"; | |
| export { clsx }; | |
| export function cn(...inputs: ClassValue[]) { | |
| return twMerge(clsx(inputs)); | |
| } | |
| export function formatTime(seconds: number): string { | |
| const s = Math.max(0, Math.floor(seconds)); | |
| const h = Math.floor(s / 3600); | |
| const m = Math.floor((s % 3600) / 60); | |
| const sec = s % 60; | |
| const mm = String(m).padStart(2, "0"); | |
| const ss = String(sec).padStart(2, "0"); | |
| return h > 0 ? `${h}:${mm}:${ss}` : `${mm}:${ss}`; | |
| } | |
| export function copyToClipboard(text: string): Promise<boolean> { | |
| if (navigator.clipboard && window.isSecureContext) { | |
| return navigator.clipboard.writeText(text).then(() => true).catch(() => false); | |
| } else { | |
| const textArea = document.createElement("textarea"); | |
| textArea.value = text; | |
| textArea.style.position = "fixed"; | |
| textArea.style.left = "-999999px"; | |
| textArea.style.top = "-999999px"; | |
| document.body.appendChild(textArea); | |
| textArea.focus(); | |
| textArea.select(); | |
| return new Promise((resolve) => { | |
| const successful = document.execCommand('copy'); | |
| textArea.remove(); | |
| resolve(successful); | |
| }); | |
| } | |
| } | |
| export function scrollToTop(behavior: ScrollBehavior = 'instant') { | |
| if (typeof window === 'undefined') return; | |
| window.scrollTo({ top: 0, left: 0, behavior }); | |
| document.documentElement.scrollTop = 0; | |
| document.body.scrollTop = 0; | |
| } | |