aewx-metar-parser 3.0.1 → 4.0.0

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.
@@ -1,161 +1,6 @@
1
- import { convert } from "./convert.js";
2
-
3
- export interface MetarCode {
4
- code: string;
5
- }
6
-
7
- export interface MetarWind {
8
- degrees: number | null;
9
- speed_kts: number;
10
- speed_mps: number;
11
- gust_kts: number | null;
12
- gust_mps: number | null;
13
- degrees_from: number | null;
14
- degrees_to: number | null;
15
- }
16
-
17
- export interface MetarVisibility {
18
- miles: number;
19
- miles_text: string;
20
- meters: number;
21
- meters_text: string;
22
- }
23
-
24
- export type MetarCloudCode = "FEW" | "SCT" | "BKN" | "OVC";
25
-
26
- export interface MetarCloud {
27
- code: MetarCloudCode;
28
- feet: number;
29
- meters: number;
30
- }
31
-
32
- export interface MetarCeiling {
33
- feet: number | null;
34
- meters: number | null;
35
- }
36
-
37
- export interface MetarTemperature {
38
- celsius: number | null;
39
- fahrenheit: number | null;
40
- }
41
-
42
- export interface MetarHumidity {
43
- percent: number | null;
44
- }
45
-
46
- export interface MetarPressure {
47
- hg: number | null;
48
- kpa: number | null;
49
- mb: number | null;
50
- }
51
-
52
- export type MetarIcaoFlightCategory = "VFR" | "IFR";
53
-
54
- export type MetarFlightCategory = MetarIcaoFlightCategory | "MVFR" | "LIFR";
55
-
56
- export interface Metar {
57
- raw_text: string;
58
- raw_parts: string[];
59
- icao: string;
60
- observed: Date;
61
- forecastFrom: Date | null;
62
- forecastTo: Date | null;
63
-
64
- wind: MetarWind;
65
- visibility: MetarVisibility;
66
- conditions: MetarCode[];
67
- clouds: MetarCloud[];
68
- ceiling: MetarCeiling;
69
- temperature: MetarTemperature;
70
- dewpoint: MetarTemperature;
71
- humidity: MetarHumidity;
72
- barometer: MetarPressure;
73
- flight_category: MetarFlightCategory | null;
74
- icao_flight_category: MetarIcaoFlightCategory | null;
75
- }
76
-
77
- class MetarParserHelpers {
78
- /**
79
- * @param {Number} value dito
80
- * @param {Number} toNext round to next full xxxx
81
- * @returns {Number} rounded value
82
- */
83
- static round(value: number, toNext: number = 500): number {
84
- return Math.round(value / toNext) * toNext;
85
- }
86
-
87
- static getVisibility(visibility_miles: number, visibility_meters: number): MetarVisibility {
88
- return {
89
- miles: visibility_miles,
90
- miles_text: String(MetarParserHelpers.round(visibility_miles, 0.5)),
91
- meters: visibility_meters,
92
- meters_text: String(MetarParserHelpers.round(visibility_meters, 500)),
93
- };
94
- }
95
-
96
- static getCloud(code: MetarCloudCode, hundredFeet: string): MetarCloud {
97
- const feet = Number(hundredFeet) * 100;
98
- return {
99
- code: code,
100
- feet: feet,
101
- meters: convert.feetToMeters(feet),
102
- };
103
- }
104
-
105
- static getTemperature(temperatureString: string): MetarTemperature {
106
- const temperature = Number(temperatureString.replace("M", "-"));
107
- return {
108
- celsius: temperature,
109
- fahrenheit: convert.celsiusToFahrenheit(temperature),
110
- };
111
- }
112
-
113
- /**
114
- * @see http://andrew.rsmas.miami.edu/bmcnoldy/Humidity.html
115
- */
116
- static getHumidity(temp: MetarTemperature, dew: MetarTemperature): number | null {
117
- if (dew.celsius === null || temp.celsius === null) {
118
- return null;
119
- }
120
- return (
121
- (Math.exp((17.625 * dew.celsius) / (243.04 + dew.celsius)) /
122
- Math.exp((17.625 * temp.celsius) / (243.04 + temp.celsius))) *
123
- 100
124
- );
125
- }
126
-
127
- static getFlightCategory(visibility: MetarVisibility, ceiling: MetarCeiling): MetarFlightCategory {
128
- if (visibility.miles > 5 && (!ceiling.feet || ceiling.feet > 3000)) {
129
- return "VFR";
130
- } else if (visibility.miles >= 3 && (!ceiling.feet || ceiling.feet >= 1000)) {
131
- return "MVFR";
132
- } else if (visibility.miles >= 1 && (!ceiling.feet || ceiling.feet >= 500)) {
133
- return "IFR";
134
- }
135
- return "LIFR";
136
- }
137
-
138
- static getIcaoFLightCategory(visibility: MetarVisibility, ceiling: MetarCeiling): MetarIcaoFlightCategory {
139
- return visibility.meters >= 5000 && (!ceiling.feet || ceiling.feet >= 1500) ? "VFR" : "IFR";
140
- }
141
-
142
- static getCeiling(clouds: MetarCloud[]): MetarCloud | undefined {
143
- return clouds.find((c) => {
144
- return c.code === "BKN" || c.code === "OVC";
145
- });
146
- }
147
-
148
- static metarSplit(metarString: string): string[] {
149
- return metarString
150
- .trim()
151
- .replace(/(\s)(\d)\s(\d)\/(\d)(SM)/, function (all, a, b, c, d, e) {
152
- // convert visbility range like `1 1/2 SM`
153
- return a + (Number(b) * Number(d) + Number(c)) + "/" + d + e;
154
- })
155
- .replace(/\n/, " \\n ")
156
- .split(/\s+/);
157
- }
158
- }
1
+ import * as convert from "./convert.js";
2
+ import * as MetarParserHelpers from "./metar-parser-helpers.js";
3
+ import type { MetarCloudCode, Metar } from "./metar-parser.type.js";
159
4
 
160
5
  /**
161
6
  * Convert METAR string into structured object.
@@ -166,53 +11,7 @@ class MetarParserHelpers {
166
11
  * reponse of the data property of https://www.checkwxapi.com/metar
167
12
  */
168
13
  export const metarParser = (metarString: string): Metar => {
169
- const metarObject: Metar = {
170
- raw_text: metarString,
171
- raw_parts: MetarParserHelpers.metarSplit(metarString),
172
- icao: "",
173
- observed: new Date(),
174
- forecastFrom: null,
175
- forecastTo: null,
176
- wind: {
177
- degrees: null,
178
- speed_kts: 0,
179
- speed_mps: 0,
180
- gust_kts: null,
181
- gust_mps: null,
182
- degrees_from: null,
183
- degrees_to: null,
184
- },
185
- visibility: {
186
- miles: 10,
187
- miles_text: "",
188
- meters: 9999,
189
- meters_text: "",
190
- },
191
- conditions: [],
192
- clouds: [],
193
- ceiling: {
194
- feet: null,
195
- meters: null,
196
- },
197
- temperature: {
198
- celsius: null,
199
- fahrenheit: null,
200
- },
201
- dewpoint: {
202
- celsius: null,
203
- fahrenheit: null,
204
- },
205
- humidity: {
206
- percent: null,
207
- },
208
- barometer: {
209
- hg: null,
210
- kpa: null,
211
- mb: null,
212
- },
213
- flight_category: null,
214
- icao_flight_category: null,
215
- };
14
+ const metarObject = initializeMetarObject(metarString);
216
15
 
217
16
  let mode = 0;
218
17
  let isTAF = false;
@@ -222,13 +21,13 @@ export const metarParser = (metarString: string): Metar => {
222
21
  isTAF = metarPart === "TAF";
223
22
  return;
224
23
  }
225
- if (!isTAF && mode > 1 && mode < 3 && metarPart.match(/^(\d+)(?:\/(\d+))?(SM)?$/)) {
24
+ if (!isTAF && mode > 1 && mode < 3 && metarPart.match(/^(\d+|\/{2,4})(?:\/(\d+))?(SM)?$/)) {
226
25
  mode = 3; // no wind reported
227
26
  }
228
- if (mode > 2 && mode < 5 && metarPart.match(/^(FEW|SCT|BKN|OVC)(\d+)?/)) {
27
+ if (mode > 2 && mode < 5 && metarPart.match(/^(FEW|SCT|BKN|OVC|VV)(\d+)?/)) {
229
28
  mode = 5; // no visibility / conditions reported
230
29
  }
231
- if (mode > 3 && mode < 6 && metarPart.match(/(^M?\d+\/M?\d+$)|(^\/\/\/\/\/)/)) {
30
+ if (mode > 3 && mode < 6 && metarPart.match(/^(M?\d+|\/\/)\/(M?\d+|\/\/)?$/)) {
232
31
  mode = 6; // end of clouds
233
32
  }
234
33
  if (metarPart.match(/^(TEMPO|FM\d+|\\n)$/)) {
@@ -237,7 +36,6 @@ export const metarParser = (metarString: string): Metar => {
237
36
 
238
37
  switch (mode) {
239
38
  case 0:
240
- // ICAO Code
241
39
  metarObject.icao = metarPart;
242
40
  mode = 1;
243
41
  break;
@@ -253,71 +51,15 @@ export const metarParser = (metarString: string): Metar => {
253
51
  }
254
52
  break;
255
53
  case 2:
256
- // Wind
257
- match = metarPart.match(/^(\d\d\d|VRB)P?(\d+)(?:G(\d+))?(KT|MPS|KPH)/);
258
- if (match) {
259
- let speed_kts = Number(match[2]);
260
- let gust_kts = match[3] ? Number(match[3]) : null;
261
- if (match[4] === "KPH") {
262
- speed_kts = convert.kphToMps(speed_kts);
263
- gust_kts = gust_kts ? convert.kphToMps(gust_kts) : null;
264
- match[4] = "MPS";
265
- }
266
- const degrees = match[1] === "VRB" ? null : Number(match[1]);
267
-
268
- metarObject.wind = {
269
- degrees: degrees,
270
- speed_kts: match[4] === "MPS" ? convert.mpsToKts(speed_kts) : speed_kts,
271
- speed_mps: match[4] === "MPS" ? speed_kts : convert.ktsToMps(speed_kts),
272
- gust_kts: gust_kts ? (match[4] === "MPS" ? convert.mpsToKts(gust_kts) : gust_kts) : null,
273
- gust_mps: gust_kts ? (match[4] === "MPS" ? gust_kts : convert.ktsToMps(gust_kts)) : null,
274
- degrees_from: null,
275
- degrees_to: null,
276
- };
277
- if (match[1] === "VRB") {
278
- metarObject.wind.degrees_from = 0;
279
- metarObject.wind.degrees_to = 359;
280
- }
281
- mode = 3;
282
- break;
283
- }
284
-
285
- // Forecast Date
286
- match = metarPart.match(/^(\d\d)(\d\d)\/(\d\d)(\d\d)$/);
287
- if (match) {
288
- metarObject.forecastFrom = new Date();
289
- metarObject.forecastFrom.setUTCDate(Number(match[1]));
290
- metarObject.forecastFrom.setUTCHours(Number(match[2]));
291
- metarObject.forecastFrom.setUTCMinutes(0);
292
-
293
- metarObject.forecastTo = new Date();
294
- metarObject.forecastTo.setUTCDate(Number(match[3]));
295
- metarObject.forecastTo.setUTCHours(Number(match[4]));
296
- metarObject.forecastTo.setUTCMinutes(0);
297
- break;
54
+ mode = parseWind(metarPart, metarObject, mode);
55
+ if (mode === 2) {
56
+ parseForecastDate(metarPart, metarObject);
298
57
  }
299
58
  break;
300
59
  case 3:
301
- // Visibility
302
- match = metarPart.match(/^P?(\d+)(?:\/(\d+))?(SM)?$/);
303
- if (match) {
304
- const visibility = match[2] ? Number(match[1]) / Number(match[2]) : Number(match[1]);
305
- metarObject.visibility = MetarParserHelpers.getVisibility(
306
- match[3] && match[3] === "SM" ? visibility : convert.metersToMiles(visibility),
307
- match[3] && match[3] === "SM" ? convert.milesToMeters(visibility) : visibility,
308
- );
309
-
310
- mode = 4;
311
- } else if (metarPart === "CAVOK" || metarPart === "CLR") {
312
- metarObject.visibility = MetarParserHelpers.getVisibility(10, convert.milesToMeters(10));
313
- mode = 5; // no clouds & conditions reported
314
- } else if (metarObject.wind) {
315
- // Variable wind direction
316
- match = metarPart.match(/^(\d+)V(\d+)$/);
317
- if (match) {
318
- metarObject.wind.degrees_from = Number(match[1]);
319
- metarObject.wind.degrees_to = Number(match[2]);
320
- }
60
+ mode = parseVisibility(metarPart, metarObject, mode);
61
+ if (mode === 3) {
62
+ parseVariableWind(metarPart, metarObject);
321
63
  }
322
64
  break;
323
65
  case 4:
@@ -338,52 +80,190 @@ export const metarParser = (metarString: string): Metar => {
338
80
  }
339
81
  break;
340
82
  case 5:
341
- // Clouds
342
- match = metarPart.match(/^(FEW|SCT|BKN|OVC)(\d+)/);
343
- if (match) {
344
- metarObject.clouds.push(MetarParserHelpers.getCloud(match[1] as MetarCloudCode, match[2]));
345
- }
83
+ parseClouds(metarPart, metarObject);
346
84
  // may occur multiple times
347
85
  break;
348
86
  case 6:
349
- // Temperature
350
- match = metarPart.match(/^(M?\d+)\/(M?\d+)$/);
351
- if (match === null && metarPart.match(/^\/\/\/\/\/$/)) {
352
- mode = 7;
353
- break;
354
- }
355
- if (match) {
356
- metarObject.temperature = MetarParserHelpers.getTemperature(match[1]);
357
- metarObject.dewpoint = MetarParserHelpers.getTemperature(match[2]);
358
- metarObject.humidity.percent = MetarParserHelpers.getHumidity(metarObject.temperature, metarObject.dewpoint);
359
- mode = 7;
360
- }
87
+ mode = parseTemperature(metarPart, metarObject, mode);
361
88
  break;
362
89
  case 7:
363
- // Pressure
364
- match = metarPart.match(/^(Q|A)(\d+)/);
365
- if (match) {
366
- let hg = Number(match[2]);
367
- hg /= match[1] === "Q" ? 10 : 100;
368
- metarObject.barometer = {
369
- hg: match[1] === "Q" ? convert.kpaToInhg(hg) : hg,
370
- kpa: match[1] === "Q" ? hg : convert.inhgToKpa(hg),
371
- mb: match[1] === "Q" ? hg * 10 : convert.inhgToKpa(hg * 10),
372
- };
373
- mode = 8;
374
- }
90
+ mode = parsePressure(metarPart, metarObject, mode);
375
91
  break;
376
92
  }
377
93
  });
378
94
 
379
- const ceilingCloud: MetarCloud | undefined = MetarParserHelpers.getCeiling(metarObject.clouds);
380
- metarObject.ceiling.feet = ceilingCloud?.feet ?? null;
381
- metarObject.ceiling.meters = ceilingCloud?.meters ?? null;
382
- metarObject.flight_category = MetarParserHelpers.getFlightCategory(metarObject.visibility, metarObject.ceiling);
383
- metarObject.icao_flight_category = MetarParserHelpers.getIcaoFLightCategory(
384
- metarObject.visibility,
385
- metarObject.ceiling,
386
- );
95
+ metarObject.ceiling = MetarParserHelpers.metarCeiling(metarObject.clouds);
96
+ metarObject.flight_category = MetarParserHelpers.flightCategoryUs(metarObject.visibility, metarObject.ceiling);
97
+ metarObject.icao_flight_category = MetarParserHelpers.flightCategoryIcao(metarObject.visibility, metarObject.ceiling);
387
98
 
388
99
  return metarObject;
389
100
  };
101
+
102
+ // -----------------------------------------------------------------------------
103
+
104
+ function parseWind(metarPart: string, metarObject: Metar, mode: number): number {
105
+ // Case: Unkonw wind
106
+ if (metarPart.match(/^\/+(KT|MPS|KPH)$/)) {
107
+ return 3;
108
+ }
109
+
110
+ const match = metarPart.match(/^(\d\d\d|VRB)P?(\d+)(?:G(\d+))?(KT|MPS|KPH)/);
111
+ if (!match) {
112
+ return mode;
113
+ }
114
+
115
+ let speed_kts = Number(match[2]);
116
+ let gust_kts = match[3] ? Number(match[3]) : null;
117
+ if (match[4] === "KPH") {
118
+ speed_kts = convert.kphToMps(speed_kts);
119
+ gust_kts = gust_kts ? convert.kphToMps(gust_kts) : null;
120
+ match[4] = "MPS";
121
+ }
122
+ const degrees = match[1] === "VRB" ? null : Number(match[1]);
123
+
124
+ metarObject.wind = {
125
+ degrees: degrees,
126
+ speed_kts: match[4] === "MPS" ? convert.mpsToKts(speed_kts) : speed_kts,
127
+ speed_mps: match[4] === "MPS" ? speed_kts : convert.ktsToMps(speed_kts),
128
+ gust_kts: gust_kts ? (match[4] === "MPS" ? convert.mpsToKts(gust_kts) : gust_kts) : null,
129
+ gust_mps: gust_kts ? (match[4] === "MPS" ? gust_kts : convert.ktsToMps(gust_kts)) : null,
130
+ degrees_from: null,
131
+ degrees_to: null,
132
+ };
133
+ if (match[1] === "VRB") {
134
+ metarObject.wind.degrees_from = 0;
135
+ metarObject.wind.degrees_to = 359;
136
+ }
137
+
138
+ return 3;
139
+ }
140
+
141
+ function parseForecastDate(metarPart: string, metarObject: Metar): void {
142
+ const match = metarPart.match(/^(\d\d)(\d\d)\/(\d\d)(\d\d)$/);
143
+ if (!match) {
144
+ return;
145
+ }
146
+ metarObject.forecastFrom = new Date();
147
+ metarObject.forecastFrom.setUTCDate(Number(match[1]));
148
+ metarObject.forecastFrom.setUTCHours(Number(match[2]));
149
+ metarObject.forecastFrom.setUTCMinutes(0);
150
+
151
+ metarObject.forecastTo = new Date();
152
+ metarObject.forecastTo.setUTCDate(Number(match[3]));
153
+ metarObject.forecastTo.setUTCHours(Number(match[4]));
154
+ metarObject.forecastTo.setUTCMinutes(0);
155
+ }
156
+
157
+ function parseVisibility(metarPart: string, metarObject: Metar, mode: number): number {
158
+ // Case: No clouds & conditions reported
159
+ if (metarPart === "CAVOK" || metarPart === "CLR") {
160
+ metarObject.visibility = MetarParserHelpers.metarVisibility(10, convert.milesToMeters(10));
161
+ return 5;
162
+ }
163
+
164
+ const [, digits, fraction, unit] = metarPart.match(/^[MP]?(\d+|\/{2,4})(?:\/(\d+))?(SM)?$/) || [];
165
+ if (digits === undefined) {
166
+ return mode;
167
+ }
168
+
169
+ // Case: Explicitly unknown visibility
170
+ if (digits.match(/^\/+/)) {
171
+ return 4;
172
+ }
173
+
174
+ // Case: Known visibility, possibly as fraction
175
+ const visibility = fraction ? Number(digits) / Number(fraction) : Number(digits);
176
+ metarObject.visibility = MetarParserHelpers.metarVisibility(
177
+ unit === "SM" ? visibility : convert.metersToMiles(visibility),
178
+ unit === "SM" ? convert.milesToMeters(visibility) : visibility,
179
+ );
180
+
181
+ return 4;
182
+ }
183
+
184
+ function parseVariableWind(metarPart: string, metarObject: Metar): void {
185
+ if (!metarObject.wind) {
186
+ return;
187
+ }
188
+
189
+ const match = metarPart.match(/^(\d+)V(\d+)$/);
190
+ if (match) {
191
+ metarObject.wind.degrees_from = Number(match[1]);
192
+ metarObject.wind.degrees_to = Number(match[2]);
193
+ }
194
+ }
195
+
196
+ function parseClouds(metarPart: string, metarObject: Metar) {
197
+ const [, cloudType, cloudAltitude] = metarPart.match(/^(FEW|SCT|BKN|OVC|VV)(\d+)/) || [];
198
+ if (cloudType && cloudAltitude) {
199
+ metarObject.clouds.push(MetarParserHelpers.metarCloud(cloudType as MetarCloudCode, cloudAltitude));
200
+ }
201
+ }
202
+
203
+ function parseTemperature(metarPart: string, metarObject: Metar, mode: number): number {
204
+ const [, temp, dewpoint] = metarPart.match(/^(M?\d+|\/\/)\/(M?\d+|\/\/)?$/) || [];
205
+
206
+ if (temp) {
207
+ metarObject.temperature = MetarParserHelpers.metarTemperature(temp ?? "//");
208
+ metarObject.dewpoint = MetarParserHelpers.metarTemperature(dewpoint ?? "//");
209
+ metarObject.humidity.percent = MetarParserHelpers.relativeHumidityPercent(
210
+ metarObject.temperature,
211
+ metarObject.dewpoint,
212
+ );
213
+ return 7;
214
+ }
215
+ return mode;
216
+ }
217
+
218
+ function parsePressure(metarPart: string, metarObject: Metar, mode: number): number {
219
+ const match = metarPart.match(/^(Q|A)(\d+)/);
220
+ if (!match) {
221
+ return mode;
222
+ }
223
+ let hg = Number(match[2]);
224
+ hg /= match[1] === "Q" ? 10 : 100;
225
+ metarObject.barometer = {
226
+ hg: match[1] === "Q" ? convert.kpaToInhg(hg) : hg,
227
+ kpa: match[1] === "Q" ? hg : convert.inhgToKpa(hg),
228
+ mb: match[1] === "Q" ? hg * 10 : convert.inhgToKpa(hg * 10),
229
+ };
230
+ return 8;
231
+ }
232
+
233
+ // -----------------------------------------------------------------------------
234
+
235
+ function initializeMetarObject(metarString: string): Metar {
236
+ return {
237
+ raw_text: metarString,
238
+ raw_parts: MetarParserHelpers.metarSplit(metarString),
239
+ icao: "",
240
+ observed: new Date(),
241
+ forecastFrom: null,
242
+ forecastTo: null,
243
+ wind: {
244
+ degrees: null,
245
+ speed_kts: null,
246
+ speed_mps: null,
247
+ gust_kts: null,
248
+ gust_mps: null,
249
+ degrees_from: null,
250
+ degrees_to: null,
251
+ },
252
+ visibility: null,
253
+ conditions: [],
254
+ clouds: [],
255
+ ceiling: null,
256
+ temperature: null,
257
+ dewpoint: null,
258
+ humidity: {
259
+ percent: null,
260
+ },
261
+ barometer: {
262
+ hg: null,
263
+ kpa: null,
264
+ mb: null,
265
+ },
266
+ flight_category: null,
267
+ icao_flight_category: null,
268
+ };
269
+ }
@@ -0,0 +1,85 @@
1
+ export interface MetarCode {
2
+ code: string;
3
+ }
4
+
5
+ export interface MetarWind {
6
+ degrees: number | null;
7
+ speed_kts: number | null;
8
+ speed_mps: number | null;
9
+ gust_kts: number | null;
10
+ gust_mps: number | null;
11
+ degrees_from: number | null;
12
+ degrees_to: number | null;
13
+ }
14
+
15
+ export interface MetarVisibility {
16
+ miles: number;
17
+ miles_text: string;
18
+ meters: number;
19
+ meters_text: string;
20
+ }
21
+
22
+ export type MetarCloudCode = "FEW" | "SCT" | "BKN" | "OVC" | "VV";
23
+
24
+ export interface MetarCloud {
25
+ code: MetarCloudCode;
26
+ feet: number;
27
+ meters: number;
28
+ }
29
+
30
+ /**
31
+ * Ceiling values of lowest cloud layer reporting `BKN` or `OVC`.
32
+ * Values will be `null` if no such layer was found.
33
+ */
34
+ export interface MetarCeiling {
35
+ /**
36
+ * Ceiling in feet of lowest cloud layer reporting `BKN` or `OVC`.
37
+ * Ceiling in feet will be `null` if no such layer was found.
38
+ */
39
+ feet: number;
40
+ /**
41
+ * Ceiling in meters of lowest cloud layer reporting `BKN` or `OVC`.
42
+ * Ceiling in meters will be `null` if no such layer was found.
43
+ */
44
+ meters: number;
45
+ }
46
+
47
+ export interface MetarTemperature {
48
+ celsius: number;
49
+ fahrenheit: number;
50
+ }
51
+
52
+ export interface MetarHumidity {
53
+ percent: number | null;
54
+ }
55
+
56
+ export interface MetarPressure {
57
+ hg: number | null;
58
+ kpa: number | null;
59
+ mb: number | null;
60
+ }
61
+
62
+ export type MetarIcaoFlightCategory = "VFR" | "IFR";
63
+
64
+ export type MetarFlightCategory = MetarIcaoFlightCategory | "MVFR" | "LIFR";
65
+
66
+ export interface Metar {
67
+ raw_text: string;
68
+ raw_parts: string[];
69
+ icao: string;
70
+ observed: Date;
71
+ forecastFrom: Date | null;
72
+ forecastTo: Date | null;
73
+
74
+ wind: MetarWind;
75
+ visibility: MetarVisibility | null;
76
+ conditions: MetarCode[];
77
+ clouds: MetarCloud[];
78
+ ceiling: MetarCeiling | null;
79
+ temperature: MetarTemperature | null;
80
+ dewpoint: MetarTemperature | null;
81
+ humidity: MetarHumidity;
82
+ barometer: MetarPressure;
83
+ flight_category: MetarFlightCategory | null;
84
+ icao_flight_category: MetarIcaoFlightCategory | null;
85
+ }
package/tsconfig.json CHANGED
@@ -15,7 +15,8 @@
15
15
  "declaration": true,
16
16
  "declarationDir": "./types",
17
17
  "types": ["node"],
18
- "verbatimModuleSyntax": true
18
+ "verbatimModuleSyntax": true,
19
+ "noUncheckedIndexedAccess": true
19
20
  },
20
21
  "include": ["./src/**/*"]
21
22
  }
@@ -1 +1 @@
1
- {"root":["./src/convert.test.ts","./src/convert.ts","./src/metar-parser.test.ts","./src/metar-parser.ts"],"version":"5.7.3"}
1
+ {"root":["./src/convert.test.ts","./src/convert.ts","./src/metar-parser-helpers.ts","./src/metar-parser.test.ts","./src/metar-parser.ts","./src/metar-parser.type.ts"],"version":"6.0.3"}
@@ -1,15 +1,10 @@
1
- /**
2
- * Convert units
3
- */
4
- export declare const convert: {
5
- celsiusToFahrenheit: (celsius: number) => number;
6
- feetToMeters: (feet: number) => number;
7
- milesToMeters: (miles: number) => number;
8
- metersToMiles: (meters: number) => number;
9
- inhgToKpa: (inHg: number) => number;
10
- kpaToInhg: (kpa: number) => number;
11
- kphToMps: (kph: number) => number;
12
- mpsToKts: (mps: number) => number;
13
- ktsToMps: (kts: number) => number;
14
- };
1
+ export declare function celsiusToFahrenheit(celsius: number): number;
2
+ export declare function feetToMeters(feet: number): number;
3
+ export declare function milesToMeters(miles: number): number;
4
+ export declare function metersToMiles(meters: number): number;
5
+ export declare function inhgToKpa(inHg: number): number;
6
+ export declare function kpaToInhg(kpa: number): number;
7
+ export declare function kphToMps(kph: number): number;
8
+ export declare function mpsToKts(mps: number): number;
9
+ export declare function ktsToMps(kts: number): number;
15
10
  //# sourceMappingURL=convert.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,OAAO;mCACsB,MAAM;yBAIhB,MAAM;2BAIJ,MAAM;4BAIL,MAAM;sBAIZ,MAAM;qBAIP,MAAM;oBAIP,MAAM;oBAIN,MAAM;oBAIN,MAAM;CAGhC,CAAC"}
1
+ {"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,UAElD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,UAExC;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,UAE1C;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,UAE3C;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,UAErC;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,UAEpC;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,UAEnC;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,UAEnC;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,UAEnC"}