aewx-metar-parser 0.9.3 → 1.0.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/.eslintrc.js ADDED
@@ -0,0 +1,26 @@
1
+ module.exports = {
2
+ env: {
3
+ browser: true,
4
+ commonjs: true,
5
+ es2021: true
6
+ },
7
+ extends: [
8
+ 'standard'
9
+ ],
10
+ parserOptions: {
11
+ ecmaVersion: 'latest'
12
+ },
13
+ rules: {
14
+ semi: ['error', 'always']
15
+ },
16
+ overrides: [
17
+ {
18
+ files: [
19
+ "test/*.js"
20
+ ],
21
+ env: {
22
+ mocha: true
23
+ }
24
+ }
25
+ ]
26
+ }
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ npm test
package/CHANGELOG.md CHANGED
@@ -3,6 +3,15 @@ Change log
3
3
 
4
4
  For detailed information check [`metar-parser`'s releases on Github](https://github.com/fboes/metar-parser/releases).
5
5
 
6
+ * 💊 Fix METAR interpretation if wind is missing
7
+
8
+ 0.10.0
9
+ ------
10
+
11
+ * 💣 Changed object properties to closer match CheckWX properties. This changes `conditions`, `ceiling`, `visibility`
12
+ * 🎁 Add property `flight_category`
13
+ * 💊 If no visibility is given, assume 10 SM
14
+
6
15
  0.9.3
7
16
  -----
8
17
 
package/CONTRIBUTING.md CHANGED
@@ -16,11 +16,6 @@ You will need:
16
16
 
17
17
  1. A [Github account](https://github.com/) and Git
18
18
  2. [NodeJs](https://nodejs.org/) with NPM installed
19
- 3. [Gulp](https://gulpjs.com/) installed globally
20
- 4. [ESLint](https://eslint.org/) installed globally
21
- 5. [Nodeunit](https://github.com/caolan/nodeunit) installed globally
22
-
23
- For Gulp, ESLint and Nodeunit call `npm install -g gulp-cli eslint nodeunit` from command line.
24
19
 
25
20
  Making changes
26
21
  --------------
package/README.md CHANGED
@@ -62,10 +62,15 @@ const metarObject = metarParser('KSFO 070121Z 19023KT 1 1/2SM R28R/6000VP6000FT
62
62
  gust_mps: 11.832222176208026
63
63
  },
64
64
  visibility: {
65
- miles: 1.5,
66
- meters: 2414.016
65
+ miles: "1.5",
66
+ miles_float: 1.5,
67
+ meters: "2500",
68
+ meters_float: 2414.016
67
69
  },
68
- conditions: [ '-', 'RA' ],
70
+ conditions: [
71
+ { code: '-'},
72
+ { code: 'RA'}
73
+ ],
69
74
  clouds: [
70
75
  { code: 'BKN', base_feet_agl: 400, base_meters_agl: 121.92 },
71
76
  { code: 'BKN', base_feet_agl: 1300, base_meters_agl: 396.24 },
@@ -73,8 +78,8 @@ const metarObject = metarParser('KSFO 070121Z 19023KT 1 1/2SM R28R/6000VP6000FT
73
78
  ],
74
79
  ceiling: {
75
80
  code: 'OVC',
76
- base_feet_agl: 3500,
77
- base_meters_agl: 1066.8
81
+ feet_agl: 3500,
82
+ meters_agl: 1066.8
78
83
  },
79
84
  temperature: {
80
85
  celsius: 15,
@@ -89,7 +94,8 @@ const metarObject = metarParser('KSFO 070121Z 19023KT 1 1/2SM R28R/6000VP6000FT
89
94
  hg: 29.7,
90
95
  kpa: 100.57572661390854,
91
96
  mb: 1005.7572661390855
92
- }
97
+ },
98
+ flight_category: 'VFR'
93
99
  }
94
100
  ```
95
101
 
@@ -110,12 +116,11 @@ Status
110
116
  -------
111
117
 
112
118
  [![npm version](https://badge.fury.io/js/aewx-metar-parser.svg)](https://badge.fury.io/js/aewx-metar-parser)
113
- [![Build Status](https://travis-ci.org/fboes/metar-parser.svg?branch=master)](https://travis-ci.org/fboes/metar-parser)
114
119
  [![devDependency Status](https://david-dm.org/fboes/metar-parser/dev-status.svg)](https://david-dm.org/fboes/metar-parser?type=dev)
115
120
 
116
121
  Legal stuff
117
122
  -----------
118
123
 
119
- Author: [Frank Boës](http://3960.org)
124
+ Author: [Frank Boës](https://3960.org)
120
125
 
121
126
  Copyright & license: See [LICENSE.txt](LICENSE.txt)
package/lib/convert.js CHANGED
@@ -4,39 +4,39 @@
4
4
  * Convert units
5
5
  */
6
6
  const convert = {
7
- celsiusToFahrenheit: function(celsius) {
7
+ celsiusToFahrenheit: function (celsius) {
8
8
  return celsius * 1.8 + 32;
9
9
  },
10
10
 
11
- feetToMeters: function(feet) {
11
+ feetToMeters: function (feet) {
12
12
  return feet * 0.3048;
13
13
  },
14
14
 
15
- milesToMeters: function(miles) {
15
+ milesToMeters: function (miles) {
16
16
  return miles * 1609.344;
17
17
  },
18
18
 
19
- metersToMiles: function(meters) {
19
+ metersToMiles: function (meters) {
20
20
  return meters / 1609.344;
21
21
  },
22
22
 
23
- inhgToKpa: function(inHg) {
23
+ inhgToKpa: function (inHg) {
24
24
  return inHg / 0.29529988;
25
25
  },
26
26
 
27
- kpaToInhg: function(kpa) {
27
+ kpaToInhg: function (kpa) {
28
28
  return kpa * 0.29529988;
29
29
  },
30
30
 
31
- kphToMps: function(kph) {
31
+ kphToMps: function (kph) {
32
32
  return kph / 3600 * 1000;
33
33
  },
34
34
 
35
- mpsToKts: function(mps) {
35
+ mpsToKts: function (mps) {
36
36
  return mps * 1.9438445;
37
37
  },
38
38
 
39
- ktsToMps: function(kts) {
39
+ ktsToMps: function (kts) {
40
40
  return kts / 1.9438445;
41
41
  }
42
42
  };
@@ -10,13 +10,13 @@ const convert = require('./convert');
10
10
  * @returns {Object} with structured information. The object resembles the API
11
11
  * reponse of the data property of https://api.checkwx.com/#31-single
12
12
  */
13
- const metarParser = function(metarString) {
14
- let metarArray = metarString
13
+ const metarParser = function (metarString) {
14
+ const metarArray = metarString
15
15
  .trim()
16
16
  .replace(/^METAR\S*?\s/, '')
17
- .replace(/(\s)(\d)\s(\d)\/(\d)(SM)/, function(all, a, b, c, d, e) {
17
+ .replace(/(\s)(\d)\s(\d)\/(\d)(SM)/, function (all, a, b, c, d, e) {
18
18
  // convert visbility range like `1 1/2 SM`
19
- return a + (Number(b) * Number(d) + Number(c)) + '/' + d + e;
19
+ return a + (Number(b) * Number(d) + Number(c)) + '/' + d + e;
20
20
  })
21
21
  .split(' ')
22
22
  ;
@@ -24,10 +24,9 @@ const metarParser = function(metarString) {
24
24
  throw new Error('Not enough METAR information found');
25
25
  }
26
26
 
27
- let metarObject = {
27
+ const metarObject = {
28
28
  raw_text: metarString,
29
29
  raw_parts: metarArray
30
- //humidity_percent: null
31
30
  };
32
31
 
33
32
  const _private = {};
@@ -38,7 +37,7 @@ const metarParser = function(metarString) {
38
37
  * @param {Number} dew in celsius
39
38
  * @returns {Number} humidity in 1/100
40
39
  */
41
- _private.calcHumidity = function(temp, dew) {
40
+ _private.calcHumidity = function (temp, dew) {
42
41
  return Math.exp(
43
42
  (17.625 * dew) / (243.04 + dew)
44
43
  ) / Math.exp(
@@ -46,13 +45,27 @@ const metarParser = function(metarString) {
46
45
  );
47
46
  };
48
47
 
48
+ /**
49
+ * @param {Number} value dito
50
+ * @param {Number} toNext round to next full xxxx
51
+ * @returns {Number} rounded value
52
+ */
53
+ _private.round = function (value, toNext = 500) {
54
+ return Math.round(value / toNext) * toNext;
55
+ };
56
+
57
+ // ---------------------------------------------------------------------------
58
+
49
59
  let mode = 0;
50
60
  metarArray.forEach((metarPart) => {
51
61
  let match;
62
+ if (mode < 3 && metarPart.match(/^(\d+)(?:\/(\d+))?(SM)?$/)) {
63
+ mode = 3; // no wind reported
64
+ }
52
65
  if (mode < 5 && metarPart.match(/^(FEW|SCT|BKN|OVC)(\d+)?/)) {
53
66
  mode = 5; // no visibility / conditions reported
54
67
  }
55
- if (mode < 6 && metarPart.match(/^M?\d+\/M?\d+$/)) {
68
+ if (mode < 6 && metarPart.match(/(^M?\d+\/M?\d+$)|(^\/\/\/\/\/)/)) {
56
69
  mode = 6; // end of clouds
57
70
  }
58
71
  switch (mode) {
@@ -85,15 +98,15 @@ const metarParser = function(metarString) {
85
98
  }
86
99
 
87
100
  metarObject.wind = {
88
- degrees: (match[1] === 'VRB') ? 180 : Number(match[1]),
101
+ degrees: (match[1] === 'VRB') ? 180 : Number(match[1]),
89
102
  speed_kts: (match[4] === 'MPS') ? convert.mpsToKts(match[2]) : match[2],
90
103
  speed_mps: (match[4] === 'MPS') ? match[2] : convert.ktsToMps(match[2]),
91
- gust_kts: (match[4] === 'MPS') ? convert.mpsToKts(match[3]) : match[3],
92
- gust_mps: (match[4] === 'MPS') ? match[3] : convert.ktsToMps(match[3])
104
+ gust_kts: (match[4] === 'MPS') ? convert.mpsToKts(match[3]) : match[3],
105
+ gust_mps: (match[4] === 'MPS') ? match[3] : convert.ktsToMps(match[3])
93
106
  };
94
107
  if (match[1] === 'VRB') {
95
108
  metarObject.wind.degrees_from = 0;
96
- metarObject.wind.degrees_to = 359;
109
+ metarObject.wind.degrees_to = 359;
97
110
  }
98
111
  mode = 3;
99
112
  }
@@ -107,15 +120,19 @@ const metarParser = function(metarString) {
107
120
  : Number(match[1])
108
121
  ;
109
122
  metarObject.visibility = {
110
- miles: (match[3] && match[3] === 'SM') ? match[1] : convert.metersToMiles(match[1]),
111
- meters: (match[3] && match[3] === 'SM') ? convert.milesToMeters(match[1]) : match[1]
123
+ miles: (match[3] && match[3] === 'SM') ? match[1] : convert.metersToMiles(match[1]),
124
+ miles_float: (match[3] && match[3] === 'SM') ? match[1] : convert.metersToMiles(match[1]),
125
+ meters: (match[3] && match[3] === 'SM') ? convert.milesToMeters(match[1]) : match[1],
126
+ meters_float: (match[3] && match[3] === 'SM') ? convert.milesToMeters(match[1]) : match[1]
112
127
  };
113
128
 
114
129
  mode = 4;
115
- } else if (metarPart === 'CAVOK') {
130
+ } else if (metarPart === 'CAVOK' || metarPart === 'CLR') {
116
131
  metarObject.visibility = {
117
- miles: 10,
118
- meters: convert.milesToMeters(10)
132
+ miles: 10,
133
+ miles_float: 10,
134
+ meters: convert.milesToMeters(10),
135
+ meters_float: convert.milesToMeters(10)
119
136
  };
120
137
  mode = 5; // no clouds & conditions reported
121
138
  } else if (metarObject.wind) {
@@ -139,7 +156,7 @@ const metarParser = function(metarString) {
139
156
  return (index !== 0 && m);
140
157
  })
141
158
  .forEach((m) => {
142
- metarObject.conditions.push(m);
159
+ metarObject.conditions.push({ code: m });
143
160
  })
144
161
  ;
145
162
  // may occur multiple times
@@ -153,19 +170,21 @@ const metarParser = function(metarString) {
153
170
  metarObject.clouds = [];
154
171
  }
155
172
  match[2] = Number(match[2]) * 100;
156
- let cloud = {
173
+ const cloud = {
157
174
  code: match[1],
158
- base_feet_agl: match[2],
175
+ base_feet_agl: match[2],
159
176
  base_meters_agl: convert.feetToMeters(match[2])
160
177
  };
161
178
  metarObject.clouds.push(cloud);
162
- metarObject.ceiling = cloud;
163
- // may occur multiple times
164
179
  }
165
180
  break;
166
181
  case 6:
167
182
  // Temperature
168
183
  match = metarPart.match(/^(M?\d+)\/(M?\d+)$/);
184
+ if (match === null && metarPart.match(/^\/\/\/\/\/$/)) {
185
+ mode = 7;
186
+ break;
187
+ }
169
188
  if (match) {
170
189
  match[1] = Number(match[1].replace('M', '-'));
171
190
  match[2] = Number(match[2].replace('M', '-'));
@@ -188,9 +207,9 @@ const metarParser = function(metarString) {
188
207
  match[2] = Number(match[2]);
189
208
  match[2] /= (match[1] === 'Q') ? 10 : 100;
190
209
  metarObject.barometer = {
191
- hg: (match[1] === 'Q') ? convert.kpaToInhg(match[2]) : match[2],
192
- kpa: (match[1] === 'Q') ? match[2] : convert.inhgToKpa(match[2]),
193
- mb: (match[1] === 'Q') ? match[2] * 10 : convert.inhgToKpa(match[2] * 10)
210
+ hg: (match[1] === 'Q') ? convert.kpaToInhg(match[2]) : match[2],
211
+ kpa: (match[1] === 'Q') ? match[2] : convert.inhgToKpa(match[2]),
212
+ mb: (match[1] === 'Q') ? match[2] * 10 : convert.inhgToKpa(match[2] * 10)
194
213
  };
195
214
  mode = 8;
196
215
  }
@@ -198,6 +217,46 @@ const metarParser = function(metarString) {
198
217
  }
199
218
  });
200
219
 
220
+ if (!metarObject.visibility) {
221
+ metarObject.visibility = {
222
+ miles: 10,
223
+ miles_float: 10,
224
+ meters: convert.milesToMeters(10),
225
+ meters_float: convert.milesToMeters(10)
226
+ };
227
+ }
228
+
229
+ // Finishing touches
230
+
231
+ metarObject.visibility.miles = String(_private.round(metarObject.visibility.miles, 0.5));
232
+ metarObject.visibility.meters = String(_private.round(metarObject.visibility.meters));
233
+
234
+ if (metarObject.clouds) {
235
+ const highestCloud = metarObject.clouds[metarObject.clouds.length - 1];
236
+ metarObject.ceiling = {
237
+ code: highestCloud.code,
238
+ feet_agl: highestCloud.base_feet_agl,
239
+ meters_agl: highestCloud.base_meters_agl
240
+ };
241
+ }
242
+
243
+ metarObject.flight_category = '';
244
+ if (metarObject.visibility.miles_float > 5 &&
245
+ (!metarObject.ceiling || metarObject.ceiling.feet_agl > 3000)
246
+ ) {
247
+ metarObject.flight_category = 'VFR';
248
+ } else if (metarObject.visibility.miles_float >= 3 &&
249
+ (!metarObject.ceiling || metarObject.ceiling.feet_agl >= 1000)
250
+ ) {
251
+ metarObject.flight_category = 'MVFR';
252
+ } else if (metarObject.visibility.miles_float >= 1 &&
253
+ (!metarObject.ceiling || metarObject.ceiling.feet_agl >= 500)
254
+ ) {
255
+ metarObject.flight_category = 'IFR';
256
+ } else {
257
+ metarObject.flight_category = 'LIFR';
258
+ }
259
+
201
260
  return metarObject;
202
261
  };
203
262
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aewx-metar-parser",
3
- "version": "0.9.3",
3
+ "version": "1.0.0",
4
4
  "description": "Parse METAR information into structured JavaScript object",
5
5
  "directories": {
6
6
  "test": "test",
@@ -9,20 +9,18 @@
9
9
  "main": "lib/metar-parser.js",
10
10
  "scripts": {
11
11
  "precommit": "npm test",
12
- "test": "eslint *.js lib/**/*.js test/**/*.js && mocha && npm outdated"
12
+ "test": "npx eslint lib/**/*.js test/**/*.js && npx mocha && npm outdated",
13
+ "prepare": "husky install"
13
14
  },
14
15
  "repository": {
15
16
  "type": "git",
16
17
  "url": "git+ssh://git@github.com/fboes/metar-parser.git"
17
18
  },
18
19
  "devDependencies": {
19
- "beeper": "^1.1.1",
20
- "gulp": "^4.0.0",
21
- "gulp-eslint": "^5.0.0",
22
- "gulp-mocha": "^6.0.0",
23
- "gulp-plumber": "^1.2.1",
24
- "husky": "^1.3.1",
25
- "mocha": "^5.2.0"
20
+ "eslint": "^8.18.0",
21
+ "eslint-config-standard": "^17.0.0",
22
+ "husky": "^8.0.0",
23
+ "mocha": "^10.0.0"
26
24
  },
27
25
  "keywords": [
28
26
  "flight",
@@ -35,10 +33,5 @@
35
33
  "bugs": {
36
34
  "url": "https://github.com/fboes/metar-parser/issues"
37
35
  },
38
- "homepage": "https://github.com/fboes/metar-parser#readme",
39
- "husky": {
40
- "hooks": {
41
- "pre-commit": "npm run precommit"
42
- }
43
- }
36
+ "homepage": "https://github.com/fboes/metar-parser#readme"
44
37
  }
package/test/convert.js CHANGED
@@ -1,56 +1,55 @@
1
1
  'use strict';
2
2
 
3
- const assert = require('assert');
3
+ const assert = require('assert');
4
4
 
5
5
  const convert = require('../lib/convert');
6
6
 
7
- describe('convert', function() {
8
-
9
- it('must convert celsius in fahrenheit', function() {
7
+ describe('convert', function () {
8
+ it('must convert celsius in fahrenheit', function () {
10
9
  const fahrenheit = convert.celsiusToFahrenheit(1);
11
- //console.log(fahrenheit);
10
+ // console.log(fahrenheit);
12
11
  assert.ok(fahrenheit > 33.75);
13
12
  assert.ok(fahrenheit < 33.85);
14
13
  });
15
14
 
16
- it('must convert kpa in hgin', function() {
15
+ it('must convert kpa in hgin', function () {
17
16
  const hgin = convert.kpaToInhg(1);
18
17
  // console.log(hgin);
19
18
  assert.ok(hgin > 0.29);
20
19
  assert.ok(hgin < 0.30);
21
20
  });
22
21
 
23
- it('must convert hgin in kpa', function() {
22
+ it('must convert hgin in kpa', function () {
24
23
  const kpa = convert.inhgToKpa(1);
25
- //console.log(kpa);
24
+ // console.log(kpa);
26
25
  assert.ok(kpa > 3.38);
27
26
  assert.ok(kpa < 3.39);
28
27
  });
29
28
 
30
- it('must convert miles in meters', function() {
29
+ it('must convert miles in meters', function () {
31
30
  const meters = convert.milesToMeters(1);
32
- //console.log(meters);
31
+ // console.log(meters);
33
32
  assert.ok(meters > 1609);
34
33
  assert.ok(meters < 1610);
35
34
  });
36
35
 
37
- it('must convert km/h in m/s', function() {
36
+ it('must convert km/h in m/s', function () {
38
37
  const mps = convert.kphToMps(1);
39
- //console.log(mps);
38
+ // console.log(mps);
40
39
  assert.ok(mps > 0.277);
41
40
  assert.ok(mps < 0.278);
42
41
  });
43
42
 
44
- it('must convert m/s to kts', function() {
43
+ it('must convert m/s to kts', function () {
45
44
  const kts = convert.mpsToKts(1);
46
- //console.log(kts);
45
+ // console.log(kts);
47
46
  assert.ok(kts > 1.94);
48
47
  assert.ok(kts < 1.95);
49
48
  });
50
49
 
51
- it('must convert kts to m/s', function() {
50
+ it('must convert kts to m/s', function () {
52
51
  const mps = convert.ktsToMps(1);
53
- //console.log(mps);
52
+ // console.log(mps);
54
53
  assert.ok(mps > 0.51);
55
54
  assert.ok(mps < 0.52);
56
55
  });
@@ -1,162 +1,172 @@
1
1
  'use strict';
2
2
 
3
- const assert = require('assert');
3
+ const assert = require('assert');
4
4
 
5
5
  const metarParser = require('../lib/metar-parser');
6
6
  const convert = require('../lib/convert');
7
7
 
8
- describe('metarParser', function() {
9
-
8
+ describe('metarParser', function () {
10
9
  const metarTestcases = [
11
10
  {
12
11
  source: 'https://aviationweather.gov/metar#1',
13
- metarCode: "KEYW 041053Z AUTO 13005KT 10SM CLR 24/22 A3000 RMK AO2 SLP159 T02440222",
12
+ metarCode: 'KEYW 041053Z AUTO 13005KT 10SM CLR 24/22 A3000 RMK AO2 SLP159 T02440222',
14
13
  expectedValues: [
15
14
  ['icao', 'KEYW'],
16
- ['wind', {degrees: 130, speed_kts: 5, gust_kts: 5}],
17
- ['visibility', { meters: convert.milesToMeters(10) }],
15
+ ['wind', { degrees: 130, speed_kts: 5, gust_kts: 5 }],
16
+ ['visibility', { meters: '16000', meters_float: convert.milesToMeters(10) }],
18
17
  ['temperature', { celsius: 24, fahrenheit: 75.2 }],
19
- ['barometer', {kpa: 3000 / 10 / 2.9529988 }]
18
+ ['barometer', { kpa: 3000 / 10 / 2.9529988 }],
19
+ ['flight_category', 'VFR']
20
20
  ],
21
21
  output: false
22
22
  },
23
23
  {
24
24
  source: 'https://aviationweather.gov/metar#2',
25
- metarCode: "KACV 041053Z AUTO 07003KT 10SM CLR 04/04 A3001 RMK AO2 SLP169 T00440039",
25
+ metarCode: 'KACV 041053Z AUTO 07003KT 10SM CLR 04/04 A3001 RMK AO2 SLP169 T00440039',
26
26
  expectedValues: [
27
27
  ['icao', 'KACV'],
28
- ['wind', {degrees: 70, speed_kts: 3, gust_kts: 3}],
29
- ['visibility', { meters: convert.milesToMeters(10) }],
28
+ ['wind', { degrees: 70, speed_kts: 3, gust_kts: 3 }],
29
+ ['visibility', { meters: '16000', meters_float: convert.milesToMeters(10) }],
30
30
  ['temperature', { celsius: 4, fahrenheit: 39.2 }],
31
- ['barometer', { hg: 30.01, kpa: convert.inhgToKpa(30.01) }]
31
+ ['barometer', { hg: 30.01, kpa: convert.inhgToKpa(30.01) }],
32
+ ['flight_category', 'VFR']
32
33
  ],
33
34
  output: false
34
35
  },
35
36
  {
36
37
  source: 'https://api.checkwx.com/#1',
37
- metarCode: "KPIE 260853Z AUTO 02013G17KT 10SM CLR 17/07 A2998 RMK AO2 SLP153 T01720072 57000",
38
+ metarCode: 'KPIE 260853Z AUTO 02013G17KT 10SM CLR 17/07 A2998 RMK AO2 SLP153 T01720072 57000',
38
39
  expectedValues: [
39
40
  ['icao', 'KPIE'],
40
- ['wind', {degrees: 20, speed_kts: 13, gust_kts: 17}],
41
- ['visibility', { meters: convert.milesToMeters(10) }],
41
+ ['wind', { degrees: 20, speed_kts: 13, gust_kts: 17 }],
42
+ ['visibility', { meters: '16000', meters_float: convert.milesToMeters(10) }],
42
43
  ['temperature', { celsius: 17, fahrenheit: 62.6 }],
43
- ['barometer', { hg: 29.98, kpa: convert.inhgToKpa(29.98) }]
44
+ ['barometer', { hg: 29.98, kpa: convert.inhgToKpa(29.98) }],
45
+ ['flight_category', 'VFR']
44
46
  ],
45
47
  output: false
46
48
  },
47
49
  {
48
50
  source: 'https://api.checkwx.com/#2',
49
- metarCode: "KSPG 260853Z AUTO 05012KT 10SM CLR 18/09 A2997 RMK AO2 SLP148 T01830094 53001",
51
+ metarCode: 'KSPG 260853Z AUTO 05012KT 10SM CLR 18/09 A2997 RMK AO2 SLP148 T01830094 53001',
50
52
  expectedValues: [
51
53
  ['icao', 'KSPG'],
52
- ['wind', {degrees: 50, speed_kts: 12, gust_kts: 12}],
53
- ['visibility', { meters: convert.milesToMeters(10) }],
54
+ ['wind', { degrees: 50, speed_kts: 12, gust_kts: 12 }],
55
+ ['visibility', { meters: '16000', meters_float: convert.milesToMeters(10) }],
54
56
  ['temperature', { celsius: 18, fahrenheit: 64.4 }],
55
- ['barometer', {kpa: 2997 / 10 / 2.9529988 }]
57
+ ['barometer', { kpa: 2997 / 10 / 2.9529988 }],
58
+ ['flight_category', 'VFR']
56
59
  ],
57
60
  output: false
58
61
  },
59
62
  {
60
63
  source: 'https://de.wikipedia.org/wiki/METAR',
61
- metarCode: "EDDS 081620Z 29010KT 9999 FEW040TCU 09/M03 Q1012 NOSIG",
64
+ metarCode: 'EDDS 081620Z 29010KT 9999 FEW040TCU 09/M03 Q1012 NOSIG',
62
65
  expectedValues: [
63
66
  ['icao', 'EDDS'],
64
67
  ['wind', {
65
68
  degrees: 290,
66
69
  speed_kts: 10,
67
70
  speed_mps: convert.ktsToMps(10),
68
- gust_kts: 10,
69
- gust_mps: convert.ktsToMps(10)
71
+ gust_kts: 10,
72
+ gust_mps: convert.ktsToMps(10)
70
73
  }],
71
- ['visibility', { meters: 9999 }],
72
- ['clouds', [{base_feet_agl: 4000, code: 'FEW'}]],
74
+ ['visibility', { meters: '10000', meters_float: 9999 }],
75
+ ['clouds', [{ base_feet_agl: 4000, code: 'FEW' }]],
73
76
  ['temperature', { celsius: 9, fahrenheit: 48.2 }],
74
- ['barometer', {kpa: 101.2 }]
77
+ ['barometer', { kpa: 101.2 }],
78
+ ['flight_category', 'VFR']
75
79
  ],
76
80
  output: false
77
81
  },
78
82
  {
79
83
  source: 'https://en.wikipedia.org/wiki/METAR#1',
80
- metarCode: "METAR LBBG 041600Z 12012MPS 090V150 1400 R04/P1500N R22/P1500U +SN BKN022 OVC050 M04/M07 Q1020 NOSIG 8849//91=",
84
+ metarCode: 'METAR LBBG 041600Z 12012MPS 090V150 1400 R04/P1500N R22/P1500U +SN BKN022 OVC050 M04/M07 Q1020 NOSIG 8849//91=',
81
85
  expectedValues: [
82
86
  ['icao', 'LBBG'],
83
87
  ['wind', {
84
88
  degrees: 120,
85
89
  speed_kts: convert.mpsToKts(12),
86
90
  speed_mps: 12,
87
- gust_kts: convert.mpsToKts(12),
88
- gust_mps: 12
91
+ gust_kts: convert.mpsToKts(12),
92
+ gust_mps: 12
89
93
  }],
90
- ['visibility', { meters: 1400 }],
91
- ['conditions', [ '+', 'SN' ]],
92
- ['clouds', [{base_feet_agl: 2200, code: 'BKN'}, {base_feet_agl: 5000, code: 'OVC'}]],
94
+ ['visibility', { meters: '1500', meters_float: 1400 }],
95
+ ['conditions', [{ code: '+' }, { code: 'SN' }]],
96
+ ['clouds', [{ base_feet_agl: 2200, code: 'BKN' }, { base_feet_agl: 5000, code: 'OVC' }]],
93
97
  ['temperature', { celsius: -4, fahrenheit: 24.8 }],
94
- ['barometer', {kpa: 102.0 }]
98
+ ['barometer', { kpa: 102.0 }],
99
+ ['flight_category', 'LIFR']
95
100
  ],
96
101
 
97
102
  output: false
98
103
  },
99
104
  {
100
105
  source: 'https://en.wikipedia.org/wiki/METAR#2',
101
- metarCode: "METAR KTTN 051853Z 04011KT 1/2SM VCTS SN FZFG BKN003 OVC010 M02/M02 A3006 RMK AO2 TSB40 SLP176 P0002 T10171017=",
106
+ metarCode: 'METAR KTTN 051853Z 04011KT 1/2SM VCTS SN FZFG BKN003 OVC010 M02/M02 A3006 RMK AO2 TSB40 SLP176 P0002 T10171017=',
102
107
  expectedValues: [
103
108
  ['icao', 'KTTN'],
104
- ['wind', {degrees: 40, speed_kts: 11, gust_kts: 11}],
105
- ['visibility', { meters: convert.milesToMeters(0.5) }],
106
- ['conditions', [ 'VC', 'TS', 'SN', 'FZ', 'FG' ]],
107
- ['clouds', [{base_feet_agl: 300, code: 'BKN'}, {base_feet_agl: 1000, code: 'OVC'}]],
109
+ ['wind', { degrees: 40, speed_kts: 11, gust_kts: 11 }],
110
+ ['visibility', { meters: '1000', meters_float: convert.milesToMeters(0.5) }],
111
+ ['conditions', [{ code: 'VC' }, { code: 'TS' }, { code: 'SN' }, { code: 'FZ' }, { code: 'FG' }]],
112
+ ['clouds', [{ base_feet_agl: 300, code: 'BKN' }, { base_feet_agl: 1000, code: 'OVC' }]],
108
113
  ['temperature', { celsius: -2, fahrenheit: 28.4 }],
109
- ['barometer', {kpa: convert.inhgToKpa(30.06) }]
114
+ ['barometer', { kpa: convert.inhgToKpa(30.06) }],
115
+ ['flight_category', 'LIFR']
110
116
  ],
111
117
  output: false
112
118
  },
113
119
  {
114
120
  source: 'https://en.allmetsat.com/metar-taf/#1',
115
- metarCode: "KEYW 041053Z AUTO 13005KT 10SM CLR 24/22 A3000 RMK AO2 SLP159 T02440222",
121
+ metarCode: 'KEYW 041053Z AUTO 13005KT 10SM CLR 24/22 A3000 RMK AO2 SLP159 T02440222',
116
122
  expectedValues: [
117
123
  ['icao', 'KEYW'],
118
- ['wind', {degrees: 130, speed_kts: 5, gust_kts: 5}],
119
- ['visibility', { meters: convert.milesToMeters(10) }],
124
+ ['wind', { degrees: 130, speed_kts: 5, gust_kts: 5 }],
125
+ ['visibility', { meters: '16000', meters_float: convert.milesToMeters(10) }],
120
126
  ['temperature', { celsius: 24 }],
121
- ['barometer', {kpa: 3000 / 10 / 2.9529988 }]
127
+ ['barometer', { kpa: 3000 / 10 / 2.9529988 }],
128
+ ['flight_category', 'VFR']
122
129
  ],
123
130
  output: false
124
131
  },
125
132
  {
126
133
  source: 'https://en.allmetsat.com/metar-taf/#2',
127
- metarCode: "EDDH 041050Z 29013KT 6000 SCT006 BKN009 04/03 Q1028 TEMPO BKN012",
134
+ metarCode: 'EDDH 041050Z 29013KT 6000 SCT006 BKN009 04/03 Q1028 TEMPO BKN012',
128
135
  expectedValues: [
129
136
  ['icao', 'EDDH'],
130
- ['wind', {degrees: 290, speed_kts: 13, gust_kts: 13}],
131
- ['visibility', { meters: 6000 }],
132
- ['clouds', [{base_feet_agl: 600, code: 'SCT'}, {base_feet_agl: 900, code: 'BKN'}]],
137
+ ['wind', { degrees: 290, speed_kts: 13, gust_kts: 13 }],
138
+ ['visibility', { meters: '6000', meters_float: 6000 }],
139
+ ['clouds', [{ base_feet_agl: 600, code: 'SCT' }, { base_feet_agl: 900, code: 'BKN' }]],
133
140
  ['temperature', { celsius: 4, fahrenheit: 39.2 }],
134
- ['barometer', {kpa: 102.8 }]
141
+ ['barometer', { kpa: 102.8 }],
142
+ ['flight_category', 'IFR']
135
143
  ],
136
144
  output: false
137
145
  },
138
146
  {
139
147
  source: 'https://en.allmetsat.com/metar-taf/#3',
140
- metarCode: "ETEB 041056Z AUTO 26010KT 9999 SCT090 00/M01 A3052 RMK AO2 SLP378 T10031013",
148
+ metarCode: 'ETEB 041056Z AUTO 26010KT 9999 SCT090 00/M01 A3052 RMK AO2 SLP378 T10031013',
141
149
  expectedValues: [
142
150
  ['icao', 'ETEB'],
143
- ['wind', {degrees: 260, speed_kts: 10, gust_kts: 10}],
144
- ['visibility', { meters: 9999 }],
145
- ['clouds', [{base_feet_agl: 9000, code: 'SCT'}]],
151
+ ['wind', { degrees: 260, speed_kts: 10, gust_kts: 10 }],
152
+ ['visibility', { meters: '10000', meters_float: 9999 }],
153
+ ['clouds', [{ base_feet_agl: 9000, code: 'SCT' }]],
146
154
  ['temperature', { celsius: 0, fahrenheit: 32 }],
147
- ['barometer', {kpa: 3052 / 10 / 2.9529988 }]
155
+ ['barometer', { kpa: 3052 / 10 / 2.9529988 }],
156
+ ['flight_category', 'VFR']
148
157
  ],
149
158
  output: false
150
159
  },
151
160
  {
152
161
  source: 'https://aviationweather.gov/metar/#3',
153
- metarCode: "KEYW 050653Z AUTO 19006KT FEW024 BKN039 26/23 A3000 RMK AO2 LTG DSNT W SLP159 T02610228",
162
+ metarCode: 'KEYW 050653Z AUTO 19006KT FEW024 BKN039 26/23 A3000 RMK AO2 LTG DSNT W SLP159 T02610228',
154
163
  expectedValues: [
155
164
  ['icao', 'KEYW'],
156
- ['wind', {degrees: 190, speed_kts: 6, gust_kts: 6}],
157
- ['clouds', [{base_feet_agl: 2400, code: 'FEW'}, {base_feet_agl: 3900, code: 'BKN'}]],
165
+ ['wind', { degrees: 190, speed_kts: 6, gust_kts: 6 }],
166
+ ['clouds', [{ base_feet_agl: 2400, code: 'FEW' }, { base_feet_agl: 3900, code: 'BKN' }]],
158
167
  ['temperature', { celsius: 26 }],
159
- ['barometer', {kpa: 3000 / 10 / 2.9529988 }]
168
+ ['barometer', { kpa: 3000 / 10 / 2.9529988 }],
169
+ ['flight_category', 'VFR']
160
170
  ],
161
171
  output: false
162
172
  },
@@ -165,11 +175,12 @@ describe('metarParser', function() {
165
175
  metarCode: 'KSFO 070121Z 19023KT 1 1/2SM R28R/6000VP6000FT -RA BKN004 BKN013 OVC035 15/12 A2970 RMK AO2 T01500122 PNO $',
166
176
  expectedValues: [
167
177
  ['icao', 'KSFO'],
168
- ['conditions', [ '-', 'RA' ]],
169
- ['visibility', { meters: convert.milesToMeters(1.5) }],
178
+ ['conditions', [{ code: '-' }, { code: 'RA' }]],
179
+ ['visibility', { meters: '2500', meters_float: convert.milesToMeters(1.5) }],
170
180
  ['temperature', { celsius: 15, fahrenheit: 59 }],
171
181
  ['dewpoint', { celsius: 12, fahrenheit: 53.6 }],
172
- ['barometer', {kpa: 2970 / 10 / 2.9529988, mb: 2970 / 2.9529988 }]
182
+ ['barometer', { kpa: 2970 / 10 / 2.9529988, mb: 2970 / 2.9529988 }],
183
+ ['flight_category', 'IFR']
173
184
  ],
174
185
  output: false
175
186
  },
@@ -177,17 +188,38 @@ describe('metarParser', function() {
177
188
  source: 'EHAM with CAVOK',
178
189
  metarCode: 'EHAM 100125Z 33004KT CAVOK M00/M01 Q1026 NOSIG',
179
190
  expectedValues: [
180
- ['visibility', { miles: 10, meters: convert.milesToMeters(10) }],
191
+ ['visibility', { miles_float: 10, meters: '16000', meters_float: convert.milesToMeters(10) }],
181
192
  ['temperature', { celsius: -0, fahrenheit: 32 }],
182
193
  ['dewpoint', { celsius: -1, fahrenheit: 30.2 }],
183
- ['barometer', { hg: 102.6, kpa: 102.6, mb: 10.26 }]
194
+ ['barometer', { hg: 102.6, kpa: 102.6, mb: 10.26 }],
195
+ ['flight_category', 'VFR']
196
+ ],
197
+ output: false
198
+ },
199
+ {
200
+ source: 'Without VIS because it is CLR',
201
+ metarCode: 'KEYW 291553Z VRB03KT CLR 17/09 A3009 RMK AO2 SLP189 T01670089 $',
202
+ expectedValues: [
203
+ ['visibility', { miles_float: 10, meters: '16000', meters_float: convert.milesToMeters(10) }],
204
+ ['wind', { degrees: 180, speed_kts: 3, gust_kts: 3 }],
205
+ ['temperature', { celsius: 17 }],
206
+ ['dewpoint', { celsius: 9 }],
207
+ ['flight_category', 'VFR']
208
+ ],
209
+ output: false
210
+ },
211
+ {
212
+ source: 'AUTO does stuff?',
213
+ metarCode: 'KDVO 022335Z AUTO 4SM BR BKN007 BKN013 12/12 A2988 RMK AO2',
214
+ expectedValues: [
215
+ ['visibility', { miles_float: 4, meters: '6500', meters_float: convert.milesToMeters(4) }]
184
216
  ],
185
217
  output: false
186
218
  }
187
219
  ];
188
220
 
189
- metarTestcases.forEach(function(test) {
190
- it('must convert METAR string from ' + test.source, function() {
221
+ metarTestcases.forEach(function (test) {
222
+ it('must convert METAR string from ' + test.source, function () {
191
223
  const metarData = metarParser(test.metarCode);
192
224
  if (test.output) {
193
225
  console.log(metarData);
@@ -207,8 +239,8 @@ describe('metarParser', function() {
207
239
  }
208
240
  if (metarData.ceiling) {
209
241
  assert.ok(metarData.ceiling.code);
210
- assert.ok(metarData.ceiling.base_feet_agl);
211
- assert.ok(metarData.ceiling.base_meters_agl);
242
+ assert.ok(metarData.ceiling.feet_agl);
243
+ assert.ok(metarData.ceiling.meters_agl);
212
244
  }
213
245
 
214
246
  test.expectedValues.forEach((valueTest) => {
@@ -256,4 +288,17 @@ describe('metarParser', function() {
256
288
  });
257
289
  });
258
290
  });
291
+
292
+ it('should LFMK 151400Z AUTO 06007KT 030V100 CAVOK ///// Q1017 NOSIG= have QNH = 1017', () => {
293
+ const metar = 'LFMK 151400Z AUTO 06007KT 030V100 CAVOK ///// Q1017 NOSIG=';
294
+ const resultat = metarParser(metar);
295
+ console.log(resultat);
296
+ assert.deepStrictEqual(resultat.barometer.mb, 1017);
297
+ });
298
+
299
+ it('should LFMK 211130Z AUTO 29005KT 260V320 9999 OVC034 24/20 Q1011= have QNH = 1011', () => {
300
+ const metar = 'LLFMK 211130Z AUTO 29005KT 260V320 9999 OVC034 24/20 Q1011=';
301
+ const resultat = metarParser(metar);
302
+ assert.deepStrictEqual(resultat.barometer.mb, 1011);
303
+ });
259
304
  });
package/.eslintrc.yaml DELETED
@@ -1,61 +0,0 @@
1
- root: true
2
- extends:
3
- - eslint:recommended
4
- env:
5
- node: true
6
- mocha: true
7
- es6: true
8
- parserOptions:
9
- ecmaVersion: 2017
10
- rules:
11
- arrow-parens:
12
- - error
13
- - always
14
- arrow-body-style:
15
- - error
16
- - always
17
- brace-style: error
18
- comma-dangle:
19
- - error
20
- - never
21
- comma-spacing:
22
- - error
23
- - { before: false, after: true }
24
- curly: error
25
- eqeqeq: error
26
- func-call-spacing:
27
- - error
28
- - never
29
- indent:
30
- - error
31
- - 2
32
- - SwitchCase: 1
33
- key-spacing:
34
- - error
35
- - beforeColon: false
36
- mode: minimum
37
- linebreak-style:
38
- - error
39
- - unix
40
- max-len:
41
- - warn
42
- - { code: 120, ignoreStrings: true, ignoreRegExpLiterals: true }
43
- no-console: off
44
- no-else-return: error
45
- no-lonely-if: error
46
- no-loop-func: error
47
- no-multi-str: error
48
- no-undef: error
49
- no-unused-vars: error
50
- no-var: error
51
- semi:
52
- - error
53
- - always
54
- space-before-function-paren:
55
- - error
56
- - never
57
- space-infix-ops: error
58
- strict:
59
- - error
60
- - safe
61
- valid-jsdoc: warn
package/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "node"
4
- notifications:
5
- email:
6
- recipients:
7
- - info@3960.org
8
- on_success: change
9
- on_failure: change
package/gulpfile.js DELETED
@@ -1,62 +0,0 @@
1
- 'use strict';
2
-
3
- // Include gulp
4
- const gulp = require('gulp');
5
- const pkg = require('./package.json');
6
- const beep = require('beeper');
7
- const onError = function() {
8
- beep();
9
- return true;
10
- };
11
-
12
- // Include Our Plugins
13
- const eslint = require('gulp-eslint');
14
- const mocha = require('gulp-mocha');
15
- const plumber = require('gulp-plumber');
16
-
17
-
18
- const tasks = {
19
- doEslint: function() {
20
- return gulp.src(
21
- [
22
- '*.js',
23
- pkg.directories.lib + '/**/*.js',
24
- pkg.directories.test + '/**/*.js'
25
- ])
26
- .pipe(plumber({errorHandler: onError}))
27
- .pipe(eslint())
28
- .pipe(eslint.format())
29
- //.pipe(eslint.failAfterError())
30
- ;
31
- },
32
-
33
- doMocha: function() {
34
- return gulp.src(pkg.directories.test + '/**/*.js', {read: false})
35
- .pipe(plumber({errorHandler: onError}))
36
- .pipe(mocha({
37
- reporter: 'dot'
38
- }))
39
- ;
40
- },
41
-
42
- // Watch Files For Changes
43
- watch: function() {
44
- gulp.watch(['gulpfile.js', 'package.json'], process.exit);
45
- gulp.watch(
46
- [
47
- '*.js',
48
- pkg.directories.lib + '/**/*.js',
49
- pkg.directories.test + '/**/*.js'
50
- ],
51
- tasks.test
52
- );
53
- }
54
- };
55
-
56
- // Bundle tasks
57
- tasks.test = gulp.parallel(tasks.doEslint, tasks.doMocha);
58
-
59
- // Expose tasks
60
- gulp.task('test', tasks.test);
61
- gulp.task('watch', tasks.watch);
62
- gulp.task('default', tasks.watch);