mirror of
https://github.com/ershisan99/db-studio.git
synced 2025-12-17 05:09:25 +00:00
initial commit
This commit is contained in:
24
frontend/src/lib/utils.ts
Normal file
24
frontend/src/lib/utils.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { type ClassValue, clsx } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
|
||||
type Valuable<T> = { [K in keyof T as T[K] extends null | undefined ? never : K]: T[K] }
|
||||
|
||||
export function getValuable<T extends object, V = Valuable<T>>(obj: T): V {
|
||||
return Object.fromEntries(
|
||||
Object.entries(obj).filter(
|
||||
([, v]) => !((typeof v === 'string' && !v.length) || v === null || typeof v === 'undefined')
|
||||
)
|
||||
) as V
|
||||
}
|
||||
|
||||
export function prettyBytes(bytes: number): string {
|
||||
const units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB']
|
||||
if (bytes === 0) return '0 B'
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(1024))
|
||||
const size = bytes / Math.pow(1024, i)
|
||||
return `${size.toFixed(2)} ${units[i]}`
|
||||
}
|
||||
Reference in New Issue
Block a user