metar-taf-parser 0.0.1 → 1.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.
Files changed (58) hide show
  1. package/LICENSE +2 -1
  2. package/README.md +19 -7
  3. package/dist/{lib/command → command}/common.d.ts +1 -1
  4. package/dist/{lib/command → command}/common.js +6 -4
  5. package/dist/{lib/command → command}/metar.d.ts +5 -1
  6. package/dist/{lib/command → command}/metar.js +6 -5
  7. package/dist/{lib/command → command}/remark.d.ts +5 -1
  8. package/dist/{lib/command → command}/remark.js +130 -148
  9. package/dist/{lib/commons → commons}/converter.d.ts +4 -1
  10. package/dist/{lib/commons → commons}/converter.js +7 -4
  11. package/dist/{lib/commons → commons}/errors.d.ts +7 -2
  12. package/dist/{lib/commons → commons}/errors.js +8 -3
  13. package/dist/commons/i18n.d.ts +12 -0
  14. package/dist/{lib/commons → commons}/i18n.js +12 -4
  15. package/dist/{lib/helpers → helpers}/helpers.d.ts +0 -1
  16. package/dist/helpers/helpers.js +23 -0
  17. package/dist/index.d.ts +11 -0
  18. package/dist/index.js +45 -0
  19. package/dist/locale/de.d.ts +321 -0
  20. package/dist/locale/de.js +322 -0
  21. package/dist/locale/en.d.ts +387 -0
  22. package/dist/locale/en.js +398 -0
  23. package/dist/locale/fr.d.ts +365 -0
  24. package/dist/locale/fr.js +376 -0
  25. package/dist/locale/it.d.ts +337 -0
  26. package/dist/locale/it.js +338 -0
  27. package/dist/locale/pl.d.ts +98 -0
  28. package/dist/locale/pl.js +99 -0
  29. package/dist/locale/zh-CN.d.ts +111 -0
  30. package/dist/locale/zh-CN.js +112 -0
  31. package/dist/model/enum.d.ts +221 -0
  32. package/dist/model/enum.js +231 -0
  33. package/dist/{lib/model → model}/model.d.ts +34 -25
  34. package/dist/{lib/model → model}/model.js +1 -1
  35. package/dist/parser/parser.d.ts +104 -0
  36. package/dist/parser/parser.js +446 -0
  37. package/package.json +10 -5
  38. package/dist/lib/commons/i18n.d.ts +0 -3
  39. package/dist/lib/helpers/helpers.js +0 -28
  40. package/dist/lib/index.d.ts +0 -1
  41. package/dist/lib/index.js +0 -3
  42. package/dist/lib/locale/en.json +0 -396
  43. package/dist/lib/model/enum.d.ts +0 -122
  44. package/dist/lib/model/enum.js +0 -132
  45. package/dist/lib/parser/parser.d.ts +0 -26
  46. package/dist/lib/parser/parser.js +0 -198
  47. package/dist/tests/command/common.test.d.ts +0 -1
  48. package/dist/tests/command/common.test.js +0 -102
  49. package/dist/tests/command/metar.test.d.ts +0 -1
  50. package/dist/tests/command/metar.test.js +0 -52
  51. package/dist/tests/command/remark.test.d.ts +0 -1
  52. package/dist/tests/command/remark.test.js +0 -689
  53. package/dist/tests/common/converter.test.d.ts +0 -1
  54. package/dist/tests/common/converter.test.js +0 -78
  55. package/dist/tests/helpers/helpers.test.d.ts +0 -1
  56. package/dist/tests/helpers/helpers.test.js +0 -17
  57. package/dist/tests/parser/parser.test.d.ts +0 -1
  58. package/dist/tests/parser/parser.test.js +0 -96
package/LICENSE CHANGED
@@ -1,6 +1,7 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Alexander Harding
3
+ Copyright (c) 2022 Alexander Harding
4
+ Copyright 2021 Jean-Kevin KPADEY
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,11 +1,9 @@
1
1
  # metar-taf-parser
2
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.
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
4
 
5
5
  ## Example
6
6
 
7
- ⚠️ This project is an active work in progress. These examples do not currently work.
8
-
9
7
  ### Parse METAR
10
8
 
11
9
  ```ts
@@ -13,7 +11,7 @@ import { parseMetar } from 'metar-taf-parser'
13
11
 
14
12
  // Get the raw METAR/TAF strings in your preferred way
15
13
  // For example: https://www.aviationweather.gov/dataserver
16
- const { metar } = await myService.getAirportData('KMSN')
14
+ // const { metar } = await myService.getAirportData('KMSN')
17
15
 
18
16
  // Readily serializable
19
17
  const metarResult = parseMetar(metar)
@@ -28,7 +26,7 @@ import { parseTAF } from 'metar-taf-parser'
28
26
 
29
27
  // Get the raw METAR/TAF strings in your preferred way
30
28
  // For example: https://www.aviationweather.gov/dataserver
31
- const { taf } = await myService.getAirportData('KMSN')
29
+ // const { taf } = await myService.getAirportData('KMSN')
32
30
 
33
31
  // Readily serializable
34
32
  const tafResult = parseTAF(taf)
@@ -40,9 +38,23 @@ const tafResult = parseTAF(taf)
40
38
 
41
39
  ```ts
42
40
  import { parseMetar } from 'metar-taf-parser'
43
- import de from 'metar-taf-parser/locale/de'
41
+ import de from 'metar-taf-parser/dist/locale/de'
44
42
 
45
43
  const { metar } = await myService.getAirportData('KMSN')
46
44
 
47
45
  const metarResult = parseMetar(metar, { locale: de })
48
- ```
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ This project is intended to provide feature parity with [python-metar-taf-parser](https://github.com/mivek/python-metar-taf-parser) and will only accept PRs to maintain feature parity or to fix inconsistencies with that project.
51
+
52
+ ## Development
53
+
54
+ ### Example site
55
+
56
+ Please see [the example site README.md](example/README.md).
57
+
58
+ ## Acknowledgment
59
+
60
+ This software port was made possible due to the fantastic work of [@mivek](https://github.com/mivek) in [python-metar-taf-parser](https://github.com/mivek/python-metar-taf-parser). If you like this project, please [consider buying @mivek a coffee](https://ko-fi.com/mivek).
@@ -1,4 +1,4 @@
1
- import { IAbstractWeatherContainer, ICloud, IWind, IWindShear } from "model/model";
1
+ import { IAbstractWeatherContainer, ICloud, IWind, IWindShear } from "../model/model";
2
2
  interface ICommand {
3
3
  canParse(str: string): boolean;
4
4
  execute(container: IAbstractWeatherContainer, str: string): boolean;
@@ -30,9 +30,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
30
30
  var _CloudCommand_cloudRegex, _MainVisibilityCommand_regex, _WindCommand_regex, _WindVariationCommand_regex, _WindShearCommand_regex, _VerticalVisibilityCommand_regex, _MinimalVisibilityCommand_regex, _MainVisibilityNauticalMilesCommand_regex, _CommandSupplier_commands;
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
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");
33
+ const converter = __importStar(require("../commons/converter"));
34
+ const enum_1 = require("../model/enum");
35
+ const errors_1 = require("../commons/errors");
36
36
  /**
37
37
  * This function creates a wind element.
38
38
  * @param wind The wind object
@@ -110,7 +110,7 @@ class WindCommand {
110
110
  const matches = windString.match(__classPrivateFieldGet(this, _WindCommand_regex, "f"));
111
111
  if (!matches)
112
112
  throw new errors_1.UnexpectedParseError("Wind should be defined");
113
- return makeWind(matches[1], matches[2], matches[3], matches[5]);
113
+ return makeWind(matches[1], matches[2], matches[3], matches[4]);
114
114
  }
115
115
  execute(container, windString) {
116
116
  const wind = this.parseWind(windString);
@@ -135,6 +135,8 @@ class WindVariationCommand {
135
135
  wind.maxVariation = +matches[2];
136
136
  }
137
137
  execute(container, windString) {
138
+ if (!container.wind)
139
+ throw new errors_1.InvalidWeatherStatementError();
138
140
  this.parseWindVariation(container.wind, windString);
139
141
  return true;
140
142
  }
@@ -1,4 +1,4 @@
1
- import { IMetar } from "model/model";
1
+ import { IMetar } from "../model/model";
2
2
  interface ICommand {
3
3
  canParse(str: string): boolean;
4
4
  execute(metar: IMetar, str: string): void;
@@ -23,4 +23,8 @@ export declare class TemperatureCommand implements ICommand {
23
23
  canParse(input: string): boolean;
24
24
  execute(metar: IMetar, input: string): void;
25
25
  }
26
+ export declare class CommandSupplier {
27
+ #private;
28
+ get(input: string): ICommand | undefined;
29
+ }
26
30
  export {};
@@ -29,9 +29,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
29
29
  };
30
30
  var _AltimeterCommand_regex, _AltimeterMercuryCommand_regex, _RunwayCommand_genericRegex, _RunwayCommand_runwayMaxRangeRegex, _RunwayCommand_runwayRegex, _TemperatureCommand_regex, _CommandSupplier_commands;
31
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");
32
+ exports.CommandSupplier = 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
35
  class AltimeterCommand {
36
36
  constructor() {
37
37
  _AltimeterCommand_regex.set(this, /^Q(\d{4})$/);
@@ -43,7 +43,7 @@ class AltimeterCommand {
43
43
  const matches = input.match(__classPrivateFieldGet(this, _AltimeterCommand_regex, "f"));
44
44
  if (!matches)
45
45
  throw new errors_1.UnexpectedParseError("Match not found");
46
- metar.altimeter = +matches[1];
46
+ metar.altimeter = Math.trunc(+matches[1]);
47
47
  }
48
48
  }
49
49
  exports.AltimeterCommand = AltimeterCommand;
@@ -60,7 +60,7 @@ class AltimeterMercuryCommand {
60
60
  if (!matches)
61
61
  throw new errors_1.UnexpectedParseError("Match not found");
62
62
  const mercury = +matches[1] / 100;
63
- metar.altimeter = converter.convertInchesMercuryToPascal(mercury);
63
+ metar.altimeter = Math.trunc(converter.convertInchesMercuryToPascal(mercury));
64
64
  }
65
65
  }
66
66
  exports.AltimeterMercuryCommand = AltimeterMercuryCommand;
@@ -131,4 +131,5 @@ class CommandSupplier {
131
131
  }
132
132
  }
133
133
  }
134
+ exports.CommandSupplier = CommandSupplier;
134
135
  _CommandSupplier_commands = new WeakMap();
@@ -1,4 +1,7 @@
1
+ import { Locale } from "../commons/i18n";
1
2
  export declare abstract class Command {
3
+ protected locale: Locale;
4
+ constructor(locale: Locale);
2
5
  abstract canParse(code: string): boolean;
3
6
  abstract execute(code: string, remark: string[]): [string, string[]];
4
7
  }
@@ -192,8 +195,9 @@ export declare class DefaultCommand extends Command {
192
195
  execute(code: string, remark: string[]): [string, string[]];
193
196
  }
194
197
  export declare class RemarkCommandSupplier {
198
+ private locale;
195
199
  defaultCommand: Command;
196
200
  commandList: Command[];
197
- constructor();
201
+ constructor(locale: Locale);
198
202
  get(code: string): Command;
199
203
  }