Socket
Socket
Sign inDemoInstall

prettysize

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    prettysize

Convert bytes to other sizes for prettier logging


Version published
Weekly downloads
135K
decreased by-25.38%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

PrettySize

Helper utility to provide pretty printed file sizes (best used for logging or CLI output)

Build Status

Build Status

Usage

npm install prettysize

var pretty = require('prettysize');

var str = pretty(1024);
//str = "1 kB"

var str = pretty(1024 * 1024);
//str = "1 MB"

var str = pretty(123456789);
//str = "117.7 MB"

It supports the following sizes:

  • bytes
  • kB
  • MB
  • GB
  • TB
  • PB
  • EB

Arguments

pretty(123456, true, true, 2);

/*

First arg is size
Second argument is to remove the space from the output
Third argument is to use a single character for the size.
Forth argument is the number of decimal places to return, default is 1. 
*/


var str = pretty(1024 * 1024, true);
//str = "1MB"

var str = pretty(123456789, true, true);
//str = "117.7M"

var str = pretty(123456789, false, true);
//str = "117.7 M"

var str = pretty(123456789, false, true, 2);
//str = "117.74 M"

var str = pretty(123456789, false, true, 3);
//str = "117.738 M"

Keywords

FAQs

Last updated on 12 Apr 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc