MCPcopy Create free account
hub / github.com/hoothin/UserScripts / formatBytes

Function formatBytes

Picviewer CE+/Picviewer CE+.user.js:12179–12191  ·  view source on GitHub ↗
(bytes)

Source from the content-addressed store, hash-verified

12177 }
12178
12179 function formatBytes(bytes) {
12180 if (bytes === null || typeof bytes === "undefined" || isNaN(bytes) || bytes < 0) return "";
12181 const units = ["B", "KB", "MB", "GB", "TB"];
12182 let size = bytes;
12183 let unitIndex = 0;
12184 while (size >= 1024 && unitIndex < units.length - 1) {
12185 size /= 1024;
12186 unitIndex++;
12187 }
12188 const precision = size >= 100 ? 0 : (size >= 10 ? 1 : 2);
12189 const value = size.toFixed(precision).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, "$1");
12190 return value + " " + units[unitIndex];
12191 }
12192
12193 function updateGalleryHeaderSize(gallery, img, strategy) {
12194 if (!gallery || !gallery.eleMaps || !gallery.eleMaps['head-left-img-info-size']) return;

Callers 3

updateGalleryHeaderSizeFunction · 0.70
updateViewmoreSizeLabelFunction · 0.70
initFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected