JSPM

nz-bank-validator

0.0.5
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 459
  • Score
    100M100P100Q99868F
  • License MIT

A small, zero dependency NZ bank account validation library that runs everywhere.

Package Exports

  • nz-bank-validator

Readme

NZ Bank Validator

v0.0.5 - A small, zero dependency Javascript NZ bank account validation library that runs everywhere.

It is based on the 2020 documentation provided by the Inland Revenue Department. This library is not however affiliated with or endorsed by the IRD.

Forked from Josh Hollinshead's nz-bank-account-validator. The project was converted to Typescript and updated to the 2020 spec from the 2016 spec without any changes to the API.

Getting Started

Using npm:

$ npm i --save nz-bank-validator

Using yarn:

$ yarn add nz-bank-validator

Installation

In Node.js (require):

const bankValidator = require("nz-bank-validator");

bankValidator.validate("01-902-0068389-00");
// => true

ES6 Modules:

import bankValidator from "nz-bank-validator";

bankValidator.validate("01-902-0068389-00");
// => true

Usage

const bankValidator = require("nz-bank-validator");

bankValidator.getId("01-902-0068389-00"); // '01'
bankValidator.getBranch("01-902-0068389-00"); // '02'
bankValidator.getBase("01-902-0068389-00"); // '0068389'
bankValidator.getSuffix("01-902-0068389-00"); // '00'

bankValidator.getPartsObject("01-902-0068389-00"); // { id: '01', branch: '902', base: '0068389', suffix: '00' }

bankValidator.validate("01-902-0068389-00"); // true
bankValidator.validate({
  id: "01",
  branch: "902",
  base: "0068389",
  suffix: "00",
}); // true

bankValidator.validate("01-902-XXXXX-00"); // false
bankValidator.validate("01-902--00"); // false
bankValidator.validate("01-902-123456-00"); // false

Running the tests

To run the tests locally:

npm i
npm run tests

License

This project is licensed under the MIT License - see the LICENSE.md file for details

References