mirror of
https://github.com/NVIDIA/dgx-spark-playbooks.git
synced 2026-04-23 02:23:53 +00:00
36 lines
983 B
TypeScript
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)
|
|
}
|