{"id":16692,"library":"thai-address-custom-database","title":"Thai Address Custom Database","description":"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.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/9hope/thai-address-custom-database","tags":["javascript"],"install":[{"cmd":"npm install thai-address-custom-database","lang":"bash","label":"npm"},{"cmd":"yarn add thai-address-custom-database","lang":"bash","label":"yarn"},{"cmd":"pnpm add thai-address-custom-database","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is the primary function for searching addresses. The package is primarily designed for ES Modules, though CJS `require` might work via transpilation/bundling environments.","wrong":"const { searchAddressByDistrict } = require('thai-address-custom-database');","symbol":"searchAddressByDistrict","correct":"import { searchAddressByDistrict } from 'thai-address-custom-database';"},{"note":"The `preprocess` function is part of the integrated `jquery.Thailand.js` 1.5.1 logic, often used for initial data preparation or normalization.","wrong":"import preprocess from 'thai-address-custom-database';","symbol":"preprocess","correct":"import { preprocess } from 'thai-address-custom-database';"},{"note":"Use this pattern to import all named exports into a single namespace object (e.g., `ThaiAddress.searchAddressByDistrict`). There is no default export.","wrong":"import ThaiAddress from 'thai-address-custom-database';","symbol":"* as ThaiAddress","correct":"import * as ThaiAddress from 'thai-address-custom-database';"}],"quickstart":{"code":"import { searchAddressByDistrict } from 'thai-address-custom-database';\n\ninterface AddressResult {\n  district: string;\n  amphoe: string;\n  province: string;\n  zipcode: string;\n}\n\nfunction simulateAddressSearch(query: string): void {\n  console.log(`\\n--- Searching for \"${query}\" ---`);\n  const results: AddressResult[] = searchAddressByDistrict(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 results found for \"${query}\".`);\n  }\n}\n\n// Example searches\nsimulateAddressSearch('บางกะปิ');\nsimulateAddressSearch('จตุจักร');\nsimulateAddressSearch('บางพลี');\nsimulateAddressSearch('สุขุมวิท 21'); // Should return some results if found\nsimulateAddressSearch('กรุงเทพ'); // Might return many results or none depending on specific search logic\nsimulateAddressSearch('xyz-nonexistent'); // Expected no results","lang":"typescript","description":"Demonstrates how to import and use the `searchAddressByDistrict` function to query Thai address data."},"warnings":[{"fix":"Always use `import ... from 'thai-address-custom-database'` when importing this package.","message":"The README examples incorrectly show `import ... from 'thai-address-database'` instead of the actual package name `thai-address-custom-database`. Copying the README's import path will result in a 'module not found' error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your database operations and expectations align with the `db.json` format. If other formats are required, consider alternative libraries.","message":"This package is explicitly limited to `db.json` database files. It does not support `db.zip` or `geodb` formats that might be available in other related Thai address database projects.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Verify that your updated address data is saved as `database.xlsx` (specifically the Excel Workbook format) before running `npm run migrate`.","message":"The database migration script (`npm run migrate`) strictly requires the input file to be named `database.xlsx` and saved in the Excel Workbook (.xlsx) format. Using an older `.xls` format or an incorrect filename will cause the migration to fail.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Be aware of potential data freshness or compatibility issues with newer versions of upstream data sources. Monitor the `thai-address-custom-database` repository for updates if upstream changes occur.","message":"The package's database and `preprocess()` function are based on `jquery.Thailand.js` version 1.5.1. Future updates or breaking changes in the original `jquery.Thailand.js` project's database schema or logic may not be automatically reflected or compatible, potentially requiring manual updates to this custom database package.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change your import statement from `import { ... } from 'thai-address-database'` to `import { ... } from 'thai-address-custom-database'`.","cause":"The module was imported using the name 'thai-address-database' as seen in some documentation examples, but the actual package name is 'thai-address-custom-database'.","error":"Error: Cannot find module 'thai-address-database'"},{"fix":"Ensure you are using ES Module `import { searchAddressByDistrict } from 'thai-address-custom-database';` in an environment configured for ESM. Verify the export name is correct.","cause":"This error typically occurs when attempting to use CommonJS `require()` syntax with an ES Module, or if the named export is incorrect or not found.","error":"TypeError: searchAddressByDistrict is not a function"},{"fix":"Confirm that the address data spreadsheet is correctly named `database.xlsx` and saved with the .xlsx extension (not .xls) before executing `npm run migrate`.","cause":"When running `npm run migrate`, the script expects a specific Excel file named `database.xlsx` saved in the modern Excel Workbook format.","error":"Error: Input file must be 'database.xlsx' in .xlsx format."}],"ecosystem":"npm"}