export type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' export class UICCountry { public constructor( public readonly name: string, /** Rest assured, unlike most ISO standards, https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 can help you for this one */ public readonly iso: string, public readonly treatyShort: string | null, public readonly uicIdentifier: IdentificationNumber, ) { UICCountry.countryMaps.byCountryName.set(name, this) UICCountry.countryMaps.byIso.set(iso, this) if (treatyShort) UICCountry.countryMaps.by1958TreatyShortCode.set(treatyShort, this) UICCountry.countryMaps.byUICIdentificationNumber.set(uicIdentifier, this) } public static readonly countryMaps = Object.freeze({ byCountryName: new Map(), byIso: new Map(), by1958TreatyShortCode: new Map(), byUICIdentificationNumber: new Map<`${Digit}${Digit}`, UICCountry>(), }) public equals(country2: UICCountry) { return (this.iso === country2.iso && this.name === country2.name && this.treatyShort === country2.treatyShort && this.uicIdentifier === country2.uicIdentifier) } public toJSON() { return { name: this.name, iso: this.iso, treatyShort: this.treatyShort, uicIdentifier: this.uicIdentifier } } } // #region Country Data // Sources: https://treaties.fcdo.gov.uk/data/Library2/pdf/1958-TS0049.pdf for variable length country codes - manually retyped // https://en.wikipedia.org/wiki/List_of_UIC_country_codes for UIC country codes ((countries: [ digit: `${Digit}${Digit}` | null, code: string, name: string ][]) => { // #region Treaty Map String const treatyMap = `Australia ........................ AUS Austria ................................. A Belgium .............................. B Belgian Congo .................. CB Bulgaria ........................... BG Chile .............................. RCH Czechoslovakia ..................... CS Denmark ........................... DK France ................................. F Saar .............................. SA India .............................. IND Iran ................................. IR Israel ................................. IL Italy .................................... I Lebanon ........................... RL Luxembourg ........................ L Netherlands ........................ NL Norway .............................. N Philippines ........................... PI Poland .............................. PL Sweden ................................. S Switzerland ........................ CH Turkey .............................. TR Union of South Africa ......... ZA United Kingdom .................. GB Alderney ..................... GBA Guernsey ..................... GBG Jersey ........................... GBJ Aden ........................... ADN Bahamas ........................ BS Basutoland ..................... BL Bechuanaland .................. BP British Honduras ............... BH Cyprus ........................... CY Gambia ..................... WAG Gibraltar ..................... GBZ Gold Coast .................. WAC Hong Kong ..................... HK Jamaica ........................... JA Johore .............................. JO Kedah ........................... KD Kelantan ........................ KL Kenya ........................ EAK Labuan ........................... SS Malacca ........................... SS Malaya ( Negri Sembilan, Pahang, Perak, Selangor) ... FM Malta ........................... GBY Mauritius ........................ MS Nigeria ........................ WAN Northern Rhodesia ............ NR Nyasaland ........................ NP Penang ........................... SS Province Wellesley ............ SS Seychelles ........................ SY Sierra Leone ............... WAL Somaliland ..................... SP Southern Rhodesia ............ SR Swaziland ........................ SD Tanganyika .................. EAT Trengganu ..................... TU Trinidad ........................ TD Uganda ........................ EAU Grenada ..................... WG St. Lucia ..................... WL St. Vincent .................. WV Zanzibar ..................... EAZ United States of America ...... USA Yugoslavia ....................... YU` // #endregion .split('\n').map(v => v.split(/ \.* /g)) as [name: string, code: string][]; for (const country of countries) if (country[0]) new UICCountry(country[2], country[1], treatyMap.find(v => v[0] === country[2])?.[1] ?? null, country[0]) })( /** (()=>{ const baseCountriesWikipedia = document.querySelector('table.wikitable.sortable.jquery-tablesorter'); const countries = []; baseCountriesWikipedia.querySelectorAll('tbody > tr').forEach(v=>{ const num = parseInt(v.querySelector('td').textContent.trim()).toString(); const alphaCode = v.querySelector('td+td').textContent.trim(); const sentientParsable = v.querySelector('td+td+td').textContent.trim(); countries.push([num==='NaN'?null:num,alphaCode,sentientParsable]); }); console.log(countries) })(); */ // #region UIC Countries [ [ "10", "FI", "Finland" ], [ "20", "RU", "Russia" ], [ "21", "BY", "Belarus" ], [ "22", "UA", "Ukraine" ], [ "23", "MD", "Moldova" ], [ "24", "LT", "Lithuania" ], [ "25", "LV", "Latvia" ], [ "26", "EE", "Estonia" ], [ "27", "KZ", "Kazakhstan" ], [ "28", "GE", "Georgia" ], [ "29", "UZ", "Uzbekistan" ], [ "30", "KP", "North Korea" ], [ "31", "MN", "Mongolia" ], [ "32", "VN", "Vietnam" ], [ "33", "CN", "China" ], [ "34", "LA", "Laos" ], [ "40", "CU", "Cuba" ], [ "41", "AL", "Albania" ], [ "42", "JP", "Japan" ], [ "44", "BA", "Bosnia and Herzegovina, Serb Republic of [note 1]" ], [ "49", "BA", "Bosnia and Herzegovina" ], [ "50", "BA", "Bosnia and Herzegovina, Muslim-Croat Federation of [note 1]" ], [ "51", "PL", "Poland" ], [ "52", "BG", "Bulgaria" ], [ "53", "RO", "Romania" ], [ "54", "CZ", "Czech Republic" ], [ "55", "HU", "Hungary" ], [ "56", "SK", "Slovakia" ], [ "57", "AZ", "Azerbaijan" ], [ "58", "AM", "Armenia" ], [ "59", "KG", "Kyrgyzstan" ], [ "60", "IE", "Ireland" ], [ "61", "KR", "South Korea" ], [ "62", "ME", "Montenegro" ], [ "65", "MK", "North Macedonia" ], [ "66", "TJ", "Tajikistan" ], [ "67", "TM", "Turkmenistan" ], [ "68", "AF", "Afghanistan" ], [ "70", "GB", "United Kingdom" ], [ "71", "ES", "Spain" ], [ "72", "RS", "Serbia" ], [ "73", "GR", "Greece" ], [ "74", "SE", "Sweden" ], [ "75", "TR", "Turkey" ], [ "76", "NO", "Norway" ], [ "78", "HR", "Croatia" ], [ "79", "SI", "Slovenia" ], [ "80", "DE", "Germany" ], [ "81", "AT", "Austria" ], [ "82", "LU", "Luxembourg" ], [ "83", "IT", "Italy" ], [ "84", "NL", "Netherlands" ], [ "85", "CH", "Switzerland" ], [ "86", "DK", "Denmark" ], [ "87", "FR", "France" ], [ "88", "BE", "Belgium" ], [ "89", "TZ", "Tanzania" ], [ "90", "EG", "Egypt" ], [ "91", "TN", "Tunisia" ], [ "92", "DZ", "Algeria" ], [ "93", "MA", "Morocco" ], [ "94", "PT", "Portugal" ], [ "95", "IL", "Israel" ], [ "96", "IR", "Iran" ], [ "97", "SY", "Syria" ], [ "98", "LB", "Lebanon" ], [ "99", "IQ", "Iraq" ], [ null, "AU", "Australia" ], [ null, "CA", "Canada" ], [ null, "CD", "DR Congo" ], [ null, "ZA", "South Africa" ], [ null, "US", "United States" ] ] // #endregion ) // #endregion