JavaScript library to generate a human readable String describing the file size
Installations
npm install filesize
Developer Guide
Typescript
✅ Yes
Module System
ESM
Min. Node Version
>= 10.4.0
Node Version
22.7.0
NPM Version
10.8.2
Score
99.8
Supply Chain
100
Quality
80.5
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Developer
Statistics
Updated on 29 Nov 2024
Bundle Size
2.57 kB
Minified
1.28 kB
Minified + Gzipped
Languages
JavaScript (99.81%)
Shell (0.19%)
Total Downloads
Cumulative downloads
Total Downloads
2,728,106,0112,728,106,011
Last day
16.6%
Compared to previous day
Last week
-2.5%
Compared to previous week
Last month
5.1%
Compared to previous month
Last year
-2.8%
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
filesize.js
filesize.js provides a simple way to get a human-readable file size string from a number (float or integer) or string.
1import {filesize} from "filesize"; 2filesize(265318, {standard: "jedec"}); // "259.1 KB"
Testing
filesize has 100% code coverage with its tests.
1--------------|---------|----------|---------|---------|----------------------- 2File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 3--------------|---------|----------|---------|---------|----------------------- 4All files | 100 | 95.52 | 100 | 100 | 5 filesize.cjs | 100 | 95.52 | 100 | 100 | 77-78,173,196,199,210 6--------------|---------|----------|---------|---------|-----------------------
Optional settings
filesize()
accepts an optional descriptor Object as a second argument, so you can customize the output.
base
(number) Number base, default is 10
bits
(boolean) Enables bit
sizes, default is false
exponent
(number) Specifies the symbol via exponent, e.g. 2
is MB
for base 2, default is -1
fullform
(boolean) Enables full form of unit of measure, default is false
fullforms
(array) Array of full form overrides, default is []
locale (overrides 'separator')
(string || boolean) BCP 47 language tag to specify a locale, or true
to use default locale, default is ""
localeOptions (overrides 'separator', requires string for 'locale' option)
(object) Dictionary of options defined by ECMA-402 (Number.prototype.toLocaleString). Requires locale option to be explicitly passed as a string, otherwise is ignored.
output
(string) Output of function (array
, exponent
, object
, or string
), default is string
pad
(boolean) Decimal place end padding, default is false
precision
(number) Sets precision of numerical output, default is 0
round
(number) Decimal place, default is 2
roundingMethod
(string) Rounding method, can be round
, floor
, or ceil
, default is round
separator
(string) Decimal separator character, default is an empty string.
spacer
(string) Character between the result
and symbol
, default is " "
standard
(string) Standard unit of measure, can be iec
, jedec
, or si
. Default is si
(base 10). The si
option is an alias of jedec
, such that it is not valid for other configuration options.
symbols
(object) Dictionary of IEC/JEDEC symbols to replace for localization, defaults to english if no match is found; SI is handled automatically with JEDEC values.
Examples
1filesize(500); // "500 B" 2filesize(500, {bits: true}); // "4 kbit" 3filesize(265318, {base: 2}); // "259.1 KiB" 4filesize(265318); // "265.32 kB" 5filesize(265318, {round: 0}); // "265 kB" 6filesize(265318, {output: "array"}); // [265.32, "kB"] 7filesize(265318, {output: "object"}); // {value: 265.32, symbol: "kB", exponent: 1, unit: "kB"} 8filesize(1, {symbols: {B: "Б"}}); // "1 Б" 9filesize(1024); // "1.02 kB" 10filesize(1024, {exponent: 0}); // "1024 B" 11filesize(1024, {output: "exponent"}); // 1 12filesize(265318, {standard: "jedec"}); // "259.1 KB" 13filesize(265318, {base: 2, fullform: true}); // "259.1 kibibytes" 14filesize(12, {fullform: true, fullforms: ["байтов"]}); // "12 байтов" 15filesize(265318, {separator: ","}); // "265,32 kB" 16filesize(265318, {locale: "de"}); // "265,32 kB"
Partial Application
partial()
takes the second parameter of filesize()
and returns a new function with the configuration applied
upon execution. This can be used to reduce Object
creation if you call filesize()
without caching the descriptor
in lexical scope.
1import {partial} from "filesize"; 2const size = partial({standard: "jedec"}); 3 4size(265318); // "259.1 KB"
License
Copyright (c) 2024 Jason Mulligan Licensed under the BSD-3 license.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: BSD 3-Clause "New" or "Revised" License: LICENSE:0
Reason
1 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
Reason
Found 3/23 approved changesets -- score normalized to 1
Reason
1 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
- Warn: jobLevel 'contents' permission set to 'write': .github/workflows/ci.yml:43
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/avoidwork/filesize.js/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/avoidwork/filesize.js/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/avoidwork/filesize.js/ci.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:31
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
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 10 are checked with a SAST tool
Score
3.4
/10
Last Scanned on 2024-12-02
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 filesize
pretty-bytes
Convert bytes to a human readable string: 1337 → 1.34 kB
rollup-plugin-filesize
A rollup plugin to show filesize in the cli
filesize.js
filesize.js is a simple browserjs / nodejs library to make filesize human-readable.
filesize-parser
Takes human readable filesystem size strings and gives you an int representing that many bytes.