Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

humanize-duration

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

humanize-duration - npm Package Compare versions

Comparing version 3.7.1 to 3.8.0

7

HISTORY.md

@@ -0,1 +1,8 @@

3.8.0 / 2016-05-19
==================
* new: `conjunctions` and `serialComma` options
* update: improve documentation
3.7.1 / 2016-04-26

@@ -2,0 +9,0 @@ ==================

10

humanize-duration.js

@@ -305,2 +305,4 @@ // HumanizeDuration.js - http://git.io/j0HgmQ

spacer: ' ',
conjunction: '',
serialComma: true,
units: ['y', 'mo', 'w', 'd', 'h', 'm', 's'],

@@ -400,3 +402,9 @@ languages: {},

if (result.length) {
return result.join(options.delimiter)
if (!options.conjunction || result.length === 1) {
return result.join(options.delimiter)
} else if (result.length === 2) {
return result.join(options.conjunction)
} else if (result.length > 2) {
return result.slice(0, -1).join(options.delimiter) + (options.serialComma ? ',' : '') + options.conjunction + result.slice(-1)
}
} else {

@@ -403,0 +411,0 @@ return render(0, options.units[options.units.length - 1], dictionary, options)

5

package.json

@@ -19,5 +19,6 @@ {

"Vidmantas Drasutis (https://github.com/drasius2)",
"Manh Tuan (https://github.com/J2TeaM)"
"Manh Tuan (https://github.com/J2TeaM)",
"Jesse Jackson (https://github.com/jsejcksn)"
],
"version": "3.7.1",
"version": "3.8.0",
"description": "Convert millisecond durations to English and many other languages.",

@@ -24,0 +25,0 @@ "homepage": "https://github.com/EvanHahn/HumanizeDuration.js",

@@ -41,28 +41,87 @@ Humanize Duration

### Options
You can change the settings by passing options as the second argument:
**language**
Language for unit display (accepts an [ISO 639-1 code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) from one of the [supported languages](#supported-languages)).
```js
humanizeDuration(3000, { language: 'es' }) // '3 segundos'
humanizeDuration(5000, { language: 'ko' }) // '5 초'
```
**delimiter**
String to display between the previous unit and the next value.
```js
humanizeDuration(22140000, { delimiter: ' and ' }) // '6 hours and 9 minutes'
humanizeDuration(22140000, { delimiter: '--' }) // '6 hours--9 minutes'
```
**spacer**
String to display between each value and unit.
```js
humanizeDuration(260040000, { spacer: ' whole ' }) // '3 whole days, 14 whole minutes'
humanizeDuration(260040000, { spacer: '' }) // '3days, 14minutes'
```
**largest**
Number representing the maximum number of units to display for the duration.
```js
humanizeDuration(1000000000000) // '31 years, 8 months, 1 week, 19 hours, 46 minutes, 40 seconds'
humanizeDuration(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']`
```js
humanizeDuration(3600000, { units: ['h'] }) // '1 hour'
humanizeDuration(3600000, { units: ['m'] }) // '60 minutes'
humanizeDuration(3600000, { units: ['d', 'h'] }) // '1 hour'
```
**round**
Boolean value. Use `true` to [round](https://en.wikipedia.org/wiki/Rounding#Round_half_up) the smallest unit displayed (can be combined with `largest` and `units`).
```js
humanizeDuration(1200) // '1.2 seconds'
humanizeDuration(1200, { round: true }) // '1 second'
humanizeDuration(1600, { round: true }) // '2 seconds'
```
**decimal**
String to substitute for the decimal point in a decimal fraction.
```js
humanizeDuration(1200) // '1.2 seconds'
humanizeDuration(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.
```js
humanizeDuration(22140000, { conjunction: ' and ' }) // '6 hours and 9 minutes'
humanizeDuration(22141000, { conjunction: ' and ' }) // '6 hours, 9 minutes, and 1 second'
humanizeDuration(22140000, { conjunction: ' and ', serialComma: false }) // '6 hours and 9 minutes'
humanizeDuration(22141000, { conjunction: ' and ', serialComma: false }) // '6 hours, 9 minutes and 1 second'
```
**unitMeasures**
Customize the value used to calculate each unit of time.
```js
humanizeDuration(400) // '0.4 seconds'

@@ -77,8 +136,14 @@ humanizeDuration(400, { // '1 year, 1 month, 5 days'

})
```
humanizeDuration(3600000, {
**Combined example**
```js
humanizeDuration(3602000, {
language: 'es',
round: true,
spacer: ' glorioso ',
units: ['m']
})
// '60 minutos'
// '60 glorioso minutos'
```

@@ -196,2 +261,3 @@

* [Manh Tuan](https://github.com/J2TeaM) for Vietnamese support
* [Jesse Jackson](https://github.com/jsejcksn) for documentation help

@@ -198,0 +264,0 @@ Licensed under the permissive [Unlicense](http://unlicense.org/). Enjoy!

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc