Thai Address Database

0.0.30 · active · verified Wed Apr 22

The `thai-address-database` package offers a client-side solution for managing and searching Thai address data within JavaScript applications. Currently at version 0.0.30, it provides functions like `searchAddressByDistrict` to query a local `db.json` file, eliminating the need for a server-side component for address lookups. The library is based on the database and `preprocess()` function from `jquery.Thailand.js` version 1.5.1. While it allows for database updates via an `npm run migrate` script, which converts a `database.xlsx` file into `db.json`, it is still in early development, with noted limitations such as exclusive support for `db.json` and no current support for `db.zip` or geodatabases. Its primary differentiator is enabling offline or client-only address search capabilities for Thai addresses.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use the `searchAddressByDistrict` function to query Thai address data, logging results to the console.

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

// In a browser environment, ensure db.json is accessible or bundled.
// For Node.js, the package typically handles database resolution.

// Simulate an input change or a search query
function performAddressSearch(query) {
  const results = searchAddressByDistrict(query);
  console.log(`\n--- Search results for "${query}" ---`);
  if (results && results.length > 0) {
    results.forEach(item => {
      console.log(`${item.district} » ${item.amphoe} » ${item.province} » ${item.zipcode}`);
    });
  } else {
    console.log("No matching addresses found.");
  }
}

// Example usage:
performAddressSearch('สีลม');
performAddressSearch('ดินแดง');
performAddressSearch('ปทุมวัน');
performAddressSearch('ถนนเพชรบุรีตัดใหม่'); // A query that might not yield direct district results
performAddressSearch('NonExistentPlace');

view raw JSON →