Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not recognize Russia #149

Closed
gajus opened this issue Oct 12, 2019 · 2 comments
Closed

Does not recognize Russia #149

gajus opened this issue Oct 12, 2019 · 2 comments

Comments

@gajus
Copy link

gajus commented Oct 12, 2019

getAlpha2Code('Russia', 'en');
// => null

I presume this is because it is trying to match "Russian Federation". However, it would be nice if this library took into consideration the alternative names too.

@gajus
Copy link
Author

gajus commented Oct 12, 2019

I have written a simple local abstraction, it would be nice to have a version of this supported by this library:

// @flow

import {
  // eslint-disable-next-line id-match
  getAlpha2Code as getCountryAlpha2Code,
} from 'i18n-iso-countries';

/**
 * Country name map based on IMDb, e.g.
 * https://www.imdb.com/title/tt6303866/releaseinfo
 */
const countryNameMap = {
  RUSSIA: 'RU',
  UK: 'GB',
  USA: 'US',
};

export default (subject: string): string | null => {
  const countryCode = getCountryAlpha2Code(subject, 'en');

  if (countryCode) {
    return countryCode.toUpperCase();
  }

  return countryNameMap[subject.toUpperCase()] || null;
};

@danilofuchs
Copy link
Contributor

#175 allows us to use an array of alternative names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants