Catalog npm
Back to packageRELEASE DETAILS

0.2.10

npm

8bits

A Javascript library for manipulating and converting byte values

bitsbytebytesconvert
Published23 Jul 2015
Direct dependencies5
Transitive dependenciesNot calculated

README

Current package documentation

8bits Build Status

A Javascript library for manipulating and converting byte values

There are two primary ways to represent byte sizes: SI units (decimal / Base 10 / 10^3) and IEC units (binary / Base 2 / 2^10). 8bits supports both of decimal and binary formats, with the default format being decimal.

Install

$ npm install --save 8bits

Usage

var byte = require('8bits');

byte(789);
//=> 789 B

byte(1000);
//=> 1 kB

// Setting the number of decimal places
byte(1024, {digits: 2});
//=> 1.02 kB

// Using binary instead of decimal
byte(1024, {digits: 2, binary: true});
//=> 1.00 KB

// Converting from one prefix to another
byte(500000, {from: 'kB', to: 'MB'});
//=> 500 MB

byte(512000, {from: 'KB', to: 'MB', binary: true});
//=> 500 MB

// Formatting the return value
byte(512000000, {format: '%s - %s'});
//=> 512 - kB

// Using custom unit values
byte(2000000, {
  units: {
    MB: 'Megabytes'
  }
});
//=> 2 Megabytes

// All together
byte(2000000000000, {
  from: 'MB',
  to: 'YB',
  format: '%s (%s)',
  binary: true,
  digits: 6,
  units: {
    YB: 'yoda bytes'
  }
});
//=> 0.000002 (yoda bytes)

Todo

  • Retrieve byte value from human-readable value (i.e. 1 MB => 1048576)
  • Include API in Readme

Useful Information

// Prefixes for multiples of bits (b) or bytes (B)
//      Decimal                   Binary
// ================================================
// Value    Metric   |  Value    JEDEC       IEC
// 1000     k kilo   |  1024     K kilo    Ki  kibi
// 1000^2   M mega   |  1024^2   M mega    Mi  mebi
// 1000^3   G giga   |  1024^3   G giga    Gi  gibi
// 1000^4   T tera   |  1024^4   – –       Ti  tebi
// 1000^5   P peta   |  1024^5   – –       Pi  pebi
// 1000^6   E exa    |  1024^6   – –       Ei  exbi
// 1000^7   Z zetta  |  1024^7   – –       Zi  zebi
// 1000^8   Y yotta  |  1024^8   – –       Yi  yobi

License

MIT © Andrew Kennedy

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 5

Native requirements
5 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
binary-prefix
Environment
{
  "local_name": "binary-prefix",
  "alias": false,
  "peer_metadata": null
}
^1.1.0runtime
lodash
Environment
{
  "local_name": "lodash",
  "alias": false,
  "peer_metadata": null
}
^2.4.2runtime
underscore.string
Environment
{
  "local_name": "underscore.string",
  "alias": false,
  "peer_metadata": null
}
^2.3.3runtime
mocha
Environment
{
  "local_name": "mocha",
  "alias": false,
  "peer_metadata": null
}
^2.1.0development
chai
Environment
{
  "local_name": "chai",
  "alias": false,
  "peer_metadata": null
}
^2.0.0development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "69f5b6a1943224d23b7011268f1b04d7e65d215d",
  "tarball": "https://registry.npmjs.org/8bits/-/8bits-0.2.10.tgz",
  "integrity": "sha512-6slQS7X5pW4Bi2ZOX8dRVFqT9+rR6lhgCd0mbE48uil37UDZ7qx6b7B3cPCDMBguKStNSSZ2gs8MHJsLJuk2UQ==",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEYCIQDyh3qqgAEjkFd7dcG/AIwGZysgsNOw5QANKs+tSHe8mgIhAJh3yoXLVk8bkBF64lZFWGM8qJNmvBVt7YZ1UodHvfyD"
    }
  ]
}

Repository

PENDING
akenn/8bits

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 21:21 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:db84fe4829da3ec0a3ec63f69624e212b32f679df2ecc9f76d4df840031d9106

Other collected versions

0.2.914 Jul0.2.84 May0.2.713 Apr0.2.613 Apr0.2.513 Apr0.2.45 MarView all collected versions →