metar-taf-parser 7.1.0 → 7.1.2

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.
Files changed (2) hide show
  1. package/metar-taf-parser.js +44 -13
  2. package/package.json +1 -1
@@ -2180,6 +2180,9 @@ class CommandSupplier {
2180
2180
  _CommandSupplier_commands = new WeakMap();
2181
2181
 
2182
2182
  var _AbstractParser_INTENSITY_REGEX, _AbstractParser_CAVOK, _AbstractParser_commonSupplier, _MetarParser_commandSupplier, _TAFParser_commandSupplier, _TAFParser_validityPattern, _RemarkParser_supplier;
2183
+ function isStation(stationString) {
2184
+ return stationString.length === 4;
2185
+ }
2183
2186
  /**
2184
2187
  * Parses the delivery time of a METAR/TAF
2185
2188
  * @param abstractWeatherCode The TAF or METAR object
@@ -2289,26 +2292,46 @@ class AbstractParser {
2289
2292
  let intensity;
2290
2293
  if (input.match(__classPrivateFieldGet(this, _AbstractParser_INTENSITY_REGEX, "f"))) {
2291
2294
  const match = input.match(__classPrivateFieldGet(this, _AbstractParser_INTENSITY_REGEX, "f"))?.[0];
2292
- if (match)
2295
+ if (match) {
2293
2296
  intensity = match;
2297
+ input = input.slice(match.length);
2298
+ }
2294
2299
  }
2295
2300
  let descriptive;
2296
- for (const key of Object.values(Descriptive)) {
2297
- if (input.includes(key))
2301
+ const descriptives = Object.values(Descriptive);
2302
+ for (let i = 0; i < descriptives.length; i++) {
2303
+ const key = descriptives[i];
2304
+ if (input.startsWith(key)) {
2298
2305
  descriptive = key;
2306
+ input = input.slice(key.length);
2307
+ break;
2308
+ }
2299
2309
  }
2300
2310
  const weatherCondition = {
2301
2311
  intensity,
2302
2312
  descriptive,
2303
2313
  phenomenons: [],
2304
2314
  };
2305
- for (const key of Object.values(Phenomenon)) {
2315
+ const phenomenons = Object.values(Phenomenon);
2316
+ for (let i = 0; i < phenomenons.length; i++) {
2317
+ const key = phenomenons[i];
2306
2318
  // Thunderstorm as descriptive should not be added as a phenomenon
2307
2319
  if (descriptive === key)
2308
2320
  continue;
2309
- if (input.includes(key))
2321
+ // Phenomenons can be separated with a slash
2322
+ const conditionRegex = new RegExp(`^\/?${key}`);
2323
+ const inputMatch = input.match(conditionRegex)?.[0];
2324
+ if (inputMatch) {
2310
2325
  weatherCondition.phenomenons.push(key);
2326
+ input = input.slice(inputMatch.length);
2327
+ // Restart the search for an additional phenomenon
2328
+ i = -1;
2329
+ continue;
2330
+ }
2311
2331
  }
2332
+ // If anything is left unparsed, it's not a valid weather condition
2333
+ if (input.replace(/\//g, "").length)
2334
+ return;
2312
2335
  return weatherCondition;
2313
2336
  }
2314
2337
  /**
@@ -2350,6 +2373,11 @@ class AbstractParser {
2350
2373
  };
2351
2374
  return true;
2352
2375
  }
2376
+ const weatherCondition = this.parseWeatherCondition(input);
2377
+ if (weatherCondition && isWeatherConditionValid(weatherCondition)) {
2378
+ abstractWeatherContainer.weatherConditions.push(weatherCondition);
2379
+ return true;
2380
+ }
2353
2381
  const command = __classPrivateFieldGet(this, _AbstractParser_commonSupplier, "f").get(input);
2354
2382
  if (command) {
2355
2383
  try {
@@ -2361,11 +2389,6 @@ class AbstractParser {
2361
2389
  throw error;
2362
2390
  }
2363
2391
  }
2364
- const weatherCondition = this.parseWeatherCondition(input);
2365
- if (isWeatherConditionValid(weatherCondition)) {
2366
- abstractWeatherContainer.weatherConditions.push(weatherCondition);
2367
- return true;
2368
- }
2369
2392
  return false;
2370
2393
  }
2371
2394
  }
@@ -2414,9 +2437,17 @@ class MetarParser extends AbstractParser {
2414
2437
  */
2415
2438
  parse(input) {
2416
2439
  const metarTab = this.tokenize(input);
2440
+ let index = 0;
2441
+ // Only parse flag if precedes station identifier
2442
+ if (isStation(metarTab[index + 1])) {
2443
+ var flags = findFlags(metarTab[index]);
2444
+ if (flags)
2445
+ index += 1;
2446
+ }
2417
2447
  const metar = {
2418
- ...parseDeliveryTime(metarTab[1]),
2419
- station: metarTab[0],
2448
+ ...parseDeliveryTime(metarTab[index + 1]),
2449
+ station: metarTab[index],
2450
+ ...flags,
2420
2451
  message: input,
2421
2452
  remarks: [],
2422
2453
  clouds: [],
@@ -2424,7 +2455,7 @@ class MetarParser extends AbstractParser {
2424
2455
  trends: [],
2425
2456
  runwaysInfo: [],
2426
2457
  };
2427
- let index = 2;
2458
+ index += 2;
2428
2459
  while (index < metarTab.length) {
2429
2460
  if (!super.generalParse(metar, metarTab[index]) &&
2430
2461
  !parseFlags(metar, metarTab[index])) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metar-taf-parser",
3
- "version": "7.1.0",
3
+ "version": "7.1.2",
4
4
  "description": "Parse METAR and TAF reports",
5
5
  "homepage": "https://aeharding.github.io/metar-taf-parser",
6
6
  "keywords": [