Skip to content

Instantly share code, notes, and snippets.

View m3tti's full-sized avatar

Mathäus m3tti

View GitHub Profile
@elawad
elawad / format-size.js
Last active March 29, 2021 10:03
Format file size like macOS
function formatSize(size) {
const base = 1000; // 1000 or 1024
const kb = base ** 1;
const mb = base ** 2;
const gb = base ** 3;
let num;
num = (size / 1).toFixed(0);
if (num < base) return Number(num) + ' B';