ISO 3166 codes in an accessible, machine readable, format.
npm:
npm install iso-3166
See examples below.
ISO 3166 is a standard to represent countries and subregions with codes. It includes three parts:
- ISO 3166-1 defines codes for countries (such as
US
USA
United States of America
) - ISO 3166-2 defines codes for subdivisions (such as
US-CA
forCalifornia
inUS
USA
United States of America
) - ISO 3166-3 defines codes for former countries (such as
BUMM
to refer to whenBU
BUR
Burma
revised its name toMM
MMR
Myanmar
in 1989)
While the information in ISO 3166 is well-known and freely available through for example WikiPedia, it is not available in a freely available machine readable format from ISO. That’s where this project comes in: it scrapes WikiPedia.
ISO 3166 is closely tied to the work of the United Nations: the names for countries stem from the UN and ISO 3166 maps to numerical UN M49 codes and vice versa. UN M49 also includes information on bigger regions between our earth and countries.
This project includes all three parts of ISO 3166 as separate files:
iso-3166/1.json
(default export) — Countries: list of assigned ISO 3166-1 entriesiso-3166/2.json
— Subdivisions: list of ISO 3166-2 entriesiso-3166/3.json
— Revisions: list of ISO 3166-3 entries
Additionally, a list of reserved ISO 3166-1 entries is available:
iso-3166/1-reserved.json
— List of reserved ISO 3166-1 entries
Finally, indexes are available to map between different codes:
iso-3166/1-a2-to-1-a3.json
— Map ISO 3166-1 alpha-2 codes to ISO 3166-1 alpha-3 codesiso-3166/1-a2-to-1-n.json
— Map ISO 3166-1 alpha-2 codes to ISO 3166-1 numeric (UN M49) codesiso-3166/1-a3-to-1-a2.json
— Map ISO 3166-1 alpha-3 codes to ISO 3166-1 alpha-2 codesiso-3166/1-n-to-1-a2.json
— Map ISO 3166-1 numeric (UN M49) codes to ISO 3166-1 alpha-2 codes
ISO 3166-1 alpha-2 code matrix
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | AA | AB | AD | AE | AF | AG | AH | AI | AJ | AK | AL | AM | AO | AQ | AR | AS | AT | AU | AV | AW | AX | AY | AZ | |||
B | BA | BB | BC | BD | BE | BF | BG | BH | BI | BJ | BK | BL | BM | BN | BO | BP | BQ | BR | BS | BT | BV | BW | BY | BZ | ||
C | CA | CB | CC | CD | CE | CF | CG | CH | CI | CJ | CK | CL | CM | CN | CO | CQ | CR | CU | CV | CW | CX | CY | CZ | |||
D | DA | DB | DC | DE | DF | DH | DI | DJ | DK | DL | DM | DN | DO | DP | DQ | DR | DS | DT | DU | DV | DW | DX | DZ | |||
E | EB | EC | ED | EE | EG | EH | EI | EJ | EK | EL | EN | EO | EQ | ER | ES | ET | EX | EY | ||||||||
F | FA | FB | FC | FD | FE | FF | FG | FH | FI | FJ | FK | FM | FN | FO | FP | FR | FS | FT | FU | FV | FW | FY | FZ | |||
G | GA | GB | GD | GE | GF | GG | GH | GI | GJ | GK | GL | GM | GN | GO | GP | GQ | GR | GS | GT | GU | GV | GW | GX | GY | GZ | |
H | HA | HB | HC | HD | HE | HF | HG | HH | HI | HJ | HK | HL | HM | HN | HO | HP | HQ | HR | HS | HT | HU | HW | HX | HY | HZ | |
I | IA | ID | IE | IF | IG | IH | II | IJ | IK | IL | IM | IN | IO | IP | IQ | IR | IS | IT | IU | IV | IW | IX | IY | IZ | ||
J | JB | JC | JD | JE | JF | JG | JH | JI | JJ | JK | JL | JM | JN | JO | JP | JQ | JR | JS | JU | JV | JW | JX | JY | JZ | ||
K | KA | KB | KC | KD | KE | KF | KG | KH | KI | KJ | KK | KL | KM | KN | KO | KP | KQ | KR | KS | KT | KU | KV | KW | KX | KY | KZ |
L | LA | LB | LC | LD | LE | LG | LH | LI | LJ | LK | LL | LM | LN | LO | LP | LQ | LR | LS | LT | LU | LV | LW | LX | LY | LZ | |
M | MA | MB | MC | MD | ME | MF | MG | MH | MJ | MK | ML | MM | MN | MO | MP | MQ | MR | MS | MT | MU | MV | MW | MX | MY | MZ | |
N | NA | NB | NC | ND | NE | NF | NG | NI | NJ | NK | NL | NM | NN | NO | NP | NR | NS | NU | NV | NW | NX | NY | NZ | |||
O | OB | OC | OD | OE | OF | OG | OH | OI | OJ | OK | OL | OM | ON | OO | OP | OQ | OR | OS | OT | OU | OV | OW | OX | OY | OZ | |
P | PA | PB | PD | PE | PF | PG | PH | PJ | PK | PL | PM | PN | PO | PP | PQ | PR | PS | PT | PV | PW | PX | PY | ||||
Q | QA | QB | QC | QD | QE | QF | QG | QH | QI | QJ | QK | QL | QM | QN | QO | QP | QR | QS | QT | QU | QV | QW | QX | QY | QZ | |
R | RD | RE | RF | RG | RJ | RK | RO | RQ | RR | RS | RT | RU | RV | RW | RX | RY | RZ | |||||||||
S | SA | SB | SC | SD | SE | SG | SH | SI | SJ | SK | SL | SM | SN | SO | SP | SQ | SR | SS | ST | SV | SW | SX | SY | SZ | ||
T | TB | TC | TD | TE | TF | TG | TH | TI | TJ | TK | TL | TM | TN | TO | TQ | TR | TS | TT | TU | TV | TW | TX | TY | TZ | ||
U | UA | UB | UC | UD | UE | UF | UG | UH | UI | UJ | UL | UM | UO | UP | UQ | UR | US | UT | UU | UV | UW | UX | UY | UZ | ||
V | VA | VB | VC | VE | VF | VG | VH | VI | VJ | VK | VL | VM | VN | VO | VP | VQ | VR | VS | VT | VU | VV | VW | VX | VY | VZ | |
W | WA | WB | WC | WD | WE | WF | WH | WI | WJ | WM | WN | WP | WQ | WR | WS | WT | WU | WW | WX | WY | WZ | |||||
X | XA | XB | XC | XD | XE | XF | XG | XH | XI | XJ | XK | XL | XM | XN | XO | XP | XQ | XR | XS | XT | XU | XV | XW | XX | XY | XZ |
Y | YA | YB | YC | YE | YF | YG | YH | YI | YJ | YK | YL | YM | YN | YO | YP | YQ | YR | YS | YT | YW | YX | YY | YZ | |||
Z | ZA | ZB | ZC | ZD | ZE | ZF | ZG | ZH | ZI | ZJ | ZK | ZL | ZM | ZN | ZO | ZP | ZQ | ZS | ZT | ZU | ZV | ZW | ZX | ZY | ZZ |
ISO31661Entry[]
— Countries: assigned ISO 3166-1 entries.
var iso31661 = require('iso-3166')
console.log(iso31661)
Yields:
[
{state: 'assigned', alpha2: 'AD', alpha3: 'AND', numeric: '020', name: 'Andorra'},
{state: 'assigned', alpha2: 'AE', alpha3: 'ARE', numeric: '784', name: 'United Arab Emirates'},
{state: 'assigned', alpha2: 'AF', alpha3: 'AFG', numeric: '004', name: 'Afghanistan'},
{state: 'assigned', alpha2: 'AG', alpha3: 'ATG', numeric: '028', name: 'Antigua and Barbuda'},
{state: 'assigned', alpha2: 'AI', alpha3: 'AIA', numeric: '660', name: 'Anguilla'},
// …
]
ISO31661Entry[]
— Reserved ISO 3166-1 entries.
var iso31661Reserved = require('iso-3166/1-reserved')
console.log(iso31661Reserved)
Yields:
[
{state: 'exceptionally-reserved', alpha2: 'AC', name: 'Ascension Island'},
{state: 'transitionally-reserved', alpha2: 'AN', name: 'Netherlands Antilles'},
{state: 'indeterminately-reserved', alpha2: 'AP', name: 'African Regional Industrial Property Organization'},
{state: 'transitionally-reserved', alpha2: 'BU', name: 'Burma'},
{state: 'indeterminately-reserved', alpha2: 'BX', name: 'Benelux Trademarks and Designs Office'},
// …
]
ISO31662Entry[]
— Subdivisions: ISO 3166-2 entries.
var iso31662 = require('iso-3166/2')
console.log(iso31662)
Yields:
[
{code: 'AD-02', name: 'Canillo', parent: 'AD'},
{code: 'AD-03', name: 'Encamp', parent: 'AD'},
// …
{code: 'BD-01', name: 'Bandarban', parent: 'BD-B'},
{code: 'BD-02', name: 'Barguna', parent: 'BD-A'},
// …
{code: 'BD-A', name: 'Barisal', parent: 'BD'},
{code: 'BD-B', name: 'Chittagong', parent: 'BD'},
// …
]
ISO31663Entry[]
— Changes: ISO 3166-3 entries.
var iso31663 = require('iso-3166/3')
console.log(iso31663)
Yields:
[
{
alpha4: 'AIDJ',
type: 'change',
from: {state: 'formerly-assigned', alpha2: 'AI', alpha3: 'AFI', numeric: '262', name: 'French Afars and Issas'},
to: [
{state: 'assigned', alpha2: 'DJ', alpha3: 'DJI', numeric: '262', name: 'Djibouti'}
]
},
{
alpha4: 'ANHH',
type: 'split',
from: {state: 'formerly-assigned', alpha2: 'AN', alpha3: 'ANT', numeric: '530', name: 'Netherlands Antilles'},
to: [
{state: 'assigned', alpha2: 'BQ', alpha3: 'BES', numeric: '535', name: 'Bonaire, Sint Eustatius and Saba'},
{state: 'assigned', alpha2: 'CW', alpha3: 'CUW', numeric: '531', name: 'Curaçao'},
{state: 'assigned', alpha2: 'SX', alpha3: 'SXM', numeric: '534', name: 'Sint Maarten (Dutch part)'}
]
},
{
alpha4: 'BQAQ',
type: 'merge',
from: {state: 'formerly-assigned', alpha2: 'BQ', alpha3: 'ATB', name: 'British Antarctic Territory'},
to: [
{state: 'assigned', alpha2: 'AQ', alpha3: 'ATA', numeric: '010', name: 'Antarctica'}
]
},
// …
]
Object with the following fields:
state
(State
) — State (example:'assigned'
)alpha2
(string
) — ISO 3166-1 alpha-2 code (example:'GB'
)alpha3
(string?
) — ISO 3166-1 alpha-3 code (example:'GBR'
)numeric
(string?
) — ISO 3166-1 numeric (UN M49) code (example:'826'
)name
(string?
) — Name (example:'United Kingdom of Great Britain and Northern Ireland'
)
Based on the state of the entry, fields may be available.
Assigned entries have all fields.
Reserved entries have alpha2
and name
fields.
string
, one of the following:
assigned
(example:VA
VAT
Holy See
)indeterminately-reserved
(example:FL
was used on some car vehicle distinguishing signs fromLI
LIE
Liechtenstein
before 1949)exceptionally-reserved
(example:UK
is reserved byUnited Kingdom
)transitionally-reserved
(example:BU
Burma
as it changed names toMM
MMR
Myanmar
in 1989)formerly-assigned
(example:PZ
Panama Canal Zone
, which was aUS
USA
United States of America
controlled area until 1979)
Most ISO 3166-1 entries are assigned, and therefore have a state
of
'assigned'
.
Some ISO 3166-1 entries are explicitly unassigned, but still have some data attached to them.
The following states are used for reserved entries:
'indeterminately-reserved'
— Reserved as other coding systems use them'exceptionally-reserved'
— Reserved by a national ISO member body'transitionally-reserved'
— Reserved for a while after removing a country'formerly-assigned'
— Codes that were previously in use (but are no longer strictly reserved)
ISO 3166-1 also has a concept of “user-assigned” codes, which can be used by
users (like you) to represent things not in ISO 3166 (example: XZ
represents
international waters in UN/LOCODE).
The user-assigned codes are:
- ISO 3166-1 alpha-2:
AA
,QM
toQZ
,XA
toXZ
, andZZ
- ISO 3166-1 alpha-3:
AAA
toAAZ
,QMA
toQZZ
,XAA
toXZZ
, andZZA
toZZZ
- ISO 3166-1 numeric:
900
to999
User-assigned codes will not be used by ISO 3166.
All other codes are unassigned and may be used by ISO 3166 in the future.
Object with the following fields:
code
(string
) — ISO 3166-2 code (example:GB-BFS
)name
(string
) — Name (example:'Belfast'
)parent
(string
) — ISO 3166-1 alpha-2 code or ISO 3166-2 code (example:'GB'
)
code
always has the format of an ISO 3166 alpha-2 code, followed by a hyphen
minus (-
), and one, two, or three upper alphabetical or numerical characters.
The latter part of the code is not unique: ID-RI
is the Riau province of
Indonesia and NG-RI
is the Rivers province in Nigeria.
parent
can be either the ISO 3166-1 alpha-2 of a country, or another ISO
3166-2 code of a subdivision.
The latter is true for BE-WNA
Namur
, whose parent is BE-WAL
Waals Gewest
, whose parent in turn is BE
BEL
Belgium
.
To get the country a subdivision is a part of, do something like
code.slice(0, 2)
to get the ISO 3166-1 alpha-2 code from an ISO 3166-2 code.
Object with the following fields:
alpha4
(string
) — ISO 3166-3 alpha-4 code (example:ANHH
)type
(Type
) — Type of revision (example:'split'
)from
(ISO31661Entry
) — Country before revisionto
(ISO31661Entry[]
) — List of countries after revision
The from
and to
entries may not match current ISO 3166-1 entries.
For example, CSHH
represents the split of CS
CSK
Czechoslovakia
to
CZ
CZE
Czech Republic
and SK
SVK
Slovakia
, but the former now uses
CZ
CZE
Czechia
.
Another example, YUCS
represents the change of YU
YUG
Yugoslavia
to
CS
SCG
Serbia and Montenegro
, but the latter later split with CSXX
to ME
MNE
Montenegro
and RS
SRB
Serbia
.
string
, one of the following:
merge
— Revision where one country merged with others (example:DDDE
represents the merger fromDD
DDR
German Democratic Republic
to formDE
DEU
Germany
in 1990)change
— Significant name revision (example:BYAA
represents the name change fromBY
BYS
Byelorussian SSR
toBY
BLR
Belarus
in 1992)split
— Revision where one country split into others (example:NTHH
represents the division ofNT
NTZ
Neutral Zone
toIQ
IRQ
Iraq
andSA
SAU
Saudi Arabia
in 1993)
bcp-47
— Parse and stringify BCP 47 language tagsbcp-47-normalize
— Normalize, canonicalize, and format BCP 47 tagsbcp-47-match
— Match BCP 47 language tags with language ranges per RFC 4647iso-639-2
— ISO 639-2 codesiso-639-3
— ISO 639-3 codesiso-15924
— ISO 15924 codesun-m49
— UN M49 codes