UNPKG

perfrunner-reporters

Version:

Home of the perfrunner reporters

21 lines (20 loc) 854 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toBytes = exports.toMs = void 0; const toMs = (v) => (v == null || isNaN(v) ? `` : `${Math.round(v)} ms`); exports.toMs = toMs; const toBytes = (bytes) => { /**Credits goes here: https://web.archive.org/web/20120507054320/http://codeaid.net/javascript/convert-size-in-bytes-to-human-readable-format-(javascript) */ if (bytes === 0) { return '0 Bytes'; } const isNegative = bytes < 0; if (isNegative) { bytes = bytes * -1; } const k = 1024; const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return `${isNegative ? '-' : ''}${parseFloat((bytes / Math.pow(k, i)).toFixed(0))} ${sizes[i]}`; }; exports.toBytes = toBytes;