export function sleep(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); } //join string and dedup slashes and make sure it doesn't start with a slash export function joinPath(...paths: string[]): string { return paths.join("/").replace(/\/+/g, "/").replace(/^\//, ""); } export function formatTime(seconds: number): string { const mins = Math.floor(seconds / 60); const secs = Math.floor(seconds % 60); return `${mins}:${secs < 10 ? "0" : ""}${secs}`; } export const LocalStorageValues = { options: "Options", volume: "Volume", playlist: "Playlist", shuffle: "Shuffle", repeat: "Repeat", offline: "Offline", path: "Path" }; export function generateUUID() { return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => { const r = (Math.random() * 16) | 0; const v = c === "x" ? r : (r & 0x3) | 0x8; return v.toString(16); }); } export function formatBytes(bytes: number): string { if (bytes === 0) return '0 Bytes'; const k = 1024; const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); const value = bytes / k ** i; return `${Number.parseFloat(value.toFixed(2))} ${sizes[i]}`; }