pubo-utils 1.0.181 → 1.0.185
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/buf.d.ts +6 -0
- package/es/buf.js +28 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/es/sleep/index.d.ts +1 -0
- package/es/sleep/index.js +23 -0
- package/lib/buf.d.ts +6 -0
- package/lib/buf.js +38 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +7 -0
- package/lib/sleep/index.d.ts +1 -0
- package/lib/sleep/index.js +34 -3
- package/package.json +2 -2
package/dist/pubo-utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.PuboUtils=e():t.PuboUtils=e()}(this,(()=>(()=>{"use strict";var t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{Base64Utils:()=>i,ColorUtils:()=>h,ContinuousTrigger:()=>T,Emitter:()=>m,HistoryStack:()=>E,Level:()=>S,LinearColor:()=>c,RegExpList:()=>q,RetryPlus:()=>w,SensorDataFilter:()=>W,StringSplit:()=>B,SyncQueue:()=>b,UTM:()=>s,WatchDog:()=>_,callbackToPromise:()=>N,cloneDeep:()=>H,debounce:()=>n,degrees:()=>R,filterKeyPoints:()=>j,filterTree:()=>Z,fixNum:()=>X,flatTree:()=>V,getAngle:()=>L,getBestPointIndex:()=>C,getCenter:()=>z,getDistance:()=>P,getPositionTheta:()=>U,getRotate:()=>O,getTreeItem:()=>K,getVectorTheta:()=>D,hex2rgb:()=>o,loop:()=>g,lower2camel:()=>F,orderByDistance:()=>I,radians:()=>k,random:()=>u,randomRangeNum:()=>l,retry:()=>d,runAsyncTasks:()=>M,searchTree:()=>Q,sleep:()=>p,superFactory:()=>f,throttle:()=>x,waitFor:()=>y});var i={};t.r(i),t.d(i,{EncoderMap:()=>A,toUnit8Array:()=>v});var s={};t.r(s),t.d(s,{fromLatLon:()=>wt,latLonToZoneNumber:()=>Mt,latitudeToZoneLetter:()=>bt,toLatLon:()=>dt});const n=(t,e,i=!1)=>{if(i){let i,s=!0;return(...n)=>{s&&(t(...n),s=!1),i&&clearTimeout(i),i=setTimeout((()=>{clearTimeout(i),s=!0,i=null}),e)}}{let i;return(...s)=>{i&&(clearTimeout(i),i=null),i=setTimeout((()=>{t(...s),clearTimeout(i),s=null,i=null}),e)}}},r=t=>parseInt(t.replace("#",""),16),o=t=>{let e;e="string"==typeof t?r(t):t;const i=e.toString(2).padStart(24,"0");return[parseInt(i.slice(0,8),2),parseInt(i.slice(8,16),2),parseInt(i.slice(16,24),2)]},a=t=>"#"+[0,1,2].map((e=>t[e].toString(16))).join("");class h{int;constructor(t){"number"==typeof t?this.int=t:"string"==typeof t?this.int=r(t):Array.isArray(t)&&(this.int=r(a(t)))}getRgbArray(){return o(this.int)}get rgb(){return`rba(${this.getRgbArray().join(", ")})`}get hex(){return a(this.getRgbArray())}toString(t="hex"){return"rgb"===t?this.rgb:this.hex}}class c{base=[255,0,0];intensity=1;min;max;constructor({base:t=[255,0,0],intensity:e=1}={}){this.base=t,this.intensity=e,this.intensity<1&&(this.intensity=1),this.min=this.base[1],this.max=this.base[0],Math.abs(this.min-this.max)<1&&(this.min=0,this.max=255)}getColor(t){if(t<0)return this.base;let e=this.base[0],i=this.base[1],s=this.base[2],n=t*this.intensity;return i=this.base[1]+n,i<this.max||(n=i-this.max,i=this.max,e=this.base[0]-n,e>this.min||(n=this.min-e,e=this.min,s=this.base[2]+n,s<this.max||(n=s-this.max,s=this.max,i-=n,i>this.min||(n=this.min-i,i=this.min,e+=n,e<this.max||(n=e-this.max,e=this.max,s-=n,s>this.min||(s=this.min)))))),[e,i,s]}}const u=(t=8)=>{const e=t=>Math.random().toString(32).slice(2,2+t);if(t<=8)return e(t);let i="";for(let s=0;s<=t;s+=8)i+=e(t-s>8?8:t-s);return i},l=t=>{const e=Math.abs(t[1]-t[0]);return Math.random()*e+Math.min(...t)};class m{state={};ids={};on(t,e){if(this.state[t]||(this.state[t]=[]),"function"!=typeof e)throw new Error("第二个参数必须为function!");const i=this.state[t].push(e)-1,s=u(40);return this.ids[s]={event:t,index:i},s}cancel(t){if(!t)return void this.clear();const{event:e,index:i}=this.ids[t]||{};e&&Array.isArray(this.state[e])&&(this.state[e].splice(i,1),delete this.ids[t],Object.keys(this.ids).forEach((t=>{this.ids[t].event===e&&this.ids[t].index>i&&(this.ids[t].index=this.ids[t].index-1)})))}clear(){this.state.length=0}emit(t,e){if(Array.isArray(this.state[t]))for(const i of this.state[t])"function"==typeof i&&i(e)}async emitSync(t,e){if(Array.isArray(this.state[t]))for(const i of this.state[t])if("function"==typeof i)try{await i(e)}catch(t){console.log(t)}}clone(){return{state:{...this.state},ids:{...this.ids}}}restore(t){this.state=t.state,this.ids=t.ids}}const f=t=>e=>{const i={};for(const s of Object.keys(e))i[s]=t(e[s],s);return i},p=async t=>{await new Promise((e=>{let i=setTimeout((()=>{e(),clearTimeout(i),i=null}),t)}))},g=(t,e)=>{let i=!0;return(async()=>{for(;i;){try{await t()}catch(t){console.log(t)}await p(e)}})(),()=>i=!1},y=(t,{checkTime:e,timeout:i}={})=>new Promise(((s,n)=>{let r,o=g((async()=>{const e=await t();e&&("function"==typeof o&&o(),r&&(clearTimeout(r),r=null),s(e),o=null,t=null,s=null)}),e||100);i&&(r=setTimeout((()=>{"function"==typeof o&&o(),r&&(clearTimeout(r),r=null),n("timeout"),n=null,o=null,t=null}),i))})),d=async(t,{times:e=5,interval:i=1e3}={times:5,interval:1e3})=>{let s=1;const n=async()=>{let r;if(s>e)throw new Error("retry times exceed");try{return r=await t(),r}catch(t){console.log(`action error, times ${s}`),console.log(t),await p(i),s+=1,await n()}};await n()};class w{times;interval;action;count=1;args=[];result;canceled=!1;constructor(t,{times:e=5,interval:i=1e3}={times:5,interval:1e3}){this.interval=i,this.times=e,this.action=t}async _run(){if(this.canceled)throw new Error("retry canceled");if(this.count>this.times)throw new Error("retry times exceed");try{this.result=await this.action(...this.args)}catch(t){console.log(`action error, times ${this.count}`),console.log(t),await p(this.interval),this.count+=1,await this._run()}}async run(...t){return this.canceled=!1,this.result=null,this.count=1,this.args=t,await this._run(),this.args=[],this.count=1,this.result}async cancel(){this.canceled=!0}}class b{cache=[];running=!1;len=0;async _run({fn:t,promise:e}){try{const i=await t();e.resolve(i)}catch(t){e.reject(t)}t=null,e=null}async run(){if(this.cache.length<1)return void(this.running=!1);this.running=!0;const t=this.cache.shift();this.len-=1,"function"==typeof t.fn&&await this._run(t),this.run()}push(t){return this.len+=1,new Promise(((e,i)=>{this.cache.push({fn:t,promise:{resolve:e,reject:i}}),this.running||this.run()}))}get length(){return this.len}}const M=async(t,e=4)=>{let i=-1;const s=[],n=async()=>{if(i+=1,t[i]){try{await t[i]()}catch(t){console.log(t)}await n()}};for(let t=0;t<e;t+=1)s.push(n());await Promise.all(s)};function x(t,e){const i=new b;let s=[];return(...n)=>{if(s=n,!(i.length>0))return i.push((async()=>{await p(e),await t(...s)}))}}class T{timeout;_count=0;props;constructor(t){this.props=t}get count(){return this._count}increment(){clearTimeout(this.timeout),this.timeout=setTimeout((()=>this.clear()),this.props.resetTime),this._count=this._count+1,this._count>this.props.count&&this.props.cb()}clear(){clearTimeout(this.timeout),this._count=0,this.timeout=0}}const A=function(){const t={};for(let e=0;e<64;e++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)]=e;return t}();function v(t){const e=new Uint8Array(6*t.length/8);let i=0,s=0,n=0;for(let r=0;r<t.length&&n<e.length;r+=1)if(s=(s<<6)+A[t.charAt(r)],i+=6,i>=8){i-=8;let t=s>>>i;e[n++]=255&t,t<<=i,s-=t}return e}class E{stack=[];len=10;point=0;constructor(t=10){this.len=t}get current(){if(this.point<this.stack.length&&this.point>-1)return this.stack[this.point]}clear(){this.stack.length=0,this.point=0}backup(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()}undo(){return this.point<this.stack.length-1&&(this.point+=1),this.current}redo(){return this.point>0&&(this.point-=1),this.current}}class _{onTimeout;timeout=null;_time;constructor({limit:t=10,onTimeout:e}){this._time=1e3*t,this.onTimeout=()=>{this.timeout&&(clearTimeout(this.timeout),this.timeout=null),e()}}feed(){this.init()}init(){clearTimeout(this.timeout),this.timeout=null,delete this.timeout,this.timeout=setTimeout(this.onTimeout,this._time)}stop(){this.timeout&&clearTimeout(this.timeout),delete this.timeout}}class S{config;step;constructor(t){this.config=t,this.step=(this.config.max-this.config.min)/(this.config.count-2)}get(t){if(t<=this.config.min)return 1;if(t>=this.config.max)return this.config.count;for(let e=2,i=this.config.min+this.step;i<this.config.max+this.step;i+=this.step,e+=1)if(t<i)return e;return this.config.count}}const N=t=>(...e)=>new Promise(((i,s)=>{t(...e,((t,...e)=>{t&&s(t),e.length<2?i(e[0]):i([...e])})),t=null})),P=(t,e)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),R=t=>180*t/Math.PI,k=t=>t*Math.PI/180,L=({w:t,h:e})=>R(Math.atan2(e,t));function j(t,e=.5){if(t.length<3||e<=0)return t;let i;return t.filter(((s,n)=>!(n>0&&P(i,s)<e||(i=t[n],0))))}function z(t){const e=[0,0];for(const i of t)Array.isArray(i)?(e[0]+=i[0],e[1]+=i[1]):(e[0]+=i.x,e[1]+=i.y);return{x:e[0]/t.length,y:e[1]/t.length}}function O(t,e,i){return i&&(e=k(e)),[Math.cos(e)*t[0]-Math.sin(e)*t[1],Math.sin(e)*t[0]+Math.cos(e)*t[1]]}const U=(t,e)=>{const i={x:e.x-t.x,y:e.y-t.y};return Math.atan2(i.y,i.x)},C=(t,e)=>{if(t.length<2)return 0;const i=[];let s=1/0,n=0;for(const r of t){const t=P(r,e),o=U(e,r)-e.theta;s>t&&(s=t),i.push({...r,index:n,distance:t,theta:o}),n+=1}return i.filter((t=>t.distance-s<.1)).sort(((t,e)=>t.theta-e.theta))[0].index},I=(t,e={x:0,y:0,theta:0})=>{let i=e;const s=[],n=[...t];for(;n.length>0;){const t=C(n,i);s.push(n[t]),i=n[t],n.splice(t,1)}return s},D=(t,e)=>Math.atan2(e.y,e.x)-Math.atan2(t.y,t.x),F=t=>t.split("_").map(((t,e)=>e>0?t.slice(0,1).toUpperCase()+t.slice(1):t)).join(""),X=(t,e=2)=>null==t||"NaN"===t?"N/A":("number"!=typeof t&&(t=parseFloat(t)),isNaN(t)?"N/A":t.toFixed(e));class q{list;_RegExpList=null;constructor(t){this.list=t}getRegEXP(t){const e=t.replace("/","\\/").replace("*",".*");return new RegExp(e)}include(t){return this._RegExpList||(this._RegExpList=this.list.map(this.getRegEXP)),this._RegExpList.some((e=>e.test(t)))}}class W{tmp=[];size;step;min;max;count=0;value=NaN;old;constructor({size:t=5,step:e=5,min:i=-1/0,max:s=1/0}={}){this.size=t,this.step=e,this.min=i,this.max=s,this.old=this.min}filter(t){return t<this.min||t>this.max||(this.tmp.push(t),this.old=this.calc(t)),this.old}calc(t){if(this.tmp.length<1)return t;this.tmp.length>this.size&&this.tmp.shift();const{res:e,dic:i}=this.getMostNumberOfTmp();return e!==t&&Math.abs(e-t)>this.step?(this.value!==t?this.count=1:this.count+=1,this.value=t,this.count>i[e]?(this.tmp.length=0,this.tmp.push(t),this.count=0,this.value=NaN,t):e):(this.count=0,this.value=NaN,t)}getMostNumberOfTmp(){const t={};let e,i=0;for(const s of this.tmp)t[s]?t[s]+=1:t[s]=1,t[s]>=i&&(i=t[s],e=s);return{res:e,dic:t}}}class B{_splitSymbol;_cache="";constructor(t){this._splitSymbol=t}split(t){const e=(this._cache+t).split(this._splitSymbol);return this._cache=e.splice(e.length-1,1)[0],e}}function H(t,e=new WeakMap){if("object"!=typeof t||null===t)return t;if(e.has(t))return e.get(t);if(Array.isArray(t)){const i=t.map((t=>H(t,e)));return e.set(t,i),i}if(t instanceof Set){const i=new Set([...t].map((t=>H(t,e))));return e.set(t,i),i}if(t instanceof Map){const i=new Map;for(const[s,n]of t.entries())i.set(H(s,e),H(n,e));return e.set(t,i),i}{const i={};e.set(t,i);for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(i[s]=H(t[s],e));return i}}function K(t,e){if(e.length<1)return null;let i;Array.isArray(t)&&(i={children:t});for(const t of e)i=i.children[t];return H(i)}function Q(t,e,i="children"){const s=[];let n=!1;const r=t=>{for(let o=0;o<t.length;o+=1){const a=t[o];if(e(a)){n=!0,s.push(o);break}if(Array.isArray(a[i])){if(s.push(o),r(a[i]),n)break;s.pop()}}};return Array.isArray(t)?r(t):Array.isArray(t[i])&&r(t[i]),n?s:[]}const V=(t,e="children",i=[],s=[])=>{let n=[];return Array.isArray(t[e])?n=t[e]:Array.isArray(t)&&(n=t),n.forEach(((t,n)=>{const r={...t};delete r[e],s.push(r),r.__indexes=[...i,n]})),n.forEach(((t,n)=>V(t,e,[...i,n],s))),s},Z=(t,e,i="children")=>{const s=[];let n=[];return Array.isArray(t[i])?n=t[i]:Array.isArray(t)&&(n=t),n.forEach((t=>{var n;t[i]&&(t[i]=Z(t[i],e)),((null===(n=t[i])||void 0===n?void 0:n.length)>0||e(t))&&s.push(t)})),s},$=.9996,G=.00669438,J=Math.pow(G,2),Y=Math.pow(G,3),tt=G/(1-G),et=Math.sqrt(1-G),it=(1-et)/(1+et),st=Math.pow(it,2),nt=Math.pow(it,3),rt=Math.pow(it,4),ot=Math.pow(it,5),at=1-G/4-3*J/64-5*Y/256,ht=3*G/8+3*J/32+45*Y/1024,ct=15*J/256+45*Y/1024,ut=35*Y/3072,lt=1.5*it-27/32*nt+269/512*ot,mt=21/16*st-55/32*rt,ft=151/96*nt-417/128*ot,pt=1097/512*rt,gt=6378137,yt="CDEFGHJKLMNPQRSTUVWXX";function dt(t){const{zoneNum:e,strict:i=!0}=t;let{zoneLetter:s,northern:n}=t;const r=t.x,o=t.y;if(!s&&void 0===n)throw new Error("either zoneLetter or northern needs to be set");if(s&&void 0!==n)throw new Error("set either zoneLetter or northern, but not both");if(i){if(r<1e5||1e6<=r)throw new RangeError("easting out of range (must be between 100 000 m and 999 999 m)");if(o<0||o>1e7)throw new RangeError("northing out of range (must be between 0 m and 10 000 000 m)")}if(e<1||e>60)throw new RangeError("zone number out of range (must be between 1 and 60)");if(s){if(s=s.toUpperCase(),1!==s.length||-1===yt.indexOf(s))throw new RangeError("zone letter out of range (must be between C and X)");n=s>="N"}const a=r-5e5;let h=o;n||(h-=1e7);const c=h/$/(gt*at),u=c+lt*Math.sin(2*c)+mt*Math.sin(4*c)+ft*Math.sin(6*c)+pt*Math.sin(8*c),l=Math.sin(u),m=Math.pow(l,2),f=Math.cos(u),p=Math.tan(u),g=Math.pow(p,2),y=Math.pow(p,4),d=1-G*m,w=Math.sqrt(d),b=(1-G)/d,M=it*f*f,x=M*M,T=a/(gt/w*$),A=Math.pow(T,2),v=Math.pow(T,3),E=Math.pow(T,4),_=Math.pow(T,5),S=Math.pow(T,6),N=(T-v/6*(1+2*g+M)+_/120*(5-2*M+28*g-3*x+8*tt+24*y))/f;return{latitude:R(u-p/b*(A/2-E/24*(5+3*g+10*M-4*x-9*tt))+S/720*(61+90*g+298*M+45*y-252*tt-3*x)),longitude:R(N)+xt(e)}}function wt({latitude:t,longitude:e},i){if(t>84||t<-80)throw new RangeError("latitude out of range (must be between 80 deg S and 84 deg N)");if(e>180||e<-180)throw new RangeError("longitude out of range (must be between 180 deg W and 180 deg E)");const s=k(t),n=Math.sin(s),r=Math.cos(s),o=Math.tan(s),a=Math.pow(o,2),h=Math.pow(o,4);let c;c=void 0===i?Mt({latitude:t,longitude:e}):i;const u=bt(t),l=k(e),m=xt(c),f=k(m),p=gt/Math.sqrt(1-G*n*n),g=tt*r*r,y=r*(l-f),d=Math.pow(y,2),w=Math.pow(y,3),b=Math.pow(y,4),M=Math.pow(y,5),x=Math.pow(y,6),T=gt*(at*s-ht*Math.sin(2*s)+ct*Math.sin(4*s)-ut*Math.sin(6*s));let A=$*(T+p*o*(d/2+b/24*(5-a+9*g+4*g*g)+x/720*(61-58*a+h+600*g-330*tt)));return t<0&&(A+=1e7),{x:$*p*(y+w/6*(1-a+g)+M/120*(5-18*a+h+72*g-58*tt))+5e5,y:A,zoneNum:c,zoneLetter:u}}function bt(t){return-80<=t&&t<=84?yt[Math.floor((t+80)/8)]:null}function Mt({latitude:t,longitude:e}){if(56<=t&&t<64&&3<=e&&e<12)return 32;if(72<=t&&t<=84&&e>=0){if(e<9)return 31;if(e<21)return 33;if(e<33)return 35;if(e<42)return 37}return Math.floor((e+180)/6)+1}function xt(t){return 6*(t-1)-180+3}return e})()));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.PuboUtils=e():t.PuboUtils=e()}(this,(()=>(()=>{"use strict";var t={d:(e,i)=>{for(var s in i)t.o(i,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:i[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{Base64Utils:()=>i,BufferSplit:()=>At,ColorUtils:()=>h,ContinuousTrigger:()=>A,Emitter:()=>f,HistoryStack:()=>_,Level:()=>S,LinearColor:()=>c,RegExpList:()=>X,RetryPlus:()=>b,SensorDataFilter:()=>W,StringSplit:()=>H,SyncQueue:()=>M,UTM:()=>s,WatchDog:()=>L,callbackToPromise:()=>P,cloneDeep:()=>K,debounce:()=>n,degrees:()=>R,filterKeyPoints:()=>z,filterTree:()=>$,fixNum:()=>q,flatTree:()=>Z,getAngle:()=>j,getBestPointIndex:()=>I,getCenter:()=>O,getDistance:()=>N,getPositionTheta:()=>C,getRotate:()=>U,getTreeItem:()=>Q,getVectorTheta:()=>D,hex2rgb:()=>o,loop:()=>y,lower2camel:()=>F,orderByDistance:()=>B,radians:()=>k,random:()=>u,randomRangeNum:()=>l,retry:()=>w,runAsyncTasks:()=>x,searchTree:()=>V,sleep:()=>p,superFactory:()=>m,throttle:()=>T,timeout:()=>g,waitFor:()=>d});var i={};t.r(i),t.d(i,{EncoderMap:()=>v,toUnit8Array:()=>E});var s={};t.r(s),t.d(s,{fromLatLon:()=>bt,latLonToZoneNumber:()=>xt,latitudeToZoneLetter:()=>Mt,toLatLon:()=>wt});const n=(t,e,i=!1)=>{if(i){let i,s=!0;return(...n)=>{s&&(t(...n),s=!1),i&&clearTimeout(i),i=setTimeout((()=>{clearTimeout(i),s=!0,i=null}),e)}}{let i;return(...s)=>{i&&(clearTimeout(i),i=null),i=setTimeout((()=>{t(...s),clearTimeout(i),s=null,i=null}),e)}}},r=t=>parseInt(t.replace("#",""),16),o=t=>{let e;e="string"==typeof t?r(t):t;const i=e.toString(2).padStart(24,"0");return[parseInt(i.slice(0,8),2),parseInt(i.slice(8,16),2),parseInt(i.slice(16,24),2)]},a=t=>"#"+[0,1,2].map((e=>t[e].toString(16))).join("");class h{int;constructor(t){"number"==typeof t?this.int=t:"string"==typeof t?this.int=r(t):Array.isArray(t)&&(this.int=r(a(t)))}getRgbArray(){return o(this.int)}get rgb(){return`rba(${this.getRgbArray().join(", ")})`}get hex(){return a(this.getRgbArray())}toString(t="hex"){return"rgb"===t?this.rgb:this.hex}}class c{base=[255,0,0];intensity=1;min;max;constructor({base:t=[255,0,0],intensity:e=1}={}){this.base=t,this.intensity=e,this.intensity<1&&(this.intensity=1),this.min=this.base[1],this.max=this.base[0],Math.abs(this.min-this.max)<1&&(this.min=0,this.max=255)}getColor(t){if(t<0)return this.base;let e=this.base[0],i=this.base[1],s=this.base[2],n=t*this.intensity;return i=this.base[1]+n,i<this.max||(n=i-this.max,i=this.max,e=this.base[0]-n,e>this.min||(n=this.min-e,e=this.min,s=this.base[2]+n,s<this.max||(n=s-this.max,s=this.max,i-=n,i>this.min||(n=this.min-i,i=this.min,e+=n,e<this.max||(n=e-this.max,e=this.max,s-=n,s>this.min||(s=this.min)))))),[e,i,s]}}const u=(t=8)=>{const e=t=>Math.random().toString(32).slice(2,2+t);if(t<=8)return e(t);let i="";for(let s=0;s<=t;s+=8)i+=e(t-s>8?8:t-s);return i},l=t=>{const e=Math.abs(t[1]-t[0]);return Math.random()*e+Math.min(...t)};class f{state={};ids={};on(t,e){if(this.state[t]||(this.state[t]=[]),"function"!=typeof e)throw new Error("第二个参数必须为function!");const i=this.state[t].push(e)-1,s=u(40);return this.ids[s]={event:t,index:i},s}cancel(t){if(!t)return void this.clear();const{event:e,index:i}=this.ids[t]||{};e&&Array.isArray(this.state[e])&&(this.state[e].splice(i,1),delete this.ids[t],Object.keys(this.ids).forEach((t=>{this.ids[t].event===e&&this.ids[t].index>i&&(this.ids[t].index=this.ids[t].index-1)})))}clear(){this.state.length=0}emit(t,e){if(Array.isArray(this.state[t]))for(const i of this.state[t])"function"==typeof i&&i(e)}async emitSync(t,e){if(Array.isArray(this.state[t]))for(const i of this.state[t])if("function"==typeof i)try{await i(e)}catch(t){console.log(t)}}clone(){return{state:{...this.state},ids:{...this.ids}}}restore(t){this.state=t.state,this.ids=t.ids}}const m=t=>e=>{const i={};for(const s of Object.keys(e))i[s]=t(e[s],s);return i},p=async t=>{await new Promise((e=>{let i=setTimeout((()=>{e(),clearTimeout(i),i=null}),t)}))},g=async(t,e=1e4)=>new Promise((async(i,s)=>{let n=!1;const r=setTimeout((()=>{n=!0,s(new Error("Timeout"))}),e);let o;try{o=await t(),clearTimeout(r)}catch(t){console.log(t),clearTimeout(r),n||s(t)}n||i(o)})),y=(t,e)=>{let i=!0;return(async()=>{for(;i;){try{await t()}catch(t){console.log(t)}await p(e)}})(),()=>i=!1},d=(t,{checkTime:e,timeout:i}={})=>new Promise(((s,n)=>{let r,o=y((async()=>{const e=await t();e&&("function"==typeof o&&o(),r&&(clearTimeout(r),r=null),s(e),o=null,t=null,s=null)}),e||100);i&&(r=setTimeout((()=>{"function"==typeof o&&o(),r&&(clearTimeout(r),r=null),n("timeout"),n=null,o=null,t=null}),i))})),w=async(t,{times:e=5,interval:i=1e3}={times:5,interval:1e3})=>{let s=1;const n=async()=>{let r;if(s>e)throw new Error("retry times exceed");try{return r=await t(),r}catch(t){console.log(`action error, times ${s}`),console.log(t),await p(i),s+=1,await n()}};await n()};class b{times;interval;action;count=1;args=[];result;canceled=!1;constructor(t,{times:e=5,interval:i=1e3}={times:5,interval:1e3}){this.interval=i,this.times=e,this.action=t}async _run(){if(this.canceled)throw new Error("retry canceled");if(this.count>this.times)throw new Error("retry times exceed");try{this.result=await this.action(...this.args)}catch(t){console.log(`action error, times ${this.count}`),console.log(t),await p(this.interval),this.count+=1,await this._run()}}async run(...t){return this.canceled=!1,this.result=null,this.count=1,this.args=t,await this._run(),this.args=[],this.count=1,this.result}async cancel(){this.canceled=!0}}class M{cache=[];running=!1;len=0;async _run({fn:t,promise:e}){try{const i=await t();e.resolve(i)}catch(t){e.reject(t)}t=null,e=null}async run(){if(this.cache.length<1)return void(this.running=!1);this.running=!0;const t=this.cache.shift();this.len-=1,"function"==typeof t.fn&&await this._run(t),this.run()}push(t){return this.len+=1,new Promise(((e,i)=>{this.cache.push({fn:t,promise:{resolve:e,reject:i}}),this.running||this.run()}))}get length(){return this.len}}const x=async(t,e=4)=>{let i=-1;const s=[],n=async()=>{if(i+=1,t[i]){try{await t[i]()}catch(t){console.log(t)}await n()}};for(let t=0;t<e;t+=1)s.push(n());await Promise.all(s)};function T(t,e){const i=new M;let s=[];return(...n)=>{if(s=n,!(i.length>0))return i.push((async()=>{await p(e),await t(...s)}))}}class A{timeout;_count=0;props;constructor(t){this.props=t}get count(){return this._count}increment(){clearTimeout(this.timeout),this.timeout=setTimeout((()=>this.clear()),this.props.resetTime),this._count=this._count+1,this._count>this.props.count&&this.props.cb()}clear(){clearTimeout(this.timeout),this._count=0,this.timeout=0}}const v=function(){const t={};for(let e=0;e<64;e++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)]=e;return t}();function E(t){const e=new Uint8Array(6*t.length/8);let i=0,s=0,n=0;for(let r=0;r<t.length&&n<e.length;r+=1)if(s=(s<<6)+v[t.charAt(r)],i+=6,i>=8){i-=8;let t=s>>>i;e[n++]=255&t,t<<=i,s-=t}return e}class _{stack=[];len=10;point=0;constructor(t=10){this.len=t}get current(){if(this.point<this.stack.length&&this.point>-1)return this.stack[this.point]}clear(){this.stack.length=0,this.point=0}backup(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()}undo(){return this.point<this.stack.length-1&&(this.point+=1),this.current}redo(){return this.point>0&&(this.point-=1),this.current}}class L{onTimeout;timeout=null;_time;constructor({limit:t=10,onTimeout:e}){this._time=1e3*t,this.onTimeout=()=>{this.timeout&&(clearTimeout(this.timeout),this.timeout=null),e()}}feed(){this.init()}init(){clearTimeout(this.timeout),this.timeout=null,delete this.timeout,this.timeout=setTimeout(this.onTimeout,this._time)}stop(){this.timeout&&clearTimeout(this.timeout),delete this.timeout}}class S{config;step;constructor(t){this.config=t,this.step=(this.config.max-this.config.min)/(this.config.count-2)}get(t){if(t<=this.config.min)return 1;if(t>=this.config.max)return this.config.count;for(let e=2,i=this.config.min+this.step;i<this.config.max+this.step;i+=this.step,e+=1)if(t<i)return e;return this.config.count}}const P=t=>(...e)=>new Promise(((i,s)=>{t(...e,((t,...e)=>{t&&s(t),e.length<2?i(e[0]):i([...e])})),t=null})),N=(t,e)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),R=t=>180*t/Math.PI,k=t=>t*Math.PI/180,j=({w:t,h:e})=>R(Math.atan2(e,t));function z(t,e=.5){if(t.length<3||e<=0)return t;let i;return t.filter(((s,n)=>!(n>0&&N(i,s)<e||(i=t[n],0))))}function O(t){const e=[0,0];for(const i of t)Array.isArray(i)?(e[0]+=i[0],e[1]+=i[1]):(e[0]+=i.x,e[1]+=i.y);return{x:e[0]/t.length,y:e[1]/t.length}}function U(t,e,i){return i&&(e=k(e)),[Math.cos(e)*t[0]-Math.sin(e)*t[1],Math.sin(e)*t[0]+Math.cos(e)*t[1]]}const C=(t,e)=>{const i={x:e.x-t.x,y:e.y-t.y};return Math.atan2(i.y,i.x)},I=(t,e)=>{if(t.length<2)return 0;const i=[];let s=1/0,n=0;for(const r of t){const t=N(r,e),o=C(e,r)-e.theta;s>t&&(s=t),i.push({...r,index:n,distance:t,theta:o}),n+=1}return i.filter((t=>t.distance-s<.1)).sort(((t,e)=>t.theta-e.theta))[0].index},B=(t,e={x:0,y:0,theta:0})=>{let i=e;const s=[],n=[...t];for(;n.length>0;){const t=I(n,i);s.push(n[t]),i=n[t],n.splice(t,1)}return s},D=(t,e)=>Math.atan2(e.y,e.x)-Math.atan2(t.y,t.x),F=t=>t.split("_").map(((t,e)=>e>0?t.slice(0,1).toUpperCase()+t.slice(1):t)).join(""),q=(t,e=2)=>null==t||"NaN"===t?"N/A":("number"!=typeof t&&(t=parseFloat(t)),isNaN(t)?"N/A":t.toFixed(e));class X{list;_RegExpList=null;constructor(t){this.list=t}getRegEXP(t){const e=t.replace("/","\\/").replace("*",".*");return new RegExp(e)}include(t){return this._RegExpList||(this._RegExpList=this.list.map(this.getRegEXP)),this._RegExpList.some((e=>e.test(t)))}}class W{tmp=[];size;step;min;max;count=0;value=NaN;old;constructor({size:t=5,step:e=5,min:i=-1/0,max:s=1/0}={}){this.size=t,this.step=e,this.min=i,this.max=s,this.old=this.min}filter(t){return t<this.min||t>this.max||(this.tmp.push(t),this.old=this.calc(t)),this.old}calc(t){if(this.tmp.length<1)return t;this.tmp.length>this.size&&this.tmp.shift();const{res:e,dic:i}=this.getMostNumberOfTmp();return e!==t&&Math.abs(e-t)>this.step?(this.value!==t?this.count=1:this.count+=1,this.value=t,this.count>i[e]?(this.tmp.length=0,this.tmp.push(t),this.count=0,this.value=NaN,t):e):(this.count=0,this.value=NaN,t)}getMostNumberOfTmp(){const t={};let e,i=0;for(const s of this.tmp)t[s]?t[s]+=1:t[s]=1,t[s]>=i&&(i=t[s],e=s);return{res:e,dic:t}}}class H{_splitSymbol;_cache="";constructor(t){this._splitSymbol=t}split(t){const e=(this._cache+t).split(this._splitSymbol);return this._cache=e.splice(e.length-1,1)[0],e}}function K(t,e=new WeakMap){if("object"!=typeof t||null===t)return t;if(e.has(t))return e.get(t);if(Array.isArray(t)){const i=t.map((t=>K(t,e)));return e.set(t,i),i}if(t instanceof Set){const i=new Set([...t].map((t=>K(t,e))));return e.set(t,i),i}if(t instanceof Map){const i=new Map;for(const[s,n]of t.entries())i.set(K(s,e),K(n,e));return e.set(t,i),i}{const i={};e.set(t,i);for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(i[s]=K(t[s],e));return i}}function Q(t,e){if(e.length<1)return null;let i;Array.isArray(t)&&(i={children:t});for(const t of e)i=i.children[t];return K(i)}function V(t,e,i="children"){const s=[];let n=!1;const r=t=>{for(let o=0;o<t.length;o+=1){const a=t[o];if(e(a)){n=!0,s.push(o);break}if(Array.isArray(a[i])){if(s.push(o),r(a[i]),n)break;s.pop()}}};return Array.isArray(t)?r(t):Array.isArray(t[i])&&r(t[i]),n?s:[]}const Z=(t,e="children",i=[],s=[])=>{let n=[];return Array.isArray(t[e])?n=t[e]:Array.isArray(t)&&(n=t),n.forEach(((t,n)=>{const r={...t};delete r[e],s.push(r),r.__indexes=[...i,n]})),n.forEach(((t,n)=>Z(t,e,[...i,n],s))),s},$=(t,e,i="children")=>{const s=[];let n=[];return Array.isArray(t[i])?n=t[i]:Array.isArray(t)&&(n=t),n.forEach((t=>{var n;t[i]&&(t[i]=$(t[i],e)),((null===(n=t[i])||void 0===n?void 0:n.length)>0||e(t))&&s.push(t)})),s},G=.9996,J=.00669438,Y=Math.pow(J,2),tt=Math.pow(J,3),et=J/(1-J),it=Math.sqrt(1-J),st=(1-it)/(1+it),nt=Math.pow(st,2),rt=Math.pow(st,3),ot=Math.pow(st,4),at=Math.pow(st,5),ht=1-J/4-3*Y/64-5*tt/256,ct=3*J/8+3*Y/32+45*tt/1024,ut=15*Y/256+45*tt/1024,lt=35*tt/3072,ft=1.5*st-27/32*rt+269/512*at,mt=21/16*nt-55/32*ot,pt=151/96*rt-417/128*at,gt=1097/512*ot,yt=6378137,dt="CDEFGHJKLMNPQRSTUVWXX";function wt(t){const{zoneNum:e,strict:i=!0}=t;let{zoneLetter:s,northern:n}=t;const r=t.x,o=t.y;if(!s&&void 0===n)throw new Error("either zoneLetter or northern needs to be set");if(s&&void 0!==n)throw new Error("set either zoneLetter or northern, but not both");if(i){if(r<1e5||1e6<=r)throw new RangeError("easting out of range (must be between 100 000 m and 999 999 m)");if(o<0||o>1e7)throw new RangeError("northing out of range (must be between 0 m and 10 000 000 m)")}if(e<1||e>60)throw new RangeError("zone number out of range (must be between 1 and 60)");if(s){if(s=s.toUpperCase(),1!==s.length||-1===dt.indexOf(s))throw new RangeError("zone letter out of range (must be between C and X)");n=s>="N"}const a=r-5e5;let h=o;n||(h-=1e7);const c=h/G/(yt*ht),u=c+ft*Math.sin(2*c)+mt*Math.sin(4*c)+pt*Math.sin(6*c)+gt*Math.sin(8*c),l=Math.sin(u),f=Math.pow(l,2),m=Math.cos(u),p=Math.tan(u),g=Math.pow(p,2),y=Math.pow(p,4),d=1-J*f,w=Math.sqrt(d),b=(1-J)/d,M=st*m*m,x=M*M,T=a/(yt/w*G),A=Math.pow(T,2),v=Math.pow(T,3),E=Math.pow(T,4),_=Math.pow(T,5),L=Math.pow(T,6),S=(T-v/6*(1+2*g+M)+_/120*(5-2*M+28*g-3*x+8*et+24*y))/m;return{latitude:R(u-p/b*(A/2-E/24*(5+3*g+10*M-4*x-9*et))+L/720*(61+90*g+298*M+45*y-252*et-3*x)),longitude:R(S)+Tt(e)}}function bt({latitude:t,longitude:e},i){if(t>84||t<-80)throw new RangeError("latitude out of range (must be between 80 deg S and 84 deg N)");if(e>180||e<-180)throw new RangeError("longitude out of range (must be between 180 deg W and 180 deg E)");const s=k(t),n=Math.sin(s),r=Math.cos(s),o=Math.tan(s),a=Math.pow(o,2),h=Math.pow(o,4);let c;c=void 0===i?xt({latitude:t,longitude:e}):i;const u=Mt(t),l=k(e),f=Tt(c),m=k(f),p=yt/Math.sqrt(1-J*n*n),g=et*r*r,y=r*(l-m),d=Math.pow(y,2),w=Math.pow(y,3),b=Math.pow(y,4),M=Math.pow(y,5),x=Math.pow(y,6),T=yt*(ht*s-ct*Math.sin(2*s)+ut*Math.sin(4*s)-lt*Math.sin(6*s));let A=G*(T+p*o*(d/2+b/24*(5-a+9*g+4*g*g)+x/720*(61-58*a+h+600*g-330*et)));return t<0&&(A+=1e7),{x:G*p*(y+w/6*(1-a+g)+M/120*(5-18*a+h+72*g-58*et))+5e5,y:A,zoneNum:c,zoneLetter:u}}function Mt(t){return-80<=t&&t<=84?dt[Math.floor((t+80)/8)]:null}function xt({latitude:t,longitude:e}){if(56<=t&&t<64&&3<=e&&e<12)return 32;if(72<=t&&t<=84&&e>=0){if(e<9)return 31;if(e<21)return 33;if(e<33)return 35;if(e<42)return 37}return Math.floor((e+180)/6)+1}function Tt(t){return 6*(t-1)-180+3}class At{c;cache=Buffer.alloc(0);constructor(t){this.c=t}push(t){const e=Buffer.concat([this.cache,t]),i=[];let s=0;for(let t=this.cache.byteLength;t<=e.byteLength-this.c.byteLength;t+=1)if(this.c.equals(e.subarray(t,this.c.byteLength+t))){const n=e.subarray(s,t);i.push(n),s=this.c.byteLength+t,t=this.c.byteLength+t}return this.cache=e.subarray(s),i}}return e})()));
|
package/es/buf.d.ts
ADDED
package/es/buf.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class BufferSplit {
|
|
2
|
+
c;
|
|
3
|
+
cache = Buffer.alloc(0);
|
|
4
|
+
constructor(buf){
|
|
5
|
+
this.c = buf;
|
|
6
|
+
}
|
|
7
|
+
push(buf) {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const tmp = Buffer.concat([
|
|
10
|
+
this.cache,
|
|
11
|
+
buf
|
|
12
|
+
]);
|
|
13
|
+
const arr = [];
|
|
14
|
+
let n = 0;
|
|
15
|
+
for(let i = this.cache.byteLength; i <= tmp.byteLength - this.c.byteLength; i += 1){
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
const bool = this.c.equals(tmp.subarray(i, this.c.byteLength + i));
|
|
18
|
+
if (bool) {
|
|
19
|
+
const res = tmp.subarray(n, i);
|
|
20
|
+
arr.push(res);
|
|
21
|
+
n = this.c.byteLength + i;
|
|
22
|
+
i = this.c.byteLength + i;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
this.cache = tmp.subarray(n);
|
|
26
|
+
return arr;
|
|
27
|
+
}
|
|
28
|
+
}
|
package/es/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { superFactory } from './factory';
|
|
|
5
5
|
export { loop, retry, waitFor, RetryPlus } from './loop';
|
|
6
6
|
export { SyncQueue, runAsyncTasks } from './queue';
|
|
7
7
|
export { random, randomRangeNum } from './random';
|
|
8
|
-
export { sleep } from './sleep';
|
|
8
|
+
export { sleep, timeout } from './sleep';
|
|
9
9
|
export { throttle } from './throttle';
|
|
10
10
|
export { ContinuousTrigger } from './trigger';
|
|
11
11
|
export * as Base64Utils from './base64';
|
|
@@ -19,3 +19,4 @@ export { RegExpList } from './regexp-list';
|
|
|
19
19
|
export { SensorDataFilter, StringSplit } from './filter/sensor';
|
|
20
20
|
export { cloneDeep, getTreeItem, searchTree, flatTree, filterTree } from './object';
|
|
21
21
|
export * as UTM from './math/utm';
|
|
22
|
+
export { BufferSplit } from './buf';
|
package/es/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export { superFactory } from './factory';
|
|
|
5
5
|
export { loop, retry, waitFor, RetryPlus } from './loop';
|
|
6
6
|
export { SyncQueue, runAsyncTasks } from './queue';
|
|
7
7
|
export { random, randomRangeNum } from './random';
|
|
8
|
-
export { sleep } from './sleep';
|
|
8
|
+
export { sleep, timeout } from './sleep';
|
|
9
9
|
export { throttle } from './throttle';
|
|
10
10
|
export { ContinuousTrigger } from './trigger';
|
|
11
11
|
export * as Base64Utils from './base64';
|
|
@@ -19,3 +19,4 @@ export { RegExpList } from './regexp-list';
|
|
|
19
19
|
export { SensorDataFilter, StringSplit } from './filter/sensor';
|
|
20
20
|
export { cloneDeep, getTreeItem, searchTree, flatTree, filterTree } from './object';
|
|
21
21
|
export * as UTM from './math/utm';
|
|
22
|
+
export { BufferSplit } from './buf';
|
package/es/sleep/index.d.ts
CHANGED
package/es/sleep/index.js
CHANGED
|
@@ -12,3 +12,26 @@
|
|
|
12
12
|
}, time);
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
|
+
export const timeout = async (cb, time = 10000)=>{
|
|
16
|
+
return new Promise(async (resolve, reject)=>{
|
|
17
|
+
let ended = false;
|
|
18
|
+
const t = setTimeout(()=>{
|
|
19
|
+
ended = true;
|
|
20
|
+
reject(new Error('Timeout'));
|
|
21
|
+
}, time);
|
|
22
|
+
let result;
|
|
23
|
+
try {
|
|
24
|
+
result = await cb();
|
|
25
|
+
clearTimeout(t);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
console.log(err);
|
|
28
|
+
clearTimeout(t);
|
|
29
|
+
if (!ended) {
|
|
30
|
+
reject(err);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (!ended) {
|
|
34
|
+
resolve(result);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
package/lib/buf.d.ts
ADDED
package/lib/buf.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "BufferSplit", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return BufferSplit;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
class BufferSplit {
|
|
12
|
+
c;
|
|
13
|
+
cache = Buffer.alloc(0);
|
|
14
|
+
constructor(buf){
|
|
15
|
+
this.c = buf;
|
|
16
|
+
}
|
|
17
|
+
push(buf) {
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
const tmp = Buffer.concat([
|
|
20
|
+
this.cache,
|
|
21
|
+
buf
|
|
22
|
+
]);
|
|
23
|
+
const arr = [];
|
|
24
|
+
let n = 0;
|
|
25
|
+
for(let i = this.cache.byteLength; i <= tmp.byteLength - this.c.byteLength; i += 1){
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
const bool = this.c.equals(tmp.subarray(i, this.c.byteLength + i));
|
|
28
|
+
if (bool) {
|
|
29
|
+
const res = tmp.subarray(n, i);
|
|
30
|
+
arr.push(res);
|
|
31
|
+
n = this.c.byteLength + i;
|
|
32
|
+
i = this.c.byteLength + i;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
this.cache = tmp.subarray(n);
|
|
36
|
+
return arr;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { superFactory } from './factory';
|
|
|
5
5
|
export { loop, retry, waitFor, RetryPlus } from './loop';
|
|
6
6
|
export { SyncQueue, runAsyncTasks } from './queue';
|
|
7
7
|
export { random, randomRangeNum } from './random';
|
|
8
|
-
export { sleep } from './sleep';
|
|
8
|
+
export { sleep, timeout } from './sleep';
|
|
9
9
|
export { throttle } from './throttle';
|
|
10
10
|
export { ContinuousTrigger } from './trigger';
|
|
11
11
|
export * as Base64Utils from './base64';
|
|
@@ -19,3 +19,4 @@ export { RegExpList } from './regexp-list';
|
|
|
19
19
|
export { SensorDataFilter, StringSplit } from './filter/sensor';
|
|
20
20
|
export { cloneDeep, getTreeItem, searchTree, flatTree, filterTree } from './object';
|
|
21
21
|
export * as UTM from './math/utm';
|
|
22
|
+
export { BufferSplit } from './buf';
|
package/lib/index.js
CHANGED
|
@@ -12,6 +12,9 @@ _export(exports, {
|
|
|
12
12
|
Base64Utils: function() {
|
|
13
13
|
return _base64;
|
|
14
14
|
},
|
|
15
|
+
BufferSplit: function() {
|
|
16
|
+
return _buf.BufferSplit;
|
|
17
|
+
},
|
|
15
18
|
ColorUtils: function() {
|
|
16
19
|
return _utils.ColorUtils;
|
|
17
20
|
},
|
|
@@ -138,6 +141,9 @@ _export(exports, {
|
|
|
138
141
|
throttle: function() {
|
|
139
142
|
return _throttle.throttle;
|
|
140
143
|
},
|
|
144
|
+
timeout: function() {
|
|
145
|
+
return _sleep.timeout;
|
|
146
|
+
},
|
|
141
147
|
waitFor: function() {
|
|
142
148
|
return _loop.waitFor;
|
|
143
149
|
}
|
|
@@ -163,6 +169,7 @@ const _regexplist = require("./regexp-list");
|
|
|
163
169
|
const _sensor = require("./filter/sensor");
|
|
164
170
|
const _object = require("./object");
|
|
165
171
|
const _utm = /*#__PURE__*/ _interop_require_wildcard(require("./math/utm"));
|
|
172
|
+
const _buf = require("./buf");
|
|
166
173
|
function _getRequireWildcardCache(nodeInterop) {
|
|
167
174
|
if (typeof WeakMap !== "function") return null;
|
|
168
175
|
var cacheBabelInterop = new WeakMap();
|
package/lib/sleep/index.d.ts
CHANGED
package/lib/sleep/index.js
CHANGED
|
@@ -7,10 +7,18 @@
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
|
8
8
|
value: true
|
|
9
9
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
function _export(target, all) {
|
|
11
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: all[name]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
_export(exports, {
|
|
17
|
+
sleep: function() {
|
|
13
18
|
return sleep;
|
|
19
|
+
},
|
|
20
|
+
timeout: function() {
|
|
21
|
+
return timeout;
|
|
14
22
|
}
|
|
15
23
|
});
|
|
16
24
|
const sleep = async (time)=>{
|
|
@@ -22,3 +30,26 @@ const sleep = async (time)=>{
|
|
|
22
30
|
}, time);
|
|
23
31
|
});
|
|
24
32
|
};
|
|
33
|
+
const timeout = async (cb, time = 10000)=>{
|
|
34
|
+
return new Promise(async (resolve, reject)=>{
|
|
35
|
+
let ended = false;
|
|
36
|
+
const t = setTimeout(()=>{
|
|
37
|
+
ended = true;
|
|
38
|
+
reject(new Error('Timeout'));
|
|
39
|
+
}, time);
|
|
40
|
+
let result;
|
|
41
|
+
try {
|
|
42
|
+
result = await cb();
|
|
43
|
+
clearTimeout(t);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.log(err);
|
|
46
|
+
clearTimeout(t);
|
|
47
|
+
if (!ended) {
|
|
48
|
+
reject(err);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (!ended) {
|
|
52
|
+
resolve(result);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.185",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"module": "./es/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">=8.0.0"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "870f649d5ade235140e5641d68dcd818cf3115f6",
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"del": "^5.1.0",
|
|
24
24
|
"eslint": "^8.42.0",
|