Gathering detailed insights and metrics for iso3166-2-db
Gathering detailed insights and metrics for iso3166-2-db
npm install iso3166-2-db
Typescript
Module System
Node Version
NPM Version
92.8
Supply Chain
100
Quality
77.1
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
1,324,958
Last Day
1,495
Last Week
6,903
Last Month
30,086
Last Year
292,287
128 Stars
98 Commits
28 Forks
9 Watching
3 Branches
10 Contributors
Minified
Minified + Gzipped
Latest Version
2.3.11
Package Id
iso3166-2-db@2.3.11
Unpacked Size
169.08 MB
Size
17.25 MB
File Count
42,268
NPM Version
8.19.4
Node Version
16.20.2
Publised On
11 Jul 2024
Cumulative downloads
Total Downloads
Last day
-19.8%
1,495
Compared to previous day
Last week
-31.8%
6,903
Compared to previous week
Last month
20.5%
30,086
Compared to previous month
Last year
7.2%
292,287
Compared to previous year
The country codes are mainly in the ISO 3166-1 alpha 2
format (US, SE ...).
It also possible to use alpha 3
codes (USA, SWE ...) or alpha-numeric codes
. In most cases you need alpha-2.
This world is small enough. But not everyone knows all countries and all states. List of countries is known as iso3166-1 and lists of states or regions is known as iso3166-2. And lets extend information withexternal references to all sources, you may use (GeoNames, OpenStreetMap, Wikipedia, WOF) This is nodejs/javascript module, but you can use it as set of json files from other languages
1import worldDatabase from 'iso3166-2-db/i18n/dispute/UN/en'; 2import listOfCountries from 'iso3166-2-db/countryList/dispute/UN/en'; 3import USregions from 'iso3166-2-db/regions/US/dispute/UN/en';
en, ru, de, fr, es, zh, hi, pt, ja, ar, it, he
Any country, and language and any set could be loaded separate
1 // to get both states and countries in an English from UN prospective 2 import data from 'iso3166-2-db/i18n/dispute/UN/en'; 3 4 // to get only list countries in an English from UN prospective 5 import data from 'iso3166-2-db/countryList/UN/en'; 6 7 // to get only list stated for the country in an %Lang% from UN prospective 8 import data from 'iso3166-2-db/regions/{COUNTRYISOCODE}/UN/{lang}';
Yep. Did not forget to add /dispute/UN/
. It is the main difference between this library and any other - it knows that world is not united, yet.
points of view
(ie Territorial dispute)trusted
sourcesnpm install iso3166-2-db
You have 2 ways to use this library:
Use it at backend
. Just import few function from 'iso3166-2-db' and go on.
You will have everything - all data, pack of languages, with different dispute models and name sources.
But - full database has a size of few megabytes.
Use it as data files, ie modular format - this way is preferred for frontend
.
Result will produce much smaller code.
modular
API - pure
and compiled
.
In 99% cases you need - compiled1 // to get country list. 2 import data from 'iso3166-2-db/countryList/dispute/UN/{lang}' 3 // to get states(regions) for selected country. 4 import data from 'iso3166-2-db/regions/{iso3166-1}/dispute/UN/{lang}' 5 // to get both states and countries. 6 import data from 'iso3166-2-db/i18n/dispute/UN/{lang}'
Where UN - is United Nations. World from United Nations point of view. We call this - dispute
.
Possible values - UN, UA, TR, RU. IF you need more - open a pull request.
You can also load pure
data:
1 //to get country list. 2 import data from 'iso3166-2-db/countryList/{lang}' 3 // to get states(regions) for selected country. 4 import data from 'iso3166-2-db/regions/{iso3166-1}/*' 5 //to get both states and countries. 6 import data from 'iso3166-2-db/i18n/{lang}'
PS: import ..._ref, to get data with external references. It has a bit bigger size.
1 import data from 'iso3166-2-db/i18n/{lang}_ref'
1 // just import what you want - /countryList/{lang} 2 import countryList from 'iso3166-2-db/countryList/en'; 3 4 // or, to have foreignKeys to wikipedia, geonames and so on 5 import countryListWithForeignKeys from 'iso3166-2-db/countryList/en_ref'; 6 7 // import states for a country /countryList/{iso1}/{lang} 8 // import states for a country /countryList/{iso1}/dispute/{source}/{lang} 9 10 // will import RU states for point of view of United Nations - without Crimea 11 import US from 'iso3166-2-db/regions/RU/dispute/UN/en'; 12 // will import RU states for point of view of Russia - including Crimea 13 import US from 'iso3166-2-db/regions/RU/dispute/RU/en';
pure
data1// you can import `default` dataset 2import US from 'iso3166-2-db/regions/US/en'; 3// or, import with foreignKeys 4import US from 'iso3166-2-db/regions/US/en_ref'; 5import DE from 'iso3166-2-db/regions/DE/de_ref';// use other lang for other country? Simple! 6 7//import combine function 8import { combine } 'iso3166-2-db/combine'; 9 10// join country dataset with states 11const dataSet = combine(countryList, { US }) ;// !!!! region object key MUST match iso code. 12// dataSet is similar to i18n, but contains regions only for US, not for a whole world. 13
To process pure
data you should call getDataSet command.
1 2// you can also import only function from library, with out data 3import { getDataSet, getRegionsFor, changeDispute, changeNameProvider, findCountryByName, findRegionByCode } from 'iso3166-2-db/api'; 4 5const fixedDataSet = getDataSet('en', combine(countryList, { US })); 6// this command will move some disputed regions across countries. 7// without this command few things can be wrong. See below.
I hope you did not understand, what dispute
means, and why you should run getDataSet.
it is very simple -
1import RU from 'iso3166-2-db/regions/RU/dispute/UN/en' // - will NOT contain Crimea 2import RU from 'iso3166-2-db/regions/RU/en' // - will NOT contain Crimea 3import RU from 'iso3166-2-db/regions/RU/dispute/RU/en' // - will CONTAIN Crimea 4const fixedDataSet = getDataSet('ru', combine(countryList, { RU })); // - will CONTAIN Crimea
Also some countries are not exists, or exists not as counties, but as stated by point of view of some different countries.
See example
getDataSet
and traverse look for .name in every object insideJust look at source json file, and you will understand.
So we have some simple things:
data/iso3166-2.json – main datafile. It containtains all counties and all regions. Just keep in mind - this is not a stupid list of names. We provide all information for any entity:
Best option is to use this file directly.
src/disputedBorders.js – set of pure functions to transform main data file for "your" country. As long all countries have their own mind. Only UN001(US), RU, UA, TR schemes supported.
Remember – main data file is wrong
by default. You HAVE to apply some filter to data.
Or you will get TW as country and Crimea as part of Russia (use 'ru' dispute mode to have it :P).
Remember – to add one region to one place, you have to remove it from other place
Ie, to add
Crimea into Russian states you have to have US states.
src/iso3166.js – library logic (main entry point)
We have a simply command for it(2.) getDataSet(dispute='en') for it.
And every one have their own knowlege
about naming. And every one have different.
What is why we create this library – to bring a peace (and foreign keys).
But, you really might wish to use different names from different sources. And we have a tools for it!
Just call changeNameProvider('geonames|osm|wikipedia')
(yup, by default we use wikipedia article names)
Working only for backend way
.
And do not forget THIS THING IS FOR BACKEND!
Datafiles are VERY large. But you can reduce them.
Call reduce(dataSet, lng, listOfCountries)
to get data ONLY for one language and selected countries.
name will be filled into .name field of entity. .names will be dropped.
example: reduce(getDataSet(), 'en', ['US','CA','AU'])
And be aware - some states
are not the states. Until they have iso3166-2(iso) code.
Some of them contain only FIPS
.
Also be aware about operstreetmap_level. Most of regions have 4
. Some of them (in Slovenia) have 6
. But.. there is regions with 7
.
I am not sure about them.
This is open source made from open source. Everything can be wrong. And will be.
Main datafile is auto generated from free sources.
Country list is a hash. Key is a iso3166-1 code Value
1{ 2 "iso": "AD", //iso3166-1 `two` letter code 3 "iso3": "AND", //iso3166-1 `three` letter code 4 "numeric": 20, //iso3166-1 `numeric` code 5 "fips": "AN", //FIPS code 6 // next key is exist only in `_ref` exports 7 "reference": { // external reference to 8 "geonames": 3041565, // geonames.org 9 "openstreetmap": 9407, // openstreetmap releation id 10 "wikipedia": "en:Andorra" // wikipedia article 11 }, 12 // next key is not exist in full pack 13 name: "Andorra", 14 // next key is not exist in language-reduced pack 15 "names": { // names in different languages 16 "geonames": "Andorra", 17 "en": "Andorra", 18 "ar": "أندورا", 19 "de": "Andorra", 20 "es": "Andorra", 21 "fr": "Andorre", 22 "it": "Andorra", 23 "ru": "Андорра", 24 "zh": "Chinese" 25 }, 26 regions:[ /* set of regions */] 27 }
Regions is an array of
1{ 2 // next keys will contain name in selected language 3 "name": "Sant Julià de Lòria", 4 // next keys is not exists in language-reduced pack 5 "names": { 6 "geonames": "Parroquia de Sant Julia de Loria", 7 "ru": "Сан-Жулиа-де-Лория", 8 "en": "Sant Julià de Lòria", 9 "de": "Sant Julià de Lòria", 10 "es": "San Julián de Loria", 11 "fr": "Sant Julià de Lòria", 12 "it": "Parrocchia di Sant Julià de Lòria", 13 "zh": "圣胡利娅-德洛里亚" 14 }, 15 "iso": "06", // iso3166-2 code 16 "fips": "06", // FIPS code 17 // next key is exist only in `_ref` exports 18 "reference": { 19 "geonames": 3039162, // geonames.org 20 "openstreetmap": 2804759, // openstreetmap relation id 21 "openstreetmap_level": 7, // openstreetmap administrative division level 22 "wikipedia": "en:Sant_Julià_de_Lòria", // wikipedia article 23 "wof": null // WOF code 24 } 25},
Used sources:
As result - iso3166-2-db is best best free source for countries divisions. With incomparable to Statoids(1000$ btw) quality. I mean - this one is better.
All sources used as external dictionaries, for ability to link and merge data.
Countries and states exists by themselves and have their own names.
You dont have to refer to us, to wikipedia, to osm, geonames or everything else in cases you showing our
list of countries.
This is not our
or their
list. This is ground truth, and it cannot be licensed.
We are on the same planet.
No vulnerabilities found.
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
Found 7/21 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
39 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More