Skip to content

Commit a878c67

Browse files
author
Dmitry Ovsyanko
committed
+BankAcct
1 parent c680f46 commit a878c67

File tree

5 files changed

+65
-5
lines changed

5 files changed

+65
-5
lines changed

__tests__/isBankAcct.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const {isBankAcct, randomBankAcct} = require ('..')
2+
3+
const BIC = '044525593', PRE = '40702810'
4+
5+
test ('basic', () => {
6+
7+
expect (isBankAcct (PRE + '801400016513', BIC)).toBeUndefined ()
8+
9+
const a = randomBankAcct (BIC, {pre: [PRE]})
10+
11+
for (let i = 0; i < 1000; i ++) expect (isBankAcct (a, BIC)).toBeUndefined ()
12+
13+
})

__tests__/isKPP.js

-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ test ('basic', () => {
1212
expect (isKPP (randomKPP ())).toBeUndefined ()
1313
expect (randomKPP ({pre: ['77', '50']})).toMatch (/^(50|77)/)
1414

15-
1615
})

index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const Check = require ('./lib/Check')
22
const {OGRN_13, OGRN_15} = require ('./lib/Horner')
33
const {INN_10, INN_12_2, INN_12_1} = require ('./lib/INN')
44
const SNILS = require ('./lib/SNILS')
5+
const BankAcct = require ('./lib/BankAcct')
56
const {OKPO_8, OKPO_10} = require ('./lib/OKPO')
67
class KPP extends Check {constructor () {super (9)}}
78

@@ -32,6 +33,9 @@ module.exports = {
3233
new INN_12_1 ().verify (str.slice (0, 11))
3334
new INN_12_2 ().verify (str)
3435
},
35-
randomINN12: () => new INN_12_2 ().appendCheckSum (new INN_12_1 ().random ())
36+
randomINN12: () => new INN_12_2 ().appendCheckSum (new INN_12_1 ().random ()),
37+
38+
isBankAcct : (str, bic) => new BankAcct ().verify (str, bic),
39+
randomBankAcct: (bic, opt) => new BankAcct ().random (bic, opt),
3640

3741
}

lib/BankAcct.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const Check = require ('./Check')
2+
const ScalarProduct = require ('./ScalarProduct')
3+
4+
const COEF = new Uint8Array ([7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1])
5+
const COEF0 = new Uint8Array ([7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 0, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1])
6+
7+
class BankAcct extends ScalarProduct {
8+
9+
constructor () {
10+
11+
super (COEF, 0)
12+
13+
this.modulus1 = 10
14+
15+
this.bic = new Check (9)
16+
17+
}
18+
19+
verify (str, bic) {
20+
21+
this.bic.verify (bic)
22+
23+
super.verify (bic.slice (-3) + str)
24+
25+
}
26+
27+
random (bic, options) {
28+
29+
this.bic.verify (bic)
30+
31+
this.valueLength = 20
32+
33+
const str = super.randomValue (options), fullStr = bic.slice (-3) + str
34+
35+
this.coefficients = COEF0
36+
this.valueLength = COEF0.length
37+
38+
this.process (fullStr)
39+
40+
return str.slice (0, 8) + ((this.sum % 10) * 3) % 10 + str.slice (9)
41+
42+
}
43+
44+
}
45+
46+
module.exports = BankAcct

lib/Check.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ module.exports = class {
8585

8686
this.mustBeEqual (str.length, this.totalLength, 'length')
8787

88-
const checkSum = this.checkSum (str); if (this.checkSumLength === 0) return
89-
90-
this.mustBeEqual (str.slice (this.valueLength), checkSum, 'checksum')
88+
this.mustBeEqual (this.checkSumLength === 0 ? '0' : str.slice (this.valueLength), this.checkSum (str), 'checksum')
9189

9290
}
9391

0 commit comments

Comments
 (0)