initial commit of v5

This commit is contained in:
Amruth Pillai
2026-01-19 23:31:54 +01:00
parent 55bdfd0067
commit cad390fa13
1132 changed files with 200807 additions and 165288 deletions
+41
View File
@@ -0,0 +1,41 @@
import { slugify } from "./string";
function getReadableTimestamp(now: Date) {
const y = now.getFullYear();
const m = String(now.getMonth() + 1).padStart(2, "0");
const d = String(now.getDate()).padStart(2, "0");
const h = String(now.getHours()).padStart(2, "0");
const min = String(now.getMinutes()).padStart(2, "0");
return `${y}${m}${d}_${h}${min}`;
}
export function generateFilename(prefix: string, extension?: string) {
const now = new Date();
const name = slugify(prefix);
const timestamp = getReadableTimestamp(now);
return `${name}_${timestamp}${extension ? `.${extension}` : ""}`;
}
export function downloadWithAnchor(blob: Blob, filename: string) {
const a = document.createElement("a");
const url = URL.createObjectURL(blob);
a.href = url;
a.rel = "noopener";
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
setTimeout(() => URL.revokeObjectURL(url), 500);
}
export async function downloadFromUrl(url: string, filename: string) {
const response = await fetch(url);
const blob = await response.blob();
downloadWithAnchor(blob, filename);
}