Coder Social home page Coder Social logo

Comments (10)

RudeySH avatar RudeySH commented on August 25, 2024

I should clarify that I understand that you can specify English country names, but there is no way to specify country code. That really seems like an oversight, any non-English application will have to resort to using a switch that converts country codes to english country names just to work with this library.

from jsvat.

se-panfilov avatar se-panfilov commented on August 25, 2024

@rlenders Sorry, I'm not sure if I catch the problem.
Can you please provide an example?

I mean it would be better if you'll provide it like "What we have now: ..., What I want to see: ..."

from jsvat.

se-panfilov avatar se-panfilov commented on August 25, 2024

Usually if I have a NL's VAT, like NL010000446B01, an output will be like {"value":"NL010000446B01","isValid":true,"country":"netherlands"}.

E.g. If I want to allow only Netherland's VAT I can check result's field "country" to be equal to netherlands.

Basically

function checkVAT(vat){
var result = jsvat.checkVAT(vat)
if (result.isValid && result.country === 'netherlands') return true
return false
}

checkVAT('NL010000446B01')

If your VATs have no country code prefixes... well I'm not sure if it will be possible to recognise for which country this VAT is belongs.

Perhaps you can try just to provide country prefix:

const countries = {
  netherlands: 'NL',
  russia: 'RU'
  //...
}

function checkVAT(vat, prefix){
var result = jsvat.checkVAT(prefix + vat)
if (result.isValid && result.country === 'netherlands') return true
return false
}

checkVAT('010000446B01',  countries.netherlands)

from jsvat.

RudeySH avatar RudeySH commented on August 25, 2024

As an example, say my application requires a user to select their country from a localized dropdown, and enter their VAT number, which will be validated if the country is supported by your library. It is not allowed to use a VAT number from a different country than the one selected.

To achieve this using this library, I will have to provide a mapping between my dropdown's ISO-standard country codes and this library's non-standard country names. I can't simply .toLowerCase() my country names because netherlands could be written as "The Netherlands", "Holland", "Nederland" or any other localized version. So I need to cook up my own mapping like you suggested (const countries).

I feel like this should not be necessary. The list of supported countries is not too long, but if each developer has to supply their own mapping, mistakes will be made. Also, if this library is updated tomorrow and a new country is added, the mapping I wrote will be incomplete. If maintainers update my application to use the latest version of this library, there's a possibility they don't realize some custom mapping requires to be updated as well.

This hurdle can easily be eliminated by supporting or even using country codes internally, like so:
jsvat.countryCodes = ['BE', 'DE', 'LU', 'NL']

Furthermore, this would be nice to have too: if (jsvat.isCountryCodeSupported(cc)) { ... }

from jsvat.

se-panfilov avatar se-panfilov commented on August 25, 2024

@rlenders Got it. Work in progress

from jsvat.

se-panfilov avatar se-panfilov commented on August 25, 2024

@rlenders You can use iso codes for comparison right now.

So first take a look at updated readme.

You can block several countries

jsvat.blocked = ['BE', 'Russia', 'GRC', '203'] //You can provide country's name, or one of iso codes

Also you can block ALL countries except listed:
You can block several countries

jsvat.allowed = ['BE', 'Russia', 'GRC', '203']

End I've changed signature of checkVAT()'s result:

{
  value: 'BG131134023', // VAT without extra characters (like '-' and spaces)
  isValid: true, 
  country: { // VAT's couuntry (null if not found)
      name: country.name, //Name of the country
      isoCode: { //Country ISO codes
        short: 'BE', 
        long: 'BEL',
        numeric: '056' //String, because of forwarding zero
      }
    }
  }

from jsvat.

se-panfilov avatar se-panfilov commented on August 25, 2024

@rlenders is it okay for you?

from jsvat.

RudeySH avatar RudeySH commented on August 25, 2024

Seems great so far! Good call on supporting multiple ISO standards. Thanks a bunch.

from jsvat.

se-panfilov avatar se-panfilov commented on August 25, 2024

@rlenders Cool than, feel free to ping me in case of anything

from jsvat.

DJmRek avatar DJmRek commented on August 25, 2024

sorry to reopen this, but I'm not quit sure if I understand this correctly:

If I have a user-entered VAT and also a preselected country (with ISO code),
I need to set the jsvat.allowed = ['myIsoCode']; prior of calling jsvat.checkVat("userEnteredVat"); ?

Wouldn't it be an easy thing to simply provide an overload for checkVat which accepts an iso code / iso code array as 2nd parameter?

Some pseudocode:

function checkVat(vat: string, isoCode: string) {
    const country = GetCountryByIsoCode(isoCode);
    return this.checkVat(vat, [country]);
}

from jsvat.

Related Issues (20)

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.