3.0.2 • Published 5 months ago

@konfirm/iso13616 v3.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

ISO 13616

Implementation of ISO 13616-1:2020 - International Bank Account Number

Installation

The ISO 13616 package is a scoped package, which means one needs to provide the scope (both in installation and use).

$ npm install --save @konfirm/iso13616

Usage

As a version 3.0 the ISO 13616 package has full support for Typescript types and ES Modules. For CommonJS (require) users the packages has a breaking change as it not longer supports the [Symbol.match] syntax for matching, please update to use ISO13616.match instead

API

The ISO 13616 package implements the validation and generation of both the checksum and the full ISO 13616 value for any input

validate

The validate method validates the provided value and determines whether it is a valid ISO 13616 value

argumenttypedescription
inputstring or numberThe ISO 13616 to validate

Example

ES Module

import { validate } from '@konfirm/iso13616';

console.log(validate('foo')); // false
console.log(validate('AD 97 82732793347266899771')); // true

CommonJS

const { validate } = require('@konfirm/iso13616');

console.log(validate('foo')); // false
console.log(validate('CA 02 0131 3167 8000 0065 1238 8')); // true

Typescript

import { validate } from '@konfirm/iso13616';

console.log(validate('foo')); // false
console.log(validate('BY 13 NBRB 3600 900000002Z00AB00')); // true

checksum

The checksum method calculates the checksum for the provided account and country values. As per ISO13616-1:2020 the checksum will be in the range 02-98.

NOTE, versions prior to 2.0 incorrectly used the character range 03-99

argumenttypedescription
accountstring or numberThe account number (BBAN, Basic Bank Account Number)
countrystringThe ISO 3166 country code

ES Module example

import { checksum } from '@konfirm/iso13616';

console.log(checksum('0131 3167 8000 0065 1238 8', 'CA')); // '02'

CommonJS example

const { checksum } = require('@konfirm/iso13616');

console.log(checksum('117 73016 1111101800000000', 'HU')); // '42'

Typescript example

import { checksum } from '@konfirm/iso13616';

console.log(checksum('X 05428 11101 000000123456', 'IT')); // '60'

generate

The generate method generates the full ISO 13616 value for the provided account and country values, optionally formatted in pairs of four characters.

argumenttypedefaultdescription
accountstring or numberThe account number (BBAN, Basic Bank Account Number)
countrystringThe ISO 3166 country code
formatbooleanfalseFormat the output in pairs of four

ES Module example

import { generate } import '@konfirm/iso13616';

console.log(generate('CENR 00000000000000700025', 'SV')); // 'SV62CENR00000000000000700025'
console.log(generate('CENR 00000000000000700025', 'SV', true)); // 'SV62 CENR 0000 0000 0000 0070 0025'

CommonJS example

const { generate } = require('@konfirm/iso13616');

console.log(generate('NBRB 3600 900000002Z00AB00', 'BY')); // 'BY13NBRB3600900000002Z00AB00'
console.log(generate('NBRB 3600 900000002Z00AB00', 'BY', true)); // 'BY13 NBRB 3600 9000 0000 2Z00 AB00'

Typescript example

import { generate } import '@konfirm/iso13616';

console.log(generate('123412341234', 'BI')); // 'BI33123412341234'
console.log(generate('123412341234', 'BI', true)); // 'BI33 1234 1234 1234'

format

Format the provided value in pairs of four characters

argumenttypedescription
inputstring or numberThe ISO 13616 to format

ES Module example

import { format } from '@konfirm/iso13616';

console.log(format('ab-cd12')); // 'ABCD 12'

CommonJS example

const { format } = require('@konfirm/iso13616');

console.log(format('ab-cd-12 ')); // 'ABCD 12'

Typescript example

import { format } from '@konfirm/iso13616';

console.log(format('ab.cd 12')); // 'ABCD 12'

match

Match the input and return an object containing the matched country, checksum, account

argumenttypedescription
inputstring or numberThe ISO 13616 to validate

ES Module example

import { match } = from '@konfirm/iso13616';
console.log(match('AT 61 19043 00234573201'));
// { country: 'AT', checksum: '61', account: '1904300234573201' }

const { country, account, checksum } = match('AT 61 19043 00234573201');
console.log(country); // 'AT'
console.log(account); // '1904300234573201'
console.log(checksum); // '61'

CommonJS example

const { match } = require('@konfirm/iso13616');
console.log(match('AT 61 19043 00234573201'));
// { country: 'AT', checksum: '61', account: '1904300234573201' }

const { country, account, checksum } = match('AT 61 19043 00234573201');
console.log(country); // 'AT'
console.log(account); // '1904300234573201'
console.log(checksum); // '61'

Typescript example

import { match } = from '@konfirm/iso13616';
console.log(match('AT 61 19043 00234573201'));
// { country: 'AT', checksum: '61', account: '1904300234573201' }

const { country, account, checksum } = match('AT 61 19043 00234573201');
console.log(country); // 'AT'
console.log(account); // '1904300234573201'
console.log(checksum); // '61'

Symbol.match

As of version 3.0 the [Symbol.match] is no longer supported, use ISO13616.match instead.

License

MIT License Copyright (c) 2019-2021 Rogier Spieker (Konfirm)

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.

3.0.2

5 months ago

3.0.1

2 years ago

3.0.0

3 years ago

2.0.0

3 years ago

1.0.5

4 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago