MCPcopy Create free account
hub / github.com/Sethispr/image-compressor / formatBytes

Function formatBytes

utils.ts:4–14  ·  view source on GitHub ↗
(bytes: number, decimals = 2)

Source from the content-addressed store, hash-verified

2import DOMPurify from 'dompurify';
3
4export const formatBytes = (bytes: number, decimals = 2): string => {
5 if (bytes === 0) return '0 B';
6
7 const k = 1024;
8 const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
9 const i = Math.floor(Math.log(bytes) / Math.log(k));
10
11 return (
12 parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + ' ' + sizes[i]
13 );
14};
15
16export const generateFilename = (
17 originalFilename: string,

Callers 1

JobCardComponentFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected