Skip to main content
Glama
fileSize.test.ts1.07 kB
import { describe, it, expect } from 'vitest'; import { formatFileSize, parseFileSize } from '../../src/utils/fileSize.js'; describe('fileSize utils', () => { it('formats bytes to human readable strings', () => { expect(formatFileSize(0)).toBe('0.0B'); expect(formatFileSize(512)).toBe('512.0B'); expect(formatFileSize(1024)).toBe('1.0KB'); expect(formatFileSize(1024 * 1024)).toBe('1.0MB'); expect(formatFileSize(1024 * 1024 * 5)).toBe('5.0MB'); }); it('parses human strings to bytes', () => { expect(parseFileSize('0')).toBe(0); expect(parseFileSize('512')).toBe(512); expect(parseFileSize('1K')).toBe(1024); expect(parseFileSize('1M')).toBe(1024 * 1024); expect(parseFileSize('5M')).toBe(5 * 1024 * 1024); }); it('round-trips basic sizes with supported parser units', () => { const pairs: Array<[number, string]> = [ [0, '0'], [512, '512'], [1024, '1K'], [1024 * 1024, '1M'], ]; for (const [bytes, human] of pairs) { expect(parseFileSize(human)).toBe(bytes); } }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bgauryy/local-explorer-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server