aewx-metar-parser 3.0.2 → 4.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/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
1
  # Change log
2
2
 
3
- ## [Unreleased]
3
+ ## [Unreleaed]
4
+
5
+ ## [4.1.0] - 2026-11-24
6
+
7
+ - Humidity may not be provided, returning `null`
8
+ - Pressure may not be provided, returning `null`
9
+ - Fixed date parser
10
+
11
+ ## [4.0.0] - 2026-11-23
12
+
13
+ - Updated ESLint
14
+ - Visbility may not be provided, returning `null`
15
+ - Temperature / dewpoints may not be provided, returning `null`
16
+ - Wind may not be provided, returning `null`
17
+ - Required values for flight category may not be provided, returning `null`
18
+
19
+ ## [3.0.2] - 2026-08-25
4
20
 
5
21
  - Added array safe guarding
6
22
 
package/README.md CHANGED
@@ -17,10 +17,14 @@ This METAR parser returns the following parts of a METAR string:
17
17
  - Temperature (in °C & °F) & humidity
18
18
  - Barometer pressure (in InHg, kpa & mb)
19
19
 
20
+ It also provides TypeScript type definitions.
21
+
22
+ Please be aware that some values may become `null`, caused by missing information in the original METAR information. This behavior is intentional and needs to be handled by your implementation.
23
+
20
24
  ## Code example
21
25
 
22
26
  ```javascript
23
- import { metarParser } from "./metar-parser.js";
27
+ import { metarParser } from "aewx-metar-parser";
24
28
 
25
29
  const metarObject = metarParser(
26
30
  "KSFO 070121Z 19023KT 1 1/2SM R28R/6000VP6000FT -RA BKN004 BKN013 OVC035 15/12 A2970 RMK AO2 T01500122 PNO $",
@@ -129,8 +133,8 @@ These sites make METAR information publicly available:
129
133
 
130
134
  ## Status
131
135
 
132
- [![npm version](https://badge.fury.io/js/aewx-metar-parser.svg)](https://badge.fury.io/js/aewx-metar-parser)
133
- [![devDependency Status](https://david-dm.org/fboes/metar-parser/dev-status.svg)](https://david-dm.org/fboes/metar-parser?type=dev)
136
+ [![NPM Version](https://img.shields.io/npm/v/aewx-metar-parser)](https://www.npmjs.com/package/aewx-metar-parser)
137
+ ![GitHub License](https://img.shields.io/github/license/fboes/metar-parser)
134
138
 
135
139
  ## Legal stuff
136
140
 
package/dist/convert.js CHANGED
@@ -1,32 +1,27 @@
1
- /**
2
- * Convert units
3
- */
4
- export const convert = {
5
- celsiusToFahrenheit: function (celsius) {
6
- return celsius * 1.8 + 32;
7
- },
8
- feetToMeters: function (feet) {
9
- return feet * 0.3048;
10
- },
11
- milesToMeters: function (miles) {
12
- return miles * 1609.344;
13
- },
14
- metersToMiles: function (meters) {
15
- return meters / 1609.344;
16
- },
17
- inhgToKpa: function (inHg) {
18
- return inHg / 0.29529988;
19
- },
20
- kpaToInhg: function (kpa) {
21
- return kpa * 0.29529988;
22
- },
23
- kphToMps: function (kph) {
24
- return (kph / 3600) * 1000;
25
- },
26
- mpsToKts: function (mps) {
27
- return mps * 1.9438445;
28
- },
29
- ktsToMps: function (kts) {
30
- return kts / 1.9438445;
31
- },
32
- };
1
+ export function celsiusToFahrenheit(celsius) {
2
+ return celsius * 1.8 + 32;
3
+ }
4
+ export function feetToMeters(feet) {
5
+ return feet * 0.3048;
6
+ }
7
+ export function milesToMeters(miles) {
8
+ return miles * 1609.344;
9
+ }
10
+ export function metersToMiles(meters) {
11
+ return meters / 1609.344;
12
+ }
13
+ export function inhgToKpa(inHg) {
14
+ return inHg / 0.29529988;
15
+ }
16
+ export function kpaToInhg(kpa) {
17
+ return kpa * 0.29529988;
18
+ }
19
+ export function kphToMps(kph) {
20
+ return (kph / 3600) * 1000;
21
+ }
22
+ export function mpsToKts(mps) {
23
+ return mps * 1.9438445;
24
+ }
25
+ export function ktsToMps(kts) {
26
+ return kts / 1.9438445;
27
+ }
@@ -1,6 +1,6 @@
1
1
  import { strict as assert } from "node:assert";
2
2
  import { describe, it } from "node:test";
3
- import { convert } from "./convert.js";
3
+ import * as convert from "./convert.js";
4
4
  describe("Conversion Tests", () => {
5
5
  it("should convert temperature units correctly", () => {
6
6
  const fahrenheit = convert.celsiusToFahrenheit(1);
@@ -0,0 +1,119 @@
1
+ import * as convert from "./convert.js";
2
+ /**
3
+ * @param {Number} value dito
4
+ * @param {Number} toNext round to next full xxxx
5
+ * @returns {Number} rounded value
6
+ */
7
+ export function round(value, toNext = 500) {
8
+ return Math.round(value / toNext) * toNext;
9
+ }
10
+ export function metarVisibility(visibility_miles, visibility_meters) {
11
+ return {
12
+ miles: visibility_miles,
13
+ miles_text: String(round(visibility_miles, 0.5)),
14
+ meters: visibility_meters,
15
+ meters_text: String(round(visibility_meters, 500)),
16
+ };
17
+ }
18
+ export function metarCloud(code, hundredFeet) {
19
+ const feet = Number(hundredFeet) * 100;
20
+ return {
21
+ code: code,
22
+ feet: feet,
23
+ meters: convert.feetToMeters(feet),
24
+ };
25
+ }
26
+ export function metarTemperature(temperatureString) {
27
+ if (temperatureString === "//") {
28
+ return null;
29
+ }
30
+ const temperature = Number(temperatureString.replace("M", "-"));
31
+ return {
32
+ celsius: temperature,
33
+ fahrenheit: convert.celsiusToFahrenheit(temperature),
34
+ };
35
+ }
36
+ /**
37
+ * @see http://andrew.rsmas.miami.edu/bmcnoldy/Humidity.html
38
+ */
39
+ export function relativeHumidity(temp, dew) {
40
+ if (dew === null || temp === null) {
41
+ return null;
42
+ }
43
+ const percent = (Math.exp((17.625 * dew.celsius) / (243.04 + dew.celsius)) /
44
+ Math.exp((17.625 * temp.celsius) / (243.04 + temp.celsius))) *
45
+ 100;
46
+ return { percent };
47
+ }
48
+ export function flightCategoryUs(visibility, ceiling) {
49
+ if (visibility === null) {
50
+ return null;
51
+ }
52
+ if (visibility.miles > 5 && (ceiling === null || ceiling.feet > 3000)) {
53
+ return "VFR";
54
+ }
55
+ else if (visibility.miles >= 3 && (ceiling === null || ceiling.feet >= 1000)) {
56
+ return "MVFR";
57
+ }
58
+ else if (visibility.miles >= 1 && (ceiling === null || ceiling.feet >= 500)) {
59
+ return "IFR";
60
+ }
61
+ return "LIFR";
62
+ }
63
+ export function flightCategoryIcao(visibility, ceiling) {
64
+ if (visibility === null) {
65
+ return null;
66
+ }
67
+ return visibility.meters >= 5000 && (ceiling === null || ceiling.feet >= 1500) ? "VFR" : "IFR";
68
+ }
69
+ /**
70
+ * @returns the lowest cloud layer reporting `BKN`, `OVC` or `VV`,
71
+ * or undefined if not such cloud layer was found.
72
+ */
73
+ function findCeiling(clouds) {
74
+ return clouds.find((c) => {
75
+ return c.code === "BKN" || c.code === "OVC" || c.code === "VV";
76
+ });
77
+ }
78
+ /**
79
+ * @see findCeiling
80
+ * @returns the ceiling by looking for the lowest cloud layer reporting `BKN`
81
+ * or `OVC`.
82
+ */
83
+ export function metarCeiling(clouds) {
84
+ const ceilingCloud = findCeiling(clouds);
85
+ if (!ceilingCloud) {
86
+ return null;
87
+ }
88
+ return {
89
+ feet: ceilingCloud.feet,
90
+ meters: ceilingCloud.meters,
91
+ };
92
+ }
93
+ /**
94
+ * @return METAR string split along its white spaces. Will convert fractional
95
+ * visibility values into one concatenated value.
96
+ */
97
+ export function metarSplit(metarString) {
98
+ return metarString
99
+ .trim()
100
+ .replace(/(\s)(\d)\s(\d)\/(\d)(SM)/, function (all, a, b, c, d, e) {
101
+ // convert visbility range like `1 1/2 SM`
102
+ return a + (Number(b) * Number(d) + Number(c)) + "/" + d + e;
103
+ })
104
+ .replace(/\n/, " \\n ")
105
+ .split(/\s+/);
106
+ }
107
+ export function date(date, hours, minutes) {
108
+ const now = new Date();
109
+ const d = new Date(0);
110
+ d.setUTCDate(date);
111
+ d.setUTCMonth(now.getUTCMonth());
112
+ d.setUTCFullYear(now.getUTCFullYear());
113
+ d.setUTCHours(hours);
114
+ d.setUTCMinutes(minutes);
115
+ if (d.getTime() > now.getTime()) {
116
+ d.setUTCMonth(d.getUTCMonth() - 1);
117
+ }
118
+ return d;
119
+ }