@accountable/jsvat

中文文档
1.3.4发布于 2024/07/09MITTypeScriptESM + CJS零依赖近 30 天下载 1.9万

检查增值税号码格式的有效性

中文使用文档
文档目录9 节
  1. 免责声明
  2. 这是什么?
  3. 安装
  4. 开始
  5. 返回值
  6. 支助国名单:
  7. 扩展国家列表 - 添加您自己的国家
  8. 关于模块... ES6 / CommunityJS
  9. 怎么样 @accountable/jsvat 检查有效性?

@ recosponsible/jsvat

检查增值税编号格式的有效性. 无依赖关系

npm PRs Welcome GitHub license

免责声明

这个图书馆是一个叉子 兹瓦特 它不再维持,所有新的拉动请求 都长期被忽略.

这么说 问责我们认为,增加对新的增值税号码格式的支持,并使图书馆随时更新和易于维护,因为图书馆是我们日常工作的一部分.

这是什么?

小型图书馆,以检查增值税的有效性号码(欧洲+其他一些州)。 (学习更多 关于增值税)

  • 重写为 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 检查有效性?

有两步检查:

  1. 与 Regexps 列表相比较;

例如,澳洲的正则解释是 /^(AT)U(\d{8})$/。 。 。 .

看起来像 ATU99999999 有效(这是满足正则表达式),但实际上应该无效.

  1. 一些神奇的数学计数;

在这里我们做了一些数学计算(各国不同). 之后我们也许可以确定 ATU99999999以及例如 ATV66889218 无效,但 ATU12011204 无效.

说明: 一些国家的增值税数字最终应具有特殊字符。 比如瑞典的"01"或塞浦路斯的"L". 如果100%的实际增值税不合适,请尝试加入适当的附录.

版本与发布记录

@accountable/jsvat 共发布 9 个版本,首次发布于 2023/08/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.3.4latest2024/07/092 年前
1.3.32024/05/022 年前
1.3.22024/04/042 年前
1.3.12024/04/042 年前
1.3.02023/08/283 年前
1.2.22023/08/083 年前

关于 @accountable/jsvat 的常见问题

@accountable/jsvat 是什么?

检查增值税号码格式的有效性

如何安装 @accountable/jsvat?

在项目目录运行 npm install @accountable/jsvat,或使用 pnpm add / yarn add / bun add。

@accountable/jsvat 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@accountable/jsvat 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@accountable/jsvat 可以商用吗?

@accountable/jsvat 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@accountable/jsvat 的下载量有多少?

根据 npm 官方下载统计,@accountable/jsvat 在 2026/10/05 – 2026/11/03 这 30 天内被下载 18,869 次,日均约 629 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@accountable/jsvat 还在维护吗?

最新版本 1.3.4 发布于 2024/07/09(2 年前);至今共发布 9 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/08/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。