Code Monkey home page Code Monkey logo

country-codes-list's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

country-codes-list's Issues

Type issue while working with typescript

node_modules/country-codes-list/index.d.ts:60:8 - error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.

60 ): { [CountryProperty]: string };

Export enum as const

There is a interface for customList to provide key, and this key is defined as CustomProperty enum. This enum is defined without const what means is not accessible in runtime. if i want to us customList function and define key as you did in documentation i we got ts error

Zrzut ekranu 2023-07-13 o 16 41 51

I could use correct value like this:

Zrzut ekranu 2023-07-13 o 16 42 04

but const in declaration is required to be able to use it in runtime

Wrong return type of customArray?

I am using this awesome library with Typescript and came across customArray.
Its just what I wanted, but it seems that the return type is string[].
Shouldn't it be something similar to {value: string, name: string}[]?

Cannot read properties of undefined (reading 'countryCode')

import countryCodes, { CountryProperty } from 'country-codes-list'

console.log(countryCodesList.CountryProperty.countryCode)

⨯ TypeError: Cannot read properties of undefined (reading 'countryCode')

node: v18.17.0
typescript: v5.4.2

Missing country codes (ISO 3166 COUNTRY CODES)

Typescript index Incorrect computed property name type

Hello,

The computed property name type in the customList function might incorrect. Currently, the code attempts to use CountryProperty as a computed property name, but TypeScript throws an error because CountryProperty is not a literal type or a unique symbol type.

The corrected code can be

index.d.ts:60

export function customList(
  key?: CountryProperty,
  label?: string,
  settings?: CustomArraySettings,
): { [K in CountryProperty]: string };

or

export function customList(
  key?: CountryProperty,
  label?: string,
  settings?: CustomArraySettings,
): { [key: string]: string };

Multiple entries have the same country code [`IO`]

Context

Library version: 1.6.11
Environment: [email protected]

I'm using the data from country codes to create a list, where each country is identified by the country code.

import countryCodes from 'country-codes-list';

const countryData = countryCodes.customArray({
  id: '{countryCode}',
  ...
});

This list is then uses as select options, using the country code as a select option value. I'm getting the following error.

Encountered two children with the same key, `IO`. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.

This issue is specific to the select library that we're using, not directly to country-codes-list, but highlights a problem that could be solved on the library level.

Problem

Going over the countries configuration file, there are two entries for IO locale, which are the following:

https://github.com/LucianoGanga/country-codes-list/blob/master/countriesData.js#L1459

  {
    "countryNameEn": "British Indian Ocean Territories",
    "countryNameLocal": "British Indian Ocean Territories",
    "countryCode": "IO",
    "currencyCode": "USD",
    "currencyNameEn": "United States dollar",
    "tinType": "",
    "tinName": "",
    "officialLanguageCode": "en",
    "officialLanguageNameEn": "English",
    "officialLanguageNameLocal": "English",
    "countryCallingCode": "246",
    "areaCodes": [],
    "region": "Indian Ocean",
    "flag": "🇮🇴",
  }

https://github.com/LucianoGanga/country-codes-list/blob/master/countriesData.js#L3859

  {
    "countryNameEn": "British Indian Ocean Territory",
    "countryNameLocal": "British Indian Ocean Territory",
    "countryCode": "IO",
    "currencyCode": "USD",
    "currencyNameEn": "United States Dollar",
    "tinType": "",
    "tinName": "",
    "officialLanguageCode": "en",
    "officialLanguageNameEn": "English",
    "officialLanguageNameLocal": "English",
    "countryCallingCode": "246",
    "areaCodes": [],
    "region": "Indian Ocean",
    "flag": "🇮🇴",
  },

The only difference between these two entries is the name (Territories vs Territory), the rest of the data for these entries is identical.

Question

Why are there two entries with the same country code? Do they represent different countries, even though all data associated with them is the same, expect for the name? Could we remove one of the two entries?

Country code is the field that's most likely to be used as the identifier / value in user interfaces. Often, they have to be unique to work properly, so perhaps it might be good to ensure there are no duplicates on the library level.

Multiple countries can have the same country calling code

Use case is USA and Canada

So this code is broken

const countryCodes = require('country-codes-list')

let b  = countryCodes.customList('countryCallingCode', '{countryCode}')
b[1] // yields 'DO'

one solution is to do map one country calling code to many country codes

wrong official language code and language name for Spain

The official language for Spain is Spanish es.
It's set to ast at the moment, which I didn't find much information on. Is it Asturian?

Here's the corrected entry:

  {
    "countryNameEn": "Spain",
    "countryNameLocal": "España",
    "countryCode": "ES",
    "currencyCode": "EUR",
    "currencyNameEn": "Euro",
    "tinType": "NIF (CIF)",
    "tinName": "Número de Identificación Fiscal (formerly named Código de Identificación Fiscal)",
    "officialLanguageCode": "es",
    "officialLanguageNameEn": "Spanish, Castilian",
    "officialLanguageNameLocal": "Español",
    "countryCallingCode": "34",
    "areaCodes": [],
    "region": "Europe",
    "flag": "🇪🇸"
  },

TS doesn't work out of the box

Please provide Typescript example here or in the documentation, if possible.
It seems that for now some twitching is required to make types work.

Missing countryCallingCode for some countries

At least these countries seem to be missing countryCallingCode:

  • Antarctica +672
  • Bouvet Island +47
  • Cabo Verde +238
  • Cote d'Ivoire +225
  • Laos +856
  • Macao +853
  • Syria +963
  • Timor-Leste +670
  • Western Sahara +212

Can you please add these? Country calling codes from quick googling.

publish newest version to npm?

hi,
could you please publish the newest version 1.6.10 (which includes the types) to npm?
thanks in advance and regards.

Consider adding Worldbase 2 character country codes

We are using this library inside of an Expo react-native app (iOS, Android & Web) and when requesting the region code via the following mechanism we have received XA from a Windows device on Chrome. After further investigation on this site XA appears to be the WorldBase 2 character representation for United Arab Emirates. Since we are not in control of what the operating system provides when asking for the region code we do not have a way of using a different ISO compliant region code.

Would it be possible to add the WorldBase 2 character country codes to this dataset?

import * as Localization from "expo-localization";
const regionCode = Localization.getLocales()?.[0]?.regionCode;

Area Code and Priorization

Hey there,

I was wondering if you'd been keen adding area codes / priorities for countries that have overlapping country codes. This would allow using this data for backing a phone picker, which also translates from phone number to country code.

See https://github.com/thegamenicorus/react-native-phone-input/blob/master/lib/resources/countries.json as an example.

I'll do a first kick-off with a PR that adds area codes for Canada based on https://en.wikipedia.org/wiki/Telephone_numbers_in_Canada. Let me know what you think.

Cheers,

Sascha

How do I filter the country list down?

Hi,

I am new to node js programming and am trying to use your object:

    var country = 'US';

const myCountryCodesObject = countryCodes.customList('countryCode', '{countryCode} +{countryCallingCode}');
    var indx = myCountryCodesObject.indexOf(country);
    console.log('index ' + indx);

I assume that customList returns a list... and I could do an indexOf that list... but it's not working...

Is there another way that I can get JUST the country code information for ONLY the country I am interested in ?

United Kingdom

The country name should be changed to United Kingdom from Great Britain in countryNameEn. It's known as the United Kingdom more than Great Britain. The countryNameLocal can be Great Britain.

Computed property name error in types

It won't compile with the latest types that was added.

A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.

In index.d.ts

customList error issue by import

Issue happen in import.
index.js:70 Uncaught (in promise) ReferenceError: value is not defined

Index.js
value = supplant(label, countryData);
Should be
const value = supplant(label, countryData);

missing define value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.