Giter Site home page Giter Site logo

prettysize's Introduction

PrettySize

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

Build Status

Build Status codecov

Usage

npm install prettysize
const pretty = require('prettysize');

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

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

    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.
Fith argument is to return a converted number without the size string.
*/


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

    str = pretty(123456789, {nospace: true}) // pretty(123456789, true, true);
  //str = "117.7M"

    str = pretty(123456789, {one: true}) // pretty(123456789, false, true);
  //str = "117.7 M"

    str = pretty(123456789, {one: true, places: 2}) // pretty(123456789, false, true, 2);
  //str = "117.74 M"

   str = pretty(123456789, {one: true, places: 3}) // pretty(123456789, false, true, 3);
 //str = "117.738 M"

   str = pretty(123456789, {numOnly: true}) // pretty(123456789, false, false, false, true);
 //num = 117.7

prettysize's People

Contributors

adrieankhisbe avatar buraktamturk avatar davglass avatar soldair avatar timoxley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

prettysize's Issues

Changelog

Is there a changelog available? I am wondering what breaking changes occurred between 0.1.0 and 1.0.0. Thanks!

Bower?

Would you consider adding this module to bower as well as npm? I'm using it both on the server and client side but I'm having to inline it for the client side-- Bower would really help.

Thanks,
Ryan

Do the viceversa

Any module that does the viceversa?
Like:

toBytes('1MB') // 1048576

Does not work in IE11

Using IE11 and prettysize (Built through webpack), the website doesn't load at all when including prettysize as a package.

You get the following error in the console app.js (6856,1), and the source leads to:
image

Removing prettysize works. Is there any polyfil needed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.