-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvreme.min.js
More file actions
1 lines (1 loc) · 4.76 KB
/
vreme.min.js
File metadata and controls
1 lines (1 loc) · 4.76 KB
1
(function(e,t){typeof exports=="object"&&exports?module.exports=t():typeof define=="function"&&define.amd?define(t):e.Vreme=t()})(this,function(){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var e=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),n=function(){function n(e){var r=this;t(this,n),this.options={monthNames:["january","february","march","april","may","june","july","august","september","october","november","december"],dayNames:["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]},e&&e.usePrototype&&function(){var e=r;Date.prototype.formatLike=function(t){return e.format(this,t)}}(),this.regex={MONTHNAMES_REGEXP:new RegExp("^("+this.options.monthNames.join("|")+")$","i"),MONTHNAMES_ABBR_REGEXP:new RegExp("^("+this.options.monthNames.map(function(e){return e.substr(0,3)}).join("|")+")$","i"),DAYNAMES_REGEXP:new RegExp("^("+this.options.dayNames.join("|")+")$","i"),DAYNAMES_ABBR_REGEXP:new RegExp("^("+this.options.dayNames.map(function(e){return e.substr(0,3)}).join("|")+")$","i"),DAYNAMES_SHORT_REGEXP:new RegExp("^("+this.options.dayNames.map(function(e){return e.substr(0,2)}).join("|")+")$","i"),ONE_DIGIT_REGEXP:/^\d{1}$/,TWO_DIGIT_REGEXP:/^\d{2}$/,FOUR_DIGIT_REGEXP:/^\d{4}$/,ORDINAL_DAY_REGEXP:/^(\d{1,2})(st|nd|rd|th)$/,TIME_REGEXP:/(\d{1,2})(:)(\d{2})(\s*)(:)?(\d{2})?(\s*)?([ap]m)?/i},this._reset()}return e(n,[{key:"format",value:function(t,n){var r=this;this._reset();var i=n.split(this.regex.TIME_REGEXP),s=i.splice(0,1)[0],o=i.pop();o=o||"";var u=s.split(/\b/).map(function(e){return r.formatDate(t,e)}),a=[];return i.length&&(a=i.map(function(e,n){return r.formatTime(t,e,n,i)})),u.join("")+a.join("")+o}},{key:"ordinalSuffix",value:function(t){var n=t%10,r=t%100;return n==1&&r!=11?t+"st":n==2&&r!=12?t+"nd":n==3&&r!=13?t+"rd":t+"th"}},{key:"formatDate",value:function(t,n){var r=this,i=function(t,n,i){var s=r,o=!0;e:while(o){var u=t,a=n,f=i;l=undefined,o=!1;if(u>12&&u<32&&!s.matches.day)return s.matches.day=!0,("0"+a.getDate()).slice(-2);if(u>12&&!s.matches.year||u>31)return s.matches.year=!0,a.getFullYear()+"";if(!s.matches.month){s.matches.month=!0;var l=a.getMonth()+1;return f?("0"+l).slice(-2):l+""}if(!s.matches.day)return s.matches.day=!0,f?("0"+a.getDate()).slice(-2):a.getDate()+"";if(!s.matches.year)return s.matches.year=!0,f?("0"+a.getFullYear()).slice(-2):a.getFullYear()+"";s.reset(),s=undefined,t=u,n=a,o=!0;continue e}};if(n.match(this.regex.MONTHNAMES_REGEXP))return this.matches.month=!0,this._correctCase(n,this.options.monthNames[t.getMonth()]);if(n.match(this.regex.MONTHNAMES_ABBR_REGEXP))return this.matches.month=!0,this._correctCase(n,this.options.monthNames[t.getMonth()].substr(0,3));if(n.match(this.regex.DAYNAMES_REGEXP))return this.matches.day=!0,this._correctCase(n,this.options.dayNames[t.getDay()]);if(n.match(this.regex.DAYNAMES_ABBR_REGEXP))return this.matches.day=!0,this._correctCase(n,this.options.dayNames[t.getDay()].substr(0,3));if(n.match(this.regex.DAYNAMES_SHORT_REGEXP))return this.matches.day=!0,this._correctCase(n,this.options.dayNames[t.getDay()].substr(0,2));if(n.match(this.regex.FOUR_DIGIT_REGEXP))return this.matches.year=!0,t.getFullYear()+"";if(n.match(this.regex.ORDINAL_DAY_REGEXP))return this.matches.day=!0,this.ordinalSuffix(t.getDate());if(n.match(this.regex.TWO_DIGIT_REGEXP)){var s=parseInt(n,10);return s>31&&s<100?(this.matches.year=!0,(t.getFullYear()+"").substring(2,4)):i(s,t,!0)}if(n.match(this.regex.ONE_DIGIT_REGEXP)){var s=parseInt(n,10);return i(s,t)}return n}},{key:"formatTime",value:function(t,n,r,i){var s=this,o=function(t,n){var r=n<12?"am":"pm";return s._isAllCaps(t)?r.toUpperCase():r};return r===0&&n.match(this.regex.ONE_DIGIT_REGEXP)?t.getHours():r===0&&n.match(this.regex.TWO_DIGIT_REGEXP)?i[7]&&t.getHours()>12?("0"+(t.getHours()-12)).slice(-2):("0"+t.getHours()).slice(-2):r===2&&n.match(this.regex.TWO_DIGIT_REGEXP)?("0"+t.getMinutes()).slice(-2):n&&r===5&&n.match(this.regex.TWO_DIGIT_REGEXP)?("0"+t.getSeconds()).slice(-2):n&&r===7?t.getHours()<12?this._correctCase(n,"am"):this._correctCase(n,"pm"):n}},{key:"_reset",value:function(){this.matches={month:!1,day:!1,year:!1}}},{key:"_isCapital",value:function(t){return t.charAt(0)===t.charAt(0).toUpperCase()}},{key:"_isLowercase",value:function(t){return t===t.toLowerCase()}},{key:"_isAllCaps",value:function(t){return t===t.toUpperCase()}},{key:"_toCapital",value:function(t){return t.charAt(0).toUpperCase()+t.slice(1,t.length)}},{key:"_correctCase",value:function(t,n){return this._isLowercase(t)?n.toLowerCase():this._isAllCaps(t)?n.toUpperCase():this._isCapital(t)?this._toCapital(n):n}}]),n}();return n})