Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
A fork of https://github.com/se-panfilov/jsvat since it was unmaintained for over a year with open PR's that were important to add.
Small library to check validity VAT numbers (European + some others counties). (learn more about VAT)
Installation:
npm i jsvat-next --save
(or yarn add jsvat-next
)
For legacy versions (below v2.0.0) also possible: Bower: bower i jsvat-next --save
import { checkVAT, belgium, austria } from 'jsvat-next';
checkVAT('BE0411905847', [belgium]); // true: accept only Belgium VATs
checkVAT('BE0411905847', [belgium, austria]); // true: accept only Belgium or Austria VATs
checkVAT('BE0411905847', [austria]); // false: accept only Austria VATs
or
import { checkVAT, countries } from 'jsvat-next';
('countries');
checkVAT('BE0411905847', countries); // check against all supported countries
to check against all supported countries
checkVAT()
returns VatCheckResult
object:
export interface VatCheckResult {
value?: string; // 'BE0411905847': your VAT without extra characters (like '-', spaces, etc)
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-next" 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
isoCode: {
// Country ISO codes
short: string;
long: string;
numeric: string;
};
};
}
import { checkVAT, countries } from 'jsvat-next';
// const { checkVAT, countries } = require('jsvat-next');
checkVAT('WD12345678', countries);
You can add your own country.
In general Country
should implement following structure:
interface Country {
name: string;
codes: ReadonlyArray<string>;
calcFn: (vat: string, options?: object) => boolean; //options - isn't a mandatory param
rules: {
multipliers: {}; // you can leave it empty
regex: ReadonlyArray<RegExp>;
};
}
Example:
import { checkVAT } from 'jsvat-next';
export const wonderland = {
name: 'Wonderland',
codes: ['WD', 'WDR', '999'], // This codes should follow ISO standards (short, long and numeric), but it's your own business
calcFn: (vat) => {
return vat.length === 10;
},
rules: {
regex: [/^(WD)(\d{8})$/]
}
};
checkVAT('WD12345678', [wonderland]); // true
jsvat build includes es6
, commonjs
, amd
, umd
and system
builds at the same time.
By default you will stick to es6
version for browsers and build tools (webpack, etc):
which expects you to import it as
import { checkVAT, belgium, austria } from 'jsvat-next';
Node.js automatically will pick up CommonJS
version by default.
Means you could import it like:
// Modern Frontend and Node
const { checkVAT, belgium, austria } = require('jsvat-next');
// Node.js
const { checkVAT, belgium, austria } = require('jsvat-next');
// Legacy Frontend
<script src="whatever/jsvat-next/lib/umd/index.js"></script>;
Alternatively you can specify which module system you do want, e.g.:
// CommonJS (i.g nodejs)
const { checkVAT, belgium, austria } = require('jsvat-next/lib/commonjs');
// ES6
import { checkVAT, belgium, austria } from 'jsvat-next/lib/es6';
// UMD
<script src="whatever/jsvat-next/lib/umd/index.js"></script>;
// AMD
const { checkVAT, belgium, austria } = require('jsvat-next/lib/amd');
// System
import { checkVAT, belgium, austria } from 'jsvat-next/lib/system';
There is 2-step check:
For example regexp for austria is /^(AT)U(\d{8})$/
.
Looks like ATU99999999
is valid (it's satisfy the regexp), but actually it's should be invalid.
Here we make some mathematical calculation (different for each country).
After that we may be sure that ATU99999999
and for example ATV66889218
isn't valid, but ATU12011204
is valid.
NOTE: VAT numbers of some countries should ends up with special characters. Like '01' for Sweden or "L" for Cyprus. If 100% real VAT doesn't fit, try to add proper appendix.
Support only of evergreen browsers.
Legacy versions (below v2.0.0) supports all browsers down to IE9 (including IE9).
The MIT License (MIT)
Copyright (c) 2015 Sergei Panfilov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Check the validity of the format of an EU VAT number
We found that jsvat-next demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.