metar-taf-parser 4.1.0 → 5.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.
- package/README.md +7 -8
- package/metar-taf-parser.d.ts +6 -9
- package/metar-taf-parser.js +9 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,9 +39,8 @@ const metar = parseMetar(rawMetarString);
|
|
|
39
39
|
|
|
40
40
|
// -or-
|
|
41
41
|
|
|
42
|
-
// Optionally pass
|
|
43
|
-
|
|
44
|
-
const datedMetar = parseMetar(rawMetarString, { date: new Date() });
|
|
42
|
+
// Optionally pass the date issued to add it to the report
|
|
43
|
+
const datedMetar = parseMetar(rawMetarString, { issued });
|
|
45
44
|
```
|
|
46
45
|
|
|
47
46
|
#### `parseTAF`
|
|
@@ -55,9 +54,9 @@ const taf = parseTAF(rawTAFString);
|
|
|
55
54
|
|
|
56
55
|
// -or-
|
|
57
56
|
|
|
58
|
-
// Optionally pass
|
|
59
|
-
//
|
|
60
|
-
const datedTAF = parseTAF(rawTAFString, {
|
|
57
|
+
// Optionally pass the date issued to get the report issued and
|
|
58
|
+
// trend validity dates (start/end) on the report:
|
|
59
|
+
const datedTAF = parseTAF(rawTAFString, { issued });
|
|
61
60
|
```
|
|
62
61
|
|
|
63
62
|
### Higher level parsing: The Forecast abstraction
|
|
@@ -72,7 +71,7 @@ Returns a more normalized TAF report. Most notably: while the `parseTAF` functio
|
|
|
72
71
|
import { parseTAFAsForecast } from "metar-taf-parser";
|
|
73
72
|
|
|
74
73
|
// You must provide an issued date to use the Forecast abstraction
|
|
75
|
-
const report = parseTAFAsForecast(rawTAFString, {
|
|
74
|
+
const report = parseTAFAsForecast(rawTAFString, { issued: tafIssuedDate });
|
|
76
75
|
|
|
77
76
|
console.log(report.forecast);
|
|
78
77
|
```
|
|
@@ -98,7 +97,7 @@ import {
|
|
|
98
97
|
getCompositeForecastForDate,
|
|
99
98
|
} from "metar-taf-parser";
|
|
100
99
|
|
|
101
|
-
const report = parseTAFAsForecast(rawTAFString, {
|
|
100
|
+
const report = parseTAFAsForecast(rawTAFString, { issued: tafIssuedDate });
|
|
102
101
|
|
|
103
102
|
const forecastPerHour = eachHourOfInterval({
|
|
104
103
|
start: report.start,
|
package/metar-taf-parser.d.ts
CHANGED
|
@@ -1142,11 +1142,11 @@ interface IAbstractValidity {
|
|
|
1142
1142
|
* Exclusive for the TS port (because python has `time()` and js does not)
|
|
1143
1143
|
*/
|
|
1144
1144
|
interface ITime {
|
|
1145
|
-
hour
|
|
1146
|
-
minute
|
|
1145
|
+
hour?: number;
|
|
1146
|
+
minute?: number;
|
|
1147
1147
|
}
|
|
1148
1148
|
interface IAbstractWeatherCode extends IAbstractWeatherContainer, ITime {
|
|
1149
|
-
day
|
|
1149
|
+
day?: number;
|
|
1150
1150
|
airport?: IAirport;
|
|
1151
1151
|
message: string;
|
|
1152
1152
|
station: string;
|
|
@@ -1326,15 +1326,12 @@ interface IMetarTAFParserOptions {
|
|
|
1326
1326
|
}
|
|
1327
1327
|
interface IMetarTAFParserOptionsDated extends IMetarTAFParserOptions {
|
|
1328
1328
|
/**
|
|
1329
|
-
* This date should
|
|
1330
|
-
* can be be +/- one week of the actual report date and work properly.
|
|
1331
|
-
*
|
|
1332
|
-
* So if you know the report was recently issued, you can pass `new Date()`
|
|
1329
|
+
* This date should be the date the report was issued.
|
|
1333
1330
|
*
|
|
1334
1331
|
* This date is needed to create actual timestamps since the report only has
|
|
1335
|
-
* day of month, hour, and minute.
|
|
1332
|
+
* day of month, hour, and minute (and sometimes not even that).
|
|
1336
1333
|
*/
|
|
1337
|
-
|
|
1334
|
+
issued: Date;
|
|
1338
1335
|
}
|
|
1339
1336
|
declare function parseMetar(rawMetar: string, options?: IMetarTAFParserOptions): IMetar;
|
|
1340
1337
|
declare function parseMetar(rawMetar: string, options?: IMetarTAFParserOptionsDated): IMetarDated;
|
package/metar-taf-parser.js
CHANGED
|
@@ -2064,7 +2064,7 @@ function parseDeliveryTime(timeString) {
|
|
|
2064
2064
|
const hour = +timeString.slice(2, 4);
|
|
2065
2065
|
const minute = +timeString.slice(4, 6);
|
|
2066
2066
|
if (isNaN(day) || isNaN(hour) || isNaN(minute))
|
|
2067
|
-
|
|
2067
|
+
return;
|
|
2068
2068
|
return {
|
|
2069
2069
|
day,
|
|
2070
2070
|
hour,
|
|
@@ -2120,7 +2120,7 @@ function parseTemperature(input) {
|
|
|
2120
2120
|
* @param input the string containing the validity
|
|
2121
2121
|
* @returns Validity object
|
|
2122
2122
|
*/
|
|
2123
|
-
function parseValidity(input
|
|
2123
|
+
function parseValidity(input) {
|
|
2124
2124
|
const parts = pySplit(input, "/");
|
|
2125
2125
|
return {
|
|
2126
2126
|
startDay: +parts[0].slice(0, 2),
|
|
@@ -2356,7 +2356,8 @@ class TAFParser extends AbstractParser {
|
|
|
2356
2356
|
const station = lines[0][index];
|
|
2357
2357
|
index += 1;
|
|
2358
2358
|
const time = parseDeliveryTime(lines[0][index]);
|
|
2359
|
-
|
|
2359
|
+
if (time)
|
|
2360
|
+
index += 1;
|
|
2360
2361
|
const validity = parseValidity(lines[0][index]);
|
|
2361
2362
|
const taf = {
|
|
2362
2363
|
station,
|
|
@@ -2546,6 +2547,9 @@ _RemarkParser_supplier = new WeakMap();
|
|
|
2546
2547
|
* @returns
|
|
2547
2548
|
*/
|
|
2548
2549
|
function determineReportIssuedDate(date, day, hour, minute) {
|
|
2550
|
+
// Some TAF reports do not include a delivery time
|
|
2551
|
+
if (day == null || hour == null)
|
|
2552
|
+
return date;
|
|
2549
2553
|
const months = [
|
|
2550
2554
|
setDateComponents(addMonthsUTC(date, -1), day, hour, minute),
|
|
2551
2555
|
setDateComponents(new Date(date), day, hour, minute),
|
|
@@ -2705,8 +2709,8 @@ function parse(rawReport, options, parser, datesHydrator) {
|
|
|
2705
2709
|
const lang = options?.locale || en;
|
|
2706
2710
|
try {
|
|
2707
2711
|
const report = new parser(lang).parse(rawReport);
|
|
2708
|
-
if (options && "
|
|
2709
|
-
return datesHydrator(report, options.
|
|
2712
|
+
if (options && "issued" in options) {
|
|
2713
|
+
return datesHydrator(report, options.issued);
|
|
2710
2714
|
}
|
|
2711
2715
|
return report;
|
|
2712
2716
|
}
|