freeall / currency-codes

Node.js module to work with currency codes based on ISO 4217
MIT License
152 stars 56 forks source link

Feature request - include ISO country codes #21

Open conorot opened 5 years ago

conorot commented 5 years ago

It would be useful to add a couple of parameters to the library, specifically the ISO 3166-1 country codes (Alpha 2, Alpha 3 and Numeric) to enable searching based on country.

Proposed to add extra objects like this:

{
    code: 'ZMW',
    number: 967,
    digits: 2,
    currency: 'Zambian kwacha',
    countries: [ 'zambia': {
                              'name': 'zambia',
                              'iso2': 'ZM',
                              'iso3': 'ZMB',
                              'numeric': '894'
                         } ] 
}

I'd propose keeping the base structure and extending it to create an array of objects for each country. This could be a breaking change but would be extendable. The key could be the country name, but also keep this as a value for consistency of use.

This would allow for functionality to be built that allows for searching for currency based on country code.

eXeDK commented 5 years ago

I agree that this valuable information however as you point out this is a breaking change. If you come up with a solution that is not breaking the existing API in a meaningful way I think we should look into it!

freeall commented 5 years ago

I think this might be out of scope for this module. I am not entirely sure though.

maxsommer commented 4 years ago

I would definitely agree this should be done in this library. To make it a non-breaking change this could also be acceptable:

{
  code: 'ZMW',
  number: 967,
  digits: 2,
  currency: 'Zambian kwacha',
  countries: [ 'zambia' ],
  isoCountries: [ 
    {
      'name': 'zambia',
      'iso2': 'ZM',
      'iso3': 'ZMB',
      'numeric': '894'
    } 
  ]
}
freeall commented 4 years ago

@maxsommer that's not a bad idea at all. If you make a PR that would include this, I'll add it. Preferably in a way that could be done automatically whenever there's updates to the data set.

maxsommer commented 4 years ago

@freeall Sure, I'm currently on it. However I've found a few points where I'd love your input.


How should I go from here? I cloned the repository and built a script to update basically all the data (see here) – I think the changes I made there would be breaking however as they would introduce changes to the current dataset (e.g. "Afghani" became "Afghan afghani" because of the data source change). There are multiple ways of going forward for me:

One cool side effect from switching to Wikipedia as data source we could have as a benefit is actually internationalization of the content – the content could be pulled in as many languages as are provided in Wikipedia and be an optional argument when interacting with the library e.g.

const cc = require('currency-codes');
console.log(cc.code('EUR'));
console.log(cc.code('EUR', 'de'));

Of course this doesn't have to be the librarys scope it's for you to decide :) In combination with a Typescript based rewrite and an automatically executed test suite this could be a full new major version as well.

Depending on what your oppinions are I will make according changes and file a pull request. Please have a look at my proposal here

maxsommer commented 4 years ago

Hey @freeall any feedback would be appreciated.

Spomky commented 4 years ago

This is a nice feature I would love to have. Just one question though: why numeric is of type string? Is there any reason to return a string instead a positive integer?

maxsommer commented 4 years ago

@Spomky I kept numberic field a type string because it seems like according to standard there are numeric identifiers with leading 0 such as 020 for Andorra. Seemed unintuitive for me as well and we could also argue this could be handled internally but I'd rather adhere to seemingly standard 😄

Spomky commented 4 years ago

there are numeric identifiers with leading 0 such as 020 for Andorra

OK I was not aware of that. Makes sense to let it as a string. Thanks for the explanation.