Installations
npm install bytes-iec
Releases
Unable to fetch releases
Developer
Saevon
Developer Guide
Module System
Unable to determine the module system for this package.
Min. Node Version
>= 0.8
Typescript Support
No
Node Version
11.15.0
NPM Version
7.0.3
Statistics
4 Stars
156 Commits
2 Forks
2 Watching
3 Branches
1 Contributors
Updated on 16 Feb 2024
Languages
JavaScript (94.84%)
TypeScript (5.16%)
Total Downloads
Cumulative downloads
Total Downloads
23,661,358
Last day
3.8%
44,144
Compared to previous day
Last week
17.1%
248,832
Compared to previous week
Last month
19.7%
917,862
Compared to previous month
Last year
38.6%
9,007,148
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
8
Bytes utility
Utility to parse a size string in bytes (e.g. '1kB'
, '2KiB'
) to numeric (1000
, 2048
) and vice-versa.
This is a fork of the bytes module, except it
- supports all of both the binary and decimal prefixes defined by ISO/IEC 80000-13:2008
- supports JEDEC, a legacy mode in which metric units have binary values
- uses decimal metric units by default, which can be overridden per call or by default
TypeScript definitions included.
Supported Units
Supported units are as follows and are case-insensitive. Note that only the abbreviation will be parsed/formatted, the full names are for the reader's understanding only.
Metric
Also referred to as SI. See Compatibility Binary for legacy definitions.
Value | Abbr | Name |
---|---|---|
1 | B | byte |
10001 | kB | kilobyte |
10002 | MB | megabyte |
10003 | GB | gigabyte |
10004 | TB | terabyte |
10005 | PB | petabyte |
10006 | EB | exabyte |
10007 | ZB | zettabyte |
10008 | YB | yottabyte |
Binary
Value | Abbr | Name |
---|---|---|
1 | B | byte |
10241 | KiB | kibibyte |
10242 | MiB | mebibyte |
10243 | GiB | gibibyte |
10244 | TiB | tebibyte |
10245 | PiB | pebibyte |
10246 | EiB | exbibyte |
10247 | ZiB | zebibite |
10248 | YiB | yobibite |
Compatibility Binary
Also referred to as JEDEC or legacy units.
Overwrites the lower units of the metric system with the commonly misused values, i.e. metric units will be binary instead of decimal. This is the behavior of e.g. the Windows OS and bytes. Units greater than terabyte are not supported.
Value | Abbr | Name |
---|---|---|
10241 | kB | kilobyte |
10242 | MB | megabyte |
10243 | GB | gigabyte |
10244 | TB | terabyte |
Installation
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
1npm install bytes-iec
Usage
1var bytes = require('bytes-iec');
Modes
Passing a unit type as mode
parameter in API calls determines
- the set of units that will be favored by autodetection when no unit is specified
- the value/size of metric units: Compatibility mode makes them base-2 instead of base-10
Unit type | mode |
---|---|
Metric | 'metric' or 'decimal' |
Binary | 'binary' |
Compatibility Binary | 'compatibility' or 'jedec' |
bytes.format(number value, [options]): string|null
Format the given value in bytes into a string. If the value is negative, it's kept as such. If it's a float, it's rounded.
Arguments
Name | Type | Description |
---|---|---|
value | number | Value in bytes |
options | Object | Conversion options |
Options
Property | Type | Description | Default |
---|---|---|---|
decimalPlaces | number |null | Maximum number of decimal places to include in output | 2 |
fixedDecimals | boolean |null | Whether to always display the maximum number of decimal places, i.e. preserve trailing zeroes | false |
thousandsSeparator | string |null | What to separate large numbers with, e.g. ',' , '.' , ' ' , ... | '' |
unit | string |null | The unit in which the result will be returned: 'B' , 'kB' , 'KiB' , ... | '' (autodetect) |
unitSeparator | string |null | Separator between numeric value and unit | '' |
mode | string |null | Which mode to use (see Modes) | 'metric' |
Returns
Name | Type | Description |
---|---|---|
results | string |null | Returns null upon error, string value otherwise. |
Example
1bytes(1000); 2// output: '1kB' 3 4bytes(1000, {thousandsSeparator: ' '}); 5// output: '1 000B' 6 7bytes(1024); 8// output: '1.02kB' 9 10bytes(1024 * 1.7, {decimalPlaces: 0}); 11// output: '2KB' 12 13bytes(1000, {unitSeparator: ' '}); 14// output: '1 kB' 15 16bytes(2048, {mode: 'binary'}); 17// output: '2 KiB' 18 19bytes(1024 * 1024 * 2, {unit: 'KiB'}); 20// output: '2048 KiB' 21 22bytes(1024 * 1024 * 2, {unit: 'KB'}); 23// output: '2097.152 KB' 24 25bytes(1024 * 1024 * 2, {unit: 'KB', mode: 'compatibility'}); 26// output: '2048 KB'
bytes.parse(string|number value): number|null
Parse the string value into an integer in bytes. If no unit is given, or value
is a number, it is assumed the value is in bytes.
If the value given has partial bytes, it's truncated (rounded down).
Arguments
Name | Type | Description |
---|---|---|
value | string |number | String to parse, or number in bytes |
options | Object | Conversion options |
Property | Type | Description | Default |
---|---|---|---|
mode | string |null | Which mode to use (see Modes) | 'metric' |
Returns
Name | Type | Description |
---|---|---|
results | number |null | Returns null upon error, value in bytes otherwise. |
Example
1bytes('1kB'); 2// output: 1024 3 4bytes('1024'); 5// output: 1024 6 7bytes('1.0001 kB'); 8// output: 1000 9bytes('1.0001 KiB'); 10// output: 1024 11 12bytes('1kB', {mode: 'jedec'}); 13// output: 1024
bytes.withDefaultMode(string mode): object
Returns a new copy of the bytes-iec
module, but with the given mode as the default.
Arguments
Name | Type | Description |
---|---|---|
mode | string | Default mode to use (see Modes) |
Returns
Name | Type | Description |
---|---|---|
results | object | Returns the byte.js module, with a default mode. |
Example
1var bytes = require('bytes').withDefaultMode('jedec'); 2 3bytes('1kB'); 4// output: 1024 5 6bytes('1KiB'); 7// output: 1024 8 9bytes(1024); 10// output: 1 kB 11 12bytes(1024, {mode: 'metric'}); 13// output: 1.02kB 14 15bytes('1kB', {mode: 'metric'}); 16// output: 1000
License
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 2/29 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 3 are checked with a SAST tool
Reason
27 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.7
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to bytes-iec
byte-size
Convert a bytes or octets value (e.g. 34565346) to a human-readable string ('34.6 MB'). Choose between metric or IEC units.
bytes
Utility to parse a string bytes to bytes and vice-versa
hls.js
JavaScript HLS client using MediaSourceExtension
codem-isoboxer
A lightweight JavaScript MP4 (MPEG-4, ISOBMFF) file/box parser.