diff --git a/index.js b/index.js index 816a464..bb02cc4 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,9 @@ const validate = (vin, checksumParam) => { let total = 0; + if(vin.length !== 17){ + return false; + } for (let i = 0; i < splitVIN.length; i++) { let numValue = 0; let weight = 0; @@ -146,10 +149,9 @@ const validate = (vin, checksumParam) => { return false; } } - if ( total % 11 === parseInt(checksum) || - (total % 11 === 10 && checksum === 'x') + (total % 11 === 10 && checksum === 'x' || (checksum === 'eu')|| (checksum === 'world')) ) { return true; } else { diff --git a/package-lock.json b/package-lock.json index 9961295..726c0c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,6 @@ "requires": true, "packages": { "": { - "name": "vin-decoder", "version": "1.3.0", "license": "ISC", "devDependencies": { diff --git a/test/index.js b/test/index.js index 15969ee..5fc0643 100644 --- a/test/index.js +++ b/test/index.js @@ -13,9 +13,14 @@ describe('#validate', () => { validate('1NXBR32E77Z92360').should.equal(false); }); + it('EU VINs do not have check sum', () => { + validate('YV1MC5851CJ126651','eu').should.equal(true); + }); + it('validate the length to be 17', () => { validate('1NXBR32E77Z923602').should.equal(true); }); + }); describe('#split', () => {