Socket
Socket
Sign inDemoInstall

javascript-time-ago

Package Overview
Dependencies
1
Maintainers
1
Versions
119
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.2 to 2.0.3

2

bundle/javascript-time-ago.min.js

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("javascript-time-ago",[],e):"object"==typeof exports?exports["javascript-time-ago"]=e():t["javascript-time-ago"]=e()}(window,function(){return function(t){var e={};function r(o){if(e[o])return e[o].exports;var n=e[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=t,r.c=e,r.d=function(t,e,o){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(o,n,function(e){return t[e]}.bind(null,n));return o},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([,function(t,e,r){"use strict";r.r(e);var o="en",n={};function a(){return o}function i(t){return n[t]}function u(t){var e=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).localeMatcher||"lookup";switch(e){case"lookup":case"best fit":return l(t);default:throw new RangeError('Invalid "localeMatcher" option: '.concat(e))}}function l(t){if(i(t))return t;for(var e=t.split("-");t.length>1;)if(e.pop(),i(t=e.join("-")))return t}function f(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function c(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var s=["second","minute","hour","day","week","month","quarter","year"],h=["auto","always"],y=["long","short","narrow"],m=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),c(this,"numeric","always"),c(this,"style","long"),c(this,"localeMatcher","lookup");var o=r.numeric,n=r.style,i=r.localeMatcher;if(o){if(h.indexOf(o)<0)throw new RangeError('Invalid "numeric" option: '.concat(o));this.numeric=o}if(n){if(y.indexOf(n)<0)throw new RangeError('Invalid "style" option: '.concat(n));this.style=n}if(i&&(this.localeMatcher=i),"string"==typeof e&&(e=[e]),e.push(a()),this.locale=t.supportedLocalesOf(e,{localeMatcher:this.localeMatcher})[0],!this.locale)throw new TypeError("No supported locale was found");this.locale=u(this.locale,{localeMatcher:this.localeMatcher}),"undefined"!=typeof Intl&&Intl.NumberFormat&&(this.numberFormat=new Intl.NumberFormat(this.locale))}var e,r,o;return e=t,(r=[{key:"format",value:function(t,e){return this.getRule(t,e).replace("{0}",this.formatNumber(Math.abs(t)))}},{key:"formatToParts",value:function(t,e){var r=this.getRule(t,e),o=r.indexOf("{0}");if(o<0)return[{type:"literal",value:r}];var n=[];return o>0&&n.push({type:"literal",value:r.slice(0,o)}),n.push({unit:e,type:"integer",value:this.formatNumber(Math.abs(t))}),o+"{0}".length<r.length-1&&n.push({type:"literal",value:r.slice(o+"{0}".length)}),n}},{key:"getRule",value:function(t,e){if(s.indexOf(e)<0)throw new RangeError("Unknown time unit: ".concat(e,"."));var r=i(this.locale)[this.style][e];if("auto"===this.numeric)if(-2===t||-1===t){var o=r["previous".concat(-1===t?"":"-"+Math.abs(t))];if(o)return o}else if(1===t||2===t){var n=r["next".concat(1===t?"":"-"+Math.abs(t))];if(n)return n}else if(0===t&&r.current)return r.current;var a=r[t<=0?"past":"future"];if("string"==typeof a)return a;var u=i(this.locale).quantify,l=u&&u(Math.abs(t));return a[l=l||"other"]||a.other}},{key:"formatNumber",value:function(t){return this.numberFormat?this.numberFormat.format(t):String(t)}},{key:"resolvedOptions",value:function(){return{locale:this.locale,style:this.style,numeric:this.numeric}}}])&&f(e.prototype,r),o&&f(e,o),t}();function p(t){return(p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function b(t){return(b="function"==typeof Symbol&&"symbol"===p(Symbol.iterator)?function(t){return p(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":p(t)})(t)}function d(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}m.supportedLocalesOf=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return"string"==typeof t&&(t=[t]),t.filter(function(t){return u(t,e)})},m.addLocale=function(t){if(!t)throw new Error("No locale data passed");n[t.locale]=t},m.setDefaultLocale=function(t){o=t},m.getDefaultLocale=a;var v=function(){function t(){var e,r,o;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),o={},(r="cache")in(e=this)?Object.defineProperty(e,r,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[r]=o}var e,r,o;return e=t,(r=[{key:"get",value:function(){for(var t=this.cache,e=arguments.length,r=new Array(e),o=0;o<e;o++)r[o]=arguments[o];for(var n=0;n<r.length;n++){var a=r[n];if("object"!==b(t))return;t=t[a]}return t}},{key:"put",value:function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];for(var o=e.pop(),n=e.pop(),a=this.cache,i=0;i<e.length;i++){var u=e[i];"object"!==b(a[u])&&(a[u]={}),a=a[u]}return a[n]=o}}])&&d(e.prototype,r),o&&d(e,o),t}(),g=86400;function w(t,e){var r=t,o=Array.isArray(r),n=0;for(r=o?r:r[Symbol.iterator]();;){var a;if(o){if(n>=r.length)break;a=r[n++]}else{if((n=r.next()).done)break;a=n.value}var i=a;if(i.unit===e)return i}}function S(t){return t instanceof Date?t:new Date(t)}var k=[{factor:1,unit:"now"},{threshold:1,threshold_for_now:45,factor:1,unit:"second"},{threshold:45,factor:60,unit:"minute"},{threshold:150,factor:60,granularity:5,unit:"minute"},{threshold:1350,factor:1800,unit:"half-hour"},{threshold:2550,threshold_for_minute:3150,factor:3600,unit:"hour"},{threshold:73800,factor:g,unit:"day"},{threshold:475200,factor:7*g,unit:"week"},{threshold:2116800,factor:2630016,unit:"month"},{threshold:27615168,factor:31556952,unit:"year"}];function O(t){return(O="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function j(t){return(j="function"==typeof Symbol&&"symbol"===O(Symbol.iterator)?function(t){return O(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":O(t)})(t)}function M(t,e,r){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:k;if(0!==(o=function(t,e){return t.filter(function(t){var r=t.unit;return!r||e.indexOf(r)>=0})}(o,r)).length){var n=function t(e,r,o){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;if(e<function(t,e,r){var o;t&&(t.id||t.unit)&&(o=e["threshold_for_".concat(t.id||t.unit)]);void 0===o&&(o=e.threshold);"function"==typeof o&&(o=o(r));if(t&&"number"!=typeof o){var n=j(o);throw new Error('Each step of a gradation must have a threshold defined except for the first one. Got "'.concat(o,'", ').concat(n,". Step: ").concat(JSON.stringify(e)))}return o}(o[n-1],o[n],r))return n-1;if(n===o.length-1)return n;return t(e,r,o,n+1)}(t,e,o),a=o[n];if(-1!==n){if(a.granularity)if(0===Math.round(t/a.factor/a.granularity)*a.granularity&&n>0)return o[n-1];return a}}}function D(t){return(D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function x(t){return(x="function"==typeof Symbol&&"symbol"===D(Symbol.iterator)?function(t){return D(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":D(t)})(t)}function F(t){if(T())return Intl.DateTimeFormat.supportedLocalesOf(t)[0]}function T(){return"object"===("undefined"==typeof Intl?"undefined":x(Intl))&&"function"==typeof Intl.DateTimeFormat}var L={gradation:k,flavour:["long-convenient","long"],units:["now","minute","hour","day","week","month","year"]},E=[{factor:1,unit:"now"},{threshold:.5,factor:1,unit:"second"},{threshold:59.5,factor:60,unit:"minute"},{threshold:3570,factor:3600,unit:"hour"},{threshold:84600,factor:g,unit:"day"},{threshold:561600,factor:7*g,unit:"week"},{threshold:2116800,factor:2630016,unit:"month"},{threshold:30245184,factor:31556952,unit:"year"}];function I(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var P={},_={gradation:[function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},o=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),o.forEach(function(e){I(t,e,r[e])})}return t}({},w(E,"minute"),{threshold:45}),w(E,"hour"),{threshold:84600,format:function(t,e){if(T())return P[e]||(P[e]={}),P[e].this_year||(P[e].this_year=new Intl.DateTimeFormat(e,{month:"short",day:"numeric"})),P[e].this_year.format(S(t))}},{threshold:function(t){return(new Date(new Date(t).getFullYear()+1,0).getTime()-t)/1e3},format:function(t,e){if(T())return P[e]||(P[e]={}),P[e].other||(P[e].other=new Intl.DateTimeFormat(e,{year:"numeric",month:"short",day:"numeric"})),P[e].other.format(S(t))}}],flavour:["tiny","short-time","narrow","short"]},N={gradation:k,flavour:"long-time",units:["now","minute","hour","day","week","month","year"]},R={};function A(t){return R[t]}function C(t){return(C="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function q(t){return(q="function"==typeof Symbol&&"symbol"===C(Symbol.iterator)?function(t){return C(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":C(t)})(t)}function U(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var V=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),"string"==typeof e&&(e=[e]),this.locale=function(t,e){var r=t,o=Array.isArray(r),n=0;for(r=o?r:r[Symbol.iterator]();;){var a;if(o){if(n>=r.length)break;a=r[n++]}else{if((n=r.next()).done)break;a=n.value}var i=a;if(e(i))return i;for(var u=i.split("-");u.length>1;)if(u.pop(),e(i=u.join("-")))return i}throw new Error("No locale data has been registered for any of the locales: ".concat(t.join(", ")))}(e.concat(m.getDefaultLocale()),A),"undefined"!=typeof Intl&&Intl.NumberFormat&&(this.numberFormat=new Intl.NumberFormat(this.locale)),this.relativeTimeFormatCache=new v}var e,r,o;return e=t,(r=[{key:"format",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:L;if("string"==typeof e)switch(e){case"twitter":e=_;break;case"time":e=N;break;default:e=L}var r=function(t){if(t.constructor===Date||(e=t,"object"===q(e)&&"function"==typeof e.getTime))return{date:t,time:t.getTime()};var e;if("number"==typeof t)return{time:t};throw new Error("Unsupported relative time formatter input: ".concat(q(t),", ").concat(t))}(t),o=r.date,n=r.time,a=this.getLocaleData(e.flavour),i=a.flavour,u=a.localeData,l=e.now||Date.now(),f=(l-n)/1e3;if(e.custom){var c=e.custom({now:l,date:o,time:n,elapsed:f,locale:this.locale});if(void 0!==c)return c}var s=function(t,e){var r=Object.keys(t);e&&(r=e.filter(function(t){return r.indexOf(t)>=0}));(!e||e.indexOf("now")>=0)&&r.indexOf("now")<0&&t.second.current&&r.unshift("now");return r}(u,e.units);if(0===s.length)return console.error('Units "'.concat(s.join(", "),'" were not found in locale data for "').concat(this.locale,'".')),"";var h=M(Math.abs(f),l,s,e.gradation);if(!h)return"";if(h.format)return h.format(o||n,this.locale);var y=h.unit,m=h.factor,p=h.granularity,b=Math.abs(f)/m;if(p&&(b=Math.round(b/p)*p),"now"===y)return function(t,e){if(t.now)return"string"==typeof t.now?t.now:e<=0?t.now.past:t.now.future;return t.second.current}(u,-1*Math.sign(f));switch(i){case"long":case"short":case"narrow":return this.getFormatter(i).format(-1*Math.sign(f)*Math.round(b),y);default:return this.formatValue(-1*Math.sign(f)*Math.round(b),y,u)}}},{key:"formatValue",value:function(t,e,r){return this.getRule(t,e,r).replace("{0}",this.formatNumber(Math.abs(t)))}},{key:"getRule",value:function(t,e,r){var o=r[e];if("string"==typeof o)return o;var n=o[t<=0?"past":"future"]||o;if("string"==typeof n)return n;var a=A(this.locale).quantify,i=a&&a(Math.abs(t));return n[i=i||"other"]||n.other}},{key:"formatNumber",value:function(t){return this.numberFormat?this.numberFormat.format(t):String(t)}},{key:"getFormatter",value:function(t){return this.relativeTimeFormatCache.get(this.locale,t)||this.relativeTimeFormatCache.put(this.locale,t,new m(this.locale,{style:t}))}},{key:"getLocaleData",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=A(this.locale);"string"==typeof t&&(t=[t]);var r=t=t.concat("long"),o=Array.isArray(r),n=0;for(r=o?r:r[Symbol.iterator]();;){var a;if(o){if(n>=r.length)break;a=r[n++]}else{if((n=r.next()).done)break;a=n.value}var i=a;if(e[i])return{flavour:i,localeData:e[i]}}}}])&&U(e.prototype,r),o&&U(e,o),t}();V.getDefaultLocale=m.getDefaultLocale,V.setDefaultLocale=m.setDefaultLocale,V.addLocale=function(t){!function(t){if(!t)throw new Error("[javascript-time-ago] No locale data passed.");R[t.locale]=t}(t),m.addLocale(t)},V.locale=V.addLocale,r.d(e,"default",function(){return V}),r.d(e,"intlDateTimeFormatSupported",function(){return T}),r.d(e,"intlDateTimeFormatSupportedLocale",function(){return F})}])});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("javascript-time-ago",[],e):"object"==typeof exports?exports["javascript-time-ago"]=e():t["javascript-time-ago"]=e()}(window,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([,function(t,e,r){"use strict";r.r(e);var n="en",o={};function a(){return n}function i(t){return o[t]}function u(t){var e=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).localeMatcher||"lookup";switch(e){case"lookup":case"best fit":return l(t);default:throw new RangeError('Invalid "localeMatcher" option: '.concat(e))}}function l(t){if(i(t))return t;for(var e=t.split("-");t.length>1;)if(e.pop(),i(t=e.join("-")))return t}function f(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function c(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var s=["second","minute","hour","day","week","month","quarter","year"],h=["auto","always"],y=["long","short","narrow"],m=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),c(this,"numeric","always"),c(this,"style","long"),c(this,"localeMatcher","lookup");var n=r.numeric,o=r.style,i=r.localeMatcher;if(n){if(h.indexOf(n)<0)throw new RangeError('Invalid "numeric" option: '.concat(n));this.numeric=n}if(o){if(y.indexOf(o)<0)throw new RangeError('Invalid "style" option: '.concat(o));this.style=o}if(i&&(this.localeMatcher=i),"string"==typeof e&&(e=[e]),e.push(a()),this.locale=t.supportedLocalesOf(e,{localeMatcher:this.localeMatcher})[0],!this.locale)throw new TypeError("No supported locale was found");this.locale=u(this.locale,{localeMatcher:this.localeMatcher}),"undefined"!=typeof Intl&&Intl.NumberFormat&&(this.numberFormat=new Intl.NumberFormat(this.locale))}var e,r,n;return e=t,(r=[{key:"format",value:function(t,e){return this.getRule(t,e).replace("{0}",this.formatNumber(Math.abs(t)))}},{key:"formatToParts",value:function(t,e){var r=this.getRule(t,e),n=r.indexOf("{0}");if(n<0)return[{type:"literal",value:r}];var o=[];return n>0&&o.push({type:"literal",value:r.slice(0,n)}),o.push({unit:e,type:"integer",value:this.formatNumber(Math.abs(t))}),n+"{0}".length<r.length-1&&o.push({type:"literal",value:r.slice(n+"{0}".length)}),o}},{key:"getRule",value:function(t,e){if(s.indexOf(e)<0)throw new RangeError("Unknown time unit: ".concat(e,"."));var r=i(this.locale)[this.style][e];if("auto"===this.numeric)if(-2===t||-1===t){var n=r["previous".concat(-1===t?"":"-"+Math.abs(t))];if(n)return n}else if(1===t||2===t){var o=r["next".concat(1===t?"":"-"+Math.abs(t))];if(o)return o}else if(0===t&&r.current)return r.current;var a=r[t<=0?"past":"future"];if("string"==typeof a)return a;var u=i(this.locale).quantify,l=u&&u(Math.abs(t));return a[l=l||"other"]||a.other}},{key:"formatNumber",value:function(t){return this.numberFormat?this.numberFormat.format(t):String(t)}},{key:"resolvedOptions",value:function(){return{locale:this.locale,style:this.style,numeric:this.numeric}}}])&&f(e.prototype,r),n&&f(e,n),t}();function p(t){return(p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function b(t){return(b="function"==typeof Symbol&&"symbol"===p(Symbol.iterator)?function(t){return p(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":p(t)})(t)}function d(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}m.supportedLocalesOf=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return"string"==typeof t&&(t=[t]),t.filter(function(t){return u(t,e)})},m.addLocale=function(t){if(!t)throw new Error("No locale data passed");o[t.locale]=t},m.setDefaultLocale=function(t){n=t},m.getDefaultLocale=a;var v=function(){function t(){var e,r,n;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),n={},(r="cache")in(e=this)?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n}var e,r,n;return e=t,(r=[{key:"get",value:function(){for(var t=this.cache,e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];for(var o=0;o<r.length;o++){var a=r[o];if("object"!==b(t))return;t=t[a]}return t}},{key:"put",value:function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];for(var n=e.pop(),o=e.pop(),a=this.cache,i=0;i<e.length;i++){var u=e[i];"object"!==b(a[u])&&(a[u]={}),a=a[u]}return a[o]=n}}])&&d(e.prototype,r),n&&d(e,n),t}(),g=86400;function w(t,e){var r=t,n=Array.isArray(r),o=0;for(r=n?r:r[Symbol.iterator]();;){var a;if(n){if(o>=r.length)break;a=r[o++]}else{if((o=r.next()).done)break;a=o.value}var i=a;if(i.unit===e)return i}}function S(t){return t instanceof Date?t:new Date(t)}var k=[{factor:1,unit:"now"},{threshold:1,threshold_for_now:45,factor:1,unit:"second"},{threshold:45,factor:60,unit:"minute"},{threshold:150,factor:60,granularity:5,unit:"minute"},{threshold:1350,factor:1800,unit:"half-hour"},{threshold:2550,threshold_for_minute:3150,factor:3600,unit:"hour"},{threshold:73800,factor:g,unit:"day"},{threshold:475200,factor:7*g,unit:"week"},{threshold:2116800,factor:2630016,unit:"month"},{threshold:27615168,factor:31556952,unit:"year"}];function O(t){return(O="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function j(t){return(j="function"==typeof Symbol&&"symbol"===O(Symbol.iterator)?function(t){return O(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":O(t)})(t)}function M(t,e,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:k;if(0!==(n=function(t,e){return t.filter(function(t){var r=t.unit;return!r||e.indexOf(r)>=0})}(n,r)).length){var o=function t(e,r,n){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;if(Math.abs(e)<function(t,e,r,n){var o;t&&(t.id||t.unit)&&(o=e["threshold_for_".concat(t.id||t.unit)]);void 0===o&&(o=e.threshold);"function"==typeof o&&(o=o(r,n));if(t&&"number"!=typeof o){var a=j(o);throw new Error('Each step of a gradation must have a threshold defined except for the first one. Got "'.concat(o,'", ').concat(a,". Step: ").concat(JSON.stringify(e)))}return o}(n[o-1],n[o],r,e<0))return o-1;if(o===n.length-1)return o;return t(e,r,n,o+1)}(t,e,n),a=n[o];if(-1!==o){if(a.granularity)if(0===Math.round(Math.abs(t)/a.factor/a.granularity)*a.granularity&&o>0)return n[o-1];return a}}}function D(t){return(D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function F(t){return(F="function"==typeof Symbol&&"symbol"===D(Symbol.iterator)?function(t){return D(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":D(t)})(t)}function x(t){if(T())return Intl.DateTimeFormat.supportedLocalesOf(t)[0]}function T(){return"object"===("undefined"==typeof Intl?"undefined":F(Intl))&&"function"==typeof Intl.DateTimeFormat}var L={gradation:k,flavour:["long-convenient","long"],units:["now","minute","hour","day","week","month","year"]},E=[{factor:1,unit:"now"},{threshold:.5,factor:1,unit:"second"},{threshold:59.5,factor:60,unit:"minute"},{threshold:3570,factor:3600,unit:"hour"},{threshold:84600,factor:g,unit:"day"},{threshold:561600,factor:7*g,unit:"week"},{threshold:2116800,factor:2630016,unit:"month"},{threshold:30245184,factor:31556952,unit:"year"}];function I(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var P={},_={gradation:[function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),n.forEach(function(e){I(t,e,r[e])})}return t}({},w(E,"minute"),{threshold:45}),w(E,"hour"),{threshold:84600,format:function(t,e){if(T())return P[e]||(P[e]={}),P[e].this_year||(P[e].this_year=new Intl.DateTimeFormat(e,{month:"short",day:"numeric"})),P[e].this_year.format(S(t))}},{threshold:function(t,e){return e?(new Date(new Date(t).getFullYear()+1,0).getTime()-t)/1e3:(t-new Date(new Date(t).getFullYear(),0).getTime())/1e3},format:function(t,e){if(T())return P[e]||(P[e]={}),P[e].other||(P[e].other=new Intl.DateTimeFormat(e,{year:"numeric",month:"short",day:"numeric"})),P[e].other.format(S(t))}}],flavour:["tiny","short-time","narrow","short"]},N={gradation:k,flavour:"long-time",units:["now","minute","hour","day","week","month","year"]},R={};function A(t){return R[t]}function C(t){return(C="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function q(t){return(q="function"==typeof Symbol&&"symbol"===C(Symbol.iterator)?function(t){return C(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":C(t)})(t)}function U(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var V=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),"string"==typeof e&&(e=[e]),this.locale=function(t,e){var r=t,n=Array.isArray(r),o=0;for(r=n?r:r[Symbol.iterator]();;){var a;if(n){if(o>=r.length)break;a=r[o++]}else{if((o=r.next()).done)break;a=o.value}var i=a;if(e(i))return i;for(var u=i.split("-");u.length>1;)if(u.pop(),e(i=u.join("-")))return i}throw new Error("No locale data has been registered for any of the locales: ".concat(t.join(", ")))}(e.concat(m.getDefaultLocale()),A),"undefined"!=typeof Intl&&Intl.NumberFormat&&(this.numberFormat=new Intl.NumberFormat(this.locale)),this.relativeTimeFormatCache=new v}var e,r,n;return e=t,(r=[{key:"format",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:L;if("string"==typeof e)switch(e){case"twitter":e=_;break;case"time":e=N;break;default:e=L}var r=function(t){if(t.constructor===Date||(e=t,"object"===q(e)&&"function"==typeof e.getTime))return{date:t,time:t.getTime()};var e;if("number"==typeof t)return{time:t};throw new Error("Unsupported relative time formatter input: ".concat(q(t),", ").concat(t))}(t),n=r.date,o=r.time,a=this.getLocaleData(e.flavour),i=a.flavour,u=a.localeData,l=e.now||Date.now(),f=(l-o)/1e3;if(e.custom){var c=e.custom({now:l,date:n,time:o,elapsed:f,locale:this.locale});if(void 0!==c)return c}var s=function(t,e){var r=Object.keys(t);e&&(r=e.filter(function(t){return r.indexOf(t)>=0}));(!e||e.indexOf("now")>=0)&&r.indexOf("now")<0&&t.second.current&&r.unshift("now");return r}(u,e.units);if(0===s.length)return console.error('Units "'.concat(s.join(", "),'" were not found in locale data for "').concat(this.locale,'".')),"";var h=M(f,l,s,e.gradation);if(!h)return"";if(h.format)return h.format(n||o,this.locale);var y=h.unit,m=h.factor,p=h.granularity,b=Math.abs(f)/m;if(p&&(b=Math.round(b/p)*p),"now"===y)return function(t,e){if(t.now)return"string"==typeof t.now?t.now:e<=0?t.now.past:t.now.future;return t.second.current}(u,-1*Math.sign(f));switch(i){case"long":case"short":case"narrow":return this.getFormatter(i).format(-1*Math.sign(f)*Math.round(b),y);default:return this.formatValue(-1*Math.sign(f)*Math.round(b),y,u)}}},{key:"formatValue",value:function(t,e,r){return this.getRule(t,e,r).replace("{0}",this.formatNumber(Math.abs(t)))}},{key:"getRule",value:function(t,e,r){var n=r[e];if("string"==typeof n)return n;var o=n[t<=0?"past":"future"]||n;if("string"==typeof o)return o;var a=A(this.locale).quantify,i=a&&a(Math.abs(t));return o[i=i||"other"]||o.other}},{key:"formatNumber",value:function(t){return this.numberFormat?this.numberFormat.format(t):String(t)}},{key:"getFormatter",value:function(t){return this.relativeTimeFormatCache.get(this.locale,t)||this.relativeTimeFormatCache.put(this.locale,t,new m(this.locale,{style:t}))}},{key:"getLocaleData",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=A(this.locale);"string"==typeof t&&(t=[t]);var r=t=t.concat("long"),n=Array.isArray(r),o=0;for(r=n?r:r[Symbol.iterator]();;){var a;if(n){if(o>=r.length)break;a=r[o++]}else{if((o=r.next()).done)break;a=o.value}var i=a;if(e[i])return{flavour:i,localeData:e[i]}}}}])&&U(e.prototype,r),n&&U(e,n),t}();V.getDefaultLocale=m.getDefaultLocale,V.setDefaultLocale=m.setDefaultLocale,V.addLocale=function(t){!function(t){if(!t)throw new Error("[javascript-time-ago] No locale data passed.");R[t.locale]=t}(t),m.addLocale(t)},V.locale=V.addLocale,r.d(e,"default",function(){return V}),r.d(e,"intlDateTimeFormatSupported",function(){return T}),r.d(e,"intlDateTimeFormatSupportedLocale",function(){return x})}])});
//# sourceMappingURL=javascript-time-ago.min.js.map

@@ -16,3 +16,3 @@ "use strict";

*
* @param {number} elapsed - Time interval (in seconds)
* @param {number} elapsed - Time interval (in seconds). Is < 0 for past dates and > 0 for future dates.
*

@@ -61,3 +61,3 @@ * @param {string[]} units - A list of allowed time units

// Recalculate the elapsed time amount based on granularity
var amount = Math.round(elapsed / step.factor / step.granularity) * step.granularity; // If the granularity for this step
var amount = Math.round(Math.abs(elapsed) / step.factor / step.granularity) * step.granularity; // If the granularity for this step
// is too high, then fallback

@@ -79,2 +79,3 @@ // to the previous step of gradation.

* @param {number} now - The current timestamp.
* @param {boolean} future - Is `true` for future dates ("in 5 minutes").
* @return {number}

@@ -85,3 +86,3 @@ * @throws Will throw if no threshold is found.

function getThreshold(fromStep, toStep, now) {
function getThreshold(fromStep, toStep, now, future) {
var threshold; // Allows custom thresholds when moving

@@ -102,3 +103,3 @@ // from a specific step to a specific step.

if (typeof threshold === 'function') {
threshold = threshold(now);
threshold = threshold(now, future);
} // Throw if no threshold is found.

@@ -133,3 +134,3 @@

// to this step is too high then return the previous step.
if (elapsed < getThreshold(gradation[i - 1], gradation[i], now)) {
if (Math.abs(elapsed) < getThreshold(gradation[i - 1], gradation[i], now, elapsed < 0)) {
return i - 1;

@@ -136,0 +137,0 @@ } // If it's the last step of gradation then return it.

@@ -174,3 +174,3 @@ "use strict";

var step = (0, _grade.default)(Math.abs(elapsed), now, units, style.gradation); // If no time unit is suitable, just output an empty string.
var step = (0, _grade.default)(elapsed, now, units, style.gradation); // If no time unit is suitable, just output an empty string.
// E.g. when "now" unit is not available

@@ -177,0 +177,0 @@ // and "second" has a threshold of `0.5`

@@ -67,6 +67,12 @@ "use strict";

{
threshold: function threshold(now) {
// Jan 1st of the next year.
var nextYear = new Date(new Date(now).getFullYear() + 1, 0);
return (nextYear.getTime() - now) / 1000;
threshold: function threshold(now, future) {
if (future) {
// Jan 1st 00:00 of the next year.
var nextYear = new Date(new Date(now).getFullYear() + 1, 0);
return (nextYear.getTime() - now) / 1000;
} else {
// Jan 1st of the current year.
var thisYear = new Date(new Date(now).getFullYear(), 0);
return (now - thisYear.getTime()) / 1000;
}
},

@@ -73,0 +79,0 @@ format: function format(value, locale) {

@@ -47,4 +47,11 @@ "use strict";

elapsed(_gradation.day + 2 * 60 + 60 * 60).should.equal('Apr 9'); // …
// "month" is an approximation.
elapsed(_gradation.year).should.equal('Apr 11, 2015');
elapsed(_gradation.month * 3).should.equal('Jan 10');
elapsed(_gradation.month * 4).should.equal('Dec 11, 2015');
elapsed(_gradation.year).should.equal('Apr 11, 2015'); // Test future dates.
// "month" is an approximation.
elapsed(-1 * _gradation.month * 8).should.equal('Dec 10');
elapsed(-1 * _gradation.month * 9).should.equal('Jan 9, 2017');
});

@@ -51,0 +58,0 @@ it('should format Twitter style relative time (Russian)', function () {

@@ -8,3 +8,3 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

*
* @param {number} elapsed - Time interval (in seconds)
* @param {number} elapsed - Time interval (in seconds). Is < 0 for past dates and > 0 for future dates.
*

@@ -54,3 +54,3 @@ * @param {string[]} units - A list of allowed time units

// Recalculate the elapsed time amount based on granularity
var amount = Math.round(elapsed / step.factor / step.granularity) * step.granularity; // If the granularity for this step
var amount = Math.round(Math.abs(elapsed) / step.factor / step.granularity) * step.granularity; // If the granularity for this step
// is too high, then fallback

@@ -72,2 +72,3 @@ // to the previous step of gradation.

* @param {number} now - The current timestamp.
* @param {boolean} future - Is `true` for future dates ("in 5 minutes").
* @return {number}

@@ -77,3 +78,3 @@ * @throws Will throw if no threshold is found.

function getThreshold(fromStep, toStep, now) {
function getThreshold(fromStep, toStep, now, future) {
var threshold; // Allows custom thresholds when moving

@@ -94,3 +95,3 @@ // from a specific step to a specific step.

if (typeof threshold === 'function') {
threshold = threshold(now);
threshold = threshold(now, future);
} // Throw if no threshold is found.

@@ -125,3 +126,3 @@

// to this step is too high then return the previous step.
if (elapsed < getThreshold(gradation[i - 1], gradation[i], now)) {
if (Math.abs(elapsed) < getThreshold(gradation[i - 1], gradation[i], now, elapsed < 0)) {
return i - 1;

@@ -128,0 +129,0 @@ } // If it's the last step of gradation then return it.

@@ -159,3 +159,3 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

var step = grade(Math.abs(elapsed), now, units, style.gradation); // If no time unit is suitable, just output an empty string.
var step = grade(elapsed, now, units, style.gradation); // If no time unit is suitable, just output an empty string.
// E.g. when "now" unit is not available

@@ -162,0 +162,0 @@ // and "second" has a threshold of `0.5`

@@ -58,6 +58,12 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

{
threshold: function threshold(now) {
// Jan 1st of the next year.
var nextYear = new Date(new Date(now).getFullYear() + 1, 0);
return (nextYear.getTime() - now) / 1000;
threshold: function threshold(now, future) {
if (future) {
// Jan 1st 00:00 of the next year.
var nextYear = new Date(new Date(now).getFullYear() + 1, 0);
return (nextYear.getTime() - now) / 1000;
} else {
// Jan 1st of the current year.
var thisYear = new Date(new Date(now).getFullYear(), 0);
return (now - thisYear.getTime()) / 1000;
}
},

@@ -64,0 +70,0 @@ format: function format(value, locale) {

@@ -7,3 +7,3 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

import JavascriptTimeAgo from '../JavascriptTimeAgo';
import { day, year } from '../gradation';
import { day, month, year } from '../gradation';
describe('"twitter" style', function () {

@@ -41,4 +41,11 @@ it('should fallback from "tiny" to "narrow" for Twitter style for autogenerated locales', function () {

elapsed(day + 2 * 60 + 60 * 60).should.equal('Apr 9'); // …
// "month" is an approximation.
elapsed(year).should.equal('Apr 11, 2015');
elapsed(month * 3).should.equal('Jan 10');
elapsed(month * 4).should.equal('Dec 11, 2015');
elapsed(year).should.equal('Apr 11, 2015'); // Test future dates.
// "month" is an approximation.
elapsed(-1 * month * 8).should.equal('Dec 10');
elapsed(-1 * month * 9).should.equal('Jan 9, 2017');
});

@@ -45,0 +52,0 @@ it('should format Twitter style relative time (Russian)', function () {

{
"name": "javascript-time-ago",
"version": "2.0.2",
"version": "2.0.3",
"description": "International highly customizable relative date/time formatting",

@@ -5,0 +5,0 @@ "main": "index.commonjs.js",

@@ -215,3 +215,3 @@ # javascript-time-ago

* `factor` — a divider for the supplied time interval (in seconds).
* `threshold` — a minimum time interval value (in seconds) required for this gradation step. Each step must have a `threshold` defined except for the first one. Can a `number` or a `function(now)` returning a `number`. Some advanced `threshold` customization is possible like `threshold_for_[prev-unit]` (see `./source/gradation/convenient.js`).
* `threshold` — a minimum time interval value (in seconds) required for this gradation step. Each step must have a `threshold` defined except for the first one. Can a `number` or a `function(now: number, future: boolean)` returning a `number`. Some advanced `threshold` customization is possible like `threshold_for_[prev-unit]` (see `./source/gradation/convenient.js`).
* `granularity` — for example, `5` for `minute` to allow only 5-minute intervals: `0 minutes`, `5 minutes`, `10 minutes`, etc.

@@ -218,0 +218,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc