Socket
Socket
Sign inDemoInstall

inactivejs

Package Overview
Dependencies
1
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.1.1

2

dist/index.js

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

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.inactivejs=e():t.inactivejs=e()}("undefined"!=typeof self?self:this,function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="/",i(i.s=0)}([function(t,e,i){t.exports=i(1)},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,o=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),r=i(2),u=(n=r)&&n.__esModule?n:{default:n};var a=function(){function t(){var e=this,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var n=i.timeout,o=void 0===n?6e4:n,r=i.onAway,a=void 0===r?function(){}:r,s=i.onBack,c=void 0===s?function(){}:s,f=i.onVisible,l=void 0===f?function(){}:f,h=i.onHidden,d=void 0===h?function(){}:h,v=i.events,y=void 0===v?["click","mousemove","mouseenter","keydown","scroll","mousewheel","touchmove","touchstart"]:v,p=i.autoStart,m=void 0===p||p,b=i.throttle,w=void 0===b?10:b;if(this.timeout=o,this.onAway=a,this.onBack=c,this.events=y,this.onVisible=l,this.onHidden=d,this._isAway=!1,this._started=!1,this._checkIdle=!(!i.onAway||!i.onBack),this._checkVisibility=!(!i.onVisible||!i.onHidden),this._visibilityEvent=function(){return e._visibilityChange()},this._eventMethod=(0,u.default)(this._triggerActive.bind(this),w),"undefined"==typeof window||"undefined"==typeof document)throw new Error("window not available");m&&this.start()}return o(t,[{key:"start",value:function(){var t=this;this._started||(this._started=!0,this._checkIdle&&(this._awayTimestamp=Date.now()+this.timeout,this.events.forEach(function(e){return window.addEventListener(e,t._eventMethod)}),this._createTimeout()),this._checkVisibility&&document.addEventListener("visibilitychange",this._visibilityEvent))}},{key:"stop",value:function(){var t=this;this._checkIdle&&this.events.forEach(function(e){return window.removeEventListener(e,t._eventMethod)}),this._checkVisibility&&document.removeEventListener("visibilitychange",this._visibilityEvent),this._started=!1}},{key:"_triggerActive",value:function(){return this._awayTimestamp=Date.now()+this.timeout,this._isAway&&(this.onBack(),this._createTimeout()),this._isAway=!1,!0}},{key:"_validateAway",value:function(){if(Date.now()<this._awayTimestamp)return this._isAway=!1,void this._createTimeout();clearTimeout(this.timer),this._isAway=!0,this.onAway()}},{key:"_createTimeout",value:function(){var t=this;if(clearTimeout(this.timer),this._started){var e=this._awayTimestamp-Date.now();this.timer=setTimeout(function(){return t._validateAway()},e)}}},{key:"_visibilityChange",value:function(){return document.hidden?this.onHidden():this.onVisible(),!0}}]),t}();e.default=a},function(t,e,i){(function(e){var i="Expected a function",n=NaN,o="[object Symbol]",r=/^\s+|\s+$/g,u=/^[-+]0x[0-9a-f]+$/i,a=/^0b[01]+$/i,s=/^0o[0-7]+$/i,c=parseInt,f="object"==typeof e&&e&&e.Object===Object&&e,l="object"==typeof self&&self&&self.Object===Object&&self,h=f||l||Function("return this")(),d=Object.prototype.toString,v=Math.max,y=Math.min,p=function(){return h.Date.now()};function m(t,e,n){var o,r,u,a,s,c,f=0,l=!1,h=!1,d=!0;if("function"!=typeof t)throw new TypeError(i);function m(e){var i=o,n=r;return o=r=void 0,f=e,a=t.apply(n,i)}function _(t){var i=t-c;return void 0===c||i>=e||i<0||h&&t-f>=u}function g(){var t=p();if(_(t))return j(t);s=setTimeout(g,function(t){var i=e-(t-c);return h?y(i,u-(t-f)):i}(t))}function j(t){return s=void 0,d&&o?m(t):(o=r=void 0,a)}function k(){var t=p(),i=_(t);if(o=arguments,r=this,c=t,i){if(void 0===s)return function(t){return f=t,s=setTimeout(g,e),l?m(t):a}(c);if(h)return s=setTimeout(g,e),m(c)}return void 0===s&&(s=setTimeout(g,e)),a}return e=w(e)||0,b(n)&&(l=!!n.leading,u=(h="maxWait"in n)?v(w(n.maxWait)||0,e):u,d="trailing"in n?!!n.trailing:d),k.cancel=function(){void 0!==s&&clearTimeout(s),f=0,o=c=r=s=void 0},k.flush=function(){return void 0===s?a:j(p())},k}function b(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function w(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&d.call(t)==o}(t))return n;if(b(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=b(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(r,"");var i=a.test(t);return i||s.test(t)?c(t.slice(2),i?2:8):u.test(t)?n:+t}t.exports=function(t,e,n){var o=!0,r=!0;if("function"!=typeof t)throw new TypeError(i);return b(n)&&(o="leading"in n?!!n.leading:o,r="trailing"in n?!!n.trailing:r),m(t,e,{leading:o,maxWait:e,trailing:r})}}).call(e,i(3))},function(t,e){var i;i=function(){return this}();try{i=i||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(i=window)}t.exports=i}]).default});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.inactivejs=e():t.inactivejs=e()}("undefined"!=typeof self?self:this,function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="/",i(i.s=0)}([function(t,e,i){t.exports=i(1)},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,o=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),r=i(2),u=(n=r)&&n.__esModule?n:{default:n};var a=function(){function t(){var e=this,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var n=i.timeout,o=void 0===n?6e4:n,r=i.onAway,a=void 0===r?function(){}:r,s=i.onBack,c=void 0===s?function(){}:s,f=i.onVisible,l=void 0===f?function(){}:f,h=i.onHidden,d=void 0===h?function(){}:h,v=i.events,y=void 0===v?["click","mousemove","mouseenter","keydown","scroll","mousewheel","touchmove","touchstart"]:v,p=i.autoStart,m=void 0===p||p,b=i.throttle,w=void 0===b?10:b;if(this.timeout=o,this.onAway=a,this.onBack=c,this.events=y,this.onVisible=l,this.onHidden=d,this._isAway=!1,this._started=!1,this._checkIdle=!(!i.onAway&&!i.onBack),this._checkVisibility=!(!i.onVisible&&!i.onHidden),this._visibilityEvent=function(){return e._visibilityChange()},this._eventMethod=(0,u.default)(this._triggerActive.bind(this),w),"undefined"==typeof window||"undefined"==typeof document)throw new Error("window not available");m&&this.start()}return o(t,[{key:"start",value:function(){var t=this;this._started||(this._started=!0,this._checkIdle&&(this._awayTimestamp=Date.now()+this.timeout,this.events.forEach(function(e){return window.addEventListener(e,t._eventMethod)}),this._createTimeout()),this._checkVisibility&&document.addEventListener("visibilitychange",this._visibilityEvent))}},{key:"stop",value:function(){var t=this;this._checkIdle&&this.events.forEach(function(e){return window.removeEventListener(e,t._eventMethod)}),this._checkVisibility&&document.removeEventListener("visibilitychange",this._visibilityEvent),this._started=!1}},{key:"_triggerActive",value:function(){return this._awayTimestamp=Date.now()+this.timeout,this._isAway&&(this.onBack(),this._createTimeout()),this._isAway=!1,!0}},{key:"_validateAway",value:function(){if(Date.now()<this._awayTimestamp)return this._isAway=!1,void this._createTimeout();clearTimeout(this.timer),this._isAway=!0,this.onAway()}},{key:"_createTimeout",value:function(){var t=this;if(clearTimeout(this.timer),this._started){var e=this._awayTimestamp-Date.now();this.timer=setTimeout(function(){return t._validateAway()},e)}}},{key:"_visibilityChange",value:function(){return document.hidden?this.onHidden():this.onVisible(),!0}}]),t}();e.default=a},function(t,e,i){(function(e){var i="Expected a function",n=NaN,o="[object Symbol]",r=/^\s+|\s+$/g,u=/^[-+]0x[0-9a-f]+$/i,a=/^0b[01]+$/i,s=/^0o[0-7]+$/i,c=parseInt,f="object"==typeof e&&e&&e.Object===Object&&e,l="object"==typeof self&&self&&self.Object===Object&&self,h=f||l||Function("return this")(),d=Object.prototype.toString,v=Math.max,y=Math.min,p=function(){return h.Date.now()};function m(t,e,n){var o,r,u,a,s,c,f=0,l=!1,h=!1,d=!0;if("function"!=typeof t)throw new TypeError(i);function m(e){var i=o,n=r;return o=r=void 0,f=e,a=t.apply(n,i)}function _(t){var i=t-c;return void 0===c||i>=e||i<0||h&&t-f>=u}function g(){var t=p();if(_(t))return j(t);s=setTimeout(g,function(t){var i=e-(t-c);return h?y(i,u-(t-f)):i}(t))}function j(t){return s=void 0,d&&o?m(t):(o=r=void 0,a)}function k(){var t=p(),i=_(t);if(o=arguments,r=this,c=t,i){if(void 0===s)return function(t){return f=t,s=setTimeout(g,e),l?m(t):a}(c);if(h)return s=setTimeout(g,e),m(c)}return void 0===s&&(s=setTimeout(g,e)),a}return e=w(e)||0,b(n)&&(l=!!n.leading,u=(h="maxWait"in n)?v(w(n.maxWait)||0,e):u,d="trailing"in n?!!n.trailing:d),k.cancel=function(){void 0!==s&&clearTimeout(s),f=0,o=c=r=s=void 0},k.flush=function(){return void 0===s?a:j(p())},k}function b(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function w(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&d.call(t)==o}(t))return n;if(b(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=b(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(r,"");var i=a.test(t);return i||s.test(t)?c(t.slice(2),i?2:8):u.test(t)?n:+t}t.exports=function(t,e,n){var o=!0,r=!0;if("function"!=typeof t)throw new TypeError(i);return b(n)&&(o="leading"in n?!!n.leading:o,r="trailing"in n?!!n.trailing:r),m(t,e,{leading:o,maxWait:e,trailing:r})}}).call(e,i(3))},function(t,e){var i;i=function(){return this}();try{i=i||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(i=window)}t.exports=i}]).default});
{
"name": "inactivejs",
"version": "0.1.0",
"version": "0.1.1",
"description": "Detect when a user is idle or change tabs",

@@ -5,0 +5,0 @@ "keywords": [

@@ -28,4 +28,4 @@ import _throttle from 'lodash.throttle';

this._started = false;
this._checkIdle = !! (options.onAway && options.onBack);
this._checkVisibility = !! (options.onVisible && options.onHidden);
this._checkIdle = !! (options.onAway || options.onBack);
this._checkVisibility = !! (options.onVisible || options.onHidden);

@@ -32,0 +32,0 @@ this._visibilityEvent = () => this._visibilityChange();

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc