thrustcurve-db 0.3.13 → 1.0.1
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 +1345 -174
- package/util.js +0 -101
package/util.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parse a thrustcurve `delays` value to determine all possible motor delay
|
|
3
|
-
* configurations.
|
|
4
|
-
*
|
|
5
|
-
* @param {String} delays
|
|
6
|
-
* @return {Object} with the following properties:
|
|
7
|
-
* - {Number[]} times (seconds)
|
|
8
|
-
* - {Boolean} plugged true if motor can be plugged
|
|
9
|
-
*/
|
|
10
|
-
export function parseDelays(delays) {
|
|
11
|
-
if (typeof(delays) != 'string') throw TypeError('`delays` must be a string');
|
|
12
|
-
|
|
13
|
-
// Remove whitespace
|
|
14
|
-
delays = delays.replace(/\s/g, '');
|
|
15
|
-
|
|
16
|
-
// Kosdon J975F has "23/P" delay. Not really sure what this means, but we
|
|
17
|
-
// map it to "23,P" for now.
|
|
18
|
-
delays = delays.replace(/\//g, ',');
|
|
19
|
-
|
|
20
|
-
// Convert hyphens to commas where it makes sense to do so...
|
|
21
|
-
// "#-#-#..." -> "#,#,#..."
|
|
22
|
-
if (/\d+-\d+-/.test(delays)) {
|
|
23
|
-
delays = delays.replace(/-/g, ',');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// For each item in comma-separated list ...
|
|
27
|
-
let times = new Set();
|
|
28
|
-
let plugged = false;
|
|
29
|
-
for (let v of delays.split(',')) {
|
|
30
|
-
switch (true) {
|
|
31
|
-
// Ignore empty string
|
|
32
|
-
case !v:
|
|
33
|
-
continue;
|
|
34
|
-
|
|
35
|
-
// Single numeric value
|
|
36
|
-
case /^\d+$/.test(v):
|
|
37
|
-
times.add(parseInt(v));
|
|
38
|
-
continue;
|
|
39
|
-
|
|
40
|
-
// Aerotech letter-delays. The Aerotech delay drilling tool can remove up
|
|
41
|
-
// to 8 seconds of delay in 2-second increments. Aerotech warns against
|
|
42
|
-
// delays < 6 seconds for in DMS drill tool instructions. And Sirius
|
|
43
|
-
// Rocketry warns against delays < 4 seconds on their product page for
|
|
44
|
-
// the RMS drill tool.
|
|
45
|
-
case v === 'S': [4, 6].forEach(times.add, times); continue;
|
|
46
|
-
case v === 'M': [4, 6, 8, 10].forEach(times.add, times); continue;
|
|
47
|
-
case v === 'L': [6, 8, 10, 12, 14].forEach(times.add, times); continue;
|
|
48
|
-
case v === 'X': [10, 12, 14, 16, 18].forEach(times.add, times); continue;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (/^(\d+)-(\d+)$/.test(v)) {
|
|
52
|
-
let min = parseInt(RegExp.$1);
|
|
53
|
-
let max = parseInt(RegExp.$2);
|
|
54
|
-
if (min > max) [min, max] = [max, min];
|
|
55
|
-
|
|
56
|
-
if (max - min > 20) throw Error(`'Unexpectedly large delay range: ${delays}`);
|
|
57
|
-
for (let d = min; d <= max; d++) times.add(d);
|
|
58
|
-
} else if (v == 'P') {
|
|
59
|
-
plugged = true;
|
|
60
|
-
} else {
|
|
61
|
-
throw Error(`Unrecognized delay value: "${v}"`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
times = [...times].sort((a, b) => a - b);
|
|
66
|
-
|
|
67
|
-
return {times, plugged};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function unparseDelays(parsed) {
|
|
71
|
-
const times = [...parsed.times].sort((a, b) => a - b);
|
|
72
|
-
|
|
73
|
-
// Tack on an ending value (to flush last value in range aggregator loop,
|
|
74
|
-
// below)
|
|
75
|
-
times.push(Symbol());
|
|
76
|
-
|
|
77
|
-
// Build list of delay values, aggregating adjacent values together into a
|
|
78
|
-
// range
|
|
79
|
-
const vals = [];
|
|
80
|
-
let min, max;
|
|
81
|
-
for (const i of times) {
|
|
82
|
-
if (min === undefined) {
|
|
83
|
-
// Do nothing
|
|
84
|
-
} else if (i === max + 1) {
|
|
85
|
-
max = i;
|
|
86
|
-
continue;
|
|
87
|
-
} else if (min === max) {
|
|
88
|
-
vals.push(min);
|
|
89
|
-
} else if (min === max - 1) {
|
|
90
|
-
vals.push(`${min},${max}`);
|
|
91
|
-
} else {
|
|
92
|
-
vals.push(`${min}-${max}`);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
min = max = i;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (parsed.plugged) vals.push('P');
|
|
99
|
-
|
|
100
|
-
return vals.join(',');
|
|
101
|
-
}
|