pubo-utils 1.0.176 → 1.0.179
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/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/loop/index.d.ts +1 -1
- package/es/loop/index.js +5 -5
- package/es/math/utm.d.ts +22 -0
- package/es/math/utm.js +146 -0
- package/es/object/index.js +21 -12
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -0
- package/lib/loop/index.d.ts +1 -1
- package/lib/loop/index.js +5 -5
- package/lib/math/utm.d.ts +22 -0
- package/lib/math/utm.js +170 -0
- package/lib/object/index.js +21 -12
- 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:()=>a,ContinuousTrigger:()=>A,Emitter:()=>u,HistoryStack:()=>M,Level:()=>v,LinearColor:()=>h,RegExpList:()=>z,SensorDataFilter:()=>B,StringSplit:()=>W,SyncQueue:()=>d,WatchDog:()=>_,callbackToPromise:()=>k,cloneDeep:()=>X,debounce:()=>s,degrees:()=>P,filterKeyPoints:()=>N,filterTree:()=>Q,fixNum:()=>F,flatTree:()=>K,getAngle:()=>j,getBestPointIndex:()=>L,getCenter:()=>R,getDistance:()=>S,getPositionTheta:()=>I,getRotate:()=>O,getTreeItem:()=>q,getVectorTheta:()=>C,hex2rgb:()=>r,loop:()=>f,lower2camel:()=>D,orderByDistance:()=>U,radians:()=>E,random:()=>c,randomRangeNum:()=>l,retry:()=>g,runAsyncTasks:()=>x,searchTree:()=>H,sleep:()=>p,superFactory:()=>m,throttle:()=>b,waitFor:()=>y});var i={};t.r(i),t.d(i,{EncoderMap:()=>T,toUnit8Array:()=>w});const s=(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)}}},n=t=>parseInt(t.replace("#",""),16),r=t=>{let e;e="string"==typeof t?n(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)]},o=t=>"#"+[0,1,2].map((e=>t[e].toString(16))).join("");class a{int;constructor(t){"number"==typeof t?this.int=t:"string"==typeof t?this.int=n(t):Array.isArray(t)&&(this.int=n(o(t)))}getRgbArray(){return r(this.int)}get rgb(){return`rba(${this.getRgbArray().join(", ")})`}get hex(){return o(this.getRgbArray())}toString(t="hex"){return"rgb"===t?this.rgb:this.hex}}class h{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 c=(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 u{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=c(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)}))},f=(t,e)=>{let i=!0,s=()=>{i=!1},n=async()=>{try{await t()}catch(t){console.log(t)}await p(e),i?n():(n=null,t=null,s=null,i=null,e=null)};return n(),s},y=(t,{checkTime:e,timeout:i}={})=>new Promise(((s,n)=>{let r,o=f((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))})),g=(t,{times:e=5,interval:i=1e3}={times:5,interval:1e3})=>{let s=1;const n=async(...r)=>{let o;if(s>e)throw new Error("retry times exceed");try{return o=await t(...r),o}catch(t){return console.log(`action error, times ${s}`),console.log(t),await p(i),s+=1,n(...r)}};return n};class d{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 b(t,e){const i=new d;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 T=function(){const t={};for(let e=0;e<64;e++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)]=e;return t}();function w(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)+T[t.charAt(r)],i+=6,i>=8){i-=8;let t=s>>>i;e[n++]=255&t,t<<=i,s-=t}return e}class M{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 v{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 k=t=>(...e)=>new Promise(((i,s)=>{t(...e,((t,...e)=>{t&&s(t),e.length<2?i(e[0]):i([...e])})),t=null})),S=(t,e)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)),P=t=>180*t/Math.PI,E=t=>t*Math.PI/180,j=({w:t,h:e})=>P(Math.atan2(e,t));function N(t,e=.5){if(t.length<3||e<=0)return t;let i;return t.filter(((s,n)=>!(n>0&&S(i,s)<e||(i=t[n],0))))}function R(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=E(e)),[Math.cos(e)*t[0]-Math.sin(e)*t[1],Math.sin(e)*t[0]+Math.cos(e)*t[1]]}const I=(t,e)=>{const i={x:e.x-t.x,y:e.y-t.y};return Math.atan2(i.y,i.x)},L=(t,e)=>{if(t.length<2)return 0;const i=[];let s=1/0,n=0;for(const r of t){const t=S(r,e),o=I(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},U=(t,e={x:0,y:0,theta:0})=>{let i=e;const s=[],n=[...t];for(;n.length>0;){const t=L(n,i);s.push(n[t]),i=n[t],n.splice(t,1)}return s},C=(t,e)=>Math.atan2(e.y,e.x)-Math.atan2(t.y,t.x),D=t=>t.split("_").map(((t,e)=>e>0?t.slice(0,1).toUpperCase()+t.slice(1):t)).join(""),F=(t,e=2)=>null==t||"NaN"===t?"N/A":("number"!=typeof t&&(t=parseFloat(t)),isNaN(t)?"N/A":t.toFixed(e));class z{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 B{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}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),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 W{_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 X(t,e=new WeakMap){if("object"!=typeof t||null===t)return t;if(e.has(t))return e.get(t);if(Array.isArray(t))return t.map((t=>X(t,e)));if(t instanceof Set)return new Set([...t]);if(t instanceof Map)return new Map([...t]);{const i={};return e.set(t,t),Object.keys(t).forEach((s=>{i[s]=X(t[s],e)})),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 X(i)}function H(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 K=(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)=>K(t,e,[...i,n],s))),s},Q=(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]=Q(t[i],e)),((null===(n=t[i])||void 0===n?void 0:n.length)>0||e(t))&&s.push(t)})),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,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},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:()=>x,Emitter:()=>f,HistoryStack:()=>v,Level:()=>_,LinearColor:()=>c,RegExpList:()=>X,SensorDataFilter:()=>q,StringSplit:()=>W,SyncQueue:()=>w,UTM:()=>n,WatchDog:()=>E,callbackToPromise:()=>S,cloneDeep:()=>B,debounce:()=>s,degrees:()=>k,filterKeyPoints:()=>L,filterTree:()=>V,fixNum:()=>F,flatTree:()=>Q,getAngle:()=>R,getBestPointIndex:()=>U,getCenter:()=>j,getDistance:()=>P,getPositionTheta:()=>O,getRotate:()=>z,getTreeItem:()=>H,getVectorTheta:()=>I,hex2rgb:()=>o,loop:()=>g,lower2camel:()=>D,orderByDistance:()=>C,radians:()=>N,random:()=>u,randomRangeNum:()=>l,retry:()=>d,runAsyncTasks:()=>b,searchTree:()=>K,sleep:()=>m,superFactory:()=>p,throttle:()=>M,waitFor:()=>y});var i={};t.r(i),t.d(i,{EncoderMap:()=>T,toUnit8Array:()=>A});var n={};t.r(n),t.d(n,{fromLatLon:()=>dt,latLonToZoneNumber:()=>bt,latitudeToZoneLetter:()=>wt,toLatLon:()=>yt});const s=(t,e,i=!1)=>{if(i){let i,n=!0;return(...s)=>{n&&(t(...s),n=!1),i&&clearTimeout(i),i=setTimeout((()=>{clearTimeout(i),n=!0,i=null}),e)}}{let i;return(...n)=>{i&&(clearTimeout(i),i=null),i=setTimeout((()=>{t(...n),clearTimeout(i),n=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],n=this.base[2],s=t*this.intensity;return i=this.base[1]+s,i<this.max||(s=i-this.max,i=this.max,e=this.base[0]-s,e>this.min||(s=this.min-e,e=this.min,n=this.base[2]+s,n<this.max||(s=n-this.max,n=this.max,i-=s,i>this.min||(s=this.min-i,i=this.min,e+=s,e<this.max||(s=e-this.max,e=this.max,n-=s,n>this.min||(n=this.min)))))),[e,i,n]}}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 n=0;n<=t;n+=8)i+=e(t-n>8?8:t-n);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,n=u(40);return this.ids[n]={event:t,index:i},n}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 p=t=>e=>{const i={};for(const n of Object.keys(e))i[n]=t(e[n],n);return i},m=async t=>{await new Promise((e=>{let i=setTimeout((()=>{e(),clearTimeout(i),i=null}),t)}))},g=(t,e)=>{let i=!0,n=()=>{i=!1},s=async()=>{try{await t()}catch(t){console.log(t)}await m(e),i?s():(s=null,t=null,n=null,i=null,e=null)};return s(),n},y=(t,{checkTime:e,timeout:i}={})=>new Promise(((n,s)=>{let r,o=g((async()=>{const e=await t();e&&("function"==typeof o&&o(),r&&(clearTimeout(r),r=null),n(e),o=null,t=null,n=null)}),e||100);i&&(r=setTimeout((()=>{"function"==typeof o&&o(),r&&(clearTimeout(r),r=null),s("timeout"),s=null,o=null,t=null}),i))})),d=async(t,{times:e=5,interval:i=1e3}={times:5,interval:1e3})=>{let n=1;const s=async()=>{let r;if(n>e)throw new Error("retry times exceed");try{return r=await t(),r}catch(t){console.log(`action error, times ${n}`),console.log(t),await m(i),n+=1,await s()}};await s()};class w{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 b=async(t,e=4)=>{let i=-1;const n=[],s=async()=>{if(i+=1,t[i]){try{await t[i]()}catch(t){console.log(t)}await s()}};for(let t=0;t<e;t+=1)n.push(s());await Promise.all(n)};function M(t,e){const i=new w;let n=[];return(...s)=>{if(n=s,!(i.length>0))return i.push((async()=>{await m(e),await t(...n)}))}}class x{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 T=function(){const t={};for(let e=0;e<64;e++)t["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)]=e;return t}();function A(t){const e=new Uint8Array(6*t.length/8);let i=0,n=0,s=0;for(let r=0;r<t.length&&s<e.length;r+=1)if(n=(n<<6)+T[t.charAt(r)],i+=6,i>=8){i-=8;let t=n>>>i;e[s++]=255&t,t<<=i,n-=t}return e}class v{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 E{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 _{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 S=t=>(...e)=>new Promise(((i,n)=>{t(...e,((t,...e)=>{t&&n(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)),k=t=>180*t/Math.PI,N=t=>t*Math.PI/180,R=({w:t,h:e})=>k(Math.atan2(e,t));function L(t,e=.5){if(t.length<3||e<=0)return t;let i;return t.filter(((n,s)=>!(s>0&&P(i,n)<e||(i=t[s],0))))}function j(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 z(t,e,i){return i&&(e=N(e)),[Math.cos(e)*t[0]-Math.sin(e)*t[1],Math.sin(e)*t[0]+Math.cos(e)*t[1]]}const O=(t,e)=>{const i={x:e.x-t.x,y:e.y-t.y};return Math.atan2(i.y,i.x)},U=(t,e)=>{if(t.length<2)return 0;const i=[];let n=1/0,s=0;for(const r of t){const t=P(r,e),o=O(e,r)-e.theta;n>t&&(n=t),i.push({...r,index:s,distance:t,theta:o}),s+=1}return i.filter((t=>t.distance-n<.1)).sort(((t,e)=>t.theta-e.theta))[0].index},C=(t,e={x:0,y:0,theta:0})=>{let i=e;const n=[],s=[...t];for(;s.length>0;){const t=U(s,i);n.push(s[t]),i=s[t],s.splice(t,1)}return n},I=(t,e)=>Math.atan2(e.y,e.x)-Math.atan2(t.y,t.x),D=t=>t.split("_").map(((t,e)=>e>0?t.slice(0,1).toUpperCase()+t.slice(1):t)).join(""),F=(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 q{tmp=[];size;step;min;max;count=0;value=NaN;old;constructor({size:t=5,step:e=5,min:i=-1/0,max:n=1/0}={}){this.size=t,this.step=e,this.min=i,this.max=n}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),t):e):(this.count=0,this.value=NaN,t)}getMostNumberOfTmp(){const t={};let e,i=0;for(const n of this.tmp)t[n]?t[n]+=1:t[n]=1,t[n]>i&&(i=t[n],e=n);return{res:e,dic:t}}}class W{_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 B(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=>B(t,e)));return e.set(t,i),i}if(t instanceof Set){const i=new Set([...t].map((t=>B(t,e))));return e.set(t,i),i}if(t instanceof Map){const i=new Map;for(const[n,s]of t.entries())i.set(B(n,e),B(s,e));return e.set(t,i),i}{const i={};e.set(t,i);for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=B(t[n],e));return i}}function H(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 B(i)}function K(t,e,i="children"){const n=[];let s=!1;const r=t=>{for(let o=0;o<t.length;o+=1){const a=t[o];if(e(a)){s=!0,n.push(o);break}if(Array.isArray(a[i])){if(n.push(o),r(a[i]),s)break;n.pop()}}};return Array.isArray(t)?r(t):Array.isArray(t[i])&&r(t[i]),s?n:[]}const Q=(t,e="children",i=[],n=[])=>{let s=[];return Array.isArray(t[e])?s=t[e]:Array.isArray(t)&&(s=t),s.forEach(((t,s)=>{const r={...t};delete r[e],n.push(r),r.__indexes=[...i,s]})),s.forEach(((t,s)=>Q(t,e,[...i,s],n))),n},V=(t,e,i="children")=>{const n=[];let s=[];return Array.isArray(t[i])?s=t[i]:Array.isArray(t)&&(s=t),s.forEach((t=>{var s;t[i]&&(t[i]=V(t[i],e)),((null===(s=t[i])||void 0===s?void 0:s.length)>0||e(t))&&n.push(t)})),n},Z=.9996,G=.00669438,J=Math.pow(G,2),$=Math.pow(G,3),Y=G/(1-G),tt=Math.sqrt(1-G),et=(1-tt)/(1+tt),it=Math.pow(et,2),nt=Math.pow(et,3),st=Math.pow(et,4),rt=Math.pow(et,5),ot=1-G/4-3*J/64-5*$/256,at=3*G/8+3*J/32+45*$/1024,ht=15*J/256+45*$/1024,ct=35*$/3072,ut=1.5*et-27/32*nt+269/512*rt,lt=21/16*it-55/32*st,ft=151/96*nt-417/128*rt,pt=1097/512*st,mt=6378137,gt="CDEFGHJKLMNPQRSTUVWXX";function yt(t){const{zoneNum:e,strict:i=!0}=t;let{zoneLetter:n,northern:s}=t;const r=t.x,o=t.y;if(!n&&void 0===s)throw new Error("either zoneLetter or northern needs to be set");if(n&&void 0!==s)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(n){if(n=n.toUpperCase(),1!==n.length||-1===gt.indexOf(n))throw new RangeError("zone letter out of range (must be between C and X)");s=n>="N"}const a=r-5e5;let h=o;s||(h-=1e7);const c=h/Z/(mt*ot),u=c+ut*Math.sin(2*c)+lt*Math.sin(4*c)+ft*Math.sin(6*c)+pt*Math.sin(8*c),l=Math.sin(u),f=Math.pow(l,2),p=Math.cos(u),m=Math.tan(u),g=Math.pow(m,2),y=Math.pow(m,4),d=1-G*f,w=Math.sqrt(d),b=(1-G)/d,M=et*p*p,x=M*M,T=a/(mt/w*Z),A=Math.pow(T,2),v=Math.pow(T,3),E=Math.pow(T,4),_=Math.pow(T,5),S=Math.pow(T,6),P=(T-v/6*(1+2*g+M)+_/120*(5-2*M+28*g-3*x+8*Y+24*y))/p;return{latitude:k(u-m/b*(A/2-E/24*(5+3*g+10*M-4*x-9*Y))+S/720*(61+90*g+298*M+45*y-252*Y-3*x)),longitude:k(P)+Mt(e)}}function dt({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 n=N(t),s=Math.sin(n),r=Math.cos(n),o=Math.tan(n),a=Math.pow(o,2),h=Math.pow(o,4);let c;c=void 0===i?bt({latitude:t,longitude:e}):i;const u=wt(t),l=N(e),f=Mt(c),p=N(f),m=mt/Math.sqrt(1-G*s*s),g=Y*r*r,y=r*(l-p),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*(ot*n-at*Math.sin(2*n)+ht*Math.sin(4*n)-ct*Math.sin(6*n));let A=Z*(T+m*o*(d/2+b/24*(5-a+9*g+4*g*g)+x/720*(61-58*a+h+600*g-330*Y)));return t<0&&(A+=1e7),{x:Z*m*(y+w/6*(1-a+g)+M/120*(5-18*a+h+72*g-58*Y))+5e5,y:A,zoneNum:c,zoneLetter:u}}function wt(t){return-80<=t&&t<=84?gt[Math.floor((t+80)/8)]:null}function bt({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 Mt(t){return 6*(t-1)-180+3}return e})()));
|
package/es/index.d.ts
CHANGED
|
@@ -18,3 +18,4 @@ export { lower2camel, fixNum } from './str';
|
|
|
18
18
|
export { RegExpList } from './regexp-list';
|
|
19
19
|
export { SensorDataFilter, StringSplit } from './filter/sensor';
|
|
20
20
|
export { cloneDeep, getTreeItem, searchTree, flatTree, filterTree } from './object';
|
|
21
|
+
export * as UTM from './math/utm';
|
package/es/index.js
CHANGED
|
@@ -18,3 +18,4 @@ export { lower2camel, fixNum } from './str';
|
|
|
18
18
|
export { RegExpList } from './regexp-list';
|
|
19
19
|
export { SensorDataFilter, StringSplit } from './filter/sensor';
|
|
20
20
|
export { cloneDeep, getTreeItem, searchTree, flatTree, filterTree } from './object';
|
|
21
|
+
export * as UTM from './math/utm';
|
package/es/loop/index.d.ts
CHANGED
package/es/loop/index.js
CHANGED
|
@@ -74,26 +74,26 @@ import { sleep } from '../sleep';
|
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
};
|
|
77
|
-
export const retry = (action, { times = 5, interval = 1000 } = {
|
|
77
|
+
export const retry = async (action, { times = 5, interval = 1000 } = {
|
|
78
78
|
times: 5,
|
|
79
79
|
interval: 1000
|
|
80
80
|
})=>{
|
|
81
81
|
let count = 1;
|
|
82
|
-
const fn = async (
|
|
82
|
+
const fn = async ()=>{
|
|
83
83
|
let result;
|
|
84
84
|
if (count > times) {
|
|
85
85
|
throw new Error('retry times exceed');
|
|
86
86
|
}
|
|
87
87
|
try {
|
|
88
|
-
result = await action(
|
|
88
|
+
result = await action();
|
|
89
89
|
return result;
|
|
90
90
|
} catch (err) {
|
|
91
91
|
console.log(`action error, times ${count}`);
|
|
92
92
|
console.log(err);
|
|
93
93
|
await sleep(interval);
|
|
94
94
|
count += 1;
|
|
95
|
-
|
|
95
|
+
await fn();
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
|
-
|
|
98
|
+
await fn();
|
|
99
99
|
};
|
package/es/math/utm.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface LatLonOptions {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
zoneNum: number;
|
|
5
|
+
zoneLetter?: string;
|
|
6
|
+
northern?: boolean;
|
|
7
|
+
strict?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface WGS84Position {
|
|
10
|
+
latitude: number;
|
|
11
|
+
longitude: number;
|
|
12
|
+
}
|
|
13
|
+
export interface UTMPosition {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
zoneNum: number;
|
|
17
|
+
zoneLetter: string | null;
|
|
18
|
+
}
|
|
19
|
+
export declare function toLatLon(options: LatLonOptions): WGS84Position;
|
|
20
|
+
export declare function fromLatLon({ latitude, longitude }: WGS84Position, forceZoneNum?: number): UTMPosition;
|
|
21
|
+
export declare function latitudeToZoneLetter(latitude: any): string | null;
|
|
22
|
+
export declare function latLonToZoneNumber({ latitude, longitude }: WGS84Position): number;
|
package/es/math/utm.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { degrees, radians } from './geometry';
|
|
2
|
+
const K0 = 0.9996;
|
|
3
|
+
const E = 0.00669438;
|
|
4
|
+
const E2 = Math.pow(E, 2);
|
|
5
|
+
const E3 = Math.pow(E, 3);
|
|
6
|
+
const E_P2 = E / (1 - E);
|
|
7
|
+
const SQRT_E = Math.sqrt(1 - E);
|
|
8
|
+
const _E = (1 - SQRT_E) / (1 + SQRT_E);
|
|
9
|
+
const _E2 = Math.pow(_E, 2);
|
|
10
|
+
const _E3 = Math.pow(_E, 3);
|
|
11
|
+
const _E4 = Math.pow(_E, 4);
|
|
12
|
+
const _E5 = Math.pow(_E, 5);
|
|
13
|
+
const M1 = 1 - E / 4 - 3 * E2 / 64 - 5 * E3 / 256;
|
|
14
|
+
const M2 = 3 * E / 8 + 3 * E2 / 32 + 45 * E3 / 1024;
|
|
15
|
+
const M3 = 15 * E2 / 256 + 45 * E3 / 1024;
|
|
16
|
+
const M4 = 35 * E3 / 3072;
|
|
17
|
+
const P2 = 3 / 2 * _E - 27 / 32 * _E3 + 269 / 512 * _E5;
|
|
18
|
+
const P3 = 21 / 16 * _E2 - 55 / 32 * _E4;
|
|
19
|
+
const P4 = 151 / 96 * _E3 - 417 / 128 * _E5;
|
|
20
|
+
const P5 = 1097 / 512 * _E4;
|
|
21
|
+
const R = 6378137;
|
|
22
|
+
const ZONE_LETTERS = 'CDEFGHJKLMNPQRSTUVWXX';
|
|
23
|
+
export function toLatLon(options) {
|
|
24
|
+
const { zoneNum, strict = true } = options;
|
|
25
|
+
let { zoneLetter, northern } = options;
|
|
26
|
+
const easting = options.x;
|
|
27
|
+
const northing = options.y;
|
|
28
|
+
if (!zoneLetter && northern === undefined) {
|
|
29
|
+
throw new Error('either zoneLetter or northern needs to be set');
|
|
30
|
+
} else if (zoneLetter && northern !== undefined) {
|
|
31
|
+
throw new Error('set either zoneLetter or northern, but not both');
|
|
32
|
+
}
|
|
33
|
+
if (strict) {
|
|
34
|
+
if (easting < 100000 || 1000000 <= easting) {
|
|
35
|
+
throw new RangeError('easting out of range (must be between 100 000 m and 999 999 m)');
|
|
36
|
+
}
|
|
37
|
+
if (northing < 0 || northing > 10000000) {
|
|
38
|
+
throw new RangeError('northing out of range (must be between 0 m and 10 000 000 m)');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (zoneNum < 1 || zoneNum > 60) {
|
|
42
|
+
throw new RangeError('zone number out of range (must be between 1 and 60)');
|
|
43
|
+
}
|
|
44
|
+
if (zoneLetter) {
|
|
45
|
+
zoneLetter = zoneLetter.toUpperCase();
|
|
46
|
+
if (zoneLetter.length !== 1 || ZONE_LETTERS.indexOf(zoneLetter) === -1) {
|
|
47
|
+
throw new RangeError('zone letter out of range (must be between C and X)');
|
|
48
|
+
}
|
|
49
|
+
northern = zoneLetter >= 'N';
|
|
50
|
+
}
|
|
51
|
+
const x = easting - 500000;
|
|
52
|
+
let y = northing;
|
|
53
|
+
if (!northern) y -= 1e7;
|
|
54
|
+
const m = y / K0;
|
|
55
|
+
const mu = m / (R * M1);
|
|
56
|
+
const pRad = mu + P2 * Math.sin(2 * mu) + P3 * Math.sin(4 * mu) + P4 * Math.sin(6 * mu) + P5 * Math.sin(8 * mu);
|
|
57
|
+
const pSin = Math.sin(pRad);
|
|
58
|
+
const pSin2 = Math.pow(pSin, 2);
|
|
59
|
+
const pCos = Math.cos(pRad);
|
|
60
|
+
const pTan = Math.tan(pRad);
|
|
61
|
+
const pTan2 = Math.pow(pTan, 2);
|
|
62
|
+
const pTan4 = Math.pow(pTan, 4);
|
|
63
|
+
const epSin = 1 - E * pSin2;
|
|
64
|
+
const epSinSqrt = Math.sqrt(epSin);
|
|
65
|
+
const n = R / epSinSqrt;
|
|
66
|
+
const r = (1 - E) / epSin;
|
|
67
|
+
const c = _E * pCos * pCos;
|
|
68
|
+
const c2 = c * c;
|
|
69
|
+
const d = x / (n * K0);
|
|
70
|
+
const d2 = Math.pow(d, 2);
|
|
71
|
+
const d3 = Math.pow(d, 3);
|
|
72
|
+
const d4 = Math.pow(d, 4);
|
|
73
|
+
const d5 = Math.pow(d, 5);
|
|
74
|
+
const d6 = Math.pow(d, 6);
|
|
75
|
+
const latitude = pRad - pTan / r * (d2 / 2 - d4 / 24 * (5 + 3 * pTan2 + 10 * c - 4 * c2 - 9 * E_P2)) + d6 / 720 * (61 + 90 * pTan2 + 298 * c + 45 * pTan4 - 252 * E_P2 - 3 * c2);
|
|
76
|
+
const longitude = (d - d3 / 6 * (1 + 2 * pTan2 + c) + d5 / 120 * (5 - 2 * c + 28 * pTan2 - 3 * c2 + 8 * E_P2 + 24 * pTan4)) / pCos;
|
|
77
|
+
return {
|
|
78
|
+
latitude: degrees(latitude),
|
|
79
|
+
longitude: degrees(longitude) + zoneNumberToCentralLongitude(zoneNum)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export function fromLatLon({ latitude, longitude }, forceZoneNum) {
|
|
83
|
+
if (latitude > 84 || latitude < -80) {
|
|
84
|
+
throw new RangeError('latitude out of range (must be between 80 deg S and 84 deg N)');
|
|
85
|
+
}
|
|
86
|
+
if (longitude > 180 || longitude < -180) {
|
|
87
|
+
throw new RangeError('longitude out of range (must be between 180 deg W and 180 deg E)');
|
|
88
|
+
}
|
|
89
|
+
const latRad = radians(latitude);
|
|
90
|
+
const latSin = Math.sin(latRad);
|
|
91
|
+
const latCos = Math.cos(latRad);
|
|
92
|
+
const latTan = Math.tan(latRad);
|
|
93
|
+
const latTan2 = Math.pow(latTan, 2);
|
|
94
|
+
const latTan4 = Math.pow(latTan, 4);
|
|
95
|
+
let zoneNum;
|
|
96
|
+
if (forceZoneNum === undefined) {
|
|
97
|
+
zoneNum = latLonToZoneNumber({
|
|
98
|
+
latitude,
|
|
99
|
+
longitude
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
zoneNum = forceZoneNum;
|
|
103
|
+
}
|
|
104
|
+
const zoneLetter = latitudeToZoneLetter(latitude);
|
|
105
|
+
const lonRad = radians(longitude);
|
|
106
|
+
const centralLon = zoneNumberToCentralLongitude(zoneNum);
|
|
107
|
+
const centralLonRad = radians(centralLon);
|
|
108
|
+
const n = R / Math.sqrt(1 - E * latSin * latSin);
|
|
109
|
+
const c = E_P2 * latCos * latCos;
|
|
110
|
+
const a = latCos * (lonRad - centralLonRad);
|
|
111
|
+
const a2 = Math.pow(a, 2);
|
|
112
|
+
const a3 = Math.pow(a, 3);
|
|
113
|
+
const a4 = Math.pow(a, 4);
|
|
114
|
+
const a5 = Math.pow(a, 5);
|
|
115
|
+
const a6 = Math.pow(a, 6);
|
|
116
|
+
const m = R * (M1 * latRad - M2 * Math.sin(2 * latRad) + M3 * Math.sin(4 * latRad) - M4 * Math.sin(6 * latRad));
|
|
117
|
+
const easting = K0 * n * (a + a3 / 6 * (1 - latTan2 + c) + a5 / 120 * (5 - 18 * latTan2 + latTan4 + 72 * c - 58 * E_P2)) + 500000;
|
|
118
|
+
let northing = K0 * (m + n * latTan * (a2 / 2 + a4 / 24 * (5 - latTan2 + 9 * c + 4 * c * c) + a6 / 720 * (61 - 58 * latTan2 + latTan4 + 600 * c - 330 * E_P2)));
|
|
119
|
+
if (latitude < 0) northing += 1e7;
|
|
120
|
+
return {
|
|
121
|
+
x: easting,
|
|
122
|
+
y: northing,
|
|
123
|
+
zoneNum: zoneNum,
|
|
124
|
+
zoneLetter: zoneLetter
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export function latitudeToZoneLetter(latitude) {
|
|
128
|
+
if (-80 <= latitude && latitude <= 84) {
|
|
129
|
+
return ZONE_LETTERS[Math.floor((latitude + 80) / 8)];
|
|
130
|
+
} else {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export function latLonToZoneNumber({ latitude, longitude }) {
|
|
135
|
+
if (56 <= latitude && latitude < 64 && 3 <= longitude && longitude < 12) return 32;
|
|
136
|
+
if (72 <= latitude && latitude <= 84 && longitude >= 0) {
|
|
137
|
+
if (longitude < 9) return 31;
|
|
138
|
+
if (longitude < 21) return 33;
|
|
139
|
+
if (longitude < 33) return 35;
|
|
140
|
+
if (longitude < 42) return 37;
|
|
141
|
+
}
|
|
142
|
+
return Math.floor((longitude + 180) / 6) + 1;
|
|
143
|
+
}
|
|
144
|
+
function zoneNumberToCentralLongitude(zoneNum) {
|
|
145
|
+
return (zoneNum - 1) * 6 - 180 + 3;
|
|
146
|
+
}
|
package/es/object/index.js
CHANGED
|
@@ -4,22 +4,31 @@ export function cloneDeep(data, hash = new WeakMap()) {
|
|
|
4
4
|
} else if (hash.has(data)) {
|
|
5
5
|
return hash.get(data);
|
|
6
6
|
} else if (Array.isArray(data)) {
|
|
7
|
-
|
|
7
|
+
const clone = data.map((item)=>cloneDeep(item, hash));
|
|
8
|
+
hash.set(data, clone);
|
|
9
|
+
return clone;
|
|
8
10
|
} else if (data instanceof Set) {
|
|
9
|
-
|
|
11
|
+
const clone = new Set([
|
|
10
12
|
...data
|
|
11
|
-
]);
|
|
13
|
+
].map((item)=>cloneDeep(item, hash)));
|
|
14
|
+
hash.set(data, clone);
|
|
15
|
+
return clone;
|
|
12
16
|
} else if (data instanceof Map) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
const clone = new Map();
|
|
18
|
+
for (const [key, value] of data.entries()){
|
|
19
|
+
clone.set(cloneDeep(key, hash), cloneDeep(value, hash));
|
|
20
|
+
}
|
|
21
|
+
hash.set(data, clone);
|
|
22
|
+
return clone;
|
|
16
23
|
} else {
|
|
17
|
-
const
|
|
18
|
-
hash.set(data,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
const clone = {};
|
|
25
|
+
hash.set(data, clone);
|
|
26
|
+
for(const key in data){
|
|
27
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
28
|
+
clone[key] = cloneDeep(data[key], hash);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return clone;
|
|
23
32
|
}
|
|
24
33
|
}
|
|
25
34
|
export function getTreeItem(tree, indexes) {
|
package/lib/index.d.ts
CHANGED
|
@@ -18,3 +18,4 @@ export { lower2camel, fixNum } from './str';
|
|
|
18
18
|
export { RegExpList } from './regexp-list';
|
|
19
19
|
export { SensorDataFilter, StringSplit } from './filter/sensor';
|
|
20
20
|
export { cloneDeep, getTreeItem, searchTree, flatTree, filterTree } from './object';
|
|
21
|
+
export * as UTM from './math/utm';
|
package/lib/index.js
CHANGED
|
@@ -42,6 +42,9 @@ _export(exports, {
|
|
|
42
42
|
SyncQueue: function() {
|
|
43
43
|
return _queue.SyncQueue;
|
|
44
44
|
},
|
|
45
|
+
UTM: function() {
|
|
46
|
+
return _utm;
|
|
47
|
+
},
|
|
45
48
|
WatchDog: function() {
|
|
46
49
|
return _watchdog.WatchDog;
|
|
47
50
|
},
|
|
@@ -156,6 +159,7 @@ const _str = require("./str");
|
|
|
156
159
|
const _regexplist = require("./regexp-list");
|
|
157
160
|
const _sensor = require("./filter/sensor");
|
|
158
161
|
const _object = require("./object");
|
|
162
|
+
const _utm = /*#__PURE__*/ _interop_require_wildcard(require("./math/utm"));
|
|
159
163
|
function _getRequireWildcardCache(nodeInterop) {
|
|
160
164
|
if (typeof WeakMap !== "function") return null;
|
|
161
165
|
var cacheBabelInterop = new WeakMap();
|
package/lib/loop/index.d.ts
CHANGED
package/lib/loop/index.js
CHANGED
|
@@ -81,26 +81,26 @@ const waitFor = (bool, { checkTime, timeout } = {})=>{
|
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
83
|
};
|
|
84
|
-
const retry = (action, { times = 5, interval = 1000 } = {
|
|
84
|
+
const retry = async (action, { times = 5, interval = 1000 } = {
|
|
85
85
|
times: 5,
|
|
86
86
|
interval: 1000
|
|
87
87
|
})=>{
|
|
88
88
|
let count = 1;
|
|
89
|
-
const fn = async (
|
|
89
|
+
const fn = async ()=>{
|
|
90
90
|
let result;
|
|
91
91
|
if (count > times) {
|
|
92
92
|
throw new Error('retry times exceed');
|
|
93
93
|
}
|
|
94
94
|
try {
|
|
95
|
-
result = await action(
|
|
95
|
+
result = await action();
|
|
96
96
|
return result;
|
|
97
97
|
} catch (err) {
|
|
98
98
|
console.log(`action error, times ${count}`);
|
|
99
99
|
console.log(err);
|
|
100
100
|
await (0, _sleep.sleep)(interval);
|
|
101
101
|
count += 1;
|
|
102
|
-
|
|
102
|
+
await fn();
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
|
-
|
|
105
|
+
await fn();
|
|
106
106
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface LatLonOptions {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
zoneNum: number;
|
|
5
|
+
zoneLetter?: string;
|
|
6
|
+
northern?: boolean;
|
|
7
|
+
strict?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface WGS84Position {
|
|
10
|
+
latitude: number;
|
|
11
|
+
longitude: number;
|
|
12
|
+
}
|
|
13
|
+
export interface UTMPosition {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
zoneNum: number;
|
|
17
|
+
zoneLetter: string | null;
|
|
18
|
+
}
|
|
19
|
+
export declare function toLatLon(options: LatLonOptions): WGS84Position;
|
|
20
|
+
export declare function fromLatLon({ latitude, longitude }: WGS84Position, forceZoneNum?: number): UTMPosition;
|
|
21
|
+
export declare function latitudeToZoneLetter(latitude: any): string | null;
|
|
22
|
+
export declare function latLonToZoneNumber({ latitude, longitude }: WGS84Position): number;
|
package/lib/math/utm.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
fromLatLon: function() {
|
|
13
|
+
return fromLatLon;
|
|
14
|
+
},
|
|
15
|
+
latLonToZoneNumber: function() {
|
|
16
|
+
return latLonToZoneNumber;
|
|
17
|
+
},
|
|
18
|
+
latitudeToZoneLetter: function() {
|
|
19
|
+
return latitudeToZoneLetter;
|
|
20
|
+
},
|
|
21
|
+
toLatLon: function() {
|
|
22
|
+
return toLatLon;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const _geometry = require("./geometry");
|
|
26
|
+
const K0 = 0.9996;
|
|
27
|
+
const E = 0.00669438;
|
|
28
|
+
const E2 = Math.pow(E, 2);
|
|
29
|
+
const E3 = Math.pow(E, 3);
|
|
30
|
+
const E_P2 = E / (1 - E);
|
|
31
|
+
const SQRT_E = Math.sqrt(1 - E);
|
|
32
|
+
const _E = (1 - SQRT_E) / (1 + SQRT_E);
|
|
33
|
+
const _E2 = Math.pow(_E, 2);
|
|
34
|
+
const _E3 = Math.pow(_E, 3);
|
|
35
|
+
const _E4 = Math.pow(_E, 4);
|
|
36
|
+
const _E5 = Math.pow(_E, 5);
|
|
37
|
+
const M1 = 1 - E / 4 - 3 * E2 / 64 - 5 * E3 / 256;
|
|
38
|
+
const M2 = 3 * E / 8 + 3 * E2 / 32 + 45 * E3 / 1024;
|
|
39
|
+
const M3 = 15 * E2 / 256 + 45 * E3 / 1024;
|
|
40
|
+
const M4 = 35 * E3 / 3072;
|
|
41
|
+
const P2 = 3 / 2 * _E - 27 / 32 * _E3 + 269 / 512 * _E5;
|
|
42
|
+
const P3 = 21 / 16 * _E2 - 55 / 32 * _E4;
|
|
43
|
+
const P4 = 151 / 96 * _E3 - 417 / 128 * _E5;
|
|
44
|
+
const P5 = 1097 / 512 * _E4;
|
|
45
|
+
const R = 6378137;
|
|
46
|
+
const ZONE_LETTERS = 'CDEFGHJKLMNPQRSTUVWXX';
|
|
47
|
+
function toLatLon(options) {
|
|
48
|
+
const { zoneNum, strict = true } = options;
|
|
49
|
+
let { zoneLetter, northern } = options;
|
|
50
|
+
const easting = options.x;
|
|
51
|
+
const northing = options.y;
|
|
52
|
+
if (!zoneLetter && northern === undefined) {
|
|
53
|
+
throw new Error('either zoneLetter or northern needs to be set');
|
|
54
|
+
} else if (zoneLetter && northern !== undefined) {
|
|
55
|
+
throw new Error('set either zoneLetter or northern, but not both');
|
|
56
|
+
}
|
|
57
|
+
if (strict) {
|
|
58
|
+
if (easting < 100000 || 1000000 <= easting) {
|
|
59
|
+
throw new RangeError('easting out of range (must be between 100 000 m and 999 999 m)');
|
|
60
|
+
}
|
|
61
|
+
if (northing < 0 || northing > 10000000) {
|
|
62
|
+
throw new RangeError('northing out of range (must be between 0 m and 10 000 000 m)');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (zoneNum < 1 || zoneNum > 60) {
|
|
66
|
+
throw new RangeError('zone number out of range (must be between 1 and 60)');
|
|
67
|
+
}
|
|
68
|
+
if (zoneLetter) {
|
|
69
|
+
zoneLetter = zoneLetter.toUpperCase();
|
|
70
|
+
if (zoneLetter.length !== 1 || ZONE_LETTERS.indexOf(zoneLetter) === -1) {
|
|
71
|
+
throw new RangeError('zone letter out of range (must be between C and X)');
|
|
72
|
+
}
|
|
73
|
+
northern = zoneLetter >= 'N';
|
|
74
|
+
}
|
|
75
|
+
const x = easting - 500000;
|
|
76
|
+
let y = northing;
|
|
77
|
+
if (!northern) y -= 1e7;
|
|
78
|
+
const m = y / K0;
|
|
79
|
+
const mu = m / (R * M1);
|
|
80
|
+
const pRad = mu + P2 * Math.sin(2 * mu) + P3 * Math.sin(4 * mu) + P4 * Math.sin(6 * mu) + P5 * Math.sin(8 * mu);
|
|
81
|
+
const pSin = Math.sin(pRad);
|
|
82
|
+
const pSin2 = Math.pow(pSin, 2);
|
|
83
|
+
const pCos = Math.cos(pRad);
|
|
84
|
+
const pTan = Math.tan(pRad);
|
|
85
|
+
const pTan2 = Math.pow(pTan, 2);
|
|
86
|
+
const pTan4 = Math.pow(pTan, 4);
|
|
87
|
+
const epSin = 1 - E * pSin2;
|
|
88
|
+
const epSinSqrt = Math.sqrt(epSin);
|
|
89
|
+
const n = R / epSinSqrt;
|
|
90
|
+
const r = (1 - E) / epSin;
|
|
91
|
+
const c = _E * pCos * pCos;
|
|
92
|
+
const c2 = c * c;
|
|
93
|
+
const d = x / (n * K0);
|
|
94
|
+
const d2 = Math.pow(d, 2);
|
|
95
|
+
const d3 = Math.pow(d, 3);
|
|
96
|
+
const d4 = Math.pow(d, 4);
|
|
97
|
+
const d5 = Math.pow(d, 5);
|
|
98
|
+
const d6 = Math.pow(d, 6);
|
|
99
|
+
const latitude = pRad - pTan / r * (d2 / 2 - d4 / 24 * (5 + 3 * pTan2 + 10 * c - 4 * c2 - 9 * E_P2)) + d6 / 720 * (61 + 90 * pTan2 + 298 * c + 45 * pTan4 - 252 * E_P2 - 3 * c2);
|
|
100
|
+
const longitude = (d - d3 / 6 * (1 + 2 * pTan2 + c) + d5 / 120 * (5 - 2 * c + 28 * pTan2 - 3 * c2 + 8 * E_P2 + 24 * pTan4)) / pCos;
|
|
101
|
+
return {
|
|
102
|
+
latitude: (0, _geometry.degrees)(latitude),
|
|
103
|
+
longitude: (0, _geometry.degrees)(longitude) + zoneNumberToCentralLongitude(zoneNum)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function fromLatLon({ latitude, longitude }, forceZoneNum) {
|
|
107
|
+
if (latitude > 84 || latitude < -80) {
|
|
108
|
+
throw new RangeError('latitude out of range (must be between 80 deg S and 84 deg N)');
|
|
109
|
+
}
|
|
110
|
+
if (longitude > 180 || longitude < -180) {
|
|
111
|
+
throw new RangeError('longitude out of range (must be between 180 deg W and 180 deg E)');
|
|
112
|
+
}
|
|
113
|
+
const latRad = (0, _geometry.radians)(latitude);
|
|
114
|
+
const latSin = Math.sin(latRad);
|
|
115
|
+
const latCos = Math.cos(latRad);
|
|
116
|
+
const latTan = Math.tan(latRad);
|
|
117
|
+
const latTan2 = Math.pow(latTan, 2);
|
|
118
|
+
const latTan4 = Math.pow(latTan, 4);
|
|
119
|
+
let zoneNum;
|
|
120
|
+
if (forceZoneNum === undefined) {
|
|
121
|
+
zoneNum = latLonToZoneNumber({
|
|
122
|
+
latitude,
|
|
123
|
+
longitude
|
|
124
|
+
});
|
|
125
|
+
} else {
|
|
126
|
+
zoneNum = forceZoneNum;
|
|
127
|
+
}
|
|
128
|
+
const zoneLetter = latitudeToZoneLetter(latitude);
|
|
129
|
+
const lonRad = (0, _geometry.radians)(longitude);
|
|
130
|
+
const centralLon = zoneNumberToCentralLongitude(zoneNum);
|
|
131
|
+
const centralLonRad = (0, _geometry.radians)(centralLon);
|
|
132
|
+
const n = R / Math.sqrt(1 - E * latSin * latSin);
|
|
133
|
+
const c = E_P2 * latCos * latCos;
|
|
134
|
+
const a = latCos * (lonRad - centralLonRad);
|
|
135
|
+
const a2 = Math.pow(a, 2);
|
|
136
|
+
const a3 = Math.pow(a, 3);
|
|
137
|
+
const a4 = Math.pow(a, 4);
|
|
138
|
+
const a5 = Math.pow(a, 5);
|
|
139
|
+
const a6 = Math.pow(a, 6);
|
|
140
|
+
const m = R * (M1 * latRad - M2 * Math.sin(2 * latRad) + M3 * Math.sin(4 * latRad) - M4 * Math.sin(6 * latRad));
|
|
141
|
+
const easting = K0 * n * (a + a3 / 6 * (1 - latTan2 + c) + a5 / 120 * (5 - 18 * latTan2 + latTan4 + 72 * c - 58 * E_P2)) + 500000;
|
|
142
|
+
let northing = K0 * (m + n * latTan * (a2 / 2 + a4 / 24 * (5 - latTan2 + 9 * c + 4 * c * c) + a6 / 720 * (61 - 58 * latTan2 + latTan4 + 600 * c - 330 * E_P2)));
|
|
143
|
+
if (latitude < 0) northing += 1e7;
|
|
144
|
+
return {
|
|
145
|
+
x: easting,
|
|
146
|
+
y: northing,
|
|
147
|
+
zoneNum: zoneNum,
|
|
148
|
+
zoneLetter: zoneLetter
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function latitudeToZoneLetter(latitude) {
|
|
152
|
+
if (-80 <= latitude && latitude <= 84) {
|
|
153
|
+
return ZONE_LETTERS[Math.floor((latitude + 80) / 8)];
|
|
154
|
+
} else {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function latLonToZoneNumber({ latitude, longitude }) {
|
|
159
|
+
if (56 <= latitude && latitude < 64 && 3 <= longitude && longitude < 12) return 32;
|
|
160
|
+
if (72 <= latitude && latitude <= 84 && longitude >= 0) {
|
|
161
|
+
if (longitude < 9) return 31;
|
|
162
|
+
if (longitude < 21) return 33;
|
|
163
|
+
if (longitude < 33) return 35;
|
|
164
|
+
if (longitude < 42) return 37;
|
|
165
|
+
}
|
|
166
|
+
return Math.floor((longitude + 180) / 6) + 1;
|
|
167
|
+
}
|
|
168
|
+
function zoneNumberToCentralLongitude(zoneNum) {
|
|
169
|
+
return (zoneNum - 1) * 6 - 180 + 3;
|
|
170
|
+
}
|
package/lib/object/index.js
CHANGED
|
@@ -31,22 +31,31 @@ function cloneDeep(data, hash = new WeakMap()) {
|
|
|
31
31
|
} else if (hash.has(data)) {
|
|
32
32
|
return hash.get(data);
|
|
33
33
|
} else if (Array.isArray(data)) {
|
|
34
|
-
|
|
34
|
+
const clone = data.map((item)=>cloneDeep(item, hash));
|
|
35
|
+
hash.set(data, clone);
|
|
36
|
+
return clone;
|
|
35
37
|
} else if (data instanceof Set) {
|
|
36
|
-
|
|
38
|
+
const clone = new Set([
|
|
37
39
|
...data
|
|
38
|
-
]);
|
|
40
|
+
].map((item)=>cloneDeep(item, hash)));
|
|
41
|
+
hash.set(data, clone);
|
|
42
|
+
return clone;
|
|
39
43
|
} else if (data instanceof Map) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
const clone = new Map();
|
|
45
|
+
for (const [key, value] of data.entries()){
|
|
46
|
+
clone.set(cloneDeep(key, hash), cloneDeep(value, hash));
|
|
47
|
+
}
|
|
48
|
+
hash.set(data, clone);
|
|
49
|
+
return clone;
|
|
43
50
|
} else {
|
|
44
|
-
const
|
|
45
|
-
hash.set(data,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
const clone = {};
|
|
52
|
+
hash.set(data, clone);
|
|
53
|
+
for(const key in data){
|
|
54
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
55
|
+
clone[key] = cloneDeep(data[key], hash);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return clone;
|
|
50
59
|
}
|
|
51
60
|
}
|
|
52
61
|
function getTreeItem(tree, indexes) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.179",
|
|
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": "a2e0127445a5d985e2c27f85aa12f5d5bef71a0a",
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"del": "^5.1.0",
|
|
24
24
|
"eslint": "^8.42.0",
|