UNPKG

@extclp/vexip-ui

Version:

A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good

38 lines (37 loc) 1.47 kB
import { makeSentence as S, getCountWord as p } from "@vexip-ui/config"; import { SECOND_ON_MILLISECONDS as M, MINUTE_ON_MILLISECONDS as I, HOUR_ON_MILLISECONDS as h, DAY_ON_MILLISECONDS as r } from "@vexip-ui/utils"; let O = 1; function D() { return O++; } const u = /* @__PURE__ */ new Map(); let l, m; function L(f, o) { u.set(f, o), u.size && !m && (clearInterval(l), l = setInterval(() => { m = !0; const e = Date.now(); u.forEach((n) => { n.interval && e - n.updated > n.interval && (n.timeAgo.value = d( n.datetime, e, n.locale.value, n.wordSpace.value ), n.updated = e); }); }, 5e3)); } function _(f) { u.delete(f), u.size || (clearInterval(l), m = !1); } function d(f, o, e, n) { const t = Math.abs(o - f.getTime()), N = o > f.getTime() ? e.ago : e.late; let i, s, a = !1; return t < 10 * M ? (i = e.justNow, a = !0) : t < I ? (i = e.second, s = Math.floor(t / M)) : t < h ? (i = e.minute, s = Math.floor(t / I)) : t < r ? (i = e.hour, s = Math.floor(t / h)) : t < 30 * r ? (s = Math.floor(t / r), s === 1 ? (i = e.yesterday, a = !0) : i = e.days) : t < 365 * r ? (s = Math.floor(t / (30 * r)), s === 1 ? (i = e.lastMonth, a = !0) : i = e.months) : (s = Math.floor(t / 365 / r), s === 1 ? (i = e.lastYear, a = !0) : i = e.years), a ? i : S(`${p(i, s)} ${N}`, n); } export { d as computeTimeAgo, D as getId, L as subscribe, _ as unsubscribe }; //# sourceMappingURL=helper.mjs.map