vague-time
Advanced tools
Comparing version
{ | ||
"name": "vague-time", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"main": "./src/vagueTime.js", | ||
@@ -5,0 +5,0 @@ "ignore": [ |
{ | ||
"name": "vague-time", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "A tiny library that formats precise time differences as a vague/fuzzy time.", | ||
@@ -5,0 +5,0 @@ "repo": "philbooth/vagueTime.js", |
{ | ||
"name": "vague-time", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "A tiny library that formats precise time differences as a vague/fuzzy time.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/philbooth/vagueTime.js", |
@@ -37,3 +37,3 @@ # vagueTime.js | ||
3.2 kb unminified with comments, | ||
3.3 kb unminified with comments, | ||
1.1 kb minified or | ||
@@ -40,0 +40,0 @@ 0.6 kb minified+gzipped. |
@@ -41,3 +41,3 @@ /** | ||
function getVagueTime (options) { | ||
var now, units, diff, action, fallback, time, value; | ||
var now, units, diff, action, fallback, time, value, plural; | ||
@@ -60,7 +60,14 @@ now = Date.now(); | ||
value = Math.floor(diff / times[time]); | ||
if (value === 1) { | ||
value = time === 'hour' ? 'an' : 'a'; | ||
switch (value) { | ||
case 1: | ||
value = time === 'hour' ? 'an' : 'a'; | ||
plural = ''; | ||
break; | ||
case 2: | ||
value = 'a couple of'; | ||
default: | ||
plural = 's' | ||
} | ||
return action(value, time + (value > 1 ? 's' : '')); | ||
return action(value, time + plural); | ||
} | ||
@@ -67,0 +74,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(e){"use strict";function n(e){var n,o,i,a,d,m,c;n=Date.now(),o=t(e.units),i=r(e.from,o,n)-r(e.to,o,n),i>=0?(a=u,d="just now"):(i=-i,a=f,d="soon");for(m in s)if(s.hasOwnProperty(m)&&i>=s[m])return c=Math.floor(i/s[m]),1===c&&(c="hour"===m?"an":"a"),a(c,m+(c>1?"s":""));return d}function t(e){if("undefined"==typeof e)return"ms";if("s"===e||"ms"===e)return e;throw new Error("Invalid units")}function r(e,n,t){if("undefined"==typeof e)return t;if("string"==typeof e&&(e=parseInt(e,10)),o(e)&&i(e))throw new Error("Invalid time");return"number"==typeof e&&"s"===n&&(e*=1e3),e}function o(e){return"[object Date]"!==Object.prototype.toString.call(e)||isNaN(e.getTime())}function i(e){return"number"!=typeof e||isNaN(e)}function u(e,n){return e+" "+n+" ago"}function f(e,n){return"in "+e+" "+n}function a(){"function"==typeof define&&define.amd?define("vagueTime",["exports"],function(e){e.get=d.get}):"undefined"!=typeof module&&module&&module.exports?module.exports=d:e.vagueTime=d}var s,d;s={year:315576e5,month:26298e5,week:6048e5,day:864e5,hour:36e5,minute:6e4},d={get:n},a()}(this); | ||
!function(e){"use strict";function n(e){var n,r,u,a,c,d,m,p;n=Date.now(),r=t(e.units),u=o(e.from,r,n)-o(e.to,r,n),u>=0?(a=i,c="just now"):(u=-u,a=f,c="soon");for(d in s)if(s.hasOwnProperty(d)&&u>=s[d]){switch(m=Math.floor(u/s[d])){case 1:m="hour"===d?"an":"a",p="";break;case 2:m="a couple of";default:p="s"}return a(m,d+p)}return c}function t(e){if("undefined"==typeof e)return"ms";if("s"===e||"ms"===e)return e;throw new Error("Invalid units")}function o(e,n,t){if("undefined"==typeof e)return t;if("string"==typeof e&&(e=parseInt(e,10)),r(e)&&u(e))throw new Error("Invalid time");return"number"==typeof e&&"s"===n&&(e*=1e3),e}function r(e){return"[object Date]"!==Object.prototype.toString.call(e)||isNaN(e.getTime())}function u(e){return"number"!=typeof e||isNaN(e)}function i(e,n){return e+" "+n+" ago"}function f(e,n){return"in "+e+" "+n}function a(){"function"==typeof define&&define.amd?define("vagueTime",["exports"],function(e){e.get=c.get}):"undefined"!=typeof module&&module&&module.exports?module.exports=c:e.vagueTime=c}var s,c;s={year:315576e5,month:26298e5,week:6048e5,day:864e5,hour:36e5,minute:6e4},c={get:n},a()}(this); |
@@ -175,3 +175,3 @@ /*globals require, chai */ | ||
test('get returns 2 years ago when time is 63,115,200 seconds ago', function () { | ||
test('get returns a couple of years ago when time is 63,115,200 seconds ago', function () { | ||
assert.equal(vagueTime.get({ | ||
@@ -181,3 +181,3 @@ from: 1234567890, | ||
units: 's' | ||
}), '2 years ago'); | ||
}), 'a couple of years ago'); | ||
}); | ||
@@ -281,3 +281,3 @@ | ||
test('get returns 2 years ago when time is 63,115,200,000 milliseconds ago', function () { | ||
test('get returns a couple of years ago when time is 63,115,200,000 milliseconds ago', function () { | ||
assert.equal(vagueTime.get({ | ||
@@ -287,3 +287,3 @@ from: 1234567890000, | ||
units: 'ms' | ||
}), '2 years ago'); | ||
}), 'a couple of years ago'); | ||
}); | ||
@@ -290,0 +290,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
-100%25116
-22.35%13
-48%452
-31.72%