sss-timer
Version:
4 lines • 3.02 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("Timer",[],e):"object"==typeof exports?exports.Timer=e():t.Timer=e()}(window,function(){return function(n){var r={};function i(t){if(r[t])return r[t].exports;var e=r[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,i),e.l=!0,e.exports}return i.m=n,i.c=r,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(n,r,function(t){return e[t]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=0)}([function(t,e,n){"use strict";n.r(e);var u={DAY:864e5,HOUR:36e5,MIN:6e4,SEC:1e3,MS:1},c=Object.keys(u),a=function(){return{DAY:0,HOUR:0,MIN:0,SEC:0,MS:0}};function i(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}
/*! SmokinSexySoftware: sss-timer
* https://github.com/Natteke
* Copyright (c) 2019-present Andrey Ponomarenko; */var r=function e(t){var n=this,r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),i(this,"interval",null),i(this,"date",a()),i(this,"start",function(){var t=Math.abs(n.tick);n.date=e.convert(n.time,n.breakOn),n.onTick(n.date,n),n.interval=setInterval(n.render,t)}),i(this,"render",function(){n.time+=n.tick,n.date=e.convert(n.time,n.breakOn),n.onTick(n.date,n),n.time<=0&&n.stop()}),i(this,"stop",function(){clearInterval(n.interval),n.onStop(n.date,n)}),i(this,"reset",function(){n.time=n.initialTime}),"function"!=typeof t)throw new TypeError("Timer: 1 argument function is required");this.onTick=t,this.onStop=r.onStop||function(){},this.time=r.time||0,this.initialTime=r.time||0,this.tick=r.tick||1e3,this.breakOn=r.breakOn||u.DAY};i(r,"duration",u),i(r,"stringify",function(t){var e=t;return Object.keys(e).forEach(function(t){e[t]=e[t]<10?"0".concat(e[t]):"".concat(e[t])}),e}),i(r,"convert",function(t){var e,n,r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:u.DAY,i=a(),o=t;for(e=0;e<c.length;e++)o>=u[c[e]]&&u[c[e]]<=r&&(i[n=c[e]]=Math.floor(o/u[n]),o-=u[n]*i[n]);return i}),i(r,"format",function(t,n){if(!t)throw Error("Timer.format string to format require");if(!n)throw Error("Timer.format object with time required");return Object.keys(n).reduce(function(t,e){return t.replace(new RegExp("{{".concat(e,"}}"),"gm"),n[e])},t)});e.default=r}]).default});