@zaes/sidc 0.0.0-stage → 0.1.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.
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @zaes/sidc/catalog — what every 2525E Change 1 code means: entity names and hierarchy, what kind of
3
+ * drawing each is, its draw rule or icon type, and every sector modifier.
4
+ *
5
+ * A separate entry so that reading a code does not cost the ~175 KB of tables.
6
+ *
7
+ * @module @zaes/sidc/catalog
8
+ */
9
+ import { parseSidc } from '../index.js';
10
+ import { ENTITIES_2525E, MODIFIERS_2525E } from './data2525e.js';
11
+ let entities;
12
+ let modifiers;
13
+ const entityKey = (symbolSet, code) => `${symbolSet}:${code}`;
14
+ const modifierKey = (symbolSet, sector, code) => `${symbolSet}:${sector}:${code}`;
15
+ function entityIndex() {
16
+ if (entities)
17
+ return entities;
18
+ const rows = new Map(ENTITIES_2525E.map((r) => [entityKey(r[0], r[1]), r]));
19
+ entities = new Map();
20
+ for (const [key, [symbolSet, code, name, kind, geometry, drawRule, iconType]] of rows) {
21
+ const path = [];
22
+ const entity = rows.get(entityKey(symbolSet, code.slice(0, 2) + '0000'));
23
+ const type = rows.get(entityKey(symbolSet, code.slice(0, 4) + '00'));
24
+ if (code !== '000000') {
25
+ if (entity && entity[1] !== code)
26
+ path.push(entity[2]);
27
+ if (type && type[1] !== code && type[1] !== (entity === null || entity === void 0 ? void 0 : entity[1]))
28
+ path.push(type[2]);
29
+ }
30
+ path.push(name);
31
+ entities.set(key, {
32
+ symbolSet,
33
+ code,
34
+ name,
35
+ path,
36
+ kind,
37
+ ...(geometry ? { tableGeometry: geometry } : {}),
38
+ ...(drawRule ? { drawRule, drawRuleAppendix: symbolSet === '45' || symbolSet === '46' ? 'M' : 'L' } : {}),
39
+ ...(iconType ? { iconType } : {}),
40
+ });
41
+ }
42
+ return entities;
43
+ }
44
+ function modifierIndex() {
45
+ if (modifiers)
46
+ return modifiers;
47
+ modifiers = new Map(MODIFIERS_2525E.map(([symbolSet, sector, code, name, category]) => [
48
+ modifierKey(symbolSet, sector, code),
49
+ { symbolSet, sector: sector, code, name, category },
50
+ ]));
51
+ return modifiers;
52
+ }
53
+ /** The entity a symbol set and positions 11–16 name, or undefined if 2525E Change 1 has none. */
54
+ export function getEntity(symbolSet, code) {
55
+ return entityIndex().get(entityKey(symbolSet, code));
56
+ }
57
+ /** Every entity, in the standard's order, optionally of one symbol set or kind. */
58
+ export function listEntities(filter = {}) {
59
+ return [...entityIndex().values()].filter((e) => (!filter.symbolSet || e.symbolSet === filter.symbolSet) && (!filter.kind || e.kind === filter.kind));
60
+ }
61
+ /**
62
+ * The sector modifier a code names. `identifier` is SIDC position 21 (sector 1) or 22 (sector 2):
63
+ * '0' looks in the symbol set's own table, anything else in the common table (A-IX, A-X), whose
64
+ * codes are the identifier followed by the two modifier positions.
65
+ */
66
+ export function getSectorModifier(symbolSet, sector, code, identifier = '0') {
67
+ return identifier === '0' ? modifierIndex().get(modifierKey(symbolSet, sector, code)) : modifierIndex().get(modifierKey('common', sector, identifier + code));
68
+ }
69
+ /** The sector modifiers of one symbol set (or `common`), in the standard's order. */
70
+ export function listSectorModifiers(symbolSet, sector) {
71
+ return [...modifierIndex().values()].filter((m) => m.symbolSet === symbolSet && m.sector === sector);
72
+ }
73
+ /** What positions 11–20 of a 2525D/E code mean, by the 2525E Change 1 tables. */
74
+ export function describeSidc(sidc) {
75
+ const parsed = typeof sidc === 'string' ? parseSidc(sidc) : { ok: true, sidc, problems: [] };
76
+ if (!parsed.ok)
77
+ return { problems: parsed.problems.map((p) => p.message) };
78
+ if (parsed.sidc.kind !== 'numeric')
79
+ return { problems: ['a 2525C letter code; convert it before describing it'] };
80
+ const s = parsed.sidc;
81
+ const problems = [];
82
+ const entity = getEntity(s.symbolSet, s.entityCode);
83
+ if (!entity)
84
+ problems.push(`entity ${s.entityCode} is not in symbol set ${s.symbolSet}`);
85
+ const modifier = (sector, code, identifier) => {
86
+ if (code === '00')
87
+ return undefined;
88
+ const m = getSectorModifier(s.symbolSet, sector, code, identifier);
89
+ if (!m)
90
+ problems.push(`sector ${sector} modifier ${identifier === '0' ? '' : identifier}${code} is not defined for symbol set ${s.symbolSet}`);
91
+ return m;
92
+ };
93
+ const sector1 = modifier(1, s.sector1, s.sector1Identifier);
94
+ const sector2 = modifier(2, s.sector2, s.sector2Identifier);
95
+ return { ...(entity ? { entity } : {}), ...(sector1 ? { sector1 } : {}), ...(sector2 ? { sector2 } : {}), problems };
96
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,294 @@
1
+ /**
2
+ * GENC (Geopolitical Entities, Names, and Codes) countries and entities by numeric code: SIDC
3
+ * positions 28–30 (MIL-STD-2525E A.5.5.4). Generated; do not edit.
4
+ */
5
+ /** [numeric, trigraph, digraph ('' where none is assigned), name]. 280 entries. */
6
+ export const GENC_COUNTRIES = [
7
+ ["004", "AFG", "AF", "AFGHANISTAN"],
8
+ ["008", "ALB", "AL", "ALBANIA"],
9
+ ["010", "ATA", "AQ", "ANTARCTICA"],
10
+ ["012", "DZA", "DZ", "ALGERIA"],
11
+ ["016", "ASM", "AS", "AMERICAN SAMOA"],
12
+ ["020", "AND", "AD", "ANDORRA"],
13
+ ["024", "AGO", "AO", "ANGOLA"],
14
+ ["028", "ATG", "AG", "ANTIGUA AND BARBUDA"],
15
+ ["031", "AZE", "AZ", "AZERBAIJAN"],
16
+ ["032", "ARG", "AR", "ARGENTINA"],
17
+ ["036", "AUS", "AU", "AUSTRALIA"],
18
+ ["040", "AUT", "AT", "AUSTRIA"],
19
+ ["044", "BHS", "BS", "BAHAMAS, THE"],
20
+ ["048", "BHR", "BH", "BAHRAIN"],
21
+ ["050", "BGD", "BD", "BANGLADESH"],
22
+ ["051", "ARM", "AM", "ARMENIA"],
23
+ ["052", "BRB", "BB", "BARBADOS"],
24
+ ["056", "BEL", "BE", "BELGIUM"],
25
+ ["060", "BMU", "BM", "BERMUDA"],
26
+ ["064", "BTN", "BT", "BHUTAN"],
27
+ ["068", "BOL", "BO", "BOLIVIA"],
28
+ ["070", "BIH", "BA", "BOSNIA AND HERZEGOVINA"],
29
+ ["072", "BWA", "BW", "BOTSWANA"],
30
+ ["074", "BVT", "BV", "BOUVET ISLAND"],
31
+ ["076", "BRA", "BR", "BRAZIL"],
32
+ ["084", "BLZ", "BZ", "BELIZE"],
33
+ ["086", "IOT", "IO", "BRITISH INDIAN OCEAN TERRITORY"],
34
+ ["090", "SLB", "SB", "SOLOMON ISLANDS"],
35
+ ["092", "VGB", "VG", "VIRGIN ISLANDS, BRITISH"],
36
+ ["096", "BRN", "BN", "BRUNEI"],
37
+ ["100", "BGR", "BG", "BULGARIA"],
38
+ ["104", "MMR", "MM", "BURMA"],
39
+ ["108", "BDI", "BI", "BURUNDI"],
40
+ ["112", "BLR", "BY", "BELARUS"],
41
+ ["116", "KHM", "KH", "CAMBODIA"],
42
+ ["120", "CMR", "CM", "CAMEROON"],
43
+ ["124", "CAN", "CA", "CANADA"],
44
+ ["132", "CPV", "CV", "CABO VERDE"],
45
+ ["136", "CYM", "KY", "CAYMAN ISLANDS"],
46
+ ["140", "CAF", "CF", "CENTRAL AFRICAN REPUBLIC"],
47
+ ["144", "LKA", "LK", "SRI LANKA"],
48
+ ["148", "TCD", "TD", "CHAD"],
49
+ ["152", "CHL", "CL", "CHILE"],
50
+ ["156", "CHN", "CN", "CHINA"],
51
+ ["158", "TWN", "TW", "TAIWAN"],
52
+ ["162", "CXR", "CX", "CHRISTMAS ISLAND"],
53
+ ["166", "CCK", "CC", "COCOS (KEELING) ISLANDS"],
54
+ ["170", "COL", "CO", "COLOMBIA"],
55
+ ["174", "COM", "KM", "COMOROS"],
56
+ ["175", "MYT", "YT", "MAYOTTE"],
57
+ ["178", "COG", "CG", "CONGO (BRAZZAVILLE)"],
58
+ ["180", "COD", "CD", "CONGO (KINSHASA)"],
59
+ ["184", "COK", "CK", "COOK ISLANDS"],
60
+ ["188", "CRI", "CR", "COSTA RICA"],
61
+ ["191", "HRV", "HR", "CROATIA"],
62
+ ["192", "CUB", "CU", "CUBA"],
63
+ ["196", "CYP", "CY", "CYPRUS"],
64
+ ["203", "CZE", "CZ", "CZECHIA"],
65
+ ["204", "BEN", "BJ", "BENIN"],
66
+ ["208", "DNK", "DK", "DENMARK"],
67
+ ["212", "DMA", "DM", "DOMINICA"],
68
+ ["214", "DOM", "DO", "DOMINICAN REPUBLIC"],
69
+ ["218", "ECU", "EC", "ECUADOR"],
70
+ ["222", "SLV", "SV", "EL SALVADOR"],
71
+ ["226", "GNQ", "GQ", "EQUATORIAL GUINEA"],
72
+ ["231", "ETH", "ET", "ETHIOPIA"],
73
+ ["232", "ERI", "ER", "ERITREA"],
74
+ ["233", "EST", "EE", "ESTONIA"],
75
+ ["234", "FRO", "FO", "FAROE ISLANDS"],
76
+ ["238", "FLK", "FK", "FALKLAND ISLANDS (ISLAS MALVINAS)"],
77
+ ["239", "SGS", "GS", "SOUTH GEORGIA AND SOUTH SANDWICH ISLANDS"],
78
+ ["242", "FJI", "FJ", "FIJI"],
79
+ ["246", "FIN", "FI", "FINLAND"],
80
+ ["250", "FRA", "FR", "FRANCE"],
81
+ ["254", "GUF", "GF", "FRENCH GUIANA"],
82
+ ["258", "PYF", "PF", "FRENCH POLYNESIA"],
83
+ ["260", "ATF", "TF", "FRENCH SOUTHERN AND ANTARCTIC LANDS"],
84
+ ["262", "DJI", "DJ", "DJIBOUTI"],
85
+ ["266", "GAB", "GA", "GABON"],
86
+ ["268", "GEO", "GE", "GEORGIA"],
87
+ ["270", "GMB", "GM", "GAMBIA, THE"],
88
+ ["276", "DEU", "DE", "GERMANY"],
89
+ ["288", "GHA", "GH", "GHANA"],
90
+ ["292", "GIB", "GI", "GIBRALTAR"],
91
+ ["296", "KIR", "KI", "KIRIBATI"],
92
+ ["300", "GRC", "GR", "GREECE"],
93
+ ["304", "GRL", "GL", "GREENLAND"],
94
+ ["308", "GRD", "GD", "GRENADA"],
95
+ ["312", "GLP", "GP", "GUADELOUPE"],
96
+ ["316", "GUM", "GU", "GUAM"],
97
+ ["320", "GTM", "GT", "GUATEMALA"],
98
+ ["324", "GIN", "GN", "GUINEA"],
99
+ ["328", "GUY", "GY", "GUYANA"],
100
+ ["332", "HTI", "HT", "HAITI"],
101
+ ["334", "HMD", "HM", "HEARD ISLAND AND MCDONALD ISLANDS"],
102
+ ["336", "VAT", "VA", "VATICAN CITY"],
103
+ ["340", "HND", "HN", "HONDURAS"],
104
+ ["344", "HKG", "HK", "HONG KONG"],
105
+ ["348", "HUN", "HU", "HUNGARY"],
106
+ ["352", "ISL", "IS", "ICELAND"],
107
+ ["356", "IND", "IN", "INDIA"],
108
+ ["360", "IDN", "ID", "INDONESIA"],
109
+ ["364", "IRN", "IR", "IRAN"],
110
+ ["368", "IRQ", "IQ", "IRAQ"],
111
+ ["372", "IRL", "IE", "IRELAND"],
112
+ ["376", "ISR", "IL", "ISRAEL"],
113
+ ["380", "ITA", "IT", "ITALY"],
114
+ ["384", "CIV", "CI", "CÔTE D’IVOIRE"],
115
+ ["388", "JAM", "JM", "JAMAICA"],
116
+ ["392", "JPN", "JP", "JAPAN"],
117
+ ["398", "KAZ", "KZ", "KAZAKHSTAN"],
118
+ ["400", "JOR", "JO", "JORDAN"],
119
+ ["404", "KEN", "KE", "KENYA"],
120
+ ["408", "PRK", "KP", "KOREA, NORTH"],
121
+ ["410", "KOR", "KR", "KOREA, SOUTH"],
122
+ ["414", "KWT", "KW", "KUWAIT"],
123
+ ["417", "KGZ", "KG", "KYRGYZSTAN"],
124
+ ["418", "LAO", "LA", "LAOS"],
125
+ ["422", "LBN", "LB", "LEBANON"],
126
+ ["426", "LSO", "LS", "LESOTHO"],
127
+ ["428", "LVA", "LV", "LATVIA"],
128
+ ["430", "LBR", "LR", "LIBERIA"],
129
+ ["434", "LBY", "LY", "LIBYA"],
130
+ ["438", "LIE", "LI", "LIECHTENSTEIN"],
131
+ ["440", "LTU", "LT", "LITHUANIA"],
132
+ ["442", "LUX", "LU", "LUXEMBOURG"],
133
+ ["446", "MAC", "MO", "MACAU"],
134
+ ["450", "MDG", "MG", "MADAGASCAR"],
135
+ ["454", "MWI", "MW", "MALAWI"],
136
+ ["458", "MYS", "MY", "MALAYSIA"],
137
+ ["462", "MDV", "MV", "MALDIVES"],
138
+ ["466", "MLI", "ML", "MALI"],
139
+ ["470", "MLT", "MT", "MALTA"],
140
+ ["474", "MTQ", "MQ", "MARTINIQUE"],
141
+ ["478", "MRT", "MR", "MAURITANIA"],
142
+ ["480", "MUS", "MU", "MAURITIUS"],
143
+ ["484", "MEX", "MX", "MEXICO"],
144
+ ["492", "MCO", "MC", "MONACO"],
145
+ ["496", "MNG", "MN", "MONGOLIA"],
146
+ ["498", "MDA", "MD", "MOLDOVA"],
147
+ ["499", "MNE", "ME", "MONTENEGRO"],
148
+ ["500", "MSR", "MS", "MONTSERRAT"],
149
+ ["504", "MAR", "MA", "MOROCCO"],
150
+ ["508", "MOZ", "MZ", "MOZAMBIQUE"],
151
+ ["512", "OMN", "OM", "OMAN"],
152
+ ["516", "NAM", "NA", "NAMIBIA"],
153
+ ["520", "NRU", "NR", "NAURU"],
154
+ ["524", "NPL", "NP", "NEPAL"],
155
+ ["528", "NLD", "NL", "NETHERLANDS"],
156
+ ["531", "CUW", "CW", "CURAÇAO"],
157
+ ["533", "ABW", "AW", "ARUBA"],
158
+ ["534", "SXM", "SX", "SINT MAARTEN"],
159
+ ["535", "BES", "BQ", "BONAIRE, SINT EUSTATIUS, AND SABA"],
160
+ ["540", "NCL", "NC", "NEW CALEDONIA"],
161
+ ["548", "VUT", "VU", "VANUATU"],
162
+ ["554", "NZL", "NZ", "NEW ZEALAND"],
163
+ ["558", "NIC", "NI", "NICARAGUA"],
164
+ ["562", "NER", "NE", "NIGER"],
165
+ ["566", "NGA", "NG", "NIGERIA"],
166
+ ["570", "NIU", "NU", "NIUE"],
167
+ ["574", "NFK", "NF", "NORFOLK ISLAND"],
168
+ ["578", "NOR", "NO", "NORWAY"],
169
+ ["580", "MNP", "MP", "NORTHERN MARIANA ISLANDS"],
170
+ ["583", "FSM", "FM", "MICRONESIA, FEDERATED STATES OF"],
171
+ ["584", "MHL", "MH", "MARSHALL ISLANDS"],
172
+ ["585", "PLW", "PW", "PALAU"],
173
+ ["586", "PAK", "PK", "PAKISTAN"],
174
+ ["591", "PAN", "PA", "PANAMA"],
175
+ ["598", "PNG", "PG", "PAPUA NEW GUINEA"],
176
+ ["600", "PRY", "PY", "PARAGUAY"],
177
+ ["604", "PER", "PE", "PERU"],
178
+ ["608", "PHL", "PH", "PHILIPPINES"],
179
+ ["612", "PCN", "PN", "PITCAIRN ISLANDS"],
180
+ ["616", "POL", "PL", "POLAND"],
181
+ ["620", "PRT", "PT", "PORTUGAL"],
182
+ ["624", "GNB", "GW", "GUINEA-BISSAU"],
183
+ ["626", "TLS", "TL", "TIMOR-LESTE"],
184
+ ["630", "PRI", "PR", "PUERTO RICO"],
185
+ ["634", "QAT", "QA", "QATAR"],
186
+ ["638", "REU", "RE", "REUNION"],
187
+ ["642", "ROU", "RO", "ROMANIA"],
188
+ ["643", "RUS", "RU", "RUSSIA"],
189
+ ["646", "RWA", "RW", "RWANDA"],
190
+ ["652", "BLM", "BL", "SAINT BARTHELEMY"],
191
+ ["654", "SHN", "SH", "SAINT HELENA, ASCENSION, AND TRISTAN DA CUNHA"],
192
+ ["659", "KNA", "KN", "SAINT KITTS AND NEVIS"],
193
+ ["660", "AIA", "AI", "ANGUILLA"],
194
+ ["662", "LCA", "LC", "SAINT LUCIA"],
195
+ ["663", "MAF", "MF", "SAINT MARTIN"],
196
+ ["666", "SPM", "PM", "SAINT PIERRE AND MIQUELON"],
197
+ ["670", "VCT", "VC", "SAINT VINCENT AND THE GRENADINES"],
198
+ ["674", "SMR", "SM", "SAN MARINO"],
199
+ ["678", "STP", "ST", "SAO TOME AND PRINCIPE"],
200
+ ["682", "SAU", "SA", "SAUDI ARABIA"],
201
+ ["686", "SEN", "SN", "SENEGAL"],
202
+ ["688", "SRB", "RS", "SERBIA"],
203
+ ["690", "SYC", "SC", "SEYCHELLES"],
204
+ ["694", "SLE", "SL", "SIERRA LEONE"],
205
+ ["702", "SGP", "SG", "SINGAPORE"],
206
+ ["703", "SVK", "SK", "SLOVAKIA"],
207
+ ["704", "VNM", "VN", "VIETNAM"],
208
+ ["705", "SVN", "SI", "SLOVENIA"],
209
+ ["706", "SOM", "SO", "SOMALIA"],
210
+ ["710", "ZAF", "ZA", "SOUTH AFRICA"],
211
+ ["716", "ZWE", "ZW", "ZIMBABWE"],
212
+ ["724", "ESP", "ES", "SPAIN"],
213
+ ["728", "SSD", "SS", "SOUTH SUDAN"],
214
+ ["729", "SDN", "SD", "SUDAN"],
215
+ ["732", "ESH", "EH", "WESTERN SAHARA"],
216
+ ["740", "SUR", "SR", "SURINAME"],
217
+ ["748", "SWZ", "SZ", "ESWATINI"],
218
+ ["752", "SWE", "SE", "SWEDEN"],
219
+ ["756", "CHE", "CH", "SWITZERLAND"],
220
+ ["760", "SYR", "SY", "SYRIA"],
221
+ ["762", "TJK", "TJ", "TAJIKISTAN"],
222
+ ["764", "THA", "TH", "THAILAND"],
223
+ ["768", "TGO", "TG", "TOGO"],
224
+ ["772", "TKL", "TK", "TOKELAU"],
225
+ ["776", "TON", "TO", "TONGA"],
226
+ ["780", "TTO", "TT", "TRINIDAD AND TOBAGO"],
227
+ ["784", "ARE", "AE", "UNITED ARAB EMIRATES"],
228
+ ["788", "TUN", "TN", "TUNISIA"],
229
+ ["792", "TUR", "TR", "TURKEY"],
230
+ ["795", "TKM", "TM", "TURKMENISTAN"],
231
+ ["796", "TCA", "TC", "TURKS AND CAICOS ISLANDS"],
232
+ ["798", "TUV", "TV", "TUVALU"],
233
+ ["800", "UGA", "UG", "UGANDA"],
234
+ ["804", "UKR", "UA", "UKRAINE"],
235
+ ["807", "MKD", "MK", "NORTH MACEDONIA"],
236
+ ["818", "EGY", "EG", "EGYPT"],
237
+ ["826", "GBR", "GB", "UNITED KINGDOM"],
238
+ ["831", "GGY", "GG", "GUERNSEY"],
239
+ ["832", "JEY", "JE", "JERSEY"],
240
+ ["833", "IMN", "IM", "ISLE OF MAN"],
241
+ ["834", "TZA", "TZ", "TANZANIA"],
242
+ ["840", "USA", "US", "UNITED STATES"],
243
+ ["850", "VIR", "VI", "VIRGIN ISLANDS, U.S."],
244
+ ["854", "BFA", "BF", "BURKINA FASO"],
245
+ ["858", "URY", "UY", "URUGUAY"],
246
+ ["860", "UZB", "UZ", "UZBEKISTAN"],
247
+ ["862", "VEN", "VE", "VENEZUELA"],
248
+ ["876", "WLF", "WF", "WALLIS AND FUTUNA"],
249
+ ["882", "WSM", "WS", "SAMOA"],
250
+ ["887", "YEM", "YE", "YEMEN"],
251
+ ["894", "ZMB", "ZM", "ZAMBIA"],
252
+ ["900", "XQZ", "QZ", "AKROTIRI"],
253
+ ["901", "XKS", "XK", "KOSOVO"],
254
+ ["902", "XAC", "XA", "ASHMORE AND CARTIER ISLANDS"],
255
+ ["903", "XBK", "XB", "BAKER ISLAND"],
256
+ ["904", "XBI", "QS", "BASSAS DA INDIA"],
257
+ ["905", "CPT", "CP", "CLIPPERTON ISLAND"],
258
+ ["906", "XCS", "XC", "CORAL SEA ISLANDS"],
259
+ ["907", "XXD", "XD", "DHEKELIA"],
260
+ ["908", "DGA", "DG", "DIEGO GARCIA"],
261
+ ["909", "XAZ", "", "ENTITY 1"],
262
+ ["910", "XCR", "", "ENTITY 2"],
263
+ ["911", "XCY", "", "ENTITY 3"],
264
+ ["912", "XKM", "", "ENTITY 4"],
265
+ ["913", "XKN", "", "ENTITY 5"],
266
+ ["914", "AX3", "A3", "ENTITY 6"],
267
+ ["915", "XEU", "XE", "EUROPA ISLAND"],
268
+ ["916", "XGZ", "XG", "GAZA STRIP"],
269
+ ["917", "XGL", "QX", "GLORIOSO ISLANDS"],
270
+ ["918", "AX2", "A2", "GUANTANAMO BAY NAVAL BASE"],
271
+ ["919", "XHO", "XH", "HOWLAND ISLAND"],
272
+ ["920", "XJM", "XJ", "JAN MAYEN"],
273
+ ["921", "XJV", "XQ", "JARVIS ISLAND"],
274
+ ["922", "XJA", "XU", "JOHNSTON ATOLL"],
275
+ ["923", "XJN", "QU", "JUAN DE NOVA ISLAND"],
276
+ ["924", "XKR", "XM", "KINGMAN REEF"],
277
+ ["925", "XMW", "QM", "MIDWAY ISLANDS"],
278
+ ["926", "XNV", "XV", "NAVASSA ISLAND"],
279
+ ["927", "XPL", "XL", "PALMYRA ATOLL"],
280
+ ["928", "XPR", "XP", "PARACEL ISLANDS"],
281
+ ["929", "XSP", "XS", "SPRATLY ISLANDS"],
282
+ ["930", "XSV", "XR", "SVALBARD"],
283
+ ["931", "XTR", "XT", "TROMELIN ISLAND"],
284
+ ["932", "AX1", "A1", "UNKNOWN"],
285
+ ["933", "XWK", "QW", "WAKE ISLAND"],
286
+ ["934", "XWB", "XW", "WEST BANK"],
287
+ ];
288
+ let byNumeric;
289
+ /** The country a three-digit GENC numeric code names, or undefined for '000' and unknown codes. */
290
+ export function gencCountry(numeric) {
291
+ byNumeric !== null && byNumeric !== void 0 ? byNumeric : (byNumeric = new Map(GENC_COUNTRIES.map((r) => [r[0], r])));
292
+ const r = byNumeric.get(numeric.padStart(3, '0'));
293
+ return r ? { trigraph: r[1], digraph: r[2], name: r[3] } : undefined;
294
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @zaes/sidc — symbol identification codes of MIL-STD-2525C, 2525D and 2525E (and APP-6 D/E):
3
+ * read, validate and write them. No dependencies, no DOM, no drawing.
4
+ *
5
+ * @module @zaes/sidc
6
+ */
7
+ import { parseLetterSidc } from './letter.js';
8
+ import { parseNumericSidc } from './numeric.js';
9
+ export * from './tables.js';
10
+ export { parseNumericSidc, formatNumericSidc } from './numeric.js';
11
+ export { parseLetterSidc, CODING_SCHEMES, LETTER_IDENTITIES, BATTLE_DIMENSIONS, LETTER_STATUSES, ORDERS_OF_BATTLE, GRAPHIC_ORDERS_OF_BATTLE } from './letter.js';
12
+ /** Reads any SIDC: starting with a letter is 2525C (15 characters); 20 or 30 digits is numeric. */
13
+ export function parseSidc(input) {
14
+ const code = input.trim();
15
+ // A numeric code starts with a digit; a letter code with its coding scheme's letter.
16
+ if (/^[A-Za-z]/.test(code))
17
+ return parseLetterSidc(code);
18
+ return parseNumericSidc(code);
19
+ }
20
+ export { GENC_COUNTRIES, gencCountry } from './genc.js';
@@ -0,0 +1,112 @@
1
+ /** 2525C Table A-I, position 1, with the appendix each scheme is defined in. */
2
+ export const CODING_SCHEMES = [
3
+ { value: 'S', name: 'Warfighting', appendix: 'A' },
4
+ { value: 'G', name: 'Tactical Graphics', appendix: 'B' },
5
+ { value: 'W', name: 'Meteorological and Oceanographic', appendix: 'C' },
6
+ { value: 'I', name: 'Signals Intelligence', appendix: 'D' },
7
+ { value: 'O', name: 'Stability Operations', appendix: 'E' },
8
+ { value: 'E', name: 'Emergency Management', appendix: 'G' },
9
+ ];
10
+ /** 2525C Table A-I, position 2, with whether it is the exercise form and its frame family. */
11
+ export const LETTER_IDENTITIES = [
12
+ { value: 'P', name: 'Pending', exercise: false, group: 'Unknown' },
13
+ { value: 'U', name: 'Unknown', exercise: false, group: 'Unknown' },
14
+ { value: 'A', name: 'Assumed Friend', exercise: false, group: 'Friend' },
15
+ { value: 'F', name: 'Friend', exercise: false, group: 'Friend' },
16
+ { value: 'N', name: 'Neutral', exercise: false, group: 'Neutral' },
17
+ { value: 'S', name: 'Suspect', exercise: false, group: 'Hostile' },
18
+ { value: 'H', name: 'Hostile', exercise: false, group: 'Hostile' },
19
+ { value: 'G', name: 'Exercise Pending', exercise: true, group: 'Unknown' },
20
+ { value: 'W', name: 'Exercise Unknown', exercise: true, group: 'Unknown' },
21
+ { value: 'M', name: 'Exercise Assumed Friend', exercise: true, group: 'Friend' },
22
+ { value: 'D', name: 'Exercise Friend', exercise: true, group: 'Friend' },
23
+ { value: 'L', name: 'Exercise Neutral', exercise: true, group: 'Neutral' },
24
+ { value: 'J', name: 'Joker', exercise: true, group: 'Hostile' },
25
+ { value: 'K', name: 'Faker', exercise: true, group: 'Hostile' },
26
+ ];
27
+ /** 2525C Table A-I, position 3, for the warfighting scheme. */
28
+ export const BATTLE_DIMENSIONS = [
29
+ { value: 'P', name: 'Space' },
30
+ { value: 'A', name: 'Air' },
31
+ { value: 'G', name: 'Ground' },
32
+ { value: 'S', name: 'Sea Surface' },
33
+ { value: 'U', name: 'Sea Subsurface' },
34
+ { value: 'F', name: 'SOF' },
35
+ { value: 'X', name: 'Other (no frame)' },
36
+ { value: 'Z', name: 'Unknown' },
37
+ ];
38
+ /** 2525C Table A-I, position 4. */
39
+ export const LETTER_STATUSES = [
40
+ { value: 'A', name: 'Anticipated/Planned' },
41
+ { value: 'P', name: 'Present' },
42
+ { value: 'C', name: 'Present/Fully capable' },
43
+ { value: 'D', name: 'Present/Damaged' },
44
+ { value: 'X', name: 'Present/Destroyed' },
45
+ { value: 'F', name: 'Present/Full to capacity' },
46
+ ];
47
+ /** 2525C Table A-I, position 15. */
48
+ export const ORDERS_OF_BATTLE = [
49
+ { value: 'A', name: 'Air OB' },
50
+ { value: 'E', name: 'Electronic OB' },
51
+ { value: 'C', name: 'Civilian OB' },
52
+ { value: 'G', name: 'Ground OB' },
53
+ { value: 'N', name: 'Maritime OB' },
54
+ { value: 'S', name: 'Strategic Force Related' },
55
+ ];
56
+ /** 2525C Table B-I, position 15 of a tactical graphic (coding scheme G). */
57
+ export const GRAPHIC_ORDERS_OF_BATTLE = [{ value: 'X', name: 'Control Markings' }];
58
+ const LETTERS = /^[A-Z0-9*-]{15}$/;
59
+ const unused = (c) => c === '-' || c === '*';
60
+ /**
61
+ * Reads a 2525C letter SIDC. Values the tables don't define are listed in `problems`. A code given
62
+ * without its trailing unused positions (`SFGPUCI` for `SFGPUCI--------`, as some systems store
63
+ * them) is read with dashes filling them, and `problems` says so; at least scheme, identity, dimension
64
+ * and status (4 characters) are needed.
65
+ */
66
+ export function parseLetterSidc(input) {
67
+ var _a;
68
+ let code = input.trim().toUpperCase();
69
+ const problems = [];
70
+ if (code.length >= 4 && code.length < 15 && /^[A-Z0-9*-]+$/.test(code)) {
71
+ problems.push({ position: code.length + 1, message: `${code.length} characters: positions ${code.length + 1}-15 read as unused (-)` });
72
+ code = code.padEnd(15, '-');
73
+ }
74
+ if (!LETTERS.test(code)) {
75
+ const why = code.length === 15 ? 'has 15 characters of A-Z, 0-9, - and *' : `has 15 characters, not ${code.length}`;
76
+ return { ok: false, problems: [{ position: 1, message: `a 2525C SIDC ${why}` }] };
77
+ }
78
+ const check = (position, value, table, what) => {
79
+ if (!unused(value) && !table.some((e) => e.value === value))
80
+ problems.push({ position, message: `${what} ${value} is not defined` });
81
+ };
82
+ const scheme = code[0];
83
+ check(1, scheme, CODING_SCHEMES, 'coding scheme');
84
+ const metoc = scheme === 'W';
85
+ const identity = metoc ? undefined : LETTER_IDENTITIES.find((e) => e.value === code[1]);
86
+ if (!metoc) {
87
+ check(2, code[1], LETTER_IDENTITIES, 'standard identity');
88
+ if (scheme === 'S')
89
+ check(3, code[2], BATTLE_DIMENSIONS, 'battle dimension');
90
+ check(4, code[3], LETTER_STATUSES, 'status');
91
+ check(15, code[14], scheme === 'G' ? GRAPHIC_ORDERS_OF_BATTLE : ORDERS_OF_BATTLE, 'order of battle');
92
+ }
93
+ return {
94
+ ok: true,
95
+ problems,
96
+ sidc: {
97
+ kind: 'letter',
98
+ standard: '2525C',
99
+ code,
100
+ scheme,
101
+ standardIdentity: code[1],
102
+ standardIdentityGroup: identity === null || identity === void 0 ? void 0 : identity.group,
103
+ exercise: (_a = identity === null || identity === void 0 ? void 0 : identity.exercise) !== null && _a !== void 0 ? _a : false,
104
+ dimension: code[2],
105
+ status: code[3],
106
+ functionId: code.slice(4, 10),
107
+ modifier: code.slice(10, 12),
108
+ country: code.slice(12, 14),
109
+ orderOfBattle: code[14],
110
+ },
111
+ };
112
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * The numeric SIDC of MIL-STD-2525D and 2525E (Appendix A, A.5): 20 positions in 2525D, 30 in
3
+ * 2525E. A 20-position code read as 2525E has an all-zero Set C.
4
+ *
5
+ * Set A 1–2 version · 3 context · 4 standard identity · 5–6 symbol set · 7 status ·
6
+ * 8 headquarters/task force/dummy · 9–10 amplifying descriptor
7
+ * Set B 11–16 entity, entity type, entity subtype · 17–18 sector 1 modifier · 19–20 sector 2 modifier
8
+ * Set C 21 sector 1 modifier identifier · 22 sector 2 modifier identifier · 23 frame shape ·
9
+ * 24–27 reserved · 28–30 country (GENC numeric)
10
+ */
11
+ import { AMPLIFYING_DESCRIPTORS, CONTEXTS, FRAME_SHAPES, HQ_TF_DUMMY, STANDARD_IDENTITIES, STATUSES, SYMBOL_SETS, SYMBOL_SETS_2525D_ONLY, VERSIONS, lookup, } from './tables.js';
12
+ const NUMERIC = /^[0-9A-F]+$/;
13
+ /**
14
+ * Reads a numeric SIDC. A code of the wrong length or with characters outside [0-9A-F] fails; a
15
+ * well-formed code with values the tables don't define parses, with each one listed in `problems`,
16
+ * so a caller can decide whether to draw it.
17
+ */
18
+ export function parseNumericSidc(input) {
19
+ const code = input.trim().toUpperCase();
20
+ if (code.length !== 20 && code.length !== 30) {
21
+ return { ok: false, problems: [{ position: 1, message: `a numeric SIDC has 20 or 30 positions, not ${code.length}` }] };
22
+ }
23
+ if (!NUMERIC.test(code))
24
+ return { ok: false, problems: [{ position: firstBad(code) + 1, message: 'a numeric SIDC holds only 0-9 and A-F' }] };
25
+ const at = (from, to = from) => code.slice(from - 1, to);
26
+ const problems = [];
27
+ const check = (position, value, known, what) => {
28
+ if (!known)
29
+ problems.push({ position, message: `${what} ${value} is not defined` });
30
+ };
31
+ const version = at(1, 2);
32
+ const versionEntry = lookup(VERSIONS, version);
33
+ check(1, version, !!versionEntry, 'version');
34
+ const standard = versionEntry === null || versionEntry === void 0 ? void 0 : versionEntry.standard;
35
+ const context = at(3);
36
+ check(3, context, !!lookup(CONTEXTS, context), 'context');
37
+ const standardIdentity = at(4);
38
+ const identity = lookup(STANDARD_IDENTITIES, standardIdentity);
39
+ check(4, standardIdentity, !!identity, 'standard identity');
40
+ const symbolSet = at(5, 6);
41
+ const sets = standard === '2525D' || standard === 'APP-6D' ? [...SYMBOL_SETS.filter((s) => s.value !== '50'), ...SYMBOL_SETS_2525D_ONLY] : SYMBOL_SETS;
42
+ check(5, symbolSet, !!lookup(sets, symbolSet), 'symbol set');
43
+ const status = at(7);
44
+ check(7, status, !!lookup(STATUSES, status), 'status');
45
+ const hqTfDummy = at(8);
46
+ check(8, hqTfDummy, !!lookup(HQ_TF_DUMMY, hqTfDummy), 'headquarters/task force/dummy');
47
+ const flags = Number.parseInt(hqTfDummy, 16);
48
+ const amplifyingDescriptor = at(9, 10);
49
+ check(9, amplifyingDescriptor, !!lookup(AMPLIFYING_DESCRIPTORS, amplifyingDescriptor), 'amplifying descriptor');
50
+ const long = code.length === 30;
51
+ if (!long && (standard === '2525E' || standard === 'APP-6E')) {
52
+ problems.push({ position: 21, message: 'a 2525E code has 30 positions; read with an all-zero Set C' });
53
+ }
54
+ const frameShape = long ? at(23) : '0';
55
+ check(23, frameShape, !!lookup(FRAME_SHAPES, frameShape), 'frame shape');
56
+ if (long && at(24, 27) !== '0000')
57
+ problems.push({ position: 24, message: 'positions 24–27 are reserved and should be 0' });
58
+ return {
59
+ ok: true,
60
+ problems,
61
+ sidc: {
62
+ kind: 'numeric',
63
+ code,
64
+ standard,
65
+ version,
66
+ context,
67
+ standardIdentity,
68
+ standardIdentityGroup: identity === null || identity === void 0 ? void 0 : identity.group,
69
+ symbolSet,
70
+ status,
71
+ hqTfDummy,
72
+ feintDummy: (flags & 1) !== 0,
73
+ headquarters: (flags & 2) !== 0,
74
+ taskForce: (flags & 4) !== 0,
75
+ amplifyingDescriptor,
76
+ entityCode: at(11, 16),
77
+ sector1: at(17, 18),
78
+ sector2: at(19, 20),
79
+ sector1Identifier: long ? at(21) : '0',
80
+ sector2Identifier: long ? at(22) : '0',
81
+ frameShape,
82
+ country: long ? at(28, 30) : '000',
83
+ },
84
+ };
85
+ }
86
+ /** Writes a 30-position 2525E SIDC (version 15 unless given). Each field is padded to its width. */
87
+ export function formatNumericSidc(fields) {
88
+ var _a;
89
+ const f = (value, width) => (value !== null && value !== void 0 ? value : '').padStart(width, '0').slice(-width);
90
+ return [
91
+ f((_a = fields.version) !== null && _a !== void 0 ? _a : '15', 2),
92
+ f(fields.context, 1),
93
+ f(fields.standardIdentity, 1),
94
+ f(fields.symbolSet, 2),
95
+ f(fields.status, 1),
96
+ f(fields.hqTfDummy, 1),
97
+ f(fields.amplifyingDescriptor, 2),
98
+ f(fields.entityCode, 6),
99
+ f(fields.sector1, 2),
100
+ f(fields.sector2, 2),
101
+ f(fields.sector1Identifier, 1),
102
+ f(fields.sector2Identifier, 1),
103
+ f(fields.frameShape, 1),
104
+ '0000',
105
+ f(fields.country, 3),
106
+ ].join('');
107
+ }
108
+ function firstBad(code) {
109
+ for (let i = 0; i < code.length; i++)
110
+ if (!NUMERIC.test(code[i]))
111
+ return i;
112
+ return 0;
113
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }