Skip to content

Commit e4ebc2d

Browse files
author
Dmitry Ovsyanko
committed
random1011 extracted
1 parent bc9a55a commit e4ebc2d

File tree

1 file changed

+25
-39
lines changed

1 file changed

+25
-39
lines changed

index.js

+25-39
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,20 @@ const randomString = length => {
8383

8484
}
8585

86-
module.exports = {
86+
const random1011 = COEF => {
8787

88-
digit,
89-
scalarProduct,
88+
const
89+
length = COEF.length - 1,
90+
no = randomString (length)
9091

91-
randomSNILS: (options = {}) => {
92+
return no + scalarProduct (COEF.slice (0, length), no) % 11 % 10
9293

93-
const
94-
length = COEF_SNILS.length - 2,
95-
no = randomString (length),
96-
sum = scalarProduct (COEF_SNILS.slice (0, length), no) % 101 % 100
97-
result = sum < 10 ? no + '0' + sum : no + sum
94+
}
9895

99-
return !options.format ? result : result.slice (0, 3) + '-' + result.slice (3, 6) + '-' + result.slice (6, 9) + ' ' + result.slice (9)
96+
module.exports = {
10097

101-
},
98+
digit,
99+
scalarProduct,
102100

103101
isSNILS: str => {
104102

@@ -126,15 +124,6 @@ module.exports = {
126124

127125
},
128126

129-
randomINN10: () => {
130-
131-
const
132-
length = COEF_INN_10.length - 1,
133-
no = randomString (length)
134-
135-
return no + scalarProduct (COEF_INN_10.slice (0, length), no) % 11 % 10
136-
137-
},
138127

139128
isINN12: str => {
140129

@@ -156,16 +145,6 @@ module.exports = {
156145

157146
},
158147

159-
randomOGRN13: () => {
160-
161-
const
162-
length = COEF_OGRN_13.length - 1,
163-
no = randomString (length)
164-
165-
return no + scalarProduct (COEF_OGRN_13.slice (0, length), no) % 11 % 10
166-
167-
},
168-
169148
isOGRN13: str => {
170149

171150
const tobe = scalarProduct (COEF_OGRN_13, str) % 11 % 10, asis = digit (str, 12)
@@ -174,15 +153,6 @@ module.exports = {
174153

175154
},
176155

177-
randomOGRN15: () => {
178-
179-
const
180-
length = COEF_OGRN_15.length - 1,
181-
no = randomString (length)
182-
183-
return no + scalarProduct (COEF_OGRN_15.slice (0, length), no) % 11 % 10
184-
185-
},
186156

187157
isOGRN15: str => {
188158

@@ -204,4 +174,20 @@ module.exports = {
204174

205175
},
206176

177+
randomINN10: () => random1011 (COEF_INN_10),
178+
randomOGRN13: () => random1011 (COEF_OGRN_13),
179+
randomOGRN15: () => random1011 (COEF_OGRN_15),
180+
181+
randomSNILS: (options = {}) => {
182+
183+
const
184+
length = COEF_SNILS.length - 2,
185+
no = randomString (length),
186+
sum = scalarProduct (COEF_SNILS.slice (0, length), no) % 101 % 100
187+
result = sum < 10 ? no + '0' + sum : no + sum
188+
189+
return !options.format ? result : result.slice (0, 3) + '-' + result.slice (3, 6) + '-' + result.slice (6, 9) + ' ' + result.slice (9)
190+
191+
},
192+
207193
}

0 commit comments

Comments
 (0)