@tak-ps/node-cot 2.7.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 -7
- package/lib/util.js +12 -11
- package/lib/xml.js +7 -8
- package/package-lock.json +134 -1833
- package/package.json +1 -1
- package/test/from_geojson.test.js +57 -0
- package/test/util.test.js +34 -0
- package/test/styles.test.js +0 -33
package/CHANGELOG.md
CHANGED
|
@@ -10,14 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
## Version History
|
|
12
12
|
|
|
13
|
-
### v2.
|
|
13
|
+
### v2.8.0
|
|
14
14
|
|
|
15
|
-
- :
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- :tada: Add support for passing style properties via GeoJSON Properties
|
|
20
|
-
- :rocket: Add support for encoding/decoding 32bit signed ARGB values
|
|
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
|
|
21
19
|
|
|
22
20
|
### v2.5.0
|
|
23
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,24 +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(new Date(start)
|
|
104
|
+
stale = new Date(+new Date(start) + 20 * 1000).toISOString();
|
|
102
105
|
} else if (!isNaN(parseInt(stale))) {
|
|
103
|
-
stale = new Date(new Date(start)
|
|
104
|
-
} else if (typeof stale === 'string') {
|
|
105
|
-
stale = new Date(stale).toISOString();
|
|
106
|
+
stale = new Date(+new Date(start) + stale).toISOString();
|
|
106
107
|
}
|
|
107
108
|
|
|
108
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,13 +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 ['type', 'how']) {
|
|
65
|
-
if (feature.properties[key]) cot.event._attributes[key] = feature.properties[key];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const dts = Util.cot_date(feature.properties.time, feature.properties.start, feature.properties.stale);
|
|
69
|
-
Object.assign(cot.event._attributes, dts);
|
|
70
|
-
|
|
71
70
|
if (!feature.geometry) throw new Error('Must have Geometry');
|
|
72
71
|
if (!['Point', 'Polygon', 'LineString'].includes(feature.geometry.type)) throw new Error('Unsupported Geoemtry Type');
|
|
73
72
|
|