Giter VIP home page Giter VIP logo

biter777 / countries Goto Github PK

View Code? Open in Web Editor NEW
360.0 8.0 68.0 1.4 MB

Countries - ISO-639, ISO-3166 countries codes with subdivisions and names, ISO-4217 currency designators, ITU-T E.164 IDD phone codes, countries capitals, UN M.49 codes, IANA ccTLD countries domains, FIPS, IOC/NOC and FIFA codes, VERY VERY FAST, compatible with Databases/JSON/BSON/GOB/XML/CSV, Emoji countries flags and currencies, Unicode CLDR.

Home Page: https://pkg.go.dev/github.com/biter777/countries?tab=doc

License: BSD 2-Clause "Simplified" License

Go 100.00%
go iso iso3166 iso3166-1 iso3166-2 iso4217 currency currencies money iso-3166

countries's Introduction

countries

Countries - ISO 639, ISO 3166 (ISO3166-1, ISO3166, Digit, Alpha-2, Alpha-3) countries codes with subdivisions and names (on eng and rus), ISO4217 currency designators, ITU-T E.164 IDD calling phone codes, countries capitals, UN M.49 regions codes, IANA ccTLD countries domains, FIPS, IOC/NOC and FIFA codes, VERY VERY FAST, NO maps[], NO slices[], NO init() funcs, NO external links/files/data, NO interface{}, NO specific dependencies, compatible with Databases/JSON/BSON/GOB/XML/CSV, Emoji countries flags and currencies support, UN M.49, FIFA codes, full support ISO 639-1, ISO 3166-1, ISO 3166-2, ISO 4217, ITU-T E.164, Unicode CLDR and IANA ccTLD standarts.

Supported standarts:

  • ISO 639-1
  • ISO 3166-1
  • ISO 3166-2
  • ISO 4217
  • ICANN
  • IANA ccTLD
  • ITU-T E.164
  • IOC
  • NOC
  • FIFA
  • FIPS
  • UN M.49
  • Unicode CLDR
  • Unicode Emoticons Flags
  • Unicode Emoticons Currencies
  • UN World Countries Capitals

GoDev GoAwesome Coder Documentation Status DOI codeclimate GolangCI GoReport Codiga Codacy Badge codecov Coverage Status Coverage ISO ITU IANA ICANN M49 CLDR License Build status Semaphore Status Build Status CLDR DMCA.com Protection Status Dependencies Free Gluten Free PRs Welcome DepShield Badge Stars

installation

go get github.com/biter777/countries

usage

countryJapan := countries.Japan
fmt.Printf("Country name in english: %v\n", countryJapan)                   // Japan
fmt.Printf("Country name in russian: %v\n", countryJapan.StringRus())       // Япония
fmt.Printf("Country ISO-3166 digit code: %d\n", countryJapan)               // 392
fmt.Printf("Country ISO-3166 Alpha-2 code: %v\n", countryJapan.Alpha2())    // JP
fmt.Printf("Country ISO-3166 Alpha-3 code: %v\n", countryJapan.Alpha3())    // JPN
fmt.Printf("Country IOC/NOC code: %v\n", countryJapan.IOC())                // JPN
fmt.Printf("Country FIFA code: %v\n", countryJapan.FIFA())                  // JPN
fmt.Printf("Country FIPS code: %v\n", countryJapan.FIPS())                  // JA
fmt.Printf("Country Capital: %v\n", countryJapan.Capital())                 // Tokyo
fmt.Printf("Country ITU-T E.164 call code: %v\n", countryJapan.CallCodes()) // +81
fmt.Printf("Country ccTLD domain: %v\n", countryJapan.Domain())             // .jp
fmt.Printf("Country UN M.49 region name: %v\n", countryJapan.Region())      // Asia
fmt.Printf("Country UN M.49 region code: %d\n", countryJapan.Region())      // 142
fmt.Printf("Country emoji/flag: %v\n", countryJapan.Emoji())                // 🇯🇵
fmt.Printf("Country Subdivisions: %v\n", countryJapan.Subdivisions())       // Hokkaido Aomori Iwate Miyagi Akita Yamagata Fukushima Ibaraki Tochigi Gunma Saitama Chiba Tokyo Kanagawa Niigata Toyama Ishikawa Fukui Yamanashi Nagano Gifu Shizuoka Aichi Mie Shiga Kyoto Osaka Hyogo Nara Wakayama Tottori Shimane Okayama Hiroshima Yamaguchi Tokushima Kagawa Ehime Kochi Fukuoka Saga Nagasaki Kumamoto Oita Miyazaki Kagoshima Okinawa

currencyJapan := countryJapan.Currency()
fmt.Printf("Country ISO-4217 Currency name in english: %v\n", currencyJapan)           // Yen
fmt.Printf("Country ISO-4217 Currency digit code: %d\n", currencyJapan)                // 392
fmt.Printf("Country ISO-4217 Currency Alpha code: %v\n", currencyJapan.Alpha())        // JPY
fmt.Printf("Country Currency emoji: %v\n", currencyJapan.Emoji())                      // 💴
fmt.Printf("Country of Currency %v: %v\n\n", currencyJapan, currencyJapan.Countries()) // Japan

// OR you can alternative use:
japanInfo := countries.Japan.Info()
fmt.Printf("Country name in english: %v\n", japanInfo.Name)                          // Japan
fmt.Printf("Country ISO-3166 digit code: %d\n", japanInfo.Code)                      // 392
fmt.Printf("Country ISO-3166 Alpha-2 code: %v\n", japanInfo.Alpha2)                  // JP
fmt.Printf("Country ISO-3166 Alpha-3 code: %v\n", japanInfo.Alpha3)                  // JPN
fmt.Printf("Country IOC/NOC code: %v\n", japanInfo.IOC)                              // JPN
fmt.Printf("Country FIFA code: %v\n", japanInfo.FIFA)                                // JPN
fmt.Printf("Country FIPS code: %v\n", japanInfo.FIPS)                                // JA
fmt.Printf("Country Capital: %v\n", japanInfo.Capital)                               // Tokyo
fmt.Printf("Country ITU-T E.164 call code: %v\n", japanInfo.CallCodes)               // +81
fmt.Printf("Country ccTLD domain: %v\n", japanInfo.Domain)                           // .jp
fmt.Printf("Country UN M.49 region name: %v\n", japanInfo.Region)                    // Asia
fmt.Printf("Country UN M.49 region code: %d\n", japanInfo.Region)                    // 142
fmt.Printf("Country emoji/flag: %v\n", japanInfo.Emoji)                              // 🇯🇵
fmt.Printf("Country ISO-4217 Currency name in english: %v\n", japanInfo.Currency)    // Yen
fmt.Printf("Country ISO-4217 Currency digit code: %d\n", japanInfo.Currency)         // 392
fmt.Printf("Country ISO-4217 Currency Alpha code: %v\n", japanInfo.Currency.Alpha()) // JPY
fmt.Printf("Country Subdivisions: %v\n", japanInfo.Subdivisions)                     // Hokkaido Aomori Iwate Miyagi Akita Yamagata Fukushima Ibaraki Tochigi Gunma Saitama Chiba Tokyo Kanagawa Niigata Toyama Ishikawa Fukui Yamanashi Nagano Gifu Shizuoka Aichi Mie Shiga Kyoto Osaka Hyogo Nara Wakayama Tottori Shimane Okayama Hiroshima Yamaguchi Tokushima Kagawa Ehime Kochi Fukuoka Saga Nagasaki Kumamoto Oita Miyazaki Kagoshima Okinawa

// Detection/Lookup usage
// Detect/Lookup by country name
country := countries.ByName("angola")
fmt.Printf("Country name in english: %v\n", country)                // Angola
fmt.Printf("Country ISO-3166 digit code: %d\n", country)            // 24
fmt.Printf("Country ISO-3166 Alpha-2 code: %v\n", country.Alpha2()) // AO
fmt.Printf("Country ISO-3166 Alpha-3 code: %v\n", country.Alpha3()) // AGO
// Detect/Lookup by country code
country = countries.ByName("AO")
fmt.Printf("Country name in english: %v\n", country.String())       // Angola
fmt.Printf("Country ISO-3166 digit code: %d\n", country)            // 24
fmt.Printf("Country ISO-3166 Alpha-2 code: %v\n", country.Alpha2()) // AO
fmt.Printf("Country ISO-3166 Alpha-3 code: %v\n", country.Alpha3()) // AGO
// Detect/Lookup by code/numeric
country = countries.ByNumeric(24)
fmt.Printf("Country name in english: %v\n", country)                // Angola
fmt.Printf("Country ISO-3166 digit code: %d\n", country)            // 24
fmt.Printf("Country ISO-3166 Alpha-2 code: %v\n", country.Alpha2()) // AO
fmt.Printf("Country ISO-3166 Alpha-3 code: %v\n", country.Alpha3()) // AGO

// Comparing usage
// Compare by code/numeric
if countries.ByName("angola") == countries.AGO {
	fmt.Println("Yes! It's Angola!") // Yes! It's Angola!
}
// Compare by name
if strings.EqualFold("angola", countries.AGO.String()) {
	fmt.Println("Yes! It's Angola!") // Yes! It's Angola!
}

// Database usage
type User struct {
	gorm.Model
	Name     string
	Country  countries.CountryCode
	Currency countries.CurrencyCode
}
user := &User{Name: "Helen", Country: countries.Slovenia, Currency: countries.CurrencyEUR}
db, err := gorm.Open("postgres", 500, "host=127.0.0.2 port=5432 user=usr password=1234567 dbname=db")
if err != nil {
	panic(err)
}
defer db.Close()
db.Create(user)

Options

For Emoji use Emoji(). Enjoy!

import "github.com/biter777/countries"

For more complex options, consult the documentation.

Contributing

  1. Welcome pull requests, bug fixes and issue reports

    Contributors list

  2. Donate - a donation isn't necessary, but it's welcome.

    Donate using Liberapay ko-fi

  3. Star us - give us a star, please, if it's not against your religion :)

    Stars

Updating ISO 3166

Making use of changes to the iso-codes project.

TODO create go generate capability to automatically generate from the json files in the data directory of the iso-codes project.

countries's People

Contributors

2785 avatar alexneises avatar altynai avatar andskur avatar benja-m-1 avatar biter777 avatar danielhilton avatar darrahk avatar deepsourcebot avatar fcornelius avatar futuarmo avatar gavincarr avatar hfkang avatar jlantto avatar joshuabeny1999 avatar jrmarkle avatar jufemaiz avatar royshahaf avatar royshahaf-at-af avatar suquant avatar zignd 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  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  avatar

countries's Issues

Two times GB

Hi,

It seems that countries.AllInfo() returns GB two times.

list := countries.AllInfo()

for i, c := range list {
     fmt.Println(i, c.Alpha2)
}

Result

38 GB
...
230 GB

Add native names

I am missing native names when I want to provide users with options to pick their country. It's all in English which does not make sense in certain situations.

So for example:
Hungary -> Magyarország
Slovakia -> Slovensko
Czechia -> Česko
Austria -> Österreich
Spain -> España
Russia -> Россия
Bulgaria -> България
China -> 中國

and so on.

Czech Republic or Czechia?

Thanks for your work on this!

We're noticing that countries.ByName("CZE") is returning Czech Republic here. The general pattern seem to be that we return the name as opposed to official_name from here in which case it seems like it should be Czechia, unless I'm missing something. Happy to submit a pr to resolve if this is not intentional.

Chile has a currency bug

HI!
Thanks for the project, this is awesome work!

I found a bug in my project when using it in production environment, that the Chilean currency is Chilean Peso (CLP) instead of Chilean Unidad de Fomento (CLF).

I hope this bug will be fixed soon.

[DepShield] (CVSS 5.9) Vulnerability due to usage of golang.org/x:crypto:0.0.0-20190325154230-a5d413f7728c

Vulnerabilities

DepShield reports that this application's usage of golang.org/x:crypto:0.0.0-20190325154230-a5d413f7728c results in the following vulnerability(s):


Occurrences

golang.org/x:crypto:0.0.0-20190325154230-a5d413f7728c is a transitive dependency introduced by the following direct dependency(s):

github.com/jinzhu:gorm:1.9.12
        └─ github.com/denisenkom:go-mssqldb:0.0.0-20191124224453-732737034ffd
              └─ golang.org/x:crypto:0.0.0-20190325154230-a5d413f7728c

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

Add below countries

AFG','BHR','BGD','BRN' add above country codes and respective country related details if missing

[DepShield] (CVSS 5.9) Vulnerability due to usage of golang.org/x:crypto:0.0.0-20190308221718-c2843e01d9a2

Vulnerabilities

DepShield reports that this application's usage of golang.org/x:crypto:0.0.0-20190308221718-c2843e01d9a2 results in the following vulnerability(s):


Occurrences

golang.org/x:crypto:0.0.0-20190308221718-c2843e01d9a2 is a transitive dependency introduced by the following direct dependency(s):

github.com/jinzhu:gorm:1.9.12
        └─ golang.org/x:crypto:0.0.0-20191205180655-e7c4368fe9dd
              └─ golang.org/x:net:0.0.0-20190404232315-eb5bcb51f2a3
                    └─ golang.org/x:crypto:0.0.0-20190308221718-c2843e01d9a2

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

more names to identify country names

MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF => North Macedonia
VENEZUELA, BOLIVARIAN REPUBLIC OF => Venezuela
MOLDOVA, REPUBLIC OF => Moldova
TAIWAN, PROVINCE OF CHINA =>Taiwan
PALESTINIAN TERRITORY, OCCUPIED => Palestine

Change in module name leads to inaccessible releases.

How shell I reference the latest releases from external project?

In this repo the module name was changed ea14952 but the other repository https://github.com/royshahaf/countries last commit is from February and there is no way to reference the recent changes any way.

in go.mod

require (
	github.com/biter777/countries v1.3.4 <- This is the last working version
	github.com/royshahaf/countries v1.5.1 <- This repo has only github.com/royshahaf/countries v1.3.7

Now Go can't find the right module and the right repository.

go: github.com/biter777/[email protected]: parsing go.mod:
        module declares its path as: github.com/royshahaf/countries
                but was required as: github.com/biter777/countries

The two only working version now are

  • github.com/biter777/countries v1.3.4
  • github.com/royshahaf/countries v1.3.7

Either fix the module names or please update the repository so the v1.5.x can be referenced from externally.

Use 'v' prefix in tags

Could you please use 'v1.4.0' for your tags? Go mod can't properly vendor tags like '1.4.0', it needs 'v' in the beginning.
Thanks!

United States currency maps to USN rather than USD

This may be a bit of a nitpick but, according to my understand, the United States has two currency codes associated with it: US dollar (USD) and US dollar, next day (USN). Why is it that calling countries.UnitedStatesOfAmerica.Info().Currency.Alpha() returns USN rather than USD when USD would be the more idiomatic usage? My use case for this code-base is primarily getting the 2-character country code and currency combinations associated with each for internationalization purposes but this doesn't seem fit-for-purpose. Perhaps split the US entry into two entries would fix this issue?

Note: I can get around this by taking the country code and doing countries.CurrencyCode(code) to get the proper code and if this is the intended usage when there is a collision then I would appreciate a function that does that explicitly.

UN M49 region codes

Are these code correct?

const (
	// RegionAfrica       RegionCode = 2
	RegionAfrica RegionCode = 2
	// RegionNorthAmerica RegionCode = 3
	RegionNorthAmerica RegionCode = 3
	// RegionSouthAmerica RegionCode = 5
	RegionSouthAmerica RegionCode = 5
	// RegionOceania      RegionCode = 9
	RegionOceania RegionCode = 9
	// RegionAntarctica   RegionCode = 999
	RegionAntarctica RegionCode = 999
	// RegionAsia         RegionCode = 142
	RegionAsia RegionCode = 142
	// RegionEurope       RegionCode = 150
	RegionEurope RegionCode = 150
)

It seems to me that North America and South America codes are wrong.
See here.

`SubdivisionCode` does not implement sql.Scanner and driver.Valuer interfaces

First of all, thank you for this amazing package! You've saved me a TON of work.

One call out I have is, this package doesn't seem to implement the database/sql/driver.Valuer and database/sql/driver.Valuer interfaces for SubdivisionCode.

How I arrived at this conclusion:
I have an API that takes in POST requests from the client, marshals it into a Go struct, then uses Gorm to store that struct model in a Postgres DB.
The struct has a field of type countries.SubdivisionCode, and the package is able to correctly unmarshal it into the struct as a string (i.e. "US-MA" --> "Massachusetts"). It also correctly inserts it into the DB as "Massachusetts." However, when I select that record from the DB and unmarshal it into a Go struct, the subdivision code field reads as "Unknown".

✅ POST request:
image

✅ Unmarshal the Request Body with Fiber into a Struct:
image

✅ Insert Into the DB:
image

❌ Select that Record from DB: Now the field shows up as Unknown.
image

On a related note, what function is causing "US-MA" to be read in as "Massachusetts" and when is that function called? Is there a way to insert it into the DB as a "US-MA"?

EDIT:
Using fmt.Printf("%+v") printed the field as "Massachusetts" (I'm guessing the package uses the String() method to do so), but when I just use fmt.Printf("%#v"), it outputs as "US-MA". Still, how is it getting inserted into the DB as "Massachusetts" when it doesn't have an explicit driver.Valuer function?

Official Turkish country name not recognised

As of December 2021, Turkey was renamed to Türkiye (full, Republic of Türkiye). This change has been recognised and adopted by the UN, WTO and NATO as of July 2022 [cite] [cite] and US State Department as of January 2023 [cite].

It would be great if the package could be updated to reflect this change.

Current name resolution

Resolves Name
Turkey
Republic of Türkiye
Türkiye

Add country languages

HI!
Thanks for the project, this is awesome work!

I'm using your library to import geolocation data and need the official languages by a country.

To solve that, I'm building a list of country codes and languages.

WDYT about put this info inside the library? If ok for you I can open a PR for these.

Fix Brazil currency code

I like to use this lib, soo when I started to test for Brazil, I got a problem because the lib just accept the code 76 for Brazil currency. But as we can see at https://pt.wikipedia.org/wiki/ISO_4217, the code 76 is for a very old Brazil currency named as Cruzeiro that is no longer valid since 30 years ago. The correct Brazil code is 986 for currency named as Real.

I created a PR for this fix, I would like if the maintainer could review :)
#39

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.