Gathering detailed insights and metrics for bytes
Gathering detailed insights and metrics for bytes
Gathering detailed insights and metrics for bytes
Gathering detailed insights and metrics for bytes
npm install bytes
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
462 Stars
169 Commits
57 Forks
9 Watching
2 Branches
23 Contributors
Updated on 26 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-8%
9,515,204
Compared to previous day
Last week
1.1%
55,800,241
Compared to previous week
Last month
0.5%
237,791,466
Compared to previous month
Last year
1%
2,735,238,747
Compared to previous year
4
Utility to parse a string bytes (ex: 1TB
) to bytes (1099511627776
) and vice-versa.
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
1$ npm install bytes
1var bytes = require('bytes');
Default export function. Delegates to either bytes.format
or bytes.parse
based on the type of value
.
Arguments
Name | Type | Description |
---|---|---|
value | number |string | Number value to format or string value to parse |
options | Object | Conversion options for format |
Returns
Name | Type | Description |
---|---|---|
results | string |number |null | Return null upon error. Numeric value in bytes, or string value otherwise. |
Example
1bytes(1024); 2// output: '1KB' 3 4bytes('1KB'); 5// output: 1024
Format the given value in bytes into a string. If the value is negative, it is kept as such. If it is a float, it is rounded.
Arguments
Name | Type | Description |
---|---|---|
value | number | Value in bytes |
options | Object | Conversion options |
Options
Property | Type | Description |
---|---|---|
decimalPlaces | number |null | Maximum number of decimal places to include in output. Default value to 2 . |
fixedDecimals | boolean |null | Whether to always display the maximum number of decimal places. Default value to false |
thousandsSeparator | string |null | Example of values: ' ' , ',' and '.' ... Default value to '' . |
unit | string |null | The unit in which the result will be returned (B/KB/MB/GB/TB). Default value to '' (which means auto detect). |
unitSeparator | string |null | Separator to use between number and unit. Default value to '' . |
Returns
Name | Type | Description |
---|---|---|
results | string |null | Return null upon error. String value otherwise. |
Example
1bytes.format(1024); 2// output: '1KB' 3 4bytes.format(1000); 5// output: '1000B' 6 7bytes.format(1000, {thousandsSeparator: ' '}); 8// output: '1 000B' 9 10bytes.format(1024 * 1.7, {decimalPlaces: 0}); 11// output: '2KB' 12 13bytes.format(1024, {unitSeparator: ' '}); 14// output: '1 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.
Supported units and abbreviations are as follows and are case-insensitive:
b
for byteskb
for kilobytesmb
for megabytesgb
for gigabytestb
for terabytespb
for petabytesThe units are in powers of two, not ten. This means 1kb = 1024b according to this parser.
Arguments
Name | Type | Description |
---|---|---|
value | string |number | String to parse, or number in bytes. |
Returns
Name | Type | Description |
---|---|---|
results | number |null | Return null upon error. Value in bytes otherwise. |
Example
1bytes.parse('1KB'); 2// output: 1024 3 4bytes.parse('1024'); 5// output: 1024 6 7bytes.parse(1024); 8// output: 1024
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 2/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
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
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