Gathering detailed insights and metrics for pretty-bytes
Gathering detailed insights and metrics for pretty-bytes
Gathering detailed insights and metrics for pretty-bytes
Gathering detailed insights and metrics for pretty-bytes
Convert bytes to a human readable string: 1337 → 1.34 kB
npm install pretty-bytes
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,119 Stars
76 Commits
81 Forks
12 Watching
1 Branches
17 Contributors
Updated on 28 Nov 2024
JavaScript (95.24%)
TypeScript (4.76%)
Cumulative downloads
Total Downloads
Last day
-6.9%
2,535,841
Compared to previous day
Last week
1.3%
14,595,027
Compared to previous week
Last month
7.4%
61,877,280
Compared to previous month
Last year
3%
687,918,535
Compared to previous year
Convert bytes to a human readable string:
1337
→1.34 kB
Useful for displaying file sizes for humans.
Note that it uses base-10 (e.g. kilobyte). Read about the difference between kilobyte and kibibyte.
1npm install pretty-bytes
1import prettyBytes from 'pretty-bytes'; 2 3prettyBytes(1337); 4//=> '1.34 kB' 5 6prettyBytes(100); 7//=> '100 B' 8 9// Display with units of bits 10prettyBytes(1337, {bits: true}); 11//=> '1.34 kbit' 12 13// Display file size differences 14prettyBytes(42, {signed: true}); 15//=> '+42 B' 16 17// Localized output using German locale 18prettyBytes(1337, {locale: 'de'}); 19//=> '1,34 kB'
Type: number
The number to format.
Type: object
Type: boolean
Default: false
Include plus sign for positive numbers. If the difference is exactly zero a space character will be prepended instead for better alignment.
Type: boolean
Default: false
Format the number as bits instead of bytes. This can be useful when, for example, referring to bit rate.
Type: boolean
Default: false
Format the number using the Binary Prefix instead of the SI Prefix. This can be useful for presenting memory amounts. However, this should not be used for presenting file sizes.
Type: boolean | string
Default: false
(No localization)
Important: Only the number and decimal separator are localized. The unit title is not and will not be localized.
true
: Localize the output using the system/browser locale.string
: Expects a BCP 47 language tag (For example: en
, de
, …)string[]
: Expects a list of BCP 47 language tags (For example: en
, de
, …)Type: number
Default: undefined
The minimum number of fraction digits to display.
If neither minimumFractionDigits
or maximumFractionDigits
are set, the default behavior is to round to 3 significant digits.
1import prettyBytes from 'pretty-bytes'; 2 3// Show the number with at least 3 fractional digits 4prettyBytes(1900, {minimumFractionDigits: 3}); 5//=> '1.900 kB' 6 7prettyBytes(1900); 8//=> '1.9 kB'
Type: number
Default: undefined
The maximum number of fraction digits to display.
If neither minimumFractionDigits
or maximumFractionDigits
are set, the default behavior is to round to 3 significant digits.
1import prettyBytes from 'pretty-bytes'; 2 3// Show the number with at most 1 fractional digit 4prettyBytes(1920, {maximumFractionDigits: 1}); 5//=> '1.9 kB' 6 7prettyBytes(1920); 8//=> '1.92 kB'
Type: boolean
Default: true
Put a space between the number and unit.
1import prettyBytes from 'pretty-bytes'; 2 3prettyBytes(1920, {space: false}); 4//=> '1.9kB' 5 6prettyBytes(1920); 7//=> '1.92 kB'
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 11/30 approved changesets -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
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-18
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