What is prettysize?
The prettysize npm package is a utility for converting file sizes into human-readable strings. It simplifies the process of displaying file sizes in a more understandable format, such as converting bytes into kilobytes, megabytes, etc.
What are prettysize's main functionalities?
Basic Usage
This feature allows you to convert a file size in bytes to a human-readable string. In this example, 123456789 bytes is converted to '117.7 MB'.
const prettysize = require('prettysize');
console.log(prettysize(123456789)); // '117.7 MB'
Customizing Units
This feature allows you to customize the units used in the conversion. By passing `true` as the second argument, the output uses binary units (MiB) instead of decimal units (MB).
const prettysize = require('prettysize');
console.log(prettysize(123456789, true)); // '117.7 MiB'
Specifying Number of Decimal Places
This feature allows you to specify the number of decimal places in the output. In this example, the output is formatted to two decimal places.
const prettysize = require('prettysize');
console.log(prettysize(123456789, {places: 2})); // '117.74 MB'
Other packages similar to prettysize
filesize
The filesize package is another utility for converting file sizes to human-readable strings. It offers more customization options compared to prettysize, such as different rounding methods, output formats (e.g., string, array, object), and support for various locales.
pretty-bytes
The pretty-bytes package is a lightweight utility for converting bytes to a human-readable string. It is similar to prettysize but focuses on simplicity and ease of use. It supports both metric and binary units and allows for customization of the number of decimal places.
PrettySize
Helper utility to provide pretty printed file sizes (best used for logging or CLI output)
Build Status

Usage
npm install prettysize
const pretty = require('prettysize');
let str = pretty(1024);
str = pretty(1024 * 1024);
str = pretty(123456789);
It supports the following sizes:
Arguments
pretty(123456, true, true, 2);
let str = pretty(1024 * 1024, true);
str = pretty(123456789, {nospace: true})
str = pretty(123456789, {one: true})
str = pretty(123456789, {one: true, places: 2})
str = pretty(123456789, {one: true, places: 3})
str = pretty(123456789, {numOnly: true})