@meterapp/vehicle-db 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -73
- package/data/compact.json +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +70 -82
- package/dist/index.js.map +1 -1
- package/package.json +5 -8
- package/data/nhtsa.db +0 -0
package/README.md
CHANGED
|
@@ -1,51 +1,58 @@
|
|
|
1
|
-
# vehicle-db
|
|
1
|
+
# @meterapp/vehicle-db
|
|
2
2
|
|
|
3
|
-
Offline NHTSA vehicle database. All U.S. vehicle makes and models from 1990–2026
|
|
3
|
+
Offline NHTSA vehicle database. All U.S. vehicle makes and models from 1990–2026. Zero dependencies, ~189 KB on npm. No network requests needed.
|
|
4
4
|
|
|
5
5
|
Covers three vehicle types: **Passenger Car**, **Truck**, and **Multipurpose Passenger Vehicle (MPV)**.
|
|
6
6
|
|
|
7
|
-
Drop-in replacement for these NHTSA vPIC API endpoints:
|
|
8
|
-
|
|
9
|
-
- `GetMakesForVehicleType/{type}`
|
|
10
|
-
- `GetModelsForMakeYear/make/{make}/modelyear/{year}`
|
|
11
|
-
- `GetModelsForMakeIdYear/makeId/{id}/modelyear/{year}/vehicleType/{type}`
|
|
12
|
-
|
|
13
7
|
## Install
|
|
14
8
|
|
|
15
9
|
```bash
|
|
16
10
|
npm install @meterapp/vehicle-db
|
|
17
11
|
```
|
|
18
12
|
|
|
19
|
-
> Requires Node.js 18+.
|
|
13
|
+
> Requires Node.js 18+. Zero runtime dependencies — data is bundled as JSON.
|
|
20
14
|
|
|
21
15
|
## Usage
|
|
22
16
|
|
|
23
17
|
```typescript
|
|
24
18
|
import {
|
|
25
19
|
getVehicleTypes,
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
getMakes,
|
|
21
|
+
getModels,
|
|
28
22
|
getAvailableYears,
|
|
29
23
|
close,
|
|
30
24
|
} from "@meterapp/vehicle-db";
|
|
31
25
|
|
|
32
26
|
// List available vehicle types
|
|
33
27
|
const types = getVehicleTypes();
|
|
34
|
-
// =>
|
|
35
|
-
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
// Get all
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
28
|
+
// => [
|
|
29
|
+
// { vehicleTypeId: 2, vehicleTypeName: "Passenger Car" },
|
|
30
|
+
// { vehicleTypeId: 3, vehicleTypeName: "Truck" },
|
|
31
|
+
// { vehicleTypeId: 7, vehicleTypeName: "Multipurpose Passenger Vehicle (MPV)" },
|
|
32
|
+
// ]
|
|
33
|
+
|
|
34
|
+
// Get all makes
|
|
35
|
+
const allMakes = getMakes();
|
|
36
|
+
|
|
37
|
+
// Get makes that have models in 2024
|
|
38
|
+
const makes2024 = getMakes({ year: 2024 });
|
|
39
|
+
|
|
40
|
+
// Get only truck makes for 2024
|
|
41
|
+
const truckMakes = getMakes({ year: 2024, vehicleTypeId: 3 });
|
|
42
|
+
|
|
43
|
+
// Get all Toyota models for 2024
|
|
44
|
+
const toyotaModels = getModels({ makeId: 474, year: 2024 });
|
|
45
|
+
// => [
|
|
46
|
+
// { modelId: 2469, modelName: "Camry", makeId: 474, makeName: "TOYOTA", vehicleTypeId: 2, vehicleTypeName: "Passenger Car" },
|
|
47
|
+
// { modelId: 2208, modelName: "Corolla", ... },
|
|
48
|
+
// ...
|
|
49
|
+
// ]
|
|
50
|
+
|
|
51
|
+
// Get only Ford trucks for 2024
|
|
52
|
+
const fordTrucks = getModels({ makeId: 460, year: 2024, vehicleTypeId: 3 });
|
|
53
|
+
// => [{ modelId: 1801, modelName: "F-150", ... }, ...]
|
|
54
|
+
|
|
55
|
+
// Get all available years
|
|
49
56
|
const years = getAvailableYears();
|
|
50
57
|
// => [1990, 1991, ..., 2026]
|
|
51
58
|
|
|
@@ -55,49 +62,54 @@ close();
|
|
|
55
62
|
|
|
56
63
|
## API
|
|
57
64
|
|
|
58
|
-
### `getVehicleTypes():
|
|
65
|
+
### `getVehicleTypes(): VehicleType[]`
|
|
59
66
|
|
|
60
67
|
Returns all vehicle types in the database.
|
|
61
68
|
|
|
62
69
|
```typescript
|
|
63
|
-
|
|
70
|
+
interface VehicleType {
|
|
71
|
+
vehicleTypeId: number; // e.g. 2
|
|
72
|
+
vehicleTypeName: string; // e.g. "Passenger Car"
|
|
73
|
+
}
|
|
64
74
|
```
|
|
65
75
|
|
|
66
|
-
### `
|
|
76
|
+
### `getMakes(options?): Make[]`
|
|
67
77
|
|
|
68
|
-
Returns
|
|
78
|
+
Returns makes, optionally filtered by year and/or vehicle type.
|
|
69
79
|
|
|
80
|
+
```typescript
|
|
81
|
+
getMakes() // all makes
|
|
82
|
+
getMakes({ year: 2024 }) // makes with models in 2024
|
|
83
|
+
getMakes({ vehicleTypeId: 3 }) // truck makes (all years)
|
|
84
|
+
getMakes({ year: 2024, vehicleTypeId: 3 }) // truck makes in 2024
|
|
70
85
|
```
|
|
71
|
-
GET https://vpic.nhtsa.dot.gov/api/vehicles/GetMakesForVehicleType/truck?year=2024&format=json
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Each result contains:
|
|
75
86
|
|
|
76
87
|
```typescript
|
|
77
|
-
{
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
VehicleTypeId: number; // e.g. 3
|
|
81
|
-
VehicleTypeName: string; // e.g. "Truck"
|
|
88
|
+
interface Make {
|
|
89
|
+
makeId: number; // e.g. 460
|
|
90
|
+
makeName: string; // e.g. "FORD"
|
|
82
91
|
}
|
|
83
92
|
```
|
|
84
93
|
|
|
85
|
-
### `
|
|
94
|
+
### `getModels(options?): Model[]`
|
|
86
95
|
|
|
87
|
-
Returns
|
|
96
|
+
Returns models, optionally filtered by year, vehicle type, and/or make.
|
|
88
97
|
|
|
98
|
+
```typescript
|
|
99
|
+
getModels({ makeId: 474, year: 2024 }) // Toyota 2024 (all types)
|
|
100
|
+
getModels({ makeId: 460, year: 2024, vehicleTypeId: 3 }) // Ford trucks 2024
|
|
101
|
+
getModels({ vehicleTypeId: 3 }) // all trucks (all years)
|
|
102
|
+
getModels({ year: 2024 }) // everything in 2024
|
|
89
103
|
```
|
|
90
|
-
GET https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMakeYear/make/Ford/modelyear/2024?format=json
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
Each result contains:
|
|
94
104
|
|
|
95
105
|
```typescript
|
|
96
|
-
{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
interface Model {
|
|
107
|
+
modelId: number; // e.g. 1801
|
|
108
|
+
modelName: string; // e.g. "F-150"
|
|
109
|
+
makeId: number; // e.g. 460
|
|
110
|
+
makeName: string; // e.g. "FORD"
|
|
111
|
+
vehicleTypeId: number; // e.g. 3
|
|
112
|
+
vehicleTypeName: string; // e.g. "Truck"
|
|
101
113
|
}
|
|
102
114
|
```
|
|
103
115
|
|
|
@@ -109,28 +121,6 @@ Returns all years present in the database, sorted ascending.
|
|
|
109
121
|
|
|
110
122
|
Closes the SQLite connection. Safe to call multiple times. The connection reopens automatically on the next query.
|
|
111
123
|
|
|
112
|
-
## Migrating from the NHTSA API
|
|
113
|
-
|
|
114
|
-
Replace your fetch calls directly:
|
|
115
|
-
|
|
116
|
-
```diff
|
|
117
|
-
- const res = await fetch(
|
|
118
|
-
- `https://vpic.nhtsa.dot.gov/api/vehicles/GetMakesForVehicleType/car?year=${year}&format=json`
|
|
119
|
-
- );
|
|
120
|
-
- const makes = await res.json();
|
|
121
|
-
+ const makes = getMakesForVehicleType("Passenger Car", year);
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
```diff
|
|
125
|
-
- const res = await fetch(
|
|
126
|
-
- `https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMakeYear/make/${encodeURIComponent(make)}/modelyear/${year}?format=json`
|
|
127
|
-
- );
|
|
128
|
-
- const models = await res.json();
|
|
129
|
-
+ const models = getModelsForMakeYear(make, year);
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
The response shape (`Count`, `Message`, `SearchCriteria`, `Results`) matches the NHTSA API, so downstream code should work unchanged.
|
|
133
|
-
|
|
134
124
|
## Database stats
|
|
135
125
|
|
|
136
126
|
| | |
|
|
@@ -139,7 +129,9 @@ The response shape (`Count`, `Message`, `SearchCriteria`, `Results`) matches the
|
|
|
139
129
|
| **Vehicle types** | 3 (Passenger Car, Truck, MPV) |
|
|
140
130
|
| **Makes** | 400 |
|
|
141
131
|
| **Model entries** | 51,270 |
|
|
142
|
-
| **
|
|
132
|
+
| **Data file** | 1.2 MB (JSON) |
|
|
133
|
+
| **npm package** | 189 KB |
|
|
134
|
+
| **npm package size** | 1.5 MB |
|
|
143
135
|
|
|
144
136
|
## Rebuilding the database
|
|
145
137
|
|