enumerate
import { listProvinces, listAmphures, listTambons } from 'thaizip'
None of these three functions take a text query. They’re for building cascade dropdowns (province → district → subdistrict), backed by the byProvince/byAmphure groupings precomputed when the index was built — no full scan of records on every call.
listProvinces
Section titled “listProvinces”function listProvinces(index: TrigramIndex): ProvinceSummary[]Parameters
Section titled “Parameters”| Name | Type | Default | Description |
|---|---|---|---|
index | TrigramIndex | — (required) | The index to list provinces from |
Returns
Section titled “Returns”ProvinceSummary[] — all 77 provinces (in the bundled default dataset), deduplicated, sorted by Thai name with Intl.Collator('th')
type ProvinceSummary = { id: number nameTh: string nameEn: string}Example
Section titled “Example”import { listProvinces } from 'thaizip'
const provinces = listProvinces(index) // 77 provinces, sorted by Thai namelistAmphures
Section titled “listAmphures”function listAmphures(index: TrigramIndex, provinceId: number): AmphureSummary[]Parameters
Section titled “Parameters”| Name | Type | Default | Description |
|---|---|---|---|
index | TrigramIndex | — (required) | The index to list districts from |
provinceId | number | — (required) | A province id (from ProvinceSummary.id) |
Returns
Section titled “Returns”AmphureSummary[] — all districts within that province, deduplicated, sorted by Thai name. Returns an empty array [] if provinceId doesn’t exist (e.g. 0 before anything is selected).
type AmphureSummary = { id: number nameTh: string nameEn: string provinceId: number}Example
Section titled “Example”import { listAmphures } from 'thaizip'
listAmphures(index, 1) // every district in BangkoklistTambons
Section titled “listTambons”function listTambons(index: TrigramIndex, amphureId: number): TambonSummary[]Parameters
Section titled “Parameters”| Name | Type | Default | Description |
|---|---|---|---|
index | TrigramIndex | — (required) | The index to list subdistricts from |
amphureId | number | — (required) | A district id (from AmphureSummary.id) |
Returns
Section titled “Returns”TambonSummary[] — all subdistricts within that district, sorted by Thai name, each with its zipCode attached. Returns an empty array [] if amphureId doesn’t exist.
type TambonSummary = { id: number nameTh: string nameEn: string amphureId: number zipCode: string}Example
Section titled “Example”import { listTambons } from 'thaizip'
listTambons(index, 1001) // every subdistrict in that district, with zipCodeShared notes
Section titled “Shared notes”- All three functions always return an empty array
[]for an unknown id — never throw — which makes it easy to write UI that resets child selections whenever a parent selection changes - Each
byAmphureentry already maps to exactly one tambon, solistTambonsdoesn’t need to deduplicate the waylistProvinces/listAmphuresdo - If the
indexpassed in lacksbyProvince/byAmphure(for example, an older-shaped index built by hand), all three functions fall back to scanningindex.recordsin full