/
index.js
executable file
·43 lines (39 loc) · 1.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const lib = require('./lib')
const api = require('./lib/nhtsa.js')
const axios = require('axios')
class Vindec {
constructor(vin, callback) {
this.vin = ''
this.callback = () => {}
this.vindecated = {}
}
validate(vin) {
return lib.validate(vin)
}
decode(vin, callback) {
return this.validate(vin) ? lib.sanitize(
{
vin: vin,
valid: true,
wmi: vin.slice(0,3),
vds: vin.slice(3,8),
checkDigit: vin.slice(8,9),
vis: vin.slice(9,17),
region: lib.getRegion(vin.slice(0,2)),
make: lib.getMake(vin.slice(0,3)),
year: lib.getYear(vin.slice(6,7), vin.slice(9,10)),
sequence_id: vin.slice(11,17)
}) : { vin: vin, valid: false }
}
nhtsaDecode(vin) {
let uri = `${api.uri}${api.action}${vin}${api.format.json}`
axios.get(uri)
.then(res => {
console.log(res.data)
})
.catch(error => {
console.error(error)
})
}
}
module.exports = new Vindec()