GithubHelp home page GithubHelp logo

richorama / country-code-lookup Goto Github PK

View Code? Open in Web Editor NEW
83.0 3.0 28.0 96 KB

:earth_africa: Finds countries by various country codes

License: MIT License

JavaScript 100.00%
country-codes countries lookup

country-code-lookup's Introduction

NPM version Downloads

Country Code Lookup

A node.js module to look up countries by various country codes.

Supported codes:

  • FIPS 10-4 codes (2 digits)
  • ISO 3166 (2 digits)
  • ISO 3166 (3 digits)
  • ISO 3166 (numbers)
  • Internet codes

Installation

$ npm install country-code-lookup

Usage

const lookup = require('country-code-lookup')

// search by FIPS
lookup.byFips('UK')

// search by ISO
lookup.byIso('GB')
lookup.byIso('GBR')
lookup.byIso(826)

// search by internet code
lookup.byInternet('UK')

// search by country name
lookup.byCountry('United Kingdom')

// get an array of all countries
lookup.countries

Searching for a country will return either null, or a country object:

{ continent: 'Europe',
  region: 'Western Europe',
  country: 'United Kingdom',
  capital: 'London',
  fips: 'UK',
  iso2: 'GB',
  iso3: 'GBR',
  isoNo: '826',
  internet: 'UK' }

Useful Links

ISO 2 and 3 digit country codes: https://www.iban.com/country-codes

License

MIT

country-code-lookup's People

Contributors

bhanukauom avatar davidmulder0 avatar dependabot[bot] avatar dotbear avatar ejrb avatar getlarge avatar jacquesg avatar leemhenson avatar nikcorg avatar nullcc avatar richorama avatar shoonia avatar

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

Watchers

 avatar  avatar  avatar

country-code-lookup's Issues

state is null when address ends with "-1234"

Hi, awesome library! I found some issue with postal codes that has dash in them.

state is null when address ends with "-1234", for example:

(async function () {
  const util = require('util')
  const parseAddressCallback = require('parse-address-string')
  const parseAddress = util.promisify(parseAddressCallback)

  const address = await parseAddress('1234 Road St, Brooklyn, NY 12345-1234')

  console.log(address)
})()

Will result with:

{
  street_address1: '1234 Road St',
  city: 'Brooklyn',
  state: null,
  postal_code: '12345',
  country: null
}

country-code-lookup version: 0.0.19
NodeJS version: 14.16.1

throw Error for ISO search

Hi there,
My point if you return null in other case, why you throw new Error in ISO case?
throw new Error('cannot determine ISO code type') in ISO case
VS
return null for other cases.
I think it is unexpectable result, isn't it?

How can I query for England, Wales, Scotland, & Northern Ireland country iso codes?

England, Wales, & Scotland are countries (in GB)
Northern Ireland is a province (in UK)

const CountryCodeLookup = require('country-code-lookup');

let countryName = 'England';
const result = CountryCodeLookup.byCountry(countryName); // yields no results
const { iso2, iso3 } = result ?? {};

console.log(iso2, iso3, countryName);

I'd expect iso2 to be 'GB' for the 4 countries.

Also, bc all data is unpacked into the default export of this lib, we don't get autocomplete in node.js repl.

Update country info?

Hey, super happy I came across this today. Exactly what I need for a project (being able to lookup region/continents by country code). Curious where the data in the csv comes from? Probably could use updated after 2 years and I'd be happy to do it.

isoNo returns non-standardized format

Running the isoNo method can return a single or two character string. For example, looking up Afghanistan's ISO numeric-3 country code returns '4' instead of '004'. This can be fixed by enforcing string length of 3 for isoNo values and adding leading zeros as padding using JS's padStart method. I'd be happy to help you implement this if you want some assistance. ๐Ÿ™‚

ISO number should be a numeric-3

There's a small issue in library with numeric iso codes. These codes are numeric-3 as per ISO, so they should not be defined without their leading zero.
Moreover, if I make a lookup as 004 that should anyway work.
I can send a fix, if there's any interest in fixing this.

Bundling app with Webpack, cannot resolve 'fs'

When bundling my app with webpack, and your library is being used, I get the following error:

Module not found: Error: Can't resolve 'fs' in '/path/to/project/node_modules/country-code-lookup'
@ ./node_modules/country-code-lookup/index.js 6:12-25

I have tried to use the suggestions listed here but they don't work and mostly just come up with the various other errors reported (e.g Can't resolve variable require, etc).

Do you have suggestions on how to fix this?

Should lower or upper case

Hello When I search by country using lower case it returns null .. you should lower or upper case the value to be as same as your data to give the right answer in all cases.

Release process has undetected errors

Looks like npm publish is failing, but CI is still green:

npm ERR! code E404
npm ERR! 404 Not Found - PUT https://registry.npmjs.org/country-code-lookup - Not found
npm ERR! 404 
npm ERR! 404  '[email protected]' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

Ref: https://github.com/richorama/country-code-lookup/actions/runs/8138888343/job/22240739416

can't lookup ByCountry for

I was just trying to use the library, looks like the following countries aren't returning for byCountry method:

[
  "UK",
  "S. Korea",
  "Czechia",
  "UAE",
  "Hong Kong",
  "Channel Islands",
  "Palestine",
  "DRC",
  "Faeroe Islands",
  "Brunei ",
  "Congo",
  "Bahamas",
  "Macao",
<--didn't read after this -->
  "Myanmar",
  "St. Vincent Grenadines",
  "MS Zaandam",
  "Gambia",
  "Turks and Caicos",
  "Cabo Verde",
  "CAR",
  "Vatican City",
  "St. Barth",
  "Falkland Islands",
  "Caribbean Netherlands",
  "Saint Pierre Miquelon"
]

M not sure, if all of these are valid countries. Feel free to close iff not.

ISO3 Country Code Romania

I think the country code of romania is ROU not ROM, so my program cant find romania with the country code ROU.

XKS returns null

Ran .byIso function for XKS, which according to Google is

xk is a temporary, unofficial country code top-level domain for Kosovo, assigned under the United Nations Security Council Resolution 1244 in 1999.

Proposal: To support IBAN country names

Taking this https://www.iban.com/country-codes as a reference. Should't UK name be:

United Kingdom of Great Britain and Northern Ireland

instead of only United Kingdom?

https://github.com/richorama/country-code-lookup/blob/master/index.js#L2385C15-L2385C29

We are trying to follow the IBAN Codes and names but wondering how practical would be to have the names here as they appear there. I noticed there are other discrepancies such as United States instead of the official name United States of America

I think that to avoid breaking changes it could be added as a separate property

feat(Search): More flexible name search byCountry()

I find this library to be extremely useful, and grateful that I found it but I have a single suggestion.

Make the byCountry() function a bit more flexible by parsing both the input and the output by homologating both strings.
Ej.-

  • Transform into all miniscule letters
  • Trim extra spaces
  • Maybe, add name variants for some countries EJ
    • The United States of America
    • United States of America

I would love to help implementing this new functionalities, if I may so ๐Ÿ˜„

Country details using country currency code.

I want to be able to get country details, using the country's currency ISO code as the key.

Or better still I should be able to get any country's details by specifying the key I wanna search with.

Example .Find({key: "currency", value: "USD"})

Zambia country code is wrong

   continent: 'Africa',
    region: 'Southern Africa',
    country: 'Zambia',
    capital: 'Lusaka',
    fips: 'ZA',
    iso2: 'ZM',
    iso3: 'ZWB',
    isoNo: '894',
    internet: 'ZM'
  }

The Zambia iso3 code is 'ZMB' not 'ZWB'

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.