uk-modulus-check
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -5,3 +5,3 @@ "use strict"; | ||
const fs_1 = require("fs"); | ||
const constants_1 = require("./constants"); | ||
const enums_1 = require("./enums"); | ||
const loadSubstitutionMap = () => (0, fs_1.readFileSync)(`${__dirname}/data/scsubtab.txt`, 'utf8') | ||
@@ -50,7 +50,7 @@ .split('\r\n') | ||
let modifiedWeightings = modulusWeight.weights; | ||
const ab = accountDetails.slice(constants_1.AccountDetailIndex.A, constants_1.AccountDetailIndex.B + 1); | ||
const ab = accountDetails.slice(enums_1.AccountDetailIndex.A, enums_1.AccountDetailIndex.B + 1); | ||
if (modulusWeight.exception == 7 || | ||
(modulusWeight.exception == 10 && ['09', '99'].includes(ab))) { | ||
if (accountDetails[constants_1.AccountDetailIndex.G] === '9') { | ||
for (let i = 0; i < constants_1.AccountDetailIndex.B + 1; i++) { | ||
if (accountDetails[enums_1.AccountDetailIndex.G] === '9') { | ||
for (let i = 0; i < enums_1.AccountDetailIndex.B + 1; i++) { | ||
modifiedWeightings[i] = 0; | ||
@@ -61,4 +61,4 @@ } | ||
if (modulusWeight.exception === 2) { | ||
const a = accountDetails[constants_1.AccountDetailIndex.A]; | ||
const g = accountDetails[constants_1.AccountDetailIndex.G]; | ||
const a = accountDetails[enums_1.AccountDetailIndex.A]; | ||
const g = accountDetails[enums_1.AccountDetailIndex.G]; | ||
if (a !== '0' && g !== '9') { | ||
@@ -75,5 +75,5 @@ modifiedWeightings = [0, 0, 1, 2, 5, 3, 6, 4, 8, 7, 10, 9, 3, 1]; | ||
const applyOverwriteExceptionRules = (modulusWeight, accountDetails) => { | ||
const a = accountDetails[constants_1.AccountDetailIndex.A]; | ||
const g = accountDetails[constants_1.AccountDetailIndex.G]; | ||
const h = accountDetails[constants_1.AccountDetailIndex.H]; | ||
const a = accountDetails[enums_1.AccountDetailIndex.A]; | ||
const g = accountDetails[enums_1.AccountDetailIndex.G]; | ||
const h = accountDetails[enums_1.AccountDetailIndex.H]; | ||
// exception 3 is a special case where the first digit of the account number must be 1 or 9 | ||
@@ -116,3 +116,3 @@ if (modulusWeight.exception === 3 && ['1', '9'].includes(a)) { | ||
if (exception == 5) { | ||
const g = parseInt(accountDetails[constants_1.AccountDetailIndex.G], 10); | ||
const g = parseInt(accountDetails[enums_1.AccountDetailIndex.G], 10); | ||
const remainder = total % 11; | ||
@@ -119,0 +119,0 @@ overwriteResult2 = |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs_1 = require("fs"); | ||
const constants_1 = require("./constants"); | ||
const enums_1 = require("./enums"); | ||
const ExceptionRules_1 = require("./ExceptionRules"); | ||
@@ -28,3 +28,3 @@ class ModulusChecker { | ||
let total; | ||
if (modulusWeight.check_type == constants_1.CheckType.DBLAL) { | ||
if (modulusWeight.check_type == enums_1.CheckType.DBLAL) { | ||
total = multiplicationResultArray | ||
@@ -45,3 +45,3 @@ .map((num) => num.toString()) | ||
} | ||
if (modulusWeight.check_type === constants_1.CheckType.MOD11) { | ||
if (modulusWeight.check_type === enums_1.CheckType.MOD11) { | ||
return adjustedTotal % 11 === 0; | ||
@@ -48,0 +48,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { CheckType } from './constants'; | ||
import { CheckType } from './enums'; | ||
export interface ModulusWeight { | ||
@@ -3,0 +3,0 @@ start: number; |
{ | ||
"name": "uk-modulus-check", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
@@ -21,2 +21,4 @@ # UKModulusCheck | ||
See [here](https://www.npmjs.com/package/uk-modulus-check) for the NPM package. | ||
## Usage | ||
@@ -34,3 +36,2 @@ | ||
## Details | ||
@@ -44,3 +45,12 @@ | ||
## Technicalities | ||
In general, I tried to minimise risk of returning `false` for a valid bank account. | ||
1. if an account has an unseen sort code (not covered by any range in src/data/valacdos), by default, any combination of sort-code and account number will be considered valid. This is altered by instantiating a check with `ModulusChecker(false)` and then default behaviour will be set to false | ||
2. I find the specification a bit confusing for some examples, specifically when 2 checks are run on the same account. I mark the account as valid if either of the two validations pass, for cases where multiple validations are provided for the same account. The specific test-cases in listest examples are 23, 27, 28. | ||
Both (1) and (2) might lead to a small % of 'false positives'. | ||
## License | ||
@@ -52,7 +62,7 @@ | ||
Many thanks to [bazerk/uk-modulus-checking](https://github.com/bazerk/uk-modulus-checking) for inspiration (Python) | ||
Thanks to [uphold/uk-modulus-checking](https://github.com/uphold/uk-modulus-checking) for creating a good Javascript implementation. | ||
Also thanks to [uphold/uk-modulus-checking](https://github.com/uphold/uk-modulus-checking) for creating a good Javascript implementation. It doesn't seem to be updated since valacdos-v640 (12/10/2020), which motivates the creation of this package | ||
It doesn't seem to have been updated since valacdos-v640 (12/10/2020), which motivates the creation of this package. | ||
import { readFileSync } from 'fs'; | ||
import { ModulusWeight } from './interfaces'; | ||
import { AccountDetailIndex } from './constants'; | ||
import { AccountDetailIndex } from './enums'; | ||
@@ -5,0 +5,0 @@ const loadSubstitutionMap = (): { [key: string]: string } => |
import { readFileSync } from 'fs'; | ||
import { ModulusWeight } from './interfaces'; | ||
import { CheckType } from './constants'; | ||
import { CheckType } from './enums'; | ||
import { | ||
@@ -5,0 +5,0 @@ applyAccountDetailExceptionRules, |
@@ -1,5 +0,3 @@ | ||
import { CheckType } from './constants'; | ||
import { CheckType } from './enums'; | ||
//create an enum for mod that is one of MOD11, MOD10, DBLAL | ||
export interface ModulusWeight { | ||
@@ -6,0 +4,0 @@ start: number; |
import ModulusChecker from '../src'; | ||
import { ModulusWeight } from '../src/interfaces'; | ||
import { CheckType } from '../src/constants'; | ||
import { CheckType } from '../src/enums'; | ||
@@ -62,34 +62,40 @@ describe('ModulusChecker', () => { | ||
// Vocalink spec tests | ||
// Comment indicates the test number from page 71, here | ||
// https://www.vocalink.com/media/a2febq5m/validating-account-numbers-uk-modulus-checking-v7-90.pdf | ||
// not passing for 23, 27, 28, which are all expected failures according to the spec. | ||
const vocalinkSpecTests = [ | ||
{ sortCode: '089999', accountNumber: '66374958', expectedResult: true }, | ||
{ sortCode: '107999', accountNumber: '88837491', expectedResult: true }, | ||
{ sortCode: '202959', accountNumber: '63748472', expectedResult: true }, | ||
{ sortCode: '871427', accountNumber: '46238510', expectedResult: true }, | ||
{ sortCode: '872427', accountNumber: '46238510', expectedResult: true }, | ||
{ sortCode: '871427', accountNumber: '09123496', expectedResult: true }, | ||
{ sortCode: '871427', accountNumber: '99123496', expectedResult: true }, | ||
{ sortCode: '820000', accountNumber: '73688637', expectedResult: true }, | ||
{ sortCode: '827999', accountNumber: '73988638', expectedResult: true }, | ||
{ sortCode: '827101', accountNumber: '28748352', expectedResult: true }, | ||
{ sortCode: '134020', accountNumber: '63849203', expectedResult: true }, | ||
{ sortCode: '118765', accountNumber: '64371389', expectedResult: true }, | ||
{ sortCode: '200915', accountNumber: '41011166', expectedResult: true }, | ||
{ sortCode: '938611', accountNumber: '07806039', expectedResult: true }, | ||
{ sortCode: '938600', accountNumber: '42368003', expectedResult: true }, | ||
{ sortCode: '938063', accountNumber: '55065200', expectedResult: true }, | ||
{ sortCode: '772798', accountNumber: '99345694', expectedResult: true }, | ||
{ sortCode: '086090', accountNumber: '06774744', expectedResult: true }, | ||
{ sortCode: '309070', accountNumber: '02355688', expectedResult: true }, | ||
{ sortCode: '309070', accountNumber: '12345668', expectedResult: true }, | ||
{ sortCode: '309070', accountNumber: '12345677', expectedResult: true }, | ||
{ sortCode: '309070', accountNumber: '99345694', expectedResult: true }, | ||
{ sortCode: '938063', accountNumber: '15764264', expectedResult: false }, | ||
{ sortCode: '938063', accountNumber: '15763217', expectedResult: false }, | ||
{ sortCode: '118765', accountNumber: '64371388', expectedResult: false }, | ||
{ sortCode: '089999', accountNumber: '66374959', expectedResult: false }, | ||
{ sortCode: '107999', accountNumber: '88837493', expectedResult: false }, | ||
{ sortCode: '074456', accountNumber: '12345112', expectedResult: true }, | ||
{ sortCode: '070116', accountNumber: '34012583', expectedResult: true }, | ||
{ sortCode: '074456', accountNumber: '11104102', expectedResult: true }, | ||
{ sortCode: '180002', accountNumber: '00000190', expectedResult: true }, | ||
{ sortCode: '089999', accountNumber: '66374958', expectedResult: true }, // 1 | ||
{ sortCode: '107999', accountNumber: '88837491', expectedResult: true }, // 2 | ||
{ sortCode: '202959', accountNumber: '63748472', expectedResult: true }, // 3 | ||
{ sortCode: '871427', accountNumber: '46238510', expectedResult: true }, // 4 | ||
{ sortCode: '872427', accountNumber: '46238510', expectedResult: true }, // 5 | ||
{ sortCode: '871427', accountNumber: '09123496', expectedResult: true }, // 6 | ||
{ sortCode: '871427', accountNumber: '99123496', expectedResult: true }, // 7 | ||
{ sortCode: '820000', accountNumber: '73688637', expectedResult: true }, // 8 | ||
{ sortCode: '827999', accountNumber: '73988638', expectedResult: true }, // 9 | ||
{ sortCode: '827101', accountNumber: '28748352', expectedResult: true }, // 10 | ||
{ sortCode: '134020', accountNumber: '63849203', expectedResult: true }, // 11 | ||
{ sortCode: '118765', accountNumber: '64371389', expectedResult: true }, // 12 | ||
{ sortCode: '200915', accountNumber: '41011166', expectedResult: true }, // 13 | ||
{ sortCode: '938611', accountNumber: '07806039', expectedResult: true }, // 14 | ||
{ sortCode: '938600', accountNumber: '42368003', expectedResult: true }, // 15 | ||
{ sortCode: '938063', accountNumber: '55065200', expectedResult: true }, // 16 | ||
{ sortCode: '772798', accountNumber: '99345694', expectedResult: true }, // 17 | ||
{ sortCode: '086090', accountNumber: '06774744', expectedResult: true }, // 18 | ||
{ sortCode: '309070', accountNumber: '02355688', expectedResult: true }, // 19 | ||
{ sortCode: '309070', accountNumber: '12345668', expectedResult: true }, // 20 | ||
{ sortCode: '309070', accountNumber: '12345677', expectedResult: true }, // 21 | ||
{ sortCode: '309070', accountNumber: '99345694', expectedResult: true }, // 22 | ||
{ sortCode: '938063', accountNumber: '15764264', expectedResult: false }, // 24 | ||
{ sortCode: '938063', accountNumber: '15763217', expectedResult: false }, // 25 | ||
{ sortCode: '118765', accountNumber: '64371388', expectedResult: false }, // 26 | ||
{ sortCode: '089999', accountNumber: '66374959', expectedResult: false }, // 29 | ||
{ sortCode: '107999', accountNumber: '88837493', expectedResult: false }, // 30 | ||
{ sortCode: '074456', accountNumber: '12345112', expectedResult: true }, // 31 | ||
{ sortCode: '070116', accountNumber: '34012583', expectedResult: true }, // 32 | ||
{ sortCode: '074456', accountNumber: '11104102', expectedResult: true }, // 33 | ||
{ sortCode: '180002', accountNumber: '00000190', expectedResult: true }, // 34 | ||
]; | ||
@@ -96,0 +102,0 @@ |
363861
32
867
65