countries-and-timezones vs i18n-iso-countries vs countries-list vs country-list vs iso-3166-1 vs country-data
Country and Timezone Libraries Comparison
1 Year
countries-and-timezonesi18n-iso-countriescountries-listcountry-listiso-3166-1country-dataSimilar Packages:
What's Country and Timezone Libraries?

These libraries provide developers with tools to manage country data and timezones in applications. They facilitate the retrieval of country names, codes, and timezone information, which is essential for localization, internationalization, and various geographical functionalities in web applications. Each library has its unique features, data formats, and use cases, making it important to choose the right one based on specific project requirements.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
countries-and-timezones823,987242316 kB95 months agoMIT
i18n-iso-countries777,548830624 kB3915 days agoMIT
countries-list271,6971,220272 kB167 months agoMIT
country-list235,41327016.6 kB5-MIT
iso-3166-1129,6565738.1 kB4-MIT
country-data75,693517-358 years agoMIT
Feature Comparison: countries-and-timezones vs i18n-iso-countries vs countries-list vs country-list vs iso-3166-1 vs country-data

Data Coverage

  • countries-and-timezones:

    Offers comprehensive data on countries and their respective timezones, including daylight saving time adjustments and historical timezone data.

  • i18n-iso-countries:

    Delivers country names in multiple languages, enhancing localization capabilities for international applications.

  • countries-list:

    Provides a basic list of countries and their ISO codes without additional metadata or timezone information.

  • country-list:

    Focuses solely on country names and ISO codes, ensuring a lightweight and efficient data retrieval process.

  • iso-3166-1:

    Strictly adheres to ISO 3166-1 standards, providing reliable country codes and names.

  • country-data:

    Includes detailed country information such as population, area, and currency, making it suitable for applications needing in-depth demographic data.

Localization Support

  • countries-and-timezones:

    Limited localization support, primarily focused on timezone data rather than localized country names.

  • i18n-iso-countries:

    Strong localization support, providing country names in various languages, making it ideal for international applications.

  • countries-list:

    No localization support; it provides country names in English only.

  • country-list:

    No localization; it offers country names in English only.

  • iso-3166-1:

    No localization; it strictly provides country codes and names in English.

  • country-data:

    No localization features; it focuses on demographic data without language variations.

Ease of Use

  • countries-and-timezones:

    Easy to use with a clear API for accessing timezone and country data, but may require additional handling for timezone calculations.

  • i18n-iso-countries:

    User-friendly with clear documentation, making it easy to retrieve localized country names for internationalization.

  • countries-list:

    Extremely simple to integrate, with a straightforward JSON structure that is easy to parse and use in applications.

  • country-list:

    Very easy to use; provides a minimalistic approach to accessing country names and codes without unnecessary complexity.

  • iso-3166-1:

    Simple to use for retrieving ISO codes, but lacks additional features or metadata.

  • country-data:

    User-friendly API that allows easy access to a wide range of country-related data, though it may be more complex than simpler libraries.

Data Format

  • countries-and-timezones:

    Data is structured in a comprehensive format that includes timezone offsets and rules, making it suitable for complex applications.

  • i18n-iso-countries:

    Structured JSON format that includes country names in multiple languages, facilitating easy localization.

  • countries-list:

    Provides a simple JSON format with country names and ISO codes, ensuring quick integration.

  • country-list:

    Delivers a minimal JSON format with just country names and codes, ensuring lightweight usage.

  • iso-3166-1:

    Provides a straightforward JSON format with ISO codes and names, adhering to international standards.

  • country-data:

    Offers a detailed JSON structure that includes various attributes for each country, suitable for applications needing extensive data.

Maintenance and Updates

  • countries-and-timezones:

    Regularly maintained with updates for timezone changes and new countries as needed, ensuring data accuracy.

  • i18n-iso-countries:

    Regularly updated to include new country names and changes in localization needs, ensuring relevance.

  • countries-list:

    Lightweight and easy to maintain, but may not receive frequent updates as it focuses on basic data.

  • country-list:

    Minimal maintenance required; updates may not be frequent due to the static nature of the data provided.

  • iso-3166-1:

    Maintained in accordance with ISO standards, ensuring that the data remains accurate and up-to-date.

  • country-data:

    Actively maintained with regular updates to include new demographic data and changes in country status.

How to Choose: countries-and-timezones vs i18n-iso-countries vs countries-list vs country-list vs iso-3166-1 vs country-data
  • countries-and-timezones:

    Choose this package if you need comprehensive timezone data along with country information. It includes detailed timezone offsets and daylight saving time rules, making it ideal for applications that require accurate time calculations across different regions.

  • i18n-iso-countries:

    Choose this package if you need to handle internationalization and localization effectively. It provides country names in multiple languages, which is essential for applications targeting diverse user bases.

  • countries-list:

    Opt for this package if you need a simple and lightweight solution for country names and ISO codes. It provides a straightforward JSON format, making it easy to integrate into projects without additional dependencies or complexity.

  • country-list:

    Use this package if you want a minimalistic approach to retrieve country names and codes. It is straightforward and efficient for applications that do not require additional metadata about the countries.

  • iso-3166-1:

    Select this package if you specifically need ISO 3166-1 country codes and their corresponding names. It is useful for applications that require strict adherence to international standards for country identification.

  • country-data:

    Select this package if you require extensive country data, including population, area, and currency information. It is suitable for applications that need detailed demographic and economic data about countries.

README for countries-and-timezones

countries-and-timezones

GitHub Actions Status NPM Downloads License: MIT

Minimalistic library to work with countries and timezones data. Updated with the IANA timezones database.

Usage

NodeJS

Install with npm or yarn:

npm install --save countries-and-timezones

Browser

Add the following script to your project (only ~9kb):

<!-- Latest version -->
<script
  src="https://cdn.jsdelivr.net/gh/manuelmhtr/countries-and-timezones@latest/dist/index.min.js"
  type="text/javascript"
></script>

<!-- Or specify a version -->
<script
  src="https://cdn.jsdelivr.net/gh/manuelmhtr/countries-and-timezones@v3.7.1/dist/index.min.js"
  type="text/javascript"
></script>

<!-- This will export a variable named "ct": -->
<script type="text/javascript">
  var data = ct.getCountry("MX");
  console.log(data);
</script>

API

.getCountry(id, options = {})

Returns a country referenced by its id.

Accepts a parameter with options.

Example

const ct = require("countries-and-timezones");

const country = ct.getCountry("DE");
console.log(country);

/*
Prints:

{
  id: 'DE',
  name: 'Germany',
  timezones: [ 'Europe/Berlin', 'Europe/Zurich' ]
}

*/

.getTimezone(name)

Returns a timezone referenced by its name.

Example

const ct = require("countries-and-timezones");

const timezone = ct.getTimezone("America/Los_Angeles");
console.log(timezone);

/*
Prints:

{
  name: 'America/Los_Angeles',
  countries: [ 'US' ],
  utcOffset: -480,
  utcOffsetStr: '-08:00',
  dstOffset: -420,
  dstOffsetStr: '-07:00',
  aliasOf: null
}

*/

.getAllCountries(options = {})

Returns an object with the data of all countries.

Accepts a parameter with options.

Example

const ct = require("countries-and-timezones");

const countries = ct.getAllCountries();
console.log(countries);

/*
Prints:

{
  AD: {
    id: 'AD',
    name: 'Andorra',
    timezones: [ 'Europe/Andorra' ]
  },
  AE: {
    id: 'AE',
    name: 'United Arab Emirates',
    timezones: [ 'Asia/Dubai' ]
  },
  AF: {
    id: 'AF',
    name: 'Afghanistan',
    timezones: [ 'Asia/Kabul' ]
  },
  AG: {
    id: 'AG',
    name: 'Antigua and Barbuda',
    timezones: [ 'America/Puerto_Rico' ]
  },
  ...
}

*/

.getAllTimezones(options = {})

Returns an object with the data of all timezones.

Accepts a parameter with options.

Example

const ct = require("countries-and-timezones");

const timezones = ct.getAllTimezones();
console.log(timezones);

/*
Prints:

{
  "Africa/Abidjan": {
    "name": "Africa/Abidjan",
    "countries": [
      "CI", "BF", "GH",
      "GM", "GN", "ML",
      "MR", "SH", "SL",
      "SN", "TG"
    ],
    "utcOffset": 0,
    "utcOffsetStr": "+00:00",
    "dstOffset": 0,
    "dstOffsetStr": "+00:00",
    "aliasOf": null
  },
  "Africa/Algiers": {
    "name": "Africa/Algiers",
    "countries": [
      "DZ"
    ],
    "utcOffset": 60,
    "utcOffsetStr": "+01:00",
    "dstOffset": 60,
    "dstOffsetStr": "+01:00",
    "aliasOf": null
  },
  "Africa/Bissau": {
    "name": "Africa/Bissau",
    "countries": [
      "GW"
    ],
    "utcOffset": 0,
    "utcOffsetStr": "+00:00",
    "dstOffset": 0,
    "dstOffsetStr": "+00:00",
    "aliasOf": null
  },
  ...
}

*/

.getTimezonesForCountry(id, options = {})

Returns an array with all the timezones of a country given its id.

Accepts a parameter with options.

Example

const ct = require("countries-and-timezones");

const timezones = ct.getTimezonesForCountry("MX");
console.log(timezones);

/*
Prints:

[
  {
    "name": "America/Bahia_Banderas",
    "countries": [ "MX" ],
    "utcOffset": -360,
    "utcOffsetStr": "-06:00",
    "dstOffset": -300,
    "dstOffsetStr": "-05:00",
    "aliasOf": null
  },
  {
    "name": "America/Cancun",
    "countries": [ "MX" ],
    "utcOffset": -300,
    "utcOffsetStr": "-05:00",
    "dstOffset": -300,
    "dstOffsetStr": "-05:00",
    "aliasOf": null
  },
  {
    "name": "America/Chihuahua",
    "countries": [ "MX" ],
    "utcOffset": -420,
    "utcOffsetStr": "-07:00",
    "dstOffset": -360,
    "dstOffsetStr": "-06:00",
    "aliasOf": null
  },
  ...
}

*/

.getCountriesForTimezone(name, options = {})

Returns a list of the countries that uses a timezone given its name. When a timezone has multiple countries the first element is more relevant due to its geographical location.

Accepts a parameter with options.

Example

const ct = require("countries-and-timezones");

const timezone = ct.getCountriesForTimezone("Europe/Zurich");
console.log(timezone);

/*
Prints:

[
  {
    "id": "CH",
    "name": "Switzerland",
    "timezones": [
      "Europe/Zurich"
    ]
  },
  {
    "id": "DE",
    "name": "Germany",
    "timezones": [
      "Europe/Berlin",
      "Europe/Zurich"
    ]
  },
  {
    "id": "LI",
    "name": "Liechtenstein",
    "timezones": [
      "Europe/Zurich"
    ]
  }
]

*/

.getCountryForTimezone(name, options = {})

Returns a the most relevant country (due to its geographical location) that uses a timezone given its name.

Accepts a parameter with options.

Example

const ct = require("countries-and-timezones");

const timezone = ct.getCountryForTimezone("Europe/Zurich");
console.log(timezone);

/*
Prints:

{
  "id": "CH",
  "name": "Switzerland",
  "timezones": [
    "Europe/Zurich"
  ]
}

*/

options

Available options for functions are:

| Parameter | Type | Description | | ------------ | ------- | -------------------------------------------------------------------------------------------------------------------- | | deprecated | Boolean | Indicates if the result should include deprecated timezones or not. By default no deprecated timezones are included. |

Data models

Country

A country is defined by the following parameters:

| Parameter | Type | Description | | ----------- | ------------- | ------------------------------------------------------------------------ | | id | String | The country ISO 3166-1 code. | | name | String | Preferred name of the country. | | timezones | Array[String] | The list of timezones used in the country. |

{
  id: 'MX',
  name: 'Mexico',
  timezones: [
    'America/Bahia_Banderas',
    'America/Cancun',
    'America/Chihuahua',
    'America/Hermosillo',
    'America/Matamoros',
    'America/Mazatlan',
    'America/Merida',
    'America/Mexico_City',
    'America/Monterrey',
    'America/Ojinaga',
    'America/Tijuana'
  ]
}

Timezone

A timezone is defined by the following parameters:

| Parameter | Type | Description | | -------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | name | String | The name of the timezone, from tz database. | | countries | [String] | A list of ISO 3166-1 codes of the countries where it's used. Etc/*, GMT and UTC timezones don't have associated countries. | | utcOffset | Number | The difference in minutes between the timezone and UTC. | | utcOffsetStr | String | The difference in hours and minutes between the timezone and UTC, expressed as string with format: ±[hh]:[mm]. | | dstOffset | Number | The difference in minutes between the timezone and UTC during daylight saving time (DST). When utcOffset and dstOffset are the same, means that the timezone does not observe a daylight saving time. | | dstOffsetStr | String | The difference in hours and minutes between the timezone and UTC during daylight saving time (DST, expressed as string with format: ±[hh]:[mm]. | | aliasOf | String | The name of a primary timezone in case this is an alias. null means this is a primary timezone. | | deprecated | Boolean | true when the timezone has been deprecated, otherwise this property is not returned. |

{
  name: 'Asia/Tel_Aviv',
  countries: [ 'IL' ],
  utcOffset: 120,
  utcOffsetStr: '+02:00',
  dstOffset: 180,
  dstOffsetStr: '+03:00',
  aliasOf: 'Asia/Jerusalem',
  deprecated: true
}

Related projects

Support

Consider sponsoring this project.

Working on something more complex?

Meet Spott:

  • Search any city, country or administrative division in the world. By full strings or autocompletion.
  • Find a place by an IP address.
  • Access to more than 240,000 geographical places. In more than 20 languages.

Spott API for cities, countries and administrative divisions

License

MIT