Gathering detailed insights and metrics for humanize-duration-es6
Gathering detailed insights and metrics for humanize-duration-es6
Gathering detailed insights and metrics for humanize-duration-es6
Gathering detailed insights and metrics for humanize-duration-es6
humanize-duration
Convert millisecond durations to English and many other languages.
@types/humanize-duration
TypeScript definitions for humanize-duration
humanize-ms
transform humanize time to ms
humanize-string
Convert a camelized/dasherized/underscored string into a humanized one: `fooBar-Baz_Faz` → `Foo bar baz faz`
npm install humanize-duration-es6
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2 Stars
2 Commits
2 Forks
2 Watching
1 Branches
1 Contributors
Updated on 31 May 2019
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
14.5%
87
Compared to previous day
Last week
-2.4%
485
Compared to previous week
Last month
33.5%
2,090
Compared to previous month
Last year
-20.5%
12,224
Compared to previous year
ES6 version of the humanize-duration library with some modifications.
Converts the time in milliseconds to something like "30 minutes" or "3 days, 1 hour".
This package is available as humanize-duration-es6 on npm.
1import Humanizer from 'humanize-duration-es6'; 2import localeEn from 'humanize-duration-es6/src/locale/en' 3 4const h = new Humanizer(localeEn); 5h.humanize(12000);
By default, library will humanize down to the second, and will return a decimal for the smallest unit.
1h.humanize(3000) // '3 seconds' 2h.humanize(2250) // '2.25 seconds' 3h.humanize(97320000) // '1 day, 3 hours, 2 minutes'
You can change the settings by passing options as the second argument:
delimiter
String to display between the previous unit and the next value.
1h.humanize(22140000, { delimiter: ' and ' }) // '6 hours and 9 minutes' 2h.humanize(22140000, { delimiter: '--' }) // '6 hours--9 minutes'
spacer
String to display between each value and unit.
1h.humanize(260040000, { spacer: ' whole ' }) // '3 whole days, 14 whole minutes' 2h.humanize(260040000, { spacer: '' }) // '3days, 14minutes'
largest
Number representing the maximum number of units to display for the duration.
1h.humanize(1000000000000) // '31 years, 8 months, 1 week, 19 hours, 46 minutes, 40 seconds' 2h.humanize(1000000000000, { largest: 2 }) // '31 years, 8 month'
units
Array of strings to define which units are used to display the duration (if needed). Can be one, or a combination of any, of the following: ['y', 'mo', 'w', 'd', 'h', 'm', 's', 'ms']
1h.humanize(3600000, { units: ['h'] }) // '1 hour' 2h.humanize(3600000, { units: ['m'] }) // '60 minutes' 3h.humanize(3600000, { units: ['d', 'h'] }) // '1 hour'
round
Boolean value. Use true
to round the smallest unit displayed (can be combined with largest
and units
).
1h.humanize(1200) // '1.2 seconds' 2h.humanize(1200, { round: true }) // '1 second' 3h.humanize(1600, { round: true }) // '2 seconds'
decimal
String to substitute for the decimal point in a decimal fraction.
1h.humanize(1200) // '1.2 seconds' 2h.humanize(1200, { decimal: ' point ' }) // '1 point 2 seconds'
conjunction
String to include before the final unit. You can also set serialComma
to false
to eliminate the final comma.
1h.humanize(22140000, { conjunction: ' and ' }) // '6 hours and 9 minutes' 2h.humanize(22141000, { conjunction: ' and ' }) // '6 hours, 9 minutes, and 1 second' 3h.humanize(22140000, { conjunction: ' and ', serialComma: false }) // '6 hours and 9 minutes' 4h.humanize(22141000, { conjunction: ' and ', serialComma: false }) // '6 hours, 9 minutes and 1 second'
unitMeasures
Customize the value used to calculate each unit of time.
1h.humanize(400) // '0.4 seconds' 2h.humanize(400, { // '1 year, 1 month, 5 days' 3 unitMeasures: { 4 y: 365, 5 mo: 30, 6 w: 7, 7 d: 1 8 } 9})
Combined example
1h.humanize(3602000, { 2 round: true, 3 spacer: ' great ', 4 units: ['m'] 5}) 6// '60 great minutes'
You can also add new languages. For example:
1import Humanizer from 'humanize-duration-es6'; 2 3const shortEnLocale = { 4 y: () => "y", 5 mo: () => "mo", 6 w: () => "w", 7 d: () => "d", 8 h: () => "h", 9 m: () => "m", 10 s: () => "s", 11 ms: () => "ms", 12 decimal: () => "." 13}; 14const shortEnglishHumanizer = new Humanizer(shortEnLocale, { 15 spacer: "", 16 delimiter: " " 17}); 18 19shortEnglishHumanizer.humanize(15600000) // '4 h, 20 m'
Humanize Duration supports the following languages:
Language | Code |
---|---|
Arabic | ar |
Catalan | ca |
Chinese, simplified | zh_CN |
Chinese, traditional | zh_TW |
Czech | cs |
Danish | da |
Dutch | nl |
English | en |
Finnish | fi |
French | fr |
German | de |
Greek | gr |
Hungarian | hu |
Icelandic | is |
Indonesian | id |
Italian | it |
Japanese | ja |
Korean | ko |
Lithuanian | lt |
Malay | ms |
Norwegian | no |
Polish | pl |
Portuguese | pt |
Russian | ru |
Spanish | es |
Swedish | sv |
Turkish | tr |
Ukrainian | uk |
Vietnamese | vi |
Based on library humanize-duration
Licensed under the permissive Unlicense.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/2 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
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
53 existing vulnerabilities detected
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