UNPKG

automin

Version:

"Create a minified mirror version of your js, css, html, json files"

16 lines (15 loc) 561 B
"use strict"; /** * Original * https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript * */ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = (bytes, decimals = 2) => { if (bytes < 1) return '0B'; const k = 1024; const dm = decimals < 0 ? 0 : decimals; const sizes = ['B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))}${sizes[i]}`; };