Gathering detailed insights and metrics for human-format
Gathering detailed insights and metrics for human-format
Gathering detailed insights and metrics for human-format
Gathering detailed insights and metrics for human-format
Converts a number to/from a human readable string: `1337` ↔ `1.34kB`
npm install human-format
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (99.53%)
Shell (0.47%)
Total Downloads
10,984,531
Last Day
16,011
Last Week
128,520
Last Month
585,325
Last Year
6,331,871
ISC License
100 Stars
114 Commits
21 Forks
2 Watchers
2 Branches
8 Contributors
Updated on Jun 25, 2025
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
Published on
Nov 06, 2024
Cumulative downloads
Total Downloads
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
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
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
20 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
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 MoreLast Day
-9.3%
16,011
Compared to previous day
Last Week
-8.2%
128,520
Compared to previous week
Last Month
8.2%
585,325
Compared to previous month
Last Year
230.2%
6,331,871
Compared to previous year