Skip to content

Commit

Permalink
fix(validate): mod11 needs to be able to take numbers longer than 10 …
Browse files Browse the repository at this point in the history
…digits

fix #6
  • Loading branch information
swantzter committed May 8, 2020
1 parent cd2d46c commit e8d9064
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SortingCodeInfo } from './banks'
type modFunction = (number: string | number) => boolean

export const mod10: modFunction = (number) => {
number = `${number}`.substr(-10).padStart(10, '0') // pad not strictly neccesary here, but makes it clear and means we get O(n) operations
number = `${number}`

let len = number.length
let bit = 1
Expand All @@ -20,7 +20,7 @@ export const mod10: modFunction = (number) => {
}

export const mod11: modFunction = (number) => {
number = `${number}`.substr(-10).padStart(10, '0') // pad not strictly neccesary here, but makes it clear and means we get O(n) operations
number = `${number}`

let len = number.length
let sum = 0
Expand All @@ -37,7 +37,7 @@ export const mod11: modFunction = (number) => {
}

export default (type: SortingCodeInfo['type'], comment: SortingCodeInfo['comment'], sortingCode: string, accountNumber: string) => {
// 1:1 => mod11 on 3 last of clearng + whole account number
// 1:1 => mod11 on 3 last of clearing + whole account number
if (type === 1 && comment === 1) return mod11(`${sortingCode.substring(1)}${accountNumber.padStart(7, '0')}`)
// 1:2 => mod 11 on whole clearing + whole account number
if (type === 1 && comment === 2) return mod11(`${sortingCode}${accountNumber.padStart(7, '0')}`)
Expand Down

0 comments on commit e8d9064

Please sign in to comment.