Gathering detailed insights and metrics for human-format
Gathering detailed insights and metrics for human-format
npm install human-format
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.7
Supply Chain
100
Quality
80.6
Maintenance
100
Vulnerability
100
License
JavaScript (99.53%)
Shell (0.47%)
Total Downloads
8,704,126
Last Day
18,642
Last Week
103,781
Last Month
536,064
Last Year
4,911,695
98 Stars
114 Commits
21 Forks
3 Watching
2 Branches
8 Contributors
Minified
Minified + Gzipped
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
Cumulative downloads
Total Downloads
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
Converts a number to/from a human readable string:
1337
↔1.34kB
Installation of the npm package:
> npm install --save human-format
Then require the package:
1var humanFormat = require("human-format");
You can directly use the build provided at unpkg.com:
1<script src="https://unpkg.com/human-format@1/index.js"></script>
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// }
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 are very welcomed, either on the documentation or on the code.
You may:
Contributors:
ISC © Julien Fontanet
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
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
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
15 existing vulnerabilities detected
Details
Score
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