metar-taf-parser 1.0.0 → 1.1.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/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,42 +1,36 @@
1
- # metar-taf-parser
1
+ # ✈️ [metar-taf-parser](https://aeharding.github.io/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 dependency-free, fully typed, tested, has i18n support, and can run on Node or the browser.
4
4
 
5
- ## Example
5
+ [Check out the demo here](https://aeharding.github.io/metar-taf-parser)
6
6
 
7
- ⚠️ This project is an active work in progress. These examples do not currently work.
7
+ ## Installation
8
8
 
9
- ### Parse METAR
9
+ ```sh
10
+ yarn add metar-taf-parser
11
+ # or
12
+ npm i --save metar-taf-parser
13
+ ```
10
14
 
11
- ```ts
12
- import { parseMetar } from 'metar-taf-parser'
15
+ ## Usage
13
16
 
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
+ ### Parse a METAR
17
18
 
18
- // Readily serializable
19
- const metarResult = parseMetar(metar)
19
+ ```ts
20
+ import { parseMetar } from 'metar-taf-parser'
20
21
 
21
- // Your code here 🚀
22
+ const metar = parseMetar(rawMetarString)
22
23
  ```
23
24
 
24
- ### Parse TAF
25
+ ### Parse a TAF
25
26
 
26
27
  ```ts
27
28
  import { parseTAF } from 'metar-taf-parser'
28
29
 
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 🚀
30
+ const taf = parseTAF(rawTAFString)
37
31
  ```
38
32
 
39
- ### i18n
33
+ ## i18n
40
34
 
41
35
  ```ts
42
36
  import { parseMetar } from 'metar-taf-parser'
@@ -51,4 +45,12 @@ const metarResult = parseMetar(metar, { locale: de })
51
45
 
52
46
  ### Example site
53
47
 
54
- Please see [the example site README.md](example/README.md).
48
+ Please see [the example site README.md](example/README.md).
49
+
50
+ ## Contributing
51
+
52
+ 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.
53
+
54
+ ## Acknowledgment
55
+
56
+ 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).
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.format = exports._ = void 0;
7
7
  const en_1 = __importDefault(require("../locale/en"));
8
- const get_1 = __importDefault(require("lodash/get"));
8
+ const helpers_1 = require("../helpers/helpers");
9
9
  const errors_1 = require("./errors");
10
10
  exports.default = en_1.default;
11
11
  function _(path, lang) {
12
- const translation = (0, get_1.default)(lang, path);
12
+ const translation = (0, helpers_1.resolve)(lang, path);
13
13
  if (!translation || typeof translation !== "string")
14
14
  throw new errors_1.TranslationError(path);
15
15
  return translation;
@@ -2,3 +2,9 @@
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
+ /**
6
+ * Access nested object properties by string path
7
+ *
8
+ * https://stackoverflow.com/a/22129960
9
+ */
10
+ export declare function resolve(obj: any, path: string | string[], separator?: string): unknown;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pySplit = void 0;
3
+ exports.resolve = exports.pySplit = void 0;
4
4
  /**
5
5
  * Split behaving similar to Python's implementation
6
6
  */
@@ -21,3 +21,13 @@ function pySplit(string, separator, n) {
21
21
  return out;
22
22
  }
23
23
  exports.pySplit = pySplit;
24
+ /**
25
+ * Access nested object properties by string path
26
+ *
27
+ * https://stackoverflow.com/a/22129960
28
+ */
29
+ function resolve(obj, path, separator = ".") {
30
+ const properties = Array.isArray(path) ? path : path.split(separator);
31
+ return properties.reduce((prev, curr) => prev === null || prev === void 0 ? void 0 : prev[curr], obj);
32
+ }
33
+ exports.resolve = resolve;
@@ -84,9 +84,9 @@ export interface IAbstractWeatherCode extends IAbstractWeatherContainer, ITime {
84
84
  trends: IAbstractTrend[];
85
85
  }
86
86
  export interface IMetar extends IAbstractWeatherCode {
87
- temperature: number;
88
- dewPoint: number;
89
- altimeter: number;
87
+ temperature?: number;
88
+ dewPoint?: number;
89
+ altimeter?: number;
90
90
  nosig: boolean;
91
91
  auto: boolean;
92
92
  runwaysInfo: IRunwayInfo[];
@@ -49,8 +49,6 @@ function parseDeliveryTime(timeString) {
49
49
  hour: +timeString.slice(2, 4),
50
50
  minute: +timeString.slice(4, 6),
51
51
  };
52
- // TODO
53
- // abstractWeatherCode.time = new Date()
54
52
  }
55
53
  /**
56
54
  * This function parses the array containing the remark and concat the array into a string
@@ -224,7 +222,6 @@ class MetarParser extends AbstractParser {
224
222
  trendParts[i].startsWith(this.AT)) {
225
223
  const trendTime = {
226
224
  type: enum_1.TimeIndicator[trendParts[i].slice(0, 2)],
227
- // TODO implement time
228
225
  hour: +trendParts[i].slice(2, 4),
229
226
  minute: +trendParts[i].slice(4, 6),
230
227
  };
@@ -244,18 +241,7 @@ class MetarParser extends AbstractParser {
244
241
  */
245
242
  parse(input) {
246
243
  const metarTab = this.tokenize(input);
247
- const metar = Object.assign(Object.assign({}, parseDeliveryTime(metarTab[1])), { station: metarTab[0], message: input,
248
- // wind: IWind,
249
- // visibility?: Visibility,
250
- // verticalVisibility: number,
251
- // windShear: IWindShear,
252
- cavok: false, remark: "", remarks: [], clouds: [], weatherConditions: [],
253
- // airport: IAirport,
254
- trends: [],
255
- // temperature: number,
256
- // dewPoint: number,
257
- // altimeter: number,
258
- nosig: false, auto: false, runwaysInfo: [] }); // TODO remove cast
244
+ const metar = Object.assign(Object.assign({}, parseDeliveryTime(metarTab[1])), { station: metarTab[0], message: input, cavok: false, remark: "", remarks: [], clouds: [], weatherConditions: [], trends: [], nosig: false, auto: false, runwaysInfo: [] });
259
245
  let index = 2;
260
246
  while (index < metarTab.length) {
261
247
  if (!super.generalParse(metar, metarTab[index])) {
@@ -272,8 +258,8 @@ class MetarParser extends AbstractParser {
272
258
  weatherConditions: [],
273
259
  clouds: [],
274
260
  times: [],
261
+ remarks: [],
275
262
  };
276
- // TODO - remove casting
277
263
  index = this.parseTrend(index, trend, metarTab);
278
264
  metar.trends.push(trend);
279
265
  }
package/package.json CHANGED
@@ -1,7 +1,16 @@
1
1
  {
2
2
  "name": "metar-taf-parser",
3
- "version": "1.0.0",
4
- "description": "Parse METAR and TAF files",
3
+ "version": "1.1.0",
4
+ "description": "Parse METAR and TAF reports",
5
+ "homepage": "https://aeharding.github.io/metar-taf-parser",
6
+ "keywords": [
7
+ "aviation",
8
+ "weather",
9
+ "metar",
10
+ "taf",
11
+ "report",
12
+ "deserialize"
13
+ ],
5
14
  "main": "./dist/index.js",
6
15
  "types": "./dist/index.d.ts",
7
16
  "author": "Alexander Harding <2166114+aeharding@users.noreply.github.com>",
@@ -16,7 +25,7 @@
16
25
  "start": "node --experimental-specifier-resolution=node --loader ts-node/esm lib",
17
26
  "check-types": "tsc --noEmit",
18
27
  "check-formatting": "prettier --check '**/*.{js,json,css,md,scss,tsx,ts}'",
19
- "watch": "watch 'yarn build' lib",
28
+ "watch": "watch 'yarn build' src",
20
29
  "test": "jest --coverage",
21
30
  "test-watch": "jest --watch --coverage",
22
31
  "prepublishOnly": "yarn build"
@@ -28,10 +37,7 @@
28
37
  "devDependencies": {
29
38
  "@babel/preset-env": "^7.16.11",
30
39
  "@babel/preset-typescript": "^7.16.7",
31
- "@types/fs-extra": "^9.0.12",
32
40
  "@types/jest": "^27.4.1",
33
- "@types/lodash": "^4.14.181",
34
- "fs-extra": "^10.0.0",
35
41
  "jest": "^27.5.1",
36
42
  "prettier": "^2.6.2",
37
43
  "ts-jest": "^27.1.4",
@@ -39,9 +45,5 @@
39
45
  "tsc-alias": "^1.6.6",
40
46
  "typescript": "^4.4.2",
41
47
  "watch": "^1.0.2"
42
- },
43
- "dependencies": {
44
- "lodash": "^4.17.21",
45
- "po2json": "^0.4.5"
46
48
  }
47
49
  }