se-panfilov / jsvat

Check the validity of the format of an EU VAT number

Home Page:http://se-panfilov.github.io/jsvat

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hand in all countries? Europe undefined.

lhtdesignde opened this issue · comments

Hi,
Great library! I just updated and trying to make it work again. Before we didn't need to hand in a country. Now it looks like it's required? How can I hand in all countries without importing all of them specifically? I tried

import {checkVAT, europe} from 'jsvat';
checkVAT(vatNumber, [europe]);

When logging this, it says that country is undefined. How come? What am I doing wrong?

country: undefined
​isValid: false
​value: "RO19"

@lhtdesignde Hi, I noticed about this problem. Will fix it in a couple of days, hopefully sooner.
You're doing everything fine. Better documentation and examples are also on the way

Hi, sorry I didn't read your last message careful enough (I guess I was tired, but no excuses - my bad)

I just realise that you were confused by europe.
It's not a shorthand for countries, it's a sort of single country - some common european VAT that starts with EU....

ATM there is no default option to include all countries with a single variable.

Now I see that it makes sense =)

I will implement it in next minor release.

You have two options right now:

  1. Include all the countries manually:
import { austria,  belgium,  bulgaria,  checkVAT,  croatia,  cyprus,  czechRepublic,  denmark,  estonia,  europe,  finland,  france,  germany,  greece,  hungary,  ireland,  italy,  latvia,  lithuania,  luxembourg,  malta,  netherlands,  norway,  poland,  portugal,  romania,  russia,  serbia,  slovakiaRepublic,  slovenia,  spain,  sweden,  switzerland,  unitedKingdom } from 'jsvat'

checkVAT(vat, [ austria,  belgium,  bulgaria,  croatia,  cyprus,  czechRepublic,  denmark,  estonia,  europe,  finland,  france,  germany,  greece,  hungary,  ireland,  italy,  latvia,  lithuania,  luxembourg,  malta,  netherlands,  norway,  poland,  portugal,  romania,  russia,  serbia,  slovakiaRepublic,  slovenia,  spain,  sweden,  switzerland,  unitedKingdom ])

Uh.. well, a bit ugly ))

  1. Write some code:
import jsvat from "jsvat"

const { checkVAT } = jsvat
const countriesObj = omit(jsvat, 'checkVAT');

function omit(obj, key) {
    const result = { ...obj };
    delete result[key]
    return result;
}

const countriesList = Object.keys(countriesObj).map(key => countriesObj[key])

const a = checkVAT('BE0411905847', countriesList);
console.info(a)

Something like that ))

P.S. Or you can wait for next release as option 3 )))

awesome! Ah I was not aware that europe is actually it's own vat number. ha. Thanks for the quick reply and so much effort. I'll wait a little bit until you managed to have a way to hand in all countries. The library is super helpful. At the moment we get to check against all countries by just doing:

jsvat.checkVAT(vatNumber).isValid === true

@lhtdesignde Hi. The functionality was added in 2.1.2:

import { checkVAT, countries } from 'jsvat';
//or
const { checkVAT, countries } = require('jsvat');

checkVAT('WD12345678', countries);

I guess this one can be closed now.
@lhtdesignde Let me know in case of any troubles

sorry i missed this! Thanks for the implementation!