Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-elapsed-time

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-elapsed-time - npm Package Compare versions

Comparing version 3.0.1 to 3.0.2

6

CHANGELOG.md
# Change Log
## 3.0.2 ( September 5th, 2021)
**Big fix:**
- Check if the value passed to `reset` is a number
## 3.0.1 ( June 20th, 2021)

@@ -4,0 +10,0 @@

2

lib/index.js

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

var P=Object.create;var l=Object.defineProperty,j=Object.defineProperties,z=Object.getOwnPropertyDescriptor,G=Object.getOwnPropertyDescriptors,H=Object.getOwnPropertyNames,B=Object.getOwnPropertySymbols,K=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var O=(e,r,t)=>r in e?l(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,T=(e,r)=>{for(var t in r||(r={}))M.call(r,t)&&O(e,t,r[t]);if(B)for(var t of B(r))Q.call(r,t)&&O(e,t,r[t]);return e},R=(e,r)=>j(e,G(r)),V=e=>l(e,"__esModule",{value:!0});var W=(e,r)=>{V(e);for(var t in r)l(e,t,{get:r[t],enumerable:!0})},X=(e,r,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let u of H(r))!M.call(e,u)&&u!=="default"&&l(e,u,{get:()=>r[u],enumerable:!(t=z(r,u))||t.enumerable});return e},C=e=>X(V(l(e!=null?P(K(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);W(exports,{useElapsedTime:()=>k});var n=C(require("react"));var b=C(require("react")),A=typeof window=="undefined"?b.useEffect:b.useLayoutEffect;var k=({isPlaying:e,duration:r,startAt:t=0,updateInterval:u=0,onComplete:E,onUpdate:y})=>{let[f,I]=(0,n.useState)(t),h=(0,n.useRef)(t*-1e3),s=(0,n.useRef)(null),m=(0,n.useRef)(null),v=(0,n.useRef)(null),o=(0,n.useRef)({elapsedTimeRef:0,startAtRef:t,durationRef:r,updateIntervalRef:u});o.current=R(T({},o.current),{durationRef:r,updateIntervalRef:u});let p=c=>{let a=c/1e3;if(m.current===null){m.current=a,s.current=requestAnimationFrame(p);return}let{durationRef:i,elapsedTimeRef:D,updateIntervalRef:x,startAtRef:S}=o.current,J=a-m.current,d=D+J;m.current=a,o.current=R(T({},o.current),{elapsedTimeRef:d});let L=S+(x===0?d:(d/x|0)*x),N=S+d,w=typeof i=="number"&&N>=i;I(w?i:L),w||(s.current=requestAnimationFrame(p))},q=()=>{s.current&&cancelAnimationFrame(s.current),v.current&&clearTimeout(v.current),m.current=null},F=(0,n.useCallback)((c=t)=>{q(),o.current=R(T({},o.current),{elapsedTimeRef:0,startAtRef:c}),I(c),e&&(s.current=requestAnimationFrame(p))},[e,t]);return A(()=>{if(y==null||y(f),r&&f>=r){h.current+=r*1e3;let{shouldRepeat:c=!1,delay:a=0,newStartAt:i}=(E==null?void 0:E(h.current/1e3))||{};c&&(v.current=setTimeout(()=>F(i),a*1e3))}},[f,r]),A(()=>(e&&(s.current=requestAnimationFrame(p)),q),[e]),{elapsedTime:f,reset:F}};
var P=Object.create;var l=Object.defineProperty,j=Object.defineProperties,z=Object.getOwnPropertyDescriptor,G=Object.getOwnPropertyDescriptors,H=Object.getOwnPropertyNames,B=Object.getOwnPropertySymbols,K=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var V=(e,r,t)=>r in e?l(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,T=(e,r)=>{for(var t in r||(r={}))M.call(r,t)&&V(e,t,r[t]);if(B)for(var t of B(r))Q.call(r,t)&&V(e,t,r[t]);return e},R=(e,r)=>j(e,G(r)),O=e=>l(e,"__esModule",{value:!0});var W=(e,r)=>{O(e);for(var t in r)l(e,t,{get:r[t],enumerable:!0})},X=(e,r,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let u of H(r))!M.call(e,u)&&u!=="default"&&l(e,u,{get:()=>r[u],enumerable:!(t=z(r,u))||t.enumerable});return e},C=e=>X(O(l(e!=null?P(K(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);W(exports,{useElapsedTime:()=>k});var n=C(require("react"));var b=C(require("react")),x=typeof window=="undefined"?b.useEffect:b.useLayoutEffect;var k=({isPlaying:e,duration:r,startAt:t=0,updateInterval:u=0,onComplete:E,onUpdate:y})=>{let[f,I]=(0,n.useState)(t),S=(0,n.useRef)(t*-1e3),c=(0,n.useRef)(null),m=(0,n.useRef)(null),A=(0,n.useRef)(null),s=(0,n.useRef)({elapsedTimeRef:0,startAtRef:t,durationRef:r,updateIntervalRef:u});s.current=R(T({},s.current),{durationRef:r,updateIntervalRef:u});let p=a=>{let o=a/1e3;if(m.current===null){m.current=o,c.current=requestAnimationFrame(p);return}let{durationRef:i,elapsedTimeRef:D,updateIntervalRef:v,startAtRef:w}=s.current,J=o-m.current,d=D+J;m.current=o,s.current=R(T({},s.current),{elapsedTimeRef:d});let L=w+(v===0?d:(d/v|0)*v),N=w+d,F=typeof i=="number"&&N>=i;I(F?i:L),F||(c.current=requestAnimationFrame(p))},h=()=>{c.current&&cancelAnimationFrame(c.current),A.current&&clearTimeout(A.current),m.current=null},q=(0,n.useCallback)(a=>{let o=typeof a=="number"?a:t;h(),s.current=R(T({},s.current),{elapsedTimeRef:0,startAtRef:o}),I(o),e&&(c.current=requestAnimationFrame(p))},[e,t]);return x(()=>{if(y==null||y(f),r&&f>=r){S.current+=r*1e3;let{shouldRepeat:a=!1,delay:o=0,newStartAt:i}=(E==null?void 0:E(S.current/1e3))||{};a&&(A.current=setTimeout(()=>q(i),o*1e3))}},[f,r]),x(()=>(e&&(c.current=requestAnimationFrame(p)),h),[e]),{elapsedTime:f,reset:q}};

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

var C=Object.defineProperty,k=Object.defineProperties;var D=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var w=(t,e,r)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,p=(t,e)=>{for(var r in e||(e={}))J.call(e,r)&&w(t,r,e[r]);if(S)for(var r of S(e))L.call(e,r)&&w(t,r,e[r]);return t},d=(t,e)=>k(t,D(e));import{useState as j,useRef as a,useCallback as z}from"react";import{useEffect as N,useLayoutEffect as P}from"react";var y=typeof window=="undefined"?N:P;var G=({isPlaying:t,duration:e,startAt:r=0,updateInterval:v=0,onComplete:T,onUpdate:R})=>{let[i,x]=j(r),A=a(r*-1e3),u=a(null),s=a(null),b=a(null),n=a({elapsedTimeRef:0,startAtRef:r,durationRef:e,updateIntervalRef:v});n.current=d(p({},n.current),{durationRef:e,updateIntervalRef:v});let l=o=>{let c=o/1e3;if(s.current===null){s.current=c,u.current=requestAnimationFrame(l);return}let{durationRef:m,elapsedTimeRef:B,updateIntervalRef:E,startAtRef:q}=n.current,M=c-s.current,f=B+M;s.current=c,n.current=d(p({},n.current),{elapsedTimeRef:f});let O=q+(E===0?f:(f/E|0)*E),V=q+f,F=typeof m=="number"&&V>=m;x(F?m:O),F||(u.current=requestAnimationFrame(l))},I=()=>{u.current&&cancelAnimationFrame(u.current),b.current&&clearTimeout(b.current),s.current=null},h=z((o=r)=>{I(),n.current=d(p({},n.current),{elapsedTimeRef:0,startAtRef:o}),x(o),t&&(u.current=requestAnimationFrame(l))},[t,r]);return y(()=>{if(R==null||R(i),e&&i>=e){A.current+=e*1e3;let{shouldRepeat:o=!1,delay:c=0,newStartAt:m}=(T==null?void 0:T(A.current/1e3))||{};o&&(b.current=setTimeout(()=>h(m),c*1e3))}},[i,e]),y(()=>(t&&(u.current=requestAnimationFrame(l)),I),[t]),{elapsedTime:i,reset:h}};export{G as useElapsedTime};
var C=Object.defineProperty,k=Object.defineProperties;var D=Object.getOwnPropertyDescriptors;var w=Object.getOwnPropertySymbols;var J=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable;var F=(t,e,r)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,p=(t,e)=>{for(var r in e||(e={}))J.call(e,r)&&F(t,r,e[r]);if(w)for(var r of w(e))L.call(e,r)&&F(t,r,e[r]);return t},d=(t,e)=>k(t,D(e));import{useState as j,useRef as m,useCallback as z}from"react";import{useEffect as N,useLayoutEffect as P}from"react";var y=typeof window=="undefined"?N:P;var G=({isPlaying:t,duration:e,startAt:r=0,updateInterval:A=0,onComplete:T,onUpdate:R})=>{let[i,v]=j(r),x=m(r*-1e3),o=m(null),c=m(null),b=m(null),u=m({elapsedTimeRef:0,startAtRef:r,durationRef:e,updateIntervalRef:A});u.current=d(p({},u.current),{durationRef:e,updateIntervalRef:A});let l=s=>{let n=s/1e3;if(c.current===null){c.current=n,o.current=requestAnimationFrame(l);return}let{durationRef:a,elapsedTimeRef:B,updateIntervalRef:E,startAtRef:h}=u.current,M=n-c.current,f=B+M;c.current=n,u.current=d(p({},u.current),{elapsedTimeRef:f});let V=h+(E===0?f:(f/E|0)*E),O=h+f,q=typeof a=="number"&&O>=a;v(q?a:V),q||(o.current=requestAnimationFrame(l))},I=()=>{o.current&&cancelAnimationFrame(o.current),b.current&&clearTimeout(b.current),c.current=null},S=z(s=>{let n=typeof s=="number"?s:r;I(),u.current=d(p({},u.current),{elapsedTimeRef:0,startAtRef:n}),v(n),t&&(o.current=requestAnimationFrame(l))},[t,r]);return y(()=>{if(R==null||R(i),e&&i>=e){x.current+=e*1e3;let{shouldRepeat:s=!1,delay:n=0,newStartAt:a}=(T==null?void 0:T(x.current/1e3))||{};s&&(b.current=setTimeout(()=>S(a),n*1e3))}},[i,e]),y(()=>(t&&(o.current=requestAnimationFrame(l)),I),[t]),{elapsedTime:i,reset:S}};export{G as useElapsedTime};
{
"name": "use-elapsed-time",
"version": "3.0.1",
"version": "3.0.2",
"description": "React hook to measure elapsed time using requestAnimationFrame",

@@ -42,13 +42,13 @@ "main": "./lib/index.js",

"devDependencies": {
"@testing-library/react-hooks": "7.0.0",
"@types/jest": "26.0.23",
"codecov": "3.8.2",
"esbuild": "0.12.9",
"jest": "27.0.4",
"prettier": "2.3.1",
"@testing-library/react-hooks": "7.0.2",
"@types/jest": "26.0.24",
"codecov": "3.8.3",
"esbuild": "0.12.24",
"jest": "27.1.0",
"prettier": "2.3.2",
"react": "17.0.2",
"react-dom": "17.0.2",
"ts-jest": "27.0.3",
"typescript": "4.3.2"
"ts-jest": "27.0.5",
"typescript": "4.4.2"
}
}
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