UNPKG

@simoko/tw-zip

Version:

台灣縣市、行政區、郵遞區號(3碼/6碼)查詢工具,支援 React/Vue/Svelte/SolidJS/Angular

79 lines (77 loc) 2.19 kB
/** * 6 碼郵遞區號查詢模組 * @module @simoko/tw-zip/zip6 */ interface AddressQuery { /** 縣市 */ city: string; /** 行政區 */ area: string; /** 路名 */ road: string; /** 門牌號碼 */ number?: number; /** 巷 */ lane?: number; /** 弄 */ alley?: number; } interface Zip6Result { /** 6 碼郵遞區號 */ zipcode: string; /** 3 碼郵遞區號 */ zip3: string; /** 縣市 */ city: string; /** 行政區 */ area: string; /** 路名 */ road: string; } /** * 取得所有有 6 碼資料的縣市 */ declare function getCities6(): string[]; /** * 取得指定縣市的所有行政區 */ declare function getAreas6(city: string): string[]; /** * 取得指定行政區的所有路名 */ declare function getRoads6(city: string, area: string): string[]; /** * 查詢 6 碼郵遞區號 * @param query 地址查詢條件 * @example * getZipCode6({ city: '臺北市', area: '中正區', road: '三元街', number: 145 }) * // { zipcode: '100060', zip3: '100', city: '臺北市', area: '中正區', road: '三元街' } */ declare function getZipCode6(query: AddressQuery): Zip6Result | undefined; /** * 取得指定路名的所有 6 碼郵遞區號 * @example * getZipCodes6ByRoad('臺北市', '中正區', '三元街') * // ['100053', '100060'] */ declare function getZipCodes6ByRoad(city: string, area: string, road: string): string[]; /** * 搜尋路名 * @param keyword 關鍵字 * @param city 限定縣市(可選) * @param area 限定行政區(可選) * @example * searchRoads6('三元') * // [{ city: '臺北市', area: '中正區', road: '三元街' }, ...] */ declare function searchRoads6(keyword: string, city?: string, area?: string): Array<{ city: string; area: string; road: string; }>; /** * 驗證 6 碼郵遞區號是否有效 * @description 使用快取優化,首次調用會建立快取,後續調用為 O(1) 查詢 */ declare function isValidZipCode6(zipcode: string): boolean; export { type AddressQuery, type Zip6Result, getAreas6, getCities6, getRoads6, getZipCode6, getZipCodes6ByRoad, isValidZipCode6, searchRoads6 };