@mailwoman/codex 7.2.0 → 7.3.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.
Files changed (66) hide show
  1. package/address-system-conventions.ts +68 -0
  2. package/au/delivery-service.ts +179 -0
  3. package/au/index.ts +15 -0
  4. package/au/level-designator.ts +209 -0
  5. package/au/postcode.ts +51 -0
  6. package/au/state.ts +35 -0
  7. package/ca/index.ts +12 -0
  8. package/ca/postal-code.ts +121 -0
  9. package/ca/province.ts +99 -0
  10. package/ca/street-type.ts +167 -0
  11. package/country/codes.ts +534 -0
  12. package/country/country.ts +125 -0
  13. package/country/index.ts +15 -0
  14. package/country/names.ts +274 -0
  15. package/country/official-languages.ts +397 -0
  16. package/country/reference-data.ts +267 -0
  17. package/country/reference.ts +47 -0
  18. package/country/subdivision.ts +93 -0
  19. package/de/bundesland.ts +102 -0
  20. package/de/index.ts +12 -0
  21. package/de/postleitzahl.ts +91 -0
  22. package/de/street-type.ts +83 -0
  23. package/fr/cedex.ts +56 -0
  24. package/fr/code-postal.ts +105 -0
  25. package/fr/departement.ts +142 -0
  26. package/fr/index.ts +14 -0
  27. package/fr/region.ts +93 -0
  28. package/fr/voie.ts +98 -0
  29. package/gb/country.ts +74 -0
  30. package/gb/index.ts +14 -0
  31. package/gb/postcode-area.ts +107 -0
  32. package/gb/postcode.ts +109 -0
  33. package/gb/street-type.ts +90 -0
  34. package/index.ts +38 -0
  35. package/jp/address-unit.ts +87 -0
  36. package/jp/index.ts +13 -0
  37. package/jp/postal-code.ts +93 -0
  38. package/jp/prefecture.ts +173 -0
  39. package/level-semantics.ts +623 -0
  40. package/nz/delivery-service.ts +211 -0
  41. package/nz/index.ts +12 -0
  42. package/nz/postcode.ts +42 -0
  43. package/out/country/index.d.ts +1 -0
  44. package/out/country/index.d.ts.map +1 -1
  45. package/out/country/index.js +1 -0
  46. package/out/country/index.js.map +1 -1
  47. package/out/country/subdivision.d.ts +44 -0
  48. package/out/country/subdivision.d.ts.map +1 -0
  49. package/out/country/subdivision.js +76 -0
  50. package/out/country/subdivision.js.map +1 -0
  51. package/package.json +81 -37
  52. package/postcode-systems.ts +68 -0
  53. package/tools/build-country-surface-lexicon.ts +166 -0
  54. package/tools/export-country-surfaces.ts +46 -0
  55. package/tools/generate-country-reference.ts +153 -0
  56. package/tools/generate-official-languages.ts +188 -0
  57. package/tools/index.ts +12 -0
  58. package/us/floor-designator.ts +119 -0
  59. package/us/index.ts +19 -0
  60. package/us/military-address.ts +199 -0
  61. package/us/po-box.ts +82 -0
  62. package/us/state.ts +156 -0
  63. package/us/street-directional.ts +220 -0
  64. package/us/street-suffix.ts +345 -0
  65. package/us/unit-designator.ts +223 -0
  66. package/us/zipcode.ts +212 -0
@@ -0,0 +1,534 @@
1
+ /**
2
+ * @copyright Sister Software (ISO 3166-1 data salvaged from isp-nexus)
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ */
6
+
7
+ import type { CountryName } from "./names.ts"
8
+
9
+ /**
10
+ * @category Country
11
+ * @title Country ISO 3166-1 Alpha-2 code
12
+ * @public
13
+ */
14
+ export const CountryISO2 = {
15
+ Afghanistan: "AF",
16
+ Albania: "AL",
17
+ Algeria: "DZ",
18
+ "American Samoa": "AS",
19
+ Andorra: "AD",
20
+ Angola: "AO",
21
+ Anguilla: "AI",
22
+ Antarctica: "AQ",
23
+ "Antigua and Barbuda": "AG",
24
+ Argentina: "AR",
25
+ Armenia: "AM",
26
+ Aruba: "AW",
27
+ Australia: "AU",
28
+ Austria: "AT",
29
+ Azerbaijan: "AZ",
30
+ Bahamas: "BS",
31
+ Bahrain: "BH",
32
+ Bangladesh: "BD",
33
+ Barbados: "BB",
34
+ Belarus: "BY",
35
+ Belgium: "BE",
36
+ Belize: "BZ",
37
+ Benin: "BJ",
38
+ Bermuda: "BM",
39
+ Bhutan: "BT",
40
+ Bolivia: "BO",
41
+ "Bonaire, Sint Eustatius and Saba": "BQ",
42
+ "Bosnia and Herzegovina": "BA",
43
+ Botswana: "BW",
44
+ "Bouvet Island": "BV",
45
+ Brazil: "BR",
46
+ "British Indian Ocean Territory": "IO",
47
+ "Brunei Darussalam": "BN",
48
+ Bulgaria: "BG",
49
+ "Burkina Faso": "BF",
50
+ Burundi: "BI",
51
+ Cambodia: "KH",
52
+ Cameroon: "CM",
53
+ Canada: "CA",
54
+ "Cape Verde": "CV",
55
+ "Cayman Islands": "KY",
56
+ "Central African Republic": "CF",
57
+ Chad: "TD",
58
+ Chile: "CL",
59
+ China: "CN",
60
+ "Christmas Island": "CX",
61
+ "Cocos (Keeling) Islands": "CC",
62
+ Colombia: "CO",
63
+ Comoros: "KM",
64
+ Congo: "CG",
65
+ "Congo, the Democratic Republic of the": "CD",
66
+ "Cook Islands": "CK",
67
+ "Costa Rica": "CR",
68
+ "Cote DIvoire": "CI",
69
+ Croatia: "HR",
70
+ Cuba: "CU",
71
+ Curaçao: "CW",
72
+ Cyprus: "CY",
73
+ "Czech Republic": "CZ",
74
+ Denmark: "DK",
75
+ Djibouti: "DJ",
76
+ Dominica: "DM",
77
+ "Dominican Republic": "DO",
78
+ Ecuador: "EC",
79
+ Egypt: "EG",
80
+ "El Salvador": "SV",
81
+ "Equatorial Guinea": "GQ",
82
+ Eritrea: "ER",
83
+ Estonia: "EE",
84
+ Ethiopia: "ET",
85
+ "Falkland Islands (Malvinas)": "FK",
86
+ "Faroe Islands": "FO",
87
+ Fiji: "FJ",
88
+ Finland: "FI",
89
+ France: "FR",
90
+ "French Guiana": "GF",
91
+ "French Polynesia": "PF",
92
+ "French Southern Territories": "TF",
93
+ Gabon: "GA",
94
+ Gambia: "GM",
95
+ Georgia: "GE",
96
+ Germany: "DE",
97
+ Ghana: "GH",
98
+ Gibraltar: "GI",
99
+ Greece: "GR",
100
+ Greenland: "GL",
101
+ Grenada: "GD",
102
+ Guadeloupe: "GP",
103
+ Guam: "GU",
104
+ Guatemala: "GT",
105
+ Guernsey: "GG",
106
+ Guinea: "GN",
107
+ "Guinea-Bissau": "GW",
108
+ Guyana: "GY",
109
+ Haiti: "HT",
110
+ "Heard Island and Mcdonald Islands": "HM",
111
+ "Holy See (Vatican City State)": "VA",
112
+ Honduras: "HN",
113
+ "Hong Kong": "HK",
114
+ Hungary: "HU",
115
+ Iceland: "IS",
116
+ India: "IN",
117
+ Indonesia: "ID",
118
+ "Iran, Islamic Republic of": "IR",
119
+ Iraq: "IQ",
120
+ Ireland: "IE",
121
+ "Isle of Man": "IM",
122
+ Israel: "IL",
123
+ Italy: "IT",
124
+ Jamaica: "JM",
125
+ Japan: "JP",
126
+ Jersey: "JE",
127
+ Jordan: "JO",
128
+ Kazakhstan: "KZ",
129
+ Kenya: "KE",
130
+ Kiribati: "KI",
131
+ "Korea, Democratic People's Republic of": "KP",
132
+ "Korea, Republic of": "KR",
133
+ Kuwait: "KW",
134
+ Kyrgyzstan: "KG",
135
+ "Lao People's Democratic Republic": "LA",
136
+ Latvia: "LV",
137
+ Lebanon: "LB",
138
+ Lesotho: "LS",
139
+ Liberia: "LR",
140
+ Libya: "LY",
141
+ Liechtenstein: "LI",
142
+ Lithuania: "LT",
143
+ Luxembourg: "LU",
144
+ Macao: "MO",
145
+ "Macedonia, the Former Yugoslav Republic of": "MK",
146
+ Madagascar: "MG",
147
+ Malawi: "MW",
148
+ Malaysia: "MY",
149
+ Maldives: "MV",
150
+ Mali: "ML",
151
+ Malta: "MT",
152
+ "Marshall Islands": "MH",
153
+ Martinique: "MQ",
154
+ Mauritania: "MR",
155
+ Mauritius: "MU",
156
+ Mayotte: "YT",
157
+ Mexico: "MX",
158
+ "Micronesia, Federated States of": "FM",
159
+ "Moldova, Republic of": "MD",
160
+ Monaco: "MC",
161
+ Mongolia: "MN",
162
+ Montenegro: "ME",
163
+ Montserrat: "MS",
164
+ Morocco: "MA",
165
+ Mozambique: "MZ",
166
+ Myanmar: "MM",
167
+ Namibia: "NA",
168
+ Nauru: "NR",
169
+ Nepal: "NP",
170
+ Netherlands: "NL",
171
+ "New Caledonia": "NC",
172
+ "New Zealand": "NZ",
173
+ Nicaragua: "NI",
174
+ Niger: "NE",
175
+ Nigeria: "NG",
176
+ Niue: "NU",
177
+ "Norfolk Island": "NF",
178
+ "Northern Mariana Islands": "MP",
179
+ Norway: "NO",
180
+ Oman: "OM",
181
+ Pakistan: "PK",
182
+ Palau: "PW",
183
+ "Palestine, State of": "PS",
184
+ Panama: "PA",
185
+ "Papua New Guinea": "PG",
186
+ Paraguay: "PY",
187
+ Peru: "PE",
188
+ Philippines: "PH",
189
+ Pitcairn: "PN",
190
+ Poland: "PL",
191
+ Portugal: "PT",
192
+ "Puerto Rico": "PR",
193
+ Qatar: "QA",
194
+ Reunion: "RE",
195
+ Romania: "RO",
196
+ "Russian Federation": "RU",
197
+ Rwanda: "RW",
198
+ "Saint Barthélemy": "BL",
199
+ "Saint Helena, Ascension and Tristan da Cunha": "SH",
200
+ "Saint Kitts and Nevis": "KN",
201
+ "Saint Lucia": "LC",
202
+ "Saint Martin (French part)": "MF",
203
+ "Saint Pierre and Miquelon": "PM",
204
+ "Saint Vincent and the Grenadines": "VC",
205
+ Samoa: "WS",
206
+ "San Marino": "SM",
207
+ "Sao Tome and Principe": "ST",
208
+ "Saudi Arabia": "SA",
209
+ Senegal: "SN",
210
+ Serbia: "RS",
211
+ Seychelles: "SC",
212
+ "Sierra Leone": "SL",
213
+ Singapore: "SG",
214
+ "Sint Maarten (Dutch part)": "SX",
215
+ Slovakia: "SK",
216
+ Slovenia: "SI",
217
+ "Solomon Islands": "SB",
218
+ Somalia: "SO",
219
+ "South Africa": "ZA",
220
+ "South Georgia and the South Sandwich Islands": "GS",
221
+ "South Sudan": "SS",
222
+ Spain: "ES",
223
+ "Sri Lanka": "LK",
224
+ Sudan: "SD",
225
+ Suriname: "SR",
226
+ "Svalbard and Jan Mayen": "SJ",
227
+ Swaziland: "SZ",
228
+ Sweden: "SE",
229
+ Switzerland: "CH",
230
+ "Syrian Arab Republic": "SY",
231
+ "Taiwan (Province of China)": "TW",
232
+ Tajikistan: "TJ",
233
+ "Tanzania, United Republic of": "TZ",
234
+ Thailand: "TH",
235
+ "Timor-Leste": "TL",
236
+ Togo: "TG",
237
+ Tokelau: "TK",
238
+ Tonga: "TO",
239
+ "Trinidad and Tobago": "TT",
240
+ Tunisia: "TN",
241
+ Turkey: "TR",
242
+ Turkmenistan: "TM",
243
+ "Turks and Caicos Islands": "TC",
244
+ Tuvalu: "TV",
245
+ Uganda: "UG",
246
+ Ukraine: "UA",
247
+ "United Arab Emirates": "AE",
248
+ "United Kingdom": "GB",
249
+ "United States": "US",
250
+ "United States Minor Outlying Islands": "UM",
251
+ Uruguay: "UY",
252
+ Uzbekistan: "UZ",
253
+ Vanuatu: "VU",
254
+ Venezuela: "VE",
255
+ "Viet Nam": "VN",
256
+ "Virgin Islands (British)": "VG",
257
+ "Virgin Islands (U.S.)": "VI",
258
+ "Wallis and Futuna": "WF",
259
+ "Western Sahara": "EH",
260
+ Yemen: "YE",
261
+ Zambia: "ZM",
262
+ Zimbabwe: "ZW",
263
+ "Åland Islands": "AX",
264
+ } as const
265
+
266
+ export type CountryISO2 = (typeof CountryISO2)[keyof typeof CountryISO2]
267
+
268
+ /**
269
+ * ISO 3166-1 alpha-3 country codes to country names.
270
+ *
271
+ * @internal
272
+ * @title Country ISO 3166-1 Alpha-3 Code
273
+ */
274
+ export const Alpha3ToCountryRecord = {
275
+ AFG: "Afghanistan",
276
+ ALB: "Albania",
277
+ DZA: "Algeria",
278
+ ASM: "American Samoa",
279
+ AND: "Andorra",
280
+ AGO: "Angola",
281
+ AIA: "Anguilla",
282
+ ATA: "Antarctica",
283
+ ATG: "Antigua and Barbuda",
284
+ ARG: "Argentina",
285
+ ARM: "Armenia",
286
+ ABW: "Aruba",
287
+ AUS: "Australia",
288
+ AUT: "Austria",
289
+ AZE: "Azerbaijan",
290
+ BHS: "Bahamas",
291
+ BHR: "Bahrain",
292
+ BGD: "Bangladesh",
293
+ BRB: "Barbados",
294
+ BLR: "Belarus",
295
+ BEL: "Belgium",
296
+ BLZ: "Belize",
297
+ BEN: "Benin",
298
+ BMU: "Bermuda",
299
+ BTN: "Bhutan",
300
+ BOL: "Bolivia",
301
+ BES: "Bonaire, Sint Eustatius and Saba",
302
+ BIH: "Bosnia and Herzegovina",
303
+ BWA: "Botswana",
304
+ BVT: "Bouvet Island",
305
+ BRA: "Brazil",
306
+ IOT: "British Indian Ocean Territory",
307
+ BRN: "Brunei Darussalam",
308
+ BGR: "Bulgaria",
309
+ BFA: "Burkina Faso",
310
+ BDI: "Burundi",
311
+ KHM: "Cambodia",
312
+ CMR: "Cameroon",
313
+ CAN: "Canada",
314
+ CPV: "Cape Verde",
315
+ CYM: "Cayman Islands",
316
+ CAF: "Central African Republic",
317
+ TCD: "Chad",
318
+ CHL: "Chile",
319
+ CHN: "China",
320
+ CXR: "Christmas Island",
321
+ CCK: "Cocos (Keeling) Islands",
322
+ COL: "Colombia",
323
+ COM: "Comoros",
324
+ COG: "Congo",
325
+ COD: "Congo, the Democratic Republic of the",
326
+ COK: "Cook Islands",
327
+ CRI: "Costa Rica",
328
+ CIV: "Cote DIvoire",
329
+ HRV: "Croatia",
330
+ CUB: "Cuba",
331
+ CUW: "Curaçao",
332
+ CYP: "Cyprus",
333
+ CZE: "Czech Republic",
334
+ DNK: "Denmark",
335
+ DJI: "Djibouti",
336
+ DMA: "Dominica",
337
+ DOM: "Dominican Republic",
338
+ ECU: "Ecuador",
339
+ EGY: "Egypt",
340
+ SLV: "El Salvador",
341
+ GNQ: "Equatorial Guinea",
342
+ ERI: "Eritrea",
343
+ EST: "Estonia",
344
+ ETH: "Ethiopia",
345
+ FLK: "Falkland Islands (Malvinas)",
346
+ FRO: "Faroe Islands",
347
+ FJI: "Fiji",
348
+ FIN: "Finland",
349
+ FRA: "France",
350
+ GUF: "French Guiana",
351
+ PYF: "French Polynesia",
352
+ ATF: "French Southern Territories",
353
+ GAB: "Gabon",
354
+ GMB: "Gambia",
355
+ GEO: "Georgia",
356
+ DEU: "Germany",
357
+ GHA: "Ghana",
358
+ GIB: "Gibraltar",
359
+ GRC: "Greece",
360
+ GRL: "Greenland",
361
+ GRD: "Grenada",
362
+ GLP: "Guadeloupe",
363
+ GUM: "Guam",
364
+ GTM: "Guatemala",
365
+ GGY: "Guernsey",
366
+ GIN: "Guinea",
367
+ GNB: "Guinea-Bissau",
368
+ GUY: "Guyana",
369
+ HTI: "Haiti",
370
+ HMD: "Heard Island and Mcdonald Islands",
371
+ VAT: "Holy See (Vatican City State)",
372
+ HND: "Honduras",
373
+ HKG: "Hong Kong",
374
+ HUN: "Hungary",
375
+ ISL: "Iceland",
376
+ IND: "India",
377
+ IDN: "Indonesia",
378
+ IRN: "Iran, Islamic Republic of",
379
+ IRQ: "Iraq",
380
+ IRL: "Ireland",
381
+ IMN: "Isle of Man",
382
+ ISR: "Israel",
383
+ ITA: "Italy",
384
+ JAM: "Jamaica",
385
+ JPN: "Japan",
386
+ JEY: "Jersey",
387
+ JOR: "Jordan",
388
+ KAZ: "Kazakhstan",
389
+ KEN: "Kenya",
390
+ KIR: "Kiribati",
391
+ PRK: "Korea, Democratic People's Republic of",
392
+ KOR: "Korea, Republic of",
393
+ KWT: "Kuwait",
394
+ KGZ: "Kyrgyzstan",
395
+ LAO: "Lao People's Democratic Republic",
396
+ LVA: "Latvia",
397
+ LBN: "Lebanon",
398
+ LSO: "Lesotho",
399
+ LBR: "Liberia",
400
+ LBY: "Libya",
401
+ LIE: "Liechtenstein",
402
+ LTU: "Lithuania",
403
+ LUX: "Luxembourg",
404
+ MAC: "Macao",
405
+ MKD: "Macedonia, the Former Yugoslav Republic of",
406
+ MDG: "Madagascar",
407
+ MWI: "Malawi",
408
+ MYS: "Malaysia",
409
+ MDV: "Maldives",
410
+ MLI: "Mali",
411
+ MLT: "Malta",
412
+ MHL: "Marshall Islands",
413
+ MTQ: "Martinique",
414
+ MRT: "Mauritania",
415
+ MUS: "Mauritius",
416
+ MYT: "Mayotte",
417
+ MEX: "Mexico",
418
+ FSM: "Micronesia, Federated States of",
419
+ MDA: "Moldova, Republic of",
420
+ MCO: "Monaco",
421
+ MNG: "Mongolia",
422
+ MNE: "Montenegro",
423
+ MSR: "Montserrat",
424
+ MAR: "Morocco",
425
+ MOZ: "Mozambique",
426
+ MMR: "Myanmar",
427
+ NAM: "Namibia",
428
+ NRU: "Nauru",
429
+ NPL: "Nepal",
430
+ NLD: "Netherlands",
431
+ NCL: "New Caledonia",
432
+ NZL: "New Zealand",
433
+ NIC: "Nicaragua",
434
+ NER: "Niger",
435
+ NGA: "Nigeria",
436
+ NIU: "Niue",
437
+ NFK: "Norfolk Island",
438
+ MNP: "Northern Mariana Islands",
439
+ NOR: "Norway",
440
+ OMN: "Oman",
441
+ PAK: "Pakistan",
442
+ PLW: "Palau",
443
+ PSE: "Palestine, State of",
444
+ PAN: "Panama",
445
+ PNG: "Papua New Guinea",
446
+ PRY: "Paraguay",
447
+ PER: "Peru",
448
+ PHL: "Philippines",
449
+ PCN: "Pitcairn",
450
+ POL: "Poland",
451
+ PRT: "Portugal",
452
+ PRI: "Puerto Rico",
453
+ QAT: "Qatar",
454
+ REU: "Reunion",
455
+ ROM: "Romania",
456
+ RUS: "Russian Federation",
457
+ RWA: "Rwanda",
458
+ BLM: "Saint Barthélemy",
459
+ SHN: "Saint Helena, Ascension and Tristan da Cunha",
460
+ KNA: "Saint Kitts and Nevis",
461
+ LCA: "Saint Lucia",
462
+ MAF: "Saint Martin (French part)",
463
+ SPM: "Saint Pierre and Miquelon",
464
+ VCT: "Saint Vincent and the Grenadines",
465
+ WSM: "Samoa",
466
+ SMR: "San Marino",
467
+ STP: "Sao Tome and Principe",
468
+ SAU: "Saudi Arabia",
469
+ SEN: "Senegal",
470
+ SRB: "Serbia",
471
+ SYC: "Seychelles",
472
+ SLE: "Sierra Leone",
473
+ SGP: "Singapore",
474
+ SXM: "Sint Maarten (Dutch part)",
475
+ SVK: "Slovakia",
476
+ SVN: "Slovenia",
477
+ SLB: "Solomon Islands",
478
+ SOM: "Somalia",
479
+ ZAF: "South Africa",
480
+ SGS: "South Georgia and the South Sandwich Islands",
481
+ SSD: "South Sudan",
482
+ ESP: "Spain",
483
+ LKA: "Sri Lanka",
484
+ SDN: "Sudan",
485
+ SUR: "Suriname",
486
+ SJM: "Svalbard and Jan Mayen",
487
+ SWZ: "Swaziland",
488
+ SWE: "Sweden",
489
+ CHE: "Switzerland",
490
+ SYR: "Syrian Arab Republic",
491
+ TWN: "Taiwan (Province of China)",
492
+ TJK: "Tajikistan",
493
+ TZA: "Tanzania, United Republic of",
494
+ THA: "Thailand",
495
+ TLS: "Timor-Leste",
496
+ TGO: "Togo",
497
+ TKL: "Tokelau",
498
+ TON: "Tonga",
499
+ TTO: "Trinidad and Tobago",
500
+ TUN: "Tunisia",
501
+ TUR: "Turkey",
502
+ TKM: "Turkmenistan",
503
+ TCA: "Turks and Caicos Islands",
504
+ TUV: "Tuvalu",
505
+ UGA: "Uganda",
506
+ UKR: "Ukraine",
507
+ ARE: "United Arab Emirates",
508
+ GBR: "United Kingdom",
509
+ USA: "United States",
510
+ UMI: "United States Minor Outlying Islands",
511
+ URY: "Uruguay",
512
+ UZB: "Uzbekistan",
513
+ VUT: "Vanuatu",
514
+ VEN: "Venezuela",
515
+ VNM: "Viet Nam",
516
+ VGB: "Virgin Islands (British)",
517
+ VIR: "Virgin Islands (U.S.)",
518
+ WLF: "Wallis and Futuna",
519
+ ESH: "Western Sahara",
520
+ YEM: "Yemen",
521
+ ZMB: "Zambia",
522
+ ZWE: "Zimbabwe",
523
+ ALA: "Åland Islands",
524
+ } as const satisfies Record<string, CountryName>
525
+
526
+ /**
527
+ * ISO 3166-1 alpha-3 country code.
528
+ *
529
+ * @category Geographic
530
+ * @category Country
531
+ * @title Country ISO 3166-1 Alpha-3 Code
532
+ * @public
533
+ */
534
+ export type CountryISO3 = keyof typeof Alpha3ToCountryRecord
@@ -0,0 +1,125 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * Country recognition for the `country` parity lever. The ISO 3166-1 base (names + alpha-2/alpha-3)
7
+ * is salvaged from isp-nexus `spatial/countries` ({@link ./names.ts}, {@link ./codes.ts}); this
8
+ * adds the layer ISO doesn't carry — the **surface forms** addresses actually use (endonyms +
9
+ * common abbreviations: "USA"/"United States"/"U.S."; "Deutschland"/"Germany"; "España"/"Spain")
10
+ * — plus a {@link matchCountry} resolver the corpus country-shard + parsing reuse. Same shape as
11
+ * the other codex matchers (street-suffix, directional, po-box).
12
+ */
13
+
14
+ import { Alpha3ToCountryRecord, CountryISO2, type CountryISO3 } from "./codes.ts"
15
+ import { type CountryName } from "./names.ts"
16
+
17
+ /**
18
+ * Common real-address surface forms per ISO 3166-1 alpha-2, **canonical English name first** then endonym +
19
+ * abbreviations. Curated for the corpus locales + frequent countries (NOT a full 249-entry variant table — the ISO base
20
+ * below catches the canonical name/code for everything else). Forms are matched case-insensitively; the first entry is
21
+ * the preferred render form.
22
+ */
23
+ export const COUNTRY_SURFACE_FORMS = {
24
+ US: ["United States", "USA", "US", "U.S.A.", "U.S.", "United States of America", "America"],
25
+ DE: ["Germany", "Deutschland", "DE", "GER", "Federal Republic of Germany"],
26
+ FR: ["France", "FR", "FRA", "French Republic"],
27
+ GB: ["United Kingdom", "UK", "Great Britain", "Britain", "England", "GB", "U.K."],
28
+ ES: ["Spain", "España", "Espana", "ES", "ESP"],
29
+ IT: ["Italy", "Italia", "IT", "ITA"],
30
+ NL: ["Netherlands", "Nederland", "The Netherlands", "Holland", "NL", "NLD"],
31
+ CA: ["Canada", "CA", "CAN"],
32
+ AU: ["Australia", "AU", "AUS"],
33
+ CH: ["Switzerland", "Schweiz", "Suisse", "Svizzera", "CH"],
34
+ AT: ["Austria", "Österreich", "Osterreich", "AT"],
35
+ BE: ["Belgium", "België", "Belgique", "BE"],
36
+ IE: ["Ireland", "Éire", "IE", "IRL"],
37
+ MX: ["Mexico", "México", "MX", "MEX"],
38
+ JP: ["Japan", "日本", "Nippon", "JP", "JPN"],
39
+ } as const satisfies Partial<Record<string, readonly string[]>>
40
+
41
+ export type CountrySurfaceISO2 = keyof typeof COUNTRY_SURFACE_FORMS
42
+
43
+ /** Alpha-2 → canonical English name (inverted from the salvaged CountryISO2 enum). */
44
+ export const ISO2_TO_NAME: ReadonlyMap<string, CountryName> = new Map(
45
+ Object.entries(CountryISO2).map(([name, code]) => [code as string, name as CountryName])
46
+ )
47
+
48
+ /**
49
+ * Any recognized country surface form / canonical name / alpha-2 / alpha-3 → alpha-2 code. Built once at module load,
50
+ * lowercase-keyed. Canonical names + codes from the ISO base, plus the curated surface forms (surface forms win on
51
+ * collision — they're the address-facing spellings).
52
+ */
53
+ export const COUNTRY_LOOKUP: ReadonlyMap<string, string> = (() => {
54
+ const out = new Map<string, string>()
55
+ const put = (k: string, iso2: string) => {
56
+ const key = k.trim().toLowerCase()
57
+
58
+ if (key && !out.has(key)) {
59
+ out.set(key, iso2)
60
+ }
61
+ }
62
+
63
+ // ISO base: canonical name + alpha-2 + alpha-3.
64
+ for (const [name, code] of Object.entries(CountryISO2)) {
65
+ put(name, code as string)
66
+ }
67
+
68
+ for (const [code] of Object.entries(CountryISO2)) {
69
+ put(code, code as string)
70
+ }
71
+
72
+ // "US" -> US
73
+ for (const [alpha3, name] of Object.entries(Alpha3ToCountryRecord)) {
74
+ const iso2 = CountryISO2[name as keyof typeof CountryISO2]
75
+
76
+ if (iso2) {
77
+ put(alpha3, iso2)
78
+ } // "USA" -> US, "DEU" -> DE
79
+ }
80
+
81
+ // Curated surface forms (override — address spellings beat the ISO base on collision).
82
+ for (const [iso2, forms] of Object.entries(COUNTRY_SURFACE_FORMS)) {
83
+ for (const f of forms) {
84
+ out.set(f.trim().toLowerCase(), iso2)
85
+ }
86
+ }
87
+
88
+ return out
89
+ })()
90
+
91
+ /** Result of a country match: the alpha-2 code, the canonical English name, and the matched surface. */
92
+ export interface CountryMatch {
93
+ iso2: string
94
+ canonical: CountryName | undefined
95
+ matched: string
96
+ }
97
+
98
+ /**
99
+ * Resolve a token (surface form, canonical name, alpha-2, or alpha-3) to a country. Case-insensitive. Returns null if
100
+ * unrecognized. Multi-word names ("United States", "Great Britain") must be passed as the whole phrase — the caller
101
+ * decides the span; this matches it.
102
+ */
103
+ export function matchCountry(token: string | null | undefined): CountryMatch | null {
104
+ if (!token || typeof token !== "string") return null
105
+ const iso2 = COUNTRY_LOOKUP.get(token.trim().toLowerCase())
106
+
107
+ if (!iso2) return null
108
+
109
+ return { iso2, canonical: ISO2_TO_NAME.get(iso2), matched: token.trim() }
110
+ }
111
+
112
+ /** Case-insensitive check: is the token any recognized country form? */
113
+ export function isCountryToken(token: unknown): boolean {
114
+ return typeof token === "string" && COUNTRY_LOOKUP.has(token.trim().toLowerCase())
115
+ }
116
+
117
+ /**
118
+ * The preferred render forms for an alpha-2 (canonical first), for synth shards. Empty if none curated.
119
+ */
120
+ export function countrySurfaceForms(iso2: string): readonly string[] {
121
+ return (COUNTRY_SURFACE_FORMS as Record<string, readonly string[]>)[iso2.toUpperCase()] ?? []
122
+ }
123
+
124
+ export { Alpha3ToCountryRecord, CountryISO2 }
125
+ export type { CountryISO3, CountryName }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * ISO 3166-1 country reference + surface-form recognition (the `country` parity lever).
7
+ */
8
+
9
+ export * from "./codes.ts"
10
+ export * from "./country.ts"
11
+ export * from "./names.ts"
12
+ export * from "./official-languages.ts"
13
+ export * from "./reference-data.ts"
14
+ export * from "./reference.ts"
15
+ export * from "./subdivision.ts"