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.16.0 to 3.17.0

5

HISTORY.md

@@ -0,1 +1,6 @@

3.17.0 / 2019-01-06
===================
* new: `fallback` option
3.16.0 / 2018-12-01

@@ -2,0 +7,0 @@ ===================

36

humanize-duration.js

@@ -502,2 +502,26 @@ // HumanizeDuration.js - https://git.io/j0HgmQ

// Build dictionary from options
function getDictionary (options) {
var languagesFromOptions = [options.language]
if (options.hasOwnProperty('fallbacks')) {
if (isArray(options.fallbacks) && options.fallbacks.length) {
languagesFromOptions = languagesFromOptions.concat(options.fallbacks)
} else {
throw new Error('fallbacks must be an array with at least one element')
}
}
for (var i = 0; i < languagesFromOptions.length; i++) {
var languageToTry = languagesFromOptions[i]
if (options.languages.hasOwnProperty(languageToTry)) {
return options.languages[languageToTry]
} else if (languages.hasOwnProperty(languageToTry)) {
return languages[languageToTry]
}
}
throw new Error('No language found.')
}
// doHumanization does the bulk of the work.

@@ -511,7 +535,3 @@ function doHumanization (ms, options) {

var dictionary = options.languages[options.language] || languages[options.language]
if (!dictionary) {
throw new Error('No language ' + dictionary + '.')
}
var dictionary = getDictionary(options)
var pieces = []

@@ -684,2 +704,8 @@

// We need to make sure we support browsers that don't have
// `Array.isArray`, so we define a fallback here.
var isArray = Array.isArray || function (arg) {
return Object.prototype.toString.call(arg) === '[object Array]'
}
humanizeDuration.getSupportedLanguages = function getSupportedLanguages () {

@@ -686,0 +712,0 @@ var result = []

4

package.json

@@ -29,3 +29,3 @@ {

],
"version": "3.16.0",
"version": "3.17.0",
"description": "Convert millisecond durations to English and many other languages.",

@@ -43,3 +43,3 @@ "homepage": "https://github.com/EvanHahn/HumanizeDuration.js",

"ms": "^0.7.2",
"standard": "^11.0.1"
"standard": "^12.0.1"
},

@@ -46,0 +46,0 @@ "keywords": [

@@ -56,2 +56,11 @@ Humanize Duration

**fallbacks**
Fallback languages if the provided language cannot be found (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)). It works from left to right.
```js
humanizeDuration(3000, { language: 'bad language', fallbacks: ['en'] }) // '3 seconds'
humanizeDuration(3000, { language: 'bad language', fallbacks: ['bad language', 'es'] }) // '3 segundos'
```
**delimiter**

@@ -58,0 +67,0 @@

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