metar-taf-parser 6.1.0 → 6.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.
- package/metar-taf-parser.d.ts +6 -0
- package/metar-taf-parser.js +26 -13
- package/package.json +1 -1
package/metar-taf-parser.d.ts
CHANGED
|
@@ -1190,6 +1190,12 @@ interface ITAF extends IAbstractWeatherCode {
|
|
|
1190
1190
|
interface IAbstractTrend extends IAbstractWeatherContainer {
|
|
1191
1191
|
type: WeatherChangeType;
|
|
1192
1192
|
raw: string;
|
|
1193
|
+
/**
|
|
1194
|
+
* No Significant Weather
|
|
1195
|
+
*
|
|
1196
|
+
* Flag indicates that previous weather conditions have stopped
|
|
1197
|
+
*/
|
|
1198
|
+
nsw?: true;
|
|
1193
1199
|
}
|
|
1194
1200
|
interface IMetarTrendTime extends ITime {
|
|
1195
1201
|
type: TimeIndicator;
|
package/metar-taf-parser.js
CHANGED
|
@@ -2341,6 +2341,7 @@ class TAFParser extends AbstractParser {
|
|
|
2341
2341
|
this.PROB = "PROB";
|
|
2342
2342
|
this.TX = "TX";
|
|
2343
2343
|
this.TN = "TN";
|
|
2344
|
+
this.NSW = "NSW";
|
|
2344
2345
|
_TAFParser_validityPattern.set(this, /^\d{4}\/\d{4}$/);
|
|
2345
2346
|
}
|
|
2346
2347
|
/**
|
|
@@ -2384,21 +2385,36 @@ class TAFParser extends AbstractParser {
|
|
|
2384
2385
|
parseRemark(taf, lines[0], i, this.locale);
|
|
2385
2386
|
break;
|
|
2386
2387
|
}
|
|
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
2388
|
else {
|
|
2392
2389
|
parseFlags(taf, token);
|
|
2393
2390
|
this.generalParse(taf, token);
|
|
2394
2391
|
}
|
|
2395
2392
|
}
|
|
2393
|
+
const minMaxTemperatureLines = [
|
|
2394
|
+
lines[0].slice(index + 1), // EU countries have min/max in first line
|
|
2395
|
+
];
|
|
2396
|
+
// US military bases have min/max in last line
|
|
2397
|
+
if (lines.length > 1)
|
|
2398
|
+
minMaxTemperatureLines.push(lines[lines.length - 1]);
|
|
2399
|
+
this.parseMaxMinTemperatures(taf, minMaxTemperatureLines);
|
|
2396
2400
|
// Handle the other lines
|
|
2397
2401
|
for (let i = 1; i < lines.length; i++) {
|
|
2398
2402
|
this.parseLine(taf, lines[i]);
|
|
2399
2403
|
}
|
|
2400
2404
|
return taf;
|
|
2401
2405
|
}
|
|
2406
|
+
parseMaxMinTemperatures(taf, lines) {
|
|
2407
|
+
for (const line of lines) {
|
|
2408
|
+
for (const token of line) {
|
|
2409
|
+
if (token == this.RMK)
|
|
2410
|
+
break;
|
|
2411
|
+
else if (token.startsWith(this.TX))
|
|
2412
|
+
taf.maxTemperature = parseTemperature(token);
|
|
2413
|
+
else if (token.startsWith(this.TN))
|
|
2414
|
+
taf.minTemperature = parseTemperature(token);
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2402
2418
|
/**
|
|
2403
2419
|
* Format the message as a multiple line code so each line can be parsed
|
|
2404
2420
|
* @param tafCode The base message
|
|
@@ -2420,14 +2436,6 @@ class TAFParser extends AbstractParser {
|
|
|
2420
2436
|
return ls;
|
|
2421
2437
|
}
|
|
2422
2438
|
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
2439
|
return linesToken;
|
|
2432
2440
|
}
|
|
2433
2441
|
/**
|
|
@@ -2507,6 +2515,8 @@ class TAFParser extends AbstractParser {
|
|
|
2507
2515
|
parseRemark(trend, line, i, this.locale);
|
|
2508
2516
|
break;
|
|
2509
2517
|
}
|
|
2518
|
+
else if (line[i] === this.NSW)
|
|
2519
|
+
trend.nsw = true;
|
|
2510
2520
|
// already parsed
|
|
2511
2521
|
else if (__classPrivateFieldGet(this, _TAFParser_validityPattern, "f").test(line[i]))
|
|
2512
2522
|
continue;
|
|
@@ -2750,13 +2760,16 @@ function hydrateWithPreviousContextIfNeeded(forecast, context) {
|
|
|
2750
2760
|
context = { ...context };
|
|
2751
2761
|
delete context.remark;
|
|
2752
2762
|
context.remarks = [];
|
|
2763
|
+
delete context.nsw;
|
|
2753
2764
|
forecast = {
|
|
2754
2765
|
...context,
|
|
2755
2766
|
...forecast,
|
|
2756
2767
|
};
|
|
2757
2768
|
if (!forecast.clouds.length)
|
|
2758
2769
|
forecast.clouds = context.clouds;
|
|
2759
|
-
|
|
2770
|
+
// If NSW = true, previous weather conditions have stopped and should
|
|
2771
|
+
// not be carried over
|
|
2772
|
+
if (!forecast.weatherConditions.length && !forecast.nsw)
|
|
2760
2773
|
forecast.weatherConditions = context.weatherConditions;
|
|
2761
2774
|
return forecast;
|
|
2762
2775
|
}
|