├── packages ├── lib │ ├── src │ │ ├── global.d.ts │ │ ├── vite-env.d.ts │ │ ├── constants.ts │ │ ├── api │ │ │ ├── index.ts │ │ │ ├── README.md │ │ │ ├── types.ts │ │ │ └── endpoints │ │ │ │ ├── index.ts │ │ │ │ ├── GetAllMakes.ts │ │ │ │ ├── GetVehicleVariableList.ts │ │ │ │ ├── types.ts │ │ │ │ ├── __tests__ │ │ │ │ ├── GetAllMakes.test.ts │ │ │ │ ├── GetVehicleVariableList.test.ts │ │ │ │ ├── DecodeWMI.test.ts │ │ │ │ ├── GetModelsForMake.test.ts │ │ │ │ ├── GetVehicleTypesForMake.test.ts │ │ │ │ ├── GetVehicleTypesForMakeId.test.ts │ │ │ │ ├── GetMakesForVehicleType.test.ts │ │ │ │ ├── GetVehicleVariableValuesList.test.ts │ │ │ │ ├── DecodeVinValuesBatch.test.ts │ │ │ │ └── GetModelsForMakeId.test.ts │ │ │ │ ├── GetModelsForMake.ts │ │ │ │ ├── GetVehicleTypesForMake.ts │ │ │ │ ├── GetMakesForVehicleType.ts │ │ │ │ ├── GetVehicleVariableValuesList.ts │ │ │ │ ├── DecodeWMI.ts │ │ │ │ ├── GetMakeForManufacturer.ts │ │ │ │ ├── GetModelsForMakeId.ts │ │ │ │ └── GetVehicleTypesForMakeId.ts │ │ ├── types.ts │ │ ├── utils │ │ │ ├── index.ts │ │ │ ├── types.ts │ │ │ ├── getTypeof.ts │ │ │ ├── errorHandler.ts │ │ │ └── __tests__ │ │ │ │ ├── getTypeof.test.ts │ │ │ │ ├── isValidVin.test.ts │ │ │ │ └── index.test.ts │ │ └── index.ts │ ├── .typedoc │ │ ├── README.md │ │ └── typedoc.cjs │ ├── tsconfig.node.json │ ├── .vitest │ │ ├── setup.ts │ │ ├── helpers.ts │ │ └── data.ts │ ├── tsconfig.json │ ├── vite.config.ts │ └── package.json └── README.md ├── .npmrc ├── pnpm-workspace.yaml ├── apps ├── docs │ ├── src │ │ ├── public │ │ │ ├── robots.txt │ │ │ ├── hero.png │ │ │ ├── favicon.ico │ │ │ ├── pwa-192x192.png │ │ │ ├── pwa-512x512.png │ │ │ ├── favicon-16x16.png │ │ │ ├── favicon-32x32.png │ │ │ └── apple-touch-icon.png │ │ ├── typedoc │ │ │ ├── modules │ │ │ │ ├── global.md │ │ │ │ ├── vite_env.md │ │ │ │ ├── constants.md │ │ │ │ ├── utils_getTypeof.md │ │ │ │ ├── utils_isValidVin.md │ │ │ │ ├── utils.md │ │ │ │ ├── utils_errorHandler.md │ │ │ │ ├── utils_types.md │ │ │ │ ├── api_endpoints_GetAllMakes.md │ │ │ │ ├── api_endpoints_GetModelsForMake.md │ │ │ │ ├── api_endpoints_GetVehicleTypesForMake.md │ │ │ │ ├── api_endpoints_GetMakesForVehicleType.md │ │ │ │ ├── api_endpoints_GetVehicleVariableList.md │ │ │ │ ├── api_endpoints_DecodeWMI.md │ │ │ │ ├── api_endpoints_GetVehicleVariableValuesList.md │ │ │ │ └── api_endpoints_GetMakeForManufacturer.md │ │ │ ├── .nojekyll │ │ │ ├── index.md │ │ │ └── modules.md │ │ ├── utils │ │ │ ├── index.md │ │ │ └── is-valid-vin.md │ │ ├── parts │ │ │ ├── package-exports-utility-functions.md │ │ │ ├── package-exports-endpoint-functions.md │ │ │ └── package-exports-types.md │ │ ├── snippets │ │ │ └── endpoints │ │ │ │ ├── get-all-makes.ts │ │ │ │ ├── decode-wmi.ts │ │ │ │ ├── get-vehicle-types-for-make-id.ts │ │ │ │ ├── get-makes-for-manufacturer-and-year.ts │ │ │ │ ├── get-wmis-for-manufacturer.ts │ │ │ │ ├── get-vehicle-variable-values-list.ts │ │ │ │ ├── get-make-for-manufacturer.ts │ │ │ │ ├── get-makes-for-vehicle-type.ts │ │ │ │ ├── get-parts.ts │ │ │ │ └── get-manufacturer-details.ts │ │ ├── api │ │ │ ├── endpoints │ │ │ │ ├── index.md │ │ │ │ └── get-vehicle-variable-list.md │ │ │ └── index.md │ │ ├── guide │ │ │ ├── offline-vin-validation.md │ │ │ └── vin-decoding.md │ │ └── index.md │ ├── CHANGELOG.md │ ├── .env.example │ ├── .vitepress │ │ ├── theme │ │ │ ├── styles │ │ │ │ ├── index.scss │ │ │ │ ├── vars.scss │ │ │ │ ├── fonts.scss │ │ │ │ ├── scrollbar.scss │ │ │ │ └── home.scss │ │ │ ├── index.ts │ │ │ └── components │ │ │ │ ├── RegisterSW.vue │ │ │ │ └── ReloadPrompt.vue │ │ ├── menu.ts │ │ ├── head.ts │ │ └── icons.ts │ ├── README.md │ ├── tsconfig.json │ └── package.json └── README.md ├── config ├── tsconfig │ ├── README.md │ ├── vitepress.json │ ├── react-library.json │ ├── vite-library.json │ ├── package.json │ ├── base.json │ └── nextjs.json ├── prettier-config │ ├── README.md │ ├── prettier-config.json │ └── package.json ├── typedoc-config │ ├── README.md │ ├── package.json │ └── typedoc-config.js ├── eslint-config-custom │ ├── README.md │ ├── package.json │ └── eslint-config.js └── README.md ├── .github ├── ISSUE_TEMPLATE │ ├── custom.md │ ├── feature_request.md │ └── bug_report.md ├── renovate.json ├── workflows │ ├── setup │ │ └── action.yaml │ ├── coverage.yml │ └── release.yml ├── todos.md └── CODE_OF_CONDUCT.md ├── vercel.json ├── examples └── simple-examples │ ├── nhtsa-test.mjs │ ├── nhtsa-test.js │ ├── nhtsa-test.cjs │ ├── nhtsa-test-umd-cjs.js │ ├── nhtsa-test-umd.html │ ├── nhtsa-test-iife.html │ └── nhtsa-test-mjs.html ├── CHANGELOG.md ├── .changeset ├── config.json └── README.md ├── .vscode ├── extensions.json └── settings.json ├── turbo.json ├── LICENSE.txt ├── .npmignore ├── .gitignore └── package.json /packages/lib/src/global.d.ts: -------------------------------------------------------------------------------- 1 | import 'vitest-fetch-mock' 2 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | prefer-workspace-packages=true 2 | strict-peer-dependencies=false -------------------------------------------------------------------------------- /packages/lib/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - 'apps/*' 3 | - 'config/*' 4 | - 'packages/*' 5 | - '!**/test/**' 6 | -------------------------------------------------------------------------------- /apps/docs/src/public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Allow: / 3 | 4 | Sitemap: https://vpic.shaggytech.com/sitemap.xml -------------------------------------------------------------------------------- /apps/docs/src/public/hero.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShaggyTech/nhtsa-api-wrapper/HEAD/apps/docs/src/public/hero.png -------------------------------------------------------------------------------- /apps/docs/src/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShaggyTech/nhtsa-api-wrapper/HEAD/apps/docs/src/public/favicon.ico -------------------------------------------------------------------------------- /apps/docs/src/public/pwa-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShaggyTech/nhtsa-api-wrapper/HEAD/apps/docs/src/public/pwa-192x192.png -------------------------------------------------------------------------------- /apps/docs/src/public/pwa-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShaggyTech/nhtsa-api-wrapper/HEAD/apps/docs/src/public/pwa-512x512.png -------------------------------------------------------------------------------- /apps/docs/src/public/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShaggyTech/nhtsa-api-wrapper/HEAD/apps/docs/src/public/favicon-16x16.png -------------------------------------------------------------------------------- /apps/docs/src/public/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShaggyTech/nhtsa-api-wrapper/HEAD/apps/docs/src/public/favicon-32x32.png -------------------------------------------------------------------------------- /config/tsconfig/README.md: -------------------------------------------------------------------------------- 1 | # `tsconfig` 2 | 3 | Internal shared typescript `.tsconfig`s for the `@shaggytools/nhtsa-api-wrapper` monorepo" 4 | -------------------------------------------------------------------------------- /apps/docs/src/public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShaggyTech/nhtsa-api-wrapper/HEAD/apps/docs/src/public/apple-touch-icon.png -------------------------------------------------------------------------------- /config/prettier-config/README.md: -------------------------------------------------------------------------------- 1 | # `prettier-config` 2 | 3 | Internal shared `prettierrc` for the `@shaggytools/nhtsa-api-wrapper` monorepo 4 | -------------------------------------------------------------------------------- /config/typedoc-config/README.md: -------------------------------------------------------------------------------- 1 | # `typedoc-config` 2 | 3 | Internal shared `typedoc` config for the `@shaggytools/nhtsa-api-wrapper` monorepo 4 | -------------------------------------------------------------------------------- /packages/lib/.typedoc/README.md: -------------------------------------------------------------------------------- 1 | ::: tip :bulb: Auto-generated By TypeDoc from package source code 2 | ::: 3 | 4 | 5 | -------------------------------------------------------------------------------- /packages/lib/src/constants.ts: -------------------------------------------------------------------------------- 1 | export const NHTSA_BASE_URL = 'https://vpic.nhtsa.dot.gov/api/vehicles' 2 | export const NHTSA_RESPONSE_FORMAT = 'json' 3 | -------------------------------------------------------------------------------- /config/eslint-config-custom/README.md: -------------------------------------------------------------------------------- 1 | # `eslint-config-custom` 2 | 3 | Internal shared `eslint-config` for the `@shaggytools/nhtsa-api-wrapper` monorepo 4 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/global.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / global 2 | 3 | # Module: global 4 | -------------------------------------------------------------------------------- /apps/docs/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # docs 2 | 3 | ## 3.0.4 4 | 5 | ### Patch Changes 6 | 7 | - Updated dependencies [99adf18] 8 | - @shaggytools/nhtsa-api-wrapper@3.0.4 9 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/vite_env.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / vite-env 2 | 3 | # Module: vite-env 4 | -------------------------------------------------------------------------------- /packages/lib/src/api/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module api 3 | * @category API 4 | */ 5 | 6 | export * from './endpoints' 7 | export { useNHTSA } from './useNHTSA' 8 | -------------------------------------------------------------------------------- /apps/docs/.env.example: -------------------------------------------------------------------------------- 1 | VITEPRESS_BASE='/' 2 | VITEPRESS_ALGOLIA_INDEX_NAME='index_name' 3 | VITEPRESS_ALGOLIA_APP_ID='app_id' 4 | VITEPRESS_ALGOLIA_API_KEY='api_key' 5 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/.nojekyll: -------------------------------------------------------------------------------- 1 | TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. -------------------------------------------------------------------------------- /packages/lib/src/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module types 3 | * @category Types 4 | */ 5 | 6 | export * from '@/api/types' 7 | export * from '@/utils/types' 8 | 9 | export {} 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/index.md: -------------------------------------------------------------------------------- 1 | @shaggytools/nhtsa-api-wrapper / [Exports](modules.md) 2 | 3 | ::: tip :bulb: Auto-generated By TypeDoc from package source code 4 | ::: 5 | 6 | 7 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "baseBranches": ["next"], 4 | "extends": ["config:base"], 5 | "labels": ["dependencies"], 6 | "prHourlyLimit": 0 7 | } 8 | -------------------------------------------------------------------------------- /packages/lib/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "esnext", 5 | "moduleResolution": "node" 6 | }, 7 | "include": [ 8 | "./vite.config.ts" 9 | ] 10 | } -------------------------------------------------------------------------------- /apps/docs/.vitepress/theme/styles/index.scss: -------------------------------------------------------------------------------- 1 | @import './fonts.scss'; 2 | @import './vars.scss'; 3 | @import './colors.scss'; 4 | @import './scrollbar.scss'; 5 | 6 | @import './nav.scss'; 7 | @import './home.scss'; 8 | @import './content.scss'; 9 | -------------------------------------------------------------------------------- /apps/docs/.vitepress/theme/styles/vars.scss: -------------------------------------------------------------------------------- 1 | // adapted from https://github.com/stackblitz/docs/blob/main/.vitepress/theme/styles/vars.scss 2 | 3 | // Breakpoints 4 | $bp-small: 500px; 5 | $bp-medium: 768px; 6 | $bp-large: 960px; 7 | $bp-xlarge: 1444px; 8 | -------------------------------------------------------------------------------- /packages/lib/.vitest/setup.ts: -------------------------------------------------------------------------------- 1 | import createFetchMock from 'vitest-fetch-mock' 2 | import { vi } from 'vitest' 3 | 4 | const fetchMocker = createFetchMock(vi) 5 | 6 | // sets globalThis.fetch and globalThis.fetchMock to our mocked version 7 | fetchMocker.enableMocks() 8 | -------------------------------------------------------------------------------- /config/tsconfig/vitepress.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "display": "Vite-Library-Mode", 4 | "extends": "./vite-library.json", 5 | "compilerOptions": { 6 | "jsx": "preserve", 7 | "preserveSymlinks": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /apps/docs/README.md: -------------------------------------------------------------------------------- 1 | # Documentation for the `@shaggytools/nhtsa-api-wrapper` Package 2 | 3 | Built With: 4 | 5 | - Vitepress 6 | 7 | Contains the source code for the `@shaggytools/nhtsa-api-wrapper` documentation. 8 | 9 | See it live at [vpic.shaggytech.com](vpic.shaggytech.com) 10 | -------------------------------------------------------------------------------- /vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "cleanUrls": true, 3 | "headers": [ 4 | { 5 | "source": "/assets/(.*)", 6 | "headers": [ 7 | { 8 | "key": "Cache-Control", 9 | "value": "max-age=31536000, immutable" 10 | } 11 | ] 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /config/prettier-config/prettier-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true, 4 | "trailingComma": "es5", 5 | "overrides": [ 6 | { 7 | "files": ["**/*.md/*.js", "**/*.md/*.ts"], 8 | "options": { 9 | "trailingComma": "es5" 10 | } 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /config/tsconfig/react-library.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "display": "React Library", 4 | "extends": "./base.json", 5 | "compilerOptions": { 6 | "jsx": "react-jsx", 7 | "lib": ["ES2015"], 8 | "module": "ESNext", 9 | "target": "es6" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /config/prettier-config/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "prettier-config", 3 | "version": "0.0.1", 4 | "description": "Internal shared prettier config for the @shaggytools/nhtsa-api-wrapper monorepo", 5 | "private": true, 6 | "main": "prettier-config.json", 7 | "devDependencies": { 8 | "prettier": "2.8.8" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/simple-examples/nhtsa-test.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* eslint-disable no-undef */ 3 | /* eslint-disable no-console */ 4 | 5 | import { DecodeVin } from "../../packages/lib/dist/nhtsa-api-wrapper.mjs"; 6 | 7 | const results = await DecodeVin("3VWCK21C92M452103").catch((err) => err); 8 | 9 | console.log(JSON.stringify(results)); 10 | -------------------------------------------------------------------------------- /apps/docs/.vitepress/theme/styles/fonts.scss: -------------------------------------------------------------------------------- 1 | :root { 2 | --vp-font-family-base: 'Inter', apple-system, BlinkMacSystemFont, 'Segoe UI', 3 | Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 4 | 'Helvetica Neue', sans-serif; 5 | --vp-font-family-mono: 'IBM Plex Mono', source-code-pro, Menlo, Monaco, 6 | Consolas, 'Courier New', monospace; 7 | } 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | This monorepo contains a CHANGELOG for the following folders: 4 | 5 | - [/packages/lib - @shaggytools/nhtsa-api-wrapper CHANGELOG](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/CHANGELOG.md) 6 | 7 | - [/apps/docs - Documentation CHANGELOG](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/apps/docs/CHANGELOG.md) -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json", 3 | "changelog": "@changesets/cli/changelog", 4 | "commit": false, 5 | "fixed": [], 6 | "linked": [["@shaggytools/nhtsa-api-wrapper", "docs"]], 7 | "access": "public", 8 | "baseBranch": "main", 9 | "updateInternalDependencies": "patch", 10 | "ignore": [] 11 | } 12 | -------------------------------------------------------------------------------- /apps/docs/src/utils/index.md: -------------------------------------------------------------------------------- 1 | # Utility Functions 2 | 3 | --- 4 | 5 | This package exports a number of helper functions for working with VINs and the VPIC API. 6 | 7 | - [isValidVin](./is-valid-vin) - function for offline VIN validation 8 | - [useNHTSA](./use-nhtsa) - composable function returning useful helper functions 9 | 10 | 11 | -------------------------------------------------------------------------------- /config/typedoc-config/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "typedoc-config", 3 | "version": "0.0.1", 4 | "description": "Internal shared typedoc-config for the @shaggytools/nhtsa-api-wrapper monorepo", 5 | "private": true, 6 | "main": "typedoc-config.js", 7 | "devDependencies": { 8 | "typedoc": "0.24.7", 9 | "typedoc-plugin-markdown": "3.15.3", 10 | "typescript": "5.0.4" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/lib/.vitest/helpers.ts: -------------------------------------------------------------------------------- 1 | export function createMockResponse( 2 | data: object, 3 | options: Partial = {} 4 | ): Response { 5 | return { 6 | json: () => new Promise((resolve) => resolve(data)), 7 | headers: new Headers({ 'Content-Type': 'application/json' }), 8 | ok: true, 9 | status: 200, 10 | redirected: false, 11 | ...options, 12 | } as Response 13 | } 14 | -------------------------------------------------------------------------------- /packages/README.md: -------------------------------------------------------------------------------- 1 | # `packages` - folder for the `@shaggytools/nhtsa-api-wrapper mono-repo` 2 | 3 | This folder contains the packages in the `@shaggytools/nhtsa-api-wrapper` mono-repo. 4 | 5 | ## Contents 6 | 7 | ### `packages/lib` 8 | 9 | Contains the source code for the `@shaggytools/nhtsa-api-wrapper` library. 10 | 11 | - published to [NPM](https://www.npmjs.com/package/@shaggytools/nhtsa-api-wrapper) 12 | -------------------------------------------------------------------------------- /packages/lib/src/utils/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module utils 3 | * @category Utility Functions 4 | */ 5 | 6 | export { catchInvalidArguments, validateArgument } from './argHandler' 7 | export { handleError, isError, rejectWithError } from './errorHandler' 8 | export { getTypeof } from './getTypeof' 9 | export { isValidVin } from './isValidVin' 10 | export { createQueryString, encodeQueryStringParams } from './queryString' 11 | -------------------------------------------------------------------------------- /config/README.md: -------------------------------------------------------------------------------- 1 | # Shared Configuration folder for the @shaggytools/nhtsa-api-wrapper monorepo 2 | 3 | ## Contents 4 | 5 | ### `config/eslint-config-custom` 6 | 7 | Shared Eslint configuration 8 | 9 | ### `config/prettier-config` 10 | 11 | Shared Prettier configuration 12 | 13 | ### `config/tsconfig` 14 | 15 | Shared Typescript configuration 16 | 17 | ### `config/typedoc-config` 18 | 19 | Shared Typedoc configuration 20 | -------------------------------------------------------------------------------- /config/tsconfig/vite-library.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "display": "Vite-Library-Mode", 4 | "extends": "./base.json", 5 | "compilerOptions": { 6 | "allowJs": true, 7 | "lib": ["esnext", "dom", "dom.iterable"], 8 | "module": "esnext", 9 | "noImplicitReturns": true, 10 | "resolveJsonModule": true, 11 | "target": "esnext", 12 | "useDefineForClassFields": true 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/simple-examples/nhtsa-test.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* eslint-disable no-undef */ 3 | /* eslint-disable no-console */ 4 | 5 | import { DecodeVin } from "../../packages/lib/dist/nhtsa-api-wrapper.mjs"; 6 | 7 | async function testApi() { 8 | // eslint-disable-next-line @typescript-eslint/no-var-requires 9 | const result = await DecodeVin("3VWCK21C92M452103"); 10 | console.log(result); 11 | return result; 12 | } 13 | 14 | testApi(); 15 | -------------------------------------------------------------------------------- /examples/simple-examples/nhtsa-test.cjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* eslint-disable no-undef */ 3 | /* eslint-disable no-console */ 4 | 5 | async function testApi() { 6 | // eslint-disable-next-line @typescript-eslint/no-var-requires 7 | const nhsta = await require("../../packages/lib/dist/nhtsa-api-wrapper.cjs"); 8 | const result = await nhsta.DecodeVin("3VWCK21C92M452103", false); 9 | console.log(result); 10 | return result; 11 | } 12 | 13 | testApi(); 14 | -------------------------------------------------------------------------------- /config/tsconfig/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tsconfig", 3 | "version": "0.0.1", 4 | "description": "Internal shared typescript configs for the @shaggytools/nhtsa-api-wrapper monorepo", 5 | "private": true, 6 | "files": [ 7 | "base.json", 8 | "library.json", 9 | "nextjs.json", 10 | "react-library.json", 11 | "vite-library.json", 12 | "vite-press.json" 13 | ], 14 | "dependencies": { 15 | "@types/node": "18.15.11" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.github/workflows/setup/action.yaml: -------------------------------------------------------------------------------- 1 | name: setup 2 | description: "Setup (Dependencies, Nodejs)" 3 | 4 | runs: 5 | using: "composite" 6 | steps: 7 | - name: Install pnpm 8 | uses: pnpm/action-setup@v2.2.4 9 | 10 | - name: Setup Node.js environment 11 | uses: actions/setup-node@v3 12 | with: 13 | node-version: 18 14 | cache: "pnpm" 15 | 16 | - name: Install dependencies 17 | shell: bash 18 | run: pnpm install 19 | -------------------------------------------------------------------------------- /packages/lib/.vitest/data.ts: -------------------------------------------------------------------------------- 1 | export const mockResults = { 2 | Count: 1, 3 | Message: 'Results returned successfully', 4 | Results: [ 5 | { 6 | VIN: '5UXWX7C5*BA', 7 | VehicleType: 'Passenger Car', 8 | ModelYear: 2011, 9 | }, 10 | ], 11 | SearchCriteria: '5UXWX7C5*BA', 12 | } 13 | 14 | export const mockEmptyResults = { 15 | Count: 0, 16 | Message: 'Results returned successfully', 17 | Results: [], 18 | SearchCriteria: '', 19 | } 20 | -------------------------------------------------------------------------------- /examples/simple-examples/nhtsa-test-umd-cjs.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* eslint-disable no-undef */ 3 | /* eslint-disable no-console */ 4 | 5 | import nhtsa from '../../dist/nhtsa-api-wrapper.umd.cjs' 6 | 7 | const decoderTest = async () => { 8 | const { Results } = await nhtsa 9 | .DecodeVin('3VWCK21C92M452103') 10 | .catch((err) => err) 11 | 12 | return Results 13 | } 14 | 15 | const results = await decoderTest() 16 | 17 | console.log(JSON.stringify(results)) 18 | -------------------------------------------------------------------------------- /packages/lib/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "extends": "tsconfig/vite-library.json", 4 | "compilerOptions": { 5 | "paths": { 6 | "@/*": [ 7 | "./src/*" 8 | ], 9 | ".vitest/*": [ 10 | "./.vitest/*" 11 | ] 12 | } 13 | }, 14 | "include": [ 15 | "src/**/*.ts", 16 | "src/**/*.d.ts" 17 | ], 18 | "references": [ 19 | { 20 | "path": "./tsconfig.node.json" 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /apps/docs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "extends": "tsconfig/vitepress.json", 4 | "compilerOptions": { 5 | "baseUrl": ".", 6 | "types": [ 7 | "@types/node", 8 | "vite-plugin-pwa/client" 9 | ] 10 | }, 11 | "include": [ 12 | "src/**/*.ts", 13 | "src/**/*.d.ts", 14 | ".vitepress/**/*.ts", 15 | ".vitepress/**/*.vue" 16 | ], 17 | "exclude": [ 18 | "cache", 19 | "dist", 20 | "node_modules" 21 | ] 22 | } -------------------------------------------------------------------------------- /apps/README.md: -------------------------------------------------------------------------------- 1 | # apps folder for the @shaggytools/nhtsa-api-wrapper mono-repo 2 | 3 | # `apps` - folder for the `@shaggytools/nhtsa-api-wrapper mono-repo` 4 | 5 | This folder contains the source code for documentation and examples sites. 6 | 7 | Apps are published to GitHub Pages, Vercel, Netlify, etc. 8 | 9 | ## Contents 10 | 11 | ### `apps/docs` 12 | 13 | Contains the source code for the `@shaggytools/nhtsa-api-wrapper` documentation. 14 | 15 | See it live at [vpic.shaggytech.com](vpic.shaggytech.com) 16 | -------------------------------------------------------------------------------- /packages/lib/.typedoc/typedoc.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires */ 2 | require('typedoc-config') 3 | const path = require('path') 4 | 5 | const cwd = process.cwd() 6 | const outDir = '../../apps/docs/src/typedoc' 7 | 8 | const out = path.join(cwd, outDir) 9 | 10 | /** @type {import('typedoc').TypeDocOptions} */ 11 | module.exports = { 12 | extends: 'typedoc-config', 13 | out, 14 | // typedoc-plugin-markdown options 15 | entryDocument: './index.md', 16 | readme: './README.md', 17 | } 18 | -------------------------------------------------------------------------------- /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /apps/docs/src/parts/package-exports-utility-functions.md: -------------------------------------------------------------------------------- 1 | ## Exported Utility Functions 2 | 3 | The following demonstrates how to import all of the VPIC utility functions from this package. 4 | 5 | ::: tip :bulb: TIP 6 | Although they are all imported at once in this example, you should import only the functions you are 7 | using. 8 | ::: 9 | 10 | ```javascript 11 | import { 12 | isValidVin, // function for offline VIN validation 13 | useNHTSA, // composable function returning helper functions for the VPIC API 14 | } from '@shaggytools/nhtsa-api-wrapper' 15 | ``` 16 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. 3 | // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp 4 | // List of extensions which should be recommended for users of this workspace. 5 | "recommendations": [ 6 | "dbaeumer.vscode-eslint", 7 | "rvest.vs-code-prettier-eslint", 8 | "zixuanchen.vitest-explorer" 9 | ], 10 | // List of extensions recommended by VS Code that should not be recommended for users of this workspace. 11 | "unwantedRecommendations": [] 12 | } -------------------------------------------------------------------------------- /apps/docs/.vitepress/theme/index.ts: -------------------------------------------------------------------------------- 1 | import { h } from 'vue' 2 | import { Theme } from 'vitepress' 3 | import DefaultTheme from 'vitepress/theme' 4 | import RegisterSW from './components/RegisterSW.vue' 5 | 6 | import './styles/index.scss' 7 | 8 | const CustomTheme: Theme = { 9 | ...DefaultTheme, 10 | Layout() { 11 | return h(DefaultTheme.Layout, null, { 12 | 'layout-bottom': () => h(RegisterSW), 13 | }) 14 | }, 15 | enhanceApp(ctx) { 16 | // register your custom global components 17 | ctx.app.component('MyGlobalComponent' /* ... */) 18 | }, 19 | } 20 | 21 | export default CustomTheme 22 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.defaultFormatter": "rvest.vs-code-prettier-eslint", 3 | "editor.codeActionsOnSave": { 4 | "source.fixAll": true, 5 | "source.fixAll.eslint": true 6 | }, 7 | "editor.formatOnPaste": false, // required 8 | "editor.formatOnType": false, // required 9 | "editor.formatOnSave": true, // optional 10 | "editor.formatOnSaveMode": "file", // required to format on save 11 | // "files.autoSave": "onFocusChange" // optional but recommended 12 | // maybe required for eslint to work in monorepo? 13 | "eslint.workingDirectories": [ 14 | { 15 | "mode": "auto" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /turbo.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://turbo.build/schema.json", 3 | "pipeline": { 4 | "build": { 5 | "dependsOn": ["^build"], 6 | "outputs": ["dist/**", "**/.vitepress/dist/**"] 7 | }, 8 | "lint": { 9 | "outputs": [] 10 | }, 11 | "lint:fix": { 12 | "outputs": [] 13 | }, 14 | "format": { 15 | "cache": false, 16 | "dependsOn": ["^lint"] 17 | }, 18 | "dev": { 19 | "cache": false 20 | }, 21 | "test": { 22 | "outputs": [] 23 | }, 24 | "coverage": { 25 | "outputs": [] 26 | }, 27 | "clean": { 28 | "outputs": [] 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /config/eslint-config-custom/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-config-custom", 3 | "version": "0.0.1", 4 | "description": "Internal shared eslint-config for the @shaggytools/nhtsa-api-wrapper monorepo", 5 | "private": true, 6 | "main": "eslint-config.js", 7 | "dependencies": { 8 | "@typescript-eslint/eslint-plugin": "5.59.7", 9 | "@typescript-eslint/parser": "5.59.7", 10 | "eslint": "8.41.0", 11 | "eslint-config-prettier": "8.8.0", 12 | "eslint-plugin-markdown": "3.0.0", 13 | "eslint-plugin-prettier": "4.2.1", 14 | "prettier": "2.8.8" 15 | }, 16 | "devDependencies": { 17 | "typescript": "5.0.4" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /config/tsconfig/base.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "display": "Base", 4 | "compilerOptions": { 5 | "composite": false, 6 | "declaration": true, 7 | "declarationMap": true, 8 | "esModuleInterop": true, 9 | "forceConsistentCasingInFileNames": true, 10 | "inlineSources": false, 11 | "isolatedModules": true, 12 | "moduleResolution": "node", 13 | "noUnusedLocals": false, 14 | "noUnusedParameters": false, 15 | "preserveWatchOutput": true, 16 | "resolveJsonModule": true, 17 | "skipLibCheck": true, 18 | "strict": true 19 | }, 20 | "exclude": ["node_modules"] 21 | } 22 | -------------------------------------------------------------------------------- /config/tsconfig/nextjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "display": "Next.js", 4 | "extends": "./base.json", 5 | "compilerOptions": { 6 | "target": "es5", 7 | "lib": ["dom", "dom.iterable", "esnext"], 8 | "allowJs": true, 9 | "skipLibCheck": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "noEmit": true, 13 | "incremental": true, 14 | "esModuleInterop": true, 15 | "module": "esnext", 16 | "resolveJsonModule": true, 17 | "isolatedModules": true, 18 | "jsx": "preserve" 19 | }, 20 | "include": ["src", "next-env.d.ts"], 21 | "exclude": ["node_modules"] 22 | } 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /config/typedoc-config/typedoc-config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | 3 | const cwd = process.cwd(); 4 | const entryPoint = path.join(cwd, "src"); 5 | 6 | const navigationLinks = { 7 | Source: "https://github.com/shaggytech/nhtsa-api-wrapper", 8 | "VPIC API": "https://vpic.nhtsa.dot.gov/api/", 9 | }; 10 | 11 | /** @type {import('typedoc').TypeDocOptions} */ 12 | module.exports = { 13 | entryPoints: [entryPoint], 14 | entryPointStrategy: "expand", 15 | exclude: ["**/*+(.spec|.e2e|.test|vite-env.d).ts"], 16 | gitRevision: "main", 17 | hideGenerator: true, 18 | includeVersion: true, 19 | navigationLinks, 20 | plugin: ["typedoc-plugin-markdown"], 21 | searchInComments: true, 22 | sort: "alphabetical", 23 | }; 24 | -------------------------------------------------------------------------------- /packages/lib/src/api/README.md: -------------------------------------------------------------------------------- 1 | # /api 2 | 3 | ## `/api` exports the following: 4 | 5 | - [useNHTSA](#useNHTSA) - a composable function that returns an object containing methods for making 6 | HTTP requests to the NHTSA API. The returned functions are documented in the 7 | [Package Documentation](https://www.shaggytech.com/nhtsa-api-wrapper) 8 | 9 | - `/api/endpoints` contains all 24 helper functions, one for each endpoint 10 | (DecodeVin, GetAllMakes, etc). 11 | 12 | - `/api/types` contains all the types used by the NHTSA API. 13 | - each endpoint response type is the endpoint name appended by `Results`, 14 | - `Results`, such as `DecodeVinResults` 15 | - see documentation of each endpoint for more details. 16 | -------------------------------------------------------------------------------- /.github/workflows/coverage.yml: -------------------------------------------------------------------------------- 1 | name: Upload Test Coverage 2 | 3 | on: 4 | push: 5 | 6 | jobs: 7 | upload-test-coverage: 8 | name: Test and Upload Coverage 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v3 14 | 15 | - name: Setup 16 | uses: ./.github/workflows/setup 17 | 18 | - name: Test 19 | run: pnpm coverage 20 | 21 | - name: Upload Coverage 22 | uses: codecov/codecov-action@v3 23 | with: 24 | token: ${{ secrets.CODECOV_TOKEN }} # don't add this token to PUBLIC repos or action will fail 25 | files: ./packages/lib/coverage/coverage-final.json 26 | name: "Upload Test Coverage" # optional 27 | fail_ci_if_error: true # optional (default = false) 28 | -------------------------------------------------------------------------------- /packages/lib/src/api/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module api/types 3 | * @category Types 4 | */ 5 | 6 | export * from './endpoints/types' 7 | export type { CreateUrlOptions } from './useNHTSA' 8 | 9 | /** 10 | * Response data returned from the NHTSA VPIC API. `Results` key will be an array of objects of type "T" 11 | */ 12 | export type NhtsaResponse = { 13 | /** The number of items returned in the Results object. Will = 0 if no Results*/ 14 | Count: number 15 | /** A message describing the Results. If Count is 0 check the Message for helpful info */ 16 | Message: string 17 | /** An array of objects returned by NHTSA VPIC API, specific to each individual API Action. */ 18 | Results: Array 19 | /** Search terms (VIN, WMI, etc) used in the request URL. */ 20 | SearchCriteria: string | null 21 | } 22 | 23 | export {} 24 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/constants.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / constants 2 | 3 | # Module: constants 4 | 5 | ## Table of contents 6 | 7 | ### Variables 8 | 9 | - [NHTSA_BASE_URL](constants.md#nhtsa_base_url) 10 | - [NHTSA_RESPONSE_FORMAT](constants.md#nhtsa_response_format) 11 | 12 | ## Variables 13 | 14 | ### NHTSA_BASE_URL 15 | 16 | • `Const` **NHTSA_BASE_URL**: `"https://vpic.nhtsa.dot.gov/api/vehicles"` 17 | 18 | #### Defined in 19 | 20 | [constants.ts:1](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/constants.ts#L1) 21 | 22 | --- 23 | 24 | ### NHTSA_RESPONSE_FORMAT 25 | 26 | • `Const` **NHTSA_RESPONSE_FORMAT**: `"json"` 27 | 28 | #### Defined in 29 | 30 | [constants.ts:2](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/constants.ts#L2) 31 | -------------------------------------------------------------------------------- /packages/lib/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | DecodeVin, 3 | DecodeVinExtended, 4 | DecodeVinValues, 5 | DecodeVinValuesBatch, 6 | DecodeVinValuesExtended, 7 | DecodeWMI, 8 | GetAllMakes, 9 | GetAllManufacturers, 10 | GetCanadianVehicleSpecifications, 11 | GetEquipmentPlantCodes, 12 | GetMakeForManufacturer, 13 | GetMakesForManufacturerAndYear, 14 | GetMakesForVehicleType, 15 | GetManufacturerDetails, 16 | GetModelsForMake, 17 | GetModelsForMakeId, 18 | GetModelsForMakeIdYear, 19 | GetModelsForMakeYear, 20 | GetParts, 21 | GetVehicleTypesForMake, 22 | GetVehicleTypesForMakeId, 23 | GetVehicleVariableList, 24 | GetVehicleVariableValuesList, 25 | GetWMIsForManufacturer, 26 | useNHTSA, 27 | } from '@/api' 28 | 29 | export { createQueryString, encodeQueryStringParams, isValidVin } from '@/utils' 30 | 31 | export * from '@/types' 32 | -------------------------------------------------------------------------------- /apps/docs/.vitepress/theme/styles/scrollbar.scss: -------------------------------------------------------------------------------- 1 | // scrollbar 2 | :root { 3 | scroll-padding-top: calc(var(--vp-nav-height-desktop) + 30px); 4 | } 5 | 6 | ::-webkit-scrollbar { 7 | width: 12px; 8 | } 9 | 10 | ::-webkit-scrollbar-track { 11 | background: rgb(166, 166, 166); 12 | } 13 | 14 | ::-webkit-scrollbar-thumb { 15 | border: 2px solid rgb(141, 141, 141); 16 | border-radius: 9999px; 17 | background-color: rgb(57, 57, 57); 18 | } 19 | 20 | ::-webkit-scrollbar-thumb:hover { 21 | background-color: rgb(41, 41, 41); 22 | } 23 | 24 | // scrollbar dark mode 25 | html.dark { 26 | ::-webkit-scrollbar-track { 27 | background: rgb(7, 11, 21); 28 | } 29 | 30 | ::-webkit-scrollbar-thumb { 31 | border-color: rgb(12, 14, 30); 32 | background-color: rgb(53, 53, 53); 33 | } 34 | 35 | ::-webkit-scrollbar-thumb:hover { 36 | background-color: rgb(81, 81, 81); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /apps/docs/.vitepress/theme/styles/home.scss: -------------------------------------------------------------------------------- 1 | // -------------------------------- 2 | // -- Home page 3 | 4 | .VPHero.VPHomeHero { 5 | background-color: var(--vp-c-bg-alt); 6 | padding: calc(var(--vp-nav-height) + var(--vp-layout-top-height, 0px) + 60px) 7 | 64px 64px; 8 | 9 | .container .main { 10 | display: flex; 11 | flex-direction: column; 12 | gap: 20px; 13 | 14 | .name { 15 | line-height: 36px; 16 | font-size: 32px; 17 | } 18 | } 19 | } 20 | 21 | .VPFeatures.VPHomeFeatures { 22 | padding-top: 48px; 23 | 24 | .container .items { 25 | row-gap: 16px; 26 | 27 | .item span { 28 | border: 2px solid var(--vp-c-bg-alt); 29 | box-shadow: 0 2px 4px 0 var(--vp-c-bg-alt); 30 | } 31 | } 32 | } 33 | 34 | @media (min-width: $bp-large) { 35 | .VPHero.VPHomeHero { 36 | .container .main { 37 | padding-left: 48px; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /packages/lib/src/utils/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module utils/types 3 | * @category Types 4 | */ 5 | 6 | export type { IArgToValidate } from './argHandler' 7 | 8 | export type { 9 | QueryStringParams, 10 | QueryStringParamsEncoded, 11 | QueryStringTypes, 12 | } from './queryString' 13 | 14 | /** 15 | * Require at least one of a set of properties in an object 16 | * https://stackoverflow.com/a/49725198 17 | */ 18 | export type AtLeastOne = { 19 | [P in R]-?: Required> & Partial> 20 | }[R] 21 | 22 | /** 23 | * Require only one of a set of properties in an object 24 | * https://stackoverflow.com/a/49725198 25 | */ 26 | export type RequireOnlyOne = Omit & 27 | { 28 | [K in keyof Required]: Required> & 29 | Partial, undefined>> 30 | }[Keys] 31 | 32 | export {} 33 | -------------------------------------------------------------------------------- /apps/docs/src/snippets/endpoints/get-all-makes.ts: -------------------------------------------------------------------------------- 1 | // #region type-results 2 | type GetAllMakesResults = { 3 | Make_ID: number 4 | Make_Name: string 5 | } 6 | // #endregion type-results 7 | 8 | // #region example-response 9 | // Using GetAllMakes() - Truncated response with 10k+ results 10 | const exampleResponse = { 11 | Count: 10596, 12 | Message: 'Response returned successfully', 13 | Results: [ 14 | { 15 | Make_ID: 11897, 16 | Make_Name: ' MID-TOWN TRAILERS', 17 | }, 18 | { 19 | Make_ID: 4877, 20 | Make_Name: '1/OFF KUSTOMS, LLC', 21 | }, 22 | { 23 | Make_ID: 11257, 24 | Make_Name: '102 IRONWORKS, INC.', 25 | }, 26 | { 27 | Make_ID: 6387, 28 | Make_Name: '17 CREEK ENTERPRISES', 29 | }, 30 | // ...10k+ more results 31 | ], 32 | SearchCriteria: null, 33 | } 34 | // #endregion example-response 35 | 36 | export type { GetAllMakesResults } 37 | export { exampleResponse } 38 | -------------------------------------------------------------------------------- /apps/docs/.vitepress/menu.ts: -------------------------------------------------------------------------------- 1 | import { createRequire } from 'module' 2 | import { sidebarLinks } from './menu-links' 3 | 4 | const require = createRequire(import.meta.url) 5 | const pkg = require('@shaggytools/nhtsa-api-wrapper/package.json') 6 | 7 | function nav() { 8 | return [ 9 | { text: 'Guide', link: '/guide/', activeMatch: '/guide|utils/' }, 10 | { text: 'API', link: '/api/', activeMatch: '/api/' }, 11 | { text: 'Typedocs', link: '/typedoc/', activeMatch: '/typedoc/' }, 12 | { 13 | text: pkg.version, 14 | items: [ 15 | { 16 | text: 'Changelog', 17 | link: 'https://github.com/shaggytech/nhtsa-api-wrapper/blob/main/CHANGELOG.md', 18 | }, 19 | ], 20 | }, 21 | ] 22 | } 23 | 24 | function sidebar() { 25 | return { 26 | '/guide/': sidebarLinks(['guide']), 27 | '/utils/': sidebarLinks(['guide']), 28 | '/api/': sidebarLinks(['api']), 29 | '/typedoc/': sidebarLinks(['typedocs']), 30 | } 31 | } 32 | 33 | export { nav, sidebar } 34 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | env: 9 | CI: true 10 | PNPM_CACHE_FOLDER: .pnpm-store 11 | 12 | jobs: 13 | release: 14 | name: Release Pull Request 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Checkout Repo 18 | uses: actions/checkout@v3 19 | 20 | - name: Setup 21 | uses: ./.github/workflows/setup 22 | 23 | - name: Creating .npmrc 24 | run: | 25 | cat << EOF > "$HOME/.npmrc" 26 | //registry.npmjs.org/:_authToken=$NPM_TOKEN 27 | EOF 28 | env: 29 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 30 | 31 | - name: Create and publish versions 32 | uses: changesets/action@v1 33 | with: 34 | version: pnpm ci:version 35 | commit: "chore: update package versions" 36 | title: "chore: update package versions" 37 | publish: pnpm ci:publish 38 | env: 39 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 40 | -------------------------------------------------------------------------------- /packages/lib/src/utils/getTypeof.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module utils/getTypeof 3 | * @category Utility Functions 4 | */ 5 | 6 | /** 7 | * Gets type of `value` using `Object.prototype.toString.call(value)`. 8 | * 9 | * Why? Because `typeof` is not reliable for all types of values. 10 | * 11 | * Object.prototype.toString gives more accurate results in the case someone has used an object wrapper 12 | * for primitive data types such as `new Number()` or `new String()`. 13 | * It will also accurately recognize any Error types, Error, TypeError, etc., as 'error'. 14 | * 15 | * @param {any} value - Any kind of value (string, object, array, function, etc). 16 | * @returns {string} - Type of value, normalized to a lowercase string. 17 | */ 18 | export const getTypeof = (value: unknown): string => { 19 | const toString: string = Object.prototype.toString 20 | .call(value) 21 | .toLowerCase() /* ex: => '[object string]' or '[object array], etc. */ 22 | 23 | /* return only the type, ex: 'string' or 'array' */ 24 | return toString.slice(8, toString.length - 1) 25 | } 26 | -------------------------------------------------------------------------------- /apps/docs/src/snippets/endpoints/decode-wmi.ts: -------------------------------------------------------------------------------- 1 | // #region type-results 2 | type DecodeWMIResults = { 3 | CommonName: string 4 | CreatedOn: string 5 | DateAvailableToPublic: string 6 | Make: string 7 | ManufacturerName: string 8 | ParentCompanyName: string 9 | URL: string 10 | UpdatedOn: string | null 11 | VehicleType: string 12 | } 13 | // #endregion type-results 14 | 15 | // #region example-response 16 | // Using DecodeWMI('WVW') 17 | const exampleResponse = { 18 | Count: 1, 19 | Message: 'Results returned successfully', 20 | Results: [ 21 | { 22 | CommonName: 'Volkswagen', 23 | CreatedOn: '2015-06-01', 24 | DateAvailableToPublic: '2015-01-01', 25 | Make: 'VOLKSWAGEN', 26 | ManufacturerName: 'VOLKSWAGEN AG', 27 | ParentCompanyName: '', 28 | URL: 'volkswagenag.com', 29 | UpdatedOn: '2022-08-08', 30 | VehicleType: 'Passenger Car', 31 | }, 32 | ], 33 | SearchCriteria: 'WMI:WVW', 34 | } 35 | // #endregion example-response 36 | 37 | export type { DecodeWMIResults } 38 | export { exampleResponse } 39 | -------------------------------------------------------------------------------- /apps/docs/src/snippets/endpoints/get-vehicle-types-for-make-id.ts: -------------------------------------------------------------------------------- 1 | // #region type-results 2 | type GetVehicleTypesForMakeIdResults = { 3 | VehicleTypeId: number 4 | VehicleTypeName: string 5 | } 6 | // #endregion type-results 7 | 8 | // #region example-response 9 | // Using GetVehicleTypesForMakeId(449) 10 | const exampleResponse = { 11 | Count: 5, 12 | Message: 'Response returned successfully', 13 | Results: [ 14 | { 15 | VehicleTypeId: 2, 16 | VehicleTypeName: 'Passenger Car', 17 | }, 18 | { 19 | VehicleTypeId: 3, 20 | VehicleTypeName: 'Truck ', 21 | }, 22 | { 23 | VehicleTypeId: 5, 24 | VehicleTypeName: 'Bus', 25 | }, 26 | { 27 | VehicleTypeId: 7, 28 | VehicleTypeName: 'Multipurpose Passenger Vehicle (MPV)', 29 | }, 30 | { 31 | VehicleTypeId: 10, 32 | VehicleTypeName: 'Incomplete Vehicle', 33 | }, 34 | ], 35 | SearchCriteria: 'Make ID: 449', 36 | } 37 | // #endregion example-response 38 | 39 | export type { GetVehicleTypesForMakeIdResults } 40 | export { exampleResponse } 41 | -------------------------------------------------------------------------------- /apps/docs/src/parts/package-exports-endpoint-functions.md: -------------------------------------------------------------------------------- 1 | ## Exported VPIC Endpoint Functions 2 | 3 | The following demonstrates how to import all of the VPIC endpoint functions from this package. 4 | 5 | ::: tip :bulb: TIP 6 | Although they are all imported at once in this example, you should import only the functions you are 7 | using. 8 | ::: 9 | 10 | ```javascript 11 | import { 12 | DecodeVin, 13 | DecodeVinExtended, 14 | DecodeVinValues, 15 | DecodeVinValuesBatch, 16 | DecodeVinValuesExtended, 17 | DecodeWMI, 18 | GetAllMakes, 19 | GetAllManufacturers, 20 | GetCanadianVehicleSpecifications, 21 | GetEquipmentPlantCodes, 22 | GetMakeForManufacturer, 23 | GetMakesForManufacturerAndYear, 24 | GetMakesForVehicleType, 25 | GetManufacturerDetails, 26 | GetModelsForMake, 27 | GetModelsForMakeId, 28 | GetModelsForMakeIdYear, 29 | GetModelsForMakeYear, 30 | GetParts, 31 | GetVehicleTypesForMake, 32 | GetVehicleTypesForMakeId, 33 | GetVehicleVariableList, 34 | GetVehicleVariableValuesList, 35 | GetWMIsForManufacturer, 36 | } from '@shaggytools/nhtsa-api-wrapper' 37 | ``` 38 | -------------------------------------------------------------------------------- /apps/docs/src/snippets/endpoints/get-makes-for-manufacturer-and-year.ts: -------------------------------------------------------------------------------- 1 | // #region type-results 2 | type GetMakesForManufacturerAndYearResults = { 3 | MakeId: number 4 | MakeName: string 5 | MfrId: number 6 | MfrName: string 7 | } 8 | // #endregion type-results 9 | 10 | // #region example-response 11 | // Using GetMakeForManufacturer('honda') 12 | const exampleResponse = { 13 | Count: 3, 14 | Message: 'Response returned successfully', 15 | Results: [ 16 | { 17 | MakeId: 482, 18 | MakeName: 'VOLKSWAGEN', 19 | MfrId: 1148, 20 | MfrName: 'VOLKSWAGEN AG', 21 | }, 22 | { 23 | MakeId: 482, 24 | MakeName: 'VOLKSWAGEN', 25 | MfrId: 16478, 26 | MfrName: 'VOLKSWAGEN DE MEXICO SA DE CV', 27 | }, 28 | { 29 | MakeId: 482, 30 | MakeName: 'VOLKSWAGEN', 31 | MfrId: 1147, 32 | MfrName: 'VOLKSWAGEN GROUP OF AMERICA, INC.', 33 | }, 34 | ], 35 | SearchCriteria: 'Manufacturer : volks, Year: 2020', 36 | } 37 | // #endregion example-response 38 | 39 | export type { GetMakesForManufacturerAndYearResults } 40 | export { exampleResponse } 41 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 - Brandon Eichler - shaggytech.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /config/eslint-config-custom/eslint-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | browser: true, 4 | node: true, 5 | es6: true, 6 | }, 7 | extends: [ 8 | "eslint:recommended", 9 | "plugin:@typescript-eslint/recommended", 10 | "plugin:markdown/recommended", 11 | "prettier", 12 | "plugin:prettier/recommended", 13 | ], 14 | parser: "@typescript-eslint/parser", 15 | plugins: ["@typescript-eslint", "prettier", "markdown"], 16 | overrides: [ 17 | { 18 | // Enable the Markdown processor for all .md files. 19 | files: ["**/*.md"], 20 | processor: "markdown/markdown", 21 | }, 22 | { 23 | // Customize the config for fenced code blocks inside .md files. 24 | files: ["**/*.md/*.js", "**/*.md/*.ts"], 25 | rules: { 26 | "@typescript-eslint/no-var-requires": "off", 27 | "@typescript-eslint/no-unused-vars": "off", 28 | "no-console": "off", 29 | }, 30 | }, 31 | ], 32 | ignorePatterns: [ 33 | "!.vitepress", 34 | "!.vitest", 35 | "!.typedoc", 36 | "cache/", 37 | "coverage/", 38 | "dist/", 39 | "dev/", 40 | "typeDoc/", 41 | ], 42 | // 0 = off, 1 = warn, 2 = error 43 | rules: { 44 | "no-console": 1, 45 | "prettier/prettier": 2, 46 | }, 47 | }; 48 | -------------------------------------------------------------------------------- /apps/docs/src/snippets/endpoints/get-wmis-for-manufacturer.ts: -------------------------------------------------------------------------------- 1 | // #region type-results 2 | type GetWMIsForManufacturerResults = { 3 | Country: string | null 4 | CreatedOn: string 5 | DateAvailableToPublic: string 6 | Id: number 7 | Name: string 8 | UpdatedOn: string 9 | VehicleType: string 10 | WMI: string 11 | } 12 | // #endregion type-results 13 | 14 | // #region example-response 15 | // Using GetWMIsForManufacturer(987, vehicleType: 2) 16 | const exampleResponse = { 17 | Count: 2, 18 | Message: 'Response returned successfully', 19 | Results: [ 20 | { 21 | Country: null, 22 | CreatedOn: '2015-03-26', 23 | DateAvailableToPublic: '2015-01-01', 24 | Id: 987, 25 | Name: 'HONDA MOTOR CO., LTD', 26 | UpdatedOn: '2015-06-04', 27 | VehicleType: 'Passenger Car', 28 | WMI: 'JHM', 29 | }, 30 | { 31 | Country: null, 32 | CreatedOn: '2015-03-27', 33 | DateAvailableToPublic: '2015-01-01', 34 | Id: 987, 35 | Name: 'HONDA MOTOR CO., LTD', 36 | UpdatedOn: null, 37 | VehicleType: 'Passenger Car', 38 | WMI: 'JH4', 39 | }, 40 | ], 41 | SearchCriteria: 'Manufacturer: 987 , VehicleType: 2', 42 | } 43 | // #endregion example-response 44 | 45 | export type { GetWMIsForManufacturerResults } 46 | export { exampleResponse } 47 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/utils_getTypeof.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / utils/getTypeof 2 | 3 | # Module: utils/getTypeof 4 | 5 | ## Table of contents 6 | 7 | ### Functions 8 | 9 | - [getTypeof](utils_getTypeof.md#gettypeof) 10 | 11 | ## Functions 12 | 13 | ### getTypeof 14 | 15 | ▸ **getTypeof**(`value`): `string` 16 | 17 | Gets type of `value` using `Object.prototype.toString.call(value)`. 18 | 19 | Why? Because `typeof` is not reliable for all types of values. 20 | 21 | Object.prototype.toString gives more accurate results in the case someone has used an object wrapper 22 | for primitive data types such as `new Number()` or `new String()`. 23 | It will also accurately recognize any Error types, Error, TypeError, etc., as 'error'. 24 | 25 | #### Parameters 26 | 27 | | Name | Type | Description | 28 | | :------ | :-------- | :-------------------------------------------------------- | 29 | | `value` | `unknown` | Any kind of value (string, object, array, function, etc). | 30 | 31 | #### Returns 32 | 33 | `string` 34 | 35 | - Type of value, normalized to a lowercase string. 36 | 37 | #### Defined in 38 | 39 | [utils/getTypeof.ts:18](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/utils/getTypeof.ts#L18) 40 | -------------------------------------------------------------------------------- /apps/docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docs", 3 | "private": true, 4 | "version": "3.0.4", 5 | "description": "Documentation for @shaggytools/nhtsa-api-wrapper", 6 | "main": "index.js", 7 | "scripts": { 8 | "preinstall": "npx only-allow pnpm", 9 | "dev": "vitepress dev --host", 10 | "build": "vitepress build", 11 | "preview": "vitepress preview", 12 | "lint": "eslint .", 13 | "lint:fix": "eslint --fix", 14 | "format": "prettier --write \"src/**/*.{ts,tsx,md}\"", 15 | "format:typedoc": "prettier --write \"src/typedoc/**/*.md\"", 16 | "clean": "rimraf .vitepress/dist .vitepress/cache .turbo", 17 | "clean:all": "pnpm run clean && rimraf node_modules" 18 | }, 19 | "dependencies": { 20 | "@shaggytools/nhtsa-api-wrapper": "workspace:*", 21 | "vue": "3.3.4" 22 | }, 23 | "devDependencies": { 24 | "@types/node": "18.13.0", 25 | "@vite-pwa/vitepress": "0.0.5", 26 | "dotenv": "16.0.3", 27 | "eslint": "8.41.0", 28 | "eslint-config-custom": "workspace:*", 29 | "prettier": "2.8.8", 30 | "prettier-config": "workspace:*", 31 | "rimraf": "5.0.1", 32 | "sass": "1.62.1", 33 | "sitemap": "7.1.1", 34 | "tsconfig": "workspace:*", 35 | "typescript": "5.0.4", 36 | "vite-plugin-pwa": "0.15.1", 37 | "vitepress": "1.0.0-beta.1", 38 | "workbox-window": "6.6.0" 39 | }, 40 | "eslintConfig": { 41 | "extends": [ 42 | "custom" 43 | ], 44 | "root": true 45 | }, 46 | "prettier": "prettier-config" 47 | } 48 | -------------------------------------------------------------------------------- /apps/docs/.vitepress/head.ts: -------------------------------------------------------------------------------- 1 | import { type HeadConfig } from 'vitepress' 2 | 3 | const getHeadTags = () => { 4 | const tags: HeadConfig[] = [ 5 | // Icons 6 | ['link', { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' }], 7 | ['link', { rel: 'mask-icon', href: '/favicon.svg', color: '#000453ff' }], 8 | [ 9 | 'link', 10 | { rel: 'apple-touch-icon', href: '/pwa-192x192.png', sizes: '192x192' }, 11 | ], 12 | 13 | // Fonts 14 | ['link', { rel: 'dns-prefetch', href: 'https://fonts.gstatic.com' }], 15 | [ 16 | 'link', 17 | { 18 | rel: 'preconnect', 19 | crossorigin: 'anonymous', 20 | href: 'https://fonts.gstatic.com', 21 | }, 22 | ], 23 | [ 24 | 'link', 25 | { 26 | href: 'https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@200;400;500&family=Inter:wght@200;400;500;600', 27 | rel: 'stylesheet', 28 | }, 29 | ], 30 | 31 | // Meta 32 | ['meta', { name: 'author', content: 'Brandon Eichler' }], 33 | ['meta', { name: 'theme-color', content: '#000453ff' }], 34 | [ 35 | 'meta', 36 | { 37 | name: 'keywords', 38 | content: 39 | 'NHTSA, VPIC, VIN, Decoder, API, Wrapper, Javascript, Typescript', 40 | }, 41 | ], 42 | ] 43 | 44 | if (process.env.NODE_ENV === 'production') { 45 | // Vercel Analytics 46 | tags.push(['script', { defer: 'true', src: '/_vercel/insights/script.js' }]) 47 | } 48 | 49 | return tags 50 | } 51 | 52 | export { getHeadTags } 53 | -------------------------------------------------------------------------------- /apps/docs/.vitepress/icons.ts: -------------------------------------------------------------------------------- 1 | export const ICON_NPM2 = ` 2 | 3 | NPM 4 | 5 | 6 | 7 | 8 | 9 | ` 10 | -------------------------------------------------------------------------------- /examples/simple-examples/nhtsa-test-umd.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Testing UMD bundle imports 7 | 8 | 12 | 13 | 14 | 15 | Click to console.log NHTSA.DecodeVin() results 16 | 17 | 18 | 19 | Click to console.log isValidVin() results 20 | 21 | 22 | 23 | 45 | 46 | -------------------------------------------------------------------------------- /packages/lib/src/utils/errorHandler.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module utils/errorHandler 3 | * @category Utility Functions 4 | */ 5 | 6 | import { getTypeof } from '@/utils' 7 | 8 | /** 9 | * Checks if `error` is an instance of any Error type. 10 | * 11 | * @param error - Any type of value 12 | * @returns - True if `error` is an instance of Error, TypeError, etc. 13 | */ 14 | export const isError = (error: unknown): boolean => { 15 | return getTypeof(error) === 'error' 16 | } 17 | 18 | /** 19 | * Handles errors by returning an Error instance. 20 | * Accepts any type of value but will return default error message of `an unknown error occurred` if 21 | * `error` is not an Error type or a message string. 22 | * 23 | * @param error - Any type of value 24 | * @returns - instance of Error with message 25 | */ 26 | export const handleError = (error: unknown): Error => { 27 | let message = 'an unknown error occurred.' 28 | if (isError(error)) { 29 | if (!(error as Error).message) { 30 | ;(error as Error).message = message 31 | } 32 | return error as Error 33 | } 34 | if (getTypeof(error) === 'string') { 35 | message = error as string 36 | } 37 | return Error(message) 38 | } 39 | 40 | /** 41 | * Returns a Promise rejection containing an Error instance. 42 | * Uses {@link handleError} to return a default error message if `error` is 43 | * not an Error type. 44 | * 45 | * @param error - Any type of value 46 | */ 47 | export const rejectWithError = async (error: unknown): Promise => { 48 | return Promise.reject(handleError(error)) 49 | } 50 | -------------------------------------------------------------------------------- /examples/simple-examples/nhtsa-test-iife.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Testing IIFE bundle imports 7 | 8 | 12 | 13 | 14 | 15 | Click to console.log NHTSA.DecodeVin() results 16 | 17 | 18 | 19 | Click to console.log isValidVin() results 20 | 21 | 22 | 23 | 46 | 47 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/utils_isValidVin.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / utils/isValidVin 2 | 3 | # Module: utils/isValidVin 4 | 5 | ## Table of contents 6 | 7 | ### Functions 8 | 9 | - [isValidVin](utils_isValidVin.md#isvalidvin) 10 | 11 | ## Functions 12 | 13 | ### isValidVin 14 | 15 | ▸ **isValidVin**(`vin`): `boolean` 16 | 17 | Provides **offline** validation of Vehicle Identification Numbers (VINs) using the 18 | [VIN Check Algorithm](). 19 | 20 | If you need to test that the algorithm is working correctly, you can use 17 ones `1` as 21 | the VIN and it should return `true` as the result. 22 | 23 | **`Example`** 24 | 25 | Browser via html script tags 26 | 27 | ```ts 28 | const isValid = NHTSA.isValidVin('3VWD07AJ5EM388202') 29 | console.log(isValid) // true 30 | ``` 31 | 32 | **`Example`** 33 | 34 | Imported as a module 35 | 36 | ```ts 37 | import { isValidVin } from '@shaggytools/nhtsa-api-wrapper' 38 | const isValid = isValidVin('3VWD07AJ5EM388202') 39 | console.log(isValid) // true 40 | ``` 41 | 42 | #### Parameters 43 | 44 | | Name | Type | Description | 45 | | :---- | :------- | :----------------------------- | 46 | | `vin` | `string` | Vehicle Identification Number. | 47 | 48 | #### Returns 49 | 50 | `boolean` 51 | 52 | True for a valid VIN, false for an invalid VIN. 53 | 54 | #### Defined in 55 | 56 | [utils/isValidVin.ts:66](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/utils/isValidVin.ts#L66) 57 | -------------------------------------------------------------------------------- /packages/lib/src/utils/__tests__/getTypeof.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | import { getTypeof } from '../getTypeof' 3 | 4 | describe('getTypeof.ts - exports', () => { 5 | it('getTypeof function', () => { 6 | expect(getTypeof).toBeDefined() 7 | expect(getTypeof).toBeInstanceOf(Function) 8 | }) 9 | }) 10 | 11 | describe('getTypeof', () => { 12 | it('it returns correct type', () => { 13 | expect(getTypeof(undefined)).toBe('undefined') 14 | expect(getTypeof(null)).toBe('null') 15 | expect(getTypeof(true)).toBe('boolean') 16 | expect(getTypeof('this is a string')).toBe('string') 17 | expect(getTypeof(() => 'this is a function')).toBe('function') 18 | expect(getTypeof({ an: 'object' })).toBe('object') 19 | expect(getTypeof(['an', 'array'])).toBe('array') 20 | }) 21 | 22 | it('it handles different Error types as type "error"', () => { 23 | const error = new Error('this is an error') 24 | const typeError = new TypeError('this is a type error') 25 | const rangeError = new RangeError('this is a range error') 26 | const referenceError = new ReferenceError('this is a reference error') 27 | const syntaxError = new SyntaxError('this is a syntax error') 28 | const uriError = new URIError('this is a URI error') 29 | 30 | expect(getTypeof(error)).toBe('error') 31 | expect(getTypeof(typeError)).toBe('error') 32 | expect(getTypeof(rangeError)).toBe('error') 33 | expect(getTypeof(referenceError)).toBe('error') 34 | expect(getTypeof(syntaxError)).toBe('error') 35 | expect(getTypeof(uriError)).toBe('error') 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | ### modified from 2 | ### https://raw.github.com/github/gitignore/8edb8a95c4c4b3dce71a378aaaf89275510b9cef/Node.gitignore 3 | 4 | ### Package Specific 5 | dev/ 6 | distDev/ 7 | docsDev/ 8 | 9 | ### Vitepress 10 | **/.vitepress/dist/** 11 | **/.vitepress/cache/** 12 | 13 | ### Turbo 14 | .turbo 15 | 16 | ### pnpm 17 | pnpm-debug.log* 18 | pack.tar.gz 19 | 20 | ### Typescript 21 | tsconfig.tsbuildinfo 22 | 23 | ### Service Workers 24 | **/*/sw.* 25 | sw.* 26 | 27 | ### Nuxt 28 | **/nuxt/ 29 | .nuxt 30 | 31 | # Logs 32 | logs 33 | *.log 34 | npm-debug.log* 35 | yarn-debug.log* 36 | yarn-error.log* 37 | 38 | # Runtime data 39 | pids 40 | *.pid 41 | *.seed 42 | *.pid.lock 43 | 44 | # Directory for instrumented libs generated by jscoverage/JSCover 45 | lib-cov 46 | 47 | # Coverage directory used by tools like istanbul 48 | coverage 49 | 50 | # nyc test coverage 51 | .nyc_output 52 | 53 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 54 | .grunt 55 | 56 | # Bower dependency directory (https://bower.io/) 57 | bower_components 58 | 59 | # node-waf configuration 60 | .lock-wscript 61 | 62 | # Compiled binary addons (http://nodejs.org/api/addons.html) 63 | build/Release 64 | 65 | # Dependency directories 66 | node_modules/ 67 | jspm_packages/ 68 | 69 | # Typescript v1 declaration files 70 | typings/ 71 | 72 | # Optional npm cache directory 73 | .npm 74 | 75 | # Optional eslint cache 76 | .eslintcache 77 | 78 | # Optional REPL history 79 | .node_repl_history 80 | 81 | # Output of 'npm pack' 82 | *.tgz 83 | 84 | # Yarn Integrity file 85 | .yarn-integrity 86 | 87 | # dotenv environment variables file 88 | .env -------------------------------------------------------------------------------- /apps/docs/src/api/endpoints/index.md: -------------------------------------------------------------------------------- 1 | # VPIC API Helper Functions 2 | 3 | --- 4 | 5 | There are a total of 24 endpoints available in the VPIC API. Each endpoint returns 6 | a different set of data and has different required inputs. 7 | 8 | ## VPIC API Endpoints 9 | 10 | - [DecodeVin](./decode-vin) 11 | - [DecodeVinExtended](./decode-vin-extended) 12 | - [DecodeVinValues](./decode-vin-values) 13 | - [DecodeVinValuesBatch](./decode-vin-values-batch) 14 | - [DecodeVinValuesExtended](./decode-vin-values-extended) 15 | - [DecodeWMI](./decode-wmi) 16 | - [GetAllMakes](./get-all-makes) 17 | - [GetAllManufacturers](./get-all-manufacturers) 18 | - [GetCanadianVehicleSpecifications](./get-canadian-vehicle-specifications) 19 | - [GetEquipmentPlantCodes](./get-equipment-plant-codes) 20 | - [GetMakeForManufacturer](./get-make-for-manufacturer) 21 | - [GetMakesForManufacturerAndYear](./get-makes-for-manufacturer-and-year) 22 | - [GetMakesForVehicleType](./get-makes-for-vehicle-type) 23 | - [GetManufacturerDetails](./get-manufacturer-details) 24 | - [GetModelsForMake](./get-models-for-make) 25 | - [GetModelsForMakeId](./get-models-for-make-id) 26 | - [GetModelsForMakeIdYear](./get-models-for-make-id-year) 27 | - [GetModelsForMakeYear](./get-models-for-make-year) 28 | - [GetParts](./get-parts) 29 | - [GetVehicleTypesForMake](./get-vehicle-types-for-make) 30 | - [GetVehicleTypesForMakeId](./get-vehicle-types-for-make-id) 31 | - [GetVehicleVariableList](./get-vehicle-variable-list) 32 | - [GetVehicleVariableValuesList](./get-vehicle-variable-values-list) 33 | - [GetWMIsForManufacturer](./get-wmis-for-manufacturer) 34 | 35 | 36 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module api/endpoints 3 | * @category API Endpoints 4 | */ 5 | 6 | export { DecodeVin } from './DecodeVin' 7 | export { DecodeVinExtended } from './DecodeVinExtended' 8 | export { DecodeVinValues } from './DecodeVinValues' 9 | export { DecodeVinValuesBatch } from './DecodeVinValuesBatch' 10 | export { DecodeVinValuesExtended } from './DecodeVinValuesExtended' 11 | export { DecodeWMI } from './DecodeWMI' 12 | export { GetAllMakes } from './GetAllMakes' 13 | export { GetAllManufacturers } from './GetAllManufacturers' 14 | export { GetCanadianVehicleSpecifications } from './GetCanadianVehicleSpecifications' 15 | export { GetEquipmentPlantCodes } from './GetEquipmentPlantCodes' 16 | export { GetMakeForManufacturer } from './GetMakeForManufacturer' 17 | export { GetMakesForManufacturerAndYear } from './GetMakesForManufacturerAndYear' 18 | export { GetMakesForVehicleType } from './GetMakesForVehicleType' 19 | export { GetManufacturerDetails } from './GetManufacturerDetails' 20 | export { GetModelsForMake } from './GetModelsForMake' 21 | export { GetModelsForMakeId } from './GetModelsForMakeId' 22 | export { GetModelsForMakeIdYear } from './GetModelsForMakeIdYear' 23 | export { GetModelsForMakeYear } from './GetModelsForMakeYear' 24 | export { GetParts } from './GetParts' 25 | export { GetVehicleTypesForMake } from './GetVehicleTypesForMake' 26 | export { GetVehicleTypesForMakeId } from './GetVehicleTypesForMakeId' 27 | export { GetVehicleVariableList } from './GetVehicleVariableList' 28 | export { GetVehicleVariableValuesList } from './GetVehicleVariableValuesList' 29 | export { GetWMIsForManufacturer } from './GetWMIsForManufacturer' 30 | -------------------------------------------------------------------------------- /packages/lib/src/utils/__tests__/isValidVin.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | import { isValidVin } from '../isValidVin' 3 | 4 | describe('isValidVin.ts - exports', () => { 5 | it('isValidVin function', () => { 6 | expect(isValidVin).toBeDefined() 7 | expect(isValidVin).toBeInstanceOf(Function) 8 | }) 9 | }) 10 | 11 | describe('isValidVin - utility helper function', () => { 12 | it('it should return true with a valid VIN', () => { 13 | // All zeros 14 | expect(isValidVin('00000000000000000')).toBe(true) 15 | // valid uppercase 16 | expect(isValidVin('3VWD07AJ5EM388202')).toBe(true) 17 | expect(isValidVin('1FMJK2AT1KEA36140')).toBe(true) 18 | expect(isValidVin('5XYZU3LA1EG176607')).toBe(true) 19 | // valid lowercase 20 | expect(isValidVin('3vwd07aj5em388202')).toBe(true) 21 | }) 22 | 23 | it('it should fail with invalid arguments', async () => { 24 | // known invalid VIN 25 | expect(isValidVin('3VWD07AJ5EM388203')).toBe(false) 26 | // VIN too short 27 | expect(isValidVin('3VWD07AJ5EM38820')).toBe(false) 28 | expect(isValidVin('1234567890')).toBe(false) 29 | expect(isValidVin('')).toBe(false) 30 | // invalid check digit (vin[8]) 31 | expect(isValidVin('3VWD07AJAEM388203')).toBe(false) 32 | // check digit is equal to 'X' but vin is invalid 33 | expect(isValidVin('3VWD07AJXEM388203')).toBe(false) 34 | // invalid argument type 35 | expect(isValidVin([] as unknown as string)).toBe(false) 36 | expect(isValidVin({} as unknown as string)).toBe(false) 37 | // missing argument 38 | expect(isValidVin(undefined as unknown as string)).toBe(false) 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### modified from 2 | ### https://raw.github.com/github/gitignore/8edb8a95c4c4b3dce71a378aaaf89275510b9cef/Node.gitignore 3 | 4 | ### Package Specific 5 | dev/ 6 | dist/ 7 | distDev/ 8 | docsDev/ 9 | dev-dist/ 10 | 11 | ### Vitepress 12 | **/.vitepress/dist/** 13 | **/.vitepress/cache/** 14 | 15 | ### Turbo 16 | .turbo 17 | 18 | ### pnpm 19 | pnpm-debug.log* 20 | pack.tar.gz 21 | 22 | ### Typescript 23 | tsconfig.tsbuildinfo 24 | 25 | ### Service Workers 26 | **/*/sw.* 27 | sw.* 28 | 29 | ### Nuxt 30 | **/nuxt/ 31 | .nuxt 32 | 33 | # Logs 34 | logs 35 | *.log 36 | npm-debug.log* 37 | yarn-debug.log* 38 | yarn-error.log* 39 | 40 | # Runtime data 41 | pids 42 | *.pid 43 | *.seed 44 | *.pid.lock 45 | 46 | # Directory for instrumented libs generated by jscoverage/JSCover 47 | lib-cov 48 | 49 | # Coverage directory used by tools like istanbul 50 | coverage 51 | 52 | # nyc test coverage 53 | .nyc_output 54 | 55 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 56 | .grunt 57 | 58 | # Bower dependency directory (https://bower.io/) 59 | bower_components 60 | 61 | # node-waf configuration 62 | .lock-wscript 63 | 64 | # Compiled binary addons (http://nodejs.org/api/addons.html) 65 | build/Release 66 | 67 | # Dependency directories 68 | node_modules/ 69 | jspm_packages/ 70 | 71 | # Typescript v1 declaration files 72 | typings/ 73 | 74 | # Optional npm cache directory 75 | .npm 76 | 77 | # Optional eslint cache 78 | .eslintcache 79 | 80 | # Optional REPL history 81 | .node_repl_history 82 | 83 | # Output of 'npm pack' 84 | *.tgz 85 | 86 | # Yarn Integrity file 87 | .yarn-integrity 88 | 89 | # dotenv environment variables file 90 | .env 91 | .vercel 92 | -------------------------------------------------------------------------------- /apps/docs/src/guide/offline-vin-validation.md: -------------------------------------------------------------------------------- 1 | # Offline VIN Validation 2 | 3 | This package exports an offline VIN validation function called `isValidVin`, that can be used to 4 | validate a VIN without making a network request. 5 | 6 | Useful if you want to validate a VIN to prevent making an unnecessary request to the API with an 7 | invalid VIN that would return no or irrelevant results. 8 | 9 | See the [isValidVin](../utils/is-valid-vin) documentation for more details and explanation of how 10 | this function works. 11 | 12 | --- 13 | 14 | ## Examples 15 | 16 | The following demonstrates how to use `isValidVin` to validate a VIN before making a request to the 17 | VPIC API. 18 | 19 | The helper funtion `isValidVin` returns a boolean value of `true` if the VIN is valid and `false` if 20 | not valid. 21 | 22 | If the VIN is invalid, the function will return early and not make the request, instead logging a 23 | message to the console that the VIN is invalid. 24 | 25 | ```typescript 26 | import { isValidVin, DecodeVinValues } from '@shaggytools/nhtsa-api-wrapper' 27 | 28 | const vin = 'WA1A4AFY2J2008189' 29 | 30 | async function decodeVin(vin: string) { 31 | // if the VIN is not valid, return early and log a message to the console 32 | if (!isValidVin(vin)) { 33 | console.log('Invalid VIN!') 34 | return 35 | } 36 | 37 | return DecodeVinValues(vin) 38 | } 39 | 40 | const response = await decodeVin(vin) 41 | 42 | console.log(response.Results[0]) 43 | ``` 44 | 45 | Some other example usage would include: 46 | 47 | - Validating a VIN before storing it in a database. 48 | - A user enters their VIN into a form input and you want to show an error state if the VIN is 49 | invalid. 50 | -------------------------------------------------------------------------------- /apps/docs/src/snippets/endpoints/get-vehicle-variable-values-list.ts: -------------------------------------------------------------------------------- 1 | // #region type-results 2 | type GetVehicleVariableValuesListResults = { 3 | ElementName: string 4 | Id: number 5 | Name: string 6 | } 7 | // #endregion type-results 8 | 9 | // #region example-response 10 | // Using GetVehicleVariableValuesList('battery type') 11 | const exampleResponse = { 12 | Count: 9, 13 | Message: 'Results returned successfully', 14 | Results: [ 15 | { 16 | ElementName: 'Battery Type', 17 | Id: 1, 18 | Name: 'Lead Acid/Lead', 19 | }, 20 | { 21 | ElementName: 'Battery Type', 22 | Id: 2, 23 | Name: 'Nickel-Metal-Hydride/NiMH', 24 | }, 25 | { 26 | ElementName: 'Battery Type', 27 | Id: 3, 28 | Name: 'Lithium-Ion/Li-Ion', 29 | }, 30 | { 31 | ElementName: 'Battery Type', 32 | Id: 4, 33 | Name: 'Cobalt Dioxide/Cobalt', 34 | }, 35 | { 36 | ElementName: 'Battery Type', 37 | Id: 5, 38 | Name: 'Nickle-Cobalt-Manganese/NCM', 39 | }, 40 | { 41 | ElementName: 'Battery Type', 42 | Id: 6, 43 | Name: 'Nickle-Cobalt-Aluminum/NCA', 44 | }, 45 | { 46 | ElementName: 'Battery Type', 47 | Id: 7, 48 | Name: 'Manganese Oxide Spinel/MnO', 49 | }, 50 | { 51 | ElementName: 'Battery Type', 52 | Id: 8, 53 | Name: 'Iron Phosphate/FePo', 54 | }, 55 | { 56 | ElementName: 'Battery Type', 57 | Id: 9, 58 | Name: 'Silicon', 59 | }, 60 | ], 61 | SearchCriteria: 'Variable:battery type', 62 | } 63 | // #endregion example-response 64 | 65 | export type { GetVehicleVariableValuesListResults } 66 | export { exampleResponse } 67 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/utils.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / utils 2 | 3 | # Module: utils 4 | 5 | ## Table of contents 6 | 7 | ### References 8 | 9 | - [catchInvalidArguments](utils.md#catchinvalidarguments) 10 | - [createQueryString](utils.md#createquerystring) 11 | - [encodeQueryStringParams](utils.md#encodequerystringparams) 12 | - [getTypeof](utils.md#gettypeof) 13 | - [handleError](utils.md#handleerror) 14 | - [isError](utils.md#iserror) 15 | - [isValidVin](utils.md#isvalidvin) 16 | - [rejectWithError](utils.md#rejectwitherror) 17 | - [validateArgument](utils.md#validateargument) 18 | 19 | ## References 20 | 21 | ### catchInvalidArguments 22 | 23 | Re-exports [catchInvalidArguments](utils_argHandler.md#catchinvalidarguments) 24 | 25 | --- 26 | 27 | ### createQueryString 28 | 29 | Re-exports [createQueryString](utils_queryString.md#createquerystring) 30 | 31 | --- 32 | 33 | ### encodeQueryStringParams 34 | 35 | Re-exports [encodeQueryStringParams](utils_queryString.md#encodequerystringparams) 36 | 37 | --- 38 | 39 | ### getTypeof 40 | 41 | Re-exports [getTypeof](utils_getTypeof.md#gettypeof) 42 | 43 | --- 44 | 45 | ### handleError 46 | 47 | Re-exports [handleError](utils_errorHandler.md#handleerror) 48 | 49 | --- 50 | 51 | ### isError 52 | 53 | Re-exports [isError](utils_errorHandler.md#iserror) 54 | 55 | --- 56 | 57 | ### isValidVin 58 | 59 | Re-exports [isValidVin](utils_isValidVin.md#isvalidvin) 60 | 61 | --- 62 | 63 | ### rejectWithError 64 | 65 | Re-exports [rejectWithError](utils_errorHandler.md#rejectwitherror) 66 | 67 | --- 68 | 69 | ### validateArgument 70 | 71 | Re-exports [validateArgument](utils_argHandler.md#validateargument) 72 | -------------------------------------------------------------------------------- /apps/docs/src/utils/is-valid-vin.md: -------------------------------------------------------------------------------- 1 | # isValidVin Utility Function 2 | 3 | ```typescript 4 | const isValidVin: (vin: string) => boolean 5 | ``` 6 | 7 | --- 8 | 9 | Provides **offline** validation of Vehicle Identification Numbers (VINs) using the 10 | [VIN Check Algorithm]() 11 | to validate the VIN. 12 | 13 | `isValidVin` returns a boolean value of `true` if the VIN is valid, or `false` if it is not. 14 | 15 | For an interactive view of how the VIN digit is calculated see the 16 | [VPIC Check Digit Calculator](https://vpic.nhtsa.dot.gov/decoder/CheckDigit/Index/5yj3e1eaxhf000316) 17 | page. 18 | 19 | ::: tip 20 | 21 | You can see implementation of the VIN Check Algorithm in the 22 | [source code](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/73d35828eec1392d2736a979ce874216456fc837/packages/lib/src/utils/isValidVin.ts) 23 | for `isValidVin`. 24 | 25 | ::: 26 | 27 | --- 28 | 29 | ## Usage 30 | 31 | ```typescript 32 | import { isValidVin } from '@shaggytools/nhtsa-api-wrapper' 33 | 34 | const isValid = isValidVin('WA1A4AFY2J2008189') // true 35 | ``` 36 | 37 | If you need to test that the function works, you can use 17 ones `11111111111111111` as a valid 38 | VIN. 39 | 40 | Straight-ones (seventeen consecutive '1's) will suffice the check-digit algorithm. This is because a 41 | value of one, multiplied against 89 (sum of weights), is still 89. And 89 % 11 is 1, the check 42 | digit. This is an easy way to test a vin-check algorithm. 43 | 44 | ```typescript 45 | const isValidStraightOnes = isValidVin('11111111111111111') // true 46 | ``` 47 | 48 | ## Examples 49 | 50 | See the [Offline VIN Validation](/guide/offline-vin-validation#examples) page for examples. 51 | -------------------------------------------------------------------------------- /examples/simple-examples/nhtsa-test-mjs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Testing module imports 7 | 8 | 40 | 41 | 42 | 43 | Click to console.log NHTSA.DecodeWMI() results 44 | 45 | 46 | 47 | Click to console.log isValidVin() results 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/GetAllMakes.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module api/endpoints/GetAllMakes 3 | * @category API Endpoints 4 | */ 5 | 6 | import { useNHTSA } from '@/api' 7 | import { rejectWithError } from '@/utils' 8 | import type { NhtsaResponse } from '@/types' 9 | 10 | /** 11 | * ::: tip :bulb: More Information 12 | * See: [GetAllMakes Documentation](/api/endpoints/get-all-makes) 13 | * ::: 14 | * 15 | * `GetAllMakes` provides a list of all the Makes available in the vPIC Dataset. 16 | * Each object in the `Results` array represents the `Make_ID` and the `Make_Name` of 17 | * an individual vehicle Make. 18 | * 19 | * - FYI there are over 10,000 registered makes in the database! 20 | * 21 | * @param {boolean} [doFetch=true] - Whether to fetch the data or just return the URL 22 | * (default: `true`) 23 | * @returns {(Promise | string>)} - Api Response `object` 24 | * -or- url `string` if `doFetch = false` (default: `true`) 25 | */ 26 | function GetAllMakes(doFetch?: true): Promise> 27 | 28 | function GetAllMakes(doFetch: false): Promise 29 | 30 | /* Implementation */ 31 | async function GetAllMakes( 32 | doFetch = true 33 | ): Promise | string> { 34 | const endpointName = 'GetAllMakes' 35 | 36 | try { 37 | const { get, createCachedUrl, getCachedUrl } = useNHTSA() 38 | 39 | createCachedUrl({ endpointName }) 40 | 41 | if (!doFetch) { 42 | return getCachedUrl() 43 | } else { 44 | return get() 45 | } 46 | } catch (error) { 47 | return rejectWithError(error) 48 | } 49 | } 50 | 51 | export { GetAllMakes } 52 | 53 | /** 54 | * Objects found in the `Results` array of `GetAllMakes` endpoint response. 55 | */ 56 | export type GetAllMakesResults = { 57 | Make_ID: number 58 | Make_Name: string 59 | } 60 | -------------------------------------------------------------------------------- /apps/docs/.vitepress/theme/components/RegisterSW.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | 29 | 30 | 35 | 36 | App ready to work offline 37 | 38 | 43 | Close 44 | 45 | 46 | 47 | 48 | 49 | 74 | -------------------------------------------------------------------------------- /packages/lib/src/utils/__tests__/index.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | import { 3 | catchInvalidArguments, 4 | createQueryString, 5 | encodeQueryStringParams, 6 | getTypeof, 7 | handleError, 8 | isError, 9 | isValidVin, 10 | rejectWithError, 11 | validateArgument, 12 | } from '../' 13 | 14 | describe('utils/index.ts', () => { 15 | it('exports catchInvalidArguments function', () => { 16 | expect(catchInvalidArguments).toBeDefined() 17 | expect(catchInvalidArguments).toBeInstanceOf(Function) 18 | }) 19 | 20 | it('exports createQueryString function', () => { 21 | expect(createQueryString).toBeDefined() 22 | expect(createQueryString).toBeInstanceOf(Function) 23 | }) 24 | 25 | it('exports encodeQueryStringParams function', () => { 26 | expect(encodeQueryStringParams).toBeDefined() 27 | expect(encodeQueryStringParams).toBeInstanceOf(Function) 28 | }) 29 | 30 | it('exports getTypeof function', () => { 31 | expect(getTypeof).toBeDefined() 32 | expect(getTypeof).toBeInstanceOf(Function) 33 | }) 34 | 35 | it('exports handleError function', () => { 36 | expect(handleError).toBeDefined() 37 | expect(handleError).toBeInstanceOf(Function) 38 | }) 39 | 40 | it('exports isError function', () => { 41 | expect(isError).toBeDefined() 42 | expect(isError).toBeInstanceOf(Function) 43 | }) 44 | 45 | it('exports isValidVin function', () => { 46 | expect(isValidVin).toBeDefined() 47 | expect(isValidVin).toBeInstanceOf(Function) 48 | }) 49 | 50 | it('exports rejectWithError function', () => { 51 | expect(rejectWithError).toBeDefined() 52 | expect(rejectWithError).toBeInstanceOf(Function) 53 | }) 54 | 55 | it('exports validateArgument function', () => { 56 | expect(validateArgument).toBeDefined() 57 | expect(validateArgument).toBeInstanceOf(Function) 58 | }) 59 | }) 60 | -------------------------------------------------------------------------------- /apps/docs/src/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: home 3 | 4 | title: '@shaggytools/nhtsa-api-wrapper' 5 | titleTemplate: Javascript Wrapper for the NHTSA VPIC Vehicle Decoding API 6 | description: A thin javascript wrapper around the NHTSA Vehicle Information API (VPIC) to make it easier to use. 7 | lang: en-US 8 | meta: 9 | - name: keywords 10 | content: nhtsa, vpic, api, wrapper, javascript, typescript, types, type hints, code completion, fetch 11 | 12 | hero: 13 | name: '@shaggytools/nhtsa-api-wrapper' 14 | text: Helper Functions for the NHTSA VPIC Vehicle Decoding API 15 | tagline: Easily Decode a VIN, Get Vehicle Models by Make, and many more. 16 | actions: 17 | - theme: brand 18 | text: Learn More 19 | link: /guide/ 20 | - theme: alt 21 | text: VPIC Helper Functions 22 | link: /api/ 23 | 24 | features: 25 | - title: Simplify the VPIC API 26 | details: Does all the heavy lifting for you. Just pass in a VIN and get back a decoded vehicle in JSON format. No query strings, path parameters, or parsing to worry about. 27 | - title: Universal Support 28 | details: Use it client or server side. Works in Node.js versions > 18 and modern browsers out of the box. 29 | - title: BYOF - Bring Your Own Fetch 30 | details: Don't want to polyfill fetch in Node versions < 18? Includes an option to bypass fetching and get back a fully built VPIC URL ready to use how you want. 31 | - title: Tree Shaking 32 | details: Bundled with Vite library mode. Only import what you need, and keep your app size small. Plays nice with bundlers like Webpack and Rollup. 33 | - title: Lightweight 34 | details: Small package size with no polyfills or dependencies in the final bundle. Only 3 kB minified and gzipped. 35 | - title: TypeScript Support 36 | details: Get easy type hints and code completion in your IDE. Written with Typescript support top of mind. Includes type definitions for all methods and VPIC responses. 37 | --- 38 | -------------------------------------------------------------------------------- /packages/lib/vite.config.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | import { resolve } from 'path' 5 | import { defineConfig } from 'vite' 6 | import dts from 'vite-plugin-dts' 7 | import tsconfigPaths from 'vite-tsconfig-paths' 8 | 9 | const packageName = 'nhtsa-api-wrapper' 10 | 11 | const fileName = { 12 | es: `${packageName}.mjs`, 13 | cjs: `${packageName}.cjs`, 14 | umd: `${packageName}.umd.cjs`, 15 | iife: `${packageName}.iife.js`, 16 | } 17 | 18 | const formats = Object.keys(fileName) as Array 19 | 20 | export default defineConfig({ 21 | server: { port: 3000 }, 22 | plugins: [ 23 | tsconfigPaths(), 24 | dts({ 25 | entryRoot: './src', 26 | outputDir: './dist/types', 27 | insertTypesEntry: true, 28 | }), 29 | ], 30 | resolve: { 31 | alias: [ 32 | { 33 | find: '@', 34 | replacement: resolve(__dirname, './src'), 35 | }, 36 | { 37 | find: '.vitest', 38 | replacement: resolve(__dirname, './.vitest'), 39 | }, 40 | ], 41 | }, 42 | build: { 43 | outDir: 'dist', 44 | lib: { 45 | entry: resolve(__dirname, 'src/index.ts'), 46 | name: 'NHTSA', 47 | formats, 48 | fileName: (format) => fileName[format], 49 | }, 50 | sourcemap: true, 51 | reportCompressedSize: true, 52 | rollupOptions: { 53 | output: { 54 | sourcemap: true, 55 | }, 56 | }, 57 | }, 58 | test: { 59 | environment: 'node', 60 | globals: true, 61 | watch: false, // turned off for CI/CD runs 62 | coverage: { 63 | provider: 'c8', 64 | all: true, 65 | src: ['./src'], 66 | exclude: [ 67 | '**/*/types.ts', 68 | '**/__tests__/**/*', 69 | '**/.vitest/**/*', 70 | 'vite-env.d.ts', 71 | 'global.d.ts', 72 | ], 73 | }, 74 | setupFiles: ['./.vitest/setup.ts'], 75 | }, 76 | }) 77 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/GetVehicleVariableList.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module api/endpoints/GetVehicleVariableList 3 | * @category API Endpoints 4 | */ 5 | 6 | import { useNHTSA } from '@/api' 7 | import { rejectWithError } from '@/utils' 8 | import type { NhtsaResponse } from '@/types' 9 | 10 | /** 11 | * ::: tip :bulb: More Information 12 | * See: [GetVehicleVariableList Documentation](/api/endpoints/get-vehicle-variable-list) 13 | * ::: 14 | * 15 | * `GetVehicleVariableList` provides a list of all the Vehicle related variables that are in the 16 | * vPIC dataset. Information on the name, description and the type of the variable is provided. 17 | * 18 | * @param {boolean} [doFetch=true] - Whether to fetch the data or just return the URL 19 | * (default: `true`) 20 | * @returns {(Promise | string>)} - Api Response 21 | * `object` -or- url `string` if `doFetch = false` 22 | */ 23 | function GetVehicleVariableList( 24 | doFetch?: true 25 | ): Promise> 26 | 27 | function GetVehicleVariableList(doFetch: false): Promise 28 | 29 | async function GetVehicleVariableList( 30 | doFetch = true 31 | ): Promise | string> { 32 | const endpointName = 'GetVehicleVariableList' 33 | 34 | try { 35 | const { get, createCachedUrl, getCachedUrl } = useNHTSA() 36 | 37 | createCachedUrl({ endpointName }) 38 | 39 | if (!doFetch) { 40 | return getCachedUrl() 41 | } else { 42 | return get() 43 | } 44 | } catch (error) { 45 | return rejectWithError(error) 46 | } 47 | } 48 | 49 | export { GetVehicleVariableList } 50 | 51 | /** 52 | * Objects found in the `Results` array of `GetVehicleVariableList` endpoint response. 53 | */ 54 | export type GetVehicleVariableListResults = { 55 | DataType: 'string' | 'int' | 'decimal' | 'lookup' 56 | Description: string 57 | GroupName: string | null 58 | ID: number 59 | Name: string 60 | } 61 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nhtsa-api-wrapper", 3 | "private": true, 4 | "version": "0.0.0", 5 | "description": "@shaggytools/nhtsa-api-wrapper Monorepo", 6 | "author": "Brandon Eichler ", 7 | "license": "MIT", 8 | "homepage": "https://www.shaggytech.com/nhtsa-api-wrapper", 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/ShaggyTech/nhtsa-api-wrapper.git" 12 | }, 13 | "bugs": { 14 | "url": "https://github.com/ShaggyTech/nhtsa-api-wrapper/issues" 15 | }, 16 | "packageManager": "pnpm@8.1.0", 17 | "workspaces": [ 18 | "apps/*", 19 | "config/*", 20 | "packages/*" 21 | ], 22 | "engines": { 23 | "node": ">=18.13.0", 24 | "pnpm": ">=7.27.1" 25 | }, 26 | "scripts": { 27 | "preinstall": "npx only-allow pnpm", 28 | "build": "turbo run build", 29 | "build:lib": "pnpm --filter @shaggytools/nhtsa-api-wrapper run build", 30 | "build:docs": "pnpm --filter docs run build", 31 | "dev": "turbo run dev --parallel", 32 | "dev:lib": "pnpm --filter @shaggytools/nhtsa-api-wrapper run dev", 33 | "dev:docs": "pnpm --filter docs run dev", 34 | "lint": "turbo run lint", 35 | "lint:fix": "turbo run lint:fix", 36 | "format": "turbo run format", 37 | "test": "turbo run test", 38 | "coverage": "pnpm --filter @shaggytools/nhtsa-api-wrapper run coverage", 39 | "clean": "turbo run clean", 40 | "ci:version": "changeset version && pnpm i --lockfile-only && pnpm run build", 41 | "ci:publish": "pnpm run build && pnpm publish -r" 42 | }, 43 | "devDependencies": { 44 | "@changesets/cli": "2.26.1", 45 | "@commitlint/cli": "17.6.3", 46 | "@commitlint/config-conventional": "17.6.3", 47 | "husky": "8.0.3", 48 | "rimraf": "5.0.1", 49 | "turbo": "1.9.9", 50 | "typescript": "5.0.4" 51 | }, 52 | "husky": { 53 | "hooks": { 54 | "pre-commit": "pnpm lint", 55 | "pre-push": "pnpm verify" 56 | } 57 | }, 58 | "lint-staged": { 59 | "*.{js,ts,tsx,vue,md}": [ 60 | "eslint --cache --fix" 61 | ] 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/types.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module api/endpoints/types 3 | * @category Types 4 | */ 5 | 6 | export type { DecodeVinResults, DecodeVinVariable } from './DecodeVin' 7 | export type { 8 | DecodeVinExtendedResults, 9 | DecodeVinExtendedVariable, 10 | } from './DecodeVinExtended' 11 | export type { DecodeVinValuesResults } from './DecodeVinValues' 12 | export type { DecodeVinValuesBatchResults } from './DecodeVinValuesBatch' 13 | export type { DecodeVinValuesExtendedResults } from './DecodeVinValuesExtended' 14 | export type { DecodeWMIResults } from './DecodeWMI' 15 | export type { GetAllMakesResults } from './GetAllMakes' 16 | export type { GetAllManufacturersResults } from './GetAllManufacturers' 17 | export type { GetCanadianVehicleSpecificationsResults } from './GetCanadianVehicleSpecifications' 18 | export type { 19 | GetEquipmentPlantCodesResults, 20 | GetEquipmentPlantCodesParams, 21 | } from './GetEquipmentPlantCodes' 22 | export type { GetMakeForManufacturerResults } from './GetMakeForManufacturer' 23 | export type { GetMakesForManufacturerAndYearResults } from './GetMakesForManufacturerAndYear' 24 | export type { GetMakesForVehicleTypeResults } from './GetMakesForVehicleType' 25 | export type { GetManufacturerDetailsResults } from './GetManufacturerDetails' 26 | export type { GetModelsForMakeResults } from './GetModelsForMake' 27 | export type { GetModelsForMakeIdResults } from './GetModelsForMakeId' 28 | export type { GetModelsForMakeIdYearResults } from './GetModelsForMakeIdYear' 29 | export type { GetModelsForMakeYearResults } from './GetModelsForMakeYear' 30 | export type { GetPartsResults } from './GetParts' 31 | export type { GetVehicleTypesForMakeResults } from './GetVehicleTypesForMake' 32 | export type { GetVehicleTypesForMakeIdResults } from './GetVehicleTypesForMakeId' 33 | export type { GetVehicleVariableListResults } from './GetVehicleVariableList' 34 | export type { GetVehicleVariableValuesListResults } from './GetVehicleVariableValuesList' 35 | export type { GetWMIsForManufacturerResults } from './GetWMIsForManufacturer' 36 | 37 | export {} 38 | -------------------------------------------------------------------------------- /.github/todos.md: -------------------------------------------------------------------------------- 1 | # Plan of action for v3.0.0 release 2 | 3 | ## Current Tags: 4 | 5 | latest: `v2.0.3` 6 | next: `v3.0.0` 7 | beta: `v3.0.0-beta.1` 8 | 9 | There is a potential problem here in that I've already published v3.0.0 under the 'next' tag. I'm 10 | not sure if this will cause any problems, but the official v3 release may need to be v3.0.1 to avoid 11 | problems with publishing. 12 | 13 | --- 14 | 15 | ## Plan of action: 16 | 17 | - update github actions workflows for new codebase 18 | - make choice on whether to use changesets or similar to manage versioning 19 | - publish v3.0.1 with 'latest' tag 20 | 21 | --- 22 | 23 | ## Github Actions Workflows 24 | 25 | On pull (/push?) to any branch (except 'main' and 'next'): 26 | 27 | - build lib and docs 28 | - lint 29 | - test 30 | - upload coverage report? 31 | 32 | On push to branch 'next': 33 | 34 | - build lib and docs 35 | - lint 36 | - test 37 | - upload coverage report? 38 | - publish 'next' as canary tag? 39 | - publish next docs to github pages, this may have conflicts with the 'latest' docs if we stick with github pages 40 | maybe use Vercel for 'next' docs? 41 | 42 | On push to branch 'main': 43 | 44 | - build lib and docs 45 | - lint 46 | - test 47 | - upload coverage report 48 | - publish 'latest' tag? (should we use changesets or similar?) 49 | - publish latest docs to github pages (should we use Vercel or similar?) 50 | 51 | All dependency update pull requests (renovate.json) are made against the 'next' branch and merged manually with a push into 'main' from there. 52 | 53 | ## Publishing nhtsa-api-wrapper lib 54 | 55 | ### Publishing to NPM 56 | 57 | Github Action to deploy to NPM on push to 'main' branch. 58 | 59 | How do we use changesets or similar to manage versioning? 60 | 61 | ### Publishing to Github Packages 62 | 63 | Github Action to deploy to Github Packages on push to 'main' branch. 64 | 65 | --- 66 | 67 | ## Publishing Docs 68 | 69 | Github Action to deploy docs to gh-pages branch on push to 'main' branch. 70 | 71 | Only deploy new docs to gh-pages on push to main branch, publish 'next' docs to Vercel. 72 | -------------------------------------------------------------------------------- /apps/docs/src/api/index.md: -------------------------------------------------------------------------------- 1 | # API Reference 2 | 3 | --- 4 | 5 | This section of the documentation describes the main functions exported by this package, as well as 6 | the response format returned by the NHTSA API. 7 | 8 | You can also find details of the VPIC API endpoints and what they return. 9 | 10 | ## VPIC API Response 11 | 12 | - [VPIC API Response](../api/vpic-api-response) 13 | 14 | ## VPIC API Endpoints 15 | 16 | - [DecodeVin](../api/endpoints/decode-vin) 17 | - [DecodeVinExtended](../api/endpoints/decode-vin-extended) 18 | - [DecodeVinValues](../api/endpoints/decode-vin-values) 19 | - [DecodeVinValuesBatch](../api/endpoints/decode-vin-values-batch) 20 | - [DecodeVinValuesExtended](../api/endpoints/decode-vin-values-extended) 21 | - [DecodeWMI](../api/endpoints/decode-wmi) 22 | - [GetAllMakes](../api/endpoints/get-all-makes) 23 | - [GetAllManufacturers](../api/endpoints/get-all-manufacturers) 24 | - [GetCanadianVehicleSpecifications](../api/endpoints/get-canadian-vehicle-specifications) 25 | - [GetEquipmentPlantCodes](../api/endpoints/get-equipment-plant-codes) 26 | - [GetMakeForManufacturer](../api/endpoints/get-make-for-manufacturer) 27 | - [GetMakesForManufacturerAndYear](../api/endpoints/get-makes-for-manufacturer-and-year) 28 | - [GetMakesForVehicleType](../api/endpoints/get-makes-for-vehicle-type) 29 | - [GetManufacturerDetails](../api/endpoints/get-manufacturer-details) 30 | - [GetModelsForMake](../api/endpoints/get-models-for-make) 31 | - [GetModelsForMakeId](../api/endpoints/get-models-for-make-id) 32 | - [GetModelsForMakeIdYear](../api/endpoints/get-models-for-make-id-year) 33 | - [GetModelsForMakeYear](../api/endpoints/get-models-for-make-year) 34 | - [GetParts](../api/endpoints/get-parts) 35 | - [GetVehicleTypesForMake](../api/endpoints/get-vehicle-types-for-make) 36 | - [GetVehicleTypesForMakeId](../api/endpoints/get-vehicle-types-for-make-id) 37 | - [GetVehicleVariableList](../api/endpoints/get-vehicle-variable-list) 38 | - [GetVehicleVariableValuesList](../api/endpoints/get-vehicle-variable-values-list) 39 | - [GetWMIsForManufacturer](../api/endpoints/get-wmis-for-manufacturer) 40 | -------------------------------------------------------------------------------- /apps/docs/src/parts/package-exports-types.md: -------------------------------------------------------------------------------- 1 | ## Types This Package Exports 2 | 3 | ::: tip :bulb: INFO 4 | All types used by this package can be found in the [Typedoc Section](../typedoc/modules/types). 5 | ::: 6 | 7 | Each endpoint function returns a `NhtsaResponse` object where `T` is one of the `Results` types 8 | listed below. 9 | 10 | For example, the `DecodeVin` endpoint returns `NhtsaResponse`. 11 | The `Results` key in the returned object contains the actual relevant data returned by the API. 12 | The number of objects and structure of of the `Results` depends on the endpoint you're using. 13 | 14 | ```javascript 15 | import type { 16 | NhtsaResponse, // full response object returned by the VPIC API 17 | 18 | // Results 19 | DecodeVinResults, 20 | DecodeVinExtendedResults, 21 | DecodeVinValuesResults, 22 | DecodeVinValuesBatchResults, 23 | DecodeVinValuesExtendedResults, 24 | DecodeWMIResults, 25 | GetAllMakesResults, 26 | GetAllManufacturersResults, 27 | GetCanadianVehicleSpecificationsResults, 28 | GetEquipmentPlantCodesResults, 29 | GetMakeForManufacturerResults, 30 | GetMakesForManufacturerAndYearResults, 31 | GetMakesForVehicleTypeResults, 32 | GetManufacturerDetailsResults, 33 | GetModelsForMakeResults, 34 | GetModelsForMakeIdResults, 35 | GetModelsForMakeIdYearResults, 36 | GetModelsForMakeYearResults, 37 | GetPartsResults, 38 | GetVehicleTypesForMakeResults, 39 | GetVehicleTypesForMakeIdResults, 40 | GetVehicleVariableListResults, 41 | GetVehicleVariableValuesListResults, 42 | GetWMIsForManufacturerResults, 43 | 44 | // possible string values for results Variables 45 | DecodeVinVariable, 46 | DecodeVinExtendedVariable, 47 | 48 | // useNHTSA 49 | CreateUrlOptions, 50 | 51 | // Query String (internal) 52 | QueryStringParams, 53 | QueryStringParamsEncoded, 54 | QueryStringTypes, 55 | } from '@shaggytools/nhtsa-api-wrapper' 56 | ``` 57 | 58 | ::: tip :bulb: TIP 59 | You can find specific details on each endpoint's `Results` types on their respective pages. 60 | 61 | See [DecodeVinResults](../api/endpoints/decode-vin#type-decodevinresults) for example. 62 | ::: 63 | -------------------------------------------------------------------------------- /apps/docs/.vitepress/theme/components/ReloadPrompt.vue: -------------------------------------------------------------------------------- 1 | 36 | 37 | 38 | 39 | 40 | 41 | {{ 42 | offlineReady 43 | ? 'App ready to work offline' 44 | : 'New content available, click the reload button to update.' 45 | }} 46 | 47 | 53 | Reload 54 | 55 | Close 56 | 57 | 58 | 59 | 60 | 85 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/__tests__/GetAllMakes.test.ts: -------------------------------------------------------------------------------- 1 | import { beforeEach, describe, expect, it } from 'vitest' 2 | import { GetAllMakes } from '../' 3 | 4 | // Mocks 5 | import { createMockResponse } from '.vitest/helpers' 6 | import { mockResults } from '.vitest/data' 7 | 8 | describe('api/endpoints/GetAllMakes.ts', () => { 9 | it('exports GetAllMakes function', () => { 10 | expect(GetAllMakes).toBeDefined() 11 | expect(GetAllMakes).toBeInstanceOf(Function) 12 | }) 13 | }) 14 | 15 | describe('GetAllMakes', () => { 16 | const endpointName = 'GetAllMakes' 17 | const mockUrl = `https://vpic.nhtsa.dot.gov/api/vehicles/${endpointName}/?format=json` 18 | 19 | const expectedFetchOptions = { 20 | saveUrl: true, 21 | method: 'GET', 22 | } 23 | 24 | beforeEach(() => { 25 | fetchMock.resetMocks() 26 | fetchMock.mockResolvedValue(createMockResponse(mockResults)) 27 | }) 28 | 29 | it('returns a Promise', () => { 30 | const response = GetAllMakes() 31 | expect(response).toBeInstanceOf(Promise) 32 | }) 33 | 34 | /***************************** 35 | * doFetch = true (default) 36 | ****************************/ 37 | it('fetches data', async () => { 38 | const results = await GetAllMakes() 39 | 40 | expect(results).toEqual(mockResults) 41 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 42 | expect(fetchMock.requests().length).toEqual(1) 43 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 44 | expect(fetchMock.requests()[0].method).toEqual('GET') 45 | }) 46 | 47 | it('fetches data when provided doFetch = true', async () => { 48 | const results = await GetAllMakes(true) 49 | 50 | expect(results).toEqual(mockResults) 51 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 52 | expect(fetchMock.requests().length).toEqual(1) 53 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 54 | expect(fetchMock.requests()[0].method).toEqual('GET') 55 | }) 56 | 57 | /***************************** 58 | * doFetch = false 59 | ****************************/ 60 | it('returns url string when provided doFetch = false', async () => { 61 | const results = await GetAllMakes(false) 62 | 63 | expect(results).toEqual(mockUrl) 64 | expect(fetchMock.requests().length).toEqual(0) 65 | }) 66 | }) 67 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/utils_errorHandler.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / utils/errorHandler 2 | 3 | # Module: utils/errorHandler 4 | 5 | ## Table of contents 6 | 7 | ### Functions 8 | 9 | - [handleError](utils_errorHandler.md#handleerror) 10 | - [isError](utils_errorHandler.md#iserror) 11 | - [rejectWithError](utils_errorHandler.md#rejectwitherror) 12 | 13 | ## Functions 14 | 15 | ### handleError 16 | 17 | ▸ **handleError**(`error`): `Error` 18 | 19 | Handles errors by returning an Error instance. 20 | Accepts any type of value but will return default error message of `an unknown error occurred` if 21 | `error` is not an Error type or a message string. 22 | 23 | #### Parameters 24 | 25 | | Name | Type | Description | 26 | | :------ | :-------- | :---------------- | 27 | | `error` | `unknown` | Any type of value | 28 | 29 | #### Returns 30 | 31 | `Error` 32 | 33 | - instance of Error with message 34 | 35 | #### Defined in 36 | 37 | [utils/errorHandler.ts:26](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/utils/errorHandler.ts#L26) 38 | 39 | --- 40 | 41 | ### isError 42 | 43 | ▸ **isError**(`error`): `boolean` 44 | 45 | Checks if `error` is an instance of any Error type. 46 | 47 | #### Parameters 48 | 49 | | Name | Type | Description | 50 | | :------ | :-------- | :---------------- | 51 | | `error` | `unknown` | Any type of value | 52 | 53 | #### Returns 54 | 55 | `boolean` 56 | 57 | - True if `error` is an instance of Error, TypeError, etc. 58 | 59 | #### Defined in 60 | 61 | [utils/errorHandler.ts:14](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/utils/errorHandler.ts#L14) 62 | 63 | --- 64 | 65 | ### rejectWithError 66 | 67 | ▸ **rejectWithError**(`error`): `Promise`<`never`\> 68 | 69 | Returns a Promise rejection containing an Error instance. 70 | Uses [handleError](utils_errorHandler.md#handleerror) to return a default error message if `error` is 71 | not an Error type. 72 | 73 | #### Parameters 74 | 75 | | Name | Type | Description | 76 | | :------ | :-------- | :---------------- | 77 | | `error` | `unknown` | Any type of value | 78 | 79 | #### Returns 80 | 81 | `Promise`<`never`\> 82 | 83 | #### Defined in 84 | 85 | [utils/errorHandler.ts:47](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/utils/errorHandler.ts#L47) 86 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/GetModelsForMake.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module api/endpoints/GetModelsForMake 3 | * @category API Endpoints 4 | */ 5 | 6 | import { useNHTSA } from '@/api' 7 | import { catchInvalidArguments, rejectWithError } from '@/utils' 8 | import type { IArgToValidate, NhtsaResponse } from '@/types' 9 | 10 | /** 11 | * ::: tip :bulb: More Information 12 | * See: [GetModelsForMake Documentation](/api/endpoints/get-models-for-make) 13 | * ::: 14 | * 15 | * `GetModelsForMake` returns the Models in the vPIC dataset for a specified `makeName` 16 | * whose Name is LIKE the Make in vPIC Dataset. 17 | * 18 | * `makeName` can be a partial, or a full for more specificity, e.g., "Harley", 19 | * "Harley Davidson", etc. 20 | * 21 | * @param {string} makeName - Vehicle make name 22 | * @returns {(Promise>)} - Api Response object 23 | * @param {boolean} [doFetch=true] - Whether to fetch the data or just return the URL 24 | * (default: `true`) 25 | * @returns {(Promise | string>)} - Api Response `object` 26 | * -or- url `string` if `doFetch = false` 27 | */ 28 | function GetModelsForMake( 29 | makeName: string, 30 | doFetch?: true 31 | ): Promise> 32 | 33 | function GetModelsForMake(makeName: string, doFetch: false): Promise 34 | 35 | async function GetModelsForMake( 36 | makeName: string, 37 | doFetch = true 38 | ): Promise | string> { 39 | const endpointName = 'GetModelsForMake' 40 | 41 | try { 42 | const args: IArgToValidate[] = [ 43 | { 44 | name: 'makeName', 45 | value: makeName, 46 | required: true, 47 | types: ['string'], 48 | }, 49 | ] 50 | catchInvalidArguments({ args }) 51 | 52 | const { get, createCachedUrl, getCachedUrl } = useNHTSA() 53 | 54 | createCachedUrl({ endpointName, path: makeName }) 55 | 56 | if (!doFetch) { 57 | return getCachedUrl() 58 | } else { 59 | return get() 60 | } 61 | } catch (error) { 62 | return rejectWithError(error) 63 | } 64 | } 65 | 66 | export { GetModelsForMake } 67 | 68 | /** 69 | * Objects found in the `Results` array of `GetModelsForMake` endpoint response. 70 | */ 71 | export type GetModelsForMakeResults = { 72 | Make_ID: number 73 | Make_Name: string 74 | Model_ID: number 75 | Model_Name: string 76 | } 77 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/utils_types.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / utils/types 2 | 3 | # Module: utils/types 4 | 5 | ## Table of contents 6 | 7 | ### References 8 | 9 | - [IArgToValidate](utils_types.md#iargtovalidate) 10 | - [QueryStringParams](utils_types.md#querystringparams) 11 | - [QueryStringParamsEncoded](utils_types.md#querystringparamsencoded) 12 | - [QueryStringTypes](utils_types.md#querystringtypes) 13 | 14 | ### Type Aliases 15 | 16 | - [AtLeastOne](utils_types.md#atleastone) 17 | - [RequireOnlyOne](utils_types.md#requireonlyone) 18 | 19 | ## References 20 | 21 | ### IArgToValidate 22 | 23 | Re-exports [IArgToValidate](utils_argHandler.md#iargtovalidate) 24 | 25 | --- 26 | 27 | ### QueryStringParams 28 | 29 | Re-exports [QueryStringParams](utils_queryString.md#querystringparams) 30 | 31 | --- 32 | 33 | ### QueryStringParamsEncoded 34 | 35 | Re-exports [QueryStringParamsEncoded](utils_queryString.md#querystringparamsencoded) 36 | 37 | --- 38 | 39 | ### QueryStringTypes 40 | 41 | Re-exports [QueryStringTypes](utils_queryString.md#querystringtypes) 42 | 43 | ## Type Aliases 44 | 45 | ### AtLeastOne 46 | 47 | Ƭ **AtLeastOne**<`T`, `R`\>: { [P in R]-?: Required\> & Partial\> }[`R`] 48 | 49 | Require at least one of a set of properties in an object 50 | https://stackoverflow.com/a/49725198 51 | 52 | #### Type parameters 53 | 54 | | Name | Type | 55 | | :--- | :---------------------------- | 56 | | `T` | `T` | 57 | | `R` | extends keyof `T` = keyof `T` | 58 | 59 | #### Defined in 60 | 61 | [utils/types.ts:18](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/utils/types.ts#L18) 62 | 63 | --- 64 | 65 | ### RequireOnlyOne 66 | 67 | Ƭ **RequireOnlyOne**<`T`, `Keys`\>: `Omit`<`T`, `Keys`\> & { [K in keyof Required]: Required\> & Partial, undefined\>\> }[`Keys`] 68 | 69 | Require only one of a set of properties in an object 70 | https://stackoverflow.com/a/49725198 71 | 72 | #### Type parameters 73 | 74 | | Name | Type | 75 | | :----- | :---------------------------- | 76 | | `T` | `T` | 77 | | `Keys` | extends keyof `T` = keyof `T` | 78 | 79 | #### Defined in 80 | 81 | [utils/types.ts:26](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/utils/types.ts#L26) 82 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/__tests__/GetVehicleVariableList.test.ts: -------------------------------------------------------------------------------- 1 | import { beforeEach, describe, expect, it } from 'vitest' 2 | import { GetVehicleVariableList } from '../' 3 | 4 | // Mocks 5 | import { createMockResponse } from '.vitest/helpers' 6 | import { mockResults } from '.vitest/data' 7 | 8 | describe('api/endpoints/GetVehicleVariableList.ts', () => { 9 | it('exports GetVehicleVariableList function', () => { 10 | expect(GetVehicleVariableList).toBeDefined() 11 | expect(GetVehicleVariableList).toBeInstanceOf(Function) 12 | }) 13 | }) 14 | 15 | describe('GetVehicleVariableList', () => { 16 | const endpointName = 'GetVehicleVariableList' 17 | const mockUrl = `https://vpic.nhtsa.dot.gov/api/vehicles/${endpointName}/?format=json` 18 | 19 | const expectedFetchOptions = { 20 | saveUrl: true, 21 | method: 'GET', 22 | } 23 | 24 | beforeEach(() => { 25 | fetchMock.resetMocks() 26 | fetchMock.mockResolvedValue(createMockResponse(mockResults)) 27 | }) 28 | 29 | it('returns a Promise', () => { 30 | const response = GetVehicleVariableList() 31 | expect(response).toBeInstanceOf(Promise) 32 | }) 33 | 34 | /***************************** 35 | * doFetch = true (default) 36 | ****************************/ 37 | it('fetches data', async () => { 38 | const results = await GetVehicleVariableList() 39 | 40 | expect(results).toEqual(mockResults) 41 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 42 | expect(fetchMock.requests().length).toEqual(1) 43 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 44 | expect(fetchMock.requests()[0].method).toEqual('GET') 45 | }) 46 | 47 | it('fetches data when provided doFetch = true', async () => { 48 | const results = await GetVehicleVariableList(true) 49 | 50 | expect(results).toEqual(mockResults) 51 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 52 | expect(fetchMock.requests().length).toEqual(1) 53 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 54 | expect(fetchMock.requests()[0].method).toEqual('GET') 55 | }) 56 | 57 | /***************************** 58 | * doFetch = false 59 | ****************************/ 60 | it('returns url string when provided doFetch = false', async () => { 61 | const results = await GetVehicleVariableList(false) 62 | 63 | expect(results).toEqual(mockUrl) 64 | expect(fetchMock.requests().length).toEqual(0) 65 | }) 66 | }) 67 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/GetVehicleTypesForMake.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module api/endpoints/GetVehicleTypesForMake 3 | * @category API Endpoints 4 | */ 5 | 6 | import { useNHTSA } from '@/api' 7 | import { catchInvalidArguments, rejectWithError } from '@/utils' 8 | import type { IArgToValidate, NhtsaResponse } from '@/types' 9 | 10 | /** 11 | * ::: tip :bulb: More Information 12 | * See: [GetVehicleTypesForMake Documentation](/api/endpoints/get-vehicle-types-for-make) 13 | * ::: 14 | * 15 | * `GetVehicleTypesForMake` returns all the Vehicle Types in the vPIC dataset for a specified Make, 16 | * whose name is LIKE the make name in the vPIC Dataset. 17 | * 18 | * `makeName` can be a partial name, or a full name for more specificity, e.g., "Merc", 19 | * "Mercedes Benz", etc. 20 | * 21 | * @param {string} makeName - Name of the vehicle make to search 22 | * @param {boolean} [doFetch=true] - Whether to fetch the data or just return the URL 23 | * (default: `true`) 24 | * @returns {(Promise | string>)} - Api Response 25 | * `object` -or- url `string` if `doFetch = false` 26 | */ 27 | function GetVehicleTypesForMake( 28 | makeName: string, 29 | doFetch?: true 30 | ): Promise> 31 | 32 | function GetVehicleTypesForMake( 33 | makeName: string, 34 | doFetch: false 35 | ): Promise 36 | 37 | async function GetVehicleTypesForMake( 38 | makeName: string, 39 | doFetch = true 40 | ): Promise | string> { 41 | const endpointName = 'GetVehicleTypesForMake' 42 | 43 | try { 44 | const args: IArgToValidate[] = [ 45 | { 46 | name: 'makeName', 47 | value: makeName, 48 | required: true, 49 | types: ['string'], 50 | }, 51 | ] 52 | catchInvalidArguments({ args }) 53 | 54 | const { get, createCachedUrl, getCachedUrl } = useNHTSA() 55 | 56 | createCachedUrl({ endpointName, path: makeName }) 57 | 58 | if (!doFetch) { 59 | return getCachedUrl() 60 | } else { 61 | return get() 62 | } 63 | } catch (error) { 64 | return rejectWithError(error) 65 | } 66 | } 67 | 68 | export { GetVehicleTypesForMake } 69 | 70 | /** 71 | * Objects found in the `Results` array of `GetVehicleTypesForMake` endpoint response. 72 | */ 73 | export type GetVehicleTypesForMakeResults = { 74 | MakeId: number 75 | MakeName: string 76 | VehicleTypeId: number 77 | VehicleTypeName: string 78 | } 79 | -------------------------------------------------------------------------------- /apps/docs/src/snippets/endpoints/get-make-for-manufacturer.ts: -------------------------------------------------------------------------------- 1 | // #region type-results 2 | type GetMakeForManufacturerResults = { 3 | Make_ID: number 4 | Make_Name: string 5 | Mfr_Name: string 6 | } 7 | // #endregion type-results 8 | 9 | // #region example-response 10 | // Using GetMakeForManufacturer('honda') 11 | const exampleResponse = { 12 | Count: 15, 13 | Message: 'Results returned successfully', 14 | Results: [ 15 | { 16 | Make_ID: 474, 17 | Make_Name: 'HONDA', 18 | Mfr_Name: 'HONDA MOTOR CO., LTD', 19 | }, 20 | { 21 | Make_ID: 474, 22 | Make_Name: 'HONDA', 23 | Mfr_Name: 'AMERICAN HONDA MOTOR CO., INC.', 24 | }, 25 | { 26 | Make_ID: 474, 27 | Make_Name: 'HONDA', 28 | Mfr_Name: 'HONDA OF CANADA MFG., INC.', 29 | }, 30 | { 31 | Make_ID: 474, 32 | Make_Name: 'HONDA', 33 | Mfr_Name: 'HONDA OF THE U.K. MFG., LTD.', 34 | }, 35 | { 36 | Make_ID: 474, 37 | Make_Name: 'HONDA', 38 | Mfr_Name: 'HONDA DE MEXICO', 39 | }, 40 | { 41 | Make_ID: 474, 42 | Make_Name: 'HONDA', 43 | Mfr_Name: 'THAI HONDA CO., LTD.', 44 | }, 45 | { 46 | Make_ID: 474, 47 | Make_Name: 'HONDA', 48 | Mfr_Name: 'HONDA VIETNAM CO., LTD.', 49 | }, 50 | { 51 | Make_ID: 474, 52 | Make_Name: 'HONDA', 53 | Mfr_Name: 'MOTO HONDA DA AMAZONIA LTDA.', 54 | }, 55 | { 56 | Make_ID: 474, 57 | Make_Name: 'HONDA', 58 | Mfr_Name: 'SUNDIRO HONDA MOTORCYCLE CO., LTD.', 59 | }, 60 | { 61 | Make_ID: 474, 62 | Make_Name: 'HONDA', 63 | Mfr_Name: 'MONTESA HONDA SA', 64 | }, 65 | { 66 | Make_ID: 475, 67 | Make_Name: 'ACURA', 68 | Mfr_Name: 'HONDA MOTOR CO., LTD', 69 | }, 70 | { 71 | Make_ID: 475, 72 | Make_Name: 'ACURA', 73 | Mfr_Name: 'AMERICAN HONDA MOTOR CO., INC.', 74 | }, 75 | { 76 | Make_ID: 475, 77 | Make_Name: 'ACURA', 78 | Mfr_Name: 'HONDA OF CANADA MFG., INC.', 79 | }, 80 | { 81 | Make_ID: 542, 82 | Make_Name: 'ISUZU', 83 | Mfr_Name: 'HONDA MOTOR CO., LTD', 84 | }, 85 | { 86 | Make_ID: 7351, 87 | Make_Name: 'SUNDIRO HONDA MOTORCYCLE CO. LTD', 88 | Mfr_Name: 'SUNDIRO HONDA MOTORCYCLE CO., LTD.', 89 | }, 90 | ], 91 | SearchCriteria: 'Manufacturer:honda', 92 | } 93 | // #endregion example-response 94 | 95 | export type { GetMakeForManufacturerResults } 96 | export { exampleResponse } 97 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/GetMakesForVehicleType.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module api/endpoints/GetMakesForVehicleType 3 | * @category API Endpoints 4 | */ 5 | 6 | import { useNHTSA } from '@/api' 7 | import { catchInvalidArguments, rejectWithError } from '@/utils' 8 | import type { IArgToValidate, NhtsaResponse } from '@/types' 9 | 10 | /** 11 | * ::: tip :bulb: More Information 12 | * See: [GetMakesForVehicleType Documentation](/api/endpoints/get-makes-for-vehicle-type) 13 | * ::: 14 | * 15 | * `GetMakesForVehicleType` returns all the Makes in the vPIC dataset for a specified vehicle type 16 | * (`typeName`), whose name is LIKE the vehicle type name in vPIC Dataset. 17 | * 18 | * `typeName` can be a partial name, or a full name for more specificity, e.g., "Vehicle", "Moto", 19 | * "Low Speed Vehicle", etc. 20 | * 21 | * @param {string} typeName - A partial or full vehicle type name 22 | * @param {boolean} [doFetch=true] - Whether to fetch the data or just return the URL 23 | * (default: `true`) 24 | * @returns {(Promise | string>)} - Api Response 25 | * `object` -or- url `string` if `doFetch = false` 26 | */ 27 | function GetMakesForVehicleType( 28 | typeName: string, 29 | doFetch?: true 30 | ): Promise> 31 | 32 | function GetMakesForVehicleType( 33 | typeName: string, 34 | doFetch: false 35 | ): Promise 36 | 37 | async function GetMakesForVehicleType( 38 | typeName: string, 39 | doFetch = true 40 | ): Promise | string> { 41 | const endpointName = 'GetMakesForVehicleType' 42 | 43 | try { 44 | const args: IArgToValidate[] = [ 45 | { 46 | name: 'typeName', 47 | value: typeName, 48 | required: true, 49 | types: ['string'], 50 | }, 51 | ] 52 | catchInvalidArguments({ args }) 53 | 54 | const { get, createCachedUrl, getCachedUrl } = useNHTSA() 55 | 56 | createCachedUrl({ endpointName, path: typeName }) 57 | 58 | if (!doFetch) { 59 | return getCachedUrl() 60 | } else { 61 | return get() 62 | } 63 | } catch (error) { 64 | return rejectWithError(error) 65 | } 66 | } 67 | 68 | export { GetMakesForVehicleType } 69 | 70 | /** 71 | * Objects found in the `Results` array of `GetMakesForVehicleType` endpoint response. 72 | */ 73 | export type GetMakesForVehicleTypeResults = { 74 | MakeId: number 75 | MakeName: string 76 | VehicleTypeId: number 77 | VehicleTypeName: string 78 | } 79 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/api_endpoints_GetAllMakes.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / api/endpoints/GetAllMakes 2 | 3 | # Module: api/endpoints/GetAllMakes 4 | 5 | ## Table of contents 6 | 7 | ### Type Aliases 8 | 9 | - [GetAllMakesResults](api_endpoints_GetAllMakes.md#getallmakesresults) 10 | 11 | ### Functions 12 | 13 | - [GetAllMakes](api_endpoints_GetAllMakes.md#getallmakes) 14 | 15 | ## Type Aliases 16 | 17 | ### GetAllMakesResults 18 | 19 | Ƭ **GetAllMakesResults**: `Object` 20 | 21 | Objects found in the `Results` array of `GetAllMakes` endpoint response. 22 | 23 | #### Type declaration 24 | 25 | | Name | Type | 26 | | :---------- | :------- | 27 | | `Make_ID` | `number` | 28 | | `Make_Name` | `string` | 29 | 30 | #### Defined in 31 | 32 | [api/endpoints/GetAllMakes.ts:56](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetAllMakes.ts#L56) 33 | 34 | ## Functions 35 | 36 | ### GetAllMakes 37 | 38 | ▸ **GetAllMakes**(`doFetch?`): `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`GetAllMakesResults`](api_endpoints_GetAllMakes.md#getallmakesresults)\>\> 39 | 40 | ::: tip :bulb: More Information 41 | See: [GetAllMakes Documentation](/api/endpoints/get-all-makes) 42 | ::: 43 | 44 | `GetAllMakes` provides a list of all the Makes available in the vPIC Dataset. 45 | Each object in the `Results` array represents the `Make_ID` and the `Make_Name` of 46 | an individual vehicle Make. 47 | 48 | - FYI there are over 10,000 registered makes in the database! 49 | 50 | #### Parameters 51 | 52 | | Name | Type | Description | 53 | | :--------- | :----- | :----------------------------------------------------------------- | 54 | | `doFetch?` | `true` | Whether to fetch the data or just return the URL (default: `true`) | 55 | 56 | #### Returns 57 | 58 | `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`GetAllMakesResults`](api_endpoints_GetAllMakes.md#getallmakesresults)\>\> 59 | 60 | - Api Response `object` 61 | -or- url `string` if `doFetch = false` (default: `true`) 62 | 63 | #### Defined in 64 | 65 | [api/endpoints/GetAllMakes.ts:26](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetAllMakes.ts#L26) 66 | 67 | ▸ **GetAllMakes**(`doFetch`): `Promise`<`string`\> 68 | 69 | #### Parameters 70 | 71 | | Name | Type | 72 | | :-------- | :------ | 73 | | `doFetch` | `false` | 74 | 75 | #### Returns 76 | 77 | `Promise`<`string`\> 78 | 79 | #### Defined in 80 | 81 | [api/endpoints/GetAllMakes.ts:28](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetAllMakes.ts#L28) 82 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/GetVehicleVariableValuesList.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module api/endpoints/GetVehicleVariableValuesList 3 | * @category API Endpoints 4 | */ 5 | 6 | import { useNHTSA } from '@/api' 7 | import { catchInvalidArguments, rejectWithError } from '@/utils' 8 | import type { IArgToValidate, NhtsaResponse } from '@/types' 9 | 10 | /** 11 | * ::: tip :bulb: More Information 12 | * See: [GetVehicleVariableValuesList Documentation](/api/endpoints/get-vehicle-variable-values-list) 13 | * ::: 14 | * 15 | * `GetVehicleVariableValuesList` provides a list of all the accepted values for a given variable 16 | * that are stored in the vPIC dataset. 17 | * 18 | * If `variableValue` is a string, it must use full name, not just part of it, e.g., 19 | * "Battery Type", not "Battery" 20 | * 21 | * `variableValue` can be also be a number, which is the ID of the variable, e.g., 1, 2, 3, etc. 22 | * 23 | * @param {(string|number)} variableValue - The variable you want to get a values list of 24 | * @param {boolean} [doFetch=true] - Whether to fetch the data or just return the URL 25 | * (default: `true`) 26 | * @returns {(Promise | string>)} - Api Response 27 | * `object` -or- url `string` if `doFetch = false` 28 | */ 29 | function GetVehicleVariableValuesList( 30 | variableValue: string | number, 31 | doFetch?: true 32 | ): Promise> 33 | 34 | function GetVehicleVariableValuesList( 35 | variableValue: string | number, 36 | doFetch: false 37 | ): Promise 38 | 39 | async function GetVehicleVariableValuesList( 40 | variableValue: string | number, 41 | doFetch = true 42 | ): Promise | string> { 43 | const endpointName = 'GetVehicleVariableValuesList' 44 | 45 | try { 46 | const args: IArgToValidate[] = [ 47 | { 48 | name: 'variableValue', 49 | value: variableValue, 50 | required: true, 51 | types: ['string', 'number'], 52 | }, 53 | ] 54 | catchInvalidArguments({ args }) 55 | 56 | const { get, createCachedUrl, getCachedUrl } = useNHTSA() 57 | 58 | createCachedUrl({ endpointName, path: variableValue.toString() }) 59 | 60 | if (!doFetch) { 61 | return getCachedUrl() 62 | } else { 63 | return get() 64 | } 65 | } catch (error) { 66 | return rejectWithError(error) 67 | } 68 | } 69 | 70 | export { GetVehicleVariableValuesList } 71 | 72 | /** 73 | * Objects found in the `Results` array of `GetVehicleVariableValuesList` endpoint response. 74 | */ 75 | export type GetVehicleVariableValuesListResults = { 76 | ElementName: string 77 | Id: number 78 | Name: string 79 | } 80 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/DecodeWMI.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module api/endpoints/DecodeWMI 3 | * @category API Endpoints 4 | */ 5 | 6 | import { useNHTSA } from '@/api' 7 | import { catchInvalidArguments, rejectWithError } from '@/utils' 8 | import type { IArgToValidate, NhtsaResponse } from '@/types' 9 | 10 | /** 11 | * ::: tip :bulb: More Information 12 | * See: [DecodeWMI Documentation](/api/endpoints/decode-wmi) 13 | * ::: 14 | * 15 | * `DecodeWMI` provides information on the World Manufacturer Identifier for a specific `WMI` code. 16 | * 17 | * `WMI` may be provided as either 3 characters representing VIN position 1-3 _or_ 6 characters 18 | * representing VIN positions 1-3 & 12-14. 19 | * - Examples: "JTD" "1T9131" 20 | * 21 | * A list of WMI codes can be found 22 | * [here](https://en.wikibooks.org/wiki/Vehicle_Identification_Numbers_(VIN_codes)/World_Manufacturer_Identifier_(WMI)), 23 | * but keep in mind that not all of the listed WMIs are registered with NHTSA and therefore may not 24 | * be available in VPIC data sets. 25 | * 26 | * @param {string} WMI - World Manufacturer Identifier 27 | * @param {boolean} [doFetch=true] - Whether to fetch the data or just return the URL 28 | * (default: `true`) 29 | * @returns {(Promise | string>)} - Api Response `object` 30 | * -or- url `string` if `doFetch = false` (default: `true`) 31 | */ 32 | function DecodeWMI( 33 | WMI: string, 34 | doFetch?: true 35 | ): Promise> 36 | 37 | function DecodeWMI(WMI: string, doFetch: false): Promise 38 | 39 | /* Implementation */ 40 | async function DecodeWMI( 41 | WMI: string, 42 | doFetch = true 43 | ): Promise | string> { 44 | const endpointName = 'DecodeWMI' 45 | 46 | try { 47 | const args: IArgToValidate[] = [ 48 | { 49 | name: 'WMI', 50 | value: WMI, 51 | required: true, 52 | types: ['string'], 53 | }, 54 | ] 55 | catchInvalidArguments({ args }) 56 | 57 | const { get, createCachedUrl, getCachedUrl } = useNHTSA() 58 | 59 | createCachedUrl({ endpointName, path: WMI }) 60 | 61 | if (!doFetch) { 62 | return getCachedUrl() 63 | } else { 64 | return get() 65 | } 66 | } catch (error) { 67 | return rejectWithError(error) 68 | } 69 | } 70 | 71 | export { DecodeWMI } 72 | 73 | /** 74 | * Objects found in the `Results` array of `DecodeWMI` endpoint response. 75 | */ 76 | export type DecodeWMIResults = { 77 | CommonName: string 78 | CreatedOn: string 79 | DateAvailableToPublic: string 80 | Make: string 81 | ManufacturerName: string 82 | ParentCompanyName: string 83 | URL: string 84 | UpdatedOn: string | null 85 | VehicleType: string 86 | } 87 | -------------------------------------------------------------------------------- /apps/docs/src/snippets/endpoints/get-makes-for-vehicle-type.ts: -------------------------------------------------------------------------------- 1 | // #region type-results 2 | type GetMakesForVehicleTypeResults = { 3 | MakeId: number 4 | MakeName: string 5 | VehicleTypeId: number 6 | VehicleTypeName: string 7 | } 8 | // #endregion type-results 9 | 10 | // #region example-response 11 | // Using GetMakesForVehicleType('truck') - truncated for brevity 12 | const exampleResponse = { 13 | Count: 171, 14 | Message: 'Response returned successfully', 15 | Results: [ 16 | { 17 | MakeId: 441, 18 | MakeName: 'TESLA', 19 | VehicleTypeId: 3, 20 | VehicleTypeName: 'Truck ', 21 | }, 22 | { 23 | MakeId: 448, 24 | MakeName: 'TOYOTA', 25 | VehicleTypeId: 3, 26 | VehicleTypeName: 'Truck ', 27 | }, 28 | { 29 | MakeId: 449, 30 | MakeName: 'MERCEDES-BENZ', 31 | VehicleTypeId: 3, 32 | VehicleTypeName: 'Truck ', 33 | }, 34 | { 35 | MakeId: 450, 36 | MakeName: 'FREIGHTLINER', 37 | VehicleTypeId: 3, 38 | VehicleTypeName: 'Truck ', 39 | }, 40 | { 41 | MakeId: 460, 42 | MakeName: 'FORD', 43 | VehicleTypeId: 3, 44 | VehicleTypeName: 'Truck ', 45 | }, 46 | { 47 | MakeId: 464, 48 | MakeName: 'LINCOLN', 49 | VehicleTypeId: 3, 50 | VehicleTypeName: 'Truck ', 51 | }, 52 | { 53 | MakeId: 465, 54 | MakeName: 'MERCURY', 55 | VehicleTypeId: 3, 56 | VehicleTypeName: 'Truck ', 57 | }, 58 | { 59 | MakeId: 467, 60 | MakeName: 'CHEVROLET', 61 | VehicleTypeId: 3, 62 | VehicleTypeName: 'Truck ', 63 | }, 64 | { 65 | MakeId: 469, 66 | MakeName: 'CADILLAC', 67 | VehicleTypeId: 3, 68 | VehicleTypeName: 'Truck ', 69 | }, 70 | { 71 | MakeId: 472, 72 | MakeName: 'GMC', 73 | VehicleTypeId: 3, 74 | VehicleTypeName: 'Truck ', 75 | }, 76 | { 77 | MakeId: 473, 78 | MakeName: 'MAZDA', 79 | VehicleTypeId: 3, 80 | VehicleTypeName: 'Truck ', 81 | }, 82 | { 83 | MakeId: 474, 84 | MakeName: 'HONDA', 85 | VehicleTypeId: 3, 86 | VehicleTypeName: 'Truck ', 87 | }, 88 | { 89 | MakeId: 475, 90 | MakeName: 'ACURA', 91 | VehicleTypeId: 3, 92 | VehicleTypeName: 'Truck ', 93 | }, 94 | { 95 | MakeId: 476, 96 | MakeName: 'DODGE', 97 | VehicleTypeId: 3, 98 | VehicleTypeName: 'Truck ', 99 | }, 100 | // ... 156 more items 101 | ], 102 | SearchCriteria: 'Vehicle Type: truck', 103 | } 104 | // #endregion example-response 105 | 106 | export type { GetMakesForVehicleTypeResults } 107 | export { exampleResponse } 108 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/GetMakeForManufacturer.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module api/endpoints/GetMakeForManufacturer 3 | * @category API Endpoints 4 | */ 5 | 6 | import { useNHTSA } from '@/api' 7 | import { catchInvalidArguments, rejectWithError } from '@/utils' 8 | import type { IArgToValidate, NhtsaResponse } from '@/types' 9 | 10 | /** 11 | * ::: tip :bulb: More Information 12 | * See: [GetMakeForManufacturer Documentation](/api/endpoints/get-make-for-manufacturer) 13 | * ::: 14 | * 15 | * `GetMakeForManufacturer` returns all the Makes in the vPIC dataset for a specified manufacturer 16 | * that is requested. Multiple results are returned in case of multiple matches. 17 | * 18 | * `manufacturer` name can be a partial name, or a full name for more specificity, e.g. "988", 19 | * "honda", "HONDA OF CANADA MFG., INC.", etc. 20 | * 21 | * - If supplied `manufacturer` is a number - method will do exact match on Manufacturer's Id. 22 | * - If supplied `manufacturer` is a string - it will look for manufacturers whose name is LIKE the 23 | * provided name. It accepts a partial manufacturer name as an input. 24 | * 25 | * @param {(string|number)} manufacturer - Manufacturer Name or ID 26 | * @param {boolean} [doFetch=true] - Whether to fetch the data or just return the URL 27 | * (default: `true`) 28 | * @returns {(Promise | string>)} - Api Response 29 | * `object` -or- url `string` if `doFetch = false` 30 | */ 31 | function GetMakeForManufacturer( 32 | manufacturer: string | number, 33 | doFetch?: true 34 | ): Promise> 35 | 36 | function GetMakeForManufacturer( 37 | manufacturer: string | number, 38 | doFetch: false 39 | ): Promise 40 | 41 | async function GetMakeForManufacturer( 42 | manufacturer: string | number, 43 | doFetch = true 44 | ): Promise | string> { 45 | const endpointName = 'GetMakeForManufacturer' 46 | 47 | try { 48 | const args: IArgToValidate[] = [ 49 | { 50 | name: 'manufacturer', 51 | value: manufacturer, 52 | required: true, 53 | types: ['string', 'number'], 54 | }, 55 | ] 56 | catchInvalidArguments({ args }) 57 | 58 | const { get, createCachedUrl, getCachedUrl } = useNHTSA() 59 | 60 | createCachedUrl({ endpointName, path: manufacturer.toString() }) 61 | 62 | if (!doFetch) { 63 | return getCachedUrl() 64 | } else { 65 | return get() 66 | } 67 | } catch (error) { 68 | return rejectWithError(error) 69 | } 70 | } 71 | 72 | export { GetMakeForManufacturer } 73 | 74 | /** 75 | * Objects found in the `Results` array of `GetMakeForManufacturer` endpoint response. 76 | */ 77 | export type GetMakeForManufacturerResults = { 78 | Make_ID: number 79 | Make_Name: string 80 | Mfr_Name: string 81 | } 82 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/__tests__/DecodeWMI.test.ts: -------------------------------------------------------------------------------- 1 | import { beforeEach, describe, expect, it } from 'vitest' 2 | import { DecodeWMI } from '../' 3 | 4 | // Mocks 5 | import { createMockResponse } from '.vitest/helpers' 6 | import { mockResults } from '.vitest/data' 7 | 8 | describe('api/endpoints/DecodeWMI.ts', () => { 9 | it('exports DecodeWMI function', () => { 10 | expect(DecodeWMI).toBeDefined() 11 | expect(DecodeWMI).toBeInstanceOf(Function) 12 | }) 13 | }) 14 | 15 | describe('DecodeWMI', () => { 16 | const endpointName = 'DecodeWMI' 17 | const WMI = 'WVW' 18 | const mockUrl = `https://vpic.nhtsa.dot.gov/api/vehicles/${endpointName}/${WMI}?format=json` 19 | 20 | const expectedFetchOptions = { 21 | saveUrl: true, 22 | method: 'GET', 23 | } 24 | 25 | beforeEach(() => { 26 | fetchMock.resetMocks() 27 | fetchMock.mockResolvedValue(createMockResponse(mockResults)) 28 | }) 29 | 30 | it('returns a Promise', () => { 31 | const response = DecodeWMI('test') 32 | expect(response).toBeInstanceOf(Promise) 33 | }) 34 | 35 | /***************************** 36 | * doFetch = true (default) 37 | ****************************/ 38 | it('fetches data when provided WMI only', async () => { 39 | const results = await DecodeWMI(WMI) 40 | 41 | expect(results).toEqual(mockResults) 42 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 43 | expect(fetchMock.requests().length).toEqual(1) 44 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 45 | expect(fetchMock.requests()[0].method).toEqual('GET') 46 | }) 47 | 48 | it('fetches data when provided WMI and doFetch = true', async () => { 49 | const results = await DecodeWMI(WMI, true) 50 | 51 | expect(results).toEqual(mockResults) 52 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 53 | expect(fetchMock.requests().length).toEqual(1) 54 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 55 | expect(fetchMock.requests()[0].method).toEqual('GET') 56 | }) 57 | 58 | /***************************** 59 | * doFetch = false 60 | ****************************/ 61 | it('returns url string when provided WMI and doFetch = false', async () => { 62 | const results = await DecodeWMI(WMI, false) 63 | 64 | expect(results).toEqual(mockUrl) 65 | expect(fetchMock.requests().length).toEqual(0) 66 | }) 67 | 68 | /***************************** 69 | * rejects with error 70 | ***************************/ 71 | it.each([1234, ['a', 'b'], { a: 'b' }, null, undefined])( 72 | 'rejects with error if WMI is not a string, %#', 73 | async (arg) => { 74 | await expect(() => 75 | DecodeWMI(arg as unknown as string) 76 | ).rejects.toThrowError(/error validating argument named "WMI"/) 77 | 78 | expect(fetchMock.requests().length).toEqual(0) 79 | } 80 | ) 81 | }) 82 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/__tests__/GetModelsForMake.test.ts: -------------------------------------------------------------------------------- 1 | import { beforeEach, describe, expect, it } from 'vitest' 2 | import { GetModelsForMake } from '../' 3 | 4 | // Mocks 5 | import { createMockResponse } from '.vitest/helpers' 6 | import { mockResults } from '.vitest/data' 7 | 8 | describe('api/endpoints/GetModelsForMake.ts', () => { 9 | it('exports GetModelsForMake function', () => { 10 | expect(GetModelsForMake).toBeDefined() 11 | expect(GetModelsForMake).toBeInstanceOf(Function) 12 | }) 13 | }) 14 | 15 | describe('GetModelsForMake', () => { 16 | const endpointName = 'GetModelsForMake' 17 | const makeName = 'Audi' 18 | 19 | const mockUrl = `https://vpic.nhtsa.dot.gov/api/vehicles/${endpointName}/${makeName}?format=json` 20 | 21 | const expectedFetchOptions = { 22 | saveUrl: true, 23 | method: 'GET', 24 | } 25 | 26 | beforeEach(() => { 27 | fetchMock.resetMocks() 28 | fetchMock.mockResolvedValue(createMockResponse(mockResults)) 29 | }) 30 | 31 | it('returns a Promise', () => { 32 | const response = GetModelsForMake(makeName) 33 | expect(response).toBeInstanceOf(Promise) 34 | }) 35 | 36 | /***************************** 37 | * doFetch = true (default) 38 | ****************************/ 39 | it('fetches data when provided makeName', async () => { 40 | const results = await GetModelsForMake(makeName) 41 | 42 | expect(results).toEqual(mockResults) 43 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 44 | expect(fetchMock.requests().length).toEqual(1) 45 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 46 | expect(fetchMock.requests()[0].method).toEqual('GET') 47 | }) 48 | 49 | it('fetches data when provided makeName and doFetch = true', async () => { 50 | const results = await GetModelsForMake(makeName, true) 51 | 52 | expect(results).toEqual(mockResults) 53 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 54 | expect(fetchMock.requests().length).toEqual(1) 55 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 56 | expect(fetchMock.requests()[0].method).toEqual('GET') 57 | }) 58 | 59 | /***************************** 60 | * doFetch = false 61 | ****************************/ 62 | it('returns url string when provided makeName and doFetch = false', async () => { 63 | const results = await GetModelsForMake(makeName, false) 64 | 65 | expect(results).toEqual(mockUrl) 66 | expect(fetchMock.requests().length).toEqual(0) 67 | }) 68 | 69 | /***************************** 70 | * rejects with error 71 | ***************************/ 72 | it.each([123, true, false, ['a', 'b'], { a: 'b' }, undefined, null])( 73 | 'rejects with error if makeName is not a string, %#', 74 | async (arg) => { 75 | await expect(() => 76 | GetModelsForMake(arg as unknown as string) 77 | ).rejects.toThrowError(/error validating argument named "makeName"/) 78 | 79 | expect(fetchMock.requests().length).toEqual(0) 80 | } 81 | ) 82 | }) 83 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/GetModelsForMakeId.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module api/endpoints/GetModelsForMakeId 3 | * @category API Endpoints 4 | */ 5 | 6 | import { useNHTSA } from '@/api' 7 | import { catchInvalidArguments, rejectWithError } from '@/utils' 8 | import type { IArgToValidate, NhtsaResponse } from '@/types' 9 | 10 | /** 11 | * ::: tip :bulb: More Information 12 | * See: [GetModelsForMakeId Documentation](/api/endpoints/get-models-for-make-id) 13 | * ::: 14 | * 15 | * `GetModelsForMakeId` returns the Models in the vPIC dataset for a specified Make whose ID is 16 | * equal to the `makeID` in the vPIC Dataset. 17 | * 18 | * You can get `makeID`s via `MAKE_ID` key in Results objects of the following endpoints: 19 | * - `GetAllMakes` endpoint 20 | * - `GetMakeForManufacturer` endpoint 21 | * - `GetModelsForMake` endpoint 22 | * - `GetModelsForMakeYear` endpoint 23 | * 24 | * You can get `makeID`s via `MakeID` key in Results objects of the following endpoints: 25 | * - `DecodeVinValues` 26 | * - `DecodeVinValuesBatch` 27 | * 28 | * You can get `makeID`s via `ValueId` key in Results objects of the following endpoints. 29 | * One of the objects in the `Results` array will contain both `Variable: "Make"` and 30 | * `VariableId: 26`. The `ValueId` key in that same object is the `makeID` for use in this 31 | * endpoint. 32 | * - `DecodeVin` 33 | * - `DecodeVinExtended` 34 | * 35 | * @param {(string|number)} makeId - Make ID to search 36 | * @param {boolean} [doFetch=true] - Whether to fetch the data or just return the URL 37 | * (default: `true`) 38 | * @returns {(Promise | string>)} - Api Response `object` 39 | * -or- url `string` if `doFetch = false` 40 | */ 41 | function GetModelsForMakeId( 42 | makeId: string | number, 43 | doFetch?: true 44 | ): Promise> 45 | 46 | function GetModelsForMakeId( 47 | makeId: string | number, 48 | doFetch: false 49 | ): Promise 50 | 51 | async function GetModelsForMakeId( 52 | makeId: string | number, 53 | doFetch = true 54 | ): Promise | string> { 55 | const endpointName = 'GetModelsForMakeId' 56 | 57 | try { 58 | const args: IArgToValidate[] = [ 59 | { 60 | name: 'makeId', 61 | value: makeId, 62 | required: true, 63 | types: ['string', 'number'], 64 | }, 65 | ] 66 | catchInvalidArguments({ args }) 67 | 68 | const { get, createCachedUrl, getCachedUrl } = useNHTSA() 69 | 70 | createCachedUrl({ endpointName, path: makeId.toString() }) 71 | 72 | if (!doFetch) { 73 | return getCachedUrl() 74 | } else { 75 | return get() 76 | } 77 | } catch (error) { 78 | return rejectWithError(error) 79 | } 80 | } 81 | 82 | export { GetModelsForMakeId } 83 | 84 | /** 85 | * Objects found in the `Results` array of `GetModelsForMakeId` endpoint response. 86 | */ 87 | export type GetModelsForMakeIdResults = { 88 | Make_ID: number 89 | Make_Name: string 90 | Model_ID: number 91 | Model_Name: string 92 | } 93 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/__tests__/GetVehicleTypesForMake.test.ts: -------------------------------------------------------------------------------- 1 | import { beforeEach, describe, expect, it } from 'vitest' 2 | import { GetVehicleTypesForMake } from '../' 3 | 4 | // Mocks 5 | import { createMockResponse } from '.vitest/helpers' 6 | import { mockResults } from '.vitest/data' 7 | 8 | describe('api/endpoints/GetVehicleTypesForMake.ts', () => { 9 | it('exports GetVehicleTypesForMake function', () => { 10 | expect(GetVehicleTypesForMake).toBeDefined() 11 | expect(GetVehicleTypesForMake).toBeInstanceOf(Function) 12 | }) 13 | }) 14 | 15 | describe('GetVehicleTypesForMake', () => { 16 | const endpointName = 'GetVehicleTypesForMake' 17 | const makeName = 'WVW' 18 | const mockUrl = `https://vpic.nhtsa.dot.gov/api/vehicles/${endpointName}/${makeName}?format=json` 19 | 20 | const expectedFetchOptions = { 21 | saveUrl: true, 22 | method: 'GET', 23 | } 24 | 25 | beforeEach(() => { 26 | fetchMock.resetMocks() 27 | fetchMock.mockResolvedValue(createMockResponse(mockResults)) 28 | }) 29 | 30 | it('returns a Promise', () => { 31 | const response = GetVehicleTypesForMake('test') 32 | expect(response).toBeInstanceOf(Promise) 33 | }) 34 | 35 | /***************************** 36 | * doFetch = true (default) 37 | ****************************/ 38 | it('fetches data when provided makeName only', async () => { 39 | const results = await GetVehicleTypesForMake(makeName) 40 | 41 | expect(results).toEqual(mockResults) 42 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 43 | expect(fetchMock.requests().length).toEqual(1) 44 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 45 | expect(fetchMock.requests()[0].method).toEqual('GET') 46 | }) 47 | 48 | it('fetches data when provided makeName and doFetch = true', async () => { 49 | const results = await GetVehicleTypesForMake(makeName, true) 50 | 51 | expect(results).toEqual(mockResults) 52 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 53 | expect(fetchMock.requests().length).toEqual(1) 54 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 55 | expect(fetchMock.requests()[0].method).toEqual('GET') 56 | }) 57 | 58 | /***************************** 59 | * doFetch = false 60 | ****************************/ 61 | it('returns url string when provided makeName and doFetch = false', async () => { 62 | const results = await GetVehicleTypesForMake(makeName, false) 63 | 64 | expect(results).toEqual(mockUrl) 65 | expect(fetchMock.requests().length).toEqual(0) 66 | }) 67 | 68 | /***************************** 69 | * rejects with error 70 | ***************************/ 71 | it.each([1234, ['a', 'b'], { a: 'b' }, null, undefined])( 72 | 'rejects with error if makeName is not a string, %#', 73 | async (arg) => { 74 | await expect(() => 75 | GetVehicleTypesForMake(arg as unknown as string) 76 | ).rejects.toThrowError(/error validating argument named "makeName"/) 77 | 78 | expect(fetchMock.requests().length).toEqual(0) 79 | } 80 | ) 81 | }) 82 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/api_endpoints_GetModelsForMake.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / api/endpoints/GetModelsForMake 2 | 3 | # Module: api/endpoints/GetModelsForMake 4 | 5 | ## Table of contents 6 | 7 | ### Type Aliases 8 | 9 | - [GetModelsForMakeResults](api_endpoints_GetModelsForMake.md#getmodelsformakeresults) 10 | 11 | ### Functions 12 | 13 | - [GetModelsForMake](api_endpoints_GetModelsForMake.md#getmodelsformake) 14 | 15 | ## Type Aliases 16 | 17 | ### GetModelsForMakeResults 18 | 19 | Ƭ **GetModelsForMakeResults**: `Object` 20 | 21 | Objects found in the `Results` array of `GetModelsForMake` endpoint response. 22 | 23 | #### Type declaration 24 | 25 | | Name | Type | 26 | | :----------- | :------- | 27 | | `Make_ID` | `number` | 28 | | `Make_Name` | `string` | 29 | | `Model_ID` | `number` | 30 | | `Model_Name` | `string` | 31 | 32 | #### Defined in 33 | 34 | [api/endpoints/GetModelsForMake.ts:71](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetModelsForMake.ts#L71) 35 | 36 | ## Functions 37 | 38 | ### GetModelsForMake 39 | 40 | ▸ **GetModelsForMake**(`makeName`, `doFetch?`): `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`GetModelsForMakeResults`](api_endpoints_GetModelsForMake.md#getmodelsformakeresults)\>\> 41 | 42 | ::: tip :bulb: More Information 43 | See: [GetModelsForMake Documentation](/api/endpoints/get-models-for-make) 44 | ::: 45 | 46 | `GetModelsForMake` returns the Models in the vPIC dataset for a specified `makeName` 47 | whose Name is LIKE the Make in vPIC Dataset. 48 | 49 | `makeName` can be a partial, or a full for more specificity, e.g., "Harley", 50 | "Harley Davidson", etc. 51 | 52 | #### Parameters 53 | 54 | | Name | Type | Description | 55 | | :--------- | :------- | :----------------------------------------------------------------- | 56 | | `makeName` | `string` | Vehicle make name | 57 | | `doFetch?` | `true` | Whether to fetch the data or just return the URL (default: `true`) | 58 | 59 | #### Returns 60 | 61 | `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`GetModelsForMakeResults`](api_endpoints_GetModelsForMake.md#getmodelsformakeresults)\>\> 62 | 63 | - Api Response object 64 | 65 | - Api Response `object` 66 | -or- url `string` if `doFetch = false` 67 | 68 | #### Defined in 69 | 70 | [api/endpoints/GetModelsForMake.ts:28](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetModelsForMake.ts#L28) 71 | 72 | ▸ **GetModelsForMake**(`makeName`, `doFetch`): `Promise`<`string`\> 73 | 74 | #### Parameters 75 | 76 | | Name | Type | 77 | | :--------- | :------- | 78 | | `makeName` | `string` | 79 | | `doFetch` | `false` | 80 | 81 | #### Returns 82 | 83 | `Promise`<`string`\> 84 | 85 | #### Defined in 86 | 87 | [api/endpoints/GetModelsForMake.ts:33](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetModelsForMake.ts#L33) 88 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/__tests__/GetVehicleTypesForMakeId.test.ts: -------------------------------------------------------------------------------- 1 | import { beforeEach, describe, expect, it } from 'vitest' 2 | import { GetVehicleTypesForMakeId } from '../' 3 | 4 | // Mocks 5 | import { createMockResponse } from '.vitest/helpers' 6 | import { mockResults } from '.vitest/data' 7 | 8 | describe('api/endpoints/GetVehicleTypesForMakeId.ts', () => { 9 | it('exports GetVehicleTypesForMakeId function', () => { 10 | expect(GetVehicleTypesForMakeId).toBeDefined() 11 | expect(GetVehicleTypesForMakeId).toBeInstanceOf(Function) 12 | }) 13 | }) 14 | 15 | describe('GetVehicleTypesForMakeId', () => { 16 | const endpointName = 'GetVehicleTypesForMakeId' 17 | const makeId = 'WVW' 18 | const mockUrl = `https://vpic.nhtsa.dot.gov/api/vehicles/${endpointName}/${makeId}?format=json` 19 | 20 | const expectedFetchOptions = { 21 | saveUrl: true, 22 | method: 'GET', 23 | } 24 | 25 | beforeEach(() => { 26 | fetchMock.resetMocks() 27 | fetchMock.mockResolvedValue(createMockResponse(mockResults)) 28 | }) 29 | 30 | it('returns a Promise', () => { 31 | const response = GetVehicleTypesForMakeId('test') 32 | expect(response).toBeInstanceOf(Promise) 33 | }) 34 | 35 | /***************************** 36 | * doFetch = true (default) 37 | ****************************/ 38 | it('fetches data when provided makeId only', async () => { 39 | const results = await GetVehicleTypesForMakeId(makeId) 40 | 41 | expect(results).toEqual(mockResults) 42 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 43 | expect(fetchMock.requests().length).toEqual(1) 44 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 45 | expect(fetchMock.requests()[0].method).toEqual('GET') 46 | }) 47 | 48 | it('fetches data when provided makeId and doFetch = true', async () => { 49 | const results = await GetVehicleTypesForMakeId(makeId, true) 50 | 51 | expect(results).toEqual(mockResults) 52 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 53 | expect(fetchMock.requests().length).toEqual(1) 54 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 55 | expect(fetchMock.requests()[0].method).toEqual('GET') 56 | }) 57 | 58 | /***************************** 59 | * doFetch = false 60 | ****************************/ 61 | it('returns url string when provided makeId and doFetch = false', async () => { 62 | const results = await GetVehicleTypesForMakeId(makeId, false) 63 | 64 | expect(results).toEqual(mockUrl) 65 | expect(fetchMock.requests().length).toEqual(0) 66 | }) 67 | 68 | /***************************** 69 | * rejects with error 70 | ***************************/ 71 | it.each([['a', 'b'], { a: 'b' }, null, undefined])( 72 | 'rejects with error if makeId is neither a string nor number, %#', 73 | async (arg) => { 74 | await expect(() => 75 | GetVehicleTypesForMakeId(arg as unknown as string) 76 | ).rejects.toThrowError(/error validating argument named "makeId"/) 77 | 78 | expect(fetchMock.requests().length).toEqual(0) 79 | } 80 | ) 81 | }) 82 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/__tests__/GetMakesForVehicleType.test.ts: -------------------------------------------------------------------------------- 1 | import { beforeEach, describe, expect, it } from 'vitest' 2 | import { GetMakesForVehicleType } from '../' 3 | 4 | // Mocks 5 | import { createMockResponse } from '.vitest/helpers' 6 | import { mockResults } from '.vitest/data' 7 | 8 | describe('api/endpoints/GetMakesForVehicleType.ts', () => { 9 | it('exports GetMakesForVehicleType function', () => { 10 | expect(GetMakesForVehicleType).toBeDefined() 11 | expect(GetMakesForVehicleType).toBeInstanceOf(Function) 12 | }) 13 | }) 14 | 15 | describe('GetMakesForVehicleType', () => { 16 | const endpointName = 'GetMakesForVehicleType' 17 | const typeName = 'Moto' 18 | 19 | const mockUrl = `https://vpic.nhtsa.dot.gov/api/vehicles/${endpointName}/${typeName}?format=json` 20 | 21 | const expectedFetchOptions = { 22 | saveUrl: true, 23 | method: 'GET', 24 | } 25 | 26 | beforeEach(() => { 27 | fetchMock.resetMocks() 28 | fetchMock.mockResolvedValue(createMockResponse(mockResults)) 29 | }) 30 | 31 | it('returns a Promise', () => { 32 | const response = GetMakesForVehicleType(typeName) 33 | expect(response).toBeInstanceOf(Promise) 34 | }) 35 | 36 | /***************************** 37 | * doFetch = true (default) 38 | ****************************/ 39 | it('fetches data when provided typeName', async () => { 40 | const results = await GetMakesForVehicleType(typeName) 41 | 42 | expect(results).toEqual(mockResults) 43 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 44 | expect(fetchMock.requests().length).toEqual(1) 45 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 46 | expect(fetchMock.requests()[0].method).toEqual('GET') 47 | }) 48 | 49 | it('fetches data when provided typeName and doFetch = true', async () => { 50 | const results = await GetMakesForVehicleType(typeName, true) 51 | 52 | expect(results).toEqual(mockResults) 53 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 54 | expect(fetchMock.requests().length).toEqual(1) 55 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 56 | expect(fetchMock.requests()[0].method).toEqual('GET') 57 | }) 58 | 59 | /***************************** 60 | * doFetch = false 61 | ****************************/ 62 | it('returns url string when provided typeName and doFetch = false', async () => { 63 | const results = await GetMakesForVehicleType(typeName, false) 64 | 65 | expect(results).toEqual(mockUrl) 66 | expect(fetchMock.requests().length).toEqual(0) 67 | }) 68 | 69 | /***************************** 70 | * rejects with error 71 | ***************************/ 72 | it.each([123, true, false, ['a', 'b'], { a: 'b' }, undefined, null])( 73 | 'rejects with error if typeName is not not a string, %#', 74 | async (arg) => { 75 | await expect(() => 76 | GetMakesForVehicleType(arg as unknown as string) 77 | ).rejects.toThrowError(/error validating argument named "typeName"/) 78 | 79 | expect(fetchMock.requests().length).toEqual(0) 80 | } 81 | ) 82 | }) 83 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/GetVehicleTypesForMakeId.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @module api/endpoints/GetVehicleTypesForMakeId 3 | * @category API Endpoints 4 | */ 5 | 6 | import { useNHTSA } from '@/api' 7 | import { catchInvalidArguments, rejectWithError } from '@/utils' 8 | import type { IArgToValidate, NhtsaResponse } from '@/types' 9 | 10 | /** 11 | * ::: tip :bulb: More Information 12 | * See: [GetVehicleTypesForMakeId Documentation](/api/endpoints/get-vehicle-types-for-make-id) 13 | * ::: 14 | * 15 | * `GetVehicleTypesForMakeId` returns the Models in the vPIC dataset for a specified Make 16 | * whose ID is equal to the `makeID` in the vPIC Dataset. 17 | * 18 | * You can get `makeID`s via `MAKE_ID` key in Results objects of the following endpoints: 19 | * - `GetAllMakes` endpoint 20 | * - `GetMakeForManufacturer` endpoint 21 | * - `GetModelsForMake` endpoint 22 | * - `GetModelsForMakeYear` endpoint 23 | * 24 | * You can get `makeID`s via `MakeID` key in Results objects of the following endpoints: 25 | * - `DecodeVinValues` 26 | * - `DecodeVinValuesBatch` 27 | * 28 | * You can get `makeID`s via `ValueId` key in Results objects of the following endpoints. 29 | * One of the objects in the `Results` array will contain both `Variable: "Make"` and 30 | * `VariableId: 26`. The `ValueId` key in that same object is the `makeID` for use in this 31 | * endpoint. 32 | * - `DecodeVin` 33 | * - `DecodeVinExtended` 34 | * 35 | * @param {(string|number)} makeId - Make ID to search 36 | * @param {boolean} [doFetch=true] - Whether to fetch the data or just return the URL 37 | * (default: `true`) 38 | * @returns {(Promise | string>)} - Api Response 39 | * `object` -or- url `string` if `doFetch = false` 40 | */ 41 | function GetVehicleTypesForMakeId( 42 | makeId: string | number, 43 | doFetch?: true 44 | ): Promise> 45 | 46 | function GetVehicleTypesForMakeId( 47 | makeId: string | number, 48 | doFetch: false 49 | ): Promise 50 | 51 | async function GetVehicleTypesForMakeId( 52 | makeId: string | number, 53 | doFetch = true 54 | ): Promise | string> { 55 | const endpointName = 'GetVehicleTypesForMakeId' 56 | 57 | try { 58 | const args: IArgToValidate[] = [ 59 | { 60 | name: 'makeId', 61 | value: makeId, 62 | required: true, 63 | types: ['string', 'number'], 64 | }, 65 | ] 66 | catchInvalidArguments({ args }) 67 | 68 | const { get, createCachedUrl, getCachedUrl } = useNHTSA() 69 | 70 | createCachedUrl({ endpointName, path: makeId.toString() }) 71 | 72 | if (!doFetch) { 73 | return getCachedUrl() 74 | } else { 75 | return get() 76 | } 77 | } catch (error) { 78 | return rejectWithError(error) 79 | } 80 | } 81 | 82 | export { GetVehicleTypesForMakeId } 83 | 84 | /** 85 | * Objects found in the `Results` array of `GetVehicleTypesForMakeId` endpoint response. 86 | */ 87 | export type GetVehicleTypesForMakeIdResults = { 88 | VehicleTypeId: number 89 | VehicleTypeName: string 90 | } 91 | -------------------------------------------------------------------------------- /apps/docs/src/snippets/endpoints/get-parts.ts: -------------------------------------------------------------------------------- 1 | // #region type-results 2 | type GetPartsResults = { 3 | CoverLetterURL: string 4 | LetterDate: string 5 | ManufacturerId: number 6 | ManufacturerName: string 7 | ModelYearFrom: number | null 8 | ModelYearTo: number | null 9 | Name: string 10 | Type: string 11 | URL: string 12 | } 13 | // #endregion type-results 14 | 15 | // #region example-response 16 | // Using GetParts({ type: 575, fromDate: '1/1/2015, toDate: `5/5/2015', manufacturer: hon }) 17 | const exampleResponse = { 18 | Count: 6, 19 | Message: 'Results returned successfully', 20 | Results: [ 21 | { 22 | CoverLetterURL: '', 23 | LetterDate: '4/30/2015', 24 | ManufacturerId: 987, 25 | ManufacturerName: 'HONDA MOTOR CO., LTD', 26 | ModelYearFrom: null, 27 | ModelYearTo: null, 28 | Name: 'ORG10655', 29 | Type: '565', 30 | URL: 'http://vpic.nhtsa.dot.gov/mid/home/displayfile/cf88fcd6-97e5-4b9a-bc6c-53f87eaf4ab3', 31 | }, 32 | { 33 | CoverLetterURL: '', 34 | LetterDate: '3/11/2015', 35 | ManufacturerId: 988, 36 | ManufacturerName: 'AMERICAN HONDA MOTOR CO., INC.', 37 | ModelYearFrom: null, 38 | ModelYearTo: null, 39 | Name: 'ORG10720', 40 | Type: '565', 41 | URL: 'http://vpic.nhtsa.dot.gov/mid/home/displayfile/0d1c7d12-b3d9-4a53-9d2c-56ab2b5ac235', 42 | }, 43 | { 44 | CoverLetterURL: '', 45 | LetterDate: '3/11/2015', 46 | ManufacturerId: 988, 47 | ManufacturerName: 'AMERICAN HONDA MOTOR CO., INC.', 48 | ModelYearFrom: null, 49 | ModelYearTo: null, 50 | Name: 'ORG10721', 51 | Type: '565', 52 | URL: 'http://vpic.nhtsa.dot.gov/mid/home/displayfile/3fee1b5a-c834-4074-8f03-6e1b73516ee0', 53 | }, 54 | { 55 | CoverLetterURL: '', 56 | LetterDate: '3/4/2015', 57 | ManufacturerId: 14236, 58 | ManufacturerName: 'CHONGQING SHINERAY MOTORCYCLE CO., LTD.', 59 | ModelYearFrom: null, 60 | ModelYearTo: null, 61 | Name: 'ORG11082', 62 | Type: '565', 63 | URL: 'http://vpic.nhtsa.dot.gov/mid/home/displayfile/f9a0be8f-e887-4491-acb1-f7bcdea9a26f', 64 | }, 65 | { 66 | CoverLetterURL: '', 67 | LetterDate: '2/26/2015', 68 | ManufacturerId: 988, 69 | ManufacturerName: 'AMERICAN HONDA MOTOR CO., INC.', 70 | ModelYearFrom: null, 71 | ModelYearTo: null, 72 | Name: 'ORG10727', 73 | Type: '565', 74 | URL: 'http://vpic.nhtsa.dot.gov/mid/home/displayfile/71f28292-1daf-4c6e-8cf1-6a9785489ad9', 75 | }, 76 | { 77 | CoverLetterURL: '', 78 | LetterDate: '1/28/2015', 79 | ManufacturerId: 987, 80 | ManufacturerName: 'HONDA MOTOR CO., LTD', 81 | ModelYearFrom: null, 82 | ModelYearTo: null, 83 | Name: 'ORG10651', 84 | Type: '565', 85 | URL: 'http://vpic.nhtsa.dot.gov/mid/home/displayfile/e591547b-0c65-4d7c-9803-00202c70868f', 86 | }, 87 | ], 88 | SearchCriteria: 89 | 'Type: 565 | From Date: 1/1/2015 | To Date: 5/5/2015 | manufacturer: hon', 90 | } 91 | // #endregion example-response 92 | 93 | export type { GetPartsResults } 94 | export { exampleResponse } 95 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](index.md) / Exports 2 | 3 | # @shaggytools/nhtsa-api-wrapper - v3.0.4 4 | 5 | ## Table of contents 6 | 7 | ### API Modules 8 | 9 | - [api](modules/api.md) 10 | - [api/useNHTSA](modules/api_useNHTSA.md) 11 | 12 | ### API Endpoints Modules 13 | 14 | - [api/endpoints](modules/api_endpoints.md) 15 | - [api/endpoints/DecodeVin](modules/api_endpoints_DecodeVin.md) 16 | - [api/endpoints/DecodeVinExtended](modules/api_endpoints_DecodeVinExtended.md) 17 | - [api/endpoints/DecodeVinValues](modules/api_endpoints_DecodeVinValues.md) 18 | - [api/endpoints/DecodeVinValuesBatch](modules/api_endpoints_DecodeVinValuesBatch.md) 19 | - [api/endpoints/DecodeVinValuesExtended](modules/api_endpoints_DecodeVinValuesExtended.md) 20 | - [api/endpoints/DecodeWMI](modules/api_endpoints_DecodeWMI.md) 21 | - [api/endpoints/GetAllMakes](modules/api_endpoints_GetAllMakes.md) 22 | - [api/endpoints/GetAllManufacturers](modules/api_endpoints_GetAllManufacturers.md) 23 | - [api/endpoints/GetCanadianVehicleSpecifications](modules/api_endpoints_GetCanadianVehicleSpecifications.md) 24 | - [api/endpoints/GetEquipmentPlantCodes](modules/api_endpoints_GetEquipmentPlantCodes.md) 25 | - [api/endpoints/GetMakeForManufacturer](modules/api_endpoints_GetMakeForManufacturer.md) 26 | - [api/endpoints/GetMakesForManufacturerAndYear](modules/api_endpoints_GetMakesForManufacturerAndYear.md) 27 | - [api/endpoints/GetMakesForVehicleType](modules/api_endpoints_GetMakesForVehicleType.md) 28 | - [api/endpoints/GetManufacturerDetails](modules/api_endpoints_GetManufacturerDetails.md) 29 | - [api/endpoints/GetModelsForMake](modules/api_endpoints_GetModelsForMake.md) 30 | - [api/endpoints/GetModelsForMakeId](modules/api_endpoints_GetModelsForMakeId.md) 31 | - [api/endpoints/GetModelsForMakeIdYear](modules/api_endpoints_GetModelsForMakeIdYear.md) 32 | - [api/endpoints/GetModelsForMakeYear](modules/api_endpoints_GetModelsForMakeYear.md) 33 | - [api/endpoints/GetParts](modules/api_endpoints_GetParts.md) 34 | - [api/endpoints/GetVehicleTypesForMake](modules/api_endpoints_GetVehicleTypesForMake.md) 35 | - [api/endpoints/GetVehicleTypesForMakeId](modules/api_endpoints_GetVehicleTypesForMakeId.md) 36 | - [api/endpoints/GetVehicleVariableList](modules/api_endpoints_GetVehicleVariableList.md) 37 | - [api/endpoints/GetVehicleVariableValuesList](modules/api_endpoints_GetVehicleVariableValuesList.md) 38 | - [api/endpoints/GetWMIsForManufacturer](modules/api_endpoints_GetWMIsForManufacturer.md) 39 | 40 | ### Other Modules 41 | 42 | - [constants](modules/constants.md) 43 | - [global](modules/global.md) 44 | - [index](modules/index.md) 45 | - [vite-env](modules/vite_env.md) 46 | 47 | ### Types Modules 48 | 49 | - [api/endpoints/types](modules/api_endpoints_types.md) 50 | - [api/types](modules/api_types.md) 51 | - [types](modules/types.md) 52 | - [utils/types](modules/utils_types.md) 53 | 54 | ### Utility Functions Modules 55 | 56 | - [utils](modules/utils.md) 57 | - [utils/argHandler](modules/utils_argHandler.md) 58 | - [utils/errorHandler](modules/utils_errorHandler.md) 59 | - [utils/getTypeof](modules/utils_getTypeof.md) 60 | - [utils/isValidVin](modules/utils_isValidVin.md) 61 | - [utils/queryString](modules/utils_queryString.md) 62 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/__tests__/GetVehicleVariableValuesList.test.ts: -------------------------------------------------------------------------------- 1 | import { beforeEach, describe, expect, it } from 'vitest' 2 | import { GetVehicleVariableValuesList } from '../' 3 | 4 | // Mocks 5 | import { createMockResponse } from '.vitest/helpers' 6 | import { mockResults } from '.vitest/data' 7 | 8 | describe('api/endpoints/GetVehicleVariableValuesList.ts', () => { 9 | it('exports GetVehicleVariableValuesList function', () => { 10 | expect(GetVehicleVariableValuesList).toBeDefined() 11 | expect(GetVehicleVariableValuesList).toBeInstanceOf(Function) 12 | }) 13 | }) 14 | 15 | describe('GetVehicleVariableValuesList', () => { 16 | const endpointName = 'GetVehicleVariableValuesList' 17 | const variableValue = 'WVW' 18 | const mockUrl = `https://vpic.nhtsa.dot.gov/api/vehicles/${endpointName}/${variableValue}?format=json` 19 | 20 | const expectedFetchOptions = { 21 | saveUrl: true, 22 | method: 'GET', 23 | } 24 | 25 | beforeEach(() => { 26 | fetchMock.resetMocks() 27 | fetchMock.mockResolvedValue(createMockResponse(mockResults)) 28 | }) 29 | 30 | it('returns a Promise', () => { 31 | const response = GetVehicleVariableValuesList('test') 32 | expect(response).toBeInstanceOf(Promise) 33 | }) 34 | 35 | /***************************** 36 | * doFetch = true (default) 37 | ****************************/ 38 | it('fetches data when provided variableValue only', async () => { 39 | const results = await GetVehicleVariableValuesList(variableValue) 40 | 41 | expect(results).toEqual(mockResults) 42 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 43 | expect(fetchMock.requests().length).toEqual(1) 44 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 45 | expect(fetchMock.requests()[0].method).toEqual('GET') 46 | }) 47 | 48 | it('fetches data when provided variableValue and doFetch = true', async () => { 49 | const results = await GetVehicleVariableValuesList(variableValue, true) 50 | 51 | expect(results).toEqual(mockResults) 52 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 53 | expect(fetchMock.requests().length).toEqual(1) 54 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 55 | expect(fetchMock.requests()[0].method).toEqual('GET') 56 | }) 57 | 58 | /***************************** 59 | * doFetch = false 60 | ****************************/ 61 | it('returns url string when provided variableValue and doFetch = false', async () => { 62 | const results = await GetVehicleVariableValuesList(variableValue, false) 63 | 64 | expect(results).toEqual(mockUrl) 65 | expect(fetchMock.requests().length).toEqual(0) 66 | }) 67 | 68 | /***************************** 69 | * rejects with error 70 | ***************************/ 71 | it.each([['a', 'b'], { a: 'b' }, null, undefined])( 72 | 'rejects with error if variableValue is neither a string nor number, %#', 73 | async (arg) => { 74 | await expect(() => 75 | GetVehicleVariableValuesList(arg as unknown as string) 76 | ).rejects.toThrowError(/error validating argument named "variableValue"/) 77 | 78 | expect(fetchMock.requests().length).toEqual(0) 79 | } 80 | ) 81 | }) 82 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | Using welcoming and inclusive language 12 | Being respectful of differing viewpoints and experiences 13 | Gracefully accepting constructive criticism 14 | Focusing on what is best for the community 15 | Showing empathy towards other community members 16 | Examples of unacceptable behavior by participants include: 17 | 18 | The use of sexualized language or imagery and unwelcome sexual attention or advances 19 | Trolling, insulting/derogatory comments, and personal or political attacks 20 | Public or private harassment 21 | Publishing others' private information, such as a physical or electronic address, without explicit permission 22 | Other conduct which could reasonably be considered inappropriate in a professional setting 23 | Our Responsibilities 24 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 25 | 26 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 27 | 28 | ## Scope 29 | 30 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 31 | 32 | ## Enforcement 33 | 34 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at beedat1@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 35 | 36 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 37 | 38 | ## Attribution 39 | 40 | This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at [http://contributor-covenant.org/version/1/4](http://contributor-covenant.org/version/1/4). 41 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/api_endpoints_GetVehicleTypesForMake.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / api/endpoints/GetVehicleTypesForMake 2 | 3 | # Module: api/endpoints/GetVehicleTypesForMake 4 | 5 | ## Table of contents 6 | 7 | ### Type Aliases 8 | 9 | - [GetVehicleTypesForMakeResults](api_endpoints_GetVehicleTypesForMake.md#getvehicletypesformakeresults) 10 | 11 | ### Functions 12 | 13 | - [GetVehicleTypesForMake](api_endpoints_GetVehicleTypesForMake.md#getvehicletypesformake) 14 | 15 | ## Type Aliases 16 | 17 | ### GetVehicleTypesForMakeResults 18 | 19 | Ƭ **GetVehicleTypesForMakeResults**: `Object` 20 | 21 | Objects found in the `Results` array of `GetVehicleTypesForMake` endpoint response. 22 | 23 | #### Type declaration 24 | 25 | | Name | Type | 26 | | :---------------- | :------- | 27 | | `MakeId` | `number` | 28 | | `MakeName` | `string` | 29 | | `VehicleTypeId` | `number` | 30 | | `VehicleTypeName` | `string` | 31 | 32 | #### Defined in 33 | 34 | [api/endpoints/GetVehicleTypesForMake.ts:73](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetVehicleTypesForMake.ts#L73) 35 | 36 | ## Functions 37 | 38 | ### GetVehicleTypesForMake 39 | 40 | ▸ **GetVehicleTypesForMake**(`makeName`, `doFetch?`): `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`GetVehicleTypesForMakeResults`](api_endpoints_GetVehicleTypesForMake.md#getvehicletypesformakeresults)\>\> 41 | 42 | ::: tip :bulb: More Information 43 | See: [GetVehicleTypesForMake Documentation](/api/endpoints/get-vehicle-types-for-make) 44 | ::: 45 | 46 | `GetVehicleTypesForMake` returns all the Vehicle Types in the vPIC dataset for a specified Make, 47 | whose name is LIKE the make name in the vPIC Dataset. 48 | 49 | `makeName` can be a partial name, or a full name for more specificity, e.g., "Merc", 50 | "Mercedes Benz", etc. 51 | 52 | #### Parameters 53 | 54 | | Name | Type | Description | 55 | | :--------- | :------- | :----------------------------------------------------------------- | 56 | | `makeName` | `string` | Name of the vehicle make to search | 57 | | `doFetch?` | `true` | Whether to fetch the data or just return the URL (default: `true`) | 58 | 59 | #### Returns 60 | 61 | `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`GetVehicleTypesForMakeResults`](api_endpoints_GetVehicleTypesForMake.md#getvehicletypesformakeresults)\>\> 62 | 63 | - Api Response 64 | `object` -or- url `string` if `doFetch = false` 65 | 66 | #### Defined in 67 | 68 | [api/endpoints/GetVehicleTypesForMake.ts:27](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetVehicleTypesForMake.ts#L27) 69 | 70 | ▸ **GetVehicleTypesForMake**(`makeName`, `doFetch`): `Promise`<`string`\> 71 | 72 | #### Parameters 73 | 74 | | Name | Type | 75 | | :--------- | :------- | 76 | | `makeName` | `string` | 77 | | `doFetch` | `false` | 78 | 79 | #### Returns 80 | 81 | `Promise`<`string`\> 82 | 83 | #### Defined in 84 | 85 | [api/endpoints/GetVehicleTypesForMake.ts:32](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetVehicleTypesForMake.ts#L32) 86 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/api_endpoints_GetMakesForVehicleType.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / api/endpoints/GetMakesForVehicleType 2 | 3 | # Module: api/endpoints/GetMakesForVehicleType 4 | 5 | ## Table of contents 6 | 7 | ### Type Aliases 8 | 9 | - [GetMakesForVehicleTypeResults](api_endpoints_GetMakesForVehicleType.md#getmakesforvehicletyperesults) 10 | 11 | ### Functions 12 | 13 | - [GetMakesForVehicleType](api_endpoints_GetMakesForVehicleType.md#getmakesforvehicletype) 14 | 15 | ## Type Aliases 16 | 17 | ### GetMakesForVehicleTypeResults 18 | 19 | Ƭ **GetMakesForVehicleTypeResults**: `Object` 20 | 21 | Objects found in the `Results` array of `GetMakesForVehicleType` endpoint response. 22 | 23 | #### Type declaration 24 | 25 | | Name | Type | 26 | | :---------------- | :------- | 27 | | `MakeId` | `number` | 28 | | `MakeName` | `string` | 29 | | `VehicleTypeId` | `number` | 30 | | `VehicleTypeName` | `string` | 31 | 32 | #### Defined in 33 | 34 | [api/endpoints/GetMakesForVehicleType.ts:73](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetMakesForVehicleType.ts#L73) 35 | 36 | ## Functions 37 | 38 | ### GetMakesForVehicleType 39 | 40 | ▸ **GetMakesForVehicleType**(`typeName`, `doFetch?`): `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`GetMakesForVehicleTypeResults`](api_endpoints_GetMakesForVehicleType.md#getmakesforvehicletyperesults)\>\> 41 | 42 | ::: tip :bulb: More Information 43 | See: [GetMakesForVehicleType Documentation](/api/endpoints/get-makes-for-vehicle-type) 44 | ::: 45 | 46 | `GetMakesForVehicleType` returns all the Makes in the vPIC dataset for a specified vehicle type 47 | (`typeName`), whose name is LIKE the vehicle type name in vPIC Dataset. 48 | 49 | `typeName` can be a partial name, or a full name for more specificity, e.g., "Vehicle", "Moto", 50 | "Low Speed Vehicle", etc. 51 | 52 | #### Parameters 53 | 54 | | Name | Type | Description | 55 | | :--------- | :------- | :----------------------------------------------------------------- | 56 | | `typeName` | `string` | A partial or full vehicle type name | 57 | | `doFetch?` | `true` | Whether to fetch the data or just return the URL (default: `true`) | 58 | 59 | #### Returns 60 | 61 | `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`GetMakesForVehicleTypeResults`](api_endpoints_GetMakesForVehicleType.md#getmakesforvehicletyperesults)\>\> 62 | 63 | - Api Response 64 | `object` -or- url `string` if `doFetch = false` 65 | 66 | #### Defined in 67 | 68 | [api/endpoints/GetMakesForVehicleType.ts:27](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetMakesForVehicleType.ts#L27) 69 | 70 | ▸ **GetMakesForVehicleType**(`typeName`, `doFetch`): `Promise`<`string`\> 71 | 72 | #### Parameters 73 | 74 | | Name | Type | 75 | | :--------- | :------- | 76 | | `typeName` | `string` | 77 | | `doFetch` | `false` | 78 | 79 | #### Returns 80 | 81 | `Promise`<`string`\> 82 | 83 | #### Defined in 84 | 85 | [api/endpoints/GetMakesForVehicleType.ts:32](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetMakesForVehicleType.ts#L32) 86 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/api_endpoints_GetVehicleVariableList.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / api/endpoints/GetVehicleVariableList 2 | 3 | # Module: api/endpoints/GetVehicleVariableList 4 | 5 | ## Table of contents 6 | 7 | ### Type Aliases 8 | 9 | - [GetVehicleVariableListResults](api_endpoints_GetVehicleVariableList.md#getvehiclevariablelistresults) 10 | 11 | ### Functions 12 | 13 | - [GetVehicleVariableList](api_endpoints_GetVehicleVariableList.md#getvehiclevariablelist) 14 | 15 | ## Type Aliases 16 | 17 | ### GetVehicleVariableListResults 18 | 19 | Ƭ **GetVehicleVariableListResults**: `Object` 20 | 21 | Objects found in the `Results` array of `GetVehicleVariableList` endpoint response. 22 | 23 | #### Type declaration 24 | 25 | | Name | Type | 26 | | :------------ | :------------------------------------------------- | 27 | | `DataType` | `"string"` \| `"int"` \| `"decimal"` \| `"lookup"` | 28 | | `Description` | `string` | 29 | | `GroupName` | `string` \| `null` | 30 | | `ID` | `number` | 31 | | `Name` | `string` | 32 | 33 | #### Defined in 34 | 35 | [api/endpoints/GetVehicleVariableList.ts:54](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetVehicleVariableList.ts#L54) 36 | 37 | ## Functions 38 | 39 | ### GetVehicleVariableList 40 | 41 | ▸ **GetVehicleVariableList**(`doFetch?`): `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`GetVehicleVariableListResults`](api_endpoints_GetVehicleVariableList.md#getvehiclevariablelistresults)\>\> 42 | 43 | ::: tip :bulb: More Information 44 | See: [GetVehicleVariableList Documentation](/api/endpoints/get-vehicle-variable-list) 45 | ::: 46 | 47 | `GetVehicleVariableList` provides a list of all the Vehicle related variables that are in the 48 | vPIC dataset. Information on the name, description and the type of the variable is provided. 49 | 50 | #### Parameters 51 | 52 | | Name | Type | Description | 53 | | :--------- | :----- | :----------------------------------------------------------------- | 54 | | `doFetch?` | `true` | Whether to fetch the data or just return the URL (default: `true`) | 55 | 56 | #### Returns 57 | 58 | `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`GetVehicleVariableListResults`](api_endpoints_GetVehicleVariableList.md#getvehiclevariablelistresults)\>\> 59 | 60 | - Api Response 61 | `object` -or- url `string` if `doFetch = false` 62 | 63 | #### Defined in 64 | 65 | [api/endpoints/GetVehicleVariableList.ts:23](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetVehicleVariableList.ts#L23) 66 | 67 | ▸ **GetVehicleVariableList**(`doFetch`): `Promise`<`string`\> 68 | 69 | #### Parameters 70 | 71 | | Name | Type | 72 | | :-------- | :------ | 73 | | `doFetch` | `false` | 74 | 75 | #### Returns 76 | 77 | `Promise`<`string`\> 78 | 79 | #### Defined in 80 | 81 | [api/endpoints/GetVehicleVariableList.ts:27](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetVehicleVariableList.ts#L27) 82 | -------------------------------------------------------------------------------- /apps/docs/src/snippets/endpoints/get-manufacturer-details.ts: -------------------------------------------------------------------------------- 1 | // #region type-results 2 | type GetManufacturerDetailsResults = { 3 | Address: string | null 4 | Address2: string | null 5 | City: string | null 6 | ContactEmail: string | null 7 | ContactFax: string | null 8 | ContactPhone: string | null 9 | Country: string | null 10 | DBAs: string | null 11 | EquipmentItems: Array 12 | LastUpdated: string 13 | ManufacturerTypes: Array<{ 14 | Name: string 15 | }> 16 | Mfr_CommonName: string | null 17 | Mfr_ID: number | null 18 | Mfr_Name: string | null 19 | OtherManufacturerDetails: string | null 20 | PostalCode: string | null 21 | PrimaryProduct: string | null 22 | PrincipalFirstName: string | null 23 | PrincipalLastName: string | null 24 | PrincipalPosition: string | null 25 | StateProvince: string | null 26 | SubmittedName: string | null 27 | SubmittedOn: string 28 | SubmittedPosition: string | null 29 | VehicleTypes: Array<{ 30 | GVWRFrom: string 31 | GVWRTo: string 32 | IsPrimary: boolean 33 | Name: string 34 | }> 35 | } 36 | // #endregion type-results 37 | 38 | // #region example-response 39 | // Using GetMakesForVehicleType('truck') - truncated for brevity 40 | const exampleResponse = { 41 | Count: 1, 42 | Message: 'Response returned successfully', 43 | Results: [ 44 | { 45 | Address: '1 Tesla Road', 46 | Address2: null, 47 | City: 'Austin', 48 | ContactEmail: 'erwilliams@tesla.com', 49 | ContactFax: null, 50 | ContactPhone: '(508)272-8358', 51 | Country: 'UNITED STATES (USA)', 52 | DBAs: 'Tesla, Inc.', 53 | EquipmentItems: [], 54 | LastUpdated: '/Date(1665153455790-0400)/', 55 | ManufacturerTypes: [ 56 | { 57 | Name: 'Completed Vehicle Manufacturer', 58 | }, 59 | ], 60 | Mfr_CommonName: 'Tesla', 61 | Mfr_ID: 955, 62 | Mfr_Name: 'TESLA, INC.', 63 | OtherManufacturerDetails: null, 64 | PostalCode: '78725', 65 | PrimaryProduct: null, 66 | PrincipalFirstName: 'Elon Musk', 67 | PrincipalLastName: null, 68 | PrincipalPosition: 'CEO', 69 | StateProvince: 'TEXAS', 70 | SubmittedName: 'David Kim', 71 | SubmittedOn: '/Date(1665152176543-0400)/', 72 | SubmittedPosition: 'Corporate Counsel, Regulatory', 73 | VehicleTypes: [ 74 | { 75 | GVWRFrom: 'Class 1A: 3,000 lb or less (1,360 kg or less)', 76 | GVWRTo: 'Class 1D: 5,001 - 6,000 lb (2,268 - 2,722 kg)', 77 | IsPrimary: true, 78 | Name: 'Passenger Car', 79 | }, 80 | { 81 | GVWRFrom: 'Class 8: 33,001 lb and above (14,969 kg and above)', 82 | GVWRTo: 'Class 8: 33,001 lb and above (14,969 kg and above)', 83 | IsPrimary: false, 84 | Name: 'Truck ', 85 | }, 86 | { 87 | GVWRFrom: 'Class 2E: 6,001 - 7,000 lb (2,722 - 3,175 kg)', 88 | GVWRTo: 'Class 2E: 6,001 - 7,000 lb (2,722 - 3,175 kg)', 89 | IsPrimary: false, 90 | Name: 'Multipurpose Passenger Vehicle (MPV)', 91 | }, 92 | ], 93 | }, 94 | ], 95 | SearchCriteria: null, 96 | } 97 | // #endregion example-response 98 | 99 | export type { GetManufacturerDetailsResults } 100 | export { exampleResponse } 101 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/__tests__/DecodeVinValuesBatch.test.ts: -------------------------------------------------------------------------------- 1 | import { beforeEach, describe, expect, it } from 'vitest' 2 | import { DecodeVinValuesBatch } from '../' 3 | 4 | // Mocks 5 | import { createMockResponse } from '.vitest/helpers' 6 | import { mockResults } from '.vitest/data' 7 | 8 | describe('api/endpoints/DecodeVinValuesBatch.ts', () => { 9 | it('exports DecodeVinValuesBatch function', () => { 10 | expect(DecodeVinValuesBatch).toBeDefined() 11 | expect(DecodeVinValuesBatch).toBeInstanceOf(Function) 12 | }) 13 | }) 14 | 15 | describe('DecodeVinValuesBatch', () => { 16 | const endpointName = 'DecodeVinValuesBatch' 17 | const inputString = '5UXWX7C5*BA, 2011; 5YJSA3DS*EF' 18 | const mockUrl = `https://vpic.nhtsa.dot.gov/api/vehicles/${endpointName}/` 19 | 20 | const expectedBody = `DATA=${encodeURI(inputString)}&format=json` 21 | const expectedFetchOptions = { 22 | body: expectedBody, 23 | headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, 24 | method: 'POST', 25 | } 26 | 27 | beforeEach(() => { 28 | fetchMock.resetMocks() 29 | fetchMock.mockResolvedValue(createMockResponse(mockResults)) 30 | }) 31 | 32 | it('returns a Promise', () => { 33 | const response = DecodeVinValuesBatch('test') 34 | expect(response).toBeInstanceOf(Promise) 35 | }) 36 | 37 | /***************************** 38 | * doFetch = true (default) 39 | ****************************/ 40 | it('fetches data when provided inputString only', async () => { 41 | const results = await DecodeVinValuesBatch(inputString) 42 | 43 | expect(results).toEqual(mockResults) 44 | expect(fetchMock).toBeCalledWith(mockUrl, expectedFetchOptions) 45 | expect(fetchMock.requests().length).toEqual(1) 46 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 47 | expect(fetchMock.requests()[0].method).toEqual('POST') 48 | }) 49 | 50 | it('fetches data when provided inputString and doFetch = true', async () => { 51 | const results = await DecodeVinValuesBatch(inputString, true) 52 | 53 | expect(results).toEqual(mockResults) 54 | expect(fetchMock).toBeCalledWith(mockUrl, expectedFetchOptions) 55 | expect(fetchMock.requests().length).toEqual(1) 56 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 57 | expect(fetchMock.requests()[0].method).toEqual('POST') 58 | }) 59 | 60 | /***************************** 61 | * doFetch = false 62 | ****************************/ 63 | it('returns url string when provided inputString and doFetch = false', async () => { 64 | const results = await DecodeVinValuesBatch(inputString, false) 65 | 66 | expect(results).toEqual(mockUrl) 67 | expect(fetchMock.requests().length).toEqual(0) 68 | }) 69 | 70 | /***************************** 71 | * rejects with error 72 | ***************************/ 73 | it('rejects with error if inputString is undefined', async () => { 74 | await expect(() => 75 | DecodeVinValuesBatch(undefined as unknown as string) 76 | ).rejects.toThrowError(/error validating argument named "inputString"/) 77 | 78 | expect(fetchMock.requests().length).toEqual(0) 79 | }) 80 | 81 | it.each([1234, ['a', 'b'], { a: 'b' }, null])( 82 | 'rejects with error if inputString is not a string, %#', 83 | async (arg) => { 84 | await expect(() => 85 | DecodeVinValuesBatch(arg as unknown as string) 86 | ).rejects.toThrowError(/error validating argument named "inputString"/) 87 | 88 | expect(fetchMock.requests().length).toEqual(0) 89 | } 90 | ) 91 | }) 92 | -------------------------------------------------------------------------------- /packages/lib/src/api/endpoints/__tests__/GetModelsForMakeId.test.ts: -------------------------------------------------------------------------------- 1 | import { beforeEach, describe, expect, it } from 'vitest' 2 | import { GetModelsForMakeId } from '../' 3 | 4 | // Mocks 5 | import { createMockResponse } from '.vitest/helpers' 6 | import { mockResults } from '.vitest/data' 7 | 8 | describe('api/endpoints/GetModelsForMakeId.ts', () => { 9 | it('exports GetModelsForMakeId function', () => { 10 | expect(GetModelsForMakeId).toBeDefined() 11 | expect(GetModelsForMakeId).toBeInstanceOf(Function) 12 | }) 13 | }) 14 | 15 | describe('GetModelsForMakeId', () => { 16 | const endpointName = 'GetModelsForMakeId' 17 | const makeIdString = '789' 18 | const makeIdNumber = 789 19 | 20 | const mockUrl = `https://vpic.nhtsa.dot.gov/api/vehicles/${endpointName}/${makeIdNumber}?format=json` 21 | 22 | const expectedFetchOptions = { 23 | saveUrl: true, 24 | method: 'GET', 25 | } 26 | 27 | beforeEach(() => { 28 | fetchMock.resetMocks() 29 | fetchMock.mockResolvedValue(createMockResponse(mockResults)) 30 | }) 31 | 32 | it('returns a Promise', () => { 33 | const response = GetModelsForMakeId(makeIdString) 34 | expect(response).toBeInstanceOf(Promise) 35 | }) 36 | 37 | /***************************** 38 | * doFetch = true (default) 39 | ****************************/ 40 | it('fetches data when provided makeId as a string', async () => { 41 | const results = await GetModelsForMakeId(makeIdString) 42 | 43 | expect(results).toEqual(mockResults) 44 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 45 | expect(fetchMock.requests().length).toEqual(1) 46 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 47 | expect(fetchMock.requests()[0].method).toEqual('GET') 48 | }) 49 | 50 | it('fetches data when provided makeId as a number', async () => { 51 | const results = await GetModelsForMakeId(makeIdNumber) 52 | 53 | expect(results).toEqual(mockResults) 54 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 55 | expect(fetchMock.requests().length).toEqual(1) 56 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 57 | expect(fetchMock.requests()[0].method).toEqual('GET') 58 | }) 59 | 60 | it('fetches data when provided makeId and doFetch = true', async () => { 61 | const results = await GetModelsForMakeId(makeIdNumber, true) 62 | 63 | expect(results).toEqual(mockResults) 64 | expect(fetchMock).toHaveBeenCalledWith(mockUrl, expectedFetchOptions) 65 | expect(fetchMock.requests().length).toEqual(1) 66 | expect(fetchMock.requests()[0].url).toEqual(mockUrl) 67 | expect(fetchMock.requests()[0].method).toEqual('GET') 68 | }) 69 | 70 | /***************************** 71 | * doFetch = false 72 | ****************************/ 73 | it('returns url string when provided makeId and doFetch = false', async () => { 74 | const results = await GetModelsForMakeId(makeIdNumber, false) 75 | 76 | expect(results).toEqual(mockUrl) 77 | expect(fetchMock.requests().length).toEqual(0) 78 | }) 79 | 80 | /***************************** 81 | * rejects with error 82 | ***************************/ 83 | it.each([true, false, ['a', 'b'], { a: 'b' }, undefined, null])( 84 | 'rejects with error if makeId is neither a string nor number, %#', 85 | async (arg) => { 86 | await expect(() => 87 | GetModelsForMakeId(arg as unknown as string) 88 | ).rejects.toThrowError(/error validating argument named "makeId"/) 89 | 90 | expect(fetchMock.requests().length).toEqual(0) 91 | } 92 | ) 93 | }) 94 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/api_endpoints_DecodeWMI.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / api/endpoints/DecodeWMI 2 | 3 | # Module: api/endpoints/DecodeWMI 4 | 5 | ## Table of contents 6 | 7 | ### Type Aliases 8 | 9 | - [DecodeWMIResults](api_endpoints_DecodeWMI.md#decodewmiresults) 10 | 11 | ### Functions 12 | 13 | - [DecodeWMI](api_endpoints_DecodeWMI.md#decodewmi) 14 | 15 | ## Type Aliases 16 | 17 | ### DecodeWMIResults 18 | 19 | Ƭ **DecodeWMIResults**: `Object` 20 | 21 | Objects found in the `Results` array of `DecodeWMI` endpoint response. 22 | 23 | #### Type declaration 24 | 25 | | Name | Type | 26 | | :---------------------- | :----------------- | 27 | | `CommonName` | `string` | 28 | | `CreatedOn` | `string` | 29 | | `DateAvailableToPublic` | `string` | 30 | | `Make` | `string` | 31 | | `ManufacturerName` | `string` | 32 | | `ParentCompanyName` | `string` | 33 | | `URL` | `string` | 34 | | `UpdatedOn` | `string` \| `null` | 35 | | `VehicleType` | `string` | 36 | 37 | #### Defined in 38 | 39 | [api/endpoints/DecodeWMI.ts:76](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/DecodeWMI.ts#L76) 40 | 41 | ## Functions 42 | 43 | ### DecodeWMI 44 | 45 | ▸ **DecodeWMI**(`WMI`, `doFetch?`): `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`DecodeWMIResults`](api_endpoints_DecodeWMI.md#decodewmiresults)\>\> 46 | 47 | ::: tip :bulb: More Information 48 | See: [DecodeWMI Documentation](/api/endpoints/decode-wmi) 49 | ::: 50 | 51 | `DecodeWMI` provides information on the World Manufacturer Identifier for a specific `WMI` code. 52 | 53 | `WMI` may be provided as either 3 characters representing VIN position 1-3 _or_ 6 characters 54 | representing VIN positions 1-3 & 12-14. 55 | 56 | - Examples: "JTD" "1T9131" 57 | 58 | A list of WMI codes can be found 59 | [here](), 60 | but keep in mind that not all of the listed WMIs are registered with NHTSA and therefore may not 61 | be available in VPIC data sets. 62 | 63 | #### Parameters 64 | 65 | | Name | Type | Description | 66 | | :--------- | :------- | :----------------------------------------------------------------- | 67 | | `WMI` | `string` | World Manufacturer Identifier | 68 | | `doFetch?` | `true` | Whether to fetch the data or just return the URL (default: `true`) | 69 | 70 | #### Returns 71 | 72 | `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`DecodeWMIResults`](api_endpoints_DecodeWMI.md#decodewmiresults)\>\> 73 | 74 | - Api Response `object` 75 | -or- url `string` if `doFetch = false` (default: `true`) 76 | 77 | #### Defined in 78 | 79 | [api/endpoints/DecodeWMI.ts:32](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/DecodeWMI.ts#L32) 80 | 81 | ▸ **DecodeWMI**(`WMI`, `doFetch`): `Promise`<`string`\> 82 | 83 | #### Parameters 84 | 85 | | Name | Type | 86 | | :-------- | :------- | 87 | | `WMI` | `string` | 88 | | `doFetch` | `false` | 89 | 90 | #### Returns 91 | 92 | `Promise`<`string`\> 93 | 94 | #### Defined in 95 | 96 | [api/endpoints/DecodeWMI.ts:37](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/DecodeWMI.ts#L37) 97 | -------------------------------------------------------------------------------- /packages/lib/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@shaggytools/nhtsa-api-wrapper", 3 | "private": false, 4 | "version": "3.0.4", 5 | "description": "Universal javascript wrapper for the NHTSA.dot.gov VPIC 'vehicles' API, useful for VIN decoding, etc.", 6 | "author": "Brandon Eichler ", 7 | "license": "MIT", 8 | "keywords": [ 9 | "NHTSA", 10 | "NHTSA.gov", 11 | "NHTSA.dot.gov", 12 | "NHTSA API", 13 | "NHTSA API Wrapper", 14 | "NHTSA API Wrapper for Node", 15 | "NHTSA API Wrapper for the browser", 16 | "National Highway Traffic Safety Administration", 17 | "Typescript", 18 | "Vehicle", 19 | "Vehicle API", 20 | "Vehicle Identification Number", 21 | "Vehicle Identification Number API", 22 | "VIN", 23 | "VIN decode", 24 | "VIN decoder", 25 | "VPIC" 26 | ], 27 | "homepage": "https://www.shaggytech.com/nhtsa-api-wrapper", 28 | "repository": { 29 | "type": "git", 30 | "url": "https://github.com/ShaggyTech/nhtsa-api-wrapper.git" 31 | }, 32 | "bugs": { 33 | "url": "https://github.com/ShaggyTech/nhtsa-api-wrapper/issues" 34 | }, 35 | "libraryName": "nhtsa-api-wrapper", 36 | "sideEffects": false, 37 | "type": "module", 38 | "main": "dist/nhtsa-api-wrapper.cjs", 39 | "module": "dist/nhtsa-api-wrapper.mjs", 40 | "types": "dist/types/index.d.ts", 41 | "source": "src/index.ts", 42 | "unpkg": "dist/nhtsa-api-wrapper.iife.js", 43 | "jsdelivr": "dist/nhtsa-api-wrapper.iife.js", 44 | "files": [ 45 | "dist" 46 | ], 47 | "exports": { 48 | ".": { 49 | "types": "./dist/types/index.d.ts", 50 | "import": { 51 | "node": "./dist/nhtsa-api-wrapper.cjs", 52 | "default": "./dist/nhtsa-api-wrapper.mjs" 53 | }, 54 | "require": "./dist/nhtsa-api-wrapper.cjs" 55 | }, 56 | "./package.json": "./package.json" 57 | }, 58 | "publishConfig": { 59 | "access": "public" 60 | }, 61 | "scripts": { 62 | "preinstall": "npx only-allow pnpm", 63 | "build": "pnpm run \"/^build:.*/\" && pnpm run format:typedoc", 64 | "build:lib": "tsc --noEmit && vite build", 65 | "build:typedocs": "typedoc --options .typedoc/typedoc.cjs", 66 | "dev": "pnpm run \"/^dev:.*/\"", 67 | "dev:lib": "vite build --watch", 68 | "dev:typedocs": "typedoc --options .typedoc/typedoc.cjs --watch", 69 | "preview": "vite preview", 70 | "lint": "eslint .", 71 | "lint:fix": "eslint --fix", 72 | "format": "prettier --write \"src/**/*.{ts,tsx,md}\"", 73 | "format:typedoc": "pnpm --filter docs run format:typedoc", 74 | "test": "vitest", 75 | "coverage": "vitest --coverage", 76 | "clean": "rimraf ./dist ./coverage .turbo", 77 | "clean:all": "pnpm run clean && rimraf node_modules" 78 | }, 79 | "devDependencies": { 80 | "@vitest/coverage-c8": "0.31.1", 81 | "@vitest/ui": "0.31.1", 82 | "eslint": "8.41.0", 83 | "eslint-config-custom": "workspace:*", 84 | "prettier": "2.8.8", 85 | "prettier-config": "workspace:*", 86 | "rimraf": "5.0.1", 87 | "tsconfig": "workspace:*", 88 | "typedoc": "0.24.7", 89 | "typedoc-config": "workspace:*", 90 | "typescript": "5.0.4", 91 | "vite": "4.3.9", 92 | "vite-plugin-dts": "2.3.0", 93 | "vite-tsconfig-paths": "4.2.0", 94 | "vitest": "0.31.1", 95 | "vitest-fetch-mock": "0.2.2" 96 | }, 97 | "eslintConfig": { 98 | "extends": [ 99 | "custom" 100 | ], 101 | "root": true 102 | }, 103 | "prettier": "prettier-config" 104 | } 105 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/api_endpoints_GetVehicleVariableValuesList.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / api/endpoints/GetVehicleVariableValuesList 2 | 3 | # Module: api/endpoints/GetVehicleVariableValuesList 4 | 5 | ## Table of contents 6 | 7 | ### Type Aliases 8 | 9 | - [GetVehicleVariableValuesListResults](api_endpoints_GetVehicleVariableValuesList.md#getvehiclevariablevalueslistresults) 10 | 11 | ### Functions 12 | 13 | - [GetVehicleVariableValuesList](api_endpoints_GetVehicleVariableValuesList.md#getvehiclevariablevalueslist) 14 | 15 | ## Type Aliases 16 | 17 | ### GetVehicleVariableValuesListResults 18 | 19 | Ƭ **GetVehicleVariableValuesListResults**: `Object` 20 | 21 | Objects found in the `Results` array of `GetVehicleVariableValuesList` endpoint response. 22 | 23 | #### Type declaration 24 | 25 | | Name | Type | 26 | | :------------ | :------- | 27 | | `ElementName` | `string` | 28 | | `Id` | `number` | 29 | | `Name` | `string` | 30 | 31 | #### Defined in 32 | 33 | [api/endpoints/GetVehicleVariableValuesList.ts:75](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetVehicleVariableValuesList.ts#L75) 34 | 35 | ## Functions 36 | 37 | ### GetVehicleVariableValuesList 38 | 39 | ▸ **GetVehicleVariableValuesList**(`variableValue`, `doFetch?`): `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`GetVehicleVariableValuesListResults`](api_endpoints_GetVehicleVariableValuesList.md#getvehiclevariablevalueslistresults)\>\> 40 | 41 | ::: tip :bulb: More Information 42 | See: [GetVehicleVariableValuesList Documentation](/api/endpoints/get-vehicle-variable-values-list) 43 | ::: 44 | 45 | `GetVehicleVariableValuesList` provides a list of all the accepted values for a given variable 46 | that are stored in the vPIC dataset. 47 | 48 | If `variableValue` is a string, it must use full name, not just part of it, e.g., 49 | "Battery Type", not "Battery" 50 | 51 | `variableValue` can be also be a number, which is the ID of the variable, e.g., 1, 2, 3, etc. 52 | 53 | #### Parameters 54 | 55 | | Name | Type | Description | 56 | | :-------------- | :------------------- | :----------------------------------------------------------------- | 57 | | `variableValue` | `string` \| `number` | The variable you want to get a values list of | 58 | | `doFetch?` | `true` | Whether to fetch the data or just return the URL (default: `true`) | 59 | 60 | #### Returns 61 | 62 | `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`GetVehicleVariableValuesListResults`](api_endpoints_GetVehicleVariableValuesList.md#getvehiclevariablevalueslistresults)\>\> 63 | 64 | - Api Response 65 | `object` -or- url `string` if `doFetch = false` 66 | 67 | #### Defined in 68 | 69 | [api/endpoints/GetVehicleVariableValuesList.ts:29](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetVehicleVariableValuesList.ts#L29) 70 | 71 | ▸ **GetVehicleVariableValuesList**(`variableValue`, `doFetch`): `Promise`<`string`\> 72 | 73 | #### Parameters 74 | 75 | | Name | Type | 76 | | :-------------- | :------------------- | 77 | | `variableValue` | `string` \| `number` | 78 | | `doFetch` | `false` | 79 | 80 | #### Returns 81 | 82 | `Promise`<`string`\> 83 | 84 | #### Defined in 85 | 86 | [api/endpoints/GetVehicleVariableValuesList.ts:34](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetVehicleVariableValuesList.ts#L34) 87 | -------------------------------------------------------------------------------- /apps/docs/src/typedoc/modules/api_endpoints_GetMakeForManufacturer.md: -------------------------------------------------------------------------------- 1 | [@shaggytools/nhtsa-api-wrapper - v3.0.4](../index.md) / [Exports](../modules.md) / api/endpoints/GetMakeForManufacturer 2 | 3 | # Module: api/endpoints/GetMakeForManufacturer 4 | 5 | ## Table of contents 6 | 7 | ### Type Aliases 8 | 9 | - [GetMakeForManufacturerResults](api_endpoints_GetMakeForManufacturer.md#getmakeformanufacturerresults) 10 | 11 | ### Functions 12 | 13 | - [GetMakeForManufacturer](api_endpoints_GetMakeForManufacturer.md#getmakeformanufacturer) 14 | 15 | ## Type Aliases 16 | 17 | ### GetMakeForManufacturerResults 18 | 19 | Ƭ **GetMakeForManufacturerResults**: `Object` 20 | 21 | Objects found in the `Results` array of `GetMakeForManufacturer` endpoint response. 22 | 23 | #### Type declaration 24 | 25 | | Name | Type | 26 | | :---------- | :------- | 27 | | `Make_ID` | `number` | 28 | | `Make_Name` | `string` | 29 | | `Mfr_Name` | `string` | 30 | 31 | #### Defined in 32 | 33 | [api/endpoints/GetMakeForManufacturer.ts:77](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetMakeForManufacturer.ts#L77) 34 | 35 | ## Functions 36 | 37 | ### GetMakeForManufacturer 38 | 39 | ▸ **GetMakeForManufacturer**(`manufacturer`, `doFetch?`): `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`GetMakeForManufacturerResults`](api_endpoints_GetMakeForManufacturer.md#getmakeformanufacturerresults)\>\> 40 | 41 | ::: tip :bulb: More Information 42 | See: [GetMakeForManufacturer Documentation](/api/endpoints/get-make-for-manufacturer) 43 | ::: 44 | 45 | `GetMakeForManufacturer` returns all the Makes in the vPIC dataset for a specified manufacturer 46 | that is requested. Multiple results are returned in case of multiple matches. 47 | 48 | `manufacturer` name can be a partial name, or a full name for more specificity, e.g. "988", 49 | "honda", "HONDA OF CANADA MFG., INC.", etc. 50 | 51 | - If supplied `manufacturer` is a number - method will do exact match on Manufacturer's Id. 52 | - If supplied `manufacturer` is a string - it will look for manufacturers whose name is LIKE the 53 | provided name. It accepts a partial manufacturer name as an input. 54 | 55 | #### Parameters 56 | 57 | | Name | Type | Description | 58 | | :------------- | :------------------- | :----------------------------------------------------------------- | 59 | | `manufacturer` | `string` \| `number` | Manufacturer Name or ID | 60 | | `doFetch?` | `true` | Whether to fetch the data or just return the URL (default: `true`) | 61 | 62 | #### Returns 63 | 64 | `Promise`<[`NhtsaResponse`](api_types.md#nhtsaresponse)<[`GetMakeForManufacturerResults`](api_endpoints_GetMakeForManufacturer.md#getmakeformanufacturerresults)\>\> 65 | 66 | - Api Response 67 | `object` -or- url `string` if `doFetch = false` 68 | 69 | #### Defined in 70 | 71 | [api/endpoints/GetMakeForManufacturer.ts:31](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetMakeForManufacturer.ts#L31) 72 | 73 | ▸ **GetMakeForManufacturer**(`manufacturer`, `doFetch`): `Promise`<`string`\> 74 | 75 | #### Parameters 76 | 77 | | Name | Type | 78 | | :------------- | :------------------- | 79 | | `manufacturer` | `string` \| `number` | 80 | | `doFetch` | `false` | 81 | 82 | #### Returns 83 | 84 | `Promise`<`string`\> 85 | 86 | #### Defined in 87 | 88 | [api/endpoints/GetMakeForManufacturer.ts:36](https://github.com/ShaggyTech/nhtsa-api-wrapper/blob/main/packages/lib/src/api/endpoints/GetMakeForManufacturer.ts#L36) 89 | -------------------------------------------------------------------------------- /apps/docs/src/api/endpoints/get-vehicle-variable-list.md: -------------------------------------------------------------------------------- 1 | # GetVehicleVariableList 2 | 3 | --- 4 | 5 | ```typescript 6 | async function GetVehicleVariableList( 7 | doFetch?: boolean 8 | ): Promise | string> 9 | ``` 10 | 11 | ::: tip :bulb: More In Depth 12 | See: [Package Reference](../../typedoc/modules/api_endpoints_GetVehicleVariableList) 13 | ::: 14 | 15 | ## Description 16 | 17 | `GetVehicleVariableList` provides a list of all the Vehicle related variables that are in the 18 | vPIC dataset. Information on the name, description and the type of the variable is provided. 19 | 20 | ## Parameters 21 | 22 | | Name | Type | Default value | Description | 23 | | :--------- | :-------- | :------------ | :----------------------------------------------------------------- | 24 | | `doFetch?` | `boolean` | `true` | Whether to fetch the data or just return the URL (default: `true`) | 25 | 26 | ::: warning 📝 NOTE 27 | 28 | Set `doFetch` to `false` if you want to fetch the data yourself. 29 | 30 | - See [BYOF - Bring Your Own Fetch](../../guide/bring-your-own-fetch.md#option-1-set-dofetch-to-false) 31 | for more info. 32 | 33 | ::: 34 | 35 | ## Returns 36 | 37 | Returns a Promise that resolves to a NhtsaResponse object containing an array of 38 | [GetVehicleVariableListResults](#type-getvehiclevariablelistresults) objects in the 39 | `Results` key. 40 | 41 | ```typescript 42 | => Promise> 43 | ``` 44 | 45 | ```typescript 46 | type NhtsaResponse = { 47 | Count: number 48 | Message: string 49 | Results: Array 50 | SearchCriteria: string 51 | } 52 | ``` 53 | 54 | ::: details :mag: Click to Show Full Example Response 55 | <<< @/snippets/endpoints/get-vehicle-variable-list.ts#example-response 56 | ::: 57 | 58 | ### If `doFetch` is set to `false` 59 | 60 | Returns a URL string that can be used to fetch the data, does _not_ fetch the data internally. 61 | 62 | ```typescript 63 | => Promise 64 | 65 | // ex: => 'https://vpic.nhtsa.dot.gov/api/vehicles/getvehiclevariablelist?format=json' 66 | ``` 67 | 68 | ::: tip :bulb: See: [BYOF - Bring Your Own Fetch](../../guide/bring-your-own-fetch.md#option-1-set-dofetch-to-false) 69 | ::: 70 | 71 | ## Type - GetVehicleVariableListResults 72 | 73 | <<< @/snippets/endpoints/get-vehicle-variable-list.ts#type-results 74 | 75 | Ƭ **GetVehicleVariableListResults**: `Object` 76 | 77 | Objects returned in the `Results` array of `GetVehicleVariableList` endpoint response. 78 | 79 | ## Examples 80 | 81 | ::: tip Example 1: 82 | 83 | - Fetches data from VPIC API 84 | 85 | - Returns: 86 | 87 | ```typescript 88 | => Promise> 89 | ``` 90 | 91 | ::: 92 | 93 | ### Example 1: Get Vehicle Variable List 94 | 95 | ```ts 96 | import { GetVehicleVariableList } from '@shaggytools/nhtsa-api-wrapper' 97 | 98 | const response = await GetVehicleVariableList() 99 | ``` 100 | 101 | ::: tip Example 2: 102 | 103 | - Does _NOT_ fetch data from VPIC API 104 | 105 | - See: [BYOF - Bring Your Own Fetch](../../guide/bring-your-own-fetch.md#option-1-set-dofetch-to-false) 106 | 107 | - Returns: 108 | 109 | ```typescript 110 | => Promise 111 | ``` 112 | 113 | ::: 114 | 115 | ### Example 2: Get Vehicle Variable List and doFetch = false 116 | 117 | ```ts 118 | import { GetVehicleVariableList } from '@shaggytools/nhtsa-api-wrapper' 119 | 120 | const url = await GetVehicleVariableList(false) 121 | 122 | // url: 'https://vpic.nhtsa.dot.gov/api/vehicles/getvehiclevariablelist?format=json' 123 | ``` 124 | -------------------------------------------------------------------------------- /apps/docs/src/guide/vin-decoding.md: -------------------------------------------------------------------------------- 1 | # Decoding Vehicle Identification Numbers (VIN) 2 | 3 | The NHTSA API provides several endpoints for decoding VINs. This section will use the 4 | `DecodeVinValues` endpoint as an example, but the same principles apply to all DecodeVinXXX 5 | endpoints. 6 | 7 | `DecodeVinValues` is the most commonly used endpoint for decoding VINs as it returns 8 | the data in a more usable format than the other endpoints called "flat file format". This format 9 | is easier to work with than the other endpoints, which return the data in a nested format and 10 | require additional processing to get the data into a usable format. 11 | 12 | --- 13 | 14 | ## Decoding a VIN 15 | 16 | Decode a VIN and store the full response in a variable called `response`: 17 | 18 | ```typescript 19 | import { DecodeVinValues } from '@shaggytools/nhtsa-api-wrapper' 20 | 21 | const response = await DecodeVinValues('WA1A4AFY2J2008189') 22 | 23 | /* 24 | response = { 25 | Count: 136, 26 | Message: 'Results returned successfully ...', 27 | Results: [ {...} ], 28 | SearchCriteria: 'VIN:WA1A4AFY2J2008189', 29 | } 30 | */ 31 | ``` 32 | 33 | ::: tip :mag: See: [VPIC Response](../api/vpic-api-response) for more info on the response object 34 | ::: 35 | 36 | --- 37 | 38 | ## Response Object 39 | 40 | The `DecodeVinValues` function returns a Promise that resolves to an object with the following 41 | properties: 42 | 43 | - `Count` - The number of results returned, if less than 1 then no results were returned 44 | - `Message` - A message from the API 45 | - `Results` - An array containing a single `DecodeVinValuesResults` object 46 | - `SearchCriteria` - The search criteria used to get the results, in this case the VIN 47 | 48 | In the example above, `response.Results` is an array containing a single `DecodeVinValuesResults` 49 | object. This object is the decoded data for the VIN. 50 | 51 | ::: tip See also: 52 | 53 | - [DecodeVinValues](../api/endpoints/decode-vin-values) 54 | - [DecodeVinValues Example Response](../api/endpoints/decode-vin-values#returns) 55 | - [Type - DecodeVinValuesResults](../typedoc/modules/api_endpoints_DecodeVinValues#decodevinvaluesresults) 56 | 57 | ::: 58 | 59 | --- 60 | 61 | ## Accessing the Decoded Data 62 | 63 | The following shows how to access and use the decoded data from the `DecodeVinValues` endpoint using 64 | several different methods. 65 | 66 | 1. Get all properties of the first object in the `Results` array and save to a variable: 67 | 68 | ```typescript 69 | import { DecodeVinValues } from '@shaggytools/nhtsa-api-wrapper' 70 | 71 | const response = await DecodeVinValues('WA1A4AFY2J2008189') 72 | 73 | // Get the first object in the Results array, this is an object of type DecodeVinValuesResults 74 | const decodedData = response.Results[0] 75 | 76 | // Save the data to variables that you want to use 77 | const year = decodedData.ModelYear 78 | const make = decodedData.Make 79 | const model = decodedData.Model 80 | const engineHP = decodedData.EngineHP 81 | 82 | console.log( 83 | `The vehicle is a ${year} ${make} ${model} and it has ${engineHP} horsepower.` 84 | ) 85 | ``` 86 | 87 | 2. Using object destructuring syntax: 88 | 89 | ```typescript 90 | import { DecodeVinValues } from '@shaggytools/nhtsa-api-wrapper' 91 | 92 | const { Count, Message, Results, SearchCriteria } = await DecodeVinValues( 93 | 'WA1A4AFY2J2008189' 94 | ) 95 | 96 | // Destructure to get the specific data you want to use 97 | const { ModelYear, Make, Model, EngineHP } = Results[0] 98 | 99 | console.log( 100 | `The vehicle is a ${ModelYear} ${Make} ${Model} and it has ${EngineHP} horsepower.` 101 | ) 102 | ``` 103 | 104 | ::: tip :mag: See Also: [VPIC API Endpoints](../api/#vpic-api-endpoints) 105 | ::: 106 | --------------------------------------------------------------------------------