Comparing version 1.0.0 to 1.0.1
122
isInn.js
@@ -1,73 +0,67 @@ | ||
( function( ) { | ||
/* | ||
* https://ru.wikipedia.org/wiki/Идентификационный_номер_налогоплательщика | ||
*/ | ||
var isInn = function( inn ) { | ||
if( typeof inn === "string" || typeof inn === "number" ) { | ||
inn = inn.toString( ); | ||
if( (/^\d+$/).test( inn ) === false ) { | ||
(function() { | ||
// https://ru.wikipedia.org/wiki/Идентификационный_номер_налогоплательщика | ||
var isInn = function(inn) { | ||
if (typeof inn === "string" || typeof inn === "number") { | ||
inn = inn.toString(); | ||
if ((/^\d+$/).test(inn) === false) { | ||
return false; | ||
} | ||
/* | ||
* Проверка контрольных цифр | ||
*/ | ||
if( inn.length === 10 ) { | ||
/* | ||
* Для 10-значного ИНН | ||
*/ | ||
return inn.charAt( 9 ) == ( ( | ||
2*inn.charAt( 0 ) + | ||
4*inn.charAt( 1 ) + | ||
10*inn.charAt( 2 ) + | ||
3*inn.charAt( 3 ) + | ||
5*inn.charAt( 4 ) + | ||
9*inn.charAt( 5 ) + | ||
4*inn.charAt( 6 ) + | ||
6*inn.charAt( 7 ) + | ||
8*inn.charAt( 8 ) | ||
) % 11 ) % 10 | ||
} else if( inn.length === 12 ) { | ||
/* | ||
* Для 12-значного ИНН | ||
*/ | ||
return ( inn.charAt( 10 ) == ( ( | ||
7*inn.charAt( 0 ) + | ||
2*inn.charAt( 1 ) + | ||
4*inn.charAt( 2 ) + | ||
10*inn.charAt( 3 ) + | ||
3*inn.charAt( 4 ) + | ||
5*inn.charAt( 5 ) + | ||
9*inn.charAt( 6 ) + | ||
4*inn.charAt( 7 ) + | ||
6*inn.charAt( 8 ) + | ||
8*inn.charAt( 9 ) | ||
) % 11 ) % 10 ) || | ||
( inn.charAt( 11 ) == ( ( | ||
3*inn.charAt( 0 ) + | ||
7*inn.charAt( 1 ) + | ||
2*inn.charAt( 2 ) + | ||
4*inn.charAt( 3 ) + | ||
10*inn.charAt( 4 ) + | ||
3*inn.charAt( 5 ) + | ||
5*inn.charAt( 6 ) + | ||
9*inn.charAt( 7 ) + | ||
4*inn.charAt( 8 ) + | ||
6*inn.charAt( 9 ) + | ||
8*inn.charAt( 9 ) | ||
) % 11 ) % 10 ) | ||
} | ||
// Проверка контрольных цифр | ||
if (inn.length === 10) { | ||
// Для 10-значного ИНН | ||
return inn.charAt(9) == (( | ||
2*inn.charAt(0) + | ||
4*inn.charAt(1) + | ||
10*inn.charAt(2) + | ||
3*inn.charAt(3) + | ||
5*inn.charAt(4) + | ||
9*inn.charAt(5) + | ||
4*inn.charAt(6) + | ||
6*inn.charAt(7) + | ||
8*inn.charAt(8) | ||
) % 11) % 10 | ||
} else if (inn.length === 12) { | ||
// Для 12-значного ИНН | ||
return (inn.charAt(10) == (( | ||
7*inn.charAt(0) + | ||
2*inn.charAt(1) + | ||
4*inn.charAt(2) + | ||
10*inn.charAt(3) + | ||
3*inn.charAt(4) + | ||
5*inn.charAt(5) + | ||
9*inn.charAt(6) + | ||
4*inn.charAt(7) + | ||
6*inn.charAt(8) + | ||
8*inn.charAt(9) | ||
) % 11) % 10) && | ||
(inn.charAt(11) == (( | ||
3*inn.charAt(0) + | ||
7*inn.charAt(1) + | ||
2*inn.charAt(2) + | ||
4*inn.charAt(3) + | ||
10*inn.charAt(4) + | ||
3*inn.charAt(5) + | ||
5*inn.charAt(6) + | ||
9*inn.charAt(7) + | ||
4*inn.charAt(8) + | ||
6*inn.charAt(9) + | ||
8*inn.charAt(10) | ||
) % 11) % 10) | ||
} | ||
return false; | ||
}; | ||
} | ||
return false; | ||
} | ||
/* | ||
* Экспортируем модуль | ||
*/ | ||
// Экспортируем модуль | ||
if (typeof module !== "undefined" && typeof module.exports !== "undefined") { | ||
module.exports = isInn; | ||
} else { | ||
if ( typeof define === "function" && define.amd ) { | ||
define( [ ], function() { | ||
if (typeof define === "function" && define.amd) { | ||
define([ ], function() { | ||
return isInn; | ||
} ); | ||
}); | ||
} else { | ||
@@ -77,2 +71,2 @@ window.isInn = isInn; | ||
} | ||
} )( ); | ||
})(); |
{ | ||
"name": "is-inn-js", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Проверка валидности ИНН", | ||
"main": "isInn.js", | ||
"typings": "./index.d.ts", | ||
"scripts": { | ||
@@ -7,0 +8,0 @@ "test": "./node_modules/mocha/bin/mocha test" |
@@ -10,2 +10,9 @@ # is-inn-js | ||
### Тестирование: | ||
```sh | ||
$ npm run test | ||
``` | ||
### Пример использования | ||
@@ -15,12 +22,14 @@ #### NodeJS | ||
const isInn = require('is-inn-js'); | ||
let isInnResult = isInn("4234002402"); | ||
console.log( isInnResult ) // print: true | ||
let isInnResult = isInn('4234002402'); | ||
console.log(isInnResult) // print: true | ||
``` | ||
#### Browser | ||
```html | ||
<script src="/node_modules/is-inn-js/isInn.js"></script> | ||
<script src='/node_modules/is-inn-js/isInn.js'></script> | ||
<script> | ||
var isInnResult = isInn("4234002402"); | ||
console.log( isInnResult ) // print: true | ||
var isInnResult = isInn('4234002402'); | ||
console.log(isInnResult) // print: true | ||
</script> | ||
``` | ||
``` | ||
isInn возвращает true для валидного ИНН и false для не валидного. Проверка идет с подсчётом контрольных сумм |
@@ -78,66 +78,11 @@ const assert = require('assert') | ||
'4207008719', | ||
'4207048077', | ||
'420900166500', | ||
'4209013376', | ||
'4209033319', | ||
'4212012816', | ||
'4216003724', | ||
'4217063067', | ||
'423001325829', | ||
'4234002402', | ||
'4238019911', | ||
'4243005569', | ||
'4246004620', | ||
'5405177439', | ||
'5407127899', | ||
'4206032998', | ||
'4206410713', | ||
'420700009348', | ||
'4207000710', | ||
'420700218140', | ||
'420700245585', | ||
'4207003319', | ||
'4207004390', | ||
'4207005468', | ||
'4207005651', | ||
'4207007151', | ||
'4207008719', | ||
'4207010475', | ||
'420800036137', | ||
'4208004298', | ||
'4208013180', | ||
'4208013246', | ||
'4208014151', | ||
'4208014218', | ||
'4209000786', | ||
'4209000962', | ||
'420900166500', | ||
'420900218123', | ||
'4209030170', | ||
'4209030438', | ||
'4209032900', | ||
'4209033319', | ||
'4209033968', | ||
'4210000710', | ||
'4210001760', | ||
'4210003051', | ||
'4210003100', | ||
'4210005980', | ||
'4211000769', | ||
'4212426831', | ||
'4212427095', | ||
'4212427151', | ||
'421300034422', | ||
'423001325829', | ||
'4230016997', | ||
'4230018458', | ||
'4230020009', | ||
'4230020425', | ||
'4230020538', | ||
'4230021242', | ||
'4230021588', | ||
'4247004340', | ||
'4247004559', | ||
'424750253733' | ||
].forEach( ( data ) => { | ||
@@ -165,4 +110,4 @@ makeTest( data ); | ||
'1112427095', | ||
'1112427151' | ||
'1112427151', | ||
'1111111111' | ||
].forEach( ( data ) => { | ||
@@ -169,0 +114,0 @@ makeTest( data ); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5
34
5713
178