atmosx-nwws-parser 1.0.18 → 1.0.22

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/src/vtec.js DELETED
@@ -1,89 +0,0 @@
1
- /*
2
- _ _ __ __
3
- /\ | | | | (_) \ \ / /
4
- / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
- / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
- / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
- /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
- | |
9
- |_|
10
-
11
- Written by: k3yomi@GitHub
12
- */
13
-
14
- let loader = require(`../bootstrap.js`);
15
-
16
- class NoaaWeatherWireServiceVtec {
17
-
18
- /**
19
- * @function getVTEC
20
- * @description Extracts VTEC information from a message and its attributes.
21
- * @param {string} message - The message containing VTEC information.
22
- * @param {object} attributes - The attributes of the message.
23
- */
24
-
25
- getVTEC = function(message, attributes) {
26
- let matches = message.match(new RegExp(loader.definitions.expressions.vtec, 'g'));
27
- if (!matches) return null;
28
- let vtecs = matches.map(match => {
29
- let splitVTEC = match.split(`.`);
30
- let vtecDates = splitVTEC[6].split(`-`);
31
- return {
32
- raw: match,
33
- tracking: this.getTrackingIdentifier(splitVTEC),
34
- event: this.getEventName(splitVTEC),
35
- status: this.getEventStatus(splitVTEC),
36
- wmo: message.match(new RegExp(loader.definitions.expressions.wmo, 'gimu')),
37
- expires: this.getExpires(vtecDates),
38
- issued: attributes.issue
39
- };
40
- });
41
- return vtecs;
42
- }
43
-
44
- /**
45
- * @function getTrackingIdentifier
46
- * @description Constructs a tracking identifier from the VTEC components.
47
- * @param {Array} args - The components of the VTEC string.
48
- */
49
-
50
- getTrackingIdentifier = function(args) {
51
- return `${args[2]}-${args[3]}-${args[4]}-${args[5]}`;
52
- }
53
-
54
- /**
55
- * @function getEventName
56
- * @description Constructs a an event name from the VTEC components.
57
- * @param {Array} args - The components of the VTEC string.
58
- */
59
-
60
- getEventName = function(args) {
61
- return `${loader.definitions.events[args[3]]} ${loader.definitions.actions[args[4]]}`;
62
- }
63
-
64
- /**
65
- * @function getEventStatus
66
- * @description Retrieves the status of the event from the VTEC components. (Issued, Updated, Extended, etc.)
67
- * @param {Array} args - The components of the VTEC string.
68
- */
69
-
70
- getEventStatus = function(args) {
71
- return loader.definitions.status[args[1]]
72
- }
73
-
74
- /**
75
- * @function getExpires
76
- * @description Converts the VTEC expiration date into a standardized format.
77
- * @param {Array} args - The components of the VTEC string.
78
- */
79
-
80
- getExpires = function(args) {
81
- if (args[1] == `000000T0000Z`) return `Invalid Date Format`;
82
- let expires = `${new Date().getFullYear().toString().substring(0, 2)}${args[1].substring(0, 2)}-${args[1].substring(2, 4)}-${args[1].substring(4, 6)}T${args[1].substring(7, 9)}:${args[1].substring(9, 11)}:00`;
83
- let local = new Date(new Date(expires).getTime() - 4 * 60 * 60000);
84
- let pad = n => n.toString().padStart(2, '0');
85
- return `${local.getFullYear()}-${pad(local.getMonth() + 1)}-${pad(local.getDate())}T${pad(local.getHours())}:${pad(local.getMinutes())}:00.000-04:00`;
86
- }
87
- }
88
-
89
- module.exports = new NoaaWeatherWireServiceVtec();