dgx-spark-playbooks/nvidia/txt2kg/assets/frontend/lib/utils.ts
2025-10-06 17:05:41 +00:00

36 lines
983 B
TypeScript

import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
/**
* Download a document file from the browser
*/
export function downloadDocument(file: File, filename?: string) {
const url = URL.createObjectURL(file)
const link = document.createElement('a')
link.href = url
link.download = filename || file.name
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
URL.revokeObjectURL(url)
}
/**
* Download text content as a file
*/
export function downloadTextAsFile(content: string, filename: string, mimeType: string = 'text/plain') {
const blob = new Blob([content], { type: mimeType })
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = filename
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
URL.revokeObjectURL(url)
}