pubo-utils 1.0.32 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["pubo-utils"]=n():t["pubo-utils"]=n()}(this,(function(){return function(t){var n={};function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(r,o,function(n){return t[n]}.bind(null,o));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=0)}([function(t,n,e){"use strict";e.r(n),e.d(n,"debounce",(function(){return u})),e.d(n,"hex2rgb",(function(){return c})),e.d(n,"Emitter",(function(){return y})),e.d(n,"superFactory",(function(){return v})),e.d(n,"loop",(function(){return S})),e.d(n,"waitFor",(function(){return k})),e.d(n,"SyncQueue",(function(){return _})),e.d(n,"random",(function(){return a})),e.d(n,"sleep",(function(){return w})),e.d(n,"throttle",(function(){return E})),e.d(n,"ContinuousTrigger",(function(){return A})),e.d(n,"WatchDog",(function(){return M})),e.d(n,"Base64Utils",(function(){return r})),e.d(n,"HistoryStack",(function(){return C})),e.d(n,"Cache",(function(){return F}));var r={};e.r(r),e.d(r,"EncoderMap",(function(){return I})),e.d(r,"toUnit8Array",(function(){return G}));var o=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},i=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(o(arguments[n]));return t},u=function(t,n,e){if(e){var r,o=!0;return function(){for(var e=[],u=0;u<arguments.length;u++)e[u]=arguments[u];o&&(t.apply(void 0,i(e)),o=!1),r&&clearTimeout(r),r=setTimeout((function(){return o=!0}),n)}}var u;return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];u&&clearTimeout(u),u=setTimeout((function(){return t.apply(void 0,i(e))}),n)}},c=function(t){var n=t.toString(2).padStart(24,0);return[parseInt(n.slice(0,8),2),parseInt(n.slice(8,16),2),parseInt(n.slice(16,24),2)]},a=function(t){void 0===t&&(t=8);var n=function(t){return Math.random().toString(32).slice(2,2+t)};if(t<=8)return n(t);for(var e="",r=8;r<=t;r+=8)e+=n(t-r>8?8:t-r);return e},l=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}a((r=r.apply(t,n||[])).next())}))},f=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},s=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},h=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},p=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(h(arguments[n]));return t},y=function(){function t(){this.state={},this.ids={}}return t.prototype.on=function(t,n){if(this.state[t]||(this.state[t]=[]),"function"!=typeof n)throw new Error("第二个参数必须为function!");var e=this.state[t].push(n)-1,r=a(40);return this.ids[r]={event:t,index:e},r},t.prototype.cancel=function(t){if(t){var n=this.ids[t]||{},e=n.event,r=n.index;e&&Array.isArray(this.state[e])&&this.state[e].splice(r,1)}else this.clear()},t.prototype.clear=function(){this.state.length=0},t.prototype.emit=function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return l(this,void 0,void 0,(function(){var e,r,o,i,u,c;return f(this,(function(a){switch(a.label){case 0:if(!Array.isArray(this.state[t]))return[3,8];a.label=1;case 1:a.trys.push([1,6,7,8]),e=s(this.state[t]),r=e.next(),a.label=2;case 2:return r.done?[3,5]:"function"!=typeof(o=r.value)?[3,4]:[4,o.apply(void 0,p(n))];case 3:a.sent(),a.label=4;case 4:return r=e.next(),[3,2];case 5:return[3,8];case 6:return i=a.sent(),u={error:i},[3,8];case 7:try{r&&!r.done&&(c=e.return)&&c.call(e)}finally{if(u)throw u.error}return[7];case 8:return[2]}}))}))},t}(),d=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},v=function(t){return function(n){var e,r,o={};try{for(var i=d(Object.keys(n)),u=i.next();!u.done;u=i.next()){var c=u.value;o[c]=t(n[c],c)}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return o}},b=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}a((r=r.apply(t,n||[])).next())}))},m=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},w=function(t){return b(void 0,void 0,void 0,(function(){return m(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){return setTimeout((function(){return n()}),t)}))];case 1:return n.sent(),[2]}}))}))},g=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}a((r=r.apply(t,n||[])).next())}))},x=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},S=function(t,n){var e=!0,r=function(){e=!1},o=function(){return g(void 0,void 0,void 0,(function(){return x(this,(function(i){switch(i.label){case 0:return[4,t(r)];case 1:return i.sent(),[4,w(n)];case 2:return i.sent(),e?o():o=null,[2]}}))}))};return o(),r},k=function(t,n){return new Promise((function(e){S((function(n){return g(void 0,void 0,void 0,(function(){var r;return x(this,(function(o){switch(o.label){case 0:return[4,t()];case 1:return(r=o.sent())&&(n(),e(r)),[2]}}))}))}),n||100)}))},T=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}a((r=r.apply(t,n||[])).next())}))},j=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},_=function(){function t(){this.cache=[],this.running=!1}return t.prototype._run=function(t){var n=t.fn,e=t.promise;return T(this,void 0,void 0,(function(){var t,r;return j(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,n()];case 1:return t=o.sent(),e.resolve(t),[3,3];case 2:return r=o.sent(),e.reject(r),[3,3];case 3:return[2]}}))}))},t.prototype.run=function(){return T(this,void 0,void 0,(function(){var t;return j(this,(function(n){switch(n.label){case 0:return this.cache.length<1?(this.running=!1,[2]):(this.running=!0,"function"!=typeof(t=this.cache.shift()).fn?[3,2]:[4,this._run(t)]);case 1:n.sent(),n.label=2;case 2:return this.run(),[2]}}))}))},t.prototype.push=function(t){var n=this;return new Promise((function(e,r){n.cache.push({fn:t,promise:{resolve:e,reject:r}}),n.running||n.run()}))},Object.defineProperty(t.prototype,"length",{get:function(){return this.cache.length},enumerable:!1,configurable:!0}),t}(),P=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},O=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(P(arguments[n]));return t};function E(t,n){var e,r=!0;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];e||(e=setTimeout((function(){r=!0,e=null}),n)),r&&(r=!1,t.apply(void 0,O(o)))}}var A=function(){function t(t){this._count=0,this.props=t}return Object.defineProperty(t.prototype,"count",{get:function(){return this._count},enumerable:!1,configurable:!0}),t.prototype.increment=function(){var t=this;clearTimeout(this.timeout),this.timeout=setTimeout((function(){return t.clear()}),this.props.resetTime),this._count=this._count+1,this._count>this.props.count&&this.props.cb()},t.prototype.clear=function(){this._count=0},t}(),M=function(){function t(t){var n=t.limit,e=void 0===n?1:n,r=t.onTimeout;this.count=0,this.i=null,this.limit=e,this.onTimeout=r}return t.prototype.onTimeout=function(){console.log("timeout!")},t.prototype.onTimer=function(){this.count>this.limit&&"function"==typeof this.onTimeout?(this.onTimeout(),this.count=0):this.count++},t.prototype.init=function(){var t=this;this.i=setInterval((function(){return t.onTimer()}),1e3)},t.prototype.feed=function(){this.count=0},t.prototype.stop=function(){this.i&&(clearInterval(this.i),this.count=0)},t}(),I=function(){for(var t={},n=0;n<64;n++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n)]=n;return t}();function G(t,n){for(var e=0,r=0,o=0,i=0;i<t.length&&o<n.length;i+=1)if(r=(r<<6)+I[t.charAt(i)],(e+=6)>=8){var u=r>>>(e-=8);n[o++]=255&u,r-=u<<=e}}var C=function(){function t(t){void 0===t&&(t=10),this.stack=[],this.len=10,this.point=0,this.len=t}return Object.defineProperty(t.prototype,"current",{get:function(){if(this.point<this.stack.length&&this.point>-1)return this.stack[this.point]},enumerable:!1,configurable:!0}),t.prototype.clear=function(){this.stack.length=0,this.point=0},t.prototype.backup=function(t){this.point>0&&this.stack.length>0&&(this.stack.splice(0,this.point),this.point=0),this.stack.unshift(t),this.stack.length>this.len&&this.stack.pop()},t.prototype.undo=function(){return this.point<this.stack.length-2&&(this.point+=1),this.current},t.prototype.redo=function(){return this.point>1&&(this.point-=1),this.current},t}(),F=function(){function t(t){this._=t}return t.prototype.get=function(){return this._},t.prototype.set=function(t){this._=t},t}()}])}));
1
+ !function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["pubo-utils"]=n():t["pubo-utils"]=n()}(this,(function(){return function(t){var n={};function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(r,o,function(n){return t[n]}.bind(null,o));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=0)}([function(t,n,e){"use strict";e.r(n),e.d(n,"debounce",(function(){return u})),e.d(n,"hex2rgb",(function(){return c})),e.d(n,"Emitter",(function(){return y})),e.d(n,"superFactory",(function(){return v})),e.d(n,"loop",(function(){return k})),e.d(n,"waitFor",(function(){return S})),e.d(n,"SyncQueue",(function(){return P})),e.d(n,"random",(function(){return a})),e.d(n,"sleep",(function(){return w})),e.d(n,"throttle",(function(){return E})),e.d(n,"ContinuousTrigger",(function(){return A})),e.d(n,"Base64Utils",(function(){return r})),e.d(n,"HistoryStack",(function(){return I}));var r={};e.r(r),e.d(r,"EncoderMap",(function(){return M})),e.d(r,"toUnit8Array",(function(){return G}));var o=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},i=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(o(arguments[n]));return t},u=function(t,n,e){if(void 0===e&&(e=!1),e){var r,o=!0;return function(){for(var e=[],u=0;u<arguments.length;u++)e[u]=arguments[u];o&&(t.apply(void 0,i(e)),o=!1),r&&clearTimeout(r),r=setTimeout((function(){return o=!0}),n)}}var u;return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];u&&clearTimeout(u),u=setTimeout((function(){return t.apply(void 0,i(e))}),n)}},c=function(t){var n=t.toString(2).padStart(24,0);return[parseInt(n.slice(0,8),2),parseInt(n.slice(8,16),2),parseInt(n.slice(16,24),2)]},a=function(t){void 0===t&&(t=8);var n=function(t){return Math.random().toString(32).slice(2,2+t)};if(t<=8)return n(t);for(var e="",r=0;r<=t;r+=8)e+=n(t-r>8?8:t-r);return e},l=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}a((r=r.apply(t,n||[])).next())}))},f=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},s=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},h=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},p=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(h(arguments[n]));return t},y=function(){function t(){this.state={},this.ids={}}return t.prototype.on=function(t,n){if(this.state[t]||(this.state[t]=[]),"function"!=typeof n)throw new Error("第二个参数必须为function!");var e=this.state[t].push(n)-1,r=a(40);return this.ids[r]={event:t,index:e},r},t.prototype.cancel=function(t){if(t){var n=this.ids[t]||{},e=n.event,r=n.index;e&&Array.isArray(this.state[e])&&this.state[e].splice(r,1)}else this.clear()},t.prototype.clear=function(){this.state.length=0},t.prototype.emit=function(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return l(this,void 0,void 0,(function(){var e,r,o,i,u,c;return f(this,(function(a){switch(a.label){case 0:if(!Array.isArray(this.state[t]))return[3,8];a.label=1;case 1:a.trys.push([1,6,7,8]),e=s(this.state[t]),r=e.next(),a.label=2;case 2:return r.done?[3,5]:"function"!=typeof(o=r.value)?[3,4]:[4,o.apply(void 0,p(n))];case 3:a.sent(),a.label=4;case 4:return r=e.next(),[3,2];case 5:return[3,8];case 6:return i=a.sent(),u={error:i},[3,8];case 7:try{r&&!r.done&&(c=e.return)&&c.call(e)}finally{if(u)throw u.error}return[7];case 8:return[2]}}))}))},t}(),d=function(t){var n="function"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")},v=function(t){return function(n){var e,r,o={};try{for(var i=d(Object.keys(n)),u=i.next();!u.done;u=i.next()){var c=u.value;o[c]=t(n[c],c)}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return o}},b=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}a((r=r.apply(t,n||[])).next())}))},m=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},w=function(t){return b(void 0,void 0,void 0,(function(){return m(this,(function(n){switch(n.label){case 0:return[4,new Promise((function(n){return setTimeout((function(){return n()}),t)}))];case 1:return n.sent(),[2]}}))}))},g=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}a((r=r.apply(t,n||[])).next())}))},x=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},k=function(t,n){var e=!0,r=function(){e=!1},o=function(){return g(void 0,void 0,void 0,(function(){return x(this,(function(i){switch(i.label){case 0:return[4,t(r)];case 1:return i.sent(),[4,w(n)];case 2:return i.sent(),e?o():o=null,[2]}}))}))};return o(),r},S=function(t,n){var e=void 0===n?{}:n,r=e.checkTime,o=e.timeout;return new Promise((function(n,e){var i=k((function(){return g(void 0,void 0,void 0,(function(){var e;return x(this,(function(r){switch(r.label){case 0:return[4,t()];case 1:return(e=r.sent())&&(i(),n(e)),[2]}}))}))}),r||100);o&&setTimeout((function(){i(),e("timeout")}),o)}))},T=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,c)}a((r=r.apply(t,n||[])).next())}))},j=function(t,n){var e,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=n.call(t,u)}catch(t){i=[6,t],r=0}finally{e=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},P=function(){function t(){this.cache=[],this.running=!1}return t.prototype._run=function(t){var n=t.fn,e=t.promise;return T(this,void 0,void 0,(function(){var t,r;return j(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,n()];case 1:return t=o.sent(),e.resolve(t),[3,3];case 2:return r=o.sent(),e.reject(r),[3,3];case 3:return[2]}}))}))},t.prototype.run=function(){return T(this,void 0,void 0,(function(){var t;return j(this,(function(n){switch(n.label){case 0:return this.cache.length<1?(this.running=!1,[2]):(this.running=!0,"function"!=typeof(t=this.cache.shift()).fn?[3,2]:[4,this._run(t)]);case 1:n.sent(),n.label=2;case 2:return this.run(),[2]}}))}))},t.prototype.push=function(t){var n=this;return new Promise((function(e,r){n.cache.push({fn:t,promise:{resolve:e,reject:r}}),n.running||n.run()}))},Object.defineProperty(t.prototype,"length",{get:function(){return this.cache.length},enumerable:!1,configurable:!0}),t}(),O=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,o,i=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(o)throw o.error}}return u},_=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(O(arguments[n]));return t};function E(t,n){var e,r=!0;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];e||(e=setTimeout((function(){r=!0,e=null}),n)),r&&(r=!1,t.apply(void 0,_(o)))}}var A=function(){function t(t){this._count=0,this.props=t}return Object.defineProperty(t.prototype,"count",{get:function(){return this._count},enumerable:!1,configurable:!0}),t.prototype.increment=function(){var t=this;clearTimeout(this.timeout),this.timeout=setTimeout((function(){return t.clear()}),this.props.resetTime),this._count=this._count+1,this._count>this.props.count&&this.props.cb()},t.prototype.clear=function(){this._count=0},t}(),M=function(){for(var t={},n=0;n<64;n++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n)]=n;return t}();function G(t,n){for(var e=0,r=0,o=0,i=0;i<t.length&&o<n.length;i+=1)if(r=(r<<6)+M[t.charAt(i)],(e+=6)>=8){var u=r>>>(e-=8);n[o++]=255&u,r-=u<<=e}}var I=function(){function t(t){void 0===t&&(t=10),this.stack=[],this.len=10,this.point=0,this.len=t}return Object.defineProperty(t.prototype,"current",{get:function(){if(this.point<this.stack.length&&this.point>-1)return this.stack[this.point]},enumerable:!1,configurable:!0}),t.prototype.clear=function(){this.stack.length=0,this.point=0},t.prototype.backup=function(t){this.point>0&&this.stack.length>0&&(this.stack.splice(0,this.point),this.point=0),this.stack.unshift(t),this.stack.length>this.len&&this.stack.pop()},t.prototype.undo=function(){return this.point<this.stack.length-2&&(this.point+=1),this.current},t.prototype.redo=function(){return this.point>1&&(this.point-=1),this.current},t}()}])}));
@@ -1 +1 @@
1
- export declare const debounce: (cb: any, time: number, first?: boolean | undefined) => (...args: any[]) => void;
1
+ export declare const debounce: (cb: any, time: number, first?: boolean) => (...args: any[]) => void;
@@ -34,6 +34,10 @@ var __spread = this && this.__spread || function () {
34
34
  };
35
35
 
36
36
  export var debounce = function debounce(cb, time, first) {
37
+ if (first === void 0) {
38
+ first = false;
39
+ }
40
+
37
41
  if (first) {
38
42
  var shouldRun_1 = true;
39
43
  var t_1;
package/es/index.d.ts CHANGED
@@ -8,7 +8,5 @@ export { random } from './random';
8
8
  export { sleep } from './sleep';
9
9
  export { throttle } from './throttle';
10
10
  export { ContinuousTrigger } from './trigger';
11
- export { WatchDog } from './watch-dog';
12
11
  export * as Base64Utils from './base64';
13
12
  export { HistoryStack } from './stack';
14
- export { Cache } from './cache';
package/es/index.js CHANGED
@@ -8,8 +8,6 @@ export { random } from './random';
8
8
  export { sleep } from './sleep';
9
9
  export { throttle } from './throttle';
10
10
  export { ContinuousTrigger } from './trigger';
11
- export { WatchDog } from './watch-dog';
12
11
  import * as _Base64Utils from './base64';
13
12
  export { _Base64Utils as Base64Utils };
14
- export { HistoryStack } from './stack';
15
- export { Cache } from './cache';
13
+ export { HistoryStack } from './stack';
@@ -1,2 +1,7 @@
1
1
  export declare const loop: (cb: (stop: () => void) => Promise<void>, time: number) => () => void;
2
- export declare const waitFor: (cb: () => boolean, time?: number | undefined) => Promise<unknown>;
2
+ declare type WaitForBool = () => boolean | Promise<boolean>;
3
+ export declare const waitFor: (bool: WaitForBool, { checkTime, timeout }?: {
4
+ checkTime?: number | undefined;
5
+ timeout?: number | undefined;
6
+ }) => Promise<unknown>;
7
+ export {};
package/es/loop/index.js CHANGED
@@ -186,9 +186,13 @@ export var loop = function loop(cb, time) {
186
186
 
187
187
  return stop;
188
188
  };
189
- export var waitFor = function waitFor(cb, time) {
190
- return new Promise(function (resolve) {
191
- loop(function (stop) {
189
+ export var waitFor = function waitFor(bool, _a) {
190
+ var _b = _a === void 0 ? {} : _a,
191
+ checkTime = _b.checkTime,
192
+ timeout = _b.timeout;
193
+
194
+ return new Promise(function (resolve, reject) {
195
+ var stop = loop(function () {
192
196
  return __awaiter(void 0, void 0, void 0, function () {
193
197
  var res;
194
198
  return __generator(this, function (_a) {
@@ -196,7 +200,7 @@ export var waitFor = function waitFor(cb, time) {
196
200
  case 0:
197
201
  return [4
198
202
  /*yield*/
199
- , cb()];
203
+ , bool()];
200
204
 
201
205
  case 1:
202
206
  res = _a.sent();
@@ -212,6 +216,13 @@ export var waitFor = function waitFor(cb, time) {
212
216
  }
213
217
  });
214
218
  });
215
- }, time || 100);
219
+ }, checkTime || 100);
220
+
221
+ if (timeout) {
222
+ setTimeout(function () {
223
+ stop();
224
+ reject('timeout');
225
+ }, timeout);
226
+ }
216
227
  });
217
228
  };
@@ -13,7 +13,7 @@ export var random = function random(n) {
13
13
 
14
14
  var res = '';
15
15
 
16
- for (var a = 8; a <= n; a += 8) {
16
+ for (var a = 0; a <= n; a += 8) {
17
17
  if (n - a > 8) {
18
18
  res += ra(8);
19
19
  } else {
@@ -1 +1 @@
1
- export declare function throttle(cb: any, time: any): (...args: any[]) => void;
1
+ export declare function throttle(cb: any, time: number): (...args: any[]) => void;
@@ -1,14 +1,13 @@
1
+ interface WatchDogProps {
2
+ limit: number;
3
+ onTimeout: () => void;
4
+ }
1
5
  export declare class WatchDog {
2
- private count;
3
6
  private readonly limit;
4
- private i;
5
- constructor({ limit, onTimeout }: {
6
- limit: number;
7
- onTimeout: () => void;
8
- });
9
- private onTimeout;
10
- private onTimer;
11
- init(): void;
7
+ private readonly onTimeout;
8
+ private timeout;
9
+ constructor({ limit, onTimeout }: WatchDogProps);
12
10
  feed(): void;
13
- stop(): void;
11
+ init(): void;
14
12
  }
13
+ export {};
@@ -3,44 +3,25 @@ var WatchDog =
3
3
  function () {
4
4
  function WatchDog(_a) {
5
5
  var _b = _a.limit,
6
- limit = _b === void 0 ? 1 : _b,
6
+ limit = _b === void 0 ? 10 : _b,
7
7
  onTimeout = _a.onTimeout;
8
- this.count = 0;
9
- this.i = null;
8
+ this.limit = 10;
9
+ this.timeout = null;
10
10
  this.limit = limit;
11
11
  this.onTimeout = onTimeout;
12
12
  }
13
13
 
14
- WatchDog.prototype.onTimeout = function () {
15
- console.log('timeout!');
16
- };
17
-
18
- WatchDog.prototype.onTimer = function () {
19
- if (this.count > this.limit && typeof this.onTimeout === 'function') {
20
- this.onTimeout();
21
- this.count = 0;
22
- } else {
23
- this.count++;
24
- }
14
+ WatchDog.prototype.feed = function () {
15
+ clearTimeout(this.timeout);
16
+ this.init();
25
17
  };
26
18
 
27
19
  WatchDog.prototype.init = function () {
28
20
  var _this = this;
29
21
 
30
- this.i = setInterval(function () {
31
- return _this.onTimer();
32
- }, 1000);
33
- };
34
-
35
- WatchDog.prototype.feed = function () {
36
- this.count = 0;
37
- };
38
-
39
- WatchDog.prototype.stop = function () {
40
- if (this.i) {
41
- clearInterval(this.i);
42
- this.count = 0;
43
- }
22
+ this.timeout = setTimeout(function () {
23
+ return _this.onTimeout();
24
+ }, this.limit * 1000);
44
25
  };
45
26
 
46
27
  return WatchDog;
@@ -1 +1 @@
1
- export declare const debounce: (cb: any, time: number, first?: boolean | undefined) => (...args: any[]) => void;
1
+ export declare const debounce: (cb: any, time: number, first?: boolean) => (...args: any[]) => void;
@@ -41,6 +41,10 @@ Object.defineProperty(exports, "__esModule", {
41
41
  exports.debounce = void 0;
42
42
 
43
43
  exports.debounce = function (cb, time, first) {
44
+ if (first === void 0) {
45
+ first = false;
46
+ }
47
+
44
48
  if (first) {
45
49
  var shouldRun_1 = true;
46
50
  var t_1;
package/lib/index.d.ts CHANGED
@@ -8,7 +8,5 @@ export { random } from './random';
8
8
  export { sleep } from './sleep';
9
9
  export { throttle } from './throttle';
10
10
  export { ContinuousTrigger } from './trigger';
11
- export { WatchDog } from './watch-dog';
12
11
  export * as Base64Utils from './base64';
13
12
  export { HistoryStack } from './stack';
14
- export { Cache } from './cache';
package/lib/index.js CHANGED
@@ -133,15 +133,6 @@ Object.defineProperty(exports, "ContinuousTrigger", {
133
133
  return trigger_1.ContinuousTrigger;
134
134
  }
135
135
  });
136
-
137
- var watch_dog_1 = require("./watch-dog");
138
-
139
- Object.defineProperty(exports, "WatchDog", {
140
- enumerable: true,
141
- get: function get() {
142
- return watch_dog_1.WatchDog;
143
- }
144
- });
145
136
  exports.Base64Utils = __importStar(require("./base64"));
146
137
 
147
138
  var stack_1 = require("./stack");
@@ -151,13 +142,4 @@ Object.defineProperty(exports, "HistoryStack", {
151
142
  get: function get() {
152
143
  return stack_1.HistoryStack;
153
144
  }
154
- });
155
-
156
- var cache_1 = require("./cache");
157
-
158
- Object.defineProperty(exports, "Cache", {
159
- enumerable: true,
160
- get: function get() {
161
- return cache_1.Cache;
162
- }
163
145
  });
@@ -1,2 +1,7 @@
1
1
  export declare const loop: (cb: (stop: () => void) => Promise<void>, time: number) => () => void;
2
- export declare const waitFor: (cb: () => boolean, time?: number | undefined) => Promise<unknown>;
2
+ declare type WaitForBool = () => boolean | Promise<boolean>;
3
+ export declare const waitFor: (bool: WaitForBool, { checkTime, timeout }?: {
4
+ checkTime?: number | undefined;
5
+ timeout?: number | undefined;
6
+ }) => Promise<unknown>;
7
+ export {};
package/lib/loop/index.js CHANGED
@@ -195,9 +195,13 @@ exports.loop = function (cb, time) {
195
195
  return stop;
196
196
  };
197
197
 
198
- exports.waitFor = function (cb, time) {
199
- return new Promise(function (resolve) {
200
- exports.loop(function (stop) {
198
+ exports.waitFor = function (bool, _a) {
199
+ var _b = _a === void 0 ? {} : _a,
200
+ checkTime = _b.checkTime,
201
+ timeout = _b.timeout;
202
+
203
+ return new Promise(function (resolve, reject) {
204
+ var stop = exports.loop(function () {
201
205
  return __awaiter(void 0, void 0, void 0, function () {
202
206
  var res;
203
207
  return __generator(this, function (_a) {
@@ -205,7 +209,7 @@ exports.waitFor = function (cb, time) {
205
209
  case 0:
206
210
  return [4
207
211
  /*yield*/
208
- , cb()];
212
+ , bool()];
209
213
 
210
214
  case 1:
211
215
  res = _a.sent();
@@ -221,6 +225,13 @@ exports.waitFor = function (cb, time) {
221
225
  }
222
226
  });
223
227
  });
224
- }, time || 100);
228
+ }, checkTime || 100);
229
+
230
+ if (timeout) {
231
+ setTimeout(function () {
232
+ stop();
233
+ reject('timeout');
234
+ }, timeout);
235
+ }
225
236
  });
226
237
  };
@@ -20,7 +20,7 @@ exports.random = function (n) {
20
20
 
21
21
  var res = '';
22
22
 
23
- for (var a = 8; a <= n; a += 8) {
23
+ for (var a = 0; a <= n; a += 8) {
24
24
  if (n - a > 8) {
25
25
  res += ra(8);
26
26
  } else {
@@ -1 +1 @@
1
- export declare function throttle(cb: any, time: any): (...args: any[]) => void;
1
+ export declare function throttle(cb: any, time: number): (...args: any[]) => void;
@@ -1,14 +1,13 @@
1
+ interface WatchDogProps {
2
+ limit: number;
3
+ onTimeout: () => void;
4
+ }
1
5
  export declare class WatchDog {
2
- private count;
3
6
  private readonly limit;
4
- private i;
5
- constructor({ limit, onTimeout }: {
6
- limit: number;
7
- onTimeout: () => void;
8
- });
9
- private onTimeout;
10
- private onTimer;
11
- init(): void;
7
+ private readonly onTimeout;
8
+ private timeout;
9
+ constructor({ limit, onTimeout }: WatchDogProps);
12
10
  feed(): void;
13
- stop(): void;
11
+ init(): void;
14
12
  }
13
+ export {};
@@ -10,44 +10,25 @@ var WatchDog =
10
10
  function () {
11
11
  function WatchDog(_a) {
12
12
  var _b = _a.limit,
13
- limit = _b === void 0 ? 1 : _b,
13
+ limit = _b === void 0 ? 10 : _b,
14
14
  onTimeout = _a.onTimeout;
15
- this.count = 0;
16
- this.i = null;
15
+ this.limit = 10;
16
+ this.timeout = null;
17
17
  this.limit = limit;
18
18
  this.onTimeout = onTimeout;
19
19
  }
20
20
 
21
- WatchDog.prototype.onTimeout = function () {
22
- console.log('timeout!');
23
- };
24
-
25
- WatchDog.prototype.onTimer = function () {
26
- if (this.count > this.limit && typeof this.onTimeout === 'function') {
27
- this.onTimeout();
28
- this.count = 0;
29
- } else {
30
- this.count++;
31
- }
21
+ WatchDog.prototype.feed = function () {
22
+ clearTimeout(this.timeout);
23
+ this.init();
32
24
  };
33
25
 
34
26
  WatchDog.prototype.init = function () {
35
27
  var _this = this;
36
28
 
37
- this.i = setInterval(function () {
38
- return _this.onTimer();
39
- }, 1000);
40
- };
41
-
42
- WatchDog.prototype.feed = function () {
43
- this.count = 0;
44
- };
45
-
46
- WatchDog.prototype.stop = function () {
47
- if (this.i) {
48
- clearInterval(this.i);
49
- this.count = 0;
50
- }
29
+ this.timeout = setTimeout(function () {
30
+ return _this.onTimeout();
31
+ }, this.limit * 1000);
51
32
  };
52
33
 
53
34
  return WatchDog;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-utils",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -18,5 +18,5 @@
18
18
  "engines": {
19
19
  "node": ">=8.0.0"
20
20
  },
21
- "gitHead": "2a8c06e4ad83471773f7b7b29c9586cd5b5b419e"
21
+ "gitHead": "c5218221058a304c692c4e9e789e7b8f8a2c7bce"
22
22
  }
package/es/cache.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export declare class Cache<T> {
2
- private _;
3
- constructor(props: T);
4
- get(): T;
5
- set(data: T): void;
6
- }
package/es/cache.js DELETED
@@ -1,19 +0,0 @@
1
- var Cache =
2
- /** @class */
3
- function () {
4
- function Cache(props) {
5
- this._ = props;
6
- }
7
-
8
- Cache.prototype.get = function () {
9
- return this._;
10
- };
11
-
12
- Cache.prototype.set = function (data) {
13
- this._ = data;
14
- };
15
-
16
- return Cache;
17
- }();
18
-
19
- export { Cache };
package/lib/cache.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export declare class Cache<T> {
2
- private _;
3
- constructor(props: T);
4
- get(): T;
5
- set(data: T): void;
6
- }
package/lib/cache.js DELETED
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Cache = void 0;
7
-
8
- var Cache =
9
- /** @class */
10
- function () {
11
- function Cache(props) {
12
- this._ = props;
13
- }
14
-
15
- Cache.prototype.get = function () {
16
- return this._;
17
- };
18
-
19
- Cache.prototype.set = function (data) {
20
- this._ = data;
21
- };
22
-
23
- return Cache;
24
- }();
25
-
26
- exports.Cache = Cache;