3.0.0 • Published 1 year ago

unbyted v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Unbyted

GitHub License GitHub Workflow Status GitHub issues

Turn bytes into readable measurement units

Getting started

npm i unbyted
const Unbyted = require('unbyted')

Unbyted.toBinary(401710738) // 383.10 MiB
Unbyted.toDecimal(401710738) // 401.71 MB

Digital Measurement Units

Unbyted can use decimal nor binary units of measurement to express the size of storage data.

DecimalSymbolValueBinarySymbolValue
KilobyteKB10e3KibibyteKiB2e10
MegabyteMB10e6MebibyteMiB2e20
GigabyteGB10e9GibibyteGiB2e30
TerabyteTB10e12TebibyteTiB2e40
PetabytePB10e15PebibytePiB2e50
ExabyteEB10e18ExbibyteEiB2e60
ZettabyteZB10e21ZebibyteZiB2e70
YottabyteYB10e24YobibyteYiB2e80

Units difference

Between decimal and binary units of measurement, binary units express data size more accurately.

Nonetheless, decimal units is the most widely used. Sometimes, you can find a mix between binary values and decimal symbols, which is not encouraged since there's a significant technical difference.

API

new Unbyted(options)

  • options
    • space boolean Add space between or not. Default: true
    • trim boolean Trim fraction digits when needed. Default: false
    • digits number The number of fraction digits. Default: 2

When called as a constructor, allows you to customize the output.

const unbyted = new Unbyted({ trim: true, space: false })

unbyted.toBinary(10240) // 10KB
unbyted.toDecimal(10000) // 10KB

.toBinary(input)

Static method to run quick binary conversions.

Unbyted.toBinary(255492) // 249.50 KiB
Unbyted.toBinary(255529156) // 243.69 MiB
Unbyted.toBinary(25552915675) // 23.80 GiB

.toDecimal(input)

Static method to run quick decimal conversions.

Unbyted.toDecimal(255492) // 255.49 KB
Unbyted.toDecimal(255529156) // 255.53 MB
Unbyted.toDecimal(25552915675) // 25.55 GB

Benchmarks

Runned on a Linux VM, allocated resources: Intel 2.5GHz, 2 Cores & 2 Threads; 4GB RAM;

MethodOperations/s
Unbyted.toBinary()3 057 603
Unbyted.toDecimal()3 053 408

You are free to run your own benchmarks, and share the results at Show & Tell.

3.0.0

1 year ago

2.0.0

1 year ago

1.2.0

1 year ago

1.0.0

1 year ago

0.4.0

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago