@tak-ps/node-cot 2.6.0 → 2.8.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 +5 -3
- package/lib/util.js +12 -9
- package/lib/xml.js +7 -5
- package/package-lock.json +2567 -0
- package/package.json +1 -1
- package/test/from_geojson.test.js +58 -1
- package/test/util.test.js +34 -0
- package/test/styles.test.js +0 -33
package/CHANGELOG.md
CHANGED
|
@@ -10,10 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
## Version History
|
|
12
12
|
|
|
13
|
-
### v2.
|
|
13
|
+
### v2.8.0
|
|
14
14
|
|
|
15
|
-
- :
|
|
16
|
-
- :
|
|
15
|
+
- :bug: Significant improvements to start/time/stale parsing
|
|
16
|
+
- :white_check_mark: Add tests for date parsing
|
|
17
|
+
- :rocket: Support parsing `Date` types
|
|
18
|
+
- :arrow_up: General Dep Update
|
|
17
19
|
|
|
18
20
|
### v2.5.0
|
|
19
21
|
|
package/lib/util.js
CHANGED
|
@@ -10,10 +10,13 @@ export default class Util {
|
|
|
10
10
|
*
|
|
11
11
|
* @param {String} type CoT Type
|
|
12
12
|
* @param {String} how CoT how
|
|
13
|
+
* @param {Date|string|null} time Time of CoT Message - if omitted, current time is used
|
|
14
|
+
* @param {Date|string|null} start Start Time of CoT - if omitted, current time is used
|
|
15
|
+
* @param {Date|string|null|numeric} stale Expiration of CoT - if null now+20s is used. Alternative an integer representing the ms offset
|
|
13
16
|
*
|
|
14
17
|
* @returns {Object}
|
|
15
18
|
*/
|
|
16
|
-
static cot_event_attr(type, how) {
|
|
19
|
+
static cot_event_attr(type, how, time, start, stale) {
|
|
17
20
|
if (!type) throw new Error('type param required');
|
|
18
21
|
if (!how) throw new Error('how param required');
|
|
19
22
|
|
|
@@ -22,7 +25,7 @@ export default class Util {
|
|
|
22
25
|
...Util.cot_uuid(),
|
|
23
26
|
type,
|
|
24
27
|
how,
|
|
25
|
-
...Util.cot_date()
|
|
28
|
+
...Util.cot_date(time, start, stale)
|
|
26
29
|
};
|
|
27
30
|
}
|
|
28
31
|
|
|
@@ -85,22 +88,22 @@ export default class Util {
|
|
|
85
88
|
*
|
|
86
89
|
* cot_date() - Time: now, Start: now, Stale: now + 20s
|
|
87
90
|
*
|
|
88
|
-
* @param {Date|null} time Time of CoT Message - if omitted, current time is used
|
|
89
|
-
* @param {Date|null} start Start Time of CoT - if omitted, current time is used
|
|
90
|
-
* @param {Date|null|numeric} stale Expiration of CoT - if null now+20s is used. Alternative an integer representing the
|
|
91
|
+
* @param {Date|string|null} time Time of CoT Message - if omitted, current time is used
|
|
92
|
+
* @param {Date|string|null} start Start Time of CoT - if omitted, current time is used
|
|
93
|
+
* @param {Date|string|null|numeric} stale Expiration of CoT - if null now+20s is used. Alternative an integer representing the ms offset
|
|
91
94
|
*
|
|
92
95
|
* @returns {Object}
|
|
93
96
|
*/
|
|
94
97
|
static cot_date(time, start, stale) {
|
|
95
98
|
const now = Date.now();
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
time = new Date(time || now).toISOString();
|
|
101
|
+
start = new Date(start || now).toISOString();
|
|
99
102
|
|
|
100
103
|
if (!stale) {
|
|
101
|
-
stale = new Date(
|
|
104
|
+
stale = new Date(+new Date(start) + 20 * 1000).toISOString();
|
|
102
105
|
} else if (!isNaN(parseInt(stale))) {
|
|
103
|
-
stale = new Date(
|
|
106
|
+
stale = new Date(+new Date(start) + stale).toISOString();
|
|
104
107
|
}
|
|
105
108
|
|
|
106
109
|
return { time, start, stale };
|
package/lib/xml.js
CHANGED
|
@@ -52,7 +52,13 @@ export default class XMLCot {
|
|
|
52
52
|
|
|
53
53
|
const cot = {
|
|
54
54
|
event: {
|
|
55
|
-
_attributes: Util.cot_event_attr(
|
|
55
|
+
_attributes: Util.cot_event_attr(
|
|
56
|
+
feature.properties.type || 'a-f-G',
|
|
57
|
+
feature.properties.how || 'm-g',
|
|
58
|
+
feature.properties.time,
|
|
59
|
+
feature.properties.start,
|
|
60
|
+
feature.properties.stale
|
|
61
|
+
),
|
|
56
62
|
point: Util.cot_point(),
|
|
57
63
|
detail: Util.cot_event_detail(feature.properties.callsign)
|
|
58
64
|
}
|
|
@@ -61,10 +67,6 @@ export default class XMLCot {
|
|
|
61
67
|
if (feature.id) cot.event._attributes.uid = feature.id;
|
|
62
68
|
if (feature.properties.callsign && !feature.id) cot.event._attributes.uid = feature.properties.callsign;
|
|
63
69
|
|
|
64
|
-
for (const key of ['time', 'start', 'stale', 'type', 'how']) {
|
|
65
|
-
if (feature.properties[key]) cot.event._attributes[key] = feature.properties[key];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
70
|
if (!feature.geometry) throw new Error('Must have Geometry');
|
|
69
71
|
if (!['Point', 'Polygon', 'LineString'].includes(feature.geometry.type)) throw new Error('Unsupported Geoemtry Type');
|
|
70
72
|
|