Gathering detailed insights and metrics for bytes-iec
Gathering detailed insights and metrics for bytes-iec
Gathering detailed insights and metrics for bytes-iec
Gathering detailed insights and metrics for 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.
npm install bytes-iec
99.4
Supply Chain
99.5
Quality
75.2
Maintenance
100
Vulnerability
100
License
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
4 Stars
156 Commits
2 Forks
2 Watching
3 Branches
1 Contributors
Updated on 16 Feb 2024
JavaScript (94.84%)
TypeScript (5.16%)
Cumulative downloads
Total Downloads
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
8
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
TypeScript definitions included.
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.
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 |
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 |
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 |
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
1npm install bytes-iec
1var bytes = require('bytes-iec');
Passing a unit type as mode
parameter in API calls determines
Unit type | mode |
---|---|
Metric | 'metric' or 'decimal' |
Binary | 'binary' |
Compatibility Binary | 'compatibility' or 'jedec' |
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'
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
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
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
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
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
27 existing vulnerabilities detected
Details
Score
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 More