Comments (10)
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.
@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.
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.
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.
@rlenders Got it. Work in progress
from jsvat.
@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.
@rlenders is it okay for you?
from jsvat.
Seems great so far! Good call on supporting multiple ISO standards. Thanks a bunch.
from jsvat.
@rlenders Cool than, feel free to ping me in case of anything
from jsvat.
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)
- Remove compiled code from git repository HOT 4
- Run unit tests against TypeScript files HOT 3
- Belgium vat validation issue HOT 2
- umd library not working properly on browser
- Add Brazil VAT (know as CNPJ) validator
- Italy VAT codes not valid HOT 3
- Lithuanian VAT code is not valid and is treated as a Brazilian code HOT 7
- Germany tax number
- Support 'XI' prefix in addition to 'GB' (Northern Ireland)
- GB and XI HOT 1
- Netherlands VAT wrongly reported as invalid HOT 1
- Add option to do strict validation check HOT 1
- ES6 imports not working for only jsvat
- Add South Korea and Australia
- BE: add support for Belgian VAT numbers starting with 1 HOT 3
- Incorrect VAT validation for Poland when total sum modulo with 11 is 10 HOT 1
- Brazilian individual vat's are not being correctly validated
- France VAT with letters, not validating those?
- Can't find variable: BigInt on Safari HOT 3
- custom country validator country is not in countries HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsvat.