You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-timer-hook

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-timer-hook - npm Package Compare versions

Comparing version

to
2.0.0

.eslintrc

2

dist/index.js

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports["react-timer-hook"]=t(require("react")):e["react-timer-hook"]=t(e.react)}(window,function(e){return 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(t,r){t.exports=e},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.useTime=t.useStopwatch=t.useTimer=void 0;var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e};t.default=function(e){if((0,u.useEffect)(function(){console.warn("react-timer-hook: default export useTimer is deprecated, use named exports { useTimer, useStopwatch, useTime } instead")},[]),e.expiryTimestamp){var t=(0,o.default)(e);return n({},t,{startTimer:t.start,stopTimer:t.pause,resetTimer:function(){}})}var r=(0,a.default)(e);return n({},r,{startTimer:r.start,stopTimer:r.pause,resetTimer:r.reset})};var u=r(0),o=c(r(2)),a=c(r(3)),i=c(r(4));function c(e){return e&&e.__esModule?e:{default:e}}t.useTimer=o.default,t.useStopwatch=a.default,t.useTime=i.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],n=!0,u=!1,o=void 0;try{for(var a,i=e[Symbol.iterator]();!(n=(a=i.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){u=!0,o=e}finally{try{!n&&i.return&&i.return()}finally{if(u)throw o}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.default=function(e){var t=e||{},r=t.expiryTimestamp,o=t.onExpire,a=(0,u.useState)(r),i=n(a,2),c=i[0],f=i[1],s=(0,u.useState)(0),l=n(s,2),d=l[0],v=l[1];var p=(0,u.useState)(0),m=n(p,2),y=m[0],h=m[1];var b=(0,u.useState)(0),S=n(b,2),T=S[0],w=S[1];var x=(0,u.useState)(0),j=n(x,2),g=j[0],O=j[1];var _=(0,u.useRef)();function I(){E(c)&&!_.current&&(P(),_.current=setInterval(function(){return P()},1e3))}function M(){_.current&&(clearInterval(_.current),_.current=void 0),v(0),h(0),w(0),O(0)}function P(){var e=(new Date).getTime(),t=c-e,r=Math.floor(t/864e5),n=Math.floor(t%864e5/36e5),u=Math.floor(t%36e5/6e4),a=Math.floor(t%6e4/1e3);a<0?(M(),A(o)&&o()):(v(a),h(u),w(n),O(r))}function E(e){var t=new Date(e).getTime()>0;return t||console.warn("react-timer-hook: { useTimer } Invalid expiryTimestamp settings",e),t}function A(e){var t=e&&"function"==typeof e;return e&&!t&&console.warn("react-timer-hook: { useTimer } Invalid onExpire settings function",e),t}return(0,u.useEffect)(function(){return I(),M},[c]),{seconds:d,minutes:y,hours:T,days:g,start:I,pause:function(){_.current&&(clearInterval(_.current),_.current=void 0)},resume:function(){E(c)&&!_.current&&(_.current=setInterval(function(){v(function(e){return 0===e?(h(function(e){return 0===e?(w(function(e){return 0===e?(O(function(e){return e>0?e-1:(M(),A(o)&&o(),0)}),23):e>0?e-1:0}),59):e>0?e-1:0}),59):e>0?e-1:0})},1e3))},restart:function(e){M(),f(e)}}};var u=r(0)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],n=!0,u=!1,o=void 0;try{for(var a,i=e[Symbol.iterator]();!(n=(a=i.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){u=!0,o=e}finally{try{!n&&i.return&&i.return()}finally{if(u)throw o}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.default=function(e){var t=(e||{}).autoStart,r=(0,u.useState)(0),o=n(r,2),a=o[0],i=o[1];function c(){i(function(e){return 59===e?(d(function(e){return 59===e?(y(function(e){return 23===e?(T(function(e){return e+1}),0):e+1}),0):e+1}),0):e+1})}var f=(0,u.useState)(0),s=n(f,2),l=s[0],d=s[1];var v=(0,u.useState)(0),p=n(v,2),m=p[0],y=p[1];var h=(0,u.useState)(0),b=n(h,2),S=b[0],T=b[1];var w=(0,u.useRef)();function x(){w.current||(w.current=setInterval(function(){return c()},1e3))}function j(){w.current&&(clearInterval(w.current),w.current=void 0),i(0),d(0),y(0),T(0)}return(0,u.useEffect)(function(){return t&&x(),j},[]),{seconds:a,minutes:l,hours:m,days:S,start:x,pause:function(){w.current&&(clearInterval(w.current),w.current=void 0)},reset:j}};var u=r(0)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],n=!0,u=!1,o=void 0;try{for(var a,i=e[Symbol.iterator]();!(n=(a=i.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){u=!0,o=e}finally{try{!n&&i.return&&i.return()}finally{if(u)throw o}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.default=function(e){var t=(e||{}).format,r=(0,u.useState)(0),o=n(r,2),a=o[0],i=o[1],c=(0,u.useState)(0),f=n(c,2),s=f[0],l=f[1],d=(0,u.useState)(0),v=n(d,2),p=v[0],m=v[1],y=(0,u.useState)(""),h=n(y,2),b=h[0],S=h[1],T=(0,u.useRef)();function w(){T.current&&(clearInterval(T.current),T.current=void 0),i(0),l(0),m(0),S("")}function x(){var e=new Date,r=e.getSeconds(),n=e.getMinutes(),u=function(e){if("12-hour"===t){var r=e>=12?"pm":"am",n=e%12;return{hours:n=n||12,ampm:r}}return{hours:e,ampm:""}}(e.getHours()),o=u.hours,a=u.ampm;i(r),l(n),m(o),S(a)}return(0,u.useEffect)(function(){return T.current||(x(),T.current=setInterval(function(){return x()},1e3)),w},[]),{seconds:a,minutes:s,hours:p,ampm:b}};var u=r(0)}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports["react-timer-hook"]=t(require("react")):e["react-timer-hook"]=t(e.react)}(window,function(e){return 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=2)}([function(t,r){t.exports=e},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Validate=t.Time=void 0;var n=u(r(4)),o=u(r(5));function u(e){return e&&e.__esModule?e:{default:e}}t.Time=n.default,t.Validate=o.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.useTime=t.useStopwatch=t.useTimer=void 0;var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e};t.default=function(e){if((0,o.useEffect)(function(){console.warn("react-timer-hook: default export useTimer is deprecated, use named exports { useTimer, useStopwatch, useTime } instead")},[]),e.expiryTimestamp){var t=(0,u.default)(e);return n({},t,{startTimer:t.start,stopTimer:t.pause,resetTimer:function(){}})}var r=(0,i.default)(e);return n({},r,{startTimer:r.start,stopTimer:r.pause,resetTimer:r.reset})};var o=r(0),u=c(r(3)),i=c(r(6)),a=c(r(7));function c(e){return e&&e.__esModule?e:{default:e}}t.useTimer=u.default,t.useStopwatch=i.default,t.useTime=a.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],n=!0,o=!1,u=void 0;try{for(var i,a=e[Symbol.iterator]();!(n=(i=a.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,u=e}finally{try{!n&&a.return&&a.return()}finally{if(o)throw u}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.default=function(e){var t=e||{},r=t.expiryTimestamp,a=t.onExpire,c=(0,u.useState)(r),f=o(c,2),s=f[0],l=f[1],d=(0,u.useState)(i.Time.getSecondsFromExpiry(s)),m=o(d,2),v=m[0],p=m[1],y=(0,u.useRef)();function b(){y.current&&(clearInterval(y.current),y.current=void 0)}function T(){b(),i.Validate.onExpire(a)&&a()}function h(){y.current||(y.current=setInterval(function(){var e=i.Time.getSecondsFromExpiry(s);e<=0&&T(),p(e)},1e3))}return(0,u.useEffect)(function(){return i.Validate.expiryTimestamp(s)&&(p(i.Time.getSecondsFromExpiry(s)),h()),b},[s]),n({},i.Time.getTimeFromSeconds(v),{start:h,pause:function(){b()},resume:function(){y.current||(y.current=setInterval(function(){return p(function(e){var t=e-1;return t<=0&&T(),t})},1e3))},restart:function(e){b(),l(e)}})};var u=r(0),i=r(1)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();var o=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return n(e,null,[{key:"getTimeFromSeconds",value:function(e){var t=Math.floor(e/86400),r=Math.floor(e%86400/3600),n=Math.floor(e%3600/60);return{seconds:Math.floor(e%60),minutes:n,hours:r,days:t}}},{key:"getSecondsFromExpiry",value:function(e){var t=e-(new Date).getTime();return t>0?Math.floor(t/1e3):0}},{key:"getSecondsFromTimeNow",value:function(){var e=new Date;return e.getTime()/1e3-60*e.getTimezoneOffset()}},{key:"getFormattedTimeFromSeconds",value:function(t,r){var n=e.getTimeFromSeconds(t),o=n.seconds,u=n.minutes,i=n.hours,a="",c=i;return"12-hour"===r&&(a=i>=12?"pm":"am",c=i%12),{seconds:o,minutes:u,hours:c,ampm:a}}}]),e}();t.default=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();var o=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return n(e,null,[{key:"expiryTimestamp",value:function(e){var t=new Date(e).getTime()>0;return t||console.warn("react-timer-hook: { useTimer } Invalid expiryTimestamp settings",e),t}},{key:"onExpire",value:function(e){var t=e&&"function"==typeof e;return e&&!t&&console.warn("react-timer-hook: { useTimer } Invalid onExpire settings function",e),t}}]),e}();t.default=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],n=!0,o=!1,u=void 0;try{for(var i,a=e[Symbol.iterator]();!(n=(i=a.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,u=e}finally{try{!n&&a.return&&a.return()}finally{if(o)throw u}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.default=function(e){var t=(e||{}).autoStart,r=(0,u.useState)(0),a=o(r,2),c=a[0],f=a[1],s=(0,u.useRef)();function l(){s.current&&(clearInterval(s.current),s.current=void 0)}function d(){s.current||(s.current=setInterval(function(){return f(function(e){return e+1})},1e3))}return(0,u.useEffect)(function(){return t&&d(),l},[]),n({},i.Time.getTimeFromSeconds(c),{start:d,pause:function(){s.current&&(clearInterval(s.current),s.current=void 0)},reset:function(){l(),f(0),t&&d()}})};var u=r(0),i=r(1)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],n=!0,o=!1,u=void 0;try{for(var i,a=e[Symbol.iterator]();!(n=(i=a.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,u=e}finally{try{!n&&a.return&&a.return()}finally{if(o)throw u}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.default=function(e){var t=(e||{}).format,r=(0,u.useState)(i.Time.getSecondsFromTimeNow()),a=o(r,2),c=a[0],f=a[1],s=(0,u.useRef)();function l(){s.current&&(clearInterval(s.current),s.current=void 0)}return(0,u.useEffect)(function(){return s.current||(s.current=setInterval(function(){return f(i.Time.getSecondsFromTimeNow())},1e3)),l},[]),n({},i.Time.getFormattedTimeFromSeconds(c,t))};var u=r(0),i=r(1)}])});
{
"name": "react-timer-hook",
"version": "1.1.10",
"version": "2.0.0",
"description": "React timer hook is a custom react hook built to handle timers(countdown), stopwatch and time logic/state in your react component.",

@@ -9,4 +9,10 @@ "main": "dist/index.js",

"build:dev": "webpack --config webpack.dev.js && webpack-dev-server --open --config webpack.dev.js",
"build:prod": "rm -rf ./dist && webpack --config webpack.prod.js"
"build:prod": "rm -rf ./dist && webpack --config webpack.prod.js",
"lint": "node_modules/.bin/eslint src"
},
"husky": {
"hooks": {
"pre-commit": "yarn lint"
}
},
"repository": {

@@ -39,2 +45,3 @@ "type": "git",

"babel-core": "^6.26.3",
"babel-eslint": "^10.0.3",
"babel-loader": "7",

@@ -46,2 +53,9 @@ "babel-preset-env": "^1.7.0",

"copy-webpack-plugin": "^4.6.0",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-react-hooks": "^2.3.0",
"husky": "^4.0.1",
"react": "^16.8.0",

@@ -48,0 +62,0 @@ "react-dom": "16.8.0",

@@ -59,6 +59,6 @@ ## react-timer-hook

// Restarts to 5 minutes timer
var t = new Date();
t.setSeconds(t.getSeconds() + 300);
restart(t)
}}>restart</button>
const time = new Date();
time.setSeconds(time.getSeconds() + 300);
restart(time)
}}>Restart</button>
</div>

@@ -69,7 +69,7 @@ );

export default function App() {
var t = new Date();
t.setSeconds(t.getSeconds() + 600); // 10 minutes timer
const time = new Date();
time.setSeconds(time.getSeconds() + 600); // 10 minutes timer
return (
<div>
<MyTimer expiryTimestamp={t} />
<MyTimer expiryTimestamp={time} />
</div>

@@ -76,0 +76,0 @@ );