control-timeout
Advanced tools
Comparing version
@@ -7,5 +7,5 @@ "use strict"; | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
// Generated by CoffeeScript 2.5.1 | ||
// Generated by CoffeeScript 2.7.0 | ||
(function () { | ||
@@ -12,0 +12,0 @@ // control-timeout - A timeout class for controlling one or multiple timeouts. |
@@ -1,1 +0,1 @@ | ||
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),e}(function(){var e,c,i;i=require("types.js"),c="control-timeout",e=function(){var e=function(){function l(e){_classCallCheck(this,l),this.timeouts={},this.running={},this.delay=Math.abs(e)||l.delay}return _createClass(l,null,[{key:"setLog",value:function(e){return l.log=i.forceFunction(e)}}]),_createClass(l,[{key:"exists",value:function(e){return this.timeouts.hasOwnProperty(e)}},{key:"isRunning",value:function(e){return this.running.hasOwnProperty(e)}},{key:"_stopOne",value:function(e){return this.isRunning(e)&&(clearTimeout(this.running[e]),delete this.running[e]),this}},{key:"stop",value:function(){for(var e,t,n,i=arguments.length,s=new Array(i),o=0;o<i;o++)s[o]=arguments[o];if(s.length)for(e=0,n=s.length;e<n;e++)t=s[e],this._stopOne(t);else for(t in this.running)this._stopOne(t);return this}},{key:"setDelay",value:function(e,t){if(this.exists(e))return this.timeouts[e].delay=i.forceNumber(t,this.timeouts[e].delay)}},{key:"getTimeout",value:function(e){return this.running[e]}},{key:"_setTimeout",value:function(e,t,n){var i=this;return this.running[e]=setTimeout(function(){return delete i.running[e],t()},n)}},{key:"run",value:function(e){var t,n,i;i=[];for(var s=arguments.length,o=new Array(1<s?s-1:0),r=1;r<s;r++)o[r-1]=arguments[r];if(e)if(this.exists(e)){var u;i.push(this._setTimeout(e,(u=this.timeouts[e].action).bind.apply(u,[null].concat(o)),this.timeouts[e].delay))}else l.log(c+': timeout with id: "'+e+'" was not found');else for(e in t=this.timeouts){var a;if(n=t[e],!this.isRunning(e))i.push(this._setTimeout(e,(a=n.action).bind.apply(a,[null].concat(o)),n.delay))}switch(i.length){case 0:return null;case 1:return i[0];default:return i}}},{key:"removeAll",value:function(){return this.stop(),this.timeouts={},this}},{key:"remove",value:function(){for(var e,t,n,i=arguments.length,s=new Array(i),o=0;o<i;o++)s[o]=arguments[o];if(s.length)for(e=0,n=s.length;e<n;e++)t=s[e],this._stopOne(t),delete this.timeouts[t];else l.log(c+": cannot remove, invalid or non-existing timeout!");return this}},{key:"_add",value:function(e,t,n){return i.notString(e)||!e.length?l.log(c+": cannot add timeout, invalid or missing id!"):this.exists(e)?l.log(c+": cannot add timeout, id: "+e+" exists already!"):this.timeouts[e]={action:i.forceFunction(t),delay:Math.abs(i.forceNumber(n,this.delay))},this}},{key:"add",value:function(e,t,n){return i.isObject(e)?this._add(e.id,e.action,e.delay):this._add(e,t,n)}}]),l}();return e.log=e.setLog("undefined"!=typeof console&&null!==console?console.log:void 0),e.delay=0,e}.call(this),module.exports=e}).call(void 0); | ||
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}(function(){var e,t,n;n=require("types.js"),t="control-timeout",e=function(){var e=function(){function e(t){_classCallCheck(this,e),this.timeouts={},this.running={},this.delay=Math.abs(t)||e.delay}return _createClass(e,null,[{key:"setLog",value:function(t){return e.log=n.forceFunction(t)}}]),_createClass(e,[{key:"exists",value:function(e){return this.timeouts.hasOwnProperty(e)}},{key:"isRunning",value:function(e){return this.running.hasOwnProperty(e)}},{key:"_stopOne",value:function(e){return this.isRunning(e)&&(clearTimeout(this.running[e]),delete this.running[e]),this}},{key:"stop",value:function(){for(var e,t,n,i=arguments.length,o=new Array(i),r=0;r<i;r++)o[r]=arguments[r];if(o.length)for(e=0,n=o.length;e<n;e++)t=o[e],this._stopOne(t);else for(t in this.running)this._stopOne(t);return this}},{key:"setDelay",value:function(e,t){if(this.exists(e))return this.timeouts[e].delay=n.forceNumber(t,this.timeouts[e].delay)}},{key:"getTimeout",value:function(e){return this.running[e]}},{key:"_setTimeout",value:function(e,t,n){var i=this;return this.running[e]=setTimeout((function(){return delete i.running[e],t()}),n)}},{key:"run",value:function(n){var i,o,r;r=[];for(var s=arguments.length,u=new Array(s>1?s-1:0),a=1;a<s;a++)u[a-1]=arguments[a];if(n)if(this.exists(n)){var l;r.push(this._setTimeout(n,(l=this.timeouts[n].action).bind.apply(l,[null].concat(u)),this.timeouts[n].delay))}else e.log(t+': timeout with id: "'+n+'" was not found');else for(n in i=this.timeouts){var c;if(o=i[n],!this.isRunning(n))r.push(this._setTimeout(n,(c=o.action).bind.apply(c,[null].concat(u)),o.delay))}switch(r.length){case 0:return null;case 1:return r[0];default:return r}}},{key:"removeAll",value:function(){return this.stop(),this.timeouts={},this}},{key:"remove",value:function(){for(var n,i,o,r=arguments.length,s=new Array(r),u=0;u<r;u++)s[u]=arguments[u];if(s.length)for(n=0,o=s.length;n<o;n++)i=s[n],this._stopOne(i),delete this.timeouts[i];else e.log(t+": cannot remove, invalid or non-existing timeout!");return this}},{key:"_add",value:function(i,o,r){return n.notString(i)||!i.length?e.log(t+": cannot add timeout, invalid or missing id!"):this.exists(i)?e.log(t+": cannot add timeout, id: "+i+" exists already!"):this.timeouts[i]={action:n.forceFunction(o),delay:Math.abs(n.forceNumber(r,this.delay))},this}},{key:"add",value:function(e,t,i){return n.isObject(e)?this._add(e.id,e.action,e.delay):this._add(e,t,i)}}]),e}();return e.log=e.setLog("undefined"!=typeof console&&null!==console?console.log:void 0),e.delay=0,e}.call(this),module.exports=e}).call(void 0); |
{ | ||
"name": "control-timeout", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "A timeout class for controlling one or multiple timeouts", | ||
"main": "control-timeout.min.js", | ||
"scripts": { | ||
"uglify": "uglifyjs control-timeout.js -c -m -o control-timeout.min.js", | ||
"build": "coffee -c --transpile control-timeout.coffee && npm run uglify", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"uglify": "terser control-timeout.js -c -m -o control-timeout.min.js" | ||
}, | ||
@@ -30,3 +30,3 @@ "repository": { | ||
], | ||
"author": "Dennis Raymondo van der Sluis <phazelift@gmail.com> (https://github.com/phazelift/)", | ||
"author": "dennis raymondo van der sluis", | ||
"license": "MIT", | ||
@@ -33,0 +33,0 @@ "bugs": { |
19553
0.33%194
0.52%