UNPKG

ll-package

Version:

2 lines (1 loc) 717 B
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=[["Y",1e3*60*60*24*365],["M",1e3*60*60*24*30],["D",1e3*60*60*24],["H",1e3*60*60],["m",1e3*60],["s",1e3],["S",1]];function m(r,n){let o=r;const e=/\[[^\]]*]/g,a=(n.match(e)||[]).map(t=>t.slice(1,-1)),c=n.replace(e,"[]"),f=S.reduce((t,p)=>{let[i,l]=p;if(t.includes(i)){const u=Math.floor(o/l);return o-=u*l,t.replace(new RegExp(`${i}+`,"g"),d=>{const g=d.length;return u.toString().padStart(g,"0")})}return t},c);let s=0;return f.replace(e,()=>{const t=a[s];return s+=1,t})}function x(r,n){const{format:o=""}=n,e=new Date(r).getTime(),a=Date.now(),c=Math.max(e-a,0);return m(c,o)}exports.formatCountdown=x;exports.formatTimeStr=m;