thrustcurve-db 0.3.14 → 1.0.2
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/README.md +53 -47
- package/index.js +1 -5
- package/package.json +5 -2
- package/thrustcurve-db.d.ts +4 -14
- package/thrustcurve-db.json +1608 -26
- package/util.js +0 -126
package/util.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parse a thrustcurve `delays` value to determine all possible motor delay
|
|
3
|
-
* configurations. This is a "loose" parser (will accept some atypical values),
|
|
4
|
-
* but delay strings are generally expected to be formatted as follows:
|
|
5
|
-
*
|
|
6
|
-
* - Delay strings are comma-separated list of values and/or ranges.
|
|
7
|
-
* - Values are non-zero integers, or an Aerotech letter designation of "S",
|
|
8
|
-
* "M", "L", or "X"
|
|
9
|
-
* - Ranges are the numeric min and max value (inclusive), separated by a dash("-")
|
|
10
|
-
*
|
|
11
|
-
* Examples:
|
|
12
|
-
*
|
|
13
|
-
* "4,6,9" = 4, 6, or 9 second delays
|
|
14
|
-
* "5-13" = all delays from 5 to 13 seconds (inclusive)
|
|
15
|
-
* "5-9,11-14" = all delays from 5 to 14 seconds, except 10
|
|
16
|
-
*
|
|
17
|
-
* @param {String} delays
|
|
18
|
-
* @return {Object} with the following properties:
|
|
19
|
-
* - {Number[]} times (seconds)
|
|
20
|
-
* - {Boolean} plugged true if motor can be plugged
|
|
21
|
-
*/
|
|
22
|
-
export function parseDelays(delays) {
|
|
23
|
-
if (typeof(delays) != 'string') throw TypeError('`delays` must be a string');
|
|
24
|
-
|
|
25
|
-
// Remove whitespace
|
|
26
|
-
delays = delays.replace(/\s/g, '');
|
|
27
|
-
|
|
28
|
-
// Kosdon J975F has "23/P" delay. Not really sure what this means, but we
|
|
29
|
-
// map it to "23,P" for now.
|
|
30
|
-
delays = delays.replace(/\//g, ',');
|
|
31
|
-
|
|
32
|
-
// Convert hyphens to commas where it makes sense to do so...
|
|
33
|
-
// "#-#-#..." -> "#,#,#..."
|
|
34
|
-
if (/\d+-\d+-/.test(delays)) {
|
|
35
|
-
delays = delays.replace(/-/g, ',');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// For each item in comma-separated list ...
|
|
39
|
-
let times = new Set();
|
|
40
|
-
let plugged = false;
|
|
41
|
-
for (let v of delays.split(',')) {
|
|
42
|
-
switch (true) {
|
|
43
|
-
// Ignore empty string
|
|
44
|
-
case !v:
|
|
45
|
-
continue;
|
|
46
|
-
|
|
47
|
-
// Single numeric value
|
|
48
|
-
case /^\d+$/.test(v):
|
|
49
|
-
times.add(parseInt(v));
|
|
50
|
-
continue;
|
|
51
|
-
|
|
52
|
-
// Aerotech letter-delays. The Aerotech delay drill tools can remove up
|
|
53
|
-
// to 8 seconds of delay in 2-second increments. There are recommended
|
|
54
|
-
// minimum delay times for the tools, however. Aerotech says to not set
|
|
55
|
-
// delays of less than 6 seconds with the DMS tool, while Sirius
|
|
56
|
-
// Rocketery says no less than 4 seconds for the RMS tool. We don't
|
|
57
|
-
// have access to the motor case info here to determine which tool is
|
|
58
|
-
// involved, but 207 of the 211 AeroTech motors in the TC db are RMS
|
|
59
|
-
// motors at the time I wrote this, so I'm enforcing a 4 second minimum
|
|
60
|
-
// here.
|
|
61
|
-
case v === 'S': [4, 6].forEach(times.add, times); continue;
|
|
62
|
-
case v === 'M': [4, 6, 8, 10].forEach(times.add, times); continue;
|
|
63
|
-
case v === 'L': [6, 8, 10, 12, 14].forEach(times.add, times); continue;
|
|
64
|
-
case v === 'X': [10, 12, 14, 16, 18].forEach(times.add, times); continue;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (/^(\d+)-(\d+)$/.test(v)) {
|
|
68
|
-
let min = parseInt(RegExp.$1);
|
|
69
|
-
let max = parseInt(RegExp.$2);
|
|
70
|
-
if (min > max) [min, max] = [max, min];
|
|
71
|
-
|
|
72
|
-
if (max - min > 20) throw Error(`'Unexpectedly large delay range: ${delays}`);
|
|
73
|
-
for (let d = min; d <= max; d++) times.add(d);
|
|
74
|
-
} else if (v == 'P') {
|
|
75
|
-
plugged = true;
|
|
76
|
-
} else {
|
|
77
|
-
throw Error(`Unrecognized delay value: "${v}"`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
times = [...times].sort((a, b) => a - b);
|
|
82
|
-
|
|
83
|
-
return {times, plugged};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Convert a `delays` structure returned from parseDelays() into a delays
|
|
88
|
-
* string.
|
|
89
|
-
*/
|
|
90
|
-
export function unparseDelays(parsed) {
|
|
91
|
-
const times = [...parsed.times].sort((a, b) => a - b);
|
|
92
|
-
|
|
93
|
-
/*
|
|
94
|
-
// Tack on an ending value (to flush last value in range aggregator loop,
|
|
95
|
-
// below)
|
|
96
|
-
times.push(Symbol());
|
|
97
|
-
|
|
98
|
-
// Build list of delay values, aggregating adjacent values together into a
|
|
99
|
-
// range
|
|
100
|
-
const vals = [];
|
|
101
|
-
let min, max;
|
|
102
|
-
for (const i of times) {
|
|
103
|
-
if (min === undefined) {
|
|
104
|
-
// Do nothing
|
|
105
|
-
} else if (i === max + 1) {
|
|
106
|
-
max = i;
|
|
107
|
-
continue;
|
|
108
|
-
} else if (min === max) {
|
|
109
|
-
vals.push(min);
|
|
110
|
-
} else if (min === max - 1) {
|
|
111
|
-
vals.push(`${min},${max}`);
|
|
112
|
-
} else {
|
|
113
|
-
vals.push(`${min}-${max}`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
min = max = i;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (parsed.plugged) vals.push('P');
|
|
120
|
-
|
|
121
|
-
return vals.join(',');
|
|
122
|
-
*/
|
|
123
|
-
|
|
124
|
-
if (parsed.plugged) times.push('P');
|
|
125
|
-
return times.join(',');
|
|
126
|
-
}
|