From a2f16b6b1c47fed741f2cef1b607cece37c14710 Mon Sep 17 00:00:00 2001 From: Kevin Dekemele Date: Wed, 31 May 2023 10:58:33 +0200 Subject: [PATCH 1/2] Added support for EU and world VINS --- index.js | 2 +- package-lock.json | 1 - test/index.js | 5 +++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 816a464..64d25de 100644 --- a/index.js +++ b/index.js @@ -149,7 +149,7 @@ const validate = (vin, checksumParam) => { 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', () => { From a47a98e8672e62e52e7266591a3302a17df61b93 Mon Sep 17 00:00:00 2001 From: Kevin Dekemele Date: Wed, 31 May 2023 13:06:34 +0200 Subject: [PATCH 2/2] Update index.js --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 64d25de..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' || checksum === 'eu' || checksum === 'world') + (total % 11 === 10 && checksum === 'x' || (checksum === 'eu')|| (checksum === 'world')) ) { return true; } else {