Installations
npm install human-format
Developer Guide
Typescript
Yes
Module System
N/A
Min. Node Version
>=4
Node Version
20.18.0
NPM Version
10.8.2
Score
99.7
Supply Chain
100
Quality
80.6
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (99.53%)
Shell (0.47%)
Developer
JsCommunity
Download Statistics
Total Downloads
8,704,126
Last Day
18,642
Last Week
103,781
Last Month
536,064
Last Year
4,911,695
GitHub Statistics
98 Stars
114 Commits
21 Forks
3 Watching
2 Branches
8 Contributors
Bundle Size
3.10 kB
Minified
1.45 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.2.1
Package Id
human-format@1.2.1
Unpacked Size
16.50 kB
Size
5.79 kB
File Count
5
NPM Version
10.8.2
Node Version
20.18.0
Publised On
06 Nov 2024
Total Downloads
Cumulative downloads
Total Downloads
8,704,126
Last day
1.1%
18,642
Compared to previous day
Last week
-27.6%
103,781
Compared to previous week
Last month
8.3%
536,064
Compared to previous month
Last year
238.9%
4,911,695
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
human-format
Converts a number to/from a human readable string:
1337
↔1.34kB
Installation
Node & Browserify/Webpack
Installation of the npm package:
> npm install --save human-format
Then require the package:
1var humanFormat = require("human-format");
Browser
You can directly use the build provided at unpkg.com:
1<script src="https://unpkg.com/human-format@1/index.js"></script>
Usage
Formatting
1humanFormat(1337); 2//=> '1.34 k' 3 4// The maximum number of decimals can be changed. 5humanFormat(1337, { 6 maxDecimals: 1, 7}); 8//=> '1.3 k' 9 10// maxDecimals can be set to auto, so that there is 1 decimal between -10 and 10 excluded and none out of this interval. 11humanFormat(1337, { 12 maxDecimals: "auto", 13}); 14//=> '1.3 k' 15 16humanFormat(13337, { 17 maxDecimals: "auto", 18}); 19//=> '13 k' 20 21// A fixed number of decimals can be set. 22humanFormat(1337, { 23 decimals: 4, 24}); 25//=> '1.3370 k' 26 27// Units and scales can be specified. 28humanFormat(65536, { 29 scale: "binary", 30 unit: "B", 31}); 32//=> 64 kiB 33 34// There is a helper for this. 35humanFormat.bytes(65536); 36//=> 64 kiB 37 38// A custom separator can be specified. 39humanFormat(1337, { 40 separator: " - ", 41}); 42//=> 1.34 - k 43 44// Custom scales can be created! 45var timeScale = new humanFormat.Scale({ 46 seconds: 1, 47 minutes: 60, 48 hours: 3600, 49 days: 86400, 50 months: 2592000, 51}); 52humanFormat(26729235, { scale: timeScale }); 53//=> 10.31 months 54 55// Helper when the scale is regular, i.e. prefixes are powers of a constant factor 56var binaryScale = humanFormat.Scale.create(["", "Ki", "Mi", "Gi", "Ti"], 1024); 57humanFormat(173559053, { scale: binaryScale }); 58//=> 165.52 Mi 59 60// You can force a prefix to be used. 61humanFormat(100, { unit: "m", prefix: "k" }); 62//=> 0.1 km 63 64// You can access the raw result. 65humanFormat.raw(100, { prefix: "k" }); 66//=> { 67// prefix: 'k', 68// value: 0.09999999999999999 // Close value, not rounded. 69// }
Parsing
1humanFormat.parse("1.34 kiB", { scale: "binary" }); 2//=> 1372.16 3 4// Fallbacks when possible if the prefix is incorrectly cased. 5humanFormat.parse("1 g"); 6// => 1000000000 7 8// You can access the raw result. 9humanFormat.parse.raw("1.34 kB"); 10//=> { 11// factor: 1000, 12// prefix: 'k', 13// unit: 'B', 14// value: 1.34 15//}
Contributions
Contributions are very welcomed, either on the documentation or on the code.
You may:
- report any issue you've encountered;
- fork and create a pull request.
Contributors:
- @djulien
- @qrohlf
- @Itay289
- @sweetpi
License
ISC © Julien Fontanet
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: ISC License: LICENSE:0
Reason
Found 4/30 approved changesets -- score normalized to 1
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
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 4 are checked with a SAST tool
Reason
15 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-rxrc-rgv4-jpvx
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-f9xv-q969-pqx4
Score
2
/10
Last Scanned on 2025-02-03
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