Source

number/formatByteSize.js

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var shortenNumberWithUnit_1 = __importDefault(require("./shortenNumberWithUnit"));
var EACH_KB = 1024;
var UNITS_MAP = [
    'B',
    'KB',
    'MB',
    'GB',
    'TB',
    'PB',
];
/**
 * Display file size in appropriate format (e.g. B, KB, MB, GB)
 *
 * @param size The size in bytes
 * @returns A tuple type of [<Displayed number>, <Displayed units>] format. E.g. [300, 'MB']
 * @category number
 * @module formatByteSize
 */
function formatByteSize(size) {
    return (0, shortenNumberWithUnit_1.default)(size, EACH_KB, UNITS_MAP);
}
exports.default = formatByteSize;