ISO 3166 (standard for country codes and codes for their subdivisions)
npm install iso-3166[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
Info on [ISO 3166][i3166].
* What is this?
* When should I use this?
* Matrix
* Install
* Use
* API
* iso31661
* iso31661Reserved
* iso31662
* iso31663
* Types
* Compatibility
* Security
* Related
* Contribute
* License
This package contains info on ISO 3166.
The purpose of ISO 3166 is to define internationally recognized codes that we
can use when we refer to countries and their subdivisions.
ISO 3166 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 for
California in US USA United States of America)
* ISO 3166-3 defines codes for former countries (such as BUMM to refer
to when BU BUR Burma revised its name to MM MMR Myanmar in 1989)
While the information in ISO 3166 is well known and freely available through for
example WikiPedia, it is not freely available in a 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][um49] 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 exports:
* [iso31661][1]
— countries: list of [assigned][] ISO 3166-1 entries
* [iso31662][2]
— subdivisions: list of ISO 3166-2 entries
* [iso31663][3]
— revisions: list of ISO 3166-3 entries
Additionally, a list of reserved ISO 3166-1 entries is available:
* [iso31661Reserved][1-reserved]
— list of [reserved][] ISO 3166-1 entries
Finally, indexes are available to map between different codes:
* [iso31661Alpha2ToAlpha3][1-a2-to-1-a3]
— map ISO 3166-1 alpha-2 codes to ISO 3166-1 alpha-3 codes
* [iso31661Alpha2ToNumeric][1-a2-to-1-n]
— map ISO 3166-1 alpha-2 codes to ISO 3166-1 numeric (UN M49) codes
* [iso31661Alpha3ToAlpha2][1-a3-to-1-a2]
— map ISO 3166-1 alpha-3 codes to ISO 3166-1 alpha-2 codes
* [iso31661NumericToAlpha2][1-n-to-1-a2]
— map ISO 3166-1 numeric (UN M49) codes to ISO 3166-1 alpha-2 codes
You can use this package any time you have to deal with countries and
subdivisions or ISO 3166 in particular.
The alphabetical codes from ISO 3166 are more useful to humans, but the
numerical codes from [UN M49][um49] are more resilient to changes.
UN M49 also encodes regions bigger than countries, such as (sub)contintents.
Show 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
AC
AD
AE
AF
AG
AH
AI
AJ
AK
AL
AM
AN
AO
AP
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
BU
BV
BW
BX
BY
BZ
C
CA
CB
CC
CD
CE
CF
CG
CH
CI
CJ
CK
CL
CM
CN
CO
CP
CQ
CR
CS
CT
CU
CV
CW
CX
CY
CZ
D
DA
DB
DC
DD
DE
DF
DG
DH
DI
DJ
DK
DL
DM
DN
DO
DP
DQ
DR
DS
DT
DU
DV
DW
DX
DY
DZ
E
EA
EB
EC
ED
EE
EF
EG
EH
EI
EJ
EK
EL
EM
EN
EO
EP
EQ
ER
ES
ET
EU
EV
EW
EX
EY
EZ
F
FA
FB
FC
FD
FE
FF
FG
FH
FI
FJ
FK
FL
FM
FN
FO
FP
FQ
FR
FS
FT
FU
FV
FW
FX
FY
FZ
G
GA
GB
GC
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
HV
HW
HX
HY
HZ
I
IA
IB
IC
ID
IE
IF
IG
IH
II
IJ
IK
IL
IM
IN
IO
IP
IQ
IR
IS
IT
IU
IV
IW
IX
IY
IZ
J
JA
JB
JC
JD
JE
JF
JG
JH
JI
JJ
JK
JL
JM
JN
JO
JP
JQ
JR
J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
WB
WC
WD
WE
WF
WG
WH
WI
WJ
WK
WL
WM
WN
WO
WP
WQ
WR
WS
WT
WU
WV
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
YD
YE
YF
YG
YH
YI
YJ
YK
YL
YM
YN
YO
YP
YQ
YR
YS
YT
YU
YV
YW
YX
YY
YZ
Z
ZA
ZB
ZC
ZD
ZE
ZF
ZG
ZH
ZI
ZJ
ZK
ZL
ZM
ZN
ZO
ZP
ZQ
ZR
ZS
ZT
ZU
ZV
ZW
ZX
ZY
ZZ
This package is [ESM only][esm].
In Node.js (version 14.14+, 16.0+), install with [npm][]:
``sh`
npm install iso-3166
In Deno with [esm.sh][esmsh]:
`js`
import * as iso3166 from 'https://esm.sh/iso-3166@4'
In browsers with [esm.sh][esmsh]:
`html`
See examples below.
This package exports the identifiers iso31661, iso31661Alpha2ToAlpha3,iso31661Alpha2ToNumeric, iso31661Alpha3ToAlpha2, iso31661NumericToAlpha2,iso31661Reserved, iso31662, iso31663.
There is no default export.
List of assigned ISO 3166-1 countries ([Array][1-entry]).
###### Example
`js
import {iso31661} from 'iso-3166'
console.log(iso31661)
`
Yields:
`js`
[
{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'},
// …
]
List of reserved ISO 3166-1 countries ([Array][1-entry]).
###### Example
`js
import {iso31661Reserved} from 'iso-3166'
console.log(iso31661Reserved)
`
Yields:
`js`
[
{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'},
// …
]
List of ISO 3166-2 subdivisions ([Array][2-entry]).
###### Example
`js
import {iso31662} from 'iso-3166'
console.log(iso31662)
`
Yields:
`js`
[
{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'},
// …
]
List of ISO 3166-3 changes ([Array][3-entry]).
###### Example
`js
import {iso31663} from 'iso-3166'
console.log(iso31663)
`
Yields:
`js`
[
{
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'}
]
},
// …
]
#### ISO31661Entry
Object representing a country.
* state ([State][state])'assigned'
— state (example: )alpha2
* (string)'GB'
— ISO 3166-1 alpha-2 code (example: )alpha3
* (string?)'GBR'
— ISO 3166-1 alpha-3 code (example: )numeric
* (string?)'826'
— ISO 3166-1 numeric (UN M49) code (example: )name
* (string?)'United Kingdom of Great Britain and Northern Ireland'
— name (example: )
Based on the state of the entry, fields may be available.
[Assigned][] entries have all fields.
[Reserved][] entries have alpha2 and name fields.
##### State
string, one of the following:
* 'assigned'VA
— currently assigned
(example: VAT Holy See)'indeterminately-reserved'
* FL
— reserved as other coding systems use them
(example: was used on some car vehicle distinguishing signs from LILIE
Liechtenstein before 1949)'exceptionally-reserved'
* UK
— reserved by a national ISO member body
(example: is reserved by United Kingdom)'transitionally-reserved'
* BU
— reserved for a while after removing a country
(example: Burma as it changed names to MMMMR
Myanmar in 1989)'formerly-assigned'
* PZ
— codes that were previously in use but are no longer strictly reserved
(example: Panama Canal Zone, which was a USUSA
United States of America controlled area until 1979)
###### Assigned
Many ISO 3166-1 entries are assigned and therefore have a state of'assigned'.
###### Reserved
Some ISO 3166-1 entries are not assigned but still have some data attached to
them.
###### User-assigned
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 to QZ, XA to XZ, and ZZAAA
* ISO 3166-1 alpha-3:
to AAZ, QMA to QZZ, XAA to XZZ, and ZZA to ZZZ900
* ISO 3166-1 numeric:
to 999
User-assigned codes will not be used by ISO 3166 and are not exposed by this
package.
###### Unassigned
All other codes are unassigned and may be used by ISO 3166 in the future.
Unassigned codes are not exposed by this package.
#### ISO31662Entry
Object representing a subdivision of a country.
* code (string)GB-BFS
— ISO 3166-2 code (example: )name
* (string)'Belfast'
— name (example: )parent
* (string)'GB'
— ISO 3166-1 alpha-2 code or ISO 3166-2 code (example: )
The code field always has the format of an ISO 3166 alpha-2 code, followed by-
a hyphen minus (), and one, two, or three upper alphabetical or numericalID-RI
characters.
The latter part of the code is not unique: is the Riau province ofNG-RI
Indonesia and is the Rivers province in Nigeria.
The parent field can be either the ISO 3166-1 alpha-2 of a country, or anotherBE-WNA
ISO 3166-2 code of a subdivision.
The latter is true for Namur, whose parent is BE-WALWaals Gewest, whose parent in turn is BE BEL Belgium.code.slice(0, 2)
To get the country a subdivision is a part of, do something like to get the ISO 3166-1 alpha-2 code from an ISO 3166-2 code.
#### ISO31663Entry
Object representing a change to a country.
* alpha4 (string)ANHH
— ISO 3166-3 alpha-4 code (example: )type
* ([Type][type])'split'
— type of revision (example: )from
* ([ISO31661Entry][1-entry])to
— country before revision
* ([ISO31661Entry[]][1-entry])
— list of countries after revision
The entries in from and to may not match current ISO 3166-1 entries.CSHH
For example, represents the split of CS CSK Czechoslovakia toCZ CZE Czech Republic and SK SVK Slovakia, but the former now usesCZ CZE Czechia.YUCS
Another example, represents the change of YU YUG Yugoslavia toCS SCG Serbia and Montenegro, but the latter later split with CSXX to ME MNE Montenegro and RS SRB Serbia.
##### Type
string, one of the following:
* 'merge'DDDE
— revision where one country merged with others
(example: represents the merger from DD DDR German Democratic
Republic to form DE DEU Germany in 1990)'change'
* BYAA
— significant name revision
(example: represents the name change from BY BYS Byelorussian
SSR to BY BLR Belarus in 1992)'split'
* NTHH
— revision where one country split into others
(example: represents the division of NT NTZ Neutral Zone toIQ
IRQ Iraq and SA SAU Saudi Arabia in 1993)
This package is fully typed with [TypeScript][].
It exports the additional types ISO31661Entry, ISO31661AssignedEntry,ISO31661ReservedEntry, ISO31662Entry, ISO31663Entry, State, and Type.
This package is at least compatible with all maintained versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
It also works in Deno and modern browsers.
This package is safe.
* wooorm/bcp-47
— parse and stringify BCP 47 language tags
* wooorm/bcp-47-normalize
— normalize, canonicalize, and format BCP 47 tags
* wooorm/bcp-47-match
— match BCP 47 language tags with language ranges per RFC 4647
* wooorm/iso-639-2
— ISO 639-2 codes
* wooorm/iso-639-3
— ISO 639-3 codes
* wooorm/iso-15924
— ISO 15924 codes
* wooorm/un-m49`
— UN M49 codes
Yes please!
See [How to Contribute to Open Source][contribute].
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/wooorm/iso-3166/workflows/main/badge.svg
[build]: https://github.com/wooorm/iso-3166/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/iso-3166.svg
[coverage]: https://codecov.io/github/wooorm/iso-3166
[downloads-badge]: https://img.shields.io/npm/dm/iso-3166.svg
[downloads]: https://www.npmjs.com/package/iso-3166
[size-badge]: https://img.shields.io/bundlephobia/minzip/iso-3166.svg
[size]: https://bundlephobia.com/result?p=iso-3166
[npm]: https://docs.npmjs.com/cli/install
[esmsh]: https://esm.sh
[license]: license
[author]: https://wooorm.com
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[typescript]: https://www.typescriptlang.org
[contribute]: https://opensource.guide/how-to-contribute/
[i3166]: https://www.iso.org/iso-3166-country-codes.html
[um49]: https://unstats.un.org/unsd/methodology/m49/
[1]: 1.js
[2]: 2.js
[3]: 3.js
[1-reserved]: 1-reserved.js
[1-a2-to-1-a3]: 1-a2-to-1-a3.js
[1-a2-to-1-n]: 1-a2-to-1-n.js
[1-a3-to-1-a2]: 1-a3-to-1-a2.js
[1-n-to-1-a2]: 1-n-to-1-a2.js
[1-entry]: #iso31661entry
[2-entry]: #iso31662entry
[3-entry]: #iso31663entry
[state]: #state
[type]: #type
[assigned]: #assigned
[reserved]: #reserved