21 lines
508 B
TypeScript
21 lines
508 B
TypeScript
export function escapeHtml(value: string) {
|
|
return value.replace(/[&<>"']/g, (char) => ({
|
|
"&": "&",
|
|
"<": "<",
|
|
">": ">",
|
|
'"': """,
|
|
"'": "'"
|
|
}[char]!));
|
|
}
|
|
|
|
export function formatBytes(bytes: number) {
|
|
if (bytes < 1024) return `${bytes} B`;
|
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
}
|
|
|
|
export function modelNameFromFile(fileName: string) {
|
|
return fileName.replace(/\.[^/.]+$/, "");
|
|
}
|
|
|