@builtwithjavascript/countdown
Advanced tools
| var d = Object.defineProperty; | ||
| var h = (s, t, i) => t in s ? d(s, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : s[t] = i; | ||
| var r = (s, t, i) => h(s, typeof t != "symbol" ? t + "" : t, i); | ||
| class m { | ||
| constructor(t) { | ||
| r(this, "intervalId"); | ||
| r(this, "callback"); | ||
| r(this, "isRunning", !1); | ||
| this.callback = t; | ||
| } | ||
| // Modified to return the new object structure | ||
| calculateRemainingTime(t, i) { | ||
| const e = t.getTime() - i.getTime(); | ||
| let n; | ||
| if (e <= 0) | ||
| n = { | ||
| days: 0, | ||
| hours: 0, | ||
| minutes: 0, | ||
| seconds: 0, | ||
| totalMilliseconds: 0, | ||
| isFinished: !0 | ||
| }; | ||
| else { | ||
| const a = Math.floor(e / 864e5), l = Math.floor(e % (1e3 * 60 * 60 * 24) / (1e3 * 60 * 60)), c = Math.floor(e % (1e3 * 60 * 60) / (1e3 * 60)), u = Math.ceil(e % (1e3 * 60) / 1e3); | ||
| n = { | ||
| days: a, | ||
| hours: l, | ||
| minutes: c, | ||
| seconds: u, | ||
| totalMilliseconds: e, | ||
| isFinished: !1 | ||
| }; | ||
| } | ||
| const o = { | ||
| days: 0, | ||
| // Days are not typically relevant for current time display in HH:MM:SS | ||
| hours: i.getHours(), | ||
| minutes: i.getMinutes(), | ||
| seconds: i.getSeconds() | ||
| }; | ||
| return { | ||
| timeRemaining: n, | ||
| currentTime: o | ||
| }; | ||
| } | ||
| start(t) { | ||
| if (this.isRunning) | ||
| return; | ||
| this.isRunning = !0; | ||
| const i = () => { | ||
| const e = /* @__PURE__ */ new Date(), n = this.calculateRemainingTime(t, e); | ||
| this.callback(n), n.timeRemaining.isFinished && this.stop(); | ||
| let a = 1e3 - e.getMilliseconds(); | ||
| a < 10 && (a += 1e3), this.intervalId = window.setTimeout(i, Math.max(1, a)); | ||
| }; | ||
| i(); | ||
| } | ||
| stop() { | ||
| this.intervalId && (clearTimeout(this.intervalId), this.intervalId = void 0), this.isRunning = !1; | ||
| } | ||
| } | ||
| function g(s) { | ||
| let t = s.seconds, i = s.minutes, e = s.hours, n = s.days; | ||
| if (t === 60 && (t = 0, i++, i === 60 && (i = 0, e++, e === 24 && (e = 0, n++))), s.isFinished) | ||
| return "00:00:00:00"; | ||
| const o = (a) => a.toString().padStart(2, "0"); | ||
| return `${o(n)}:${o(e)}:${o(i)}:${o(t)}`; | ||
| } | ||
| function y(s) { | ||
| const t = (i) => i.toString().padStart(2, "0"); | ||
| return `${t(s.hours)}:${t(s.minutes)}:${t(s.seconds)}`; | ||
| } | ||
| export { | ||
| m as Countdown, | ||
| y as formatCurrentTime, | ||
| g as formatTimeRemaining | ||
| }; |
| (function(e,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(e=typeof globalThis<"u"?globalThis:e||self,n(e.countdown={}))})(this,function(e){"use strict";var g=Object.defineProperty;var y=(e,n,c)=>n in e?g(e,n,{enumerable:!0,configurable:!0,writable:!0,value:c}):e[n]=c;var u=(e,n,c)=>y(e,typeof n!="symbol"?n+"":n,c);class n{constructor(s){u(this,"intervalId");u(this,"callback");u(this,"isRunning",!1);this.callback=s}calculateRemainingTime(s,t){const i=s.getTime()-t.getTime();let a;if(i<=0)a={days:0,hours:0,minutes:0,seconds:0,totalMilliseconds:0,isFinished:!0};else{const l=Math.floor(i/864e5),f=Math.floor(i%(1e3*60*60*24)/(1e3*60*60)),m=Math.floor(i%(1e3*60*60)/(1e3*60)),h=Math.ceil(i%(1e3*60)/1e3);a={days:l,hours:f,minutes:m,seconds:h,totalMilliseconds:i,isFinished:!1}}const r={days:0,hours:t.getHours(),minutes:t.getMinutes(),seconds:t.getSeconds()};return{timeRemaining:a,currentTime:r}}start(s){if(this.isRunning)return;this.isRunning=!0;const t=()=>{const i=new Date,a=this.calculateRemainingTime(s,i);this.callback(a),a.timeRemaining.isFinished&&this.stop();let l=1e3-i.getMilliseconds();l<10&&(l+=1e3),this.intervalId=window.setTimeout(t,Math.max(1,l))};t()}stop(){this.intervalId&&(clearTimeout(this.intervalId),this.intervalId=void 0),this.isRunning=!1}}function c(o){let s=o.seconds,t=o.minutes,i=o.hours,a=o.days;if(s===60&&(s=0,t++,t===60&&(t=0,i++,i===24&&(i=0,a++))),o.isFinished)return"00:00:00:00";const r=l=>l.toString().padStart(2,"0");return`${r(a)}:${r(i)}:${r(t)}:${r(s)}`}function d(o){const s=t=>t.toString().padStart(2,"0");return`${s(o.hours)}:${s(o.minutes)}:${s(o.seconds)}`}e.Countdown=n,e.formatCurrentTime=d,e.formatTimeRemaining=c,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}); |
+1
-1
| { | ||
| "name": "@builtwithjavascript/countdown", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "Accurate countdown", | ||
@@ -5,0 +5,0 @@ "author": "Damiano Fusco", |
| var d = Object.defineProperty; | ||
| var h = (s, t, i) => t in s ? d(s, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : s[t] = i; | ||
| var r = (s, t, i) => h(s, typeof t != "symbol" ? t + "" : t, i); | ||
| class m { | ||
| constructor(t) { | ||
| r(this, "intervalId"); | ||
| r(this, "callback"); | ||
| r(this, "isRunning", !1); | ||
| this.callback = t; | ||
| } | ||
| // Modified to return the new object structure | ||
| calculateRemainingTime(t, i) { | ||
| const e = t.getTime() - i.getTime(); | ||
| let n; | ||
| if (e <= 0) | ||
| n = { | ||
| days: 0, | ||
| hours: 0, | ||
| minutes: 0, | ||
| seconds: 0, | ||
| totalMilliseconds: 0, | ||
| isFinished: !0 | ||
| }; | ||
| else { | ||
| const a = Math.floor(e / 864e5), l = Math.floor(e % (1e3 * 60 * 60 * 24) / (1e3 * 60 * 60)), c = Math.floor(e % (1e3 * 60 * 60) / (1e3 * 60)), u = Math.ceil(e % (1e3 * 60) / 1e3); | ||
| n = { | ||
| days: a, | ||
| hours: l, | ||
| minutes: c, | ||
| seconds: u, | ||
| totalMilliseconds: e, | ||
| isFinished: !1 | ||
| }; | ||
| } | ||
| const o = { | ||
| days: 0, | ||
| // Days are not typically relevant for current time display in HH:MM:SS | ||
| hours: i.getHours(), | ||
| minutes: i.getMinutes(), | ||
| seconds: i.getSeconds() | ||
| }; | ||
| return { | ||
| timeRemaining: n, | ||
| currentTime: o | ||
| }; | ||
| } | ||
| start(t) { | ||
| if (this.isRunning) | ||
| return; | ||
| this.isRunning = !0; | ||
| const i = () => { | ||
| const e = /* @__PURE__ */ new Date(), n = this.calculateRemainingTime(t, e); | ||
| this.callback(n), n.timeRemaining.isFinished && this.stop(); | ||
| let a = 1e3 - e.getMilliseconds(); | ||
| a < 10 && (a += 1e3), this.intervalId = window.setTimeout(i, Math.max(1, a)); | ||
| }; | ||
| i(); | ||
| } | ||
| stop() { | ||
| this.intervalId && (clearTimeout(this.intervalId), this.intervalId = void 0), this.isRunning = !1; | ||
| } | ||
| } | ||
| function g(s) { | ||
| let t = s.seconds, i = s.minutes, e = s.hours, n = s.days; | ||
| if (t === 60 && (t = 0, i++, i === 60 && (i = 0, e++, e === 24 && (e = 0, n++))), s.isFinished) | ||
| return "00:00:00:00"; | ||
| const o = (a) => a.toString().padStart(2, "0"); | ||
| return `${o(n)}:${o(e)}:${o(i)}:${o(t)}`; | ||
| } | ||
| function y(s) { | ||
| const t = (i) => i.toString().padStart(2, "0"); | ||
| return `${t(s.hours)}:${t(s.minutes)}:${t(s.seconds)}`; | ||
| } | ||
| export { | ||
| m as Countdown, | ||
| y as formatCurrentTime, | ||
| g as formatTimeRemaining | ||
| }; |
| (function(e,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(e=typeof globalThis<"u"?globalThis:e||self,n(e.permissions={}))})(this,function(e){"use strict";var g=Object.defineProperty;var p=(e,n,c)=>n in e?g(e,n,{enumerable:!0,configurable:!0,writable:!0,value:c}):e[n]=c;var u=(e,n,c)=>p(e,typeof n!="symbol"?n+"":n,c);class n{constructor(s){u(this,"intervalId");u(this,"callback");u(this,"isRunning",!1);this.callback=s}calculateRemainingTime(s,t){const i=s.getTime()-t.getTime();let a;if(i<=0)a={days:0,hours:0,minutes:0,seconds:0,totalMilliseconds:0,isFinished:!0};else{const l=Math.floor(i/864e5),f=Math.floor(i%(1e3*60*60*24)/(1e3*60*60)),m=Math.floor(i%(1e3*60*60)/(1e3*60)),h=Math.ceil(i%(1e3*60)/1e3);a={days:l,hours:f,minutes:m,seconds:h,totalMilliseconds:i,isFinished:!1}}const r={days:0,hours:t.getHours(),minutes:t.getMinutes(),seconds:t.getSeconds()};return{timeRemaining:a,currentTime:r}}start(s){if(this.isRunning)return;this.isRunning=!0;const t=()=>{const i=new Date,a=this.calculateRemainingTime(s,i);this.callback(a),a.timeRemaining.isFinished&&this.stop();let l=1e3-i.getMilliseconds();l<10&&(l+=1e3),this.intervalId=window.setTimeout(t,Math.max(1,l))};t()}stop(){this.intervalId&&(clearTimeout(this.intervalId),this.intervalId=void 0),this.isRunning=!1}}function c(o){let s=o.seconds,t=o.minutes,i=o.hours,a=o.days;if(s===60&&(s=0,t++,t===60&&(t=0,i++,i===24&&(i=0,a++))),o.isFinished)return"00:00:00:00";const r=l=>l.toString().padStart(2,"0");return`${r(a)}:${r(i)}:${r(t)}:${r(s)}`}function d(o){const s=t=>t.toString().padStart(2,"0");return`${s(o.hours)}:${s(o.minutes)}:${s(o.seconds)}`}e.Countdown=n,e.formatCurrentTime=d,e.formatTimeRemaining=c,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}); |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
8086
-0.02%