metar-taf-parser 0.0.1 → 0.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.
Files changed (57) hide show
  1. package/README.md +8 -2
  2. package/dist/{lib/command → command}/common.d.ts +1 -1
  3. package/dist/{lib/command → command}/common.js +4 -4
  4. package/dist/{lib/command → command}/metar.d.ts +5 -1
  5. package/dist/{lib/command → command}/metar.js +6 -5
  6. package/dist/{lib/command → command}/remark.d.ts +5 -1
  7. package/dist/{lib/command → command}/remark.js +130 -148
  8. package/dist/{lib/commons → commons}/converter.d.ts +0 -0
  9. package/dist/{lib/commons → commons}/converter.js +2 -2
  10. package/dist/{lib/commons → commons}/errors.d.ts +7 -2
  11. package/dist/{lib/commons → commons}/errors.js +8 -3
  12. package/dist/commons/i18n.d.ts +12 -0
  13. package/dist/{lib/commons → commons}/i18n.js +12 -4
  14. package/dist/{lib/helpers → helpers}/helpers.d.ts +0 -1
  15. package/dist/helpers/helpers.js +23 -0
  16. package/dist/index.d.ts +10 -0
  17. package/dist/index.js +38 -0
  18. package/dist/locale/de.d.ts +321 -0
  19. package/dist/locale/de.js +322 -0
  20. package/dist/locale/en.d.ts +387 -0
  21. package/dist/locale/en.js +398 -0
  22. package/dist/locale/fr.d.ts +365 -0
  23. package/dist/locale/fr.js +376 -0
  24. package/dist/locale/it.d.ts +337 -0
  25. package/dist/locale/it.js +338 -0
  26. package/dist/locale/pl.d.ts +98 -0
  27. package/dist/locale/pl.js +99 -0
  28. package/dist/locale/zh-CN.d.ts +111 -0
  29. package/dist/locale/zh-CN.js +112 -0
  30. package/dist/model/enum.d.ts +221 -0
  31. package/dist/model/enum.js +231 -0
  32. package/dist/{lib/model → model}/model.d.ts +14 -7
  33. package/dist/{lib/model → model}/model.js +1 -1
  34. package/dist/parser/parser.d.ts +66 -0
  35. package/dist/parser/parser.js +322 -0
  36. package/package.json +8 -3
  37. package/dist/lib/commons/i18n.d.ts +0 -3
  38. package/dist/lib/helpers/helpers.js +0 -28
  39. package/dist/lib/index.d.ts +0 -1
  40. package/dist/lib/index.js +0 -3
  41. package/dist/lib/locale/en.json +0 -396
  42. package/dist/lib/model/enum.d.ts +0 -122
  43. package/dist/lib/model/enum.js +0 -132
  44. package/dist/lib/parser/parser.d.ts +0 -26
  45. package/dist/lib/parser/parser.js +0 -198
  46. package/dist/tests/command/common.test.d.ts +0 -1
  47. package/dist/tests/command/common.test.js +0 -102
  48. package/dist/tests/command/metar.test.d.ts +0 -1
  49. package/dist/tests/command/metar.test.js +0 -52
  50. package/dist/tests/command/remark.test.d.ts +0 -1
  51. package/dist/tests/command/remark.test.js +0 -689
  52. package/dist/tests/common/converter.test.d.ts +0 -1
  53. package/dist/tests/common/converter.test.js +0 -78
  54. package/dist/tests/helpers/helpers.test.d.ts +0 -1
  55. package/dist/tests/helpers/helpers.test.js +0 -17
  56. package/dist/tests/parser/parser.test.d.ts +0 -1
  57. package/dist/tests/parser/parser.test.js +0 -96
@@ -4,20 +4,24 @@ exports.UnexpectedParseError = exports.TranslationError = exports.InvalidWeather
4
4
  class ParseError extends Error {
5
5
  constructor(message) {
6
6
  super(message);
7
+ this.name = "ParseError";
7
8
  Object.setPrototypeOf(this, new.target.prototype);
8
9
  }
9
10
  }
10
11
  exports.ParseError = ParseError;
11
12
  class InvalidWeatherStatementError extends ParseError {
12
- constructor(missing) {
13
- super(`Invalid weather string. Missing: ${missing}`);
13
+ constructor(cause) {
14
+ super(`Invalid weather string.`);
15
+ this.name = "InvalidWeatherStatementError";
14
16
  Object.setPrototypeOf(this, new.target.prototype);
17
+ this.cause = cause;
15
18
  }
16
19
  }
17
20
  exports.InvalidWeatherStatementError = InvalidWeatherStatementError;
18
21
  class TranslationError extends ParseError {
19
22
  constructor(missingLocale) {
20
- super(`Missing locale "${missingLocale}"`);
23
+ super(`Missing translation "${missingLocale}"`);
24
+ this.name = "TranslationError";
21
25
  Object.setPrototypeOf(this, new.target.prototype);
22
26
  }
23
27
  }
@@ -28,6 +32,7 @@ exports.TranslationError = TranslationError;
28
32
  class UnexpectedParseError extends ParseError {
29
33
  constructor(message) {
30
34
  super(message);
35
+ this.name = "UnexpectedParseError";
31
36
  Object.setPrototypeOf(this, new.target.prototype);
32
37
  }
33
38
  }
@@ -0,0 +1,12 @@
1
+ import en from "../locale/en";
2
+ export default en;
3
+ declare type DeepPartial<T> = T extends object ? {
4
+ [P in keyof T]?: DeepPartial<T[P]>;
5
+ } : T;
6
+ export declare type Locale = DeepPartial<typeof en>;
7
+ declare type PathsToStringProps<T> = T extends string ? [] : {
8
+ [K in Extract<keyof T, string>]: [K, ...PathsToStringProps<T[K]>];
9
+ }[Extract<keyof T, string>];
10
+ declare type Join<T extends string[], D extends string> = T extends [] ? never : T extends [infer F] ? F : T extends [infer F, ...infer R] ? F extends string ? `${F}${D}${Join<Extract<R, string[]>, D>}` : never : string;
11
+ export declare function _(path: Join<PathsToStringProps<typeof en>, ".">, lang: Locale): string;
12
+ export declare function format(message: string, ...args: unknown[]): string;
@@ -3,10 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.format = void 0;
7
- const en_json_1 = __importDefault(require("locale/en.json"));
8
- // TODO - add other language support. EN hardcoded for now.
9
- exports.default = en_json_1.default;
6
+ exports.format = exports._ = void 0;
7
+ const en_1 = __importDefault(require("../locale/en"));
8
+ const get_1 = __importDefault(require("lodash/get"));
9
+ const errors_1 = require("./errors");
10
+ exports.default = en_1.default;
11
+ function _(path, lang) {
12
+ const translation = (0, get_1.default)(lang, path);
13
+ if (!translation || typeof translation !== "string")
14
+ throw new errors_1.TranslationError(path);
15
+ return translation;
16
+ }
17
+ exports._ = _;
10
18
  function format(message, ...args) {
11
19
  return message.replace(/{\d+}/g, (match) => {
12
20
  const index = +match.slice(1, -1);
@@ -2,4 +2,3 @@
2
2
  * Split behaving similar to Python's implementation
3
3
  */
4
4
  export declare function pySplit(string: string, separator: string, n?: number): string[];
5
- export declare function findAll(regex: RegExp, str: string): string[];
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pySplit = void 0;
4
+ /**
5
+ * Split behaving similar to Python's implementation
6
+ */
7
+ function pySplit(string, separator, n) {
8
+ let split = string.split(separator);
9
+ // Note: Python implementation will automatically trim empty values if
10
+ // separator is undefined. Since this function is kinda meh, we'll just do it
11
+ // for any spaces (pretty close to their implementation, since a space is the
12
+ // default character to split on)
13
+ //
14
+ // https://docs.python.org/3/library/stdtypes.html?highlight=split#str.split
15
+ if (separator === " ")
16
+ split = split.filter((n) => n);
17
+ if (n == null || split.length <= n)
18
+ return split;
19
+ const out = split.slice(0, n);
20
+ out.push(split.slice(n).join(separator));
21
+ return out;
22
+ }
23
+ exports.pySplit = pySplit;
@@ -0,0 +1,10 @@
1
+ import { IMetar } from "./model/model";
2
+ import { Locale } from "./commons/i18n";
3
+ export interface IMetarTAFParserOptions {
4
+ locale?: Locale;
5
+ }
6
+ export declare function parseMetar(metar: string, options: IMetarTAFParserOptions): IMetar;
7
+ export { Locale } from "./commons/i18n";
8
+ export * from "./commons/errors";
9
+ export * from "./model/model";
10
+ export * from "./model/enum";
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.parseMetar = void 0;
21
+ const parser_1 = require("./parser/parser");
22
+ const errors_1 = require("./commons/errors");
23
+ const en_1 = __importDefault(require("./locale/en"));
24
+ function parseMetar(metar, options) {
25
+ const lang = (options === null || options === void 0 ? void 0 : options.locale) || en_1.default;
26
+ try {
27
+ return new parser_1.MetarParser(lang).parse(metar);
28
+ }
29
+ catch (e) {
30
+ if (e instanceof errors_1.ParseError)
31
+ throw e;
32
+ throw new errors_1.InvalidWeatherStatementError(e);
33
+ }
34
+ }
35
+ exports.parseMetar = parseMetar;
36
+ __exportStar(require("./commons/errors"), exports);
37
+ __exportStar(require("./model/model"), exports);
38
+ __exportStar(require("./model/enum"), exports);
@@ -0,0 +1,321 @@
1
+ declare const _default: {
2
+ CloudQuantity: {
3
+ BKN: string;
4
+ FEW: string;
5
+ NSC: string;
6
+ OVC: string;
7
+ SCT: string;
8
+ SKC: string;
9
+ };
10
+ CloudType: {
11
+ CC: string;
12
+ TCU: string;
13
+ };
14
+ DepositBrakingCapacity: {
15
+ NOT_REPORTED: string;
16
+ POOR: string;
17
+ MEDIUM_POOR: string;
18
+ MEDIUM: string;
19
+ MEDIUM_GOOD: string;
20
+ GOOD: string;
21
+ UNRELIABLE: string;
22
+ };
23
+ DepositCoverage: {
24
+ NOT_REPORTED: string;
25
+ LESS_10: string;
26
+ FROM_11_TO_25: string;
27
+ FROM_26_TO_50: string;
28
+ FROM_51_TO_100: string;
29
+ };
30
+ DepositThickness: {
31
+ NOT_REPORTED: string;
32
+ LESS_1_MM: string;
33
+ THICKNESS_40: string;
34
+ CLOSED: string;
35
+ };
36
+ DepositType: {
37
+ NOT_REPORTED: string;
38
+ CLEAR_DRY: string;
39
+ DAMP: string;
40
+ WET_WATER_PATCHES: string;
41
+ RIME_FROST_COVERED: string;
42
+ DRY_SNOW: string;
43
+ WET_SNOW: string;
44
+ ICE: string;
45
+ COMPACTED_SNOW: string;
46
+ FROZEN_RIDGES: string;
47
+ };
48
+ Descriptive: {
49
+ BC: string;
50
+ BL: string;
51
+ DR: string;
52
+ FZ: string;
53
+ MI: string;
54
+ PR: string;
55
+ SH: string;
56
+ TS: string;
57
+ };
58
+ Error: {
59
+ prefix: string;
60
+ };
61
+ ErrorCode: {
62
+ AirportNotFound: string;
63
+ InvalidMessage: string;
64
+ };
65
+ Indicator: {
66
+ M: string;
67
+ P: string;
68
+ };
69
+ Intensity: {
70
+ "-": string;
71
+ VC: string;
72
+ };
73
+ "intensity-plus": string;
74
+ Phenomenon: {
75
+ BR: string;
76
+ DS: string;
77
+ DU: string;
78
+ DZ: string;
79
+ FC: string;
80
+ FG: string;
81
+ FU: string;
82
+ GR: string;
83
+ GS: string;
84
+ HZ: string;
85
+ IC: string;
86
+ PL: string;
87
+ PO: string;
88
+ PY: string;
89
+ RA: string;
90
+ SA: string;
91
+ SG: string;
92
+ SN: string;
93
+ SQ: string;
94
+ SS: string;
95
+ UP: string;
96
+ VA: string;
97
+ TS: string;
98
+ };
99
+ Remark: {
100
+ AO1: string;
101
+ AO2: string;
102
+ BASED: string;
103
+ Ceiling: {
104
+ Height: string;
105
+ Second: {
106
+ Location: string;
107
+ };
108
+ };
109
+ FCST: string;
110
+ FUNNELCLOUD: string;
111
+ Hail: {
112
+ "0": string;
113
+ LesserThan: string;
114
+ };
115
+ HVY: string;
116
+ LGT: string;
117
+ MOD: string;
118
+ Obscuration: string;
119
+ ON: string;
120
+ NXT: string;
121
+ PeakWind: string;
122
+ Precipitation: {
123
+ Beg: {
124
+ End: string;
125
+ };
126
+ };
127
+ PRESFR: string;
128
+ PRESRR: string;
129
+ Second: {
130
+ Location: {
131
+ Visibility: string;
132
+ };
133
+ };
134
+ Sea: {
135
+ Level: {
136
+ Pressure: string;
137
+ };
138
+ };
139
+ Sector: {
140
+ Visibility: string;
141
+ };
142
+ SLPNO: string;
143
+ Snow: {
144
+ Increasing: {
145
+ Rapidly: string;
146
+ };
147
+ Pellets: string;
148
+ };
149
+ Surface: {
150
+ Visibility: string;
151
+ };
152
+ Thunderstorm: {
153
+ Location: {
154
+ "0": string;
155
+ Moving: string;
156
+ };
157
+ };
158
+ Tornadic: {
159
+ Activity: {
160
+ Beginning: string;
161
+ BegEnd: string;
162
+ Ending: string;
163
+ };
164
+ };
165
+ TORNADO: string;
166
+ Tower: {
167
+ Visibility: string;
168
+ };
169
+ Variable: {
170
+ Prevailing: {
171
+ Visibility: string;
172
+ };
173
+ Sky: {
174
+ Condition: {
175
+ "0": string;
176
+ Height: string;
177
+ };
178
+ };
179
+ };
180
+ VIRGA: string;
181
+ Virga: {
182
+ Direction: string;
183
+ };
184
+ WATERSPOUT: string;
185
+ WindShift: {
186
+ "0": string;
187
+ FROPA: string;
188
+ };
189
+ };
190
+ MetarFacade: {
191
+ InvalidIcao: string;
192
+ };
193
+ Converter: {
194
+ D: string;
195
+ E: string;
196
+ ENE: string;
197
+ ESE: string;
198
+ N: string;
199
+ NE: string;
200
+ NNE: string;
201
+ NNW: string;
202
+ NSC: string;
203
+ NW: string;
204
+ S: string;
205
+ SE: string;
206
+ SSE: string;
207
+ SSW: string;
208
+ SW: string;
209
+ U: string;
210
+ VRB: string;
211
+ WNW: string;
212
+ WSW: string;
213
+ };
214
+ WeatherChangeType: {
215
+ FM: string;
216
+ BECMG: string;
217
+ TEMPO: string;
218
+ PROB: string;
219
+ };
220
+ TimeIndicator: {
221
+ AT: string;
222
+ FM: string;
223
+ TL: string;
224
+ };
225
+ ToString: {
226
+ airport: string;
227
+ altimeter: string;
228
+ amendment: string;
229
+ auto: string;
230
+ cavok: string;
231
+ clouds: string;
232
+ day: {
233
+ month: string;
234
+ hour: string;
235
+ };
236
+ deposit: {
237
+ braking: string;
238
+ coverage: string;
239
+ thickness: string;
240
+ type: string;
241
+ };
242
+ descriptive: string;
243
+ dew: {
244
+ point: string;
245
+ };
246
+ end: {
247
+ day: {
248
+ month: string;
249
+ };
250
+ hour: {
251
+ day: string;
252
+ };
253
+ };
254
+ height: {
255
+ feet: string;
256
+ meter: string;
257
+ };
258
+ intensity: string;
259
+ indicator: string;
260
+ message: string;
261
+ name: string;
262
+ nosig: string;
263
+ phenomenons: string;
264
+ probability: string;
265
+ quantity: string;
266
+ remark: string;
267
+ report: {
268
+ time: string;
269
+ };
270
+ runway: {
271
+ info: string;
272
+ };
273
+ start: {
274
+ day: {
275
+ month: string;
276
+ };
277
+ hour: {
278
+ day: string;
279
+ };
280
+ minute: string;
281
+ };
282
+ temperature: {
283
+ "0": string;
284
+ max: string;
285
+ min: string;
286
+ };
287
+ trend: string;
288
+ trends: string;
289
+ type: string;
290
+ visibility: {
291
+ main: string;
292
+ min: {
293
+ "0": string;
294
+ direction: string;
295
+ };
296
+ max: string;
297
+ };
298
+ vertical: {
299
+ visibility: string;
300
+ };
301
+ weather: {
302
+ conditions: string;
303
+ };
304
+ wind: {
305
+ direction: {
306
+ "0": string;
307
+ degrees: string;
308
+ };
309
+ gusts: string;
310
+ min: {
311
+ variation: string;
312
+ };
313
+ max: {
314
+ variation: string;
315
+ };
316
+ speed: string;
317
+ unit: string;
318
+ };
319
+ };
320
+ };
321
+ export default _default;