metar-taf-parser 6.1.0 → 6.1.1

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 +19 -12
  2. package/package.json +1 -1
@@ -2384,21 +2384,36 @@ class TAFParser extends AbstractParser {
2384
2384
  parseRemark(taf, lines[0], i, this.locale);
2385
2385
  break;
2386
2386
  }
2387
- else if (token.startsWith(this.TX))
2388
- taf.maxTemperature = parseTemperature(token);
2389
- else if (token.startsWith(this.TN))
2390
- taf.minTemperature = parseTemperature(token);
2391
2387
  else {
2392
2388
  parseFlags(taf, token);
2393
2389
  this.generalParse(taf, token);
2394
2390
  }
2395
2391
  }
2392
+ const minMaxTemperatureLines = [
2393
+ lines[0].slice(index + 1), // EU countries have min/max in first line
2394
+ ];
2395
+ // US military bases have min/max in last line
2396
+ if (lines.length > 1)
2397
+ minMaxTemperatureLines.push(lines[lines.length - 1]);
2398
+ this.parseMaxMinTemperatures(taf, minMaxTemperatureLines);
2396
2399
  // Handle the other lines
2397
2400
  for (let i = 1; i < lines.length; i++) {
2398
2401
  this.parseLine(taf, lines[i]);
2399
2402
  }
2400
2403
  return taf;
2401
2404
  }
2405
+ parseMaxMinTemperatures(taf, lines) {
2406
+ for (const line of lines) {
2407
+ for (const token of line) {
2408
+ if (token == this.RMK)
2409
+ break;
2410
+ else if (token.startsWith(this.TX))
2411
+ taf.maxTemperature = parseTemperature(token);
2412
+ else if (token.startsWith(this.TN))
2413
+ taf.minTemperature = parseTemperature(token);
2414
+ }
2415
+ }
2416
+ }
2402
2417
  /**
2403
2418
  * Format the message as a multiple line code so each line can be parsed
2404
2419
  * @param tafCode The base message
@@ -2420,14 +2435,6 @@ class TAFParser extends AbstractParser {
2420
2435
  return ls;
2421
2436
  }
2422
2437
  const linesToken = lines.map(this.tokenize);
2423
- if (linesToken.length > 1) {
2424
- const lastLine = linesToken[lines.length - 1];
2425
- const temperatures = lastLine.filter((l) => l.startsWith(this.TX) || l.startsWith(this.TN));
2426
- if (temperatures.length) {
2427
- linesToken[0] = linesToken[0].concat(temperatures);
2428
- linesToken[lines.length - 1] = lastLine.filter((l) => !l.startsWith(this.TX) && !l.startsWith(this.TN));
2429
- }
2430
- }
2431
2438
  return linesToken;
2432
2439
  }
2433
2440
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metar-taf-parser",
3
- "version": "6.1.0",
3
+ "version": "6.1.1",
4
4
  "description": "Parse METAR and TAF reports",
5
5
  "homepage": "https://aeharding.github.io/metar-taf-parser",
6
6
  "keywords": [