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 2.0.0 to 2.0.1

2

lib/index.js

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

module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var u=t[n]={i:n,l:!1,exports:{}};return e[n].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var u in e)r.d(n,u,function(t){return e[t]}.bind(null,u));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(e,t){e.exports=require("react")},function(e,t,r){"use strict";r.r(t),r.d(t,"useElapsedTime",(function(){return i}));var n=r(0);function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,u=!1,o=void 0;try{for(var i,c=e[Symbol.iterator]();!(n=(i=c.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){u=!0,o=e}finally{try{n||null==c.return||c.return()}finally{if(u)throw o}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var i=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.duration,o=t.onComplete,i=t.startAt,c=void 0===i?0:i,a=t.shouldResetOnDurationChange,f=void 0!==a&&a,l=Object(n.useState)(c),s=u(l,2),d=s[0],m=s[1],b=Object(n.useRef)(-1e3*c),y=Object(n.useRef)(null),p=Object(n.useRef)(null),v=Object(n.useRef)(null),j=Object(n.useRef)(!0),O=Object(n.useCallback)((function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:c;m(e)}),[c]),g=function e(t){var n=t/1e3;if(null===p.current)return p.current=n,void(y.current=requestAnimationFrame(e));m((function(t){var u=t+(n-p.current);if("number"!=typeof r||u<r)return p.current=n,y.current=requestAnimationFrame(e),u;if("function"==typeof o){b.current+=1e3*r;var i=b.current/1e3,c=o(i)||{},a=c.shouldRepeat,f=void 0!==a&&a,l=c.delay,s=void 0===l?0:l,d=c.newStartAt;f&&(v.current=setTimeout((function(){O(d),p.current=null,y.current=requestAnimationFrame(e)}),1e3*s))}return r}))},h=function(){cancelAnimationFrame(y.current),clearTimeout(v.current),p.current=null};return Object(n.useLayoutEffect)((function(){return e&&(y.current=requestAnimationFrame(g)),h}),[e]),Object(n.useLayoutEffect)((function(){j.current?j.current=!1:(e&&(h(),y.current=requestAnimationFrame(g)),f&&O())}),[r]),{elapsedTime:d,reset:O}}}]);
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var u=t[n]={i:n,l:!1,exports:{}};return e[n].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var u in e)r.d(n,u,function(t){return e[t]}.bind(null,u));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(e,t){e.exports=require("react")},function(e,t,r){"use strict";r.r(t),r.d(t,"useElapsedTime",(function(){return i}));var n=r(0);function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,u=!1,o=void 0;try{for(var i,c=e[Symbol.iterator]();!(n=(i=c.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){u=!0,o=e}finally{try{n||null==c.return||c.return()}finally{if(u)throw o}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var i=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.duration,o=t.onComplete,i=t.startAt,c=void 0===i?0:i,a=t.shouldResetOnDurationChange,f=void 0!==a&&a,l=Object(n.useState)(c),s=u(l,2),d=s[0],b=s[1],m=Object(n.useRef)(-1e3*c),y=Object(n.useRef)(null),p=Object(n.useRef)(null),v=Object(n.useRef)(null),j=Object(n.useRef)(!0),O=Object(n.useRef)(!1),g=Object(n.useRef)(0),h=Object(n.useCallback)((function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:c;g.current+=1,b(e)}),[]),A=function e(t){var n=t/1e3;if(null===p.current)return p.current=n,void(y.current=requestAnimationFrame(e));b((function(t){var u=t+(n-p.current);if("number"!=typeof r||u<r)return p.current=n,y.current=requestAnimationFrame(e),u;if(O.current=!0,"function"==typeof o){m.current+=1e3*r;var i=m.current/1e3,c=o(i)||{},a=c.shouldRepeat,f=void 0!==a&&a,l=c.delay,s=void 0===l?0:l,d=c.newStartAt;f&&(v.current=setTimeout((function(){h(d)}),1e3*s))}return r}))},S=function(){cancelAnimationFrame(y.current),clearTimeout(v.current),p.current=null};return Object(n.useLayoutEffect)((function(){return e&&(y.current=requestAnimationFrame(A)),S}),[e]),Object(n.useLayoutEffect)((function(){j.current?j.current=!1:(e&&(S(),y.current=requestAnimationFrame(A)),f&&h())}),[r]),Object(n.useLayoutEffect)((function(){e&&O.current&&(O.current=!1,S(),y.current=requestAnimationFrame(A))}),[g.current]),{elapsedTime:d,reset:h}}}]);
{
"name": "use-elapsed-time",
"version": "2.0.0",
"version": "2.0.1",
"description": "React hook to measure elapsed time using requestAnimationFrame",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

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