Vietnam Administrative Address Database

1.0.0 · active · verified Wed Apr 22

This package provides a raw JSON database of Vietnamese administrative addresses, meticulously structured according to Resolution 202/2025/QH15 and NQ-UBTVQH15, with applicability from July 1, 2025, and January 1, 2025, respectively. As of version 1.0.0, it includes data for 34 provinces/cities, 3,321 wards/communes, and 10,977 ward mapping rules. It is explicitly designed as a dependency for other JavaScript/TypeScript libraries, offering unopinionated access to the latest administrative boundary data. The package ships with comprehensive TypeScript type definitions, enabling robust static type checking for consumers. Its core differentiator is providing a directly consumable, machine-readable dataset reflecting future administrative changes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import the `vietnam-address-database` data, extract the specific 'provinces', 'wards', and 'ward_mappings' tables, and provides example functions for accessing and searching the administrative data with TypeScript types.

import addressData, { Province, Ward, WardMapping, DatabaseItem } from 'vietnam-address-database';

// The exported data is an array of DatabaseItem, which includes header, database info, and tables.
const allData: DatabaseItem[] = addressData;

// Extract specific tables for easier access and type safety
let provinces: Province[] = [];
let wards: Ward[] = [];
let wardMappings: WardMapping[] = [];

allData.forEach(item => {
  if (item.type === 'table') {
    if (item.name === 'provinces') {
      provinces = item.data as Province[];
    } else if (item.name === 'wards') {
      wards = item.data as Ward[];
    } else if (item.name === 'ward_mappings') {
      wardMappings = item.data as WardMapping[];
    }
  }
});

// Example functions to work with the extracted data
function getProvinces(): Province[] {
  console.log(`Found ${provinces.length} provinces.`);
  return provinces;
}

function getProvinceByCode(code: string): Province | undefined {
  const province = provinces.find(p => p.province_code === code);
  console.log(`Province for code '${code}': ${province?.name || 'Not found'}`);
  return province;
}

// Usage examples:
const haNoi = getProvinceByCode('01'); // Example: Hà Nội
const firstWard = wards[0];
if (firstWard) {
  console.log(`First ward: ${firstWard.name}, code: ${firstWard.ward_code}`);
}

const firstMapping = wardMappings[0];
if (firstMapping) {
  console.log(`First ward mapping: Old: ${firstMapping.old_ward_name} (${firstMapping.old_ward_code}), New: ${firstMapping.new_ward_name} (${firstMapping.new_ward_code})`);
}

view raw JSON →