pubo-utils 1.0.198 → 1.0.201
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/fp/index.d.ts +15 -0
- package/es/fp/index.js +37 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/sleep/index.js +2 -0
- package/lib/fp/index.d.ts +15 -0
- package/lib/fp/index.js +64 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -0
- package/lib/sleep/index.js +1 -0
- 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,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},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:()=>s,BufferSplit:()=>Et,CacheEmitter:()=>f,ColorUtils:()=>h,ContinuousTrigger:()=>v,Emitter:()=>m,HistoryStack:()=>L,Level:()=>P,LinearColor:()=>c,RegExpList:()=>$,RemoteControl:()=>x,RetryPlus:()=>M,SensorDataFilter:()=>H,StringSplit:()=>K,SyncQueue:()=>T,UTM:()=>i,WatchDog:()=>k,callbackToPromise:()=>N,cloneDeep:()=>Q,debounce:()=>n,degrees:()=>j,filterKeyPoints:()=>C,filterTree:()=>J,fixNum:()=>W,flatTree:()=>G,getAngle:()=>z,getBestPointIndex:()=>B,getCenter:()=>U,getDistance:()=>R,getPositionTheta:()=>D,getRotate:()=>I,getTreeItem:()=>V,getVectorTheta:()=>q,hex2rgb:()=>o,loop:()=>d,lower2camel:()=>X,orderByDistance:()=>F,radians:()=>O,random:()=>u,randomRangeNum:()=>l,reflection:()=>Y,retry:()=>b,runAsyncTasks:()=>_,searchTree:()=>Z,sleep:()=>g,superFactory:()=>p,throttle:()=>A,timeout:()=>y,waitFor:()=>w});var s={};t.r(s),t.d(s,{EncoderMap:()=>E,toUnit8Array:()=>S});var i={};t.r(i),t.d(i,{fromLatLon:()=>Tt,latLonToZoneNumber:()=>At,latitudeToZoneLetter:()=>_t,toLatLon:()=>xt});const n=(t,e,s=!1)=>{if(s){let s,i=!0;return(...n)=>{i&&(t(...n),i=!1),s&&clearTimeout(s),s=setTimeout((()=>{clearTimeout(s),i=!0,s=null}),e)}}{let s;return(...i)=>{s&&(clearTimeout(s),s=null),s=setTimeout((()=>{t(...i),clearTimeout(s),i=null,s=null}),e)}}},r=t=>parseInt(t.replace("#",""),16),o=t=>{let e;e="string"==typeof t?r(t):t;const s=e.toString(2).padStart(24,"0");return[parseInt(s.slice(0,8),2),parseInt(s.slice(8,16),2),parseInt(s.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],s=this.base[1],i=this.base[2],n=t*this.intensity;return s=this.base[1]+n,s<this.max||(n=s-this.max,s=this.max,e=this.base[0]-n,e>this.min||(n=this.min-e,e=this.min,i=this.base[2]+n,i<this.max||(n=i-this.max,i=this.max,s-=n,s>this.min||(n=this.min-s,s=this.min,e+=n,e<this.max||(n=e-this.max,e=this.max,i-=n,i>this.min||(i=this.min)))))),[e,s,i]}}const u=(t=8)=>{const e=t=>Math.random().toString(32).slice(2,2+t);if(t<=8)return e(t);let s="";for(let i=0;i<=t;i+=8)s+=e(t-i>8?8:t-i);return s},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 s=`${u(40)}_${(new Date).valueOf()}`;return this.state[t][s]=e,this.ids[s]=t,s}cancel(t){if(!t)return;const e=this.ids[t];e&&this.state[e]&&(delete this.state[e][t],0===Object.keys(this.state[e]).length&&delete this.state[e],delete this.ids[t])}clear(){this.state={},this.ids={}}emit(t,e){if(this.state[t])for(const s of Object.keys(this.state[t])){const i=this.state[t][s];"function"==typeof i&&i(e)}}async emitSync(t,e){if(this.state[t])for(const s of Object.keys(this.state[t])){const i=this.state[t][s];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}}class f extends m{_cache={};emit(t,e){this._cache[t]=e,super.emit(t,e)}getState(t){return this._cache[t]}}const p=t=>e=>{const s={};for(const i of Object.keys(e))s[i]=t(e[i],i);return s},g=async t=>{await new Promise((e=>{let s=setTimeout((()=>{e(),clearTimeout(s),s=null}),t)}))},y=async(t,e=1e4)=>new Promise((async(s,i)=>{let n=!1;const r=setTimeout((()=>{n=!0,i(new Error("Timeout"))}),e);let o;try{o=await t(),clearTimeout(r)}catch(t){console.log(t),clearTimeout(r),n||i(t)}n||s(o)})),d=(t,e)=>{let s=!0;return(async()=>{for(;s;){try{await t()}catch(t){console.log(t)}await g(e)}})(),()=>s=!1},w=(t,{checkTime:e,timeout:s}={})=>new Promise(((i,n)=>{let r,o=d((async()=>{const e=await t();e&&("function"==typeof o&&o(),r&&(clearTimeout(r),r=null),i(e),o=null,t=null,i=null)}),e||100);s&&(r=setTimeout((()=>{"function"==typeof o&&o(),r&&(clearTimeout(r),r=null),n("timeout"),n=null,o=null,t=null}),s))})),b=async(t,{times:e=5,interval:s=1e3}={times:5,interval:1e3})=>{let i=1;const n=async()=>{let r;if(i>e)throw new Error("retry times exceed");try{return r=await t(),r}catch(t){console.log(`action error, times ${i}`),console.log(t),await g(s),i+=1,await n()}};await n()};class M{times;interval;action;count=1;args=[];result;canceled=!1;constructor(t,{times:e=5,interval:s=1e3}={times:5,interval:1e3}){this.interval=s,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 g(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 x{timeout;_start;_stop;fps;payload;constructor({start:t,stop:e,fps:s=5}){this._start=t,this._stop=e,this.fps=s}send(){this.payload&&this._start(this.payload)}control(t){this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.payload=t,this.send(),this.timeout=setTimeout((()=>this.stop()),1e3/this.fps)}stop(){this.payload=null,clearTimeout(this.timeout),this.timeout=null,this._stop()}}class T{cache=[];running=!1;len=0;async _run({fn:t,promise:e}){try{const s=await t();e.resolve(s)}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,s)=>{this.cache.push({fn:t,promise:{resolve:e,reject:s}}),this.running||this.run()}))}get length(){return this.len}}const _=async(t,e=4)=>{let s=-1;const i=[],n=async()=>{if(s+=1,t[s]){try{await t[s]()}catch(t){console.log(t)}await n()}};for(let t=0;t<e;t+=1)i.push(n());await Promise.all(i)};function A(t,e){const s=new T;let i=[];return(...n)=>{if(i=n,!(s.length>0))return s.push((async()=>{await g(e),await t(...i)}))}}class v{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 E=function(){const t={};for(let e=0;e<64;e++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)]=e;return t}();function S(t){const e=new Uint8Array(6*t.length/8);let s=0,i=0,n=0;for(let r=0;r<t.length&&n<e.length;r+=1)if(i=(i<<6)+E[t.charAt(r)],s+=6,s>=8){s-=8;let t=i>>>s;e[n++]=255&t,t<<=s,i-=t}return e}class L{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 k{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 P{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,s=this.config.min+this.step;s<this.config.max+this.step;s+=this.step,e+=1)if(t<s)return e;return this.config.count}}const N=t=>(...e)=>new Promise(((s,i)=>{t(...e,((t,...e)=>{t&&i(t),e.length<2?s(e[0]):s([...e])})),t=null})),R=(t,e)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),j=t=>180*t/Math.PI,O=t=>t*Math.PI/180,z=({w:t,h:e})=>j(Math.atan2(e,t));function C(t,e=.5){if(t.length<3||e<=0)return t;let s;return t.filter(((i,n)=>!(n>0&&R(s,i)<e||(s=t[n],0))))}function U(t){const e=[0,0];for(const s of t)Array.isArray(s)?(e[0]+=s[0],e[1]+=s[1]):(e[0]+=s.x,e[1]+=s.y);return{x:e[0]/t.length,y:e[1]/t.length}}function I(t,e,s){return s&&(e=O(e)),[Math.cos(e)*t[0]-Math.sin(e)*t[1],Math.sin(e)*t[0]+Math.cos(e)*t[1]]}const D=(t,e)=>{const s={x:e.x-t.x,y:e.y-t.y};return Math.atan2(s.y,s.x)},B=(t,e)=>{if(t.length<2)return 0;const s=[];let i=1/0,n=0;for(const r of t){const t=R(r,e),o=D(e,r)-e.theta;i>t&&(i=t),s.push({...r,index:n,distance:t,theta:o}),n+=1}return s.filter((t=>t.distance-i<.1)).sort(((t,e)=>t.theta-e.theta))[0].index},F=(t,e={x:0,y:0,theta:0})=>{let s=e;const i=[],n=[...t];for(;n.length>0;){const t=B(n,s);i.push(n[t]),s=n[t],n.splice(t,1)}return i},q=(t,e)=>Math.atan2(e.y,e.x)-Math.atan2(t.y,t.x),X=t=>t.split("_").map(((t,e)=>e>0?t.slice(0,1).toUpperCase()+t.slice(1):t)).join(""),W=(t,e=2)=>null==t||"NaN"===t?"N/A":("number"!=typeof t&&(t=parseFloat(t)),isNaN(t)?"N/A":t.toFixed(e));class ${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 H{tmp=[];size;step;min;max;count=0;value=NaN;old;constructor({size:t=5,step:e=5,min:s=-1/0,max:i=1/0}={}){this.size=t,this.step=e,this.min=s,this.max=i,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:s}=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>s[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,s=0;for(const i of this.tmp)t[i]?t[i]+=1:t[i]=1,t[i]>=s&&(s=t[i],e=i);return{res:e,dic:t}}}class K{_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 Q(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 s=t.map((t=>Q(t,e)));return e.set(t,s),s}if(t instanceof Set){const s=new Set([...t].map((t=>Q(t,e))));return e.set(t,s),s}if(t instanceof Map){const s=new Map;for(const[i,n]of t.entries())s.set(Q(i,e),Q(n,e));return e.set(t,s),s}{const s={};e.set(t,s);for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(s[i]=Q(t[i],e));return s}}function V(t,e){if(e.length<1)return null;let s;Array.isArray(t)&&(s={children:t});for(const t of e)s=s.children[t];return Q(s)}function Z(t,e,s="children"){const i=[];let n=!1;const r=t=>{for(let o=0;o<t.length;o+=1){const a=t[o];if(e(a)){n=!0,i.push(o);break}if(Array.isArray(a[s])){if(i.push(o),r(a[s]),n)break;i.pop()}}};return Array.isArray(t)?r(t):Array.isArray(t[s])&&r(t[s]),n?i:[]}const G=(t,e="children",s=[],i=[])=>{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],i.push(r),r.__indexes=[...s,n]})),n.forEach(((t,n)=>G(t,e,[...s,n],i))),i},J=(t,e,s="children")=>{const i=[];let n=[];return Array.isArray(t[s])?n=t[s]:Array.isArray(t)&&(n=t),n.forEach((t=>{var n;t[s]&&(t[s]=J(t[s],e)),((null===(n=t[s])||void 0===n?void 0:n.length)>0||e(t))&&i.push(t)})),i},Y=t=>{const e={};for(const s of Object.keys(t))e[t[s]]=s;return e},tt=.9996,et=.00669438,st=Math.pow(et,2),it=Math.pow(et,3),nt=et/(1-et),rt=Math.sqrt(1-et),ot=(1-rt)/(1+rt),at=Math.pow(ot,2),ht=Math.pow(ot,3),ct=Math.pow(ot,4),ut=Math.pow(ot,5),lt=1-et/4-3*st/64-5*it/256,mt=3*et/8+3*st/32+45*it/1024,ft=15*st/256+45*it/1024,pt=35*it/3072,gt=1.5*ot-27/32*ht+269/512*ut,yt=21/16*at-55/32*ct,dt=151/96*ht-417/128*ut,wt=1097/512*ct,bt=6378137,Mt="CDEFGHJKLMNPQRSTUVWXX";function xt(t){const{zoneNum:e,strict:s=!0}=t;let{zoneLetter:i,northern:n}=t;const r=t.x,o=t.y;if(!i&&void 0===n)throw new Error("either zoneLetter or northern needs to be set");if(i&&void 0!==n)throw new Error("set either zoneLetter or northern, but not both");if(s){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(i){if(i=i.toUpperCase(),1!==i.length||-1===Mt.indexOf(i))throw new RangeError("zone letter out of range (must be between C and X)");n=i>="N"}const a=r-5e5;let h=o;n||(h-=1e7);const c=h/tt/(bt*lt),u=c+gt*Math.sin(2*c)+yt*Math.sin(4*c)+dt*Math.sin(6*c)+wt*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-et*m,w=Math.sqrt(d),b=(1-et)/d,M=ot*f*f,x=M*M,T=a/(bt/w*tt),_=Math.pow(T,2),A=Math.pow(T,3),v=Math.pow(T,4),E=Math.pow(T,5),S=Math.pow(T,6),L=(T-A/6*(1+2*g+M)+E/120*(5-2*M+28*g-3*x+8*nt+24*y))/f;return{latitude:j(u-p/b*(_/2-v/24*(5+3*g+10*M-4*x-9*nt))+S/720*(61+90*g+298*M+45*y-252*nt-3*x)),longitude:j(L)+vt(e)}}function Tt({latitude:t,longitude:e},s){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 i=O(t),n=Math.sin(i),r=Math.cos(i),o=Math.tan(i),a=Math.pow(o,2),h=Math.pow(o,4);let c;c=void 0===s?At({latitude:t,longitude:e}):s;const u=_t(t),l=O(e),m=vt(c),f=O(m),p=bt/Math.sqrt(1-et*n*n),g=nt*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=bt*(lt*i-mt*Math.sin(2*i)+ft*Math.sin(4*i)-pt*Math.sin(6*i));let _=tt*(T+p*o*(d/2+b/24*(5-a+9*g+4*g*g)+x/720*(61-58*a+h+600*g-330*nt)));return t<0&&(_+=1e7),{x:tt*p*(y+w/6*(1-a+g)+M/120*(5-18*a+h+72*g-58*nt))+5e5,y:_,zoneNum:c,zoneLetter:u}}function _t(t){return-80<=t&&t<=84?Mt[Math.floor((t+80)/8)]:null}function At({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 vt(t){return 6*(t-1)-180+3}class Et{cache=Buffer.alloc(0);c;constructor(t){this.c=t}push(t){const e=Buffer.concat([this.cache,t]),s=[];let i=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(i,t);s.push(n),i=this.c.byteLength+t,t=this.c.byteLength+t}return this.cache=e.subarray(i),s}}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,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},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:()=>s,BufferSplit:()=>St,CacheEmitter:()=>p,ColorUtils:()=>c,ContinuousTrigger:()=>E,Emitter:()=>f,FP:()=>n,HistoryStack:()=>L,Level:()=>N,LinearColor:()=>u,RegExpList:()=>H,RemoteControl:()=>T,RetryPlus:()=>x,SensorDataFilter:()=>K,StringSplit:()=>Q,SyncQueue:()=>_,UTM:()=>i,WatchDog:()=>k,callbackToPromise:()=>R,cloneDeep:()=>V,debounce:()=>r,degrees:()=>O,filterKeyPoints:()=>F,filterTree:()=>Y,fixNum:()=>$,flatTree:()=>J,getAngle:()=>z,getBestPointIndex:()=>B,getCenter:()=>U,getDistance:()=>j,getPositionTheta:()=>D,getRotate:()=>I,getTreeItem:()=>Z,getVectorTheta:()=>X,hex2rgb:()=>a,loop:()=>w,lower2camel:()=>W,orderByDistance:()=>q,radians:()=>C,random:()=>l,randomRangeNum:()=>m,reflection:()=>tt,retry:()=>M,runAsyncTasks:()=>A,searchTree:()=>G,sleep:()=>y,superFactory:()=>g,throttle:()=>v,timeout:()=>d,waitFor:()=>b});var s={};t.r(s),t.d(s,{EncoderMap:()=>S,toUnit8Array:()=>P});var i={};t.r(i),t.d(i,{fromLatLon:()=>_t,latLonToZoneNumber:()=>vt,latitudeToZoneLetter:()=>At,toLatLon:()=>Tt});var n={};t.r(n),t.d(n,{Command:()=>kt,Failure:()=>Lt,Success:()=>Pt,effectPipe:()=>Rt,runEffect:()=>jt});const r=(t,e,s=!1)=>{if(s){let s,i=!0;return(...n)=>{i&&(t(...n),i=!1),s&&clearTimeout(s),s=setTimeout((()=>{clearTimeout(s),i=!0,s=null}),e)}}{let s;return(...i)=>{s&&(clearTimeout(s),s=null),s=setTimeout((()=>{t(...i),clearTimeout(s),i=null,s=null}),e)}}},o=t=>parseInt(t.replace("#",""),16),a=t=>{let e;e="string"==typeof t?o(t):t;const s=e.toString(2).padStart(24,"0");return[parseInt(s.slice(0,8),2),parseInt(s.slice(8,16),2),parseInt(s.slice(16,24),2)]},h=t=>"#"+[0,1,2].map((e=>t[e].toString(16))).join("");class c{int;constructor(t){"number"==typeof t?this.int=t:"string"==typeof t?this.int=o(t):Array.isArray(t)&&(this.int=o(h(t)))}getRgbArray(){return a(this.int)}get rgb(){return`rba(${this.getRgbArray().join(", ")})`}get hex(){return h(this.getRgbArray())}toString(t="hex"){return"rgb"===t?this.rgb:this.hex}}class u{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],s=this.base[1],i=this.base[2],n=t*this.intensity;return s=this.base[1]+n,s<this.max||(n=s-this.max,s=this.max,e=this.base[0]-n,e>this.min||(n=this.min-e,e=this.min,i=this.base[2]+n,i<this.max||(n=i-this.max,i=this.max,s-=n,s>this.min||(n=this.min-s,s=this.min,e+=n,e<this.max||(n=e-this.max,e=this.max,i-=n,i>this.min||(i=this.min)))))),[e,s,i]}}const l=(t=8)=>{const e=t=>Math.random().toString(32).slice(2,2+t);if(t<=8)return e(t);let s="";for(let i=0;i<=t;i+=8)s+=e(t-i>8?8:t-i);return s},m=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 s=`${l(40)}_${(new Date).valueOf()}`;return this.state[t][s]=e,this.ids[s]=t,s}cancel(t){if(!t)return;const e=this.ids[t];e&&this.state[e]&&(delete this.state[e][t],0===Object.keys(this.state[e]).length&&delete this.state[e],delete this.ids[t])}clear(){this.state={},this.ids={}}emit(t,e){if(this.state[t])for(const s of Object.keys(this.state[t])){const i=this.state[t][s];"function"==typeof i&&i(e)}}async emitSync(t,e){if(this.state[t])for(const s of Object.keys(this.state[t])){const i=this.state[t][s];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}}class p extends f{_cache={};emit(t,e){this._cache[t]=e,super.emit(t,e)}getState(t){return this._cache[t]}}const g=t=>e=>{const s={};for(const i of Object.keys(e))s[i]=t(e[i],i);return s},y=async t=>{await new Promise((e=>{let s=setTimeout((()=>{e(),clearTimeout(s),s=null}),t)}))},d=async(t,e=1e4)=>new Promise((async(s,i)=>{let n=!1;const r=setTimeout((()=>{n=!0,i(new Error("Timeout"))}),e);let o;try{o=await t(),clearTimeout(r)}catch(t){console.log(t),clearTimeout(r),n||i(t)}n||s(o)})),w=(t,e)=>{let s=!0;return(async()=>{for(;s;){try{await t()}catch(t){console.log(t)}await y(e)}})(),()=>s=!1},b=(t,{checkTime:e,timeout:s}={})=>new Promise(((i,n)=>{let r,o=w((async()=>{const e=await t();e&&("function"==typeof o&&o(),r&&(clearTimeout(r),r=null),i(e),o=null,t=null,i=null)}),e||100);s&&(r=setTimeout((()=>{"function"==typeof o&&o(),r&&(clearTimeout(r),r=null),n("timeout"),n=null,o=null,t=null}),s))})),M=async(t,{times:e=5,interval:s=1e3}={times:5,interval:1e3})=>{let i=1;const n=async()=>{let r;if(i>e)throw new Error("retry times exceed");try{return r=await t(),r}catch(t){console.log(`action error, times ${i}`),console.log(t),await y(s),i+=1,await n()}};await n()};class x{times;interval;action;count=1;args=[];result;canceled=!1;constructor(t,{times:e=5,interval:s=1e3}={times:5,interval:1e3}){this.interval=s,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 y(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 T{timeout;_start;_stop;fps;payload;constructor({start:t,stop:e,fps:s=5}){this._start=t,this._stop=e,this.fps=s}send(){this.payload&&this._start(this.payload)}control(t){this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.payload=t,this.send(),this.timeout=setTimeout((()=>this.stop()),1e3/this.fps)}stop(){this.payload=null,clearTimeout(this.timeout),this.timeout=null,this._stop()}}class _{cache=[];running=!1;len=0;async _run({fn:t,promise:e}){try{const s=await t();e.resolve(s)}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,s)=>{this.cache.push({fn:t,promise:{resolve:e,reject:s}}),this.running||this.run()}))}get length(){return this.len}}const A=async(t,e=4)=>{let s=-1;const i=[],n=async()=>{if(s+=1,t[s]){try{await t[s]()}catch(t){console.log(t)}await n()}};for(let t=0;t<e;t+=1)i.push(n());await Promise.all(i)};function v(t,e){const s=new _;let i=[];return(...n)=>{if(i=n,!(s.length>0))return s.push((async()=>{await y(e),await t(...i)}))}}class E{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 S=function(){const t={};for(let e=0;e<64;e++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)]=e;return t}();function P(t){const e=new Uint8Array(6*t.length/8);let s=0,i=0,n=0;for(let r=0;r<t.length&&n<e.length;r+=1)if(i=(i<<6)+S[t.charAt(r)],s+=6,s>=8){s-=8;let t=i>>>s;e[n++]=255&t,t<<=s,i-=t}return e}class L{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 k{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 N{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,s=this.config.min+this.step;s<this.config.max+this.step;s+=this.step,e+=1)if(t<s)return e;return this.config.count}}const R=t=>(...e)=>new Promise(((s,i)=>{t(...e,((t,...e)=>{t&&i(t),e.length<2?s(e[0]):s([...e])})),t=null})),j=(t,e)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),O=t=>180*t/Math.PI,C=t=>t*Math.PI/180,z=({w:t,h:e})=>O(Math.atan2(e,t));function F(t,e=.5){if(t.length<3||e<=0)return t;let s;return t.filter(((i,n)=>!(n>0&&j(s,i)<e||(s=t[n],0))))}function U(t){const e=[0,0];for(const s of t)Array.isArray(s)?(e[0]+=s[0],e[1]+=s[1]):(e[0]+=s.x,e[1]+=s.y);return{x:e[0]/t.length,y:e[1]/t.length}}function I(t,e,s){return s&&(e=C(e)),[Math.cos(e)*t[0]-Math.sin(e)*t[1],Math.sin(e)*t[0]+Math.cos(e)*t[1]]}const D=(t,e)=>{const s={x:e.x-t.x,y:e.y-t.y};return Math.atan2(s.y,s.x)},B=(t,e)=>{if(t.length<2)return 0;const s=[];let i=1/0,n=0;for(const r of t){const t=j(r,e),o=D(e,r)-e.theta;i>t&&(i=t),s.push({...r,index:n,distance:t,theta:o}),n+=1}return s.filter((t=>t.distance-i<.1)).sort(((t,e)=>t.theta-e.theta))[0].index},q=(t,e={x:0,y:0,theta:0})=>{let s=e;const i=[],n=[...t];for(;n.length>0;){const t=B(n,s);i.push(n[t]),s=n[t],n.splice(t,1)}return i},X=(t,e)=>Math.atan2(e.y,e.x)-Math.atan2(t.y,t.x),W=t=>t.split("_").map(((t,e)=>e>0?t.slice(0,1).toUpperCase()+t.slice(1):t)).join(""),$=(t,e=2)=>null==t||"NaN"===t?"N/A":("number"!=typeof t&&(t=parseFloat(t)),isNaN(t)?"N/A":t.toFixed(e));class H{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 K{tmp=[];size;step;min;max;count=0;value=NaN;old;constructor({size:t=5,step:e=5,min:s=-1/0,max:i=1/0}={}){this.size=t,this.step=e,this.min=s,this.max=i,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:s}=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>s[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,s=0;for(const i of this.tmp)t[i]?t[i]+=1:t[i]=1,t[i]>=s&&(s=t[i],e=i);return{res:e,dic:t}}}class Q{_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 V(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 s=t.map((t=>V(t,e)));return e.set(t,s),s}if(t instanceof Set){const s=new Set([...t].map((t=>V(t,e))));return e.set(t,s),s}if(t instanceof Map){const s=new Map;for(const[i,n]of t.entries())s.set(V(i,e),V(n,e));return e.set(t,s),s}{const s={};e.set(t,s);for(const i in t)Object.prototype.hasOwnProperty.call(t,i)&&(s[i]=V(t[i],e));return s}}function Z(t,e){if(e.length<1)return null;let s;Array.isArray(t)&&(s={children:t});for(const t of e)s=s.children[t];return V(s)}function G(t,e,s="children"){const i=[];let n=!1;const r=t=>{for(let o=0;o<t.length;o+=1){const a=t[o];if(e(a)){n=!0,i.push(o);break}if(Array.isArray(a[s])){if(i.push(o),r(a[s]),n)break;i.pop()}}};return Array.isArray(t)?r(t):Array.isArray(t[s])&&r(t[s]),n?i:[]}const J=(t,e="children",s=[],i=[])=>{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],i.push(r),r.__indexes=[...s,n]})),n.forEach(((t,n)=>J(t,e,[...s,n],i))),i},Y=(t,e,s="children")=>{const i=[];let n=[];return Array.isArray(t[s])?n=t[s]:Array.isArray(t)&&(n=t),n.forEach((t=>{var n;t[s]&&(t[s]=Y(t[s],e)),((null===(n=t[s])||void 0===n?void 0:n.length)>0||e(t))&&i.push(t)})),i},tt=t=>{const e={};for(const s of Object.keys(t))e[t[s]]=s;return e},et=.9996,st=.00669438,it=Math.pow(st,2),nt=Math.pow(st,3),rt=st/(1-st),ot=Math.sqrt(1-st),at=(1-ot)/(1+ot),ht=Math.pow(at,2),ct=Math.pow(at,3),ut=Math.pow(at,4),lt=Math.pow(at,5),mt=1-st/4-3*it/64-5*nt/256,ft=3*st/8+3*it/32+45*nt/1024,pt=15*it/256+45*nt/1024,gt=35*nt/3072,yt=1.5*at-27/32*ct+269/512*lt,dt=21/16*ht-55/32*ut,wt=151/96*ct-417/128*lt,bt=1097/512*ut,Mt=6378137,xt="CDEFGHJKLMNPQRSTUVWXX";function Tt(t){const{zoneNum:e,strict:s=!0}=t;let{zoneLetter:i,northern:n}=t;const r=t.x,o=t.y;if(!i&&void 0===n)throw new Error("either zoneLetter or northern needs to be set");if(i&&void 0!==n)throw new Error("set either zoneLetter or northern, but not both");if(s){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(i){if(i=i.toUpperCase(),1!==i.length||-1===xt.indexOf(i))throw new RangeError("zone letter out of range (must be between C and X)");n=i>="N"}const a=r-5e5;let h=o;n||(h-=1e7);const c=h/et/(Mt*mt),u=c+yt*Math.sin(2*c)+dt*Math.sin(4*c)+wt*Math.sin(6*c)+bt*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-st*m,w=Math.sqrt(d),b=(1-st)/d,M=at*f*f,x=M*M,T=a/(Mt/w*et),_=Math.pow(T,2),A=Math.pow(T,3),v=Math.pow(T,4),E=Math.pow(T,5),S=Math.pow(T,6),P=(T-A/6*(1+2*g+M)+E/120*(5-2*M+28*g-3*x+8*rt+24*y))/f;return{latitude:O(u-p/b*(_/2-v/24*(5+3*g+10*M-4*x-9*rt))+S/720*(61+90*g+298*M+45*y-252*rt-3*x)),longitude:O(P)+Et(e)}}function _t({latitude:t,longitude:e},s){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 i=C(t),n=Math.sin(i),r=Math.cos(i),o=Math.tan(i),a=Math.pow(o,2),h=Math.pow(o,4);let c;c=void 0===s?vt({latitude:t,longitude:e}):s;const u=At(t),l=C(e),m=Et(c),f=C(m),p=Mt/Math.sqrt(1-st*n*n),g=rt*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=Mt*(mt*i-ft*Math.sin(2*i)+pt*Math.sin(4*i)-gt*Math.sin(6*i));let _=et*(T+p*o*(d/2+b/24*(5-a+9*g+4*g*g)+x/720*(61-58*a+h+600*g-330*rt)));return t<0&&(_+=1e7),{x:et*p*(y+w/6*(1-a+g)+M/120*(5-18*a+h+72*g-58*rt))+5e5,y:_,zoneNum:c,zoneLetter:u}}function At(t){return-80<=t&&t<=84?xt[Math.floor((t+80)/8)]:null}function vt({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 Et(t){return 6*(t-1)-180+3}class St{cache=Buffer.alloc(0);c;constructor(t){this.c=t}push(t){const e=Buffer.concat([this.cache,t]),s=[];let i=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(i,t);s.push(n),i=this.c.byteLength+t,t=this.c.byteLength+t}return this.cache=e.subarray(i),s}}const Pt=t=>({type:"Success",value:t}),Lt=t=>({type:"Failure",error:t}),kt=(t,e)=>({type:"Command",cmd:t,next:e}),Nt=(t,e)=>{switch(t.type){case"Success":return e(t.value);case"Failure":return t;case"Command":const s=s=>Nt(t.next(s),e);return kt(t.cmd,s)}},Rt=(...t)=>e=>t.reduce(Nt,Pt(e));async function jt(t){for(;"Command"===t.type;)try{t=t.next(await t.cmd())}catch(t){return Lt(t)}return t}return e})()));
|
package/es/fp/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const Success: (value: any) => {
|
|
2
|
+
type: string;
|
|
3
|
+
value: any;
|
|
4
|
+
};
|
|
5
|
+
export declare const Failure: (error: any) => {
|
|
6
|
+
type: string;
|
|
7
|
+
error: any;
|
|
8
|
+
};
|
|
9
|
+
export declare const Command: (cmd: any, next: any) => {
|
|
10
|
+
type: string;
|
|
11
|
+
cmd: any;
|
|
12
|
+
next: any;
|
|
13
|
+
};
|
|
14
|
+
export declare const effectPipe: (...fns: any[]) => (start: any) => any;
|
|
15
|
+
export declare function runEffect(effect: any): Promise<any>;
|
package/es/fp/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const Success = (value)=>({
|
|
2
|
+
type: 'Success',
|
|
3
|
+
value
|
|
4
|
+
});
|
|
5
|
+
export const Failure = (error)=>({
|
|
6
|
+
type: 'Failure',
|
|
7
|
+
error
|
|
8
|
+
});
|
|
9
|
+
export const Command = (cmd, next)=>({
|
|
10
|
+
type: 'Command',
|
|
11
|
+
cmd,
|
|
12
|
+
next
|
|
13
|
+
});
|
|
14
|
+
const chain = (effect, fn)=>{
|
|
15
|
+
switch(effect.type){
|
|
16
|
+
case 'Success':
|
|
17
|
+
return fn(effect.value);
|
|
18
|
+
case 'Failure':
|
|
19
|
+
return effect;
|
|
20
|
+
case 'Command':
|
|
21
|
+
const next = (result)=>chain(effect.next(result), fn);
|
|
22
|
+
return Command(effect.cmd, next);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export const effectPipe = (...fns)=>{
|
|
26
|
+
return (start)=>fns.reduce(chain, Success(start));
|
|
27
|
+
};
|
|
28
|
+
export async function runEffect(effect) {
|
|
29
|
+
while(effect.type === 'Command'){
|
|
30
|
+
try {
|
|
31
|
+
effect = effect.next(await effect.cmd());
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return Failure(e);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return effect;
|
|
37
|
+
}
|
package/es/index.d.ts
CHANGED
|
@@ -20,3 +20,4 @@ export { SensorDataFilter, StringSplit } from './filter/sensor';
|
|
|
20
20
|
export { cloneDeep, getTreeItem, searchTree, flatTree, filterTree, reflection } from './object';
|
|
21
21
|
export * as UTM from './math/utm';
|
|
22
22
|
export { BufferSplit } from './buf';
|
|
23
|
+
export * as FP from './fp';
|
package/es/index.js
CHANGED
|
@@ -20,3 +20,4 @@ export { SensorDataFilter, StringSplit } from './filter/sensor';
|
|
|
20
20
|
export { cloneDeep, getTreeItem, searchTree, flatTree, filterTree, reflection } from './object';
|
|
21
21
|
export * as UTM from './math/utm';
|
|
22
22
|
export { BufferSplit } from './buf';
|
|
23
|
+
export * as FP from './fp';
|
package/es/sleep/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const Success: (value: any) => {
|
|
2
|
+
type: string;
|
|
3
|
+
value: any;
|
|
4
|
+
};
|
|
5
|
+
export declare const Failure: (error: any) => {
|
|
6
|
+
type: string;
|
|
7
|
+
error: any;
|
|
8
|
+
};
|
|
9
|
+
export declare const Command: (cmd: any, next: any) => {
|
|
10
|
+
type: string;
|
|
11
|
+
cmd: any;
|
|
12
|
+
next: any;
|
|
13
|
+
};
|
|
14
|
+
export declare const effectPipe: (...fns: any[]) => (start: any) => any;
|
|
15
|
+
export declare function runEffect(effect: any): Promise<any>;
|
package/lib/fp/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
Command: function() {
|
|
13
|
+
return Command;
|
|
14
|
+
},
|
|
15
|
+
Failure: function() {
|
|
16
|
+
return Failure;
|
|
17
|
+
},
|
|
18
|
+
Success: function() {
|
|
19
|
+
return Success;
|
|
20
|
+
},
|
|
21
|
+
effectPipe: function() {
|
|
22
|
+
return effectPipe;
|
|
23
|
+
},
|
|
24
|
+
runEffect: function() {
|
|
25
|
+
return runEffect;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const Success = (value)=>({
|
|
29
|
+
type: 'Success',
|
|
30
|
+
value
|
|
31
|
+
});
|
|
32
|
+
const Failure = (error)=>({
|
|
33
|
+
type: 'Failure',
|
|
34
|
+
error
|
|
35
|
+
});
|
|
36
|
+
const Command = (cmd, next)=>({
|
|
37
|
+
type: 'Command',
|
|
38
|
+
cmd,
|
|
39
|
+
next
|
|
40
|
+
});
|
|
41
|
+
const chain = (effect, fn)=>{
|
|
42
|
+
switch(effect.type){
|
|
43
|
+
case 'Success':
|
|
44
|
+
return fn(effect.value);
|
|
45
|
+
case 'Failure':
|
|
46
|
+
return effect;
|
|
47
|
+
case 'Command':
|
|
48
|
+
const next = (result)=>chain(effect.next(result), fn);
|
|
49
|
+
return Command(effect.cmd, next);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const effectPipe = (...fns)=>{
|
|
53
|
+
return (start)=>fns.reduce(chain, Success(start));
|
|
54
|
+
};
|
|
55
|
+
async function runEffect(effect) {
|
|
56
|
+
while(effect.type === 'Command'){
|
|
57
|
+
try {
|
|
58
|
+
effect = effect.next(await effect.cmd());
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return Failure(e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return effect;
|
|
64
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -20,3 +20,4 @@ export { SensorDataFilter, StringSplit } from './filter/sensor';
|
|
|
20
20
|
export { cloneDeep, getTreeItem, searchTree, flatTree, filterTree, reflection } from './object';
|
|
21
21
|
export * as UTM from './math/utm';
|
|
22
22
|
export { BufferSplit } from './buf';
|
|
23
|
+
export * as FP from './fp';
|
package/lib/index.js
CHANGED
|
@@ -27,6 +27,9 @@ _export(exports, {
|
|
|
27
27
|
Emitter: function() {
|
|
28
28
|
return _emitter.Emitter;
|
|
29
29
|
},
|
|
30
|
+
FP: function() {
|
|
31
|
+
return _fp;
|
|
32
|
+
},
|
|
30
33
|
HistoryStack: function() {
|
|
31
34
|
return _stack.HistoryStack;
|
|
32
35
|
},
|
|
@@ -179,6 +182,7 @@ const _sensor = require("./filter/sensor");
|
|
|
179
182
|
const _object = require("./object");
|
|
180
183
|
const _utm = /*#__PURE__*/ _interop_require_wildcard(require("./math/utm"));
|
|
181
184
|
const _buf = require("./buf");
|
|
185
|
+
const _fp = /*#__PURE__*/ _interop_require_wildcard(require("./fp"));
|
|
182
186
|
function _getRequireWildcardCache(nodeInterop) {
|
|
183
187
|
if (typeof WeakMap !== "function") return null;
|
|
184
188
|
var cacheBabelInterop = new WeakMap();
|
package/lib/sleep/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.201",
|
|
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": "2b70f52fbccc90c61d200cb237244e762a7b106e",
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"del": "^5.1.0",
|
|
24
24
|
"eslint": "^8.42.0",
|