Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsvat

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsvat - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

26

lib/amd/lib/jsvat.js

@@ -8,2 +8,4 @@ define(["require", "exports"], function (require, exports) {

isValid: Boolean(isValid),
isValidFormat: country ? isVatValidToRegexp(vat, country.rules.regex).isValid : false,
isSupportedCountry: Boolean(country),
country: (!country) ? undefined : {

@@ -22,10 +24,19 @@ name: country.name,

}
function getCountryCodes(country) {
return ([
...country.codes,
(country.name === 'Greece') ? 'EL' : undefined
]).filter(Boolean);
}
function getCountry(vat, countriesList) {
for (const country of countriesList) {
const regexpValidRes = isVatValidToRegexp(vat, country.rules.regex);
if (regexpValidRes.isValid)
return country;
if (startsWithCode(vat, country))
return { ...country };
}
return undefined;
}
function startsWithCode(vat, country) {
const countryCodes = getCountryCodes(country);
return countryCodes.filter(code => vat.startsWith(code)).length > 0;
}
function isVatValidToRegexp(vat, regexArr) {

@@ -52,12 +63,7 @@ for (const regex of regexArr) {

const cleanVAT = removeExtraChars(vat);
const result = makeResult(cleanVAT);
const country = getCountry(cleanVAT, countriesList);
if (!country)
return result;
const isValid = isVatValid(cleanVAT, country);
if (isValid)
return makeResult(cleanVAT, isValid, country);
return result;
const isValid = (country) ? isVatValid(cleanVAT, country) : false;
return makeResult(cleanVAT, isValid, country);
}
exports.checkVAT = checkVAT;
});
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -7,2 +25,4 @@ function makeResult(vat, isValid, country) {

isValid: Boolean(isValid),
isValidFormat: country ? isVatValidToRegexp(vat, country.rules.regex).isValid : false,
isSupportedCountry: Boolean(country),
country: (!country) ? undefined : {

@@ -22,11 +42,19 @@ name: country.name,

}
function getCountryCodes(country) {
return (__spreadArrays(country.codes, [
(country.name === 'Greece') ? 'EL' : undefined
])).filter(Boolean);
}
function getCountry(vat, countriesList) {
for (var _i = 0, countriesList_1 = countriesList; _i < countriesList_1.length; _i++) {
var country = countriesList_1[_i];
var regexpValidRes = isVatValidToRegexp(vat, country.rules.regex);
if (regexpValidRes.isValid)
return country;
if (startsWithCode(vat, country))
return __assign({}, country);
}
return undefined;
}
function startsWithCode(vat, country) {
var countryCodes = getCountryCodes(country);
return countryCodes.filter(function (code) { return vat.startsWith(code); }).length > 0;
}
function isVatValidToRegexp(vat, regexArr) {

@@ -55,11 +83,6 @@ for (var _i = 0, regexArr_1 = regexArr; _i < regexArr_1.length; _i++) {

var cleanVAT = removeExtraChars(vat);
var result = makeResult(cleanVAT);
var country = getCountry(cleanVAT, countriesList);
if (!country)
return result;
var isValid = isVatValid(cleanVAT, country);
if (isValid)
return makeResult(cleanVAT, isValid, country);
return result;
var isValid = (country) ? isVatValid(cleanVAT, country) : false;
return makeResult(cleanVAT, isValid, country);
}
exports.checkVAT = checkVAT;

@@ -5,2 +5,4 @@ function makeResult(vat, isValid, country) {

isValid: Boolean(isValid),
isValidFormat: country ? isVatValidToRegexp(vat, country.rules.regex).isValid : false,
isSupportedCountry: Boolean(country),
country: (!country) ? undefined : {

@@ -19,10 +21,19 @@ name: country.name,

}
function getCountryCodes(country) {
return ([
...country.codes,
(country.name === 'Greece') ? 'EL' : undefined
]).filter(Boolean);
}
function getCountry(vat, countriesList) {
for (const country of countriesList) {
const regexpValidRes = isVatValidToRegexp(vat, country.rules.regex);
if (regexpValidRes.isValid)
return country;
if (startsWithCode(vat, country))
return { ...country };
}
return undefined;
}
function startsWithCode(vat, country) {
const countryCodes = getCountryCodes(country);
return countryCodes.filter(code => vat.startsWith(code)).length > 0;
}
function isVatValidToRegexp(vat, regexArr) {

@@ -49,10 +60,5 @@ for (const regex of regexArr) {

const cleanVAT = removeExtraChars(vat);
const result = makeResult(cleanVAT);
const country = getCountry(cleanVAT, countriesList);
if (!country)
return result;
const isValid = isVatValid(cleanVAT, country);
if (isValid)
return makeResult(cleanVAT, isValid, country);
return result;
const isValid = (country) ? isVatValid(cleanVAT, country) : false;
return makeResult(cleanVAT, isValid, country);
}

@@ -8,2 +8,4 @@ System.register([], function (exports_1, context_1) {

isValid: Boolean(isValid),
isValidFormat: country ? isVatValidToRegexp(vat, country.rules.regex).isValid : false,
isSupportedCountry: Boolean(country),
country: (!country) ? undefined : {

@@ -22,10 +24,19 @@ name: country.name,

}
function getCountryCodes(country) {
return ([
...country.codes,
(country.name === 'Greece') ? 'EL' : undefined
]).filter(Boolean);
}
function getCountry(vat, countriesList) {
for (const country of countriesList) {
const regexpValidRes = isVatValidToRegexp(vat, country.rules.regex);
if (regexpValidRes.isValid)
return country;
if (startsWithCode(vat, country))
return { ...country };
}
return undefined;
}
function startsWithCode(vat, country) {
const countryCodes = getCountryCodes(country);
return countryCodes.filter(code => vat.startsWith(code)).length > 0;
}
function isVatValidToRegexp(vat, regexArr) {

@@ -52,10 +63,5 @@ for (const regex of regexArr) {

const cleanVAT = removeExtraChars(vat);
const result = makeResult(cleanVAT);
const country = getCountry(cleanVAT, countriesList);
if (!country)
return result;
const isValid = isVatValid(cleanVAT, country);
if (isValid)
return makeResult(cleanVAT, isValid, country);
return result;
const isValid = (country) ? isVatValid(cleanVAT, country) : false;
return makeResult(cleanVAT, isValid, country);
}

@@ -62,0 +68,0 @@ exports_1("checkVAT", checkVAT);

@@ -16,2 +16,4 @@ (function (factory) {

isValid: Boolean(isValid),
isValidFormat: country ? isVatValidToRegexp(vat, country.rules.regex).isValid : false,
isSupportedCountry: Boolean(country),
country: (!country) ? undefined : {

@@ -30,10 +32,19 @@ name: country.name,

}
function getCountryCodes(country) {
return ([
...country.codes,
(country.name === 'Greece') ? 'EL' : undefined
]).filter(Boolean);
}
function getCountry(vat, countriesList) {
for (const country of countriesList) {
const regexpValidRes = isVatValidToRegexp(vat, country.rules.regex);
if (regexpValidRes.isValid)
return country;
if (startsWithCode(vat, country))
return { ...country };
}
return undefined;
}
function startsWithCode(vat, country) {
const countryCodes = getCountryCodes(country);
return countryCodes.filter(code => vat.startsWith(code)).length > 0;
}
function isVatValidToRegexp(vat, regexArr) {

@@ -60,12 +71,7 @@ for (const regex of regexArr) {

const cleanVAT = removeExtraChars(vat);
const result = makeResult(cleanVAT);
const country = getCountry(cleanVAT, countriesList);
if (!country)
return result;
const isValid = isVatValid(cleanVAT, country);
if (isValid)
return makeResult(cleanVAT, isValid, country);
return result;
const isValid = (country) ? isVatValid(cleanVAT, country) : false;
return makeResult(cleanVAT, isValid, country);
}
exports.checkVAT = checkVAT;
});
{
"name": "jsvat",
"version": "2.2.0",
"version": "2.3.0",
"description": "Check the validity of the format of an EU VAT number",

@@ -49,2 +49,5 @@ "main": "./lib/commonjs/index.js",

"author": "S.Panfilov <se-panfilov@ya.ru> (https://se-panfilov.github.io)",
"contributors": [
"Wilgert Velinga <wilgert@wilgert.nl> (http://wilgert.nl)"
],
"private": false,

@@ -56,5 +59,5 @@ "dependencies": {},

"babel-plugin-transform-es2015-modules-commonjs": "6.26.2",
"jest": "25.2.7",
"jest": "25.3.0",
"rimraf": "3.0.2",
"ts-loader": "6.2.2",
"ts-loader": "7.0.0",
"tslint": "6.1.1",

@@ -61,0 +64,0 @@ "tslint-config-prettier": "1.18.0",

@@ -24,9 +24,11 @@ [![Codacy Badge](https://api.codacy.com/project/badge/grade/874e7dce623149e18807bdc0a02671c2)](https://www.codacy.com/app/se-panfilov/jsvat)

- no dependencies;
- no http calls;
- No dependencies;
- No http calls;
- 2-step checks: math + regexp;
- tree-shakeable;
- extendable;
- dynamically add/remove countries with which you want to check the VAT;
- written in `typescript`;
- Tree-shakeable;
- Extendable;
- Separate checks for valid VAT and valid VAT format;
- Dynamically add/remove countries with which you want to check the VAT;
- Detecting possible country before you finish;
- Typescript;

@@ -38,4 +40,8 @@ Installation

`npm i jsvat --save` or `yarn add jsvat`
```bash
npm i jsvat --save
```
(or `yarn add jsvat`)
For legacy versions (below v2.0.0) also possible: Bower: `bower i jsvat --save`

@@ -57,3 +63,3 @@

`checkVAT()` returns a `Result` Object:
`checkVAT()` returns `VatCheckResult` object:

@@ -64,4 +70,6 @@ ```typescript

value?: string; // 'BE0411905847': your VAT without extra characters (like '-', spaces, etc)
isValid: boolean; // main result - is VAT correct against provided countries or not
country?: { // VAT's couuntry (null if not found)
isValid: boolean; // The main result. Indicates if VAT is correct against provided countries or not
isValidFormat: boolean; // Indicates the validation of the format of VAT only. E.g. "BE0411905847" is a valid VAT, and "BE0897221791" is not. But they both has valid format, so "isValidFormat" will return "true"
isSupportedCountry: boolean; // Indicates if "jsvat" could recognize the VAT. Sometimes you want to understand - if it's an invalid VAT from supported country or from an unknown one
country?: { // VAT's country (null if not found). By "supported" I mean imported.
name: string; // ISO country name of VAT

@@ -68,0 +76,0 @@ isoCode: { // Country ISO codes

@@ -25,2 +25,4 @@ export interface Multipliers {

isValid: boolean;
isValidFormat: boolean;
isSupportedCountry: boolean;
country?: {

@@ -27,0 +29,0 @@ name: string;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc