Current collected state Current
Observed since 20 Oct, 21:21 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
8bits
A Javascript library for manipulating and converting byte values
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.
$ npm install --save 8bits
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)
// 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
MIT © Andrew Kennedy
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
binary-prefixEnvironment{
"local_name": "binary-prefix",
"alias": false,
"peer_metadata": null
} | ^1.1.0 | runtime |
lodashEnvironment{
"local_name": "lodash",
"alias": false,
"peer_metadata": null
} | ^2.4.2 | runtime |
underscore.stringEnvironment{
"local_name": "underscore.string",
"alias": false,
"peer_metadata": null
} | ^2.3.3 | runtime |
mochaEnvironment{
"local_name": "mocha",
"alias": false,
"peer_metadata": null
} | ^2.1.0 | development |
chaiEnvironment{
"local_name": "chai",
"alias": false,
"peer_metadata": null
} | ^2.0.0 | development |
Source distribution
{
"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"
}
]
}Observed since 20 Oct, 21:21 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:db84fe4829da3ec0a3ec63f69624e212b32f679df2ecc9f76d4df840031d9106