New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-hook-time

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hook-time - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

239

dist/index.es.js

@@ -1,152 +0,165 @@

import { useEffect as P, useRef as M, useState as L } from "react";
function X(r) {
P(() => {
r();
import { useEffect as O, useRef as p, useState as _ } from "react";
function S(e) {
O(() => {
e();
}, []);
}
function Z(r) {
P(() => r, []);
function g(e) {
O(() => e, []);
}
const _ = (r) => {
const a = new Date(r);
return isNaN(a.getTime()) ? void 0 : a.getTime() - Date.now();
}, N = (r, a) => {
const m = typeof r != "number", u = m ? _(r) : r;
if (typeof u != "number")
const rr = (e) => {
const l = new Date(e);
return isNaN(l.getTime()) ? void 0 : l.getTime() - Date.now();
}, m = (e, l) => {
const M = typeof e != "number", o = M ? rr(e) : e;
if (typeof o != "number")
return 0;
if (m)
return u;
switch (a) {
if (M)
return o;
switch (l) {
case "ms":
return u;
return o;
case "sec":
return u * 1e3;
return o * 1e3;
case "min":
return u * 6e4;
return o * 6e4;
case "hour":
return u * 36e5;
return o * 36e5;
case "day":
return u * 864e5;
return o * 864e5;
}
}, h = (r) => r / 1e3, $ = (r) => {
const t = r / 1e3 / 60 / 60 / 24, I = t / 365, i = Math.floor(I), f = t % 365, b = Math.floor(f), R = (f - b) * 24, l = Math.floor(R), v = (R - l) * 60, y = Math.floor(v), w = (v - y) * 60, C = Math.round(w);
}, w = (e) => e / 1e3, nr = (e) => {
const I = e / 1e3 / 60 / 60 / 24, a = I / 365, h = Math.floor(a), F = I % 365, T = Math.floor(F), i = (F - T) * 24, b = Math.floor(i), x = (i - b) * 60, C = Math.floor(x), N = (x - C) * 60, R = Math.round(N);
return {
years: i,
days: b,
hours: l,
minutes: y,
seconds: C
years: h,
days: T,
hours: b,
minutes: C,
seconds: R
};
};
function S(r, a) {
let m = r, u = a;
!["number", "string"].includes(typeof r) && !(r instanceof Date) && (m = 0, u = r);
let t = {
start: () => t,
pause: () => t,
reset: () => t,
setStep: () => t,
setTime: () => t,
incTime: () => t,
decTime: () => t
};
function er(e, l) {
let M = e, o = l;
!["number", "string"].includes(typeof e) && !(e instanceof Date) && (M = 0, o = e);
const {
autostart: I,
stopUpdate: i,
stopwatch: f,
speedUpFirstSecond: b,
onPause: R,
onStart: l,
onCancel: v,
onReset: y,
onUpdate: w,
onTimeSet: C,
onEnd: x,
timeUnit: F = "sec",
step: O = 1e3
} = u || {}, o = M(null), d = M(null), Y = M(!0), H = M(O), q = N(m, F), p = M(q), [T, V] = L(p.current), s = M(T), [z, j] = L(!!I), Q = () => {
o.current && (v && v(), U());
}, U = () => {
if (i) {
if (!o.current)
stopUpdate: a,
stopwatch: h,
speedUpFirstSecond: F,
onPause: T,
onStart: i,
onCancel: b,
onReset: x,
onUpdate: C,
onTimeSet: N,
onEnd: R,
timeUnit: d = "sec",
step: $ = 1e3
} = o || {};
let r = {};
const u = p(null), v = p(null), Q = p(!0), V = p($), k = m(M, d), s = p(k), P = p(0), [U, K] = _(s.current), f = p(U), [W, Y] = _(!!I), X = () => (u.current && (b && b(), H()), r), H = () => {
if (a) {
if (!u.current)
return;
j(!1), clearInterval(o.current), o.current = null;
Y(!1), clearInterval(u.current), u.current = null;
return;
}
d.current && (j(!1), o.current && (clearInterval(o.current), o.current = null), clearTimeout(d.current), d.current = null);
v.current && (Y(!1), u.current && (clearInterval(u.current), u.current = null), clearTimeout(v.current), v.current = null);
};
P(() => {
if (Y.current) {
Y.current = !1;
O(() => {
if (Q.current) {
Q.current = !1;
return;
}
!f && T === 0 && (x && x(), U()), w && w(h(T));
}, [T]);
const W = () => {
d.current = setTimeout(() => {
const e = f ? s.current + 1e3 : Math.max(s.current - 1e3, 0);
V(e), s.current = e, e !== 0 && (o.current = setInterval(() => {
V((n) => {
const c = f ? n + 1e3 : Math.max(n - 1e3, 0);
return s.current = c, c;
!h && U === 0 && (R && R(), H()), C && C(w(U));
}, [U]);
const A = () => {
v.current = setTimeout(() => {
const t = h ? f.current + 1e3 : Math.max(f.current - 1e3, 0);
K(t), f.current = t, t !== 0 && (u.current = setInterval(() => {
K((n) => {
const c = h ? n + 1e3 : Math.max(n - 1e3, 0);
return f.current = c, c;
});
}, H.current));
}, b ? 300 : H.current);
}, D = () => {
const e = i ? void 0 : t;
if (o.current)
return e;
if (i) {
l && l(), j(!0), o.current = setTimeout(() => {
x && x(), U();
}, q);
return;
}, V.current));
}, F ? 300 : V.current);
}, j = (t) => {
P.current = Date.now(), u.current && clearTimeout(u.current), u.current = setTimeout(() => {
P.current = 0, R && R(), H();
}, t < 0 ? 0 : t);
}, D = () => u.current ? r : a ? (i && i(), Y(!0), j(k), r) : (v.current || !h && f.current === 0 || (i && i(w(f.current)), Y(!0), A()), r);
S(() => I && D()), g(H);
const q = (t) => {
K(t), f.current = t;
}, z = (t, n) => {
if (a) {
if (!u.current)
return r;
const y = m(t, (n == null ? void 0 : n.timeUnit) || d);
return j(y), s.current = y, r;
}
return d.current || !f && s.current === 0 || (l && l(h(s.current)), j(!0), W()), e;
const c = m(t, (n == null ? void 0 : n.timeUnit) || d);
return N && N(w(c)), s.current = c, q(c), r;
}, B = (t, n) => {
if (a) {
if (!u.current)
return r;
const y = Date.now() - P.current, E = k - y + m(t, (n == null ? void 0 : n.timeUnit) || d);
return j(E), s.current = E, r;
}
const c = f.current + m(t, (n == null ? void 0 : n.timeUnit) || d);
return s.current = c, q(c), r;
}, G = (t, n) => {
if (a) {
if (!u.current)
return r;
const y = Date.now() - P.current, E = k - y - m(t, (n == null ? void 0 : n.timeUnit) || d);
return j(E), s.current = E, r;
}
let c = f.current - m(t, (n == null ? void 0 : n.timeUnit) || d);
return c < 0 && (c = 0), s.current = c, q(c), r;
}, J = () => a ? (u.current && j(s.current), r) : (x && x(w(s.current)), q(s.current), r), L = () => (v.current && (H(), T && T(w(f.current))), r), Z = (t) => {
if (!a)
return V.current === t || (V.current = t, u.current && (L(), D())), r;
};
X(() => I && D()), Z(U);
const E = (e) => {
V(e), s.current = e;
}, A = (e, n) => {
const c = N(e, (n == null ? void 0 : n.timeUnit) || F);
return C && C(h(c)), p.current = c, E(c), t;
}, B = (e, n) => {
const c = s.current + N(e, (n == null ? void 0 : n.timeUnit) || F);
return p.current = c, E(c), t;
}, G = (e, n) => {
let c = s.current - N(e, (n == null ? void 0 : n.timeUnit) || F);
return c < 0 && (c = 0), p.current = c, E(c), t;
}, J = () => (y && y(h(p.current)), E(p.current), t), k = () => (d.current && (U(), R && R(h(s.current))), t), K = (e) => {
if (!i)
return H.current === e || (H.current = e, o.current && (k(), D())), t;
};
return t = {
return r = a ? {
start: D,
pause: k,
reset: J,
setTime: A,
setTime: z,
incTime: B,
decTime: G,
setStep: K
}, i ? {
cancel: X
} : {
start: D,
cancel: Q,
isRunning: z
reset: J,
setTime: z,
incTime: B,
decTime: G,
pause: L,
setStep: Z
}, a ? {
start: D,
cancel: X,
reset: J,
setTime: z,
incTime: B,
decTime: G,
isRunning: W
} : {
start: D,
pause: k,
pause: L,
reset: J,
setTime: A,
setTime: z,
incTime: B,
decTime: G,
setStep: K,
isRunning: z,
currentTime: h(T),
formattedCurrentTime: $(T)
setStep: Z,
isRunning: W,
currentTime: w(U),
formattedCurrentTime: nr(U)
};
}
export {
S as default,
S as useTimer
er as default,
er as useTimer
};
//# sourceMappingURL=index.es.js.map

@@ -1,2 +0,2 @@

(function(a,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],r):(a=typeof globalThis<"u"?globalThis:a||self,r(a["react-hook-time"]={},a.React))})(this,function(a,r){"use strict";function K(n){r.useEffect(()=>{n()},[])}function L(n){r.useEffect(()=>n,[])}const Q=n=>{const f=new Date(n);return isNaN(f.getTime())?void 0:f.getTime()-Date.now()},I=(n,f)=>{const T=typeof n!="number",o=T?Q(n):n;if(typeof o!="number")return 0;if(T)return o;switch(f){case"ms":return o;case"sec":return o*1e3;case"min":return o*6e4;case"hour":return o*36e5;case"day":return o*864e5}},p=n=>n/1e3,W=n=>{const e=n/1e3/60/60/24,w=e/365,l=Math.floor(w),d=e%365,j=Math.floor(d),v=(d-j)*24,m=Math.floor(v),y=(v-m)*60,U=Math.floor(y),C=(y-U)*60,E=Math.round(C);return{years:l,days:j,hours:m,minutes:U,seconds:E}};function _(n,f){let T=n,o=f;!["number","string"].includes(typeof n)&&!(n instanceof Date)&&(T=0,o=n);let e={start:()=>e,pause:()=>e,reset:()=>e,setStep:()=>e,setTime:()=>e,incTime:()=>e,decTime:()=>e};const{autostart:w,stopUpdate:l,stopwatch:d,speedUpFirstSecond:j,onPause:v,onStart:m,onCancel:y,onReset:U,onUpdate:C,onTimeSet:E,onEnd:x,timeUnit:F="sec",step:X=1e3}=o||{},s=r.useRef(null),h=r.useRef(null),q=r.useRef(!0),H=r.useRef(X),O=I(T,F),M=r.useRef(O),[R,P]=r.useState(M.current),i=r.useRef(R),[Y,k]=r.useState(!!w),Z=()=>{s.current&&(y&&y(),b())},b=()=>{if(l){if(!s.current)return;k(!1),clearInterval(s.current),s.current=null;return}h.current&&(k(!1),s.current&&(clearInterval(s.current),s.current=null),clearTimeout(h.current),h.current=null)};r.useEffect(()=>{if(q.current){q.current=!1;return}!d&&R===0&&(x&&x(),b()),C&&C(p(R))},[R]);const $=()=>{h.current=setTimeout(()=>{const t=d?i.current+1e3:Math.max(i.current-1e3,0);P(t),i.current=t,t!==0&&(s.current=setInterval(()=>{P(u=>{const c=d?u+1e3:Math.max(u-1e3,0);return i.current=c,c})},H.current))},j?300:H.current)},D=()=>{const t=l?void 0:e;if(s.current)return t;if(l){m&&m(),k(!0),s.current=setTimeout(()=>{x&&x(),b()},O);return}return h.current||!d&&i.current===0||(m&&m(p(i.current)),k(!0),$()),t};K(()=>w&&D()),L(b);const N=t=>{P(t),i.current=t},z=(t,u)=>{const c=I(t,(u==null?void 0:u.timeUnit)||F);return E&&E(p(c)),M.current=c,N(c),e},A=(t,u)=>{const c=i.current+I(t,(u==null?void 0:u.timeUnit)||F);return M.current=c,N(c),e},B=(t,u)=>{let c=i.current-I(t,(u==null?void 0:u.timeUnit)||F);return c<0&&(c=0),M.current=c,N(c),e},G=()=>(U&&U(p(M.current)),N(M.current),e),V=()=>(h.current&&(b(),v&&v(p(i.current))),e),J=t=>{if(!l)return H.current===t||(H.current=t,s.current&&(V(),D())),e};return e={start:D,pause:V,reset:G,setTime:z,incTime:A,decTime:B,setStep:J},l?{start:D,cancel:Z,isRunning:Y}:{start:D,pause:V,reset:G,setTime:z,incTime:A,decTime:B,setStep:J,isRunning:Y,currentTime:p(R),formattedCurrentTime:W(R)}}a.default=_,a.useTimer=_,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
(function(l,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],c):(l=typeof globalThis<"u"?globalThis:l||self,c(l["react-hook-time"]={},l.React))})(this,function(l,c){"use strict";function $(t){c.useEffect(()=>{t()},[])}function A(t){c.useEffect(()=>t,[])}const S=t=>{const p=new Date(t);return isNaN(p.getTime())?void 0:p.getTime()-Date.now()},d=(t,p)=>{const h=typeof t!="number",s=h?S(t):t;if(typeof s!="number")return 0;if(h)return s;switch(p){case"ms":return s;case"sec":return s*1e3;case"min":return s*6e4;case"hour":return s*36e5;case"day":return s*864e5}},M=t=>t/1e3,g=t=>{const w=t/1e3/60/60/24,a=w/365,v=Math.floor(a),F=w%365,I=Math.floor(F),m=(F-I)*24,j=Math.floor(m),E=(m-j)*60,x=Math.floor(E),N=(E-x)*60,y=Math.round(N);return{years:v,days:I,hours:j,minutes:x,seconds:y}};function L(t,p){let h=t,s=p;!["number","string"].includes(typeof t)&&!(t instanceof Date)&&(h=0,s=t);const{autostart:w,stopUpdate:a,stopwatch:v,speedUpFirstSecond:F,onPause:I,onStart:m,onCancel:j,onReset:E,onUpdate:x,onTimeSet:N,onEnd:y,timeUnit:R="sec",step:rr=1e3}=s||{};let r={};const u=c.useRef(null),T=c.useRef(null),Q=c.useRef(!0),P=c.useRef(rr),V=d(h,R),f=c.useRef(V),_=c.useRef(0),[U,J]=c.useState(f.current),i=c.useRef(U),[W,q]=c.useState(!!w),X=()=>(u.current&&(j&&j(),C()),r),C=()=>{if(a){if(!u.current)return;q(!1),clearInterval(u.current),u.current=null;return}T.current&&(q(!1),u.current&&(clearInterval(u.current),u.current=null),clearTimeout(T.current),T.current=null)};c.useEffect(()=>{if(Q.current){Q.current=!1;return}!v&&U===0&&(y&&y(),C()),x&&x(M(U))},[U]);const er=()=>{T.current=setTimeout(()=>{const n=v?i.current+1e3:Math.max(i.current-1e3,0);J(n),i.current=n,n!==0&&(u.current=setInterval(()=>{J(e=>{const o=v?e+1e3:Math.max(e-1e3,0);return i.current=o,o})},P.current))},F?300:P.current)},H=n=>{_.current=Date.now(),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{_.current=0,y&&y(),C()},n<0?0:n)},D=()=>u.current?r:a?(m&&m(),q(!0),H(V),r):(T.current||!v&&i.current===0||(m&&m(M(i.current)),q(!0),er()),r);$(()=>w&&D()),A(C);const O=n=>{J(n),i.current=n},Y=(n,e)=>{if(a){if(!u.current)return r;const b=d(n,(e==null?void 0:e.timeUnit)||R);return H(b),f.current=b,r}const o=d(n,(e==null?void 0:e.timeUnit)||R);return N&&N(M(o)),f.current=o,O(o),r},z=(n,e)=>{if(a){if(!u.current)return r;const b=Date.now()-_.current,k=V-b+d(n,(e==null?void 0:e.timeUnit)||R);return H(k),f.current=k,r}const o=i.current+d(n,(e==null?void 0:e.timeUnit)||R);return f.current=o,O(o),r},B=(n,e)=>{if(a){if(!u.current)return r;const b=Date.now()-_.current,k=V-b-d(n,(e==null?void 0:e.timeUnit)||R);return H(k),f.current=k,r}let o=i.current-d(n,(e==null?void 0:e.timeUnit)||R);return o<0&&(o=0),f.current=o,O(o),r},G=()=>a?(u.current&&H(f.current),r):(E&&E(M(f.current)),O(f.current),r),K=()=>(T.current&&(C(),I&&I(M(i.current))),r),Z=n=>{if(!a)return P.current===n||(P.current=n,u.current&&(K(),D())),r};return r=a?{start:D,reset:G,setTime:Y,incTime:z,decTime:B,cancel:X}:{start:D,reset:G,setTime:Y,incTime:z,decTime:B,pause:K,setStep:Z},a?{start:D,cancel:X,reset:G,setTime:Y,incTime:z,decTime:B,isRunning:W}:{start:D,pause:K,reset:G,setTime:Y,incTime:z,decTime:B,setStep:Z,isRunning:W,currentTime:M(U),formattedCurrentTime:g(U)}}l.default=L,l.useTimer=L,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
//# sourceMappingURL=index.umd.js.map

@@ -55,17 +55,31 @@ export interface ITimeObject {

}
export interface IChainingFunctions {
start: () => IChainingFunctions;
pause: () => IChainingFunctions;
reset: () => IChainingFunctions;
setStep: (newStep: number) => IChainingFunctions;
export interface IChainingFunctionsWithUpdate {
start: () => IChainingFunctionsWithUpdate;
reset: () => IChainingFunctionsWithUpdate;
setTime: (newTime: TTimerInitialTime, setTimeSettings?: {
timeUnit?: TTimeUnit;
}) => IChainingFunctions;
}) => IChainingFunctionsWithUpdate;
incTime: (timeAmount: TTimerInitialTime, setTimeSettings?: {
timeUnit?: TTimeUnit;
}) => IChainingFunctions;
}) => IChainingFunctionsWithUpdate;
decTime: (timeAmount: TTimerInitialTime, setTimeSettings?: {
timeUnit?: TTimeUnit;
}) => IChainingFunctions;
}) => IChainingFunctionsWithUpdate;
setStep: (newStep: number) => IChainingFunctionsWithUpdate;
pause: () => IChainingFunctionsWithUpdate;
}
export interface IChainingFunctionsWithoutUpdate {
start: () => IChainingFunctionsWithoutUpdate;
reset: () => IChainingFunctionsWithoutUpdate;
setTime: (newTime: TTimerInitialTime, setTimeSettings?: {
timeUnit?: TTimeUnit;
}) => IChainingFunctionsWithoutUpdate;
incTime: (timeAmount: TTimerInitialTime, setTimeSettings?: {
timeUnit?: TTimeUnit;
}) => IChainingFunctionsWithoutUpdate;
decTime: (timeAmount: TTimerInitialTime, setTimeSettings?: {
timeUnit?: TTimeUnit;
}) => IChainingFunctionsWithoutUpdate;
cancel: () => IChainingFunctionsWithoutUpdate;
}
export interface ITimerResultWithUpdate {

@@ -75,3 +89,3 @@ start: () => ITimerResultWithUpdate;

reset: () => ITimerResultWithUpdate;
setStep: (newStep: number) => IChainingFunctions;
setStep: (newStep: number) => IChainingFunctionsWithUpdate;
setTime: (newTime: TTimerInitialTime, setTimeSettings?: {

@@ -91,5 +105,15 @@ timeUnit?: TTimeUnit;

export interface ITimerResultWithoutUpdate {
start: () => IChainingFunctions;
cancel: () => void;
start: () => ITimerResultWithoutUpdate;
cancel: () => ITimerResultWithoutUpdate;
reset: () => ITimerResultWithoutUpdate;
setTime: (newTime: TTimerInitialTime, setTimeSettings?: {
timeUnit?: TTimeUnit;
}) => ITimerResultWithoutUpdate;
isRunning: boolean;
incTime: (timeAmount: TTimerInitialTime, setTimeSettings?: {
timeUnit?: TTimeUnit;
}) => ITimerResultWithoutUpdate;
decTime: (timeAmount: TTimerInitialTime, setTimeSettings?: {
timeUnit?: TTimeUnit;
}) => ITimerResultWithoutUpdate;
}
{
"name": "react-hook-time",
"version": "1.0.6",
"version": "1.0.7",
"type": "module",

@@ -5,0 +5,0 @@ "description": "A React timer library",

@@ -72,3 +72,3 @@ ![react-hook-time](https://github.com/dancheskus/react-hook-time/assets/35524994/ec15bc66-8213-4f80-9b74-c30ac41f3673)

**stopUpdate** - with this prop most of the callbacks are not working. Only `onStart`, `onEnd` and `onCancel` are available
**stopUpdate** - with this prop most of the callbacks are not working. Only `onStart`, `onEnd` and `onCancel` are available. `currentTime` is not available as well.

@@ -75,0 +75,0 @@ **stopwatch** - with this prop `onEnd` callback is disabled

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc