Skip to content

Commit 2e2ab61

Browse files
author
Dmitry Ovsyanko
committed
INN +default pre
1 parent c6d641e commit 2e2ab61

File tree

6 files changed

+42
-7
lines changed

6 files changed

+42
-7
lines changed

__tests__/isINN10.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ test ('basic', () => {
77
expect (isINN10 ('1111111117')).toBeUndefined ()
88
expect (isINN10 ('6449013711')).toBeUndefined ()
99

10-
for (let i = 0; i < 1000; i ++) expect (isINN10 (randomINN10 ())).toBeUndefined ()
10+
for (let i = 0; i < 1000; i ++) {
11+
12+
const value = randomINN10 ()
13+
14+
expect (value).not.toMatch (/^00/)
15+
16+
expect (isINN10 (value)).toBeUndefined ()
17+
18+
}
1119

1220
})

__tests__/isINN12.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ test ('basic', () => {
66
expect (() => isINN12 ('635277570473')).toThrow ()
77

88
expect (isINN12 ('635277570478')).toBeUndefined ()
9-
for (let i = 0; i < 1000; i ++) expect (isINN12 (randomINN12 ())).toBeUndefined ()
9+
10+
for (let i = 0; i < 1000; i ++) {
11+
12+
const value = randomINN12 ({pre: ['77', '78']})
13+
14+
expect (value).toMatch (/^7[78]/)
15+
16+
expect (isINN12 (value)).toBeUndefined ()
17+
18+
}
1019

1120
})

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = {
3434
new INN_12_1 ().verify (str.slice (0, 11))
3535
new INN_12_2 ().verify (str)
3636
},
37-
randomINN12: () => new INN_12_2 ().appendCheckSum (new INN_12_1 ().random ()),
37+
randomINN12: opt => new INN_12_2 ().appendCheckSum (new INN_12_1 ().random (opt)),
3838

3939
isBankAcct : (str, bic) => new BankAcct ().verify (str, bic),
4040
randomBankAcct : (bic, opt) => new BankAcct ().random (bic, opt),

lib/INN.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
const ScalarProduct = require ('./ScalarProduct')
22

3+
const PRE = []; for (let i = 1; i < 90; i ++) PRE.push (String (i).padStart (2, '0'))
4+
35
const COEF = new Uint8Array ([3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8])
46

5-
const inn = skip => class extends ScalarProduct {constructor () {super (COEF.slice (skip))}}
7+
const inn = skip => class extends ScalarProduct {
8+
9+
constructor () {
10+
11+
super (COEF.slice (skip))
12+
13+
}
14+
15+
randomValue (options) {
16+
17+
if (!options.pre) options.pre = PRE
18+
19+
return super.randomValue (options)
20+
21+
}
22+
23+
}
624

725
module.exports = {
826

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ru-codes",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "Проверка и генерация ИНН, КПП и т. п.",
55
"main": "index.js",
66
"files": ["/lib", "/badges"],

0 commit comments

Comments
 (0)