UNPKG

xplora

Version:

Xplora is a command-line tool to visualize files & directories on your file system and output them into a hierarchical tree. Xplora also comes with many other great features.

27 lines (21 loc) 550 B
"use strict"; const chalk = require("chalk"); /** * Humanize file size. * * @param {number} size Size in bytes. * @returns */ function calculateFileSize(size) { if (size / 1024 ** 2 > 999) { return chalk.red((size / 1024 ** 3).toFixed("1") + " GB"); } if (size / 1024 > 999) { return chalk.yellowBright((size / 1024 ** 2).toFixed(1) + " MB"); } if (size > 999) { return chalk.blue((size / 1024).toFixed(1) + " KB"); } return chalk.cyan(size + " B"); } module.exports = calculateFileSize;