Files
frontend/apps/as/entities/instl-sncn/lib/format.ts
T

48 lines
1.2 KiB
TypeScript

import { PRGRS_STTS_LABELS, type PrgrsStts } from "../model";
export function fmtPrgrsStts(stts: PrgrsStts): string {
return PRGRS_STTS_LABELS[stts] || stts;
}
export function fmtJobSeComma(jobSe: string): string {
if (!jobSe) return "";
return jobSe.split("").join(",");
}
export function jobSeSpSummary(jobSeSp: string): string {
if (!jobSeSp) return "";
return jobSeSp.replace(/,/g, "");
}
export function parseJobSeSpArr(jobSeSp: string): string[] {
if (!jobSeSp) return [];
return jobSeSp.split(",").filter(Boolean);
}
export function fmtFileSize(bytes: number): string {
if (bytes === 0) return "0 Bytes";
const k = 1024;
const sizes = ["Bytes", "KB", "MB", "GB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + " " + sizes[i];
}
export function fmtDt(dtString: string | undefined): string {
if (!dtString) return "-";
try {
const dt = new Date(dtString);
return new Intl.DateTimeFormat("ko-KR", {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
}).format(dt);
} catch {
return dtString;
}
}