@cardog/corgi

中文文档
2.0.4发布于 2026/04/15ISCTypeScriptESM + CJS近 30 天下载 1.3万

Fast, offline VIN decoding for Node.js, browsers, and Cloudflare Workers. Powered by the NHTSA VPIC database.

原始使用文档
文档目录21 节
  1. Installation
  2. Quick Start
  3. Platform Support
  4. Node.js
  5. Browser
  6. Cloudflare Workers (D1)
  7. Configuration
  8. Response Structure
  9. Error Handling
  10. CLI
  11. Architecture
  12. VIN Structure
  13. Check Digit Algorithm
  14. Model Year Decoding
  15. Database
  16. VPIC Lite
  17. Hosted Database
  18. Local Cache
  19. Exports
  20. Cardog API
  21. License

Corgi VIN Decoder

Cardog      Corgi - Fast VIN Decoder
Fast, offline VIN decoding for Node.js, browsers, and Cloudflare Workers.
Powered by the NHTSA VPIC database.

npm version Downloads TypeScript License: ISC Cardog API

Need more than basic VIN decoding? Check out the Cardog API for comprehensive vehicle data including market values, safety recalls, ownership costs, and more.

Installation

npm install @cardog/corgi

Quick Start

import { createDecoder } from "@cardog/corgi";

const decoder = await createDecoder();
const result = await decoder.decode("KM8K2CAB4PU001140");

console.log(result.components.vehicle);
// { make: 'Hyundai', model: 'Kona', year: 2023, ... }

await decoder.close();

Platform Support

Node.js

import { createDecoder } from "@cardog/corgi";

const decoder = await createDecoder();
const result = await decoder.decode("1HGCM82633A123456");

// Custom database path
const decoder = await createDecoder({
  databasePath: "/path/to/vpic.lite.db",
});

Browser

import { createDecoder } from "@cardog/corgi/browser";

const decoder = await createDecoder({
  databasePath: "https://corgi.cardog.io/vpic.lite.db.gz",
  runtime: "browser",
});

Cloudflare Workers (D1)

import { createDecoder, initD1Adapter } from "@cardog/corgi";

initD1Adapter(env.D1_DATABASE);

const decoder = await createDecoder({
  databasePath: "D1",
  runtime: "cloudflare",
});

Configuration

const decoder = await createDecoder({
  databasePath: "./custom/path.db",
  forceFresh: true,
  defaultOptions: {
    includePatternDetails: true,
    includeRawData: false,
    confidenceThreshold: 0.8,
    includeDiagnostics: true,
  },
});

// Per-decode options
const result = await decoder.decode("VIN12345678901234", {
  modelYear: 2024,
  includePatternDetails: true,
});

Response Structure

interface DecodeResult {
  vin: string;
  valid: boolean;

  components: {
    vehicle?: {
      make: string;
      model: string;
      year: number;
      series?: string;
      bodyStyle?: string;
      driveType?: string;
      fuelType?: string;
      doors?: string;
    };
    wmi?: {
      manufacturer: string;
      make: string;
      country: string;
      region: string;
    };
    plant?: {
      country: string;
      city?: string;
      code: string;
    };
    engine?: {
      model?: string;
      cylinders?: string;
      displacement?: string;
      fuel?: string;
    };
    modelYear?: {
      year: number;
      source: string;
      confidence: number;
    };
    checkDigit?: {
      isValid: boolean;
      expected?: string;
      actual: string;
    };
  };

  errors: DecodeError[];
  metadata?: DiagnosticInfo;
  patterns?: PatternMatch[];
}

Error Handling

import { ErrorCode } from "@cardog/corgi";

const result = await decoder.decode("INVALID_VIN");

if (!result.valid) {
  result.errors.forEach((error) => {
    switch (error.code) {
      case ErrorCode.INVALID_CHECK_DIGIT:
      case ErrorCode.INVALID_LENGTH:
      case ErrorCode.WMI_NOT_FOUND:
        console.log(error.message);
    }
  });
}

CLI

npx @cardog/corgi decode 1HGCM82633A123456
npx @cardog/corgi decode 1HGCM82633A123456 --patterns --format json
npx @cardog/corgi --help

Architecture

VIN Structure

A Vehicle Identification Number (VIN) is a 17-character identifier assigned to every vehicle manufactured for road use. The structure is defined by ISO 3779 and follows this format:

Position:  1-3    4-8      9       10      11      12-17
           WMI    VDS      Check   Year    Plant   VIS
           │      │        │       │       │       │
           │      │        │       │       │       └─ Sequential production number
           │      │        │       │       └───────── Assembly plant code
           │      │        │       └─────────────── Model year (A-Y, 1-9, excluding I,O,Q,U,Z,0)
           │      │        └─────────────────────── Check digit (0-9, X)
           │      └──────────────────────────────── Vehicle attributes (model, body, engine, etc.)
           └─────────────────────────────────────── World Manufacturer Identifier

WMI (Positions 1-3): Identifies the manufacturer. First character indicates country/region, second indicates manufacturer, third indicates vehicle type or manufacturing division.

VDS (Positions 4-8): Vehicle Descriptor Section. Manufacturer-defined attributes including model, body style, engine type, and restraint system.

Check Digit (Position 9): Validates VIN integrity using a weighted algorithm. Required for all vehicles sold in North America.

Model Year (Position 10): Encodes the model year. Uses letters A-Y (excluding I, O, Q, U, Z) and digits 1-9 in a 30-year cycle.

Plant Code (Position 11): Identifies the assembly plant. Manufacturer-specific encoding.

VIS (Positions 12-17): Vehicle Identifier Section. Sequential production number unique within the model year and plant.

Check Digit Algorithm

The check digit (position 9) is calculated by:

  1. Assigning each character a value (A=1, B=2, ..., N=5, P=7, ..., 0-9 = face value)
  2. Multiplying each position by a weight: [8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2]
  3. Summing all products and taking modulo 11
  4. Result 10 = 'X', otherwise the digit itself

Model Year Decoding

Per 49 CFR 565.15, model year codes cycle every 30 years:

CodeYears
A1980, 2010
B1981, 2011
......
X1999, 2029
Y2000, 2030
12001, 2031
......
92009, 2039

Characters I, O, Q are excluded from all VIN positions. U, Z, and 0 are additionally excluded from position 10.


Database

VPIC Lite

Corgi uses an optimized subset of the NHTSA vPIC (Vehicle Product Information Catalog) database. The database is compressed and bundled with the package for offline operation.

Specifications:

  • Source: NHTSA VPIC
  • Format: SQLite (optimized)
  • Compressed: ~20MB (gzip)
  • Uncompressed: ~40MB
  • Updates: Monthly via automated pipeline

Hosted Database

Cardog maintains a public CDN with the latest VPIC database builds:

Base URL: https://corgi.cardog.io

FileDescription
vpic.lite.db.gzDatabase (gzip)
vpic.lite.db.bz2Database (bzip2)
vpic.lite.db.xzDatabase (xz)
vpic.lite.db.zstDatabase (zstd)
vpic.lite.jsonMetadata (version, checksums, record counts)
vpic.lite.sha256SHA256 checksums

Dated archives are also available: vpic_lite_YYYYMMDD.db.gz

Local Cache

  • Node.js: ~/.corgi-cache/vpic.lite.db
  • Browser: Loaded from provided URL
  • Cloudflare: Managed by D1
import { getDatabasePath } from "@cardog/corgi";

const dbPath = await getDatabasePath();
const decoder = await createDecoder({ forceFresh: true }); // Force refresh

Exports

// Core
import { createDecoder, quickDecode, getDatabasePath } from "@cardog/corgi";

// Types
import type { DecodeResult, DecodeOptions, DecoderConfig } from "@cardog/corgi";

// Enums
import { ErrorCode, ErrorCategory, BodyStyle } from "@cardog/corgi";

// Adapters
import { initD1Adapter } from "@cardog/corgi/d1-adapter";
import { createDecoder } from "@cardog/corgi/browser";

Cardog API

Corgi provides fast, offline VIN decoding - but if you need comprehensive vehicle intelligence, the Cardog API offers much more:

  • Enriched VIN Decoding - Corgi decoding plus detailed variant data, specs, and features
  • Market Analysis - Pricing insights, market trends, and comparable vehicle listings
  • Safety Recalls - NHTSA and Transport Canada recall data searchable by VIN or make/model
  • Vehicle Listings - Search active listings with filters for make, model, price, location
  • EV Data - Charging stations, efficiency ratings, and range estimates
# Decode a VIN with full vehicle data
curl "https://api.cardog.io/v1/vin/1HGCM82633A123456" \
  -H "x-api-key: your-api-key"

Get started at docs.cardog.app


License

ISC License - see LICENSE for details.

版本与发布记录

@cardog/corgi 共发布 16 个版本,首次发布于 2025/05/28;过去 12 个月发布了 10 个版本。

版本发布日期距今
2.0.4latest2026/04/156 个月前
3.0.1-beta.0beta2026/04/156 个月前
3.0.0-alpha.1alpha2026/04/037 个月前
2.0.32026/04/017 个月前
2.0.22026/04/017 个月前
2.0.12026/03/127 个月前

关于 @cardog/corgi 的常见问题

@cardog/corgi 是什么?

Fast, offline VIN decoding for Node.js, browsers, and Cloudflare Workers. Powered by the NHTSA VPIC database.

如何安装 @cardog/corgi?

在项目目录运行 npm install @cardog/corgi,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:sql.js(^1.8.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 corgi,可以用 npx corgi 直接运行。

@cardog/corgi 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cardog/corgi 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cardog/corgi 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cardog/corgi 可以商用吗?

@cardog/corgi 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cardog/corgi 的下载量有多少?

根据 npm 官方下载统计,@cardog/corgi 在 2026/10/09 – 2026/11/07 这 30 天内被下载 12,616 次,日均约 421 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cardog/corgi 还在维护吗?

最新版本 2.0.4 发布于 2026/04/15(6 个月前);至今共发布 16 个版本,其中过去 12 个月发布了 10 个;首次发布于 2025/05/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。