MCPcopy
hub / github.com/modelcontextprotocol/servers / formatSize

Function formatSize

src/filesystem/lib.ts:44–54  ·  view source on GitHub ↗
(bytes: number)

Source from the content-addressed store, hash-verified

42
43// Pure Utility Functions
44export function formatSize(bytes: number): string {
45 const units = ['B', 'KB', 'MB', 'GB', 'TB'];
46 if (bytes === 0) return '0 B';
47
48 const i = Math.floor(Math.log(bytes) / Math.log(1024));
49
50 if (i < 0 || i === 0) return `${bytes} ${units[0]}`;
51
52 const unitIndex = Math.min(i, units.length - 1);
53 return `${(bytes / Math.pow(1024, unitIndex)).toFixed(2)} ${units[unitIndex]}`;
54}
55
56export function normalizeLineEndings(text: string): string {
57 return text.replace(/\r\n/g, '\n');

Callers 2

index.tsFile · 0.85
lib.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected