metar-taf-parser 3.1.2 → 4.0.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/README.md +1 -1
- package/{dist/locale → locale}/de.d.ts +0 -0
- package/{dist/locale → locale}/de.js +3 -3
- package/{dist/locale → locale}/en.d.ts +0 -0
- package/{dist/locale → locale}/en.js +3 -3
- package/{dist/locale → locale}/fr.d.ts +0 -0
- package/{dist/locale → locale}/fr.js +3 -3
- package/{dist/locale → locale}/it.d.ts +0 -0
- package/{dist/locale → locale}/it.js +3 -3
- package/{dist/locale → locale}/pl.d.ts +0 -0
- package/{dist/locale → locale}/pl.js +3 -3
- package/{dist/locale → locale}/zh-CN.d.ts +0 -0
- package/{dist/locale → locale}/zh-CN.js +3 -3
- package/metar-taf-parser.d.ts +1325 -0
- package/metar-taf-parser.js +2703 -0
- package/package.json +23 -16
- package/dist/command/common.d.ts +0 -54
- package/dist/command/common.js +0 -243
- package/dist/command/metar/AltimeterCommand.d.ts +0 -7
- package/dist/command/metar/AltimeterCommand.js +0 -26
- package/dist/command/metar/AltimeterMercuryCommand.d.ts +0 -7
- package/dist/command/metar/AltimeterMercuryCommand.js +0 -51
- package/dist/command/metar/RunwayCommand.d.ts +0 -7
- package/dist/command/metar/RunwayCommand.js +0 -60
- package/dist/command/metar/TemperatureCommand.d.ts +0 -7
- package/dist/command/metar/TemperatureCommand.js +0 -51
- package/dist/command/metar.d.ts +0 -9
- package/dist/command/metar.js +0 -31
- package/dist/command/remark/CeilingHeightCommand.d.ts +0 -18
- package/dist/command/remark/CeilingHeightCommand.js +0 -40
- package/dist/command/remark/CeilingSecondLocationCommand.d.ts +0 -12
- package/dist/command/remark/CeilingSecondLocationCommand.js +0 -40
- package/dist/command/remark/Command.d.ts +0 -8
- package/dist/command/remark/Command.js +0 -9
- package/dist/command/remark/DefaultCommand.d.ts +0 -11
- package/dist/command/remark/DefaultCommand.js +0 -38
- package/dist/command/remark/HailSizeCommand.d.ts +0 -11
- package/dist/command/remark/HailSizeCommand.js +0 -38
- package/dist/command/remark/HourlyMaximumMinimumTemperatureCommand.d.ts +0 -18
- package/dist/command/remark/HourlyMaximumMinimumTemperatureCommand.js +0 -39
- package/dist/command/remark/HourlyMaximumTemperatureCommand.d.ts +0 -14
- package/dist/command/remark/HourlyMaximumTemperatureCommand.js +0 -38
- package/dist/command/remark/HourlyMinimumTemperatureCommand.d.ts +0 -14
- package/dist/command/remark/HourlyMinimumTemperatureCommand.js +0 -38
- package/dist/command/remark/HourlyPrecipitationAmountCommand.d.ts +0 -14
- package/dist/command/remark/HourlyPrecipitationAmountCommand.js +0 -38
- package/dist/command/remark/HourlyPressureCommand.d.ts +0 -32
- package/dist/command/remark/HourlyPressureCommand.js +0 -40
- package/dist/command/remark/HourlyTemperatureDewPointCommand.d.ts +0 -18
- package/dist/command/remark/HourlyTemperatureDewPointCommand.js +0 -52
- package/dist/command/remark/IceAccretionCommand.d.ts +0 -15
- package/dist/command/remark/IceAccretionCommand.js +0 -38
- package/dist/command/remark/ObscurationCommand.d.ts +0 -14
- package/dist/command/remark/ObscurationCommand.js +0 -44
- package/dist/command/remark/PrecipitationAmount24HourCommand.d.ts +0 -14
- package/dist/command/remark/PrecipitationAmount24HourCommand.js +0 -39
- package/dist/command/remark/PrecipitationAmount36HourCommand.d.ts +0 -15
- package/dist/command/remark/PrecipitationAmount36HourCommand.js +0 -41
- package/dist/command/remark/PrecipitationBegCommand.d.ts +0 -15
- package/dist/command/remark/PrecipitationBegCommand.js +0 -45
- package/dist/command/remark/PrecipitationBegEndCommand.d.ts +0 -17
- package/dist/command/remark/PrecipitationBegEndCommand.js +0 -46
- package/dist/command/remark/PrecipitationEndCommand.d.ts +0 -15
- package/dist/command/remark/PrecipitationEndCommand.js +0 -45
- package/dist/command/remark/PrevailingVisibilityCommand.d.ts +0 -12
- package/dist/command/remark/PrevailingVisibilityCommand.js +0 -41
- package/dist/command/remark/SeaLevelPressureCommand.d.ts +0 -11
- package/dist/command/remark/SeaLevelPressureCommand.js +0 -39
- package/dist/command/remark/SecondLocationVisibilityCommand.d.ts +0 -12
- package/dist/command/remark/SecondLocationVisibilityCommand.js +0 -41
- package/dist/command/remark/SectorVisibilityCommand.d.ts +0 -13
- package/dist/command/remark/SectorVisibilityCommand.js +0 -42
- package/dist/command/remark/SmallHailSizeCommand.d.ts +0 -11
- package/dist/command/remark/SmallHailSizeCommand.js +0 -38
- package/dist/command/remark/SnowDepthCommand.d.ts +0 -11
- package/dist/command/remark/SnowDepthCommand.js +0 -38
- package/dist/command/remark/SnowIncreaseCommand.d.ts +0 -12
- package/dist/command/remark/SnowIncreaseCommand.js +0 -40
- package/dist/command/remark/SnowPelletsCommand.d.ts +0 -11
- package/dist/command/remark/SnowPelletsCommand.js +0 -37
- package/dist/command/remark/SunshineDurationCommand.d.ts +0 -11
- package/dist/command/remark/SunshineDurationCommand.js +0 -38
- package/dist/command/remark/SurfaceVisibilityCommand.d.ts +0 -11
- package/dist/command/remark/SurfaceVisibilityCommand.js +0 -39
- package/dist/command/remark/ThunderStormLocationCommand.d.ts +0 -12
- package/dist/command/remark/ThunderStormLocationCommand.js +0 -40
- package/dist/command/remark/ThunderStormLocationMovingCommand.d.ts +0 -19
- package/dist/command/remark/ThunderStormLocationMovingCommand.js +0 -42
- package/dist/command/remark/TornadicActivityBegCommand.d.ts +0 -16
- package/dist/command/remark/TornadicActivityBegCommand.js +0 -44
- package/dist/command/remark/TornadicActivityBegEndCommand.d.ts +0 -18
- package/dist/command/remark/TornadicActivityBegEndCommand.js +0 -46
- package/dist/command/remark/TornadicActivityEndCommand.d.ts +0 -16
- package/dist/command/remark/TornadicActivityEndCommand.js +0 -44
- package/dist/command/remark/TowerVisibilityCommand.d.ts +0 -11
- package/dist/command/remark/TowerVisibilityCommand.js +0 -39
- package/dist/command/remark/VariableSkyCommand.d.ts +0 -12
- package/dist/command/remark/VariableSkyCommand.js +0 -41
- package/dist/command/remark/VariableSkyHeightCommand.d.ts +0 -13
- package/dist/command/remark/VariableSkyHeightCommand.js +0 -43
- package/dist/command/remark/VirgaDirectionCommand.d.ts +0 -12
- package/dist/command/remark/VirgaDirectionCommand.js +0 -40
- package/dist/command/remark/WaterEquivalentSnowCommand.d.ts +0 -11
- package/dist/command/remark/WaterEquivalentSnowCommand.js +0 -38
- package/dist/command/remark/WindPeakCommandCommand.d.ts +0 -17
- package/dist/command/remark/WindPeakCommandCommand.js +0 -42
- package/dist/command/remark/WindShiftCommand.d.ts +0 -12
- package/dist/command/remark/WindShiftCommand.js +0 -38
- package/dist/command/remark/WindShiftFropaCommand.d.ts +0 -12
- package/dist/command/remark/WindShiftFropaCommand.js +0 -38
- package/dist/command/remark.d.ts +0 -109
- package/dist/command/remark.js +0 -152
- package/dist/commons/converter.d.ts +0 -21
- package/dist/commons/converter.js +0 -108
- package/dist/commons/errors.d.ts +0 -24
- package/dist/commons/errors.js +0 -46
- package/dist/commons/i18n.d.ts +0 -12
- package/dist/commons/i18n.js +0 -30
- package/dist/dates/metar.d.ts +0 -5
- package/dist/dates/metar.js +0 -8
- package/dist/dates/taf.d.ts +0 -28
- package/dist/dates/taf.js +0 -17
- package/dist/forecast/forecast.d.ts +0 -36
- package/dist/forecast/forecast.js +0 -72
- package/dist/helpers/date.d.ts +0 -11
- package/dist/helpers/date.js +0 -56
- package/dist/helpers/helpers.d.ts +0 -17
- package/dist/helpers/helpers.js +0 -46
- package/dist/index.d.ts +0 -32
- package/dist/index.js +0 -62
- package/dist/model/enum.d.ts +0 -265
- package/dist/model/enum.js +0 -280
- package/dist/model/model.d.ts +0 -188
- package/dist/model/model.js +0 -11
- package/dist/parser/parser.d.ts +0 -111
- package/dist/parser/parser.js +0 -480
package/dist/parser/parser.js
DELETED
|
@@ -1,480 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
26
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
27
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
28
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
29
|
-
};
|
|
30
|
-
var _AbstractParser_INTENSITY_REGEX, _AbstractParser_CAVOK, _AbstractParser_commonSupplier, _MetarParser_commandSupplier, _TAFParser_validityPattern, _RemarkParser_supplier;
|
|
31
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.RemarkParser = exports.TAFParser = exports.MetarParser = exports.AbstractParser = exports.parseValidity = exports.parseTemperature = void 0;
|
|
33
|
-
const remark_1 = require("../command/remark");
|
|
34
|
-
const model_1 = require("../model/model");
|
|
35
|
-
const enum_1 = require("../model/enum");
|
|
36
|
-
const converter = __importStar(require("../commons/converter"));
|
|
37
|
-
const helpers_1 = require("../helpers/helpers");
|
|
38
|
-
const common_1 = require("../command/common");
|
|
39
|
-
const enum_2 = require("../model/enum");
|
|
40
|
-
const metar_1 = require("../command/metar");
|
|
41
|
-
const errors_1 = require("../commons/errors");
|
|
42
|
-
/**
|
|
43
|
-
* Parses the delivery time of a METAR/TAF
|
|
44
|
-
* @param abstractWeatherCode The TAF or METAR object
|
|
45
|
-
* @param timeString The string representing the delivery time
|
|
46
|
-
*/
|
|
47
|
-
function parseDeliveryTime(timeString) {
|
|
48
|
-
const day = +timeString.slice(0, 2);
|
|
49
|
-
const hour = +timeString.slice(2, 4);
|
|
50
|
-
const minute = +timeString.slice(4, 6);
|
|
51
|
-
if (isNaN(day) || isNaN(hour) || isNaN(minute))
|
|
52
|
-
throw new errors_1.InvalidWeatherStatementError("Report time is invalid");
|
|
53
|
-
return {
|
|
54
|
-
day,
|
|
55
|
-
hour,
|
|
56
|
-
minute,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* This function parses the array containing the remark and concat the array into a string
|
|
61
|
-
* @param container the metar, taf or taf trend to update
|
|
62
|
-
* @param line The array containing the current line tokens
|
|
63
|
-
* @param index the index starting the remark ie token RMK
|
|
64
|
-
*/
|
|
65
|
-
function parseRemark(container, line, index, locale) {
|
|
66
|
-
const remarks = new RemarkParser(locale).parse(line.slice(index + 1).join(" "));
|
|
67
|
-
container.remarks = remarks;
|
|
68
|
-
container.remark = remarks
|
|
69
|
-
.map(({ description, raw }) => description || raw)
|
|
70
|
-
.join(" ");
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Parses the temperature in a TAF
|
|
74
|
-
* @param input the string containing the temperature
|
|
75
|
-
* @returns TemperatureDated object
|
|
76
|
-
*/
|
|
77
|
-
function parseTemperature(input) {
|
|
78
|
-
const parts = (0, helpers_1.pySplit)(input, "/");
|
|
79
|
-
return {
|
|
80
|
-
temperature: converter.convertTemperature(parts[0].slice(2)),
|
|
81
|
-
day: +parts[1].slice(0, 2),
|
|
82
|
-
hour: +parts[1].slice(2, 4),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
exports.parseTemperature = parseTemperature;
|
|
86
|
-
/**
|
|
87
|
-
* Parses validity of a TAF or a TAFTrend
|
|
88
|
-
* @param input the string containing the validity
|
|
89
|
-
* @returns Validity object
|
|
90
|
-
*/
|
|
91
|
-
function parseValidity(input, date) {
|
|
92
|
-
const parts = (0, helpers_1.pySplit)(input, "/");
|
|
93
|
-
return {
|
|
94
|
-
startDay: +parts[0].slice(0, 2),
|
|
95
|
-
startHour: +parts[0].slice(2),
|
|
96
|
-
endDay: +parts[1].slice(0, 2),
|
|
97
|
-
endHour: +parts[1].slice(2),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
exports.parseValidity = parseValidity;
|
|
101
|
-
/**
|
|
102
|
-
* Parses the validity for a FROM taf trend
|
|
103
|
-
* @param input the string containing the validity
|
|
104
|
-
* @returns a Validity object
|
|
105
|
-
*/
|
|
106
|
-
function parseFromValidity(input) {
|
|
107
|
-
return {
|
|
108
|
-
startDay: +input.slice(2, 4),
|
|
109
|
-
startHour: +input.slice(4, 6),
|
|
110
|
-
startMinutes: +input.slice(6, 8),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Abstract class.
|
|
115
|
-
* Base parser.
|
|
116
|
-
*/
|
|
117
|
-
class AbstractParser {
|
|
118
|
-
constructor(locale) {
|
|
119
|
-
this.locale = locale;
|
|
120
|
-
this.FM = "FM";
|
|
121
|
-
this.TEMPO = "TEMPO";
|
|
122
|
-
this.BECMG = "BECMG";
|
|
123
|
-
this.RMK = "RMK";
|
|
124
|
-
// Safari does not currently support negative lookbehind
|
|
125
|
-
// #TOKENIZE_REGEX = /\s((?=\d\/\dSM)(?<!\s\d\s)|(?!\d\/\dSM))|=/;
|
|
126
|
-
_AbstractParser_INTENSITY_REGEX.set(this, /^(-|\+|VC)/);
|
|
127
|
-
_AbstractParser_CAVOK.set(this, "CAVOK");
|
|
128
|
-
_AbstractParser_commonSupplier.set(this, new common_1.CommandSupplier());
|
|
129
|
-
}
|
|
130
|
-
parseWeatherCondition(input) {
|
|
131
|
-
var _a;
|
|
132
|
-
let intensity;
|
|
133
|
-
if (input.match(__classPrivateFieldGet(this, _AbstractParser_INTENSITY_REGEX, "f"))) {
|
|
134
|
-
const match = (_a = input.match(__classPrivateFieldGet(this, _AbstractParser_INTENSITY_REGEX, "f"))) === null || _a === void 0 ? void 0 : _a[0];
|
|
135
|
-
if (match)
|
|
136
|
-
intensity = match;
|
|
137
|
-
}
|
|
138
|
-
let descriptive;
|
|
139
|
-
for (const key of Object.values(enum_2.Descriptive)) {
|
|
140
|
-
if (input.includes(key))
|
|
141
|
-
descriptive = key;
|
|
142
|
-
}
|
|
143
|
-
const weatherCondition = {
|
|
144
|
-
intensity,
|
|
145
|
-
descriptive,
|
|
146
|
-
phenomenons: [],
|
|
147
|
-
};
|
|
148
|
-
for (const key of Object.values(enum_2.Phenomenon)) {
|
|
149
|
-
// Thunderstorm as descriptive should not be added as a phenomenon
|
|
150
|
-
if (descriptive === key)
|
|
151
|
-
continue;
|
|
152
|
-
if (input.includes(key))
|
|
153
|
-
weatherCondition.phenomenons.push(key);
|
|
154
|
-
}
|
|
155
|
-
return weatherCondition;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Parses the message into different tokens
|
|
159
|
-
* @param input The metar or TAF as string
|
|
160
|
-
* @returns List of tokens
|
|
161
|
-
*/
|
|
162
|
-
tokenize(input) {
|
|
163
|
-
// Missing safari support. If added in the future, put this back
|
|
164
|
-
// return input.split(this.#TOKENIZE_REGEX).filter((v) => v);
|
|
165
|
-
// Hack for safari below...
|
|
166
|
-
const splitRegex = /\s|=/;
|
|
167
|
-
const smRegex = /^\d\/\dSM$/;
|
|
168
|
-
const digitRegex = /^(P|M)?\d$/;
|
|
169
|
-
// return input.split(this.#TOKENIZE_REGEX).filter((v) => v);
|
|
170
|
-
const splitted = input.split(splitRegex);
|
|
171
|
-
for (let i = 0; i < splitted.length; i++) {
|
|
172
|
-
if (digitRegex.test(splitted[i])) {
|
|
173
|
-
if (splitted[i + 1] && smRegex.test(splitted[i + 1])) {
|
|
174
|
-
splitted.splice(i, 2, `${splitted[i]} ${splitted[i + 1]}`);
|
|
175
|
-
i--;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return splitted.filter((t) => t);
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Common parse method for METAR, TAF and trends object
|
|
183
|
-
* @param abstractWeatherCode the object to update
|
|
184
|
-
* @param input The token to parse
|
|
185
|
-
* @returns True if the token was parsed false otherwise
|
|
186
|
-
*/
|
|
187
|
-
generalParse(abstractWeatherContainer, input) {
|
|
188
|
-
if (input === __classPrivateFieldGet(this, _AbstractParser_CAVOK, "f")) {
|
|
189
|
-
abstractWeatherContainer.cavok = true;
|
|
190
|
-
abstractWeatherContainer.visibility = {
|
|
191
|
-
indicator: enum_1.ValueIndicator.GreaterThan,
|
|
192
|
-
value: 9999,
|
|
193
|
-
unit: enum_1.DistanceUnit.Meters,
|
|
194
|
-
};
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
const command = __classPrivateFieldGet(this, _AbstractParser_commonSupplier, "f").get(input);
|
|
198
|
-
if (command) {
|
|
199
|
-
return command.execute(abstractWeatherContainer, input);
|
|
200
|
-
}
|
|
201
|
-
const weatherCondition = this.parseWeatherCondition(input);
|
|
202
|
-
if ((0, model_1.isWeatherConditionValid)(weatherCondition)) {
|
|
203
|
-
abstractWeatherContainer.weatherConditions.push(weatherCondition);
|
|
204
|
-
return true;
|
|
205
|
-
}
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
exports.AbstractParser = AbstractParser;
|
|
210
|
-
_AbstractParser_INTENSITY_REGEX = new WeakMap(), _AbstractParser_CAVOK = new WeakMap(), _AbstractParser_commonSupplier = new WeakMap();
|
|
211
|
-
class MetarParser extends AbstractParser {
|
|
212
|
-
constructor() {
|
|
213
|
-
super(...arguments);
|
|
214
|
-
this.AT = "AT";
|
|
215
|
-
this.TL = "TL";
|
|
216
|
-
_MetarParser_commandSupplier.set(this, new metar_1.CommandSupplier());
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Parses a trend of a metar
|
|
220
|
-
* @param index the index starting the trend in the list
|
|
221
|
-
* @param trend The trend to update
|
|
222
|
-
* @param trendParts array of tokens
|
|
223
|
-
* @returns the last index of the token that was last parsed
|
|
224
|
-
*/
|
|
225
|
-
parseTrend(index, trend, trendParts) {
|
|
226
|
-
let i = index + 1;
|
|
227
|
-
while (i < trendParts.length &&
|
|
228
|
-
trendParts[i] !== this.TEMPO &&
|
|
229
|
-
trendParts[i] !== this.BECMG) {
|
|
230
|
-
if (trendParts[i].startsWith(this.FM) ||
|
|
231
|
-
trendParts[i].startsWith(this.TL) ||
|
|
232
|
-
trendParts[i].startsWith(this.AT)) {
|
|
233
|
-
const trendTime = {
|
|
234
|
-
type: enum_2.TimeIndicator[trendParts[i].slice(0, 2)],
|
|
235
|
-
hour: +trendParts[i].slice(2, 4),
|
|
236
|
-
minute: +trendParts[i].slice(4, 6),
|
|
237
|
-
};
|
|
238
|
-
trend.times.push(trendTime);
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
this.generalParse(trend, trendParts[i]);
|
|
242
|
-
}
|
|
243
|
-
i = i + 1;
|
|
244
|
-
}
|
|
245
|
-
return i - 1;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Parses an message and returns a METAR
|
|
249
|
-
* @param input The message to parse
|
|
250
|
-
* @returns METAR
|
|
251
|
-
*/
|
|
252
|
-
parse(input) {
|
|
253
|
-
const metarTab = this.tokenize(input);
|
|
254
|
-
const metar = Object.assign(Object.assign({}, parseDeliveryTime(metarTab[1])), { station: metarTab[0], message: input, remarks: [], clouds: [], weatherConditions: [], trends: [], runwaysInfo: [] });
|
|
255
|
-
let index = 2;
|
|
256
|
-
while (index < metarTab.length) {
|
|
257
|
-
if (!super.generalParse(metar, metarTab[index])) {
|
|
258
|
-
if (metarTab[index] === "NOSIG") {
|
|
259
|
-
metar.nosig = true;
|
|
260
|
-
}
|
|
261
|
-
else if (metarTab[index] === "AUTO") {
|
|
262
|
-
metar.auto = true;
|
|
263
|
-
}
|
|
264
|
-
else if (metarTab[index] === this.TEMPO ||
|
|
265
|
-
metarTab[index] === this.BECMG) {
|
|
266
|
-
const trend = {
|
|
267
|
-
type: enum_2.WeatherChangeType[metarTab[index]],
|
|
268
|
-
weatherConditions: [],
|
|
269
|
-
clouds: [],
|
|
270
|
-
times: [],
|
|
271
|
-
remarks: [],
|
|
272
|
-
};
|
|
273
|
-
index = this.parseTrend(index, trend, metarTab);
|
|
274
|
-
metar.trends.push(trend);
|
|
275
|
-
}
|
|
276
|
-
else if (metarTab[index] === this.RMK) {
|
|
277
|
-
parseRemark(metar, metarTab, index, this.locale);
|
|
278
|
-
break;
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
const command = __classPrivateFieldGet(this, _MetarParser_commandSupplier, "f").get(metarTab[index]);
|
|
282
|
-
if (command)
|
|
283
|
-
command.execute(metar, metarTab[index]);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
index = index + 1;
|
|
287
|
-
}
|
|
288
|
-
return metar;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
exports.MetarParser = MetarParser;
|
|
292
|
-
_MetarParser_commandSupplier = new WeakMap();
|
|
293
|
-
/**
|
|
294
|
-
* Parser for TAF messages
|
|
295
|
-
*/
|
|
296
|
-
class TAFParser extends AbstractParser {
|
|
297
|
-
constructor() {
|
|
298
|
-
super(...arguments);
|
|
299
|
-
this.TAF = "TAF";
|
|
300
|
-
this.PROB = "PROB";
|
|
301
|
-
this.TX = "TX";
|
|
302
|
-
this.TN = "TN";
|
|
303
|
-
_TAFParser_validityPattern.set(this, /^\d{4}\/\d{4}$/);
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* the message to parse
|
|
307
|
-
* @param input
|
|
308
|
-
* @returns a TAF object
|
|
309
|
-
* @throws ParseError if the message is invalid
|
|
310
|
-
*/
|
|
311
|
-
parse(input) {
|
|
312
|
-
let amendment;
|
|
313
|
-
const lines = this.extractLinesTokens(input);
|
|
314
|
-
let index = 0;
|
|
315
|
-
if (lines[0][0] === this.TAF)
|
|
316
|
-
index = 1;
|
|
317
|
-
if (lines[0][1] === this.TAF)
|
|
318
|
-
index = 2;
|
|
319
|
-
if (lines[0][index] === "AMD") {
|
|
320
|
-
amendment = true;
|
|
321
|
-
index += 1;
|
|
322
|
-
}
|
|
323
|
-
const station = lines[0][index];
|
|
324
|
-
index += 1;
|
|
325
|
-
const time = parseDeliveryTime(lines[0][index]);
|
|
326
|
-
index += 1;
|
|
327
|
-
const validity = parseValidity(lines[0][index]);
|
|
328
|
-
const taf = Object.assign(Object.assign({ station,
|
|
329
|
-
amendment }, time), { validity, message: input, trends: [], remarks: [], clouds: [], weatherConditions: [] });
|
|
330
|
-
for (let i = index + 1; i < lines[0].length; i++) {
|
|
331
|
-
const token = lines[0][i];
|
|
332
|
-
if (token == this.RMK) {
|
|
333
|
-
parseRemark(taf, lines[0], i, this.locale);
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
else if (token.startsWith(this.TX))
|
|
337
|
-
taf.maxTemperature = parseTemperature(token);
|
|
338
|
-
else if (token.startsWith(this.TN))
|
|
339
|
-
taf.minTemperature = parseTemperature(token);
|
|
340
|
-
else
|
|
341
|
-
this.generalParse(taf, token);
|
|
342
|
-
}
|
|
343
|
-
// Handle the other lines
|
|
344
|
-
for (let i = 1; i < lines.length; i++) {
|
|
345
|
-
this.parseLine(taf, lines[i]);
|
|
346
|
-
}
|
|
347
|
-
return taf;
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Format the message as a multiple line code so each line can be parsed
|
|
351
|
-
* @param tafCode The base message
|
|
352
|
-
* @returns a list of string representing the lines of the message
|
|
353
|
-
*/
|
|
354
|
-
extractLinesTokens(tafCode) {
|
|
355
|
-
const singleLine = tafCode.replace(/\n/g, " ");
|
|
356
|
-
const cleanLine = singleLine.replace(/\s{2,}/g, " ");
|
|
357
|
-
const lines = joinProbIfNeeded(cleanLine
|
|
358
|
-
.replace(/\s(?=PROB\d{2}\sTEMPO|TEMPO|BECMG|FM|PROB)/g, "\n")
|
|
359
|
-
.split(/\n/));
|
|
360
|
-
// TODO cleanup
|
|
361
|
-
function joinProbIfNeeded(ls) {
|
|
362
|
-
for (let i = 0; i < ls.length; i++) {
|
|
363
|
-
if (/PROB\d{2}/.test(ls[i]) && /TEMPO/.test(ls[i + 1])) {
|
|
364
|
-
ls.splice(i, 2, `${ls[i]} ${ls[i + 1]}`);
|
|
365
|
-
i--;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
return ls;
|
|
369
|
-
}
|
|
370
|
-
const linesToken = lines.map(this.tokenize);
|
|
371
|
-
if (linesToken.length > 1) {
|
|
372
|
-
const lastLine = linesToken[lines.length - 1];
|
|
373
|
-
const temperatures = lastLine.filter((l) => l.startsWith(this.TX) || l.startsWith(this.TN));
|
|
374
|
-
if (temperatures.length) {
|
|
375
|
-
linesToken[0] = linesToken[0].concat(temperatures);
|
|
376
|
-
linesToken[lines.length - 1] = lastLine.filter((l) => !l.startsWith(this.TX) && !l.startsWith(this.TN));
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
return linesToken;
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* Parses the tokens of the line and updates the TAF object
|
|
383
|
-
* @param taf TAF object to update
|
|
384
|
-
* @param lineTokens the array of tokens representing a line
|
|
385
|
-
*/
|
|
386
|
-
parseLine(taf, lineTokens) {
|
|
387
|
-
let index = 1;
|
|
388
|
-
let trend;
|
|
389
|
-
if (lineTokens[0].startsWith(this.FM)) {
|
|
390
|
-
trend = Object.assign(Object.assign({}, this.makeEmptyTAFTrend()), { type: enum_2.WeatherChangeType.FM, validity: parseFromValidity(lineTokens[0]) });
|
|
391
|
-
}
|
|
392
|
-
else if (lineTokens[0].startsWith(this.PROB)) {
|
|
393
|
-
const validity = this.findLineValidity(index, lineTokens);
|
|
394
|
-
if (!validity)
|
|
395
|
-
return;
|
|
396
|
-
trend = Object.assign(Object.assign({}, this.makeEmptyTAFTrend()), { type: enum_2.WeatherChangeType.PROB, validity });
|
|
397
|
-
if (lineTokens.length > 1 && lineTokens[1] === this.TEMPO) {
|
|
398
|
-
trend = Object.assign(Object.assign({}, this.makeEmptyTAFTrend()), { type: enum_2.WeatherChangeType[lineTokens[1]], validity });
|
|
399
|
-
index = 2;
|
|
400
|
-
}
|
|
401
|
-
trend.probability = +lineTokens[0].slice(4);
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
const validity = this.findLineValidity(index, lineTokens);
|
|
405
|
-
if (!validity)
|
|
406
|
-
return;
|
|
407
|
-
trend = Object.assign(Object.assign({}, this.makeEmptyTAFTrend()), { type: enum_2.WeatherChangeType[lineTokens[0]], validity });
|
|
408
|
-
}
|
|
409
|
-
this.parseTrend(index, lineTokens, trend);
|
|
410
|
-
taf.trends.push(trend);
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Finds a non-FM validity in a line
|
|
414
|
-
* @param index the index at which the array should be parsed
|
|
415
|
-
* @param line The array of string containing the line
|
|
416
|
-
* @param trend The trend object to update
|
|
417
|
-
*/
|
|
418
|
-
findLineValidity(index, line) {
|
|
419
|
-
let validity;
|
|
420
|
-
for (let i = index; i < line.length; i++) {
|
|
421
|
-
if (__classPrivateFieldGet(this, _TAFParser_validityPattern, "f").test(line[i]))
|
|
422
|
-
validity = parseValidity(line[i]);
|
|
423
|
-
}
|
|
424
|
-
return validity;
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Parses a trend of the TAF
|
|
428
|
-
* @param index the index at which the array should be parsed
|
|
429
|
-
* @param line The array of string containing the line
|
|
430
|
-
* @param trend The trend object to update
|
|
431
|
-
*/
|
|
432
|
-
parseTrend(index, line, trend) {
|
|
433
|
-
for (let i = index; i < line.length; i++) {
|
|
434
|
-
if (line[i] === this.RMK) {
|
|
435
|
-
parseRemark(trend, line, i, this.locale);
|
|
436
|
-
break;
|
|
437
|
-
}
|
|
438
|
-
// already parsed
|
|
439
|
-
else if (__classPrivateFieldGet(this, _TAFParser_validityPattern, "f").test(line[i]))
|
|
440
|
-
continue;
|
|
441
|
-
else
|
|
442
|
-
super.generalParse(trend, line[i]);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
makeEmptyTAFTrend() {
|
|
446
|
-
return {
|
|
447
|
-
remarks: [],
|
|
448
|
-
clouds: [],
|
|
449
|
-
weatherConditions: [],
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
exports.TAFParser = TAFParser;
|
|
454
|
-
_TAFParser_validityPattern = new WeakMap();
|
|
455
|
-
class RemarkParser {
|
|
456
|
-
constructor(locale) {
|
|
457
|
-
this.locale = locale;
|
|
458
|
-
_RemarkParser_supplier.set(this, new remark_1.RemarkCommandSupplier(this.locale));
|
|
459
|
-
}
|
|
460
|
-
parse(code) {
|
|
461
|
-
let rmkStr = code;
|
|
462
|
-
let rmkList = [];
|
|
463
|
-
while (rmkStr) {
|
|
464
|
-
try {
|
|
465
|
-
[rmkStr, rmkList] = __classPrivateFieldGet(this, _RemarkParser_supplier, "f").get(rmkStr).execute(rmkStr, rmkList);
|
|
466
|
-
}
|
|
467
|
-
catch (e) {
|
|
468
|
-
if (e instanceof errors_1.CommandExecutionError) {
|
|
469
|
-
[rmkStr, rmkList] = __classPrivateFieldGet(this, _RemarkParser_supplier, "f").defaultCommand.execute(rmkStr, rmkList);
|
|
470
|
-
}
|
|
471
|
-
else {
|
|
472
|
-
throw e;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
return rmkList;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
exports.RemarkParser = RemarkParser;
|
|
480
|
-
_RemarkParser_supplier = new WeakMap();
|