function formatBytes
formatBytes(bytes: number): string

A byte count as a person would read it: 0 bytes, 812 bytes, 4.2 KB, 1.3 MB.

Whole numbers under a kilobyte because nobody wants 0.8 KB, one decimal above it because the difference between 4.2 and 4.9 is the difference between two answers.

import { formatBytes } from './http-service.ts';

formatBytes(1); // '1 byte'
formatBytes(812); // '812 bytes'
formatBytes(4_300); // '4.2 KB'

Parameters

bytes: number

Return Type

string

Usage

import { formatBytes } from "lib/repl/http-service.ts";