source: frontend/node_modules/webpack/lib/util/formatSize.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 639 bytes
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Sean Larkin @thelarkinn
4*/
5
6"use strict";
7
8/**
9 * Returns the formatted size.
10 * @param {number=} size the size in bytes
11 * @returns {string} the formatted size
12 */
13const formatSize = (size) => {
14 if (typeof size !== "number" || Number.isNaN(size) === true) {
15 return "unknown size";
16 }
17
18 if (size <= 0) {
19 return "0 bytes";
20 }
21
22 const abbreviations = ["bytes", "KiB", "MiB", "GiB"];
23 const index = Math.floor(Math.log(size) / Math.log(1024));
24
25 return `${Number((size / 1024 ** index).toPrecision(3))} ${abbreviations[index]}`;
26};
27
28module.exports = formatSize;
Note: See TracBrowser for help on using the repository browser.