bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/web/static/js/moment-duration-format.min.js (about)

     1  (function(e,t){function n(e){var t="";e=parseInt(e,10);if(!e||e<1){return t}while(e){t+="0";e-=1}return t}function r(e,t,r){if(e==null){e=""}e=""+e;return(r?e:"")+n(t-e.length)+(r?"":e)}function i(e){return Object.prototype.toString.call(e)==="[object Array]"}function s(e){return Object.prototype.toString.call(e)==="[object Object]"}function o(e,t){var n=e.length;while(n-=1){if(t(e[n])){return e[n]}}}function u(e,t){var n=0,r=e.length,i;if(typeof t!=="function"){i=t;t=function(e){return e===i}}while(n<r){if(t(e[n])){return e[n]}n+=1}}function a(e,t){var n=0,r=e.length;if(!e||!r){return}while(n<r){if(t(e[n],n)===false){return}n+=1}}function f(e,t){var n=0,r=e.length,i=[];if(!e||!r){return i}while(n<r){i[n]=t(e[n],n);n+=1}return i}function l(e,t){return f(e,function(e){return e[t]})}function c(e){var t=[];a(e,function(e){if(e){t.push(e)}});return t}function h(e){var t=[];a(e,function(e){if(!u(t,e)){t.push(e)}});return t}function p(e,t){var n=[];a(e,function(e){a(t,function(t){if(e===t){n.push(e)}})});return h(n)}function d(e,t){var n=[];a(e,function(r,i){if(!t(r)){n=e.slice(i);return false}});return n}function v(e,t){var n=e.slice().reverse();return d(n,t).reverse()}function m(e,t){for(var n in t){if(t.hasOwnProperty(n)){e[n]=t[n]}}return e}var g;if(typeof require==="function"){try{g=require("moment")}catch(y){}}if(!g&&e.moment){g=e.moment}if(!g){throw"Moment Duration Format cannot find Moment.js"}g.duration.fn.format=function(){var e,t,o,y,b,w,E,S=[].slice.call(arguments),x=m({},this.format.defaults),T=g.duration(this);x.duration=this;a(S,function(e){if(typeof e==="string"||typeof e==="function"){x.template=e;return}if(typeof e==="number"){x.precision=e;return}if(s(e)){m(x,e)}});o=x.types=i(x.types)?x.types:x.types.split(" ");if(typeof x.template==="function"){x.template=x.template.apply(x)}e=new RegExp(f(o,function(e){return x[e].source}).join("|"),"g");y=function(e){return u(o,function(t){return x[t].test(e)})};t=f(x.template.match(e),function(e,t){var n=y(e),r=e.length;return{index:t,length:r,token:n==="escape"?e.replace(x.escape,"$1"):e,type:n==="escape"||n==="general"?null:n}},this);b=p(o,h(c(l(t,"type"))));if(!b.length){return l(t,"token").join("")}a(b,function(e,n){var r,i,s,o,u;r=T.as(e);i=r>0?Math.floor(r):Math.ceil(r);s=r-i;o=n+1===b.length;u=!n;a(t,function(t){if(t.type===e){m(t,{value:r,wholeValue:i,decimalValue:s,isLeast:o,isMost:u});if(u){if(x.forceLength==null&&t.length>1){x.forceLength=true}}}});T.subtract(i,e)});if(x.trim){t=(x.trim==="left"?d:v)(t,function(e){return!(e.isLeast||e.type!=null&&e.wholeValue)})}w=false;if(x.trim==="right"){t.reverse()}t=f(t,function(e){var t,i;if(!e.type){return e.token}if(e.isLeast&&x.precision<0){t=(Math.floor(e.wholeValue*Math.pow(10,x.precision))*Math.pow(10,-x.precision)).toString()}else{t=e.wholeValue.toString()}t=t.replace(/^\-/,"");if(e.length>1&&(w||e.isMost||x.forceLength)){t=r(t,e.length)}if(e.isLeast&&x.precision>0){i=e.decimalValue.toString().replace(/^\-/,"").split(/\.|e\-/);switch(i.length){case 1:t+="."+r(i[0],x.precision,true).slice(0,x.precision);break;case 2:t+="."+r(i[1],x.precision,true).slice(0,x.precision);break;case 3:t+="."+r(n(+i[2]-1)+(i[0]||"0")+i[1],x.precision,true).slice(0,x.precision);break;default:throw"Moment Duration Format: unable to parse token decimal value."}}if(e.isMost&&e.value<0){t="-"+t}w=true;return t});if(x.trim==="right"){t.reverse()}return t.join("")};g.duration.fn.format.defaults={escape:/\[(.+?)\]/,years:/[Yy]+/,months:/M+/,weeks:/[Ww]+/,days:/[Dd]+/,hours:/[Hh]+/,minutes:/m+/,seconds:/s+/,milliseconds:/S+/,general:/.+?/,types:"escape years months weeks days hours minutes seconds milliseconds general",trim:"left",precision:0,forceLength:null,template:function(){var e=this.types,t=this.duration,n=o(e,function(e){return t._data[e]});switch(n){case"seconds":return"h:mm:ss";case"minutes":return"d[d] h:mm";case"hours":return"d[d] h[h]";case"days":return"M[m] d[d]";case"weeks":return"y[y] w[w]";case"months":return"y[y] M[m]";case"years":return"y[y]";default:return"y[y] M[m] d[d] h:mm:ss"}}}})(this)