sizeFormatter = new Intl.NumberFormat([], { style: "unit", unit: "byte", notation: "compact", unitDisplay: "narrow", }); (_bytes) => { const units = { B: " bytes", KB: " kb", MB: " mb", GB: " gb", TB: " tb" }; const parts = sizeFormatter.formatToParts(_bytes); const vo: any = parts.reduce( (a, part: Intl.NumberFormatPart) => { a[part.type] = part.value; return a; }, { decimal: "", fraction: "", compact: "" }, ); return `${vo.integer}${vo.decimal}${vo.fraction} ${units[`${vo.compact}${vo.unit}`]}`; }