pubo-utils 1.0.13 → 1.0.17
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.
- package/dist/pubo-utils.js +1 -1
- package/es/debounce/index.d.ts +1 -1
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/es/statck/index.d.ts +10 -0
- package/es/statck/index.js +59 -0
- package/lib/debounce/index.d.ts +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +11 -2
- package/lib/statck/index.d.ts +10 -0
- package/lib/statck/index.js +66 -0
- package/package.json +2 -2
package/dist/pubo-utils.js
CHANGED
|
@@ -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,"random",(function(){return a})),e.d(n,"WatchDog",(function(){return A})),e.d(n,"superFactory",(function(){return d})),e.d(n,"Emitter",(function(){return y})),e.d(n,"SyncQueue",(function(){return k})),e.d(n,"sleep",(function(){return w})),e.d(n,"ContinuousTrigger",(function(){return E})),e.d(n,"throttle",(function(){return O})),e.d(n,"loop",(function(){return S})),e.d(n,"hex2rgb",(function(){return c})),e.d(n,"debounce",(function(){return u})),e.d(n,"Base64Utils",(function(){return r}));var r={};e.r(r),e.d(r,"EncoderMap",(function(){return M})),e.d(r,"toUnit8Array",(function(){return I}));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.")},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},h=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(p(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,h(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}(),v=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.")},d=function(t){return function(n){var e,r,o={};try{for(var i=v(Object.keys(n)),u=i.next();!u.done;u=i.next()){var c=u.value;o[c]=t(n[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};return function o(){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(),[2]}}))}))}(),r},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])}}},k=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},_=function(){for(var t=[],n=0;n<arguments.length;n++)t=t.concat(P(arguments[n]));return t};function O(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 E=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}(),A=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}(),M=function(){for(var t={},n=0;n<64;n++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n)]=n;return t}();function I(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}}}])}));
|
|
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,"random",(function(){return a})),e.d(n,"WatchDog",(function(){return A})),e.d(n,"superFactory",(function(){return v})),e.d(n,"Emitter",(function(){return y})),e.d(n,"SyncQueue",(function(){return j})),e.d(n,"sleep",(function(){return w})),e.d(n,"ContinuousTrigger",(function(){return E})),e.d(n,"throttle",(function(){return _})),e.d(n,"loop",(function(){return S})),e.d(n,"hex2rgb",(function(){return c})),e.d(n,"debounce",(function(){return u})),e.d(n,"Base64Utils",(function(){return r})),e.d(n,"HistoryStack",(function(){return G}));var r={};e.r(r),e.d(r,"EncoderMap",(function(){return M})),e.d(r,"toUnit8Array",(function(){return I}));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])}}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};return function o(){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(),[2]}}))}))}(),r},k=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())}))},T=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])}}},j=function(){function t(){this.cache=[],this.running=!1}return t.prototype._run=function(t){var n=t.fn,e=t.promise;return k(this,void 0,void 0,(function(){var t,r;return T(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 k(this,void 0,void 0,(function(){var t;return T(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 _(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 E=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}(),A=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}(),M=function(){for(var t={},n=0;n<64;n++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n)]=n;return t}();function I(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 G=function(){function t(t){void 0===t&&(t=10),this.stack=[],this.len=10,this.point=-1,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.push=function(t){this.point>-1&&(this.stack.splice(0,this.point+1),this.point=-1),this.stack.unshift(t),this.stack.length>this.len&&this.stack.pop()},t.prototype.back=function(){return this.point<this.stack.length-1&&(this.point+=1),this.current},t.prototype.forward=function(){return this.point>0&&(this.point-=1),this.current},t}()}])}));
|
package/es/debounce/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const debounce: (cb: any, time: number, first
|
|
1
|
+
export declare const debounce: (cb: any, time: number, first?: boolean | undefined) => (...args: any[]) => void;
|
package/es/index.d.ts
CHANGED
|
@@ -10,4 +10,5 @@ import { throttle } from './throttle';
|
|
|
10
10
|
import { ContinuousTrigger } from './trigger';
|
|
11
11
|
import { WatchDog } from './watch-dog';
|
|
12
12
|
import * as Base64Utils from './base64';
|
|
13
|
-
|
|
13
|
+
import { HistoryStack } from './statck';
|
|
14
|
+
export { random, WatchDog, superFactory, Emitter, SyncQueue, sleep, ContinuousTrigger, throttle, loop, hex2rgb, debounce, Base64Utils, HistoryStack, };
|
package/es/index.js
CHANGED
|
@@ -10,4 +10,5 @@ import { throttle } from './throttle';
|
|
|
10
10
|
import { ContinuousTrigger } from './trigger';
|
|
11
11
|
import { WatchDog } from './watch-dog';
|
|
12
12
|
import * as Base64Utils from './base64';
|
|
13
|
-
|
|
13
|
+
import { HistoryStack } from './statck';
|
|
14
|
+
export { random, WatchDog, superFactory, Emitter, SyncQueue, sleep, ContinuousTrigger, throttle, loop, hex2rgb, debounce, Base64Utils, HistoryStack };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var HistoryStack =
|
|
2
|
+
/** @class */
|
|
3
|
+
function () {
|
|
4
|
+
function HistoryStack(len) {
|
|
5
|
+
if (len === void 0) {
|
|
6
|
+
len = 10;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
this.stack = [];
|
|
10
|
+
this.len = 10;
|
|
11
|
+
this.point = -1;
|
|
12
|
+
this.len = len;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Object.defineProperty(HistoryStack.prototype, "current", {
|
|
16
|
+
get: function get() {
|
|
17
|
+
if (this.point < this.stack.length && this.point > -1) {
|
|
18
|
+
return this.stack[this.point];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return undefined;
|
|
22
|
+
},
|
|
23
|
+
enumerable: false,
|
|
24
|
+
configurable: true
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
HistoryStack.prototype.push = function (item) {
|
|
28
|
+
if (this.point > -1) {
|
|
29
|
+
this.stack.splice(0, this.point + 1);
|
|
30
|
+
this.point = -1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
this.stack.unshift(item);
|
|
34
|
+
|
|
35
|
+
if (this.stack.length > this.len) {
|
|
36
|
+
this.stack.pop();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
HistoryStack.prototype.back = function () {
|
|
41
|
+
if (this.point < this.stack.length - 1) {
|
|
42
|
+
this.point += 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return this.current;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
HistoryStack.prototype.forward = function () {
|
|
49
|
+
if (this.point > 0) {
|
|
50
|
+
this.point -= 1;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return this.current;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return HistoryStack;
|
|
57
|
+
}();
|
|
58
|
+
|
|
59
|
+
export { HistoryStack };
|
package/lib/debounce/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const debounce: (cb: any, time: number, first
|
|
1
|
+
export declare const debounce: (cb: any, time: number, first?: boolean | undefined) => (...args: any[]) => void;
|
package/lib/index.d.ts
CHANGED
|
@@ -10,4 +10,5 @@ import { throttle } from './throttle';
|
|
|
10
10
|
import { ContinuousTrigger } from './trigger';
|
|
11
11
|
import { WatchDog } from './watch-dog';
|
|
12
12
|
import * as Base64Utils from './base64';
|
|
13
|
-
|
|
13
|
+
import { HistoryStack } from './statck';
|
|
14
|
+
export { random, WatchDog, superFactory, Emitter, SyncQueue, sleep, ContinuousTrigger, throttle, loop, hex2rgb, debounce, Base64Utils, HistoryStack, };
|
package/lib/index.js
CHANGED
|
@@ -37,7 +37,7 @@ var __importStar = this && this.__importStar || function (mod) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", {
|
|
38
38
|
value: true
|
|
39
39
|
});
|
|
40
|
-
exports.Base64Utils = exports.debounce = exports.hex2rgb = exports.loop = exports.throttle = exports.ContinuousTrigger = exports.sleep = exports.SyncQueue = exports.Emitter = exports.superFactory = exports.WatchDog = exports.random = void 0;
|
|
40
|
+
exports.HistoryStack = exports.Base64Utils = exports.debounce = exports.hex2rgb = exports.loop = exports.throttle = exports.ContinuousTrigger = exports.sleep = exports.SyncQueue = exports.Emitter = exports.superFactory = exports.WatchDog = exports.random = void 0;
|
|
41
41
|
|
|
42
42
|
var debounce_1 = require("./debounce");
|
|
43
43
|
|
|
@@ -140,4 +140,13 @@ Object.defineProperty(exports, "WatchDog", {
|
|
|
140
140
|
|
|
141
141
|
var Base64Utils = __importStar(require("./base64"));
|
|
142
142
|
|
|
143
|
-
exports.Base64Utils = Base64Utils;
|
|
143
|
+
exports.Base64Utils = Base64Utils;
|
|
144
|
+
|
|
145
|
+
var statck_1 = require("./statck");
|
|
146
|
+
|
|
147
|
+
Object.defineProperty(exports, "HistoryStack", {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function get() {
|
|
150
|
+
return statck_1.HistoryStack;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.HistoryStack = void 0;
|
|
7
|
+
|
|
8
|
+
var HistoryStack =
|
|
9
|
+
/** @class */
|
|
10
|
+
function () {
|
|
11
|
+
function HistoryStack(len) {
|
|
12
|
+
if (len === void 0) {
|
|
13
|
+
len = 10;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
this.stack = [];
|
|
17
|
+
this.len = 10;
|
|
18
|
+
this.point = -1;
|
|
19
|
+
this.len = len;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Object.defineProperty(HistoryStack.prototype, "current", {
|
|
23
|
+
get: function get() {
|
|
24
|
+
if (this.point < this.stack.length && this.point > -1) {
|
|
25
|
+
return this.stack[this.point];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return undefined;
|
|
29
|
+
},
|
|
30
|
+
enumerable: false,
|
|
31
|
+
configurable: true
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
HistoryStack.prototype.push = function (item) {
|
|
35
|
+
if (this.point > -1) {
|
|
36
|
+
this.stack.splice(0, this.point + 1);
|
|
37
|
+
this.point = -1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this.stack.unshift(item);
|
|
41
|
+
|
|
42
|
+
if (this.stack.length > this.len) {
|
|
43
|
+
this.stack.pop();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
HistoryStack.prototype.back = function () {
|
|
48
|
+
if (this.point < this.stack.length - 1) {
|
|
49
|
+
this.point += 1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return this.current;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
HistoryStack.prototype.forward = function () {
|
|
56
|
+
if (this.point > 0) {
|
|
57
|
+
this.point -= 1;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return this.current;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return HistoryStack;
|
|
64
|
+
}();
|
|
65
|
+
|
|
66
|
+
exports.HistoryStack = HistoryStack;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
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": "
|
|
21
|
+
"gitHead": "9b3ea07fafc516d4b3330a402820eb80d4b76092"
|
|
22
22
|
}
|