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 1.1.4 to 1.1.5

6

CHANGELOG.md
# Change Log
## 1.1.5 (December 22nd, 2019)
**Implemented enhancements:**
- Refactor internals
- Add test coverage
## 1.1.4 (December 19th, 2019)

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

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 o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.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 o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));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 u}));var n=r(0);function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var r=[],n=!0,o=!1,u=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){o=!0,u=e}finally{try{n||null==c.return||c.return()}finally{if(o)throw u}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var u=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.durationMilliseconds,u=t.onComplete,i=t.startAt,c=Object(n.useState)(i||0),a=o(c,2),f=a[0],l=a[1],s=Object(n.useRef)(),d=Object(n.useRef)(),v=function e(t){var n=!1;if(void 0!==d.current){var i=t-d.current;l((function(e){var t=e+i;return(n=t>=r)?r:t}))}if(n){if("function"==typeof u){var c=o(u()||[],2),a=c[0],f=void 0!==a&&a,v=c[1];f&&setTimeout((function(){l(0),d.current=void 0,s.current=requestAnimationFrame(e)}),void 0===v?0:v)}}else d.current=t,s.current=requestAnimationFrame(e)};return Object(n.useLayoutEffect)((function(){return e&&(s.current=requestAnimationFrame(v)),function(){cancelAnimationFrame(s.current),d.current=void 0,s.current=void 0}}),[e]),f}}]);
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 o}));var n=r(0);function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(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(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var o=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.durationMilliseconds,o=t.onComplete,i=t.startAt,c="number"==typeof r,l=Object(n.useState)(i||0),a=u(l,2),f=a[0],s=a[1],d=Object(n.useRef)(null),p=Object(n.useRef)(null),m=function e(t){if(null===p.current)return p.current=t,void(d.current=requestAnimationFrame(e));s((function(n){var i=n+(t-p.current);if(!c||i<r)return p.current=t,d.current=requestAnimationFrame(e),i;if("function"==typeof o){var l=u(o()||[],2),a=l[0],f=void 0!==a&&a,m=l[1];f&&setTimeout((function(){s(0),p.current=null,d.current=requestAnimationFrame(e)}),void 0===m?0:m)}return r}))};return Object(n.useLayoutEffect)((function(){return e&&(d.current=requestAnimationFrame(m)),function(){cancelAnimationFrame(d.current),p.current=null,d.current=null}}),[e]),f}}]);
{
"name": "use-elapsed-time",
"version": "1.1.4",
"version": "1.1.5",
"description": "React hook to get the elapsed time in an animation using requestAnimationFrame",

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

"build": "webpack",
"prepare": "install-peers"
"prepare": "install-peers",
"test": "jest --config jestconfig.json",
"test-watch": "jest --watch"
},

@@ -39,7 +41,13 @@ "repository": {

"@babel/core": "^7.5.5",
"@babel/plugin-transform-modules-commonjs": "^7.7.5",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"@testing-library/react-hooks": "^3.2.1",
"babel-loader": "^8.0.6",
"codecov": "^3.6.1",
"install-peers-cli": "^2.1.1",
"jest": "^24.9.0",
"path": "^0.12.7",
"raf-stub": "^3.0.0",
"react-test-renderer": "16.8.0",
"webpack": "^4.41.4",

@@ -46,0 +54,0 @@ "webpack-cli": "^3.3.10"

# useElapsedTime React hook
![npm bundle size](https://img.shields.io/bundlephobia/min/use-elapsed-time)
![Codecov](https://img.shields.io/codecov/c/github/vydimitrov/use-elapsed-time)
![npm](https://img.shields.io/npm/v/use-elapsed-time)
The only hook you need to perform JavaScript animations in React.
* Lightweight: only 2.4kB min / 1.1kB min+gzip
* Built with 0 dependencies
* Toggle play/pause

@@ -37,2 +39,3 @@ * Combine with [any easing function](http://www.gizma.com/easing/#l) to get the right animation

config?: {
startAt: number,
durationMilliseconds: number,

@@ -45,3 +48,3 @@ onComplete?: () => undefined | [shouldRepeat: boolean, delay: number]

The first argument `isPlaying` indicates if the loop to get the elapsed time is running or it is paused.
The second argument `config` is optional and it makes sense when the animation duration `durationMilliseconds` is defined. `onComplete` callback will be fired when the duration is reached. `onComplete` can be used to restart the elapsed time loop by returning an array where the first element `shouldRepeat` indicates if the loop should start over and second element `delay` specifies the delay before looping again in milliseconds.
The second argument `config` is optional. `durationMilliseconds` option set the animation duration in milliseconds. `onComplete` callback will be fired when the duration is reached. `onComplete` can be used to restart the elapsed time loop by returning an array where the first element `shouldRepeat` indicates if the loop should start over and second element `delay` specifies the delay before looping again in milliseconds. `startAt` option can shift the start time to a different value than 0. `{ durationMilliseconds: 5000, startAt: 2000 }` will return the elapsed time from 2000 to 5000 milliseconds.

@@ -48,0 +51,0 @@ The hook returns elapsed time in milliseconds.

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