@ recosponsible/jsvat
检查增值税编号格式的有效性. 无依赖关系
免责声明
这个图书馆是一个叉子 兹瓦特 它不再维持,所有新的拉动请求 都长期被忽略.
这么说 问责我们认为,增加对新的增值税号码格式的支持,并使图书馆随时更新和易于维护,因为图书馆是我们日常工作的一部分.
这是什么?
小型图书馆,以检查增值税的有效性号码(欧洲+其他一些州)。 (学习更多 关于增值税)
- 重写为 Typescript : new :
- 无依赖关系
- 没有 http 呼叫
- 双步检查:数学+正则表达式
- 树能震动
- 可扩展
- 对有效增值税和有效增值税格式分别进行检查
- 动态添加/移动您想要检查增值税的国家
- 在完成前检测可能的国家
- 字体
安装
通过 无数字 :
npm i @accountable/jsvat
通过 线条数字 :
yarn add @accountable/jsvat
开始
- 对具体国家的检查
import { checkVAT, belgium, austria } from '@accountable/jsvat';
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
- 对所有支助国家进行核对
import { checkVAT } from '@accountable/jsvat';
checkVAT('BE0411905847'); // no need to pass countries as all supported countries will be used as default behavior
- 对照除特定国家以外的所有支助国家
import { checkVAT, countriesMap } from '@accountable/jsvat';
const { france, germany, ...countriesToValidate } = countriesMap;
checkVAT('BE0411905847', countriesToValidate);
返回值
checkVAT() 返回时 VatCheckResult 对象 :
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" 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;
};
};
}
支助国名单:
- 安道尔
- 奥地利
- 比利时
- 🇧🇷 巴西
- 保加利亚
- 克罗地亚
- 塞浦路斯
- 捷克共和国
- 丹麦
- 爱沙尼亚
- 欧洲
- 芬兰
- 法国
- 德国
- 希腊
- 匈牙利
- 爱尔兰
- * 意大利
- 拉脱维亚
- 立陶宛
- 卢森堡
- 马耳他
- 荷兰
- 挪威
- 波兰
- 葡萄牙
- 罗马尼亚
- 俄罗斯
- 塞尔维亚
- 斯洛伐克共和国
- 斯洛文尼亚
- 🇪🇸 西班牙
- 瑞典
- 联合王国
- 瑞士
扩展国家列表 - 添加您自己的国家
亦可自加本国.
一般情况 Country 应执行下列结构:
interface Country {
name: string;
codes: ReadonlyArray<string>;
rules: {
multipliers: {}; // you can leave it empty
regex: ReadonlyArray<RegExp>;
};
} & ({
calcFn: (vat: string, options?: object) => boolean; // use this if you want to check only format of VAT
} | {
calcWithFormatFn: (vat: string, options?: object) => {isValid: boolean, vat: string}; // use this if you want to check format of VAT and re-format it
})
示例
import { checkVAT } from '@accountable/jsvat';
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
关于模块... ES6 / CommunityJS
jsvat 建筑包括 es6, (中文(简体) ), commonjs, (中文(简体) ), amd, (中文(简体) ), umd 财务报告和审定财务报表 system 同时建设.
默认你会坚持 es6 浏览器和构建工具的版本(webpack等):
它希望您导入为
import { checkVAT, belgium, austria } from '@accountable/jsvat';
节点.js会自动接上 CommonJS 默认版本.
意味着你可以导入它,比如:
// Modern Frontend and Node
const { checkVAT, belgium, austria } = require('@accountable/jsvat');
// Node.js
const { checkVAT, belgium, austria } = require('@accountable/jsvat');
// Legacy Frontend
<script src='whatever/jsvat/lib/umd/index.js'></script>;
或者您可以指定您想要的模块系统,例如:
// CommonJS (i.g nodejs)
const { checkVAT, belgium, austria } = require('jsvat/lib/commonjs');
// ES6
import { checkVAT, belgium, austria } from 'jsvat/lib/es6';
怎么样 @accountable/jsvat 检查有效性?
有两步检查:
- 与 Regexps 列表相比较;
例如,澳洲的正则解释是 /^(AT)U(\d{8})$/。 。 。 .
看起来像 ATU99999999 有效(这是满足正则表达式),但实际上应该无效.
- 一些神奇的数学计数;
在这里我们做了一些数学计算(各国不同).
之后我们也许可以确定 ATU99999999以及例如 ATV66889218 无效,但 ATU12011204 无效.
说明: 一些国家的增值税数字最终应具有特殊字符。 比如瑞典的"01"或塞浦路斯的"L". 如果100%的实际增值税不合适,请尝试加入适当的附录.