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 0.8.1 to 0.8.2

61

humanize-duration.js

@@ -116,3 +116,3 @@ /*

// A utility function for creating the strings.
// Internal utility function for rendering the strings.
// render(1, "minute") == "1 minute"

@@ -129,2 +129,15 @@ // render(12, "hour") == "12 hours"

// Internal helper function for Polish language.
function getPolishForm(c) {
if (c === 1) {
return 0;
} else if (Math.floor(c) !== c) {
return 1;
} else if (2 <= c % 10 && c % 10 <= 4 && !(10 < c % 100 && c % 100 < 20)) {
return 2;
} else {
return 3;
}
}
// Grab the components.

@@ -134,2 +147,6 @@ function componentsOf(total, language) {

var result = { total: {} };
// Make sure we have positive numbers.
// Has the nice sideffect of turning Number objects into primitives.
total = Math.abs(total);
var ms = total;

@@ -144,9 +161,14 @@

// What's the total?
unitTotal = Math.floor(total / unit.milliseconds);
result.total[unitName] = render(unitTotal, unit.name, language);
// What are the totals and the rest?
if (unit.name === "millisecond") {
unitCount = ms / unit.milliseconds;
unitTotal = total / unit.milliseconds;
} else {
unitCount = Math.floor(ms / unit.milliseconds);
unitTotal = Math.floor(total / unit.milliseconds);
}
// What's the rest?
unitCount = Math.floor(ms / unit.milliseconds);
// Put them in the result.
result[unitName] = render(unitCount, unit.name, language);
result.total[unitName] = render(unitTotal, unit.name, language);

@@ -165,5 +187,5 @@ // Lower the number of milliseconds.

// Turn Number objects into primitives.
if (ms instanceof Number)
ms = ms.valueOf();
// Make sure we have a positive number.
// Has the nice sideffect of turning Number objects into primitives.
ms = Math.abs(ms);

@@ -179,3 +201,3 @@ // Humanizing zero, I see.

var unit, unitCount, mightBeHalfUnit;
for (var i = 0, len = UNITS.length; (i < len) && (ms); i ++) {
for (var i = 0, len = UNITS.length; i < len; i ++) {

@@ -193,3 +215,7 @@ // Store the current unit.

// What's the number of full units we can fit?
unitCount = Math.floor(ms / unit.milliseconds);
if (unit.name === "millisecond") {
unitCount = ms / unit.milliseconds;
} else {
unitCount = Math.floor(ms / unit.milliseconds);
}

@@ -210,15 +236,2 @@ // Add the string.

// Helper function for Polish language.
function getPolishForm(c) {
if (c === 1) {
return 0;
} else if (Math.floor(c) !== c) {
return 1;
} else if (2 <= c % 10 && c % 10 <= 4 && !(10 < c % 100 && c % 100 < 20)) {
return 2;
} else {
return 3;
}
}
// What's the default language?

@@ -225,0 +238,0 @@ humanizeDuration.language = "en";

@@ -10,3 +10,3 @@ {

],
"version": "0.8.1",
"version": "0.8.2",
"description": "Convert millisecond durations to English or many other languages.",

@@ -18,3 +18,3 @@ "main": "humanize-duration.js",

"devDependencies": {
"mocha": "1.18.x",
"mocha": "1.19.x",
"chai": "1.9.x",

@@ -21,0 +21,0 @@ "sugar": "1.4.x",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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