num-beauty
Version:
An ultra lightweight module for formatting numbers into human-friendly strings
1 lines • 274 B
JavaScript
const UNITS=["B","KB","MB","GB","TB","PB","EB","ZB","YB"];export function formatBytes(t,o={}){if(0===t)return"0 B";const B=void 0!==o.decimals?o.decimals:2,a=UNITS,e=Math.floor(Math.log(Math.abs(t))/Math.log(1024)),r=0===e?0:B;return(t/Math.pow(1024,e)).toFixed(r)+" "+a[e]}