# prettysize

> Convert bytes to other sizes for prettier logging

Latest version **2.0.0** (published 2018-12-07) · 0 weekly downloads

## Install

```sh
npm install prettysize
pnpm add prettysize
yarn add prettysize
bun add prettysize
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2018-12-07 |
| First published | 2013-02-15 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 66 |
| Maintainers | davglass |
| Keywords | size, bytes, MB, megs |

## Links

- npm: https://www.npmjs.com/package/prettysize
- Repository: https://github.com/davglass/prettysize
- Homepage: https://github.com/davglass/prettysize#readme
- Issues: http://github.com/davglass/prettysize/issues
- npm.io page: https://npm.io/package/prettysize

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2018-12-07
- 1.1.0 — 2017-09-19
- 1.0.0 — 2017-09-18
- 0.1.0 — 2017-04-12
- 0.0.3 — 2013-07-08
- 0.0.2 — 2013-02-15
- 0.0.1 — 2013-02-15

## README

PrettySize
==========

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

Build Status
------------

[![Build Status](https://secure.travis-ci.org/davglass/prettysize.svg?branch=master)](http://travis-ci.org/davglass/prettysize)
[![codecov](https://codecov.io/gh/davglass/prettysize/branch/master/graph/badge.svg)](https://codecov.io/gh/davglass/prettysize)

Usage
-----

```
npm install prettysize
```

```javascript

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
---------

```javascript
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

```

---
_Source: https://npm.io/package/prettysize · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
