atmosx-nwws-parser 1.0.1916 → 1.0.1918

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/bootstrap.ts CHANGED
@@ -81,6 +81,7 @@ export const definitions = {
81
81
  wmo: `[A-Z0-9]{6}\\s[A-Z]{4}\\s\\d{6}`,
82
82
  ugc1: `(\\w{2}[CZ](\\d{3}((-|>)\\s?(\n\n)?))+)`,
83
83
  ugc2: `(\\d{6}(-|>)\\s?(\n\n)?)`,
84
+ ugc3: `(\\d{6})(?=-|$)`,
84
85
  dateline: `/\d{3,4}\s*(AM|PM)?\s*[A-Z]{2,4}\s+[A-Z]{3,}\s+[A-Z]{3,}\s+\d{1,2}\s+\d{4}`
85
86
  },
86
87
  tags: {
package/dist/bootstrap.js CHANGED
@@ -112,6 +112,7 @@ exports.definitions = {
112
112
  wmo: "[A-Z0-9]{6}\\s[A-Z]{4}\\s\\d{6}",
113
113
  ugc1: "(\\w{2}[CZ](\\d{3}((-|>)\\s?(\n\n)?))+)",
114
114
  ugc2: "(\\d{6}(-|>)\\s?(\n\n)?)",
115
+ ugc3: "(\\d{6})(?=-|$)",
115
116
  dateline: "/d{3,4}s*(AM|PM)?s*[A-Z]{2,4}s+[A-Z]{3,}s+[A-Z]{3,}s+d{1,2}s+d{4}"
116
117
  },
117
118
  tags: {
@@ -438,7 +438,7 @@ var mEvents = /** @class */ (function () {
438
438
  history: [{ description: getDescription, action: "Issued", issued: getTimeIssued }],
439
439
  properties: {
440
440
  areaDesc: mUgc.locations.join("; ") || 'N/A',
441
- expires: new Date(new Date().getTime() + 1 * 60 * 60 * 1000),
441
+ expires: new Date(mUgc.expiry != null ? mUgc.expiry : new Date().getTime() + 1 * 60 * 60 * 1000),
442
442
  sent: new Date(getTimeIssued),
443
443
  messageType: "Issued",
444
444
  event: Object.keys(loader.definitions.offshore).find(function (event) { return message.toLowerCase().includes(event.toLowerCase()); }) || 'Unknown Event',
@@ -545,7 +545,7 @@ var mEvents = /** @class */ (function () {
545
545
  history: [{ description: getDescription, action: "Issued", issued: getTimeIssued }],
546
546
  properties: {
547
547
  areaDesc: mUgc.locations.join("; ") || 'N/A',
548
- expires: new Date(new Date().getTime() + 1 * 60 * 60 * 1000),
548
+ expires: new Date(mUgc.expiry != null ? mUgc.expiry : new Date().getTime() + 1 * 60 * 60 * 1000),
549
549
  sent: new Date(getTimeIssued),
550
550
  messageType: "Issued",
551
551
  event: "Special Weather Statement",
@@ -82,6 +82,7 @@ var mTextParser = /** @class */ (function () {
82
82
  * @param {string} handle - The VTEC handle to help identify the start of the main content.
83
83
  */
84
84
  mTextParser.getCleanDescription = function (message, handle) {
85
+ var originalMessage = message; // Store the original message for reference
85
86
  var dateLineMatches = Array.from(message.matchAll(/\d{3,4}\s*(AM|PM)?\s*[A-Z]{2,4}\s+[A-Z]{3,}\s+[A-Z]{3,}\s+\d{1,2}\s+\d{4}/gim));
86
87
  if (dateLineMatches.length) {
87
88
  var dateLineMatch = dateLineMatches[dateLineMatches.length - 1];
@@ -111,6 +112,9 @@ var mTextParser = /** @class */ (function () {
111
112
  message = latStart !== -1 ? afterVtec.substring(0, latStart).trim() : afterVtec.trim();
112
113
  }
113
114
  }
115
+ if (message.replace(/\s+/g, ' ').trim().startsWith("ISSUED TIME...")) {
116
+ message = originalMessage;
117
+ }
114
118
  return message;
115
119
  };
116
120
  return mTextParser;
package/dist/src/ugc.js CHANGED
@@ -94,16 +94,17 @@ var mUgcParser = /** @class */ (function () {
94
94
  */
95
95
  mUgcParser.getUGC = function (message) {
96
96
  return __awaiter(this, void 0, void 0, function () {
97
- var header, zones, locations, ugc;
97
+ var header, zones, expiry, locations, ugc;
98
98
  return __generator(this, function (_a) {
99
99
  switch (_a.label) {
100
100
  case 0:
101
101
  header = this.getHeader(message);
102
102
  zones = this.getZones(header);
103
+ expiry = this.getExpiry(message);
103
104
  return [4 /*yield*/, this.getLocations(zones)];
104
105
  case 1:
105
106
  locations = _a.sent();
106
- ugc = zones.length > 0 ? { zones: zones, locations: locations } : null;
107
+ ugc = zones.length > 0 ? { zones: zones, locations: locations, expiry: expiry } : null;
107
108
  return [2 /*return*/, ugc];
108
109
  }
109
110
  });
@@ -121,6 +122,18 @@ var mUgcParser = /** @class */ (function () {
121
122
  var full = message.substring(start, start + end).replace(/\s+/g, '').slice(0, -1);
122
123
  return full;
123
124
  };
125
+ mUgcParser.getExpiry = function (message) {
126
+ var start = message.match(new RegExp(loader.definitions.expressions.ugc3, "gimu"));
127
+ if (start != null) {
128
+ var day = parseInt(start[0].substring(0, 2), 10);
129
+ var hour = parseInt(start[0].substring(2, 4), 10);
130
+ var minute = parseInt(start[0].substring(4, 6), 10);
131
+ var now = new Date();
132
+ var expires = new Date(now.getUTCFullYear(), now.getUTCMonth(), day, hour, minute, 0);
133
+ return expires;
134
+ }
135
+ return null;
136
+ };
124
137
  /**
125
138
  * @function getLocations
126
139
  * @description Retrieves location names from a database based on UGC zone codes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atmosx-nwws-parser",
3
- "version": "1.0.1916",
3
+ "version": "1.0.1918",
4
4
  "description": "NOAA Weather Wire Parser - Built for standalone and Project AtmosphericX Integration.",
5
5
  "main": "dist/src/helper.js",
6
6
  "types": "src/helper.d.ts",
package/src/events.ts CHANGED
@@ -282,7 +282,7 @@ export class mEvents {
282
282
  history: [{description: getDescription, action: `Issued`, issued: getTimeIssued}],
283
283
  properties: {
284
284
  areaDesc: mUgc.locations.join(`; `) || 'N/A',
285
- expires: new Date(new Date().getTime() + 1 * 60 * 60 * 1000),
285
+ expires: new Date(mUgc.expiry != null ? mUgc.expiry : new Date().getTime() + 1 * 60 * 60 * 1000),
286
286
  sent: new Date(getTimeIssued),
287
287
  messageType: `Issued`,
288
288
  event: Object.keys(loader.definitions.offshore).find(event => message.toLowerCase().includes(event.toLowerCase())) || 'Unknown Event',
@@ -354,7 +354,7 @@ export class mEvents {
354
354
  history: [{description: getDescription, action: `Issued`, issued: getTimeIssued}],
355
355
  properties: {
356
356
  areaDesc: mUgc.locations.join(`; `) || 'N/A',
357
- expires: new Date(new Date().getTime() + 1 * 60 * 60 * 1000),
357
+ expires: new Date(mUgc.expiry != null ? mUgc.expiry : new Date().getTime() + 1 * 60 * 60 * 1000),
358
358
  sent: new Date(getTimeIssued),
359
359
  messageType: `Issued`,
360
360
  event: `Special Weather Statement`,
@@ -85,6 +85,7 @@ export class mTextParser {
85
85
  */
86
86
 
87
87
  static getCleanDescription(message: string, handle: string) {
88
+ let originalMessage = message; // Store the original message for reference
88
89
  let dateLineMatches = Array.from(message.matchAll(/\d{3,4}\s*(AM|PM)?\s*[A-Z]{2,4}\s+[A-Z]{3,}\s+[A-Z]{3,}\s+\d{1,2}\s+\d{4}/gim));
89
90
  if (dateLineMatches.length) {
90
91
  let dateLineMatch = dateLineMatches[dateLineMatches.length - 1];
@@ -110,6 +111,7 @@ export class mTextParser {
110
111
  message = latStart !== -1 ? afterVtec.substring(0, latStart).trim() : afterVtec.trim();
111
112
  }
112
113
  }
114
+ if (message.replace(/\s+/g, ' ').trim().startsWith(`ISSUED TIME...`)) { message = originalMessage; }
113
115
  return message;
114
116
  }
115
117
 
package/src/ugc.ts CHANGED
@@ -26,8 +26,9 @@ export class mUgcParser {
26
26
  static async getUGC (message: string) {
27
27
  const header = this.getHeader(message);
28
28
  const zones = this.getZones(header);
29
+ const expiry = this.getExpiry(message)
29
30
  const locations = await this.getLocations(zones);
30
- const ugc = zones.length > 0 ? { zones, locations} : null;
31
+ const ugc = zones.length > 0 ? { zones, locations, expiry } : null;
31
32
  return ugc;
32
33
  }
33
34
 
@@ -39,12 +40,25 @@ export class mUgcParser {
39
40
  */
40
41
 
41
42
  static getHeader (message: string) {
42
- let start = message.search(new RegExp(loader.definitions.expressions.ugc1, "gimu"));
43
- let end = message.substring(start).search(new RegExp(loader.definitions.expressions.ugc2, "gimu"));
44
- let full = message.substring(start, start + end).replace(/\s+/g, '').slice(0, -1);
43
+ const start = message.search(new RegExp(loader.definitions.expressions.ugc1, "gimu"));
44
+ const end = message.substring(start).search(new RegExp(loader.definitions.expressions.ugc2, "gimu"));
45
+ const full = message.substring(start, start + end).replace(/\s+/g, '').slice(0, -1);
45
46
  return full;
46
47
  }
47
48
 
49
+ static getExpiry (message: string) {
50
+ const start = message.match(new RegExp(loader.definitions.expressions.ugc3, "gimu"));
51
+ if (start != null) {
52
+ const day = parseInt(start[0].substring(0, 2), 10);
53
+ const hour = parseInt(start[0].substring(2, 4), 10);
54
+ const minute = parseInt(start[0].substring(4, 6), 10);
55
+ const now = new Date();
56
+ const expires = new Date(now.getUTCFullYear(), now.getUTCMonth(), day, hour, minute, 0);
57
+ return expires;
58
+ }
59
+ return null;
60
+ }
61
+
48
62
  /**
49
63
  * @function getLocations
50
64
  * @description Retrieves location names from a database based on UGC zone codes.