Skip to content

Commit

Permalink
chore: ensure vin is 17 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jun 15, 2024
1 parent ed3cdb7 commit 26efb9c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const debug = require('debug-logfmt')('tesla-vin')
const digit = (input, start, end) => (end ? input.slice(start - 1, end) : input[start - 1])

/**
* - https://www.findmyelectric.com/tesla-tesla-vin/
* - https://teslatap.com/tesla-vin/
* - https://service.tesla.com/docs/ModelS/ServiceManual/en-us/GUID-BED77626-E575-4DB7-8C1F-CFA600EAA082.html
* - https://service.tesla.com/docs/ModelS/ServiceManual/Palladium/en-us/GUID-C79EB66B-D6DB-4439-BFC4-6AB53FB19E2C.html
* - https://service.tesla.com/docs/ModelX/ServiceManual/en-us/GUID-B81908BE-D0D7-4E89-BD3A-FC3CA402C54F.html
Expand All @@ -15,6 +13,10 @@ const digit = (input, start, end) => (end ? input.slice(start - 1, end) : input[
* - https://service.tesla.com/docs/Model3/ServiceManual/en-us/GUID-0C797294-574D-4EE4-8017-C339A7D58411.html
*/
module.exports = vin => {
if (vin.length !== 17) {
throw new TypeError(`The VIN must have 17 characters, got ${vin.length} (${vin})`)
}

const modelLetter = digit(vin, 4)
const year = require('./year')(digit(vin, 10))
const result = {
Expand Down
13 changes: 13 additions & 0 deletions test/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'

const test = require('ava')

const vinDecoder = require('../src')

test('throw an errr if the VIN has more than 17 characters', t => {
const error = t.throws(() => vinDecoder('5YJ3300_66a231d5904bac9ea439118675746d8f'))
t.is(
error.message,
'The VIN must have 17 characters, got 40 (5YJ3300_66a231d5904bac9ea439118675746d8f)'
)
})
4 changes: 0 additions & 4 deletions test/model-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,3 @@ test('Tesla Model 3 Performance 2019', t => {
test('Tesla Model 3 Long Range AWD 2020', t => {
t.snapshot(vinDecoder('5YJ3E1EB7LF788019'))
})

// test('Tesla Model 3 Performance 2023', t => {
// t.snapshot(vinDecoder('5YJ3300_66a231d5904bac9ea439118675746d8f'))
// })

0 comments on commit 26efb9c

Please sign in to comment.