Coder Social home page Coder Social logo

se-panfilov / jsvat Goto Github PK

View Code? Open in Web Editor NEW
128.0 5.0 33.0 3.7 MB

Check the validity of the format of an EU VAT number

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

License: MIT License

JavaScript 89.88% TypeScript 10.12%
vat-number vat-validator vat javascript eu-vat-validator eu-vat-number inn european

jsvat's People

Contributors

andrebazoli avatar greenkeeper[bot] avatar greenkeeperio-bot avatar javi-p-nt avatar maersu avatar mattivdweem avatar nygardk avatar rdgrieve avatar rhinoandre avatar sandstrom avatar se-panfilov avatar slischka avatar smilovanovic avatar treago avatar wilgert 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

jsvat's Issues

Add Brazil VAT (know as CNPJ) validator

My company is launching in Brazil next month and I wouldn't like to have to add another library to only validate the VAT in Brazil.

Do you mind if I open a PR to add this validation?

It will require some small changes to getCountry logic because Brazil VAT doesn't start with the country code and also add the / to removeExtraChars method.

formatted vat number

Given a valid vat number, I'd like to format it as usual in its country

eg, for Switzerland, CHE272990183 would be formatted as CHE-272.990.183

Why Estonia isn't supported?

Hi!
I wonder why Estonia isn't supported in VAT validation checker?
Or do you maybe have a typo in List of supported Countries?
Because there is one country listed as Europe but Estonia is missing?

screen shot 2018-04-01 at 13 42 15

Thank you for this library! ;)

Only some countries working

Hello there,
I just installed this module, and I can't get it work for some countries.

Here is an example of returns I get:

import { checkVAT, countries } from 'jsvat';

console.log(checkVat('FRXX999999999', countries).isValid)   // => true
console.log(checkVat('DE999999999', countries).isValid)     // => false
console.log(checkVat('BE1234567890', countries).isValid)    // => false

Did I miss something ?

custom country validator country is not in countries

I've tried this:export const andorra = { name: 'Andorra', codes: ['AD', 'AND', '20'], // This codes should follow ISO standards (short, long and numeric), but it's your own business calcFn: (vat) => { return vat.length === 10; }, rules: { regex: [/^(AD)(\d{8})$/] } };
and in main file
import { andorra } from "../lib/jsvatCustom/checkNIFAndorra"; //and then: checkVAT(, [andorra])

What i am doing wrong?? I think it doesnt pass the right country to de checker

Library interface

Thanks for a great library!

Two thoughts:

  1. It's slightly cumbersome to import the countries. Have you considered adjusting the interface to something like this:
import { lookup } from 'jsvat'; 

let response = lookup('BE0411905847');
// where response would be the current response object
  1. Perhaps there could be a property for groups of countries in the response, e.g. blocs: ['eu'], so one could quickly check if a VAT number is within the EU VAT scheme. Could add more relevant blocks in the future if needed.

Happy to hear your thoughts!

Incorrect VAT validation for Poland when total sum modulo with 11 is 10

It seems there is an issue with VAT validation for Poland.
According to this wikipedia page (https://pl.wikipedia.org/wiki/Numer_identyfikacji_podatkowej) and the spec here (https://romek.info/ut/nip-rego.html#nip) the following numbers are invalid VAT numbers:

  • 0000000000
  • 1234567890
    The above links are in Polish, I used google translate to make sense out of the parts where it states that the modulo of the calculated sum cannot be equal to 10, otherwise that VAT is invalid.

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • Replaced the old Node.js version in your .nvmrc with the new one

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Hand in all countries? Europe undefined.

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"

Add option to do strict validation check

I ran into a 'bug' where the system said the VAT number is valid, when it was actually not.

checkVAT('BE0740-509975', countries) return true, because the library automatically clears the special characters (https://github.com/se-panfilov/jsvat/blob/master/src/lib/jsvat.ts#L107)

Would it be possible to add an attribute that specifies if the client actually wants to remove those characters?

I don't mind submitting a PR, if you don't have the time to implement this.

Thanks for your library!

Internet explorer

Any plans to make the latest version compatible with Internet Explorer 11 ?

node example

Hello,

I just made npm i jsvat but i am unable to use it in node. How can it be done? With require givens error with your example using import also gives an error. Am using node 12.3.1. With the import command ives error in the first {. With the require complains about the main reference. Thank you

BE: add support for Belgian VAT numbers starting with 1

Issue

  • Belgian VAT numbers are composed of the prefix 'BE' followed by the company number of the company. For example: BE0606838532
  • VAT numbers starting with digit 1 do not pass validation, while the official documentation states it can start with either 0 or 1. For example: BE1001686633
  • In the near future the Crossroads Bank for Enterprises in Belgium will start registering companies with a company number starting with digit 1. By 01/01/2023 it is strongly recommended to allow VAT numbers to allow such format.
  • Official communication about this change can be found here.

Suggested fixes in Belgium.ts

  • The regex in the Belgian VAT validator can be changed from ^(BE)(0?\d{9})$ to ^(BE)([0-1]?\d{9})$
  • The following line of code should (imo) be completely removed because the sample VAT number that we received does have 0 as second digit. Otherwise BE1001686633 would be marked as not valid.
    if (Number(newVat.slice(1, 2)) === 0) return false;
  • A Belgian company number consists of 10 digits. There is a line of code that adds a 0 to the start of the entered VAT if the entered VAT is only 9 characters. But since the start of the company number can be either 0 or 1, this line is not correct. I'm not sure what the best fix is, since this is kind of a breaking change.
    this const newVat = vat.length === 9 ? '0' + vat : vat;

Doesn't work with Jest

Error if jsvat is used with Jest during test.
(Works fine elsewhere)

Details:

    C:\Projets\bp-client\node_modules\jsvat\dist\index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export { austria } from './lib/countries/austria';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token export

jsvat : 2.0.1

Italy VAT number validator - office number

Currently library is using the following condition to check office code part of VAT number:

// italy.js
    temp = +vat.slice(7, 10)
    if ((temp < 1) || (temp > 201) && temp !== 999 && temp !== 888) {
      return false
    }

According to Wikipedia (https://it.wikipedia.org/wiki/Partita_IVA) the range should be 1-121. BTW I am not Italian so I am not 100% sure, just the other backend VAT validation library that I use accepts only vats with office number in range 1-121 and 888 and 999. Is this a mistake or is my other validation library not up to date?

umd library not working properly on browser

Using the <script> tag inside a webpage loading index.js from umd package, it will not generate any functions, and checkVAT and other methods are undefined.
How can I use this library on a simple webpage?

Possibility to configure/disable default country

I found that by default country code for GB is optional. So for example both GB000472631 and 000472631 are valid VAT numbers. We would like to accept only VAT numbers with country code.

Would it be possible to make it configurable what country is default if any?

ES6 imports not working for only jsvat

Hi all,

We're trying to use the library at my company and we're having trouble having the es6 version work with our system.

As a workaround we are currently using the commonjs version but we're trying to figure out why the es6 version didn't work and were looking for some help.

This is the error message:
image

Our react app is not ejected but we're using this babel config file to do the parsing of code:

module.exports = {
  presets: [
    '@babel/preset-flow',
    '@babel/preset-react',
    [
      '@babel/preset-env',
      {
        targets: '>0.25%',
      },
    ],
    'module:metro-react-native-babel-preset',
  ],
  plugins: [
    '@babel/plugin-syntax-dynamic-import',
    'dynamic-import-node',
    'react-native-web',
  ],
  overrides: [
    {
      test: ['./src/**/*.ts'],
      presets: [
        '@babel/preset-typescript',
        '@babel/preset-react',
        [
          '@babel/preset-env',
          {
            targets: '>0.25%',
          },
        ],
      ],
    },
  ],
};

Weirdly enough, we are using other libraries in node_modules that make use of es6 language constructs without any issues.

This is our dependency tree:

    "@babel/cli": "^7.0.0",
    "@babel/core": "7.0.0",
    "@babel/plugin-syntax-dynamic-import": "^7.0.0",
    "@babel/preset-env": "^7.7.1",
    "@babel/preset-flow": "^7.0.0",
    "@babel/preset-react": "^7.8.3",
    "@babel/preset-typescript": "^7.7.2",
    "babel-core": "7.0.0-bridge.0",
    "babel-eslint": "^9.0.0",
    "babel-jest": "^23.4.2",
    "babel-plugin-react-native-web": "^0.11.2",
    "cross-env": "^5.1.4",

Any ideas?

Import mechanism

Wouldn't it be good idea to provide a kind of import mechanism for countries.
So you would be able to be more dynamic and to get only the necessarily code downloaded to the client (browser).

Run unit tests against TypeScript files

Currently unit tests are ran against one of the generated JavaScript bundles.
I think we want to run our tests against the TypeScript files, this will also give us insight into the code coverage.

Belgium vat validation issue

There is an issue with the vat validation for Belgium.
Actually, vat format is BE0 + 9 numbers.

Using your validator with the example :
checkVAT('BE0411905847', [belgium]); // true: accept only Belgium VATs
is working but the issue is with this format (without the zero)
checkVAT('BE411905847', [belgium]); // return true but should be false

detect country before number it's fully typed

There should be one or more regexp to find out if a string is the beginning of a vat number for a country

eg: if it starts with FI, it could return that this is an invalid vat number that looks like it's from Finland

CZ: Individuals type 2

Hi,

When I use this library to validate the Czech VAT number "CZ699000899", is returns false, yet when I use the site of VIES (http://ec.europa.eu/taxation_customs/vies/) it says that the VAT number is valid.
Maybe the validation rules changed of perhaps there is an error in the validation? According to the code this should be a Czech Individuals type 2 number.

Kind regards

Possibility to differentiate between invalid VAT and unsupported country?

Is there a possibility to know if VAT validation for specific country is supported?

We have a use case where customer submits WEB form with his name, address and VAT number etc and we should be able to validate at minimum EU VAT numbers.

Now this library works great as long as the customer is from supported countries.

If the customer is for example from Canada or India and enters their local VAT Id, response is similar as it would be for invalid VAT.

Yes I could build hard-coded list of country ISO codes and then validate VAT only for the supported ones but it would be more future proof if I could get the list of supported country ISO codes from lib or if validation response could somehow differentiate between unsupported country / invalid VAT?

generate example number for country

For input placeholders I'd like to be able to generate a fake vat number from a country, the number should probably only look like a vat number for this country but not be a valid one

one example of each is enough, they don't have to be randomly generated (in fact event better if there's only one by country because it would be distracting if the number changed on page refresh)

Swedish VAT numbers do not validate correctly

When validating Swedish VAT numbers, the result is always false with real-world VAT numbers, such as:

556012-5790
969728-1989
716453-0326

I have tried both SE and SV as country code and both return false.

Unexpected token: keyword «const»

Hi,
I just updated to 2.1.2. It all works great and I can check now against all countries. Unfortunately a problem with the production build happened. We use webpack and babel to build. We run our code through babel but not the vendor files so everything es6 related breaks browsers that can't handle es6.
Would it be possible to avoid using es6 features? This error happened when UglifyJs tried to do it's thing. Here the error:

ERROR in 22-chunk.js from UglifyJs Unexpected token: keyword «const» [./node_modules/jsvat/lib/es6/lib/countries/austria.js:1,7]

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.