Skip to content

Getting Started

thaizip is a headless Thai address search library — zero runtime dependencies, no framework lock-in. This page walks through installing it and getting your first result.

Terminal window
npm install thaizip

Requires Node.js 18 or later. React is an optional peer dependency — only needed if you want the useThaiAddressAutocomplete hook from thaizip/react. Without React, the core API works exactly the same.

The package splits into three entry points so you only import what you use:

import pathcontents
thaizipcore functions + types (no React code, 4.4 KB gzip)
thaizip/reactuseThaiAddressAutocomplete (ships "use client")
thaizip/dataloadDefaultIndex, clearDefaultIndex (132 KB gzip)

thaizip/data is separated out because it’s by far the largest chunk — a tree-shaking bundler won’t pull it in unless you actually import it.

import { loadDefaultIndex } from 'thaizip/data'
import { searchThaiAddress, formatThaiAddressSuggestion, resolveThaiAddress } from 'thaizip'
const index = await loadDefaultIndex() // ~40ms of synchronous work, cached after
searchThaiAddress(index, 'ลาดพร้าว')
searchThaiAddress(index, 'bang rak')
searchThaiAddress(index, '10500')

loadDefaultIndex() loads all tambon/amphure/province data and builds an in-memory trigram index. The result is cached as a module-level singleton, so subsequent calls return the same index immediately without rebuilding it.

Call loadDefaultIndex() at mount time or when the route loads — don’t wait for the user’s first keystroke. Building the index costs roughly 40ms of synchronous main-thread work, and if that happens while the user is typing, it shows up as about 2 dropped frames.

  • SearchingsearchThaiAddress options, result ranking, and known limitations
  • Postal code lookup — how postal code search behaves, and why zipLimit is unlimited by default
  • Cascade dropdowns — the province → district → subdistrict enumeration API
  • English input — RTGS spellings and the supported alias list
  • React HookuseThaiAddressAutocomplete from thaizip/react
  • Custom data — build an index from your own data with buildThaiAddressIndex
  • Playground — try every searchThaiAddress option and see the results live