humanize-duration
Advanced tools
Comparing version 0.9.0 to 1.0.0
@@ -10,4 +10,16 @@ /* | ||
// What are the languages? | ||
var LANGUAGES = { | ||
// Start by defining the units and how many ms is in each. | ||
var UNITS = [ | ||
{ name: "year", milliseconds: 31557600000 }, | ||
{ name: "month", milliseconds: 2629800000 }, | ||
{ name: "week", milliseconds: 604800000 }, | ||
{ name: "day", milliseconds: 86400000 }, | ||
{ name: "hour", milliseconds: 3600000 }, | ||
{ name: "minute", milliseconds: 60000 }, | ||
{ name: "second", milliseconds: 1000 }, | ||
{ name: "millisecond", milliseconds: 1 } | ||
]; | ||
// Let's also define the default languages. | ||
var languages = { | ||
en: { | ||
@@ -115,14 +127,2 @@ year: function(c) { return "year" + ((c !== 1) ? "s" : ""); }, | ||
// Start by defining the units and how many ms is in each. | ||
var UNITS = [ | ||
{ name: "year", milliseconds: 31557600000 }, | ||
{ name: "month", milliseconds: 2629800000 }, | ||
{ name: "week", milliseconds: 604800000 }, | ||
{ name: "day", milliseconds: 86400000 }, | ||
{ name: "hour", milliseconds: 3600000 }, | ||
{ name: "minute", milliseconds: 60000 }, | ||
{ name: "second", milliseconds: 1000 }, | ||
{ name: "millisecond", milliseconds: 1 } | ||
]; | ||
// Internal utility function for rendering the strings. | ||
@@ -133,3 +133,3 @@ // render(1, "minute") == "1 minute" | ||
function render(count, word, language) { | ||
var dictionary = LANGUAGES[language || humanizeDuration.language]; | ||
var dictionary = languages[language || humanizeDuration.language]; | ||
if (!dictionary) { | ||
@@ -172,3 +172,3 @@ throw new Error("Language " + language + " not defined"); | ||
// What are the totals and the rest? | ||
if (unit.name === "millisecond") { | ||
if (unitName === "milliseconds") { | ||
unitCount = ms / unit.milliseconds; | ||
@@ -243,2 +243,11 @@ unitTotal = total / unit.milliseconds; | ||
// How do you add a new language? | ||
humanizeDuration.addLanguage = function addLanguage(name, definition) { | ||
if (languages[name]) { | ||
throw Error("Language " + name + " already defined. If you think this " + | ||
"is an error, please submit a patch!"); | ||
} | ||
languages[name] = definition; | ||
}; | ||
// What's the default language? | ||
@@ -245,0 +254,0 @@ humanizeDuration.language = "en"; |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "0.9.0", | ||
"version": "1.0.0", | ||
"description": "Convert millisecond durations to English or many other languages.", | ||
@@ -13,0 +13,0 @@ "main": "humanize-duration.js", |
Humanize Duration | ||
================= | ||
[![npm version](https://badge.fury.io/js/humanize-duration.svg)](https://npmjs.org/package/humanize-duration) | ||
I have the time in milliseconds and I want it to become "30 minutes" or "3 days, 1 hour". Enter Humanize Duration! | ||
@@ -5,0 +7,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
54114
20
269
1
80