Socket
Socket
Sign inDemoInstall

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 2.2.1 to 2.3.0

9

humanize-duration.js

@@ -201,2 +201,3 @@ // HumanizeDuration.js - http://git.io/j0HgmQ

delimiter: ", ",
spacer: " ",
units: ["year", "month", "week", "day", "hour", "minute", "second"],

@@ -248,3 +249,3 @@ languages: {}

if (mightBeHalfUnit === Math.floor(mightBeHalfUnit)) {
return render(mightBeHalfUnit / 2, unitName, dictionary);
return render(mightBeHalfUnit / 2, unitName, dictionary, options.spacer);
}

@@ -262,3 +263,3 @@ }

if (unitCount) {
result.push(render(unitCount, unitName, dictionary));
result.push(render(unitCount, unitName, dictionary, options.spacer));
}

@@ -282,3 +283,3 @@

function render(count, type, dictionary) {
function render(count, type, dictionary, spacer) {
var dictionaryValue = dictionary[type];

@@ -291,3 +292,3 @@ var word;

}
return count + " " + word;
return count + spacer + word;
}

@@ -294,0 +295,0 @@

@@ -11,3 +11,3 @@ {

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

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

"jshint": "^2.5.11",
"mocha": "^2.0.1",
"mocha": "^2.1.0",
"ms": "^0.7.0"

@@ -27,0 +27,0 @@ },

@@ -50,2 +50,5 @@ Humanize Duration

humanizeDuration(260040000, { spacer: " whole " }) // "3 whole days, 14 whole minutes"
humanizeDuration(260040000, { spacer: "" }) // "3days, 14minutes"
humanizeDuration(3600000, { units: ["hours"] }) // 1 hour

@@ -76,2 +79,33 @@ humanizeDuration(3600000, { units: ["days", "hours"] }) // 1 hour

You can also add new languages to humanizers. For example:
```js
var shortEnglishHumanizer = humanizeDuration.humanizer({
language: "shortEn",
languages: {
shortEn: {
year: function(c) { return c + "y"; },
month: function(c) { return c + "mo"; },
week: function(c) { return c + "w"; },
day: function(c) { return c + "d"; },
hour: function(c) { return c + "h"; },
minute: function(c) { return c + "m"; },
second: function(c) { return c + "s"; },
millisecond: function(c) { return c + "ms"; },
}
}
});
shortEnglishHumanizer(15600000) // "4 h, 20 m"
```
You can also add languages after initializing:
```js
var humanizer = humanizeDuration.humanizer();
humanizer.languages.shortEn = {
year: function(c) { return c + "y"; },
// ...
```
Internally, the main `humanizeDuration` function is just a wrapper around a humanizer.

@@ -105,4 +139,4 @@

Lovingly made by [Evan Hahn](http://evanhahn.com/) with language support by [Martin Prins](https://github.com/magarcia). Thanks to [Filipi Siqueira](https://github.com/filipi777) for Portuguese support, [Peter Rekdal Sunde](https://github.com/peters) for Norwegian support, [Michał Janiec](https://github.com/mjjaniec) for Polish support, [Eileen Li](https://github.com/eileen3) for Chinese support and [Tommy Brunn](https://github.com/Nevon) for Swedish support.
Lovingly made by [Evan Hahn](http://evanhahn.com/) with language support by [Martin Prins](https://github.com/magarcia). Thanks to [Filipi Siqueira](https://github.com/filipi777) for Portuguese support, [Peter Rekdal Sunde](https://github.com/peters) for Norwegian support, [Michał Janiec](https://github.com/mjjaniec) for Polish support, [Eileen Li](https://github.com/eileen3) for Chinese support, and [Tommy Brunn](https://github.com/Nevon) for Swedish support.
Licensed under the WTFPL, so you can do whatever you want. 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