Thai Address Custom Database

1.0.2 · active · verified Wed Apr 22

The `thai-address-custom-database` package offers a client-side database for Thai addresses, removing the need for server-side lookups. It builds upon the `Sellsuki/thai-address-database` project and specifically incorporates the database and `preprocess()` function from `jquery.Thailand.js` version 1.5.1 (commit 4e5f496). The current stable version is 1.0.2. This library is updated infrequently, primarily providing database maintenance and minor library updates. A key differentiator is its ability to generate the client-side `db.json` from an `xlsx` spreadsheet via a migration script. However, it currently only supports the `db.json` format and does not include support for `db.zip` or `geodb` variants found in some related projects. It requires Node.js version 12 or higher.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use the `searchAddressByDistrict` function to query Thai address data.

import { searchAddressByDistrict } from 'thai-address-custom-database';

interface AddressResult {
  district: string;
  amphoe: string;
  province: string;
  zipcode: string;
}

function simulateAddressSearch(query: string): void {
  console.log(`\n--- Searching for "${query}" ---`);
  const results: AddressResult[] = searchAddressByDistrict(query);
  if (results && results.length > 0) {
    results.forEach(item => {
      console.log(`${item.district} » ${item.amphoe} » ${item.province} » ${item.zipcode}`);
    });
  } else {
    console.log(`No results found for "${query}".`);
  }
}

// Example searches
simulateAddressSearch('บางกะปิ');
simulateAddressSearch('จตุจักร');
simulateAddressSearch('บางพลี');
simulateAddressSearch('สุขุมวิท 21'); // Should return some results if found
simulateAddressSearch('กรุงเทพ'); // Might return many results or none depending on specific search logic
simulateAddressSearch('xyz-nonexistent'); // Expected no results

view raw JSON →