From 370ee9ed04da1486035494a14d6d07ab4f5b3d85 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Thu, 12 Sep 2019 15:48:27 +0200 Subject: [PATCH] Unminify formatBytes There's no reason to minify formatBytes it saves nothing. Use the unminified version as published. --- lib/manager/modManager.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/manager/modManager.js b/lib/manager/modManager.js index cef0a6b4..296d4a2e 100644 --- a/lib/manager/modManager.js +++ b/lib/manager/modManager.js @@ -19,8 +19,19 @@ const fileOps = require("lib/fileOps"); function ellipse(str, max){ return str.length > (max - 3) ? str.substring(0,max-3) + '...' : str; } + // https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript -function formatBytes(a,b){if(0==a)return"0 Bytes";var c=1024,d=b||2,e=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],f=Math.floor(Math.log(a)/Math.log(c));return parseFloat((a/Math.pow(c,f)).toFixed(d))+" "+e[f]}; +function formatBytes(size, decimals) { + if (bytes === 0) return '0 Bytes'; + + const k = 1024; + const dm = decimals < 0 ? 0 : decimals; + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + + const i = Math.floor(Math.log(bytes) / Math.log(k)); + + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; +} /**