pubo-utils 1.0.94 → 1.0.98
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/factory/index.d.ts +6 -0
- package/es/factory/index.js +6 -0
- package/es/filter/sensor.d.ts +17 -0
- package/es/filter/sensor.js +26 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/loop/index.d.ts +16 -0
- package/es/loop/index.js +16 -0
- package/es/random/index.d.ts +12 -0
- package/es/random/index.js +12 -0
- package/es/sleep/index.d.ts +6 -0
- package/es/sleep/index.js +6 -0
- package/lib/factory/index.d.ts +6 -0
- package/lib/factory/index.js +6 -0
- package/lib/filter/sensor.d.ts +17 -0
- package/lib/filter/sensor.js +27 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +7 -1
- package/lib/loop/index.d.ts +16 -0
- package/lib/loop/index.js +16 -0
- package/lib/random/index.d.ts +12 -0
- package/lib/random/index.js +12 -0
- package/lib/sleep/index.d.ts +6 -0
- package/lib/sleep/index.js +6 -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,(()=>(()=>{"use strict";var t={d:(n,e)=>{for(var r in e)t.o(e,r)&&!t.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:e[r]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},n={};t.r(n),t.d(n,{Base64Utils:()=>e,ContinuousTrigger:()=>O,Emitter:()=>d,HistoryStack:()=>_,Level:()=>I,RegExpList:()=>K,SensorDataFilter:()=>W,SyncQueue:()=>A,WatchDog:()=>N,callbackToPromise:()=>D,concatArray:()=>Q,debounce:()=>i,degrees:()=>U,filterKeyPoints:()=>X,getAngle:()=>C,getCenter:()=>B,getDistance:()=>G,getRotate:()=>H,hex2rgb:()=>a,loop:()=>x,radians:()=>q,random:()=>s,randomRangeNum:()=>f,sleep:()=>g,superFactory:()=>b,throttle:()=>P,waitFor:()=>S});var e={};t.r(e),t.d(e,{EncoderMap:()=>E,toUnit8Array:()=>R});var r=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(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},i=function(t,n,e){if(void 0===e&&(e=!1),e){var i,u=!0;return function(){for(var e=[],a=0;a<arguments.length;a++)e[a]=arguments[a];u&&(t.apply(void 0,o([],r(e),!1)),u=!1),i&&clearTimeout(i),i=setTimeout((function(){return u=!0}),n)}}var a;return function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];a&&clearTimeout(a),a=setTimeout((function(){return t.apply(void 0,o([],r(e),!1))}),n)}},u=function(t){return parseInt(t.replace("#",""),16)},a=function(t){var n=("string"==typeof t?u(t):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)]},c=function(t){return"#"+[0,1,2].map((function(n){return t[n].toString(16)})).join("")},l=(function(){function t(t){"number"==typeof t?this.int=t:"string"==typeof t?this.int=u(t):Array.isArray(t)&&(this.int=u(c(t)))}t.prototype.getRgbArray=function(){return a(this.int)},Object.defineProperty(t.prototype,"rgb",{get:function(){return"rba(".concat(this.getRgbArray().join(", "),")")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hex",{get:function(){return c(this.getRgbArray())},enumerable:!1,configurable:!0}),t.prototype.toString=function(t){return void 0===t&&(t="hex"),"rgb"===t?this.rgb:this.hex}}(),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}),s=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},f=function(t){var n=Math.abs(t[1]-t[0]);return Math.random()*n+Math.min.apply(Math,function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))}([],l(t),!1))},h=function(){return h=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},h.apply(this,arguments)},p=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.")},y=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},v=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},d=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=s(40);return this.ids[r]={event:t,index:e},r},t.prototype.cancel=function(t){var n=this;if(t){var e=this.ids[t]||{},r=e.event,o=e.index;r&&Array.isArray(this.state[r])&&(this.state[r].splice(o,1),delete this.ids[t],Object.keys(this.ids).forEach((function(t){n.ids[t].event===r&&n.ids[t].index>o&&(n.ids[t].index=n.ids[t].index-1)})))}else this.clear()},t.prototype.clear=function(){this.state.length=0},t.prototype.emit=function(t){for(var n,e,r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];if(Array.isArray(this.state[t]))try{for(var i=p(this.state[t]),u=i.next();!u.done;u=i.next()){var a=u.value;"function"==typeof a&&a.apply(void 0,v([],y(r),!1))}}catch(t){n={error:t}}finally{try{u&&!u.done&&(e=i.return)&&e.call(i)}finally{if(n)throw n.error}}},t.prototype.clone=function(){return{state:h({},this.state),ids:h({},this.ids)}},t.prototype.restore=function(t){this.state=t.state,this.ids=t.ids},t}(),b=function(t){return function(n){var e,r,o={};try{for(var i=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.")}(Object.keys(n)),u=i.next();!u.done;u=i.next()){var a=u.value;o[a]=t(n[a],a)}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return o}},g=function(t){return n=void 0,e=void 0,o=function(){return 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:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(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]}}))},new((r=void 0)||(r=Promise))((function(t,i){function u(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(n){var e;n.done?t(n.value):(e=n.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,a)}c((o=o.apply(n,e||[])).next())}));var n,e,r,o},m=function(t,n,e,r){return new(e||(e=Promise))((function(o,i){function u(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,a)}c((r=r.apply(t,n||[])).next())}))},w=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:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},x=function(t,n){var e=!0,r=function(){e=!1},o=function(){return m(void 0,void 0,void 0,(function(){return w(this,(function(i){switch(i.label){case 0:return[4,t(r)];case 1:return i.sent(),[4,g(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=x((function(){return m(void 0,void 0,void 0,(function(){var e;return w(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{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var n;t.done?o(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,a)}c((r=r.apply(t,n||[])).next())}))},k=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:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},A=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 k(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 k(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}(),j=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},M=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))};function P(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,M([],j(o),!1)))}}var O=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}(),E=function(){for(var t={},n=0;n<64;n++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n)]=n;return t}();function R(t){for(var n=new Uint8Array(6*t.length/8),e=0,r=0,o=0,i=0;i<t.length&&o<n.length;i+=1)if(r=(r<<6)+E[t.charAt(i)],(e+=6)>=8){var u=r>>>(e-=8);n[o++]=255&u,r-=u<<=e}return n}var _=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-1&&(this.point+=1),this.current},t.prototype.redo=function(){return this.point>0&&(this.point-=1),this.current},t}(),N=function(){function t(t){var n=t.limit,e=void 0===n?10:n,r=t.onTimeout;this.limit=10,this.timeout=null,this.limit=e,this.onTimeout=r}return t.prototype.feed=function(){this.init()},t.prototype.init=function(){var t=this;clearTimeout(this.timeout),this.timeout=setTimeout((function(){return t.onTimeout()}),1e3*this.limit)},t.prototype.stop=function(){this.timeout&&clearTimeout(this.timeout)},t}(),I=function(){function t(t){this.config=t,this.step=(this.config.max-this.config.min)/(this.config.count-2)}return t.prototype.get=function(t){if(t<=this.config.min)return 1;if(t>=this.config.max)return this.config.count;for(var n=2,e=this.config.min+this.step;e<this.config.max+this.step;e+=this.step,n+=1)if(t<e)return n;return this.config.count},t}(),L=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},z=function(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))},D=function(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return new Promise((function(e,r){t.apply(void 0,z(z([],L(n),!1),[function(t){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];t&&r(t),n.length<2?e(n[0]):e(z([],L(n),!1))}],!1))}))}},F=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.")},G=function(t,n){return Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2))},U=function(t){return 180*t/Math.PI},q=function(t){return t*Math.PI/180},C=function(t){var n,e=t.w,r=t.h,o=U(Math.asin(r/Math.sqrt(Math.pow(e,2)+Math.pow(r,2))));return(n=e<=0?180-o:o>0?o:360+o)<-180&&(n+=360),n>180&&(n-=360),n};function X(t,n){return void 0===n&&(n=.5),t.length<3||n<=0?t:t.filter((function(r,o){return!(o>0&&G(e,r)<n||(e=t[o],0))}));var e}function B(t){var n,e,r=[0,0];try{for(var o=F(t),i=o.next();!i.done;i=o.next()){var u=i.value;Array.isArray(u)?(r[0]+=u[0],r[1]+=u[1]):(r[0]+=u.x,r[1]+=u.y)}}catch(t){n={error:t}}finally{try{i&&!i.done&&(e=o.return)&&e.call(o)}finally{if(n)throw n.error}}return{x:r[0]/t.length,y:r[1]/t.length}}function H(t,n){return[Math.cos(n)*t[0]-Math.sin(n)*t[1],Math.sin(n)*t[0]+Math.cos(n)*t[1]]}var K=function(){function t(t){this._RegExpList=null,this.list=t}return t.prototype.getRegEXP=function(t){var n=t.replace("/","\\/").replace("*",".*");return new RegExp(n)},t.prototype.include=function(t){return this._RegExpList||(this._RegExpList=this.list.map(this.getRegEXP)),this._RegExpList.some((function(n){return n.test(t)}))},t}(),Q=function(t,n){void 0===n&&(n=Array);for(var e=t.map((function(t){return t.length})).reduce((function(t,n){return t+n}),0),r=new n(e),o=0,i=0,u=0;u<e;)o<t[i].length?(r[u]=t[i][o],o+=1,u+=1):(i+=1,o=0);return r},W=function(){function t(t){var n=void 0===t?{}:t,e=n.size,r=void 0===e?5:e,o=n.step,i=void 0===o?5:o,u=n.min,a=void 0===u?-1/0:u,c=n.max,l=void 0===c?1/0:c;this.tmp=[],this.count=0,this.value=NaN,this.size=r,this.step=i,this.min=a,this.max=l}return t.prototype.filter=function(t){return t<this.min||t>this.max||(this.tmp.push(t),this.old=this.calc(t)),this.old},t.prototype.calc=function(t){if(this.tmp.length<1)return t;this.tmp.length>this.size&&this.tmp.shift();var n=this.getMostNumberOfTmp(),e=n.res,r=n.dic;return e!==t&&Math.abs(e-t)>this.step?(this.value!==t?this.count=1:this.count+=1,this.value=t,this.count>r[e]?(this.tmp.length=0,this.tmp.push(t),t):e):(this.count=0,this.value=NaN,t)},t.prototype.getMostNumberOfTmp=function(){var t,n,e,r={},o=0;try{for(var i=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.")}(this.tmp),u=i.next();!u.done;u=i.next()){var a=u.value;r[a]?r[a]+=1:r[a]=1,r[a]>o&&(o=r[a],e=a)}}catch(n){t={error:n}}finally{try{u&&!u.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return{res:e,dic:r}},t}();return n})()));
|
|
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,(()=>(()=>{"use strict";var t={d:(n,e)=>{for(var r in e)t.o(e,r)&&!t.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:e[r]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},n={};t.r(n),t.d(n,{Base64Utils:()=>e,ContinuousTrigger:()=>O,Emitter:()=>d,HistoryStack:()=>R,Level:()=>I,RegExpList:()=>K,SensorDataFilter:()=>W,StringSplit:()=>J,SyncQueue:()=>A,WatchDog:()=>N,callbackToPromise:()=>D,concatArray:()=>Q,debounce:()=>o,degrees:()=>U,filterKeyPoints:()=>X,getAngle:()=>C,getCenter:()=>B,getDistance:()=>G,getRotate:()=>H,hex2rgb:()=>a,loop:()=>x,radians:()=>q,random:()=>s,randomRangeNum:()=>f,sleep:()=>g,superFactory:()=>b,throttle:()=>P,waitFor:()=>S});var e={};t.r(e),t.d(e,{EncoderMap:()=>E,toUnit8Array:()=>_});var r=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,i,o=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=o.next()).done;)u.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(e=o.return)&&e.call(o)}finally{if(i)throw i.error}}return u},i=function(t,n,e){if(e||2===arguments.length)for(var r,i=0,o=n.length;i<o;i++)!r&&i in n||(r||(r=Array.prototype.slice.call(n,0,i)),r[i]=n[i]);return t.concat(r||Array.prototype.slice.call(n))},o=function(t,n,e){if(void 0===e&&(e=!1),e){var o,u=!0;return function(){for(var e=[],a=0;a<arguments.length;a++)e[a]=arguments[a];u&&(t.apply(void 0,i([],r(e),!1)),u=!1),o&&clearTimeout(o),o=setTimeout((function(){return u=!0}),n)}}var a;return function(){for(var e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];a&&clearTimeout(a),a=setTimeout((function(){return t.apply(void 0,i([],r(e),!1))}),n)}},u=function(t){return parseInt(t.replace("#",""),16)},a=function(t){var n=("string"==typeof t?u(t):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)]},c=function(t){return"#"+[0,1,2].map((function(n){return t[n].toString(16)})).join("")},l=(function(){function t(t){"number"==typeof t?this.int=t:"string"==typeof t?this.int=u(t):Array.isArray(t)&&(this.int=u(c(t)))}t.prototype.getRgbArray=function(){return a(this.int)},Object.defineProperty(t.prototype,"rgb",{get:function(){return"rba(".concat(this.getRgbArray().join(", "),")")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hex",{get:function(){return c(this.getRgbArray())},enumerable:!1,configurable:!0}),t.prototype.toString=function(t){return void 0===t&&(t="hex"),"rgb"===t?this.rgb:this.hex}}(),function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,i,o=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=o.next()).done;)u.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(e=o.return)&&e.call(o)}finally{if(i)throw i.error}}return u}),s=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},f=function(t){var n=Math.abs(t[1]-t[0]);return Math.random()*n+Math.min.apply(Math,function(t,n,e){if(e||2===arguments.length)for(var r,i=0,o=n.length;i<o;i++)!r&&i in n||(r||(r=Array.prototype.slice.call(n,0,i)),r[i]=n[i]);return t.concat(r||Array.prototype.slice.call(n))}([],l(t),!1))},h=function(){return h=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var i in n=arguments[e])Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i]);return t},h.apply(this,arguments)},p=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.")},y=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,i,o=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=o.next()).done;)u.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(e=o.return)&&e.call(o)}finally{if(i)throw i.error}}return u},v=function(t,n,e){if(e||2===arguments.length)for(var r,i=0,o=n.length;i<o;i++)!r&&i in n||(r||(r=Array.prototype.slice.call(n,0,i)),r[i]=n[i]);return t.concat(r||Array.prototype.slice.call(n))},d=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=s(40);return this.ids[r]={event:t,index:e},r},t.prototype.cancel=function(t){var n=this;if(t){var e=this.ids[t]||{},r=e.event,i=e.index;r&&Array.isArray(this.state[r])&&(this.state[r].splice(i,1),delete this.ids[t],Object.keys(this.ids).forEach((function(t){n.ids[t].event===r&&n.ids[t].index>i&&(n.ids[t].index=n.ids[t].index-1)})))}else this.clear()},t.prototype.clear=function(){this.state.length=0},t.prototype.emit=function(t){for(var n,e,r=[],i=1;i<arguments.length;i++)r[i-1]=arguments[i];if(Array.isArray(this.state[t]))try{for(var o=p(this.state[t]),u=o.next();!u.done;u=o.next()){var a=u.value;"function"==typeof a&&a.apply(void 0,v([],y(r),!1))}}catch(t){n={error:t}}finally{try{u&&!u.done&&(e=o.return)&&e.call(o)}finally{if(n)throw n.error}}},t.prototype.clone=function(){return{state:h({},this.state),ids:h({},this.ids)}},t.prototype.restore=function(t){this.state=t.state,this.ids=t.ids},t}(),b=function(t){return function(n){var e,r,i={};try{for(var o=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.")}(Object.keys(n)),u=o.next();!u.done;u=o.next()){var a=u.value;i[a]=t(n[a],a)}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return i}},g=function(t){return n=void 0,e=void 0,i=function(){return function(t,n){var e,r,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((i=(i=u.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){u.label=a[1];break}if(6===a[0]&&u.label<i[1]){u.label=i[1],i=a;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(a);break}i[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}(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]}}))},new((r=void 0)||(r=Promise))((function(t,o){function u(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(n){var e;n.done?t(n.value):(e=n.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,a)}c((i=i.apply(n,e||[])).next())}));var n,e,r,i},m=function(t,n,e,r){return new(e||(e=Promise))((function(i,o){function u(t){try{c(r.next(t))}catch(t){o(t)}}function a(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var n;t.done?i(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,a)}c((r=r.apply(t,n||[])).next())}))},w=function(t,n){var e,r,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((i=(i=u.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){u.label=a[1];break}if(6===a[0]&&u.label<i[1]){u.label=i[1],i=a;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(a);break}i[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},x=function(t,n){var e=!0,r=function(){e=!1},i=function(){return m(void 0,void 0,void 0,(function(){return w(this,(function(o){switch(o.label){case 0:return[4,t(r)];case 1:return o.sent(),[4,g(n)];case 2:return o.sent(),e?i():i=null,[2]}}))}))};return i(),r},S=function(t,n){var e=void 0===n?{}:n,r=e.checkTime,i=e.timeout;return new Promise((function(n,e){var o=x((function(){return m(void 0,void 0,void 0,(function(){var e;return w(this,(function(r){switch(r.label){case 0:return[4,t()];case 1:return(e=r.sent())&&(o(),n(e)),[2]}}))}))}),r||100);i&&setTimeout((function(){o(),e("timeout")}),i)}))},T=function(t,n,e,r){return new(e||(e=Promise))((function(i,o){function u(t){try{c(r.next(t))}catch(t){o(t)}}function a(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var n;t.done?i(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,a)}c((r=r.apply(t,n||[])).next())}))},k=function(t,n){var e,r,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((i=(i=u.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){u.label=a[1];break}if(6===a[0]&&u.label<i[1]){u.label=i[1],i=a;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(a);break}i[2]&&u.ops.pop(),u.trys.pop();continue}a=n.call(t,u)}catch(t){a=[6,t],r=0}finally{e=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},A=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 k(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,n()];case 1:return t=i.sent(),e.resolve(t),[3,3];case 2:return r=i.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 k(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}(),j=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,i,o=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=o.next()).done;)u.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(e=o.return)&&e.call(o)}finally{if(i)throw i.error}}return u},M=function(t,n,e){if(e||2===arguments.length)for(var r,i=0,o=n.length;i<o;i++)!r&&i in n||(r||(r=Array.prototype.slice.call(n,0,i)),r[i]=n[i]);return t.concat(r||Array.prototype.slice.call(n))};function P(t,n){var e,r=!0;return function(){for(var i=[],o=0;o<arguments.length;o++)i[o]=arguments[o];e||(e=setTimeout((function(){r=!0,e=null}),n)),r&&(r=!1,t.apply(void 0,M([],j(i),!1)))}}var O=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}(),E=function(){for(var t={},n=0;n<64;n++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n)]=n;return t}();function _(t){for(var n=new Uint8Array(6*t.length/8),e=0,r=0,i=0,o=0;o<t.length&&i<n.length;o+=1)if(r=(r<<6)+E[t.charAt(o)],(e+=6)>=8){var u=r>>>(e-=8);n[i++]=255&u,r-=u<<=e}return n}var R=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-1&&(this.point+=1),this.current},t.prototype.redo=function(){return this.point>0&&(this.point-=1),this.current},t}(),N=function(){function t(t){var n=t.limit,e=void 0===n?10:n,r=t.onTimeout;this.limit=10,this.timeout=null,this.limit=e,this.onTimeout=r}return t.prototype.feed=function(){this.init()},t.prototype.init=function(){var t=this;clearTimeout(this.timeout),this.timeout=setTimeout((function(){return t.onTimeout()}),1e3*this.limit)},t.prototype.stop=function(){this.timeout&&clearTimeout(this.timeout)},t}(),I=function(){function t(t){this.config=t,this.step=(this.config.max-this.config.min)/(this.config.count-2)}return t.prototype.get=function(t){if(t<=this.config.min)return 1;if(t>=this.config.max)return this.config.count;for(var n=2,e=this.config.min+this.step;e<this.config.max+this.step;e+=this.step,n+=1)if(t<e)return n;return this.config.count},t}(),L=function(t,n){var e="function"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,i,o=e.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(r=o.next()).done;)u.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(e=o.return)&&e.call(o)}finally{if(i)throw i.error}}return u},z=function(t,n,e){if(e||2===arguments.length)for(var r,i=0,o=n.length;i<o;i++)!r&&i in n||(r||(r=Array.prototype.slice.call(n,0,i)),r[i]=n[i]);return t.concat(r||Array.prototype.slice.call(n))},D=function(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return new Promise((function(e,r){t.apply(void 0,z(z([],L(n),!1),[function(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];t&&r(t),n.length<2?e(n[0]):e(z([],L(n),!1))}],!1))}))}},F=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.")},G=function(t,n){return Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2))},U=function(t){return 180*t/Math.PI},q=function(t){return t*Math.PI/180},C=function(t){var n,e=t.w,r=t.h,i=U(Math.asin(r/Math.sqrt(Math.pow(e,2)+Math.pow(r,2))));return(n=e<=0?180-i:i>0?i:360+i)<-180&&(n+=360),n>180&&(n-=360),n};function X(t,n){return void 0===n&&(n=.5),t.length<3||n<=0?t:t.filter((function(r,i){return!(i>0&&G(e,r)<n||(e=t[i],0))}));var e}function B(t){var n,e,r=[0,0];try{for(var i=F(t),o=i.next();!o.done;o=i.next()){var u=o.value;Array.isArray(u)?(r[0]+=u[0],r[1]+=u[1]):(r[0]+=u.x,r[1]+=u.y)}}catch(t){n={error:t}}finally{try{o&&!o.done&&(e=i.return)&&e.call(i)}finally{if(n)throw n.error}}return{x:r[0]/t.length,y:r[1]/t.length}}function H(t,n){return[Math.cos(n)*t[0]-Math.sin(n)*t[1],Math.sin(n)*t[0]+Math.cos(n)*t[1]]}var K=function(){function t(t){this._RegExpList=null,this.list=t}return t.prototype.getRegEXP=function(t){var n=t.replace("/","\\/").replace("*",".*");return new RegExp(n)},t.prototype.include=function(t){return this._RegExpList||(this._RegExpList=this.list.map(this.getRegEXP)),this._RegExpList.some((function(n){return n.test(t)}))},t}(),Q=function(t,n){void 0===n&&(n=Array);for(var e=t.map((function(t){return t.length})).reduce((function(t,n){return t+n}),0),r=new n(e),i=0,o=0,u=0;u<e;)i<t[o].length?(r[u]=t[o][i],i+=1,u+=1):(o+=1,i=0);return r},W=function(){function t(t){var n=void 0===t?{}:t,e=n.size,r=void 0===e?5:e,i=n.step,o=void 0===i?5:i,u=n.min,a=void 0===u?-1/0:u,c=n.max,l=void 0===c?1/0:c;this.tmp=[],this.count=0,this.value=NaN,this.size=r,this.step=o,this.min=a,this.max=l}return t.prototype.filter=function(t){return t<this.min||t>this.max||(this.tmp.push(t),this.old=this.calc(t)),this.old},t.prototype.calc=function(t){if(this.tmp.length<1)return t;this.tmp.length>this.size&&this.tmp.shift();var n=this.getMostNumberOfTmp(),e=n.res,r=n.dic;return e!==t&&Math.abs(e-t)>this.step?(this.value!==t?this.count=1:this.count+=1,this.value=t,this.count>r[e]?(this.tmp.length=0,this.tmp.push(t),t):e):(this.count=0,this.value=NaN,t)},t.prototype.getMostNumberOfTmp=function(){var t,n,e,r={},i=0;try{for(var o=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.")}(this.tmp),u=o.next();!u.done;u=o.next()){var a=u.value;r[a]?r[a]+=1:r[a]=1,r[a]>i&&(i=r[a],e=a)}}catch(n){t={error:n}}finally{try{u&&!u.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}return{res:e,dic:r}},t}(),J=function(){function t(t){this._cache="",this._splitSymbol=t}return t.prototype.split=function(t){var n=(this._cache+t).split(this._splitSymbol);return this._cache=n.splice(n.length-1,1)[0],n},t}();return n})()));
|
package/es/factory/index.d.ts
CHANGED
|
@@ -7,5 +7,11 @@ type ProductsObject<T, F> = {
|
|
|
7
7
|
type Factory<C> = (config: C, key: string) => any;
|
|
8
8
|
export type CreateFactory<C, F> = <T>(apis: OptionsObject<T, C>) => ProductsObject<T, F>;
|
|
9
9
|
export type SuperFactory = <C, F>(factory: Factory<C>) => CreateFactory<C, F>;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a factory function that takes another factory function and returns a new function that creates a product object based on the options passed in.
|
|
12
|
+
*
|
|
13
|
+
* @param {SuperFactory} factory - the factory function to be used in creating the product object
|
|
14
|
+
* @return {(options: any) => any} the new factory function that creates the product object
|
|
15
|
+
*/
|
|
10
16
|
export declare const superFactory: SuperFactory;
|
|
11
17
|
export {};
|
package/es/factory/index.js
CHANGED
|
@@ -14,6 +14,12 @@ var __values = this && this.__values || function (o) {
|
|
|
14
14
|
};
|
|
15
15
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Creates a factory function that takes another factory function and returns a new function that creates a product object based on the options passed in.
|
|
19
|
+
*
|
|
20
|
+
* @param {SuperFactory} factory - the factory function to be used in creating the product object
|
|
21
|
+
* @return {(options: any) => any} the new factory function that creates the product object
|
|
22
|
+
*/
|
|
17
23
|
export var superFactory = function superFactory(factory) {
|
|
18
24
|
return function (options) {
|
|
19
25
|
var e_1, _a;
|
package/es/filter/sensor.d.ts
CHANGED
|
@@ -15,5 +15,22 @@ export declare class SensorDataFilter {
|
|
|
15
15
|
});
|
|
16
16
|
filter(n: number): number;
|
|
17
17
|
private calc;
|
|
18
|
+
/**
|
|
19
|
+
* A function to calculate the most frequent element in the 'tmp' array and its frequency.
|
|
20
|
+
*
|
|
21
|
+
* @return {object} An object containing the most frequent element and its frequency.
|
|
22
|
+
*/
|
|
18
23
|
private getMostNumberOfTmp;
|
|
19
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Splits the input string using the specified split symbol and returns an array of substrings.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} str - the input string to be split
|
|
29
|
+
* @return {string[]} an array of substrings
|
|
30
|
+
*/
|
|
31
|
+
export declare class StringSplit {
|
|
32
|
+
private readonly _splitSymbol;
|
|
33
|
+
private _cache;
|
|
34
|
+
constructor(splitSymbol: string);
|
|
35
|
+
split(str: string): string[];
|
|
36
|
+
}
|
package/es/filter/sensor.js
CHANGED
|
@@ -80,6 +80,11 @@ var SensorDataFilter = /** @class */function () {
|
|
|
80
80
|
}
|
|
81
81
|
return res;
|
|
82
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* A function to calculate the most frequent element in the 'tmp' array and its frequency.
|
|
85
|
+
*
|
|
86
|
+
* @return {object} An object containing the most frequent element and its frequency.
|
|
87
|
+
*/
|
|
83
88
|
SensorDataFilter.prototype.getMostNumberOfTmp = function () {
|
|
84
89
|
var e_1, _a;
|
|
85
90
|
var a = {};
|
|
@@ -116,4 +121,24 @@ var SensorDataFilter = /** @class */function () {
|
|
|
116
121
|
};
|
|
117
122
|
return SensorDataFilter;
|
|
118
123
|
}();
|
|
119
|
-
export { SensorDataFilter };
|
|
124
|
+
export { SensorDataFilter };
|
|
125
|
+
/**
|
|
126
|
+
* Splits the input string using the specified split symbol and returns an array of substrings.
|
|
127
|
+
*
|
|
128
|
+
* @param {string} str - the input string to be split
|
|
129
|
+
* @return {string[]} an array of substrings
|
|
130
|
+
*/
|
|
131
|
+
var StringSplit = /** @class */function () {
|
|
132
|
+
function StringSplit(splitSymbol) {
|
|
133
|
+
this._cache = '';
|
|
134
|
+
this._splitSymbol = splitSymbol;
|
|
135
|
+
}
|
|
136
|
+
StringSplit.prototype.split = function (str) {
|
|
137
|
+
var tmp = this._cache + str;
|
|
138
|
+
var arr = tmp.split(this._splitSymbol);
|
|
139
|
+
this._cache = arr.splice(arr.length - 1, 1)[0];
|
|
140
|
+
return arr;
|
|
141
|
+
};
|
|
142
|
+
return StringSplit;
|
|
143
|
+
}();
|
|
144
|
+
export { StringSplit };
|
package/es/index.d.ts
CHANGED
|
@@ -16,4 +16,4 @@ export { callbackToPromise } from './promise';
|
|
|
16
16
|
export { getAngle, getDistance, getCenter, degrees, radians, filterKeyPoints, getRotate } from './math/geometry';
|
|
17
17
|
export { RegExpList } from './regexp-list';
|
|
18
18
|
export { concatArray } from './array';
|
|
19
|
-
export { SensorDataFilter } from './filter/sensor';
|
|
19
|
+
export { SensorDataFilter, StringSplit } from './filter/sensor';
|
package/es/index.js
CHANGED
|
@@ -17,4 +17,4 @@ export { callbackToPromise } from './promise';
|
|
|
17
17
|
export { getAngle, getDistance, getCenter, degrees, radians, filterKeyPoints, getRotate } from './math/geometry';
|
|
18
18
|
export { RegExpList } from './regexp-list';
|
|
19
19
|
export { concatArray } from './array';
|
|
20
|
-
export { SensorDataFilter } from './filter/sensor';
|
|
20
|
+
export { SensorDataFilter, StringSplit } from './filter/sensor';
|
package/es/loop/index.d.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes the given callback function in a loop with the specified time interval.
|
|
3
|
+
*
|
|
4
|
+
* @param {Function} cb - The callback function to be executed in the loop. It takes a stop function as a parameter.
|
|
5
|
+
* @param {number} time - The time interval in milliseconds for the loop.
|
|
6
|
+
* @return {Function} The stop function that can be used to stop the loop.
|
|
7
|
+
*/
|
|
1
8
|
export declare const loop: (cb: (stop: () => void) => Promise<void>, time: number) => () => void;
|
|
2
9
|
type WaitForBool = () => boolean | Promise<boolean>;
|
|
10
|
+
/**
|
|
11
|
+
* Waits for a boolean condition to be true, with optional timeouts for the check and the overall wait.
|
|
12
|
+
*
|
|
13
|
+
* @param {WaitForBool} bool - the boolean condition to wait for
|
|
14
|
+
* @param {Object} options - optional parameters for checkTime and timeout
|
|
15
|
+
* @param {number} options.checkTime - the time interval for checking the boolean condition (default is 100)
|
|
16
|
+
* @param {number} options.timeout - the maximum time to wait for the boolean condition to be true
|
|
17
|
+
* @return {Promise<any>} a promise that resolves when the boolean condition is true or rejects with 'timeout' if the timeout is reached
|
|
18
|
+
*/
|
|
3
19
|
export declare const waitFor: (bool: WaitForBool, { checkTime, timeout }?: {
|
|
4
20
|
checkTime?: number | undefined;
|
|
5
21
|
timeout?: number | undefined;
|
package/es/loop/index.js
CHANGED
|
@@ -114,6 +114,13 @@ var __generator = this && this.__generator || function (thisArg, body) {
|
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
import { sleep } from '../sleep';
|
|
117
|
+
/**
|
|
118
|
+
* Executes the given callback function in a loop with the specified time interval.
|
|
119
|
+
*
|
|
120
|
+
* @param {Function} cb - The callback function to be executed in the loop. It takes a stop function as a parameter.
|
|
121
|
+
* @param {number} time - The time interval in milliseconds for the loop.
|
|
122
|
+
* @return {Function} The stop function that can be used to stop the loop.
|
|
123
|
+
*/
|
|
117
124
|
export var loop = function loop(cb, time) {
|
|
118
125
|
var onOff = true;
|
|
119
126
|
var stop = function stop() {
|
|
@@ -144,6 +151,15 @@ export var loop = function loop(cb, time) {
|
|
|
144
151
|
_fn();
|
|
145
152
|
return stop;
|
|
146
153
|
};
|
|
154
|
+
/**
|
|
155
|
+
* Waits for a boolean condition to be true, with optional timeouts for the check and the overall wait.
|
|
156
|
+
*
|
|
157
|
+
* @param {WaitForBool} bool - the boolean condition to wait for
|
|
158
|
+
* @param {Object} options - optional parameters for checkTime and timeout
|
|
159
|
+
* @param {number} options.checkTime - the time interval for checking the boolean condition (default is 100)
|
|
160
|
+
* @param {number} options.timeout - the maximum time to wait for the boolean condition to be true
|
|
161
|
+
* @return {Promise<any>} a promise that resolves when the boolean condition is true or rejects with 'timeout' if the timeout is reached
|
|
162
|
+
*/
|
|
147
163
|
export var waitFor = function waitFor(bool, _a) {
|
|
148
164
|
var _b = _a === void 0 ? {} : _a,
|
|
149
165
|
checkTime = _b.checkTime,
|
package/es/random/index.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a random string of specified length.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} n - The length of the random string to generate
|
|
5
|
+
* @return {string} The randomly generated string
|
|
6
|
+
*/
|
|
1
7
|
export declare const random: (n?: number) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Generates a random number within the specified range.
|
|
10
|
+
*
|
|
11
|
+
* @param {number[]} range - The range within which to generate the random number.
|
|
12
|
+
* @return {number} The randomly generated number within the specified range.
|
|
13
|
+
*/
|
|
2
14
|
export declare const randomRangeNum: (range: any) => number;
|
package/es/random/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a random string of specified length.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} n - The length of the random string to generate
|
|
5
|
+
* @return {string} The randomly generated string
|
|
6
|
+
*/
|
|
1
7
|
var __read = this && this.__read || function (o, n) {
|
|
2
8
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
9
|
if (!m) return o;
|
|
@@ -49,6 +55,12 @@ export var random = function random(n) {
|
|
|
49
55
|
}
|
|
50
56
|
return res;
|
|
51
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* Generates a random number within the specified range.
|
|
60
|
+
*
|
|
61
|
+
* @param {number[]} range - The range within which to generate the random number.
|
|
62
|
+
* @return {number} The randomly generated number within the specified range.
|
|
63
|
+
*/
|
|
52
64
|
export var randomRangeNum = function randomRangeNum(range) {
|
|
53
65
|
var size = Math.abs(range[1] - range[0]);
|
|
54
66
|
return Math.random() * size + Math.min.apply(Math, __spreadArray([], __read(range), false));
|
package/es/sleep/index.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronous function to sleep for a specified amount of time.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} time - The duration in milliseconds to sleep
|
|
5
|
+
* @return {Promise<void>} A promise that resolves after the specified time
|
|
6
|
+
*/
|
|
1
7
|
export declare const sleep: (time: number) => Promise<void>;
|
package/es/sleep/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronous function to sleep for a specified amount of time.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} time - The duration in milliseconds to sleep
|
|
5
|
+
* @return {Promise<void>} A promise that resolves after the specified time
|
|
6
|
+
*/
|
|
1
7
|
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
8
|
function adopt(value) {
|
|
3
9
|
return value instanceof P ? value : new P(function (resolve) {
|
package/lib/factory/index.d.ts
CHANGED
|
@@ -7,5 +7,11 @@ type ProductsObject<T, F> = {
|
|
|
7
7
|
type Factory<C> = (config: C, key: string) => any;
|
|
8
8
|
export type CreateFactory<C, F> = <T>(apis: OptionsObject<T, C>) => ProductsObject<T, F>;
|
|
9
9
|
export type SuperFactory = <C, F>(factory: Factory<C>) => CreateFactory<C, F>;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a factory function that takes another factory function and returns a new function that creates a product object based on the options passed in.
|
|
12
|
+
*
|
|
13
|
+
* @param {SuperFactory} factory - the factory function to be used in creating the product object
|
|
14
|
+
* @return {(options: any) => any} the new factory function that creates the product object
|
|
15
|
+
*/
|
|
10
16
|
export declare const superFactory: SuperFactory;
|
|
11
17
|
export {};
|
package/lib/factory/index.js
CHANGED
|
@@ -20,6 +20,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
20
20
|
value: true
|
|
21
21
|
});
|
|
22
22
|
exports.superFactory = void 0;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a factory function that takes another factory function and returns a new function that creates a product object based on the options passed in.
|
|
25
|
+
*
|
|
26
|
+
* @param {SuperFactory} factory - the factory function to be used in creating the product object
|
|
27
|
+
* @return {(options: any) => any} the new factory function that creates the product object
|
|
28
|
+
*/
|
|
23
29
|
var superFactory = function superFactory(factory) {
|
|
24
30
|
return function (options) {
|
|
25
31
|
var e_1, _a;
|
package/lib/filter/sensor.d.ts
CHANGED
|
@@ -15,5 +15,22 @@ export declare class SensorDataFilter {
|
|
|
15
15
|
});
|
|
16
16
|
filter(n: number): number;
|
|
17
17
|
private calc;
|
|
18
|
+
/**
|
|
19
|
+
* A function to calculate the most frequent element in the 'tmp' array and its frequency.
|
|
20
|
+
*
|
|
21
|
+
* @return {object} An object containing the most frequent element and its frequency.
|
|
22
|
+
*/
|
|
18
23
|
private getMostNumberOfTmp;
|
|
19
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Splits the input string using the specified split symbol and returns an array of substrings.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} str - the input string to be split
|
|
29
|
+
* @return {string[]} an array of substrings
|
|
30
|
+
*/
|
|
31
|
+
export declare class StringSplit {
|
|
32
|
+
private readonly _splitSymbol;
|
|
33
|
+
private _cache;
|
|
34
|
+
constructor(splitSymbol: string);
|
|
35
|
+
split(str: string): string[];
|
|
36
|
+
}
|
package/lib/filter/sensor.js
CHANGED
|
@@ -19,7 +19,7 @@ var __values = this && this.__values || function (o) {
|
|
|
19
19
|
Object.defineProperty(exports, "__esModule", {
|
|
20
20
|
value: true
|
|
21
21
|
});
|
|
22
|
-
exports.SensorDataFilter = void 0;
|
|
22
|
+
exports.StringSplit = exports.SensorDataFilter = void 0;
|
|
23
23
|
// 过滤跳变数据
|
|
24
24
|
var SensorDataFilter = /** @class */function () {
|
|
25
25
|
function SensorDataFilter(_a) {
|
|
@@ -86,6 +86,11 @@ var SensorDataFilter = /** @class */function () {
|
|
|
86
86
|
}
|
|
87
87
|
return res;
|
|
88
88
|
};
|
|
89
|
+
/**
|
|
90
|
+
* A function to calculate the most frequent element in the 'tmp' array and its frequency.
|
|
91
|
+
*
|
|
92
|
+
* @return {object} An object containing the most frequent element and its frequency.
|
|
93
|
+
*/
|
|
89
94
|
SensorDataFilter.prototype.getMostNumberOfTmp = function () {
|
|
90
95
|
var e_1, _a;
|
|
91
96
|
var a = {};
|
|
@@ -122,4 +127,24 @@ var SensorDataFilter = /** @class */function () {
|
|
|
122
127
|
};
|
|
123
128
|
return SensorDataFilter;
|
|
124
129
|
}();
|
|
125
|
-
exports.SensorDataFilter = SensorDataFilter;
|
|
130
|
+
exports.SensorDataFilter = SensorDataFilter;
|
|
131
|
+
/**
|
|
132
|
+
* Splits the input string using the specified split symbol and returns an array of substrings.
|
|
133
|
+
*
|
|
134
|
+
* @param {string} str - the input string to be split
|
|
135
|
+
* @return {string[]} an array of substrings
|
|
136
|
+
*/
|
|
137
|
+
var StringSplit = /** @class */function () {
|
|
138
|
+
function StringSplit(splitSymbol) {
|
|
139
|
+
this._cache = '';
|
|
140
|
+
this._splitSymbol = splitSymbol;
|
|
141
|
+
}
|
|
142
|
+
StringSplit.prototype.split = function (str) {
|
|
143
|
+
var tmp = this._cache + str;
|
|
144
|
+
var arr = tmp.split(this._splitSymbol);
|
|
145
|
+
this._cache = arr.splice(arr.length - 1, 1)[0];
|
|
146
|
+
return arr;
|
|
147
|
+
};
|
|
148
|
+
return StringSplit;
|
|
149
|
+
}();
|
|
150
|
+
exports.StringSplit = StringSplit;
|
package/lib/index.d.ts
CHANGED
|
@@ -16,4 +16,4 @@ export { callbackToPromise } from './promise';
|
|
|
16
16
|
export { getAngle, getDistance, getCenter, degrees, radians, filterKeyPoints, getRotate } from './math/geometry';
|
|
17
17
|
export { RegExpList } from './regexp-list';
|
|
18
18
|
export { concatArray } from './array';
|
|
19
|
-
export { SensorDataFilter } from './filter/sensor';
|
|
19
|
+
export { SensorDataFilter, StringSplit } from './filter/sensor';
|
package/lib/index.js
CHANGED
|
@@ -34,7 +34,7 @@ var __importStar = this && this.__importStar || function (mod) {
|
|
|
34
34
|
Object.defineProperty(exports, "__esModule", {
|
|
35
35
|
value: true
|
|
36
36
|
});
|
|
37
|
-
exports.SensorDataFilter = exports.concatArray = exports.RegExpList = exports.getRotate = exports.filterKeyPoints = exports.radians = exports.degrees = exports.getCenter = exports.getDistance = exports.getAngle = exports.callbackToPromise = exports.Level = exports.WatchDog = exports.HistoryStack = exports.Base64Utils = exports.ContinuousTrigger = exports.throttle = exports.sleep = exports.randomRangeNum = exports.random = exports.SyncQueue = exports.waitFor = exports.loop = exports.superFactory = exports.Emitter = exports.hex2rgb = exports.debounce = void 0;
|
|
37
|
+
exports.StringSplit = exports.SensorDataFilter = exports.concatArray = exports.RegExpList = exports.getRotate = exports.filterKeyPoints = exports.radians = exports.degrees = exports.getCenter = exports.getDistance = exports.getAngle = exports.callbackToPromise = exports.Level = exports.WatchDog = exports.HistoryStack = exports.Base64Utils = exports.ContinuousTrigger = exports.throttle = exports.sleep = exports.randomRangeNum = exports.random = exports.SyncQueue = exports.waitFor = exports.loop = exports.superFactory = exports.Emitter = exports.hex2rgb = exports.debounce = void 0;
|
|
38
38
|
var debounce_1 = require("./debounce");
|
|
39
39
|
Object.defineProperty(exports, "debounce", {
|
|
40
40
|
enumerable: true,
|
|
@@ -209,4 +209,10 @@ Object.defineProperty(exports, "SensorDataFilter", {
|
|
|
209
209
|
get: function get() {
|
|
210
210
|
return sensor_1.SensorDataFilter;
|
|
211
211
|
}
|
|
212
|
+
});
|
|
213
|
+
Object.defineProperty(exports, "StringSplit", {
|
|
214
|
+
enumerable: true,
|
|
215
|
+
get: function get() {
|
|
216
|
+
return sensor_1.StringSplit;
|
|
217
|
+
}
|
|
212
218
|
});
|
package/lib/loop/index.d.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes the given callback function in a loop with the specified time interval.
|
|
3
|
+
*
|
|
4
|
+
* @param {Function} cb - The callback function to be executed in the loop. It takes a stop function as a parameter.
|
|
5
|
+
* @param {number} time - The time interval in milliseconds for the loop.
|
|
6
|
+
* @return {Function} The stop function that can be used to stop the loop.
|
|
7
|
+
*/
|
|
1
8
|
export declare const loop: (cb: (stop: () => void) => Promise<void>, time: number) => () => void;
|
|
2
9
|
type WaitForBool = () => boolean | Promise<boolean>;
|
|
10
|
+
/**
|
|
11
|
+
* Waits for a boolean condition to be true, with optional timeouts for the check and the overall wait.
|
|
12
|
+
*
|
|
13
|
+
* @param {WaitForBool} bool - the boolean condition to wait for
|
|
14
|
+
* @param {Object} options - optional parameters for checkTime and timeout
|
|
15
|
+
* @param {number} options.checkTime - the time interval for checking the boolean condition (default is 100)
|
|
16
|
+
* @param {number} options.timeout - the maximum time to wait for the boolean condition to be true
|
|
17
|
+
* @return {Promise<any>} a promise that resolves when the boolean condition is true or rejects with 'timeout' if the timeout is reached
|
|
18
|
+
*/
|
|
3
19
|
export declare const waitFor: (bool: WaitForBool, { checkTime, timeout }?: {
|
|
4
20
|
checkTime?: number | undefined;
|
|
5
21
|
timeout?: number | undefined;
|
package/lib/loop/index.js
CHANGED
|
@@ -120,6 +120,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
120
120
|
});
|
|
121
121
|
exports.waitFor = exports.loop = void 0;
|
|
122
122
|
var sleep_1 = require("../sleep");
|
|
123
|
+
/**
|
|
124
|
+
* Executes the given callback function in a loop with the specified time interval.
|
|
125
|
+
*
|
|
126
|
+
* @param {Function} cb - The callback function to be executed in the loop. It takes a stop function as a parameter.
|
|
127
|
+
* @param {number} time - The time interval in milliseconds for the loop.
|
|
128
|
+
* @return {Function} The stop function that can be used to stop the loop.
|
|
129
|
+
*/
|
|
123
130
|
var loop = function loop(cb, time) {
|
|
124
131
|
var onOff = true;
|
|
125
132
|
var stop = function stop() {
|
|
@@ -151,6 +158,15 @@ var loop = function loop(cb, time) {
|
|
|
151
158
|
return stop;
|
|
152
159
|
};
|
|
153
160
|
exports.loop = loop;
|
|
161
|
+
/**
|
|
162
|
+
* Waits for a boolean condition to be true, with optional timeouts for the check and the overall wait.
|
|
163
|
+
*
|
|
164
|
+
* @param {WaitForBool} bool - the boolean condition to wait for
|
|
165
|
+
* @param {Object} options - optional parameters for checkTime and timeout
|
|
166
|
+
* @param {number} options.checkTime - the time interval for checking the boolean condition (default is 100)
|
|
167
|
+
* @param {number} options.timeout - the maximum time to wait for the boolean condition to be true
|
|
168
|
+
* @return {Promise<any>} a promise that resolves when the boolean condition is true or rejects with 'timeout' if the timeout is reached
|
|
169
|
+
*/
|
|
154
170
|
var waitFor = function waitFor(bool, _a) {
|
|
155
171
|
var _b = _a === void 0 ? {} : _a,
|
|
156
172
|
checkTime = _b.checkTime,
|
package/lib/random/index.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a random string of specified length.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} n - The length of the random string to generate
|
|
5
|
+
* @return {string} The randomly generated string
|
|
6
|
+
*/
|
|
1
7
|
export declare const random: (n?: number) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Generates a random number within the specified range.
|
|
10
|
+
*
|
|
11
|
+
* @param {number[]} range - The range within which to generate the random number.
|
|
12
|
+
* @return {number} The randomly generated number within the specified range.
|
|
13
|
+
*/
|
|
2
14
|
export declare const randomRangeNum: (range: any) => number;
|
package/lib/random/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Generates a random string of specified length.
|
|
5
|
+
*
|
|
6
|
+
* @param {number} n - The length of the random string to generate
|
|
7
|
+
* @return {string} The randomly generated string
|
|
8
|
+
*/
|
|
3
9
|
var __read = this && this.__read || function (o, n) {
|
|
4
10
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
5
11
|
if (!m) return o;
|
|
@@ -56,6 +62,12 @@ var random = function random(n) {
|
|
|
56
62
|
return res;
|
|
57
63
|
};
|
|
58
64
|
exports.random = random;
|
|
65
|
+
/**
|
|
66
|
+
* Generates a random number within the specified range.
|
|
67
|
+
*
|
|
68
|
+
* @param {number[]} range - The range within which to generate the random number.
|
|
69
|
+
* @return {number} The randomly generated number within the specified range.
|
|
70
|
+
*/
|
|
59
71
|
var randomRangeNum = function randomRangeNum(range) {
|
|
60
72
|
var size = Math.abs(range[1] - range[0]);
|
|
61
73
|
return Math.random() * size + Math.min.apply(Math, __spreadArray([], __read(range), false));
|
package/lib/sleep/index.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronous function to sleep for a specified amount of time.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} time - The duration in milliseconds to sleep
|
|
5
|
+
* @return {Promise<void>} A promise that resolves after the specified time
|
|
6
|
+
*/
|
|
1
7
|
export declare const sleep: (time: number) => Promise<void>;
|
package/lib/sleep/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Asynchronous function to sleep for a specified amount of time.
|
|
5
|
+
*
|
|
6
|
+
* @param {number} time - The duration in milliseconds to sleep
|
|
7
|
+
* @return {Promise<void>} A promise that resolves after the specified time
|
|
8
|
+
*/
|
|
3
9
|
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
4
10
|
function adopt(value) {
|
|
5
11
|
return value instanceof P ? value : new P(function (resolve) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.98",
|
|
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": "4f1b1c6ff194adccef99ba0cead655b0ce82a406"
|
|
22
22
|
}
|