dayjs-twitter
Version:
A Twitter-like date formatter for day.js
1 lines • 5.04 kB
JavaScript
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.dayjsTwitter=n():e.dayjsTwitter=n()}(this,function(){return function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=1)}([function(e,n,t){var r,o=function(){var e={ns:1e-6,us:.001,"µs":.001,"μs":.001,ms:1,s:1e3,m:6e4,h:36e5,d:864e5,w:6048e5},n=function(e){if(e instanceof n)return e;switch(typeof e){case"number":if(!isFinite(e))throw new Error("invalid duration: "+e);this._milliseconds=e;break;case"string":this._milliseconds=n.parse(e).valueOf();break;case"undefined":this._milliseconds=0;break;default:throw new Error("invalid duration: "+e)}};return n.millisecond=new n(1),n.second=new n(1e3),n.minute=new n(6e4),n.hour=new n(36e5),n.day=new n(864e5),n.week=new n(6048e5),n.prototype.nanoseconds=function(){return Math.floor(this._milliseconds/1e-6)},n.prototype.microseconds=function(){return Math.floor(this._milliseconds/.001)},n.prototype.milliseconds=function(){return this._milliseconds},n.prototype.seconds=function(){return Math.floor(this._milliseconds/1e3)},n.prototype.minutes=function(){return Math.floor(this._milliseconds/6e4)},n.prototype.hours=function(){return Math.floor(this._milliseconds/36e5)},n.prototype.days=function(){return Math.floor(this._milliseconds/864e5)},n.prototype.weeks=function(){return Math.floor(this._milliseconds/6048e5)},n.prototype.toString=function(){var e="",n=Math.abs(this._milliseconds),t=this._milliseconds<0?"-":"";if(0===n)return"0";var r=Math.floor(n/36e5);0!==r&&(n-=36e5*r,e+=r.toString()+"h");var o=Math.floor(n/6e4);0!==o&&(n-=6e4*o,e+=o.toString()+"m");var i=Math.floor(n/1e3);return 0!==i&&(n-=1e3*i,e+=i.toString()+"s"),0!==n&&(e+=n.toString()+"ms"),t+e},n.prototype.valueOf=function(){return this._milliseconds},n.parse=function(t){if("0"===t||"+0"===t||"-0"===t)return new n(0);for(var r,o,i,s=/([\-\+\d\.]+)([a-zµμ]+)/g,u=0,a=0,f="-"===t[0]?-1:1;i=s.exec(t);){if(r=i[2],o=Math.abs(parseFloat(i[1])),a++,isNaN(o))throw new Error("invalid duration");if(void 0===e[r])throw new Error("invalid unit: "+r);u+=o*e[r]}if(0===a)throw new Error("invalid duration");return new n(Math.floor(u)*f)},n.prototype.roundTo=function(e){var t=new n(e).valueOf();this._milliseconds=t*Math.round(this._milliseconds/t)},n.prototype.isGreaterThan=function(e){return this.valueOf()>new n(e).valueOf()},n.prototype.isLessThan=function(e){return this.valueOf()<new n(e).valueOf()},n.prototype.isEqualTo=function(e){return this.valueOf()===new n(e).valueOf()},n.prototype.after=function(e){return new Date(e.valueOf()+this._milliseconds)},n.since=function(e){return new n((new Date).valueOf()-e.valueOf())},n.until=function(e){return new n(e.valueOf()-(new Date).valueOf())},n.fromMicroseconds=function(e){var t=Math.floor(e/1e3);return new n(t)},n.fromNanoseconds=function(e){var t=Math.floor(e/1e6);return new n(t)},n.between=function(e,t){return new n(t.valueOf()-e.valueOf())},n.add=function(e,t){return new n(e+t)},n.subtract=function(e,t){return new n(e-t)},n.multiply=function(e,t){return new n(e*t)},n.divide=function(e,n){return e/n},n}.call(this);void 0===(r=function(){return o}.apply(n,[]))||(e.exports=r)},function(e,n,t){"use strict";t.r(n);var r=t(0),o=t.n(r),i={en:{now:"Now",seconds:"%ds",minutes:"%dm",hours:"%dh",days:"MMM D",years:"MMM D, YYYY"},es:{now:"Ahora",seconds:"%ds",minutes:"%dmin",hours:"%dh",days:"D MMM.",years:"D MMM. YYYY"},ru:{now:"1 с",seconds:"%d с",minutes:"%d мин",hours:"%d ч",days:"D MMM.",years:"D MMM. YYYY"},fr:{now:"Μaintenant",seconds:"%ds",minutes:"%dm",hours:"%dh",days:"MMM D",years:"MMM D, YYYY"},el:{now:"Τώρα",seconds:"%dδ",minutes:"%dλ",hours:"%dω",days:"MMM D",years:"MMM D, YYYY"}};n.default=function(e,n,t){n.prototype.twitter=function(){return function(e){var n=e.$locale(),t=n?n.name:"en",r=Math.abs(e.diff(new Date)),s=null,u=null;(s=r<=1e3?"now":r<6e4?"seconds":r<36e5?"minutes":r<864e5?"hours":r<31536e6?"days":"years",u&&s||!(["seconds","minutes","hours"].indexOf(s)>-1))||(u=new o.a(r)[s]());if("days"===s||"years"===s){var a=i[t][s];return e.format(a)}return i[t][s].replace("%d",u)}(this)}}}])});