{"id":16549,"library":"thai-address-database","title":"Thai Address Database","description":"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.","status":"active","version":"0.0.30","language":"javascript","source_language":"en","source_url":"https://github.com/Sellsuki/thai-address-database","tags":["javascript"],"install":[{"cmd":"npm install thai-address-database","lang":"bash","label":"npm"},{"cmd":"yarn add thai-address-database","lang":"bash","label":"yarn"},{"cmd":"pnpm add thai-address-database","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package primarily uses named exports. Direct CommonJS `require` might not correctly expose the named functions, and it is not a default export.","wrong":"const searchAddressByDistrict = require('thai-address-database');\nimport searchAddressByDistrict from 'thai-address-database';","symbol":"searchAddressByDistrict","correct":"import { searchAddressByDistrict } from 'thai-address-database';"}],"quickstart":{"code":"import { searchAddressByDistrict } from 'thai-address-database';\n\n// In a browser environment, ensure db.json is accessible or bundled.\n// For Node.js, the package typically handles database resolution.\n\n// Simulate an input change or a search query\nfunction performAddressSearch(query) {\n  const results = searchAddressByDistrict(query);\n  console.log(`\\n--- Search results for \"${query}\" ---`);\n  if (results && results.length > 0) {\n    results.forEach(item => {\n      console.log(`${item.district} » ${item.amphoe} » ${item.province} » ${item.zipcode}`);\n    });\n  } else {\n    console.log(\"No matching addresses found.\");\n  }\n}\n\n// Example usage:\nperformAddressSearch('สีลม');\nperformAddressSearch('ดินแดง');\nperformAddressSearch('ปทุมวัน');\nperformAddressSearch('ถนนเพชรบุรีตัดใหม่'); // A query that might not yield direct district results\nperformAddressSearch('NonExistentPlace');","lang":"javascript","description":"Demonstrates how to import and use the `searchAddressByDistrict` function to query Thai address data, logging results to the console."},"warnings":[{"fix":"Ensure your database is in `db.json` format. The package includes an `npm run migrate` script to convert `database.xlsx` to `db.json`.","message":"The library currently only supports `db.json` for its address data. It does not support `db.zip` or `geodb` formats that might be present in related or original projects.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Run `npm run migrate` in your project's root directory after updating `database.xlsx`. Ensure the Excel file is always `.xlsx` format.","message":"To update the local address database, you must use the provided `npm run migrate` command after modifying the `database.xlsx` file. Manual manipulation of `db.json` is not recommended as it can be overwritten.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Refer to the `thai-address-database` documentation for specific functionality. If you require features or data from newer `jquery.Thailand.js` versions, you may need to contribute or seek alternatives.","message":"This package is based on an older version (1.5.1) of the database and `preprocess()` function from `jquery.Thailand.js`. Be aware of potential differences in data structure or available functionality compared to newer versions of the original project.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Run `npm install thai-address-database` or `yarn add thai-address-database` in your project directory.","cause":"The package has not been installed or is not correctly resolved by your module bundler/Node.js environment.","error":"Cannot find module 'thai-address-database'"},{"fix":"Use a named import: `import { searchAddressByDistrict } from 'thai-address-database';`","cause":"The `searchAddressByDistrict` function was imported incorrectly, often due to attempting a default import or incorrect CommonJS `require`.","error":"searchAddressByDistrict is not a function"},{"fix":"Ensure the package is fully installed and the database file is present. If you are developing or have manually altered the database, run `npm run migrate` to generate/restore `db.json` from `database.xlsx`.","cause":"The `db.json` file, which contains the address data, is missing or inaccessible in the expected location.","error":"Error: ENOENT: no such file or directory, open '.../node_modules/thai-address-database/database/db.json'"}],"ecosystem":"npm"}