@dellacagna/iban

中文文档
1.1.1发布于 2023/01/25MITTypeScriptCommonJS零依赖近 30 天下载 4349

Validate, format and generate IBAN numbers

原始使用文档
文档目录12 节
  1. Usage
  2. NodeJS
  3. API
  4. isValid()
  5. getError()
  6. getOriginal()
  7. toElectronicFormat()
  8. toPrintFormat()
  9. getBBAN()
  10. getFields()
  11. random()
  12. Resources

npm version GitHub license

IBAN Library

A simple library for validating, formatting and generating fake IBAN numbers.

This library follows the ISO 13616 IBAN Registry technical specification and supports 107 countries.

Usage

NodeJS

import { IBAN } from '../index';  
let iban = new IBAN('GB82 WEST 1234 5698 7654 32');
if (iban.isValid()) {
    console.log('The IBAN is valid');
}

API

isValid()

Returns true for a valid IBAN or false if invalid.

example:

let iban = new IBAN('GB82 WEST 1234 5698 7654 32');
if (iban.isValid()) {
    console.log('The IBAN is valid');
}

getError()

If the IBAN is invalid, one of the following errors will be returned as a string:

INVALID_COUNTRY
INVALID_LENGTH
INVALID_FORMAT
CHECKSUM_FAILED

example:


let iban = new IBAN('GB82 WEST 1234');
if (!iban.isValid()) {
    console.log(!iban.getError()); //prints INVALID_LENGTH
}

getOriginal()

Returns the original unformatted IBAN that was used to instantiate the object.

example:

let iban = new IBAN('GB82 weST 123456987654   32');
let unformatted = iban.getOriginal()
console.log(unformatted); //prints GB82 weST 123456987654   32

toElectronicFormat()

Returns the IBAN capitalized with all spaces removed.

example:

let iban = new IBAN('GB82 weST 123456987654   32');
let formatted = iban.toElectronicFormat()
console.log(formatted); //prints GB82WEST12345698765432

toPrintFormat()

Returns the IBAN capitalized with spaces placed as per country format.

example:

let iban = new IBAN('GB82 weST 123456987654   32');
let formatted = iban.toPrintFormat()
console.log(formatted); //prints GB82 WEST 1234 5698 7654 32

getBBAN()

Returns the BBAN (Basic Bank Account Number) capitalized with all spaces removed.

example:

let iban = new IBAN('GB82 WeST 1234 5698 7654 32');
let bban = iban.getBBAN()
console.log(bban); //prints WEST12345698765432

getFields()

Returns an object with extracted information from a valid IBAN. Empty keys will not be returned:

{
  countryCode: string;
  country: string;
  checkDigits: string;
  accountNumber?: string;
  currencyCode?: string;
  ownerAccountNumber?: string;
  accountNumberPrefix?: string;
  bicBankCode?: string;
  branchCode?: string;
  accountType?: string;
  nationalCheckDigit?: string;
 }

example:

let iban = new IBAN('BA39 1290 0794 0102 8494');
let fields = iban.getFields()
console.log(fields);

/* This will output:
  {
    countryCode: 'BA',
    country: 'Bosnia and Herzegovina',
    checkDigits: '39',
    accountNumber: '94010284',
    bankCode: '129',
    branchCode: '007',
    nationalCheckDigit: '94',
 } 
*/

random()

Generate a random IBAN number and return it as a string in print format. You can optionally pass the country code to specify a random IBAN for that country

example (random country):

let iban = IBAN.random();
console.log(iban); //example output: GB82 WEST 1234 5698 7654 32

example (specified country):

let iban = IBAN.random('IT');
console.log(iban); //example output: IT60 X054 2811 1010 0000 0123 456

Resources

版本与发布记录

@dellacagna/iban 共发布 3 个版本,首次发布于 2023/01/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.1latest2023/01/253 年前
1.0.02023/01/243 年前
0.0.12023/01/173 年前

关于 @dellacagna/iban 的常见问题

@dellacagna/iban 是什么?

Validate, format and generate IBAN numbers

如何安装 @dellacagna/iban?

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

@dellacagna/iban 支持 TypeScript 吗?

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

@dellacagna/iban 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dellacagna/iban 可以商用吗?

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

@dellacagna/iban 的下载量有多少?

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

@dellacagna/iban 还在维护吗?

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