UNPKG

@ykcl/countdown

Version:

倒计时

7 lines (6 loc) 2.2 kB
/*! * @ykcl/countdown v1.0.1 * (c) 2022-2022 fangtao <fangtao@smartlink.com.cn> */ import{isUndefined as n}from"lodash";function t(n,t,e,r){return new(e||(e=Promise))((function(a,o){function u(n){try{l(r.next(n))}catch(n){o(n)}}function i(n){try{l(r.throw(n))}catch(n){o(n)}}function l(n){var t;n.done?a(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(u,i)}l((r=r.apply(n,t||[])).next())}))}function e(n,t){var e,r,a,o,u={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return u.label++,{value:o[1],done:!1};case 5:u.label++,r=o[1],o=[0];continue;case 7:o=u.ops.pop(),u.trys.pop();continue;default:if(!(a=u.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){u=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){u.label=o[1];break}if(6===o[0]&&u.label<a[1]){u.label=a[1],a=o;break}if(a&&u.label<a[2]){u.label=a[2],u.ops.push(o);break}a[2]&&u.ops.pop(),u.trys.pop();continue}o=t.call(n,u)}catch(n){o=[6,n],r=0}finally{e=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,i])}}}var r=function(r,o,u,i,l){if(r&&!n(r)&&o){var c={day:"00",hour:"00",minute:"00",second:"00"},s=null;clearInterval(s);var f=Number(o/1e3)-Number(r/1e3);f&&f<=0||(s=setInterval((function(){return t(void 0,void 0,void 0,(function(){return e(this,(function(n){switch(n.label){case 0:return(f-=1)<=0?(clearInterval(s),s=null,[2,c]):[4,a(f)];case 1:return c=n.sent(),i(c),[2]}}))}))}),u))}},a=function(n){var t={day:"00",hour:"00",minute:"00",second:"00"};return t.day=String(parseInt(n/60/60/24)).padStart(2,"0"),t.hour=String(parseInt(n/60/60%24)).padStart(2,"0"),t.minute=String(parseInt(n/60%60)).padStart(2,"0"),t.second=String(parseInt(n%60)).padStart(2,"0"),t};export{r as countDown}; //# sourceMappingURL=index.js.map