metar-taf-parser 0.0.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.
- package/LICENSE +21 -0
- package/README.md +48 -0
- package/dist/lib/command/common.d.ts +54 -0
- package/dist/lib/command/common.js +239 -0
- package/dist/lib/command/metar.d.ts +26 -0
- package/dist/lib/command/metar.js +134 -0
- package/dist/lib/command/remark.d.ts +199 -0
- package/dist/lib/command/remark.js +789 -0
- package/dist/lib/commons/converter.d.ts +6 -0
- package/dist/lib/commons/converter.js +57 -0
- package/dist/lib/commons/errors.d.ts +15 -0
- package/dist/lib/commons/errors.js +34 -0
- package/dist/lib/commons/i18n.d.ts +3 -0
- package/dist/lib/commons/i18n.js +16 -0
- package/dist/lib/helpers/helpers.d.ts +5 -0
- package/dist/lib/helpers/helpers.js +28 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +3 -0
- package/dist/lib/locale/en.json +396 -0
- package/dist/lib/model/enum.d.ts +122 -0
- package/dist/lib/model/enum.js +132 -0
- package/dist/lib/model/model.d.ts +114 -0
- package/dist/lib/model/model.js +9 -0
- package/dist/lib/parser/parser.d.ts +26 -0
- package/dist/lib/parser/parser.js +198 -0
- package/dist/tests/command/common.test.d.ts +1 -0
- package/dist/tests/command/common.test.js +102 -0
- package/dist/tests/command/metar.test.d.ts +1 -0
- package/dist/tests/command/metar.test.js +52 -0
- package/dist/tests/command/remark.test.d.ts +1 -0
- package/dist/tests/command/remark.test.js +689 -0
- package/dist/tests/common/converter.test.d.ts +1 -0
- package/dist/tests/common/converter.test.js +78 -0
- package/dist/tests/helpers/helpers.test.d.ts +1 -0
- package/dist/tests/helpers/helpers.test.js +17 -0
- package/dist/tests/parser/parser.test.d.ts +1 -0
- package/dist/tests/parser/parser.test.js +96 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Alexander Harding
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# metar-taf-parser
|
|
2
|
+
|
|
3
|
+
This is a port of [python-metar-taf-parser](https://github.com/mivek/python-metar-taf-parser) to typescript. It's fully typed and tested with i18n support, and can run on Node or the browser.
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
⚠️ This project is an active work in progress. These examples do not currently work.
|
|
8
|
+
|
|
9
|
+
### Parse METAR
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { parseMetar } from 'metar-taf-parser'
|
|
13
|
+
|
|
14
|
+
// Get the raw METAR/TAF strings in your preferred way
|
|
15
|
+
// For example: https://www.aviationweather.gov/dataserver
|
|
16
|
+
const { metar } = await myService.getAirportData('KMSN')
|
|
17
|
+
|
|
18
|
+
// Readily serializable
|
|
19
|
+
const metarResult = parseMetar(metar)
|
|
20
|
+
|
|
21
|
+
// Your code here 🚀
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Parse TAF
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { parseTAF } from 'metar-taf-parser'
|
|
28
|
+
|
|
29
|
+
// Get the raw METAR/TAF strings in your preferred way
|
|
30
|
+
// For example: https://www.aviationweather.gov/dataserver
|
|
31
|
+
const { taf } = await myService.getAirportData('KMSN')
|
|
32
|
+
|
|
33
|
+
// Readily serializable
|
|
34
|
+
const tafResult = parseTAF(taf)
|
|
35
|
+
|
|
36
|
+
// Your code here 🚀
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### i18n
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { parseMetar } from 'metar-taf-parser'
|
|
43
|
+
import de from 'metar-taf-parser/locale/de'
|
|
44
|
+
|
|
45
|
+
const { metar } = await myService.getAirportData('KMSN')
|
|
46
|
+
|
|
47
|
+
const metarResult = parseMetar(metar, { locale: de })
|
|
48
|
+
```
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { IAbstractWeatherContainer, ICloud, IWind, IWindShear } from "model/model";
|
|
2
|
+
interface ICommand {
|
|
3
|
+
canParse(str: string): boolean;
|
|
4
|
+
execute(container: IAbstractWeatherContainer, str: string): boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class CloudCommand implements ICommand {
|
|
7
|
+
#private;
|
|
8
|
+
parse(cloudString: string): ICloud | undefined;
|
|
9
|
+
execute(container: IAbstractWeatherContainer, cloudString: string): boolean;
|
|
10
|
+
canParse(cloudString: string): boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class MainVisibilityCommand implements ICommand {
|
|
13
|
+
#private;
|
|
14
|
+
canParse(visibilityString: string): boolean;
|
|
15
|
+
execute(container: IAbstractWeatherContainer, visibilityString: string): boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare class WindCommand implements ICommand {
|
|
18
|
+
#private;
|
|
19
|
+
canParse(windString: string): boolean;
|
|
20
|
+
parseWind(windString: string): IWind;
|
|
21
|
+
execute(container: IAbstractWeatherContainer, windString: string): boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare class WindVariationCommand implements ICommand {
|
|
24
|
+
#private;
|
|
25
|
+
canParse(windString: string): boolean;
|
|
26
|
+
parseWindVariation(wind: IWind, windString: string): void;
|
|
27
|
+
execute(container: IAbstractWeatherContainer, windString: string): boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare class WindShearCommand implements ICommand {
|
|
30
|
+
#private;
|
|
31
|
+
canParse(windString: string): boolean;
|
|
32
|
+
parseWindShear(windString: string): IWindShear;
|
|
33
|
+
execute(container: IAbstractWeatherContainer, windString: string): boolean;
|
|
34
|
+
}
|
|
35
|
+
export declare class VerticalVisibilityCommand implements ICommand {
|
|
36
|
+
#private;
|
|
37
|
+
execute(container: IAbstractWeatherContainer, visibilityString: string): boolean;
|
|
38
|
+
canParse(windString: string): boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare class MinimalVisibilityCommand implements ICommand {
|
|
41
|
+
#private;
|
|
42
|
+
execute(container: IAbstractWeatherContainer, visibilityString: string): boolean;
|
|
43
|
+
canParse(windString: string): boolean;
|
|
44
|
+
}
|
|
45
|
+
export declare class MainVisibilityNauticalMilesCommand implements ICommand {
|
|
46
|
+
#private;
|
|
47
|
+
execute(container: IAbstractWeatherContainer, visibilityString: string): boolean;
|
|
48
|
+
canParse(windString: string): boolean;
|
|
49
|
+
}
|
|
50
|
+
export declare class CommandSupplier {
|
|
51
|
+
#private;
|
|
52
|
+
get(input: string): ICommand | undefined;
|
|
53
|
+
}
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,239 @@
|
|
|
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 _CloudCommand_cloudRegex, _MainVisibilityCommand_regex, _WindCommand_regex, _WindVariationCommand_regex, _WindShearCommand_regex, _VerticalVisibilityCommand_regex, _MinimalVisibilityCommand_regex, _MainVisibilityNauticalMilesCommand_regex, _CommandSupplier_commands;
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.CommandSupplier = exports.MainVisibilityNauticalMilesCommand = exports.MinimalVisibilityCommand = exports.VerticalVisibilityCommand = exports.WindShearCommand = exports.WindVariationCommand = exports.WindCommand = exports.MainVisibilityCommand = exports.CloudCommand = void 0;
|
|
33
|
+
const converter = __importStar(require("commons/converter"));
|
|
34
|
+
const enum_1 = require("model/enum");
|
|
35
|
+
const errors_1 = require("commons/errors");
|
|
36
|
+
/**
|
|
37
|
+
* This function creates a wind element.
|
|
38
|
+
* @param wind The wind object
|
|
39
|
+
* @param direction The direction in degrees
|
|
40
|
+
* @param speed The speed
|
|
41
|
+
* @param gust The speed of the gust.
|
|
42
|
+
* @param unit The speed unit
|
|
43
|
+
*/
|
|
44
|
+
function makeWind(direction, speed, gust, unit) {
|
|
45
|
+
return {
|
|
46
|
+
speed: +speed,
|
|
47
|
+
direction: converter.degreesToCardinal(direction),
|
|
48
|
+
degrees: direction !== "VRB" ? +direction : undefined,
|
|
49
|
+
gust: gust ? +gust : undefined,
|
|
50
|
+
unit: unit || "KT",
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
class CloudCommand {
|
|
54
|
+
constructor() {
|
|
55
|
+
_CloudCommand_cloudRegex.set(this, /^([A-Z]{3})(\d{3})?([A-Z]{2,3})?$/);
|
|
56
|
+
}
|
|
57
|
+
parse(cloudString) {
|
|
58
|
+
const m = cloudString.match(__classPrivateFieldGet(this, _CloudCommand_cloudRegex, "f"));
|
|
59
|
+
if (!m)
|
|
60
|
+
return;
|
|
61
|
+
const quantity = enum_1.CloudQuantity[m[1]];
|
|
62
|
+
const height = 100 * +m[2] || undefined;
|
|
63
|
+
const type = enum_1.CloudType[m[3]];
|
|
64
|
+
if (!quantity)
|
|
65
|
+
return;
|
|
66
|
+
return { quantity, height, type };
|
|
67
|
+
}
|
|
68
|
+
execute(container, cloudString) {
|
|
69
|
+
const cloud = this.parse(cloudString);
|
|
70
|
+
if (cloud) {
|
|
71
|
+
container.clouds.push(cloud);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
canParse(cloudString) {
|
|
77
|
+
return __classPrivateFieldGet(this, _CloudCommand_cloudRegex, "f").test(cloudString);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.CloudCommand = CloudCommand;
|
|
81
|
+
_CloudCommand_cloudRegex = new WeakMap();
|
|
82
|
+
class MainVisibilityCommand {
|
|
83
|
+
constructor() {
|
|
84
|
+
_MainVisibilityCommand_regex.set(this, /^(\d{4})(|NDV)$/);
|
|
85
|
+
}
|
|
86
|
+
canParse(visibilityString) {
|
|
87
|
+
return __classPrivateFieldGet(this, _MainVisibilityCommand_regex, "f").test(visibilityString);
|
|
88
|
+
}
|
|
89
|
+
execute(container, visibilityString) {
|
|
90
|
+
const matches = visibilityString.match(__classPrivateFieldGet(this, _MainVisibilityCommand_regex, "f"));
|
|
91
|
+
if (!matches)
|
|
92
|
+
return false;
|
|
93
|
+
const distance = converter.convertVisibility(matches[1]);
|
|
94
|
+
if (!container.visibility)
|
|
95
|
+
container.visibility = { distance };
|
|
96
|
+
container.visibility.distance = distance;
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.MainVisibilityCommand = MainVisibilityCommand;
|
|
101
|
+
_MainVisibilityCommand_regex = new WeakMap();
|
|
102
|
+
class WindCommand {
|
|
103
|
+
constructor() {
|
|
104
|
+
_WindCommand_regex.set(this, /^(VRB|\d{3})(\d{2})G?(\d{2})?(KT|MPS|KM\/H)?/);
|
|
105
|
+
}
|
|
106
|
+
canParse(windString) {
|
|
107
|
+
return __classPrivateFieldGet(this, _WindCommand_regex, "f").test(windString);
|
|
108
|
+
}
|
|
109
|
+
parseWind(windString) {
|
|
110
|
+
const matches = windString.match(__classPrivateFieldGet(this, _WindCommand_regex, "f"));
|
|
111
|
+
if (!matches)
|
|
112
|
+
throw new errors_1.UnexpectedParseError("Wind should be defined");
|
|
113
|
+
return makeWind(matches[1], matches[2], matches[3], matches[5]);
|
|
114
|
+
}
|
|
115
|
+
execute(container, windString) {
|
|
116
|
+
const wind = this.parseWind(windString);
|
|
117
|
+
container.wind = wind;
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.WindCommand = WindCommand;
|
|
122
|
+
_WindCommand_regex = new WeakMap();
|
|
123
|
+
class WindVariationCommand {
|
|
124
|
+
constructor() {
|
|
125
|
+
_WindVariationCommand_regex.set(this, /^(\d{3})V(\d{3})/);
|
|
126
|
+
}
|
|
127
|
+
canParse(windString) {
|
|
128
|
+
return __classPrivateFieldGet(this, _WindVariationCommand_regex, "f").test(windString);
|
|
129
|
+
}
|
|
130
|
+
parseWindVariation(wind, windString) {
|
|
131
|
+
const matches = windString.match(__classPrivateFieldGet(this, _WindVariationCommand_regex, "f"));
|
|
132
|
+
if (!matches)
|
|
133
|
+
throw new errors_1.UnexpectedParseError("Wind should be defined");
|
|
134
|
+
wind.minVariation = +matches[1];
|
|
135
|
+
wind.maxVariation = +matches[2];
|
|
136
|
+
}
|
|
137
|
+
execute(container, windString) {
|
|
138
|
+
this.parseWindVariation(container.wind, windString);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.WindVariationCommand = WindVariationCommand;
|
|
143
|
+
_WindVariationCommand_regex = new WeakMap();
|
|
144
|
+
class WindShearCommand {
|
|
145
|
+
constructor() {
|
|
146
|
+
_WindShearCommand_regex.set(this, /^WS(\d{3})\/(\w{3})(\d{2})G?(\d{2})?(KT|MPS|KM\/H)/);
|
|
147
|
+
}
|
|
148
|
+
canParse(windString) {
|
|
149
|
+
return __classPrivateFieldGet(this, _WindShearCommand_regex, "f").test(windString);
|
|
150
|
+
}
|
|
151
|
+
parseWindShear(windString) {
|
|
152
|
+
const matches = windString.match(__classPrivateFieldGet(this, _WindShearCommand_regex, "f"));
|
|
153
|
+
if (!matches)
|
|
154
|
+
throw new errors_1.UnexpectedParseError("Wind shear should be defined");
|
|
155
|
+
return Object.assign(Object.assign({}, makeWind(matches[2], matches[3], matches[4], matches[5])), { height: 100 * +matches[1] });
|
|
156
|
+
}
|
|
157
|
+
execute(container, windString) {
|
|
158
|
+
container.windShear = this.parseWindShear(windString);
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.WindShearCommand = WindShearCommand;
|
|
163
|
+
_WindShearCommand_regex = new WeakMap();
|
|
164
|
+
class VerticalVisibilityCommand {
|
|
165
|
+
constructor() {
|
|
166
|
+
_VerticalVisibilityCommand_regex.set(this, /^VV(\d{3})$/);
|
|
167
|
+
}
|
|
168
|
+
execute(container, visibilityString) {
|
|
169
|
+
const matches = visibilityString.match(__classPrivateFieldGet(this, _VerticalVisibilityCommand_regex, "f"));
|
|
170
|
+
if (!matches)
|
|
171
|
+
throw new errors_1.UnexpectedParseError("Vertical visibility should be defined");
|
|
172
|
+
container.verticalVisibility = 100 * +matches[1];
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
canParse(windString) {
|
|
176
|
+
return __classPrivateFieldGet(this, _VerticalVisibilityCommand_regex, "f").test(windString);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.VerticalVisibilityCommand = VerticalVisibilityCommand;
|
|
180
|
+
_VerticalVisibilityCommand_regex = new WeakMap();
|
|
181
|
+
class MinimalVisibilityCommand {
|
|
182
|
+
constructor() {
|
|
183
|
+
_MinimalVisibilityCommand_regex.set(this, /^(\d{4}[a-z])$/);
|
|
184
|
+
}
|
|
185
|
+
execute(container, visibilityString) {
|
|
186
|
+
const matches = visibilityString.match(__classPrivateFieldGet(this, _MinimalVisibilityCommand_regex, "f"));
|
|
187
|
+
if (!matches)
|
|
188
|
+
throw new errors_1.UnexpectedParseError("Vertical visibility should be defined");
|
|
189
|
+
if (!container.visibility)
|
|
190
|
+
throw new errors_1.UnexpectedParseError("container.visibility not instantiated");
|
|
191
|
+
container.visibility.minDistance = +matches[1].slice(0, 4);
|
|
192
|
+
container.visibility.minDirection = matches[1][4];
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
canParse(windString) {
|
|
196
|
+
return __classPrivateFieldGet(this, _MinimalVisibilityCommand_regex, "f").test(windString);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
exports.MinimalVisibilityCommand = MinimalVisibilityCommand;
|
|
200
|
+
_MinimalVisibilityCommand_regex = new WeakMap();
|
|
201
|
+
class MainVisibilityNauticalMilesCommand {
|
|
202
|
+
constructor() {
|
|
203
|
+
_MainVisibilityNauticalMilesCommand_regex.set(this, /^(\d)*(\s)?((\d\/\d)?SM)$/);
|
|
204
|
+
}
|
|
205
|
+
execute(container, visibilityString) {
|
|
206
|
+
if (!container.visibility)
|
|
207
|
+
container.visibility = { distance: visibilityString };
|
|
208
|
+
container.visibility.distance = visibilityString;
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
canParse(windString) {
|
|
212
|
+
return __classPrivateFieldGet(this, _MainVisibilityNauticalMilesCommand_regex, "f").test(windString);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.MainVisibilityNauticalMilesCommand = MainVisibilityNauticalMilesCommand;
|
|
216
|
+
_MainVisibilityNauticalMilesCommand_regex = new WeakMap();
|
|
217
|
+
class CommandSupplier {
|
|
218
|
+
constructor() {
|
|
219
|
+
_CommandSupplier_commands.set(this, [
|
|
220
|
+
new WindShearCommand(),
|
|
221
|
+
new WindCommand(),
|
|
222
|
+
new WindVariationCommand(),
|
|
223
|
+
new MainVisibilityCommand(),
|
|
224
|
+
new MainVisibilityNauticalMilesCommand(),
|
|
225
|
+
new MinimalVisibilityCommand(),
|
|
226
|
+
new VerticalVisibilityCommand(),
|
|
227
|
+
new CloudCommand(),
|
|
228
|
+
]);
|
|
229
|
+
}
|
|
230
|
+
get(input) {
|
|
231
|
+
for (let i = 0; i < __classPrivateFieldGet(this, _CommandSupplier_commands, "f").length; i++) {
|
|
232
|
+
const command = __classPrivateFieldGet(this, _CommandSupplier_commands, "f")[i];
|
|
233
|
+
if (command.canParse(input))
|
|
234
|
+
return command;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
exports.CommandSupplier = CommandSupplier;
|
|
239
|
+
_CommandSupplier_commands = new WeakMap();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IMetar } from "model/model";
|
|
2
|
+
interface ICommand {
|
|
3
|
+
canParse(str: string): boolean;
|
|
4
|
+
execute(metar: IMetar, str: string): void;
|
|
5
|
+
}
|
|
6
|
+
export declare class AltimeterCommand implements ICommand {
|
|
7
|
+
#private;
|
|
8
|
+
canParse(input: string): boolean;
|
|
9
|
+
execute(metar: IMetar, input: string): void;
|
|
10
|
+
}
|
|
11
|
+
export declare class AltimeterMercuryCommand implements ICommand {
|
|
12
|
+
#private;
|
|
13
|
+
canParse(input: string): boolean;
|
|
14
|
+
execute(metar: IMetar, input: string): void;
|
|
15
|
+
}
|
|
16
|
+
export declare class RunwayCommand implements ICommand {
|
|
17
|
+
#private;
|
|
18
|
+
canParse(input: string): boolean;
|
|
19
|
+
execute(metar: IMetar, input: string): void;
|
|
20
|
+
}
|
|
21
|
+
export declare class TemperatureCommand implements ICommand {
|
|
22
|
+
#private;
|
|
23
|
+
canParse(input: string): boolean;
|
|
24
|
+
execute(metar: IMetar, input: string): void;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
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 _AltimeterCommand_regex, _AltimeterMercuryCommand_regex, _RunwayCommand_genericRegex, _RunwayCommand_runwayMaxRangeRegex, _RunwayCommand_runwayRegex, _TemperatureCommand_regex, _CommandSupplier_commands;
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.TemperatureCommand = exports.RunwayCommand = exports.AltimeterMercuryCommand = exports.AltimeterCommand = void 0;
|
|
33
|
+
const converter = __importStar(require("commons/converter"));
|
|
34
|
+
const errors_1 = require("commons/errors");
|
|
35
|
+
class AltimeterCommand {
|
|
36
|
+
constructor() {
|
|
37
|
+
_AltimeterCommand_regex.set(this, /^Q(\d{4})$/);
|
|
38
|
+
}
|
|
39
|
+
canParse(input) {
|
|
40
|
+
return __classPrivateFieldGet(this, _AltimeterCommand_regex, "f").test(input);
|
|
41
|
+
}
|
|
42
|
+
execute(metar, input) {
|
|
43
|
+
const matches = input.match(__classPrivateFieldGet(this, _AltimeterCommand_regex, "f"));
|
|
44
|
+
if (!matches)
|
|
45
|
+
throw new errors_1.UnexpectedParseError("Match not found");
|
|
46
|
+
metar.altimeter = +matches[1];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.AltimeterCommand = AltimeterCommand;
|
|
50
|
+
_AltimeterCommand_regex = new WeakMap();
|
|
51
|
+
class AltimeterMercuryCommand {
|
|
52
|
+
constructor() {
|
|
53
|
+
_AltimeterMercuryCommand_regex.set(this, /^A(\d{4})$/);
|
|
54
|
+
}
|
|
55
|
+
canParse(input) {
|
|
56
|
+
return __classPrivateFieldGet(this, _AltimeterMercuryCommand_regex, "f").test(input);
|
|
57
|
+
}
|
|
58
|
+
execute(metar, input) {
|
|
59
|
+
const matches = input.match(__classPrivateFieldGet(this, _AltimeterMercuryCommand_regex, "f"));
|
|
60
|
+
if (!matches)
|
|
61
|
+
throw new errors_1.UnexpectedParseError("Match not found");
|
|
62
|
+
const mercury = +matches[1] / 100;
|
|
63
|
+
metar.altimeter = converter.convertInchesMercuryToPascal(mercury);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.AltimeterMercuryCommand = AltimeterMercuryCommand;
|
|
67
|
+
_AltimeterMercuryCommand_regex = new WeakMap();
|
|
68
|
+
class RunwayCommand {
|
|
69
|
+
constructor() {
|
|
70
|
+
_RunwayCommand_genericRegex.set(this, /^(R\d{2}\w?\/)/);
|
|
71
|
+
_RunwayCommand_runwayMaxRangeRegex.set(this, /^R(\d{2}\w?)\/(\d{4})V(\d{3})(\w{0,2})/);
|
|
72
|
+
_RunwayCommand_runwayRegex.set(this, /^R(\d{2}\w?)\/(\w)?(\d{4})(\w{0,2})$/);
|
|
73
|
+
}
|
|
74
|
+
canParse(input) {
|
|
75
|
+
return __classPrivateFieldGet(this, _RunwayCommand_genericRegex, "f").test(input);
|
|
76
|
+
}
|
|
77
|
+
execute(metar, input) {
|
|
78
|
+
const matches = input.match(__classPrivateFieldGet(this, _RunwayCommand_runwayRegex, "f"));
|
|
79
|
+
// TODO idk if this matches super well...
|
|
80
|
+
if (matches) {
|
|
81
|
+
metar.runwaysInfo.push({
|
|
82
|
+
name: matches[1],
|
|
83
|
+
minRange: +matches[3],
|
|
84
|
+
trend: matches[4],
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const maxRangeMatches = input.match(__classPrivateFieldGet(this, _RunwayCommand_runwayMaxRangeRegex, "f"));
|
|
88
|
+
if (maxRangeMatches) {
|
|
89
|
+
metar.runwaysInfo.push({
|
|
90
|
+
name: maxRangeMatches[1],
|
|
91
|
+
minRange: +maxRangeMatches[2],
|
|
92
|
+
maxRange: +maxRangeMatches[3],
|
|
93
|
+
trend: maxRangeMatches[4],
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.RunwayCommand = RunwayCommand;
|
|
99
|
+
_RunwayCommand_genericRegex = new WeakMap(), _RunwayCommand_runwayMaxRangeRegex = new WeakMap(), _RunwayCommand_runwayRegex = new WeakMap();
|
|
100
|
+
class TemperatureCommand {
|
|
101
|
+
constructor() {
|
|
102
|
+
_TemperatureCommand_regex.set(this, /^(M?\d{2})\/(M?\d{2})$/);
|
|
103
|
+
}
|
|
104
|
+
canParse(input) {
|
|
105
|
+
return __classPrivateFieldGet(this, _TemperatureCommand_regex, "f").test(input);
|
|
106
|
+
}
|
|
107
|
+
execute(metar, input) {
|
|
108
|
+
const matches = input.match(__classPrivateFieldGet(this, _TemperatureCommand_regex, "f"));
|
|
109
|
+
if (!matches)
|
|
110
|
+
throw new errors_1.UnexpectedParseError("Match not found");
|
|
111
|
+
metar.temperature = converter.convertTemperature(matches[1]);
|
|
112
|
+
metar.dewPoint = converter.convertTemperature(matches[2]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.TemperatureCommand = TemperatureCommand;
|
|
116
|
+
_TemperatureCommand_regex = new WeakMap();
|
|
117
|
+
class CommandSupplier {
|
|
118
|
+
constructor() {
|
|
119
|
+
_CommandSupplier_commands.set(this, [
|
|
120
|
+
new RunwayCommand(),
|
|
121
|
+
new TemperatureCommand(),
|
|
122
|
+
new AltimeterCommand(),
|
|
123
|
+
new AltimeterMercuryCommand(),
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
126
|
+
get(input) {
|
|
127
|
+
for (let i = 0; i < __classPrivateFieldGet(this, _CommandSupplier_commands, "f").length; i++) {
|
|
128
|
+
const command = __classPrivateFieldGet(this, _CommandSupplier_commands, "f")[i];
|
|
129
|
+
if (command.canParse(input))
|
|
130
|
+
return command;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
_CommandSupplier_commands = new WeakMap();
|