@idm-plugin/geo 1.0.2 → 1.0.3

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import M from "moment";
1
+ import y from "moment";
2
2
  import "moment-timezone";
3
3
  import T from "tz-lookup";
4
4
  import * as N from "@turf/turf";
@@ -9,8 +9,8 @@ class u {
9
9
  * @param lat
10
10
  */
11
11
  static guessTimeZoneOffset(e, t) {
12
- const o = T(t, e), i = M().tz(o).utcOffset();
13
- return this.roundPrecision(i / 60, 1);
12
+ const r = T(t, e), s = y().tz(r).utcOffset();
13
+ return this.roundPrecision(s / 60, 1);
14
14
  }
15
15
  /**
16
16
  * 将时间offset转换为时区,例如:8.5 => +08:30
@@ -18,21 +18,21 @@ class u {
18
18
  * @return timezone => +08:30
19
19
  */
20
20
  static prettyTimeZoneOffset(e) {
21
- let t = Math.floor(Math.abs(e)), o = Math.round((Math.abs(e) - t) * 60);
22
- return o = o > 9 ? o : `0${o}`, t = t > 9 ? t : `0${t}`, e > 0 ? `+${t}:${o}` : `-${t}:${o}`;
21
+ let t = Math.floor(Math.abs(e)), r = Math.round((Math.abs(e) - t) * 60);
22
+ return r = r > 9 ? r : `0${r}`, t = t > 9 ? t : `0${t}`, e > 0 ? `+${t}:${r}` : `-${t}:${r}`;
23
23
  }
24
- static lng2pretty(e, t = 6, o = "H°M′") {
24
+ static lng2pretty(e, t = 6, r = "H°M′") {
25
25
  e = u.convertToStdLng(e, t);
26
- let i = "E";
27
- e < 0 && (i = "W"), e = Math.abs(e), o = o.toUpperCase();
28
- let r = e * 3600, n, p, s, d, a, f;
29
- n = r % 3600 % 60, o.indexOf("S") !== -1 && (r = r - n, p = u.padNumber(n, 2, 2)), s = r / 60 % 60, o.indexOf("M") !== -1 && (o.indexOf("S") !== -1 ? d = u.roundPrecision(s, t).toString().padStart(2, "0") : d = u.padNumber(s, 2, 2), r = r - s * 60), a = r / 3600, o.indexOf("M") !== -1 ? f = u.roundPrecision(a, t).toString().padStart(3, "0") : f = u.padNumber(a, 3, 2);
30
- const h = `${o.replace(/S+/gi, p).replace(/M+/gi, d).replace(/H+/gi, f)}${i}`;
26
+ let s = "E";
27
+ e < 0 && (s = "W"), e = Math.abs(e), r = r.toUpperCase();
28
+ let i = e * 3600, o, n, c, a, m, p;
29
+ o = i % 3600 % 60, r.indexOf("S") !== -1 && (i = i - o, n = u.padNumber(o, 2, 2)), c = i / 60 % 60, r.indexOf("M") !== -1 && (r.indexOf("S") !== -1 ? a = u.roundPrecision(c, t).toString().padStart(2, "0") : a = u.padNumber(c, 2, 2), i = i - c * 60), m = i / 3600, r.indexOf("M") !== -1 ? p = u.roundPrecision(m, t).toString().padStart(3, "0") : p = u.padNumber(m, 3, 2);
30
+ const h = `${r.replace(/S+/gi, n).replace(/M+/gi, a).replace(/H+/gi, p)}${s}`;
31
31
  return {
32
- direction: i,
33
- degree: u.roundPrecision(a, t),
34
- minute: u.roundPrecision(s, t),
35
- second: u.roundPrecision(n, t),
32
+ direction: s,
33
+ degree: u.roundPrecision(m, t),
34
+ minute: u.roundPrecision(c, t),
35
+ second: u.roundPrecision(o, t),
36
36
  pretty: h
37
37
  };
38
38
  }
@@ -42,59 +42,59 @@ class u {
42
42
  * @param precision 精确度
43
43
  * @param format 格式化
44
44
  */
45
- static lat2pretty(e, t = 6, o = "H°M′") {
45
+ static lat2pretty(e, t = 6, r = "H°M′") {
46
46
  e = e % 180;
47
- let i = "N";
48
- e < 0 && (i = "S"), e = Math.abs(e), o = o.toUpperCase();
49
- let r = e * 3600, n, p, s, d, a, f;
50
- n = r % 3600 % 60, o.indexOf("S") !== -1 && (r = r - n, p = u.padNumber(n, 2, 2)), s = r / 60 % 60, o.indexOf("M") !== -1 && (o.indexOf("S") !== -1 ? d = u.roundPrecision(s, t).toString().padStart(2, "0") : d = u.padNumber(s, 2, 2), r = r - s * 60), a = r / 3600, o.indexOf("M") !== -1 ? f = u.roundPrecision(a, t).toString().padStart(2, "0") : f = u.padNumber(a, 2, 2);
51
- const h = `${o.replace(/S+/gi, p).replace(/M+/gi, d).replace(/H+/gi, f)}${i}`;
47
+ let s = "N";
48
+ e < 0 && (s = "S"), e = Math.abs(e), r = r.toUpperCase();
49
+ let i = e * 3600, o, n, c, a, m, p;
50
+ o = i % 3600 % 60, r.indexOf("S") !== -1 && (i = i - o, n = u.padNumber(o, 2, 2)), c = i / 60 % 60, r.indexOf("M") !== -1 && (r.indexOf("S") !== -1 ? a = u.roundPrecision(c, t).toString().padStart(2, "0") : a = u.padNumber(c, 2, 2), i = i - c * 60), m = i / 3600, r.indexOf("M") !== -1 ? p = u.roundPrecision(m, t).toString().padStart(2, "0") : p = u.padNumber(m, 2, 2);
51
+ const h = `${r.replace(/S+/gi, n).replace(/M+/gi, a).replace(/H+/gi, p)}${s}`;
52
52
  return {
53
- direction: i,
54
- degree: u.roundPrecision(a, t),
55
- minute: u.roundPrecision(s, t),
56
- second: u.roundPrecision(n, t),
53
+ direction: s,
54
+ degree: u.roundPrecision(m, t),
55
+ minute: u.roundPrecision(c, t),
56
+ second: u.roundPrecision(o, t),
57
57
  pretty: h
58
58
  };
59
59
  }
60
60
  static str2Lng(e, t = 6) {
61
- let o;
61
+ let r;
62
62
  if (isNaN(e)) {
63
63
  e = u.strReplace(e, "LNG");
64
- const i = e[e.length - 1].toUpperCase();
64
+ const s = e[e.length - 1].toUpperCase();
65
65
  e = e.substring(0, e.length - 1).trim();
66
- const r = e.split(" ").filter((s) => s !== "").map((s) => Number(s));
67
- let [n, p] = r;
68
- if (n > 360 && !p) {
69
- const s = this.roundPrecision(n / 100, 0);
70
- p = n - s * 100, n = s;
66
+ const i = e.split(" ").filter((c) => c !== "").map((c) => Number(c));
67
+ let [o, n] = i;
68
+ if (o > 360 && !n) {
69
+ const c = this.roundPrecision(o / 100, 0);
70
+ n = o - c * 100, o = c;
71
71
  }
72
- o = n + (p ?? 0) / 60, i === "W" && (o = o * -1);
72
+ r = o + (n ?? 0) / 60, s === "W" && (r = r * -1);
73
73
  } else
74
- o = Number(e);
75
- return u.convertToStdLng(o, t);
74
+ r = Number(e);
75
+ return u.convertToStdLng(r, t);
76
76
  }
77
77
  static str2Lat(e, t = 6) {
78
- let o;
78
+ let r;
79
79
  if (isNaN(e)) {
80
80
  e = u.strReplace(e, "LAT");
81
- const i = e[e.length - 1].toUpperCase();
81
+ const s = e[e.length - 1].toUpperCase();
82
82
  e = e.substring(0, e.length - 1).trim();
83
- const r = e.split(" ").filter((s) => s !== "").map((s) => Number(s));
84
- let [n, p] = r;
85
- if (n > 90 && !p) {
86
- const s = this.roundPrecision(n / 100, 0);
87
- p = n - s * 100, n = s;
83
+ const i = e.split(" ").filter((c) => c !== "").map((c) => Number(c));
84
+ let [o, n] = i;
85
+ if (o > 90 && !n) {
86
+ const c = this.roundPrecision(o / 100, 0);
87
+ n = o - c * 100, o = c;
88
88
  }
89
- o = n + (p ?? 0) / 60, i === "S" && (o = o * -1);
89
+ r = o + (n ?? 0) / 60, s === "S" && (r = r * -1);
90
90
  } else
91
- o = Number(e);
92
- return u.roundPrecision(o, t);
91
+ r = Number(e);
92
+ return u.roundPrecision(r, t);
93
93
  }
94
- static str2LngOrLat(e, t = 6, o = "LAT") {
95
- e = u.strReplace(e, o);
96
- const i = e[e.length - 1].toUpperCase();
97
- return ["N", "S"].includes(i) ? {
94
+ static str2LngOrLat(e, t = 6, r = "LAT") {
95
+ e = u.strReplace(e, r);
96
+ const s = e[e.length - 1].toUpperCase();
97
+ return ["N", "S"].includes(s) ? {
98
98
  lat: u.str2Lat(e, t)
99
99
  } : {
100
100
  lng: u.str2Lng(e, t)
@@ -105,8 +105,8 @@ class u {
105
105
  }
106
106
  static roundPrecision(e, t = 4) {
107
107
  if (typeof e == "number") {
108
- const o = Number("1".padEnd(t + 1, "0"));
109
- return Math.round(e * o) / o;
108
+ const r = Number("1".padEnd(t + 1, "0"));
109
+ return Math.round(e * r) / r;
110
110
  }
111
111
  return e;
112
112
  }
@@ -130,12 +130,12 @@ class u {
130
130
  }
131
131
  static strReplace(e, t = "LAT") {
132
132
  e = e.replace(/([0-9]+)\.([0-9]+\.[0-9]+)/g, "$1 $2").replace(/-/g, " ").replace(/°/, " ").replace(/'/g, " ").replace(/′/g, " ").replace(/"/g, " ").replace(/∼/g, " ").replace(/°/g, " ").replace(/,/g, ".").replace(/^ /g, "").replace(/ $/g, "").trim();
133
- const o = e[e.length - 1].toUpperCase();
134
- if (!["N", "S", "E", "W"].includes(o)) {
135
- const i = e, r = Number(i.split(" ")[0]);
136
- if (isNaN(r))
133
+ const r = e[e.length - 1].toUpperCase();
134
+ if (!["N", "S", "E", "W"].includes(r)) {
135
+ const s = e, i = Number(s.split(" ")[0]);
136
+ if (isNaN(i))
137
137
  throw new Error(`invalid Lat/Lng: ${e}`);
138
- r >= 90 ? e = `${i}E` : r <= -90 ? e = `${i}W` : ["LAN", "LNG"].includes(t == null ? void 0 : t.toUpperCase()) ? e = `${i}${r > 0 ? "E" : "W"}` : e = `${i}${r > 0 ? "N" : "S"}`;
138
+ i >= 90 ? e = `${s}E` : i <= -90 ? e = `${s}W` : ["LAN", "LNG"].includes(t == null ? void 0 : t.toUpperCase()) ? e = `${s}${i > 0 ? "E" : "W"}` : e = `${s}${i > 0 ? "N" : "S"}`;
139
139
  }
140
140
  return e;
141
141
  }
@@ -146,73 +146,91 @@ class u {
146
146
  * @param intPrecision 整数位数
147
147
  * @param dcmPrecision 小数位数
148
148
  */
149
- static padNumber(e, t = 2, o = 2) {
150
- const i = Math.trunc(e).toString().padStart(t, "0"), r = Math.trunc(u.roundPrecision(e - Math.trunc(e), o) * Math.pow(10, o)).toString().padStart(o, "0");
151
- return `${i}.${r}`;
149
+ static padNumber(e, t = 2, r = 2) {
150
+ const s = Math.trunc(e).toString().padStart(t, "0"), i = Math.trunc(u.roundPrecision(e - Math.trunc(e), r) * Math.pow(10, r)).toString().padStart(r, "0");
151
+ return `${s}.${i}`;
152
152
  }
153
153
  }
154
- class D {
154
+ class x {
155
155
  static convert2Geojson(e) {
156
+ var r;
156
157
  const t = N.featureCollection([]);
157
- for (const o of e) {
158
- if (o.forecasts)
159
- for (const i of o.forecasts) {
160
- const r = [], n = M(i.date).utc(), p = `${o.name}-${i.model}`;
161
- for (const s in i == null ? void 0 : i.hours) {
162
- const d = i.hours[s];
163
- d.wind.spd = d.wind.spd || d.wind.speed;
164
- const a = n.clone().add(Number(s), "hour"), f = N.point([d.lng, d.lat], {
165
- date: a.format(),
166
- hour: Number(s),
167
- format: a.format("MMM-DD/HHmm[Z]"),
168
- pressure: d.pressure > 1e4 ? u.roundPrecision(d.pressure / 100, 0) : u.roundPrecision(d.pressure, 0),
169
- gusts: d.gusts,
170
- wind: d.wind || {},
171
- movement: d.movement,
172
- category: p,
158
+ for (const s of e) {
159
+ if (s.forecasts) {
160
+ const i = (r = s.history) == null ? void 0 : r[0];
161
+ for (const o of s.forecasts) {
162
+ const n = [], c = y(o.date).utc(), a = `${s.name}-${o.model}`;
163
+ if (i) {
164
+ const m = y(i.updated).utc(), p = N.point([i.lng, i.lat], {
165
+ name: s.name,
166
+ date: m.format(),
167
+ hour: 0,
168
+ format: m.format("MMM-DD/HHmm[Z]"),
169
+ pressure: i.pressure > 1e4 ? u.roundPrecision(i.pressure / 100, 0) : u.roundPrecision(i.pressure, 0),
170
+ wind: { kts: i.kts, spd: i.speed || i.spd },
171
+ category: a,
173
172
  type: "forecast"
174
173
  });
175
- t.features.push(f), r.push(f.geometry.coordinates);
174
+ t.features.push(p), n.push(p.geometry.coordinates);
176
175
  }
177
- if ((r == null ? void 0 : r.length) > 1) {
178
- const s = N.lineString(u.convertToMonotonicLng2(r), {
179
- date: i.date,
180
- id: o.id || o.name,
181
- model: i.model,
182
- name: o.name,
183
- category: p,
176
+ for (const m in o == null ? void 0 : o.hours) {
177
+ const p = o.hours[m];
178
+ p.wind.spd = p.wind.spd || p.wind.speed;
179
+ const h = c.clone().add(Number(m), "hour"), l = N.point([p.lng, p.lat], {
180
+ name: s.name,
181
+ date: h.format(),
182
+ hour: Number(m),
183
+ format: h.format("MMM-DD/HHmm[Z]"),
184
+ pressure: p.pressure > 1e4 ? u.roundPrecision(p.pressure / 100, 0) : u.roundPrecision(p.pressure, 0),
185
+ gusts: p.gusts,
186
+ wind: p.wind || {},
187
+ movement: p.movement,
188
+ category: a,
184
189
  type: "forecast"
185
190
  });
186
- t.features.push(s);
191
+ t.features.push(l), n.push(l.geometry.coordinates);
192
+ }
193
+ if ((n == null ? void 0 : n.length) > 1) {
194
+ const m = N.lineString(u.convertToMonotonicLng2(n), {
195
+ date: o.date,
196
+ id: s.id || s.name,
197
+ model: o.model,
198
+ name: s.name,
199
+ category: a,
200
+ type: "forecast"
201
+ });
202
+ t.features.push(m);
187
203
  }
188
204
  }
189
- if (o.history) {
205
+ }
206
+ if (s.history) {
190
207
  const i = [];
191
- for (const n of o.history) {
192
- const p = M(n.updated).utc(), s = N.point([n.lng, n.lat], {
193
- date: p.format(),
194
- format: p.format("MMM-DD/HHmm[Z]"),
208
+ for (const n of s.history) {
209
+ const c = y(n.updated).utc(), a = N.point([n.lng, n.lat], {
210
+ name: s.name,
211
+ date: c.format(),
212
+ format: c.format("MMM-DD/HHmm[Z]"),
195
213
  pressure: n.pressure > 1e4 ? u.roundPrecision(n.pressure / 100, 0) : u.roundPrecision(n.pressure, 0),
196
214
  spd: n.speed || n.spd,
197
215
  kts: n.kts,
198
216
  source: n.source,
199
217
  level: n.type,
200
218
  type: "history",
201
- category: `${o.name}-history`
219
+ category: `${s.name}-history`
202
220
  });
203
- t.features.push(s), i.push(s.geometry.coordinates);
221
+ t.features.push(a), i.push(a.geometry.coordinates);
204
222
  }
205
- const r = o.history[0];
223
+ const o = s.history[0];
206
224
  if (i.length === 1 && i.push(i[0]), i.length > 1) {
207
225
  const n = N.lineString(u.convertToMonotonicLng2(i), {
208
- name: o.name,
226
+ name: s.name,
209
227
  type: "history",
210
- updated: r == null ? void 0 : r.updated,
211
- pressure: (r == null ? void 0 : r.pressure) > 1e4 ? u.roundPrecision((r == null ? void 0 : r.pressure) / 100, 0) : u.roundPrecision(r == null ? void 0 : r.pressure, 0),
212
- spd: (r == null ? void 0 : r.speed) || (r == null ? void 0 : r.spd),
213
- kts: r == null ? void 0 : r.kts,
214
- source: r == null ? void 0 : r.source,
215
- level: r == null ? void 0 : r.type
228
+ updated: o == null ? void 0 : o.updated,
229
+ pressure: (o == null ? void 0 : o.pressure) > 1e4 ? u.roundPrecision((o == null ? void 0 : o.pressure) / 100, 0) : u.roundPrecision(o == null ? void 0 : o.pressure, 0),
230
+ spd: (o == null ? void 0 : o.speed) || (o == null ? void 0 : o.spd),
231
+ kts: o == null ? void 0 : o.kts,
232
+ source: o == null ? void 0 : o.source,
233
+ level: o == null ? void 0 : o.type
216
234
  });
217
235
  t.features.push(n);
218
236
  }
@@ -221,54 +239,55 @@ class D {
221
239
  return t;
222
240
  }
223
241
  static interpolate(e, t = 3) {
224
- var r, n, p, s;
225
- const o = (r = e == null ? void 0 : e.data) == null ? void 0 : r.features.filter((d) => d.geometry.type === "LineString" && d.properties.type === "forecast"), i = [];
226
- for (const d of o) {
227
- const a = d.properties.name, f = d.properties.model, h = M(d.properties.date).utc();
228
- let y = t * 60 - (h.get("hour") * 60 + h.get("minute")) % (t * 60);
229
- const b = (n = e == null ? void 0 : e.data) == null ? void 0 : n.features.filter(
230
- (m) => m.geometry.type === "Point" && m.properties.type === "forecast" && m.properties.category === `${a}-${f}`
242
+ var i, o, n, c;
243
+ const r = (i = e == null ? void 0 : e.data) == null ? void 0 : i.features.filter((a) => a.geometry.type === "LineString" && a.properties.type === "forecast"), s = [];
244
+ for (const a of r) {
245
+ const m = a.properties.name, p = a.properties.model, h = y(a.properties.date).utc();
246
+ let l = t * 60 - (h.get("hour") * 60 + h.get("minute")) % (t * 60);
247
+ const b = (o = e == null ? void 0 : e.data) == null ? void 0 : o.features.filter(
248
+ (f) => f.geometry.type === "Point" && f.properties.type === "forecast" && f.properties.category === `${m}-${p}`
231
249
  );
232
- let g, S = h.clone().add(y, "minute").set({ minute: 0, second: 0, millisecond: 0 });
233
- for (; g = this.pickIndex(b, S), g <= b.length - 1; ) {
234
- if (g > 0) {
235
- const m = b[g], c = g === 0 ? void 0 : b[g - 1], l = (y / 60 - ((p = c == null ? void 0 : c.properties) == null ? void 0 : p.hour)) / (m.properties.hour - ((s = c == null ? void 0 : c.properties) == null ? void 0 : s.hour)), $ = this.computeNumber(c == null ? void 0 : c.geometry.coordinates[0], m.geometry.coordinates[0], l), P = this.computeNumber(c == null ? void 0 : c.geometry.coordinates[1], m.geometry.coordinates[1], l), w = N.point([$, P], {
236
- model: f,
237
- category: m == null ? void 0 : m.properties.category,
250
+ let M, S = h.clone().add(l, "minute").set({ minute: 0, second: 0, millisecond: 0 });
251
+ for (; M = this.pickIndex(b, S), M <= b.length - 1; ) {
252
+ if (M > 0) {
253
+ const f = b[M], d = M === 0 ? void 0 : b[M - 1], g = (l / 60 - ((n = d == null ? void 0 : d.properties) == null ? void 0 : n.hour)) / (f.properties.hour - ((c = d == null ? void 0 : d.properties) == null ? void 0 : c.hour)), $ = this.computeNumber(d == null ? void 0 : d.geometry.coordinates[0], f.geometry.coordinates[0], g), P = this.computeNumber(d == null ? void 0 : d.geometry.coordinates[1], f.geometry.coordinates[1], g), w = N.point([$, P], {
254
+ name: m,
255
+ model: p,
256
+ category: f == null ? void 0 : f.properties.category,
238
257
  date: S.format(),
239
258
  format: S.format("MMM-DD/HHmm[Z]"),
240
- gusts: this.computeNumber(c == null ? void 0 : c.properties.gusts, m.properties.gusts, l),
241
- hour: this.computeNumber(c == null ? void 0 : c.properties.hour, m.properties.hour, l),
242
- movement: this.computeNumber(c == null ? void 0 : c.properties.movement, m.properties.movement, l),
243
- pressure: this.computeNumber(c == null ? void 0 : c.properties.pressure, m.properties.pressure, l),
244
- wind: this.computeNumber(c == null ? void 0 : c.properties.wind, m.properties.wind, l)
259
+ gusts: this.computeNumber(d == null ? void 0 : d.properties.gusts, f.properties.gusts, g),
260
+ hour: this.computeNumber(d == null ? void 0 : d.properties.hour, f.properties.hour, g),
261
+ movement: this.computeNumber(d == null ? void 0 : d.properties.movement, f.properties.movement, g),
262
+ pressure: this.computeNumber(d == null ? void 0 : d.properties.pressure, f.properties.pressure, g),
263
+ wind: this.computeNumber(d == null ? void 0 : d.properties.wind, f.properties.wind, g)
245
264
  });
246
- i.push(w);
265
+ s.push(w);
247
266
  }
248
- y += t * 60, S = h.clone().add(y, "minute").set({ minute: 0, second: 0, millisecond: 0 });
267
+ l += t * 60, S = h.clone().add(l, "minute").set({ minute: 0, second: 0, millisecond: 0 });
249
268
  }
250
269
  }
251
- return i;
270
+ return s;
252
271
  }
253
272
  static pickIndex(e, t) {
254
- let o = 0;
255
- for (const i of e) {
256
- if (M(i.properties.date).isAfter(t))
257
- return o === 0 ? -1 : o;
258
- o++;
273
+ let r = 0;
274
+ for (const s of e) {
275
+ if (y(s.properties.date).isAfter(t))
276
+ return r === 0 ? -1 : r;
277
+ r++;
259
278
  }
260
- return o;
279
+ return r;
261
280
  }
262
- static computeNumber(e, t, o) {
281
+ static computeNumber(e, t, r) {
263
282
  if (e)
264
283
  if (t) {
265
284
  if (isNaN(e) && isNaN(t) && typeof e != "string" && typeof t != "string") {
266
- const i = {};
267
- for (const r in e)
268
- i[r] = this.computeNumber(e[r], t[r], o);
269
- return i;
285
+ const s = {};
286
+ for (const i in e)
287
+ s[i] = this.computeNumber(e[i], t[i], r);
288
+ return s;
270
289
  }
271
- return Math.round((e + (t - e) * o) * 100) / 100;
290
+ return Math.round((e + (t - e) * r) * 100) / 100;
272
291
  } else
273
292
  return e;
274
293
  else
@@ -277,5 +296,5 @@ class D {
277
296
  }
278
297
  export {
279
298
  u as LngLatHelper,
280
- D as TropicalHelper
299
+ x as TropicalHelper
281
300
  };
@@ -1 +1 @@
1
- (function(h,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("moment"),require("moment-timezone"),require("tz-lookup"),require("@turf/turf")):typeof define=="function"&&define.amd?define(["exports","moment","moment-timezone","tz-lookup","@turf/turf"],l):(h=typeof globalThis<"u"?globalThis:h||self,l(h["idm-plugin-rabbitmq"]={},h.moment,h["moment-timezone"],h["tz-lookup"],h["@turf/turf"]))})(this,function(h,l,j,T,O){"use strict";function w(b){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(b){for(const t in b)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(b,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>b[t]})}}return e.default=b,Object.freeze(e)}const N=w(O);class u{static guessTimeZoneOffset(e,t){const o=T(t,e),i=l().tz(o).utcOffset();return this.roundPrecision(i/60,1)}static prettyTimeZoneOffset(e){let t=Math.floor(Math.abs(e)),o=Math.round((Math.abs(e)-t)*60);return o=o>9?o:`0${o}`,t=t>9?t:`0${t}`,e>0?`+${t}:${o}`:`-${t}:${o}`}static lng2pretty(e,t=6,o="H°M′"){e=u.convertToStdLng(e,t);let i="E";e<0&&(i="W"),e=Math.abs(e),o=o.toUpperCase();let r=e*3600,n,p,s,d,f,a;n=r%3600%60,o.indexOf("S")!==-1&&(r=r-n,p=u.padNumber(n,2,2)),s=r/60%60,o.indexOf("M")!==-1&&(o.indexOf("S")!==-1?d=u.roundPrecision(s,t).toString().padStart(2,"0"):d=u.padNumber(s,2,2),r=r-s*60),f=r/3600,o.indexOf("M")!==-1?a=u.roundPrecision(f,t).toString().padStart(3,"0"):a=u.padNumber(f,3,2);const g=`${o.replace(/S+/gi,p).replace(/M+/gi,d).replace(/H+/gi,a)}${i}`;return{direction:i,degree:u.roundPrecision(f,t),minute:u.roundPrecision(s,t),second:u.roundPrecision(n,t),pretty:g}}static lat2pretty(e,t=6,o="H°M′"){e=e%180;let i="N";e<0&&(i="S"),e=Math.abs(e),o=o.toUpperCase();let r=e*3600,n,p,s,d,f,a;n=r%3600%60,o.indexOf("S")!==-1&&(r=r-n,p=u.padNumber(n,2,2)),s=r/60%60,o.indexOf("M")!==-1&&(o.indexOf("S")!==-1?d=u.roundPrecision(s,t).toString().padStart(2,"0"):d=u.padNumber(s,2,2),r=r-s*60),f=r/3600,o.indexOf("M")!==-1?a=u.roundPrecision(f,t).toString().padStart(2,"0"):a=u.padNumber(f,2,2);const g=`${o.replace(/S+/gi,p).replace(/M+/gi,d).replace(/H+/gi,a)}${i}`;return{direction:i,degree:u.roundPrecision(f,t),minute:u.roundPrecision(s,t),second:u.roundPrecision(n,t),pretty:g}}static str2Lng(e,t=6){let o;if(isNaN(e)){e=u.strReplace(e,"LNG");const i=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const r=e.split(" ").filter(s=>s!=="").map(s=>Number(s));let[n,p]=r;if(n>360&&!p){const s=this.roundPrecision(n/100,0);p=n-s*100,n=s}o=n+(p??0)/60,i==="W"&&(o=o*-1)}else o=Number(e);return u.convertToStdLng(o,t)}static str2Lat(e,t=6){let o;if(isNaN(e)){e=u.strReplace(e,"LAT");const i=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const r=e.split(" ").filter(s=>s!=="").map(s=>Number(s));let[n,p]=r;if(n>90&&!p){const s=this.roundPrecision(n/100,0);p=n-s*100,n=s}o=n+(p??0)/60,i==="S"&&(o=o*-1)}else o=Number(e);return u.roundPrecision(o,t)}static str2LngOrLat(e,t=6,o="LAT"){e=u.strReplace(e,o);const i=e[e.length-1].toUpperCase();return["N","S"].includes(i)?{lat:u.str2Lat(e,t)}:{lng:u.str2Lng(e,t)}}static convertToStdLng(e,t=4){return e>180?(e=e%360,e=e>180?e-360:e):e<-180&&(e=e%360,e=e<-180?e+360:e),u.roundPrecision(e,t)}static roundPrecision(e,t=4){if(typeof e=="number"){const o=Number("1".padEnd(t+1,"0"));return Math.round(e*o)/o}return e}static convertToMonotonicLng2(e){for(let t=1;t<e.length;t++)e[t][0]+=Math.round((e[t-1][0]-e[t][0])/360)*360;return e}static convertToMonotonicLng(e){for(let t=1;t<e.length;t++)e[t].lng+=Math.round((e[t-1].lng-e[t].lng)/360)*360;return e}static strReplace(e,t="LAT"){e=e.replace(/([0-9]+)\.([0-9]+\.[0-9]+)/g,"$1 $2").replace(/-/g," ").replace(/°/," ").replace(/'/g," ").replace(/′/g," ").replace(/"/g," ").replace(/∼/g," ").replace(/°/g," ").replace(/,/g,".").replace(/^ /g,"").replace(/ $/g,"").trim();const o=e[e.length-1].toUpperCase();if(!["N","S","E","W"].includes(o)){const i=e,r=Number(i.split(" ")[0]);if(isNaN(r))throw new Error(`invalid Lat/Lng: ${e}`);r>=90?e=`${i}E`:r<=-90?e=`${i}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${i}${r>0?"E":"W"}`:e=`${i}${r>0?"N":"S"}`}return e}static padNumber(e,t=2,o=2){const i=Math.trunc(e).toString().padStart(t,"0"),r=Math.trunc(u.roundPrecision(e-Math.trunc(e),o)*Math.pow(10,o)).toString().padStart(o,"0");return`${i}.${r}`}}class k{static convert2Geojson(e){const t=N.featureCollection([]);for(const o of e){if(o.forecasts)for(const i of o.forecasts){const r=[],n=l(i.date).utc(),p=`${o.name}-${i.model}`;for(const s in i==null?void 0:i.hours){const d=i.hours[s];d.wind.spd=d.wind.spd||d.wind.speed;const f=n.clone().add(Number(s),"hour"),a=N.point([d.lng,d.lat],{date:f.format(),hour:Number(s),format:f.format("MMM-DD/HHmm[Z]"),pressure:d.pressure>1e4?u.roundPrecision(d.pressure/100,0):u.roundPrecision(d.pressure,0),gusts:d.gusts,wind:d.wind||{},movement:d.movement,category:p,type:"forecast"});t.features.push(a),r.push(a.geometry.coordinates)}if((r==null?void 0:r.length)>1){const s=N.lineString(u.convertToMonotonicLng2(r),{date:i.date,id:o.id||o.name,model:i.model,name:o.name,category:p,type:"forecast"});t.features.push(s)}}if(o.history){const i=[];for(const n of o.history){const p=l(n.updated).utc(),s=N.point([n.lng,n.lat],{date:p.format(),format:p.format("MMM-DD/HHmm[Z]"),pressure:n.pressure>1e4?u.roundPrecision(n.pressure/100,0):u.roundPrecision(n.pressure,0),spd:n.speed||n.spd,kts:n.kts,source:n.source,level:n.type,type:"history",category:`${o.name}-history`});t.features.push(s),i.push(s.geometry.coordinates)}const r=o.history[0];if(i.length===1&&i.push(i[0]),i.length>1){const n=N.lineString(u.convertToMonotonicLng2(i),{name:o.name,type:"history",updated:r==null?void 0:r.updated,pressure:(r==null?void 0:r.pressure)>1e4?u.roundPrecision((r==null?void 0:r.pressure)/100,0):u.roundPrecision(r==null?void 0:r.pressure,0),spd:(r==null?void 0:r.speed)||(r==null?void 0:r.spd),kts:r==null?void 0:r.kts,source:r==null?void 0:r.source,level:r==null?void 0:r.type});t.features.push(n)}}}return t}static interpolate(e,t=3){var r,n,p,s;const o=(r=e==null?void 0:e.data)==null?void 0:r.features.filter(d=>d.geometry.type==="LineString"&&d.properties.type==="forecast"),i=[];for(const d of o){const f=d.properties.name,a=d.properties.model,g=l(d.properties.date).utc();let S=t*60-(g.get("hour")*60+g.get("minute"))%(t*60);const $=(n=e==null?void 0:e.data)==null?void 0:n.features.filter(m=>m.geometry.type==="Point"&&m.properties.type==="forecast"&&m.properties.category===`${f}-${a}`);let M,P=g.clone().add(S,"minute").set({minute:0,second:0,millisecond:0});for(;M=this.pickIndex($,P),M<=$.length-1;){if(M>0){const m=$[M],c=M===0?void 0:$[M-1],y=(S/60-((p=c==null?void 0:c.properties)==null?void 0:p.hour))/(m.properties.hour-((s=c==null?void 0:c.properties)==null?void 0:s.hour)),z=this.computeNumber(c==null?void 0:c.geometry.coordinates[0],m.geometry.coordinates[0],y),D=this.computeNumber(c==null?void 0:c.geometry.coordinates[1],m.geometry.coordinates[1],y),C=N.point([z,D],{model:a,category:m==null?void 0:m.properties.category,date:P.format(),format:P.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(c==null?void 0:c.properties.gusts,m.properties.gusts,y),hour:this.computeNumber(c==null?void 0:c.properties.hour,m.properties.hour,y),movement:this.computeNumber(c==null?void 0:c.properties.movement,m.properties.movement,y),pressure:this.computeNumber(c==null?void 0:c.properties.pressure,m.properties.pressure,y),wind:this.computeNumber(c==null?void 0:c.properties.wind,m.properties.wind,y)});i.push(C)}S+=t*60,P=g.clone().add(S,"minute").set({minute:0,second:0,millisecond:0})}}return i}static pickIndex(e,t){let o=0;for(const i of e){if(l(i.properties.date).isAfter(t))return o===0?-1:o;o++}return o}static computeNumber(e,t,o){if(e)if(t){if(isNaN(e)&&isNaN(t)&&typeof e!="string"&&typeof t!="string"){const i={};for(const r in e)i[r]=this.computeNumber(e[r],t[r],o);return i}return Math.round((e+(t-e)*o)*100)/100}else return e;else return t}}h.LngLatHelper=u,h.TropicalHelper=k,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
1
+ (function(h,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("moment"),require("moment-timezone"),require("tz-lookup"),require("@turf/turf")):typeof define=="function"&&define.amd?define(["exports","moment","moment-timezone","tz-lookup","@turf/turf"],g):(h=typeof globalThis<"u"?globalThis:h||self,g(h["idm-plugin-rabbitmq"]={},h.moment,h["moment-timezone"],h["tz-lookup"],h["@turf/turf"]))})(this,function(h,g,j,T,O){"use strict";function w(b){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(b){for(const t in b)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(b,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>b[t]})}}return e.default=b,Object.freeze(e)}const y=w(O);class s{static guessTimeZoneOffset(e,t){const o=T(t,e),n=g().tz(o).utcOffset();return this.roundPrecision(n/60,1)}static prettyTimeZoneOffset(e){let t=Math.floor(Math.abs(e)),o=Math.round((Math.abs(e)-t)*60);return o=o>9?o:`0${o}`,t=t>9?t:`0${t}`,e>0?`+${t}:${o}`:`-${t}:${o}`}static lng2pretty(e,t=6,o="H°M′"){e=s.convertToStdLng(e,t);let n="E";e<0&&(n="W"),e=Math.abs(e),o=o.toUpperCase();let i=e*3600,r,u,c,a,m,p;r=i%3600%60,o.indexOf("S")!==-1&&(i=i-r,u=s.padNumber(r,2,2)),c=i/60%60,o.indexOf("M")!==-1&&(o.indexOf("S")!==-1?a=s.roundPrecision(c,t).toString().padStart(2,"0"):a=s.padNumber(c,2,2),i=i-c*60),m=i/3600,o.indexOf("M")!==-1?p=s.roundPrecision(m,t).toString().padStart(3,"0"):p=s.padNumber(m,3,2);const l=`${o.replace(/S+/gi,u).replace(/M+/gi,a).replace(/H+/gi,p)}${n}`;return{direction:n,degree:s.roundPrecision(m,t),minute:s.roundPrecision(c,t),second:s.roundPrecision(r,t),pretty:l}}static lat2pretty(e,t=6,o="H°M′"){e=e%180;let n="N";e<0&&(n="S"),e=Math.abs(e),o=o.toUpperCase();let i=e*3600,r,u,c,a,m,p;r=i%3600%60,o.indexOf("S")!==-1&&(i=i-r,u=s.padNumber(r,2,2)),c=i/60%60,o.indexOf("M")!==-1&&(o.indexOf("S")!==-1?a=s.roundPrecision(c,t).toString().padStart(2,"0"):a=s.padNumber(c,2,2),i=i-c*60),m=i/3600,o.indexOf("M")!==-1?p=s.roundPrecision(m,t).toString().padStart(2,"0"):p=s.padNumber(m,2,2);const l=`${o.replace(/S+/gi,u).replace(/M+/gi,a).replace(/H+/gi,p)}${n}`;return{direction:n,degree:s.roundPrecision(m,t),minute:s.roundPrecision(c,t),second:s.roundPrecision(r,t),pretty:l}}static str2Lng(e,t=6){let o;if(isNaN(e)){e=s.strReplace(e,"LNG");const n=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const i=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[r,u]=i;if(r>360&&!u){const c=this.roundPrecision(r/100,0);u=r-c*100,r=c}o=r+(u??0)/60,n==="W"&&(o=o*-1)}else o=Number(e);return s.convertToStdLng(o,t)}static str2Lat(e,t=6){let o;if(isNaN(e)){e=s.strReplace(e,"LAT");const n=e[e.length-1].toUpperCase();e=e.substring(0,e.length-1).trim();const i=e.split(" ").filter(c=>c!=="").map(c=>Number(c));let[r,u]=i;if(r>90&&!u){const c=this.roundPrecision(r/100,0);u=r-c*100,r=c}o=r+(u??0)/60,n==="S"&&(o=o*-1)}else o=Number(e);return s.roundPrecision(o,t)}static str2LngOrLat(e,t=6,o="LAT"){e=s.strReplace(e,o);const n=e[e.length-1].toUpperCase();return["N","S"].includes(n)?{lat:s.str2Lat(e,t)}:{lng:s.str2Lng(e,t)}}static convertToStdLng(e,t=4){return e>180?(e=e%360,e=e>180?e-360:e):e<-180&&(e=e%360,e=e<-180?e+360:e),s.roundPrecision(e,t)}static roundPrecision(e,t=4){if(typeof e=="number"){const o=Number("1".padEnd(t+1,"0"));return Math.round(e*o)/o}return e}static convertToMonotonicLng2(e){for(let t=1;t<e.length;t++)e[t][0]+=Math.round((e[t-1][0]-e[t][0])/360)*360;return e}static convertToMonotonicLng(e){for(let t=1;t<e.length;t++)e[t].lng+=Math.round((e[t-1].lng-e[t].lng)/360)*360;return e}static strReplace(e,t="LAT"){e=e.replace(/([0-9]+)\.([0-9]+\.[0-9]+)/g,"$1 $2").replace(/-/g," ").replace(/°/," ").replace(/'/g," ").replace(/′/g," ").replace(/"/g," ").replace(/∼/g," ").replace(/°/g," ").replace(/,/g,".").replace(/^ /g,"").replace(/ $/g,"").trim();const o=e[e.length-1].toUpperCase();if(!["N","S","E","W"].includes(o)){const n=e,i=Number(n.split(" ")[0]);if(isNaN(i))throw new Error(`invalid Lat/Lng: ${e}`);i>=90?e=`${n}E`:i<=-90?e=`${n}W`:["LAN","LNG"].includes(t==null?void 0:t.toUpperCase())?e=`${n}${i>0?"E":"W"}`:e=`${n}${i>0?"N":"S"}`}return e}static padNumber(e,t=2,o=2){const n=Math.trunc(e).toString().padStart(t,"0"),i=Math.trunc(s.roundPrecision(e-Math.trunc(e),o)*Math.pow(10,o)).toString().padStart(o,"0");return`${n}.${i}`}}class k{static convert2Geojson(e){var o;const t=y.featureCollection([]);for(const n of e){if(n.forecasts){const i=(o=n.history)==null?void 0:o[0];for(const r of n.forecasts){const u=[],c=g(r.date).utc(),a=`${n.name}-${r.model}`;if(i){const m=g(i.updated).utc(),p=y.point([i.lng,i.lat],{name:n.name,date:m.format(),hour:0,format:m.format("MMM-DD/HHmm[Z]"),pressure:i.pressure>1e4?s.roundPrecision(i.pressure/100,0):s.roundPrecision(i.pressure,0),wind:{kts:i.kts,spd:i.speed||i.spd},category:a,type:"forecast"});t.features.push(p),u.push(p.geometry.coordinates)}for(const m in r==null?void 0:r.hours){const p=r.hours[m];p.wind.spd=p.wind.spd||p.wind.speed;const l=c.clone().add(Number(m),"hour"),M=y.point([p.lng,p.lat],{name:n.name,date:l.format(),hour:Number(m),format:l.format("MMM-DD/HHmm[Z]"),pressure:p.pressure>1e4?s.roundPrecision(p.pressure/100,0):s.roundPrecision(p.pressure,0),gusts:p.gusts,wind:p.wind||{},movement:p.movement,category:a,type:"forecast"});t.features.push(M),u.push(M.geometry.coordinates)}if((u==null?void 0:u.length)>1){const m=y.lineString(s.convertToMonotonicLng2(u),{date:r.date,id:n.id||n.name,model:r.model,name:n.name,category:a,type:"forecast"});t.features.push(m)}}}if(n.history){const i=[];for(const u of n.history){const c=g(u.updated).utc(),a=y.point([u.lng,u.lat],{name:n.name,date:c.format(),format:c.format("MMM-DD/HHmm[Z]"),pressure:u.pressure>1e4?s.roundPrecision(u.pressure/100,0):s.roundPrecision(u.pressure,0),spd:u.speed||u.spd,kts:u.kts,source:u.source,level:u.type,type:"history",category:`${n.name}-history`});t.features.push(a),i.push(a.geometry.coordinates)}const r=n.history[0];if(i.length===1&&i.push(i[0]),i.length>1){const u=y.lineString(s.convertToMonotonicLng2(i),{name:n.name,type:"history",updated:r==null?void 0:r.updated,pressure:(r==null?void 0:r.pressure)>1e4?s.roundPrecision((r==null?void 0:r.pressure)/100,0):s.roundPrecision(r==null?void 0:r.pressure,0),spd:(r==null?void 0:r.speed)||(r==null?void 0:r.spd),kts:r==null?void 0:r.kts,source:r==null?void 0:r.source,level:r==null?void 0:r.type});t.features.push(u)}}}return t}static interpolate(e,t=3){var i,r,u,c;const o=(i=e==null?void 0:e.data)==null?void 0:i.features.filter(a=>a.geometry.type==="LineString"&&a.properties.type==="forecast"),n=[];for(const a of o){const m=a.properties.name,p=a.properties.model,l=g(a.properties.date).utc();let M=t*60-(l.get("hour")*60+l.get("minute"))%(t*60);const P=(r=e==null?void 0:e.data)==null?void 0:r.features.filter(f=>f.geometry.type==="Point"&&f.properties.type==="forecast"&&f.properties.category===`${m}-${p}`);let S,$=l.clone().add(M,"minute").set({minute:0,second:0,millisecond:0});for(;S=this.pickIndex(P,$),S<=P.length-1;){if(S>0){const f=P[S],d=S===0?void 0:P[S-1],N=(M/60-((u=d==null?void 0:d.properties)==null?void 0:u.hour))/(f.properties.hour-((c=d==null?void 0:d.properties)==null?void 0:c.hour)),D=this.computeNumber(d==null?void 0:d.geometry.coordinates[0],f.geometry.coordinates[0],N),z=this.computeNumber(d==null?void 0:d.geometry.coordinates[1],f.geometry.coordinates[1],N),C=y.point([D,z],{name:m,model:p,category:f==null?void 0:f.properties.category,date:$.format(),format:$.format("MMM-DD/HHmm[Z]"),gusts:this.computeNumber(d==null?void 0:d.properties.gusts,f.properties.gusts,N),hour:this.computeNumber(d==null?void 0:d.properties.hour,f.properties.hour,N),movement:this.computeNumber(d==null?void 0:d.properties.movement,f.properties.movement,N),pressure:this.computeNumber(d==null?void 0:d.properties.pressure,f.properties.pressure,N),wind:this.computeNumber(d==null?void 0:d.properties.wind,f.properties.wind,N)});n.push(C)}M+=t*60,$=l.clone().add(M,"minute").set({minute:0,second:0,millisecond:0})}}return n}static pickIndex(e,t){let o=0;for(const n of e){if(g(n.properties.date).isAfter(t))return o===0?-1:o;o++}return o}static computeNumber(e,t,o){if(e)if(t){if(isNaN(e)&&isNaN(t)&&typeof e!="string"&&typeof t!="string"){const n={};for(const i in e)n[i]=this.computeNumber(e[i],t[i],o);return n}return Math.round((e+(t-e)*o)*100)/100}else return e;else return t}}h.LngLatHelper=s,h.TropicalHelper=k,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
@@ -7,6 +7,7 @@ export declare class TropicalHelper {
7
7
  history: any[];
8
8
  }[]): turf.helpers.FeatureCollection<turf.helpers.Geometry, turf.helpers.Properties>;
9
9
  static interpolate(tropicals: any, step?: number): turf.helpers.Feature<turf.helpers.Point, {
10
+ name: any;
10
11
  model: any;
11
12
  category: any;
12
13
  date: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/geo",
3
3
  "private": false,
4
- "version": "1.0.2",
4
+ "version": "1.0.3",
5
5
  "description": "idm plugin for geo",
6
6
  "type": "module",
7
7
  "keywords": [