@zaes/sidc 0.0.0-stage → 0.2.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 +58 -0
- package/LICENSE +21 -0
- package/README.md +24 -3
- package/THIRD-PARTY-NOTICES +217 -0
- package/dist/cjs/2525c/data2525c.js +1965 -0
- package/dist/cjs/2525c/index.js +178 -0
- package/dist/cjs/catalog/data2525e.js +2704 -0
- package/dist/cjs/catalog/dataApp6e.js +85 -0
- package/dist/cjs/catalog/index.js +137 -0
- package/dist/cjs/catalog/types.js +2 -0
- package/dist/cjs/genc.js +298 -0
- package/dist/cjs/index.js +49 -0
- package/dist/cjs/letter.js +116 -0
- package/dist/cjs/numeric.js +127 -0
- package/dist/cjs/tables.js +151 -0
- package/dist/esm/2525c/data2525c.js +1962 -0
- package/dist/esm/2525c/index.js +174 -0
- package/dist/esm/catalog/data2525e.js +2701 -0
- package/dist/esm/catalog/dataApp6e.js +82 -0
- package/dist/esm/catalog/index.js +130 -0
- package/dist/esm/catalog/types.js +1 -0
- package/dist/esm/genc.js +294 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/letter.js +112 -0
- package/dist/esm/numeric.js +123 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/tables.js +147 -0
- package/dist/types/2525c/data2525c.d.ts +10 -0
- package/dist/types/2525c/index.d.ts +22 -0
- package/dist/types/catalog/data2525e.d.ts +12 -0
- package/dist/types/catalog/dataApp6e.d.ts +15 -0
- package/dist/types/catalog/index.d.ts +31 -0
- package/dist/types/catalog/types.d.ts +46 -0
- package/dist/types/genc.d.ts +12 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/letter.d.ts +51 -0
- package/dist/types/numeric.d.ts +66 -0
- package/dist/types/tables.d.ts +56 -0
- package/package.json +66 -6
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.C_TO_D = void 0;
|
|
4
|
+
exports.convert2525C = convert2525C;
|
|
5
|
+
/**
|
|
6
|
+
* @zaes/sidc/2525c — MIL-STD-2525C letter codes as 2525D codes (2525E for the few that need it). A separate entry, so a host that reads
|
|
7
|
+
* only numeric codes does not carry the crosswalk.
|
|
8
|
+
*
|
|
9
|
+
* A letter code names its symbol with the coding scheme, battle dimension and function ID (positions
|
|
10
|
+
* 1, 3 and 5–10), which the crosswalk turns into a 2525D symbol set, entity and sector modifiers (and version). The
|
|
11
|
+
* positions a letter code fills per use are converted by 2525C Appendix A Tables A-I and A-II: standard
|
|
12
|
+
* identity (2), status (4), symbol modifier (11–12: headquarters, task force, feint/dummy, echelon,
|
|
13
|
+
* mobility, towed array, installation) and country (13–14, ISO 3166-1 two-letter, written as the GENC
|
|
14
|
+
* numeric code in positions 28–30). Order of battle (15) has no 2525D field and is dropped.
|
|
15
|
+
*
|
|
16
|
+
* @module @zaes/sidc/2525c
|
|
17
|
+
*/
|
|
18
|
+
const genc_js_1 = require("../genc.js");
|
|
19
|
+
const letter_js_1 = require("../letter.js");
|
|
20
|
+
const numeric_js_1 = require("../numeric.js");
|
|
21
|
+
const data2525c_js_1 = require("./data2525c.js");
|
|
22
|
+
Object.defineProperty(exports, "C_TO_D", { enumerable: true, get: function () { return data2525c_js_1.C_TO_D; } });
|
|
23
|
+
/** Position 2 (Table A-I): [context, standard identity]. Exercise identities are context 1 in 2525D. */
|
|
24
|
+
const IDENTITY = {
|
|
25
|
+
P: ['0', '0'], U: ['0', '1'], A: ['0', '2'], F: ['0', '3'], N: ['0', '4'], S: ['0', '5'], H: ['0', '6'],
|
|
26
|
+
G: ['1', '0'], W: ['1', '1'], M: ['1', '2'], D: ['1', '3'], L: ['1', '4'], J: ['1', '5'], K: ['1', '6'],
|
|
27
|
+
};
|
|
28
|
+
/** Position 4 (Table A-I) to 2525D status. */
|
|
29
|
+
const STATUS = { A: '1', P: '0', C: '2', D: '3', X: '4', F: '5' };
|
|
30
|
+
/** Position 11 (Table A-II): headquarters, task force and feint/dummy, as 2525D's digit. */
|
|
31
|
+
const HQ_TF_DUMMY = { A: '2', B: '6', C: '3', D: '7', E: '4', F: '1', G: '5' };
|
|
32
|
+
/** Position 12 (Table A-II) with position 11 a dash or A–G: echelon, as 2525D's amplifying descriptor. */
|
|
33
|
+
const ECHELON = {
|
|
34
|
+
A: '11', B: '12', C: '13', D: '14', E: '15', F: '16', G: '17', H: '18',
|
|
35
|
+
I: '21', J: '22', K: '23', L: '24', M: '25', N: '26',
|
|
36
|
+
};
|
|
37
|
+
/** Positions 11–12 (Table A-II), mobility and towed arrays, as 2525D's amplifying descriptor. */
|
|
38
|
+
const MOBILITY = {
|
|
39
|
+
MO: '31', MP: '32', MQ: '33', MR: '34', MS: '35', MT: '36', MW: '37',
|
|
40
|
+
MU: '41', MV: '42', MX: '51', MY: '52', NS: '61', NL: '62',
|
|
41
|
+
};
|
|
42
|
+
const blank = (c) => c === '-' || c === '*';
|
|
43
|
+
/** The crosswalk row for a code, trying parents (the function ID cut back a character at a time) if need be. */
|
|
44
|
+
function lookup(code) {
|
|
45
|
+
const exact = data2525c_js_1.C_TO_D[`=${code}`];
|
|
46
|
+
if (exact)
|
|
47
|
+
return { row: exact, functionId: code.slice(4, 10) };
|
|
48
|
+
let fn = code.slice(4, 10);
|
|
49
|
+
for (;;) {
|
|
50
|
+
const row = data2525c_js_1.C_TO_D[code[0] + code[2] + fn];
|
|
51
|
+
if (row)
|
|
52
|
+
return { row, functionId: fn };
|
|
53
|
+
const last = fn.replace(/-+$/, '').length - 1;
|
|
54
|
+
if (last < 0)
|
|
55
|
+
return undefined;
|
|
56
|
+
fn = `${fn.slice(0, last)}-${fn.slice(last + 1)}`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** The ISO 3166-1 two-letter code as GENC numeric, or undefined. */
|
|
60
|
+
function countryOf(digraph) {
|
|
61
|
+
var _a;
|
|
62
|
+
return (_a = genc_js_1.GENC_COUNTRIES.find((c) => c[2] === digraph)) === null || _a === void 0 ? void 0 : _a[0];
|
|
63
|
+
}
|
|
64
|
+
/** Splits a crosswalk sector value: two digits, or three where the first names the common-modifier table. */
|
|
65
|
+
function sector(value) {
|
|
66
|
+
return value.length === 3 ? { identifier: value[0], code: value.slice(1) } : { identifier: '0', code: value };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Converts a 2525C letter code to a 30-position 2525D (or 2525E) code. A function ID the crosswalk does not list
|
|
70
|
+
* is converted as its nearest listed parent, with a problem; values the tables don't define are
|
|
71
|
+
* problems too, and only a code with no listed parent at all fails.
|
|
72
|
+
*/
|
|
73
|
+
function convert2525C(input) {
|
|
74
|
+
var _a, _b, _c;
|
|
75
|
+
const parsed = (0, letter_js_1.parseLetterSidc)(input);
|
|
76
|
+
if (!parsed.ok)
|
|
77
|
+
return parsed;
|
|
78
|
+
const problems = [...parsed.problems];
|
|
79
|
+
const code = parsed.sidc.code;
|
|
80
|
+
// The special C2 headquarters component (S*G*UH----, 2525C Table VI field AA, APP-6(B) figure 9): a
|
|
81
|
+
// headquarters, its name (AA) in the frame. The crosswalk has no row for it; 2525D/E draw it as
|
|
82
|
+
// Command and Control (10 110000), whose drawing is the AA field, with the headquarters staff.
|
|
83
|
+
const specialC2 = code[0] === 'S' && code[2] === 'G' && code.slice(4, 10) === 'UH----';
|
|
84
|
+
// The sea surface and subsurface dimensions themselves (S*S*------, S*U*------): the crosswalk lists the
|
|
85
|
+
// other dimensions' roots but not these two; each is its symbol set's frame with no icon.
|
|
86
|
+
// They are also the last parent of a function ID with no listed parent (APP-6(B)'s Iceberg, S*S*ZI).
|
|
87
|
+
const rootSet = code[0] === 'S' ? { S: '30', U: '35' }[code[2]] : undefined;
|
|
88
|
+
const rootRow = rootSet ? { row: ['11', rootSet, '000000', '00', '00', ''], functionId: '------' } : undefined;
|
|
89
|
+
const found = specialC2
|
|
90
|
+
? { row: ['11', '10', '110000', '00', '00', ''], functionId: 'UH----' }
|
|
91
|
+
: rootRow && code.slice(4, 10) === '------'
|
|
92
|
+
? rootRow
|
|
93
|
+
: ((_a = lookup(code)) !== null && _a !== void 0 ? _a : rootRow);
|
|
94
|
+
if (!found)
|
|
95
|
+
return { ok: false, problems: [...problems, { position: 5, message: `${code} is not in the 2525C crosswalk` }] };
|
|
96
|
+
const [version, symbolSet, entityCode, s1, s2, note] = found.row;
|
|
97
|
+
if (found.functionId !== code.slice(4, 10)) {
|
|
98
|
+
problems.push({ position: 5, message: `function ID ${code.slice(4, 10)} is not in the 2525C crosswalk: drawn as ${found.functionId}` });
|
|
99
|
+
}
|
|
100
|
+
const metoc = code[0] === 'W';
|
|
101
|
+
const graphic = code[0] === 'G';
|
|
102
|
+
const [context, standardIdentity] = metoc ? ['0', '0'] : (_b = IDENTITY[code[1]]) !== null && _b !== void 0 ? _b : ['0', '1'];
|
|
103
|
+
const status = metoc || blank(code[3]) ? '0' : (_c = STATUS[code[3]]) !== null && _c !== void 0 ? _c : '0';
|
|
104
|
+
let hqTfDummy = specialC2 ? '2' : '0';
|
|
105
|
+
let amplifyingDescriptor = '00';
|
|
106
|
+
if (!metoc && !graphic) {
|
|
107
|
+
const [m1, m2] = [code[10], code[11]];
|
|
108
|
+
const pair = m1 + m2;
|
|
109
|
+
if (m1 === 'H') {
|
|
110
|
+
if (m2 === 'B')
|
|
111
|
+
hqTfDummy = '1';
|
|
112
|
+
else if (!blank(m2))
|
|
113
|
+
problems.push({ position: 12, message: `installation modifier ${m2} is not defined` });
|
|
114
|
+
}
|
|
115
|
+
else if (m1 === 'M' || m1 === 'N') {
|
|
116
|
+
if (MOBILITY[pair])
|
|
117
|
+
amplifyingDescriptor = MOBILITY[pair];
|
|
118
|
+
else
|
|
119
|
+
problems.push({ position: 11, message: `mobility modifier ${pair} is not defined` });
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
if (!blank(m1)) {
|
|
123
|
+
if (HQ_TF_DUMMY[m1])
|
|
124
|
+
hqTfDummy = HQ_TF_DUMMY[m1];
|
|
125
|
+
else
|
|
126
|
+
problems.push({ position: 11, message: `symbol modifier ${m1} is not defined` });
|
|
127
|
+
}
|
|
128
|
+
if (!blank(m2)) {
|
|
129
|
+
if (ECHELON[m2])
|
|
130
|
+
amplifyingDescriptor = ECHELON[m2];
|
|
131
|
+
else
|
|
132
|
+
problems.push({ position: 12, message: `echelon ${m2} is not defined` });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
let country = '000';
|
|
137
|
+
const digraph = code.slice(12, 14);
|
|
138
|
+
if (!metoc && /^[A-Z]{2}$/.test(digraph)) {
|
|
139
|
+
const numeric = countryOf(digraph);
|
|
140
|
+
if (numeric)
|
|
141
|
+
country = numeric;
|
|
142
|
+
else
|
|
143
|
+
problems.push({ position: 13, message: `country ${digraph} is not a GENC code` });
|
|
144
|
+
}
|
|
145
|
+
let one = sector(s1);
|
|
146
|
+
const two = sector(s2);
|
|
147
|
+
let v = version;
|
|
148
|
+
// A symbol defined at team level (2525C's Emergency Team, E*O*BJ) is the crosswalk's common modifier
|
|
149
|
+
// Team/Crew (support level, 162). 2525C draws it as the team echelon above the frame: with no echelon
|
|
150
|
+
// of its own, the code takes echelon Team/Crew, and the modifier (and 2525E's version for it) goes.
|
|
151
|
+
if (one.identifier === '1' && one.code === '62' && amplifyingDescriptor === '00' && two.code === '00') {
|
|
152
|
+
amplifyingDescriptor = '11';
|
|
153
|
+
one = { code: '00', identifier: '0' };
|
|
154
|
+
v = '11';
|
|
155
|
+
}
|
|
156
|
+
const sidc = (0, numeric_js_1.formatNumericSidc)({
|
|
157
|
+
version: v,
|
|
158
|
+
context,
|
|
159
|
+
standardIdentity,
|
|
160
|
+
symbolSet,
|
|
161
|
+
status,
|
|
162
|
+
hqTfDummy,
|
|
163
|
+
amplifyingDescriptor,
|
|
164
|
+
entityCode,
|
|
165
|
+
sector1: one.code,
|
|
166
|
+
sector2: two.code,
|
|
167
|
+
sector1Identifier: one.identifier,
|
|
168
|
+
sector2Identifier: two.identifier,
|
|
169
|
+
country,
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
ok: true,
|
|
173
|
+
sidc,
|
|
174
|
+
problems,
|
|
175
|
+
...(note ? { note } : {}),
|
|
176
|
+
...(found.functionId !== code.slice(4, 10) ? { matched: found.functionId } : {}),
|
|
177
|
+
};
|
|
178
|
+
}
|