diff --git a/packages/core/LICENSE b/packages/core/LICENSE new file mode 100644 index 0000000..4f9dbc7 --- /dev/null +++ b/packages/core/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 LUO YONG NENG + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/core/README.md b/packages/core/README.md new file mode 100644 index 0000000..0ae8cef --- /dev/null +++ b/packages/core/README.md @@ -0,0 +1,72 @@ +# @zipkit/core + +台灣地址英譯與 3+3 郵遞區號查詢的核心邏輯,無框架依賴。 + +此套件是 [Zipkit](https://github.com/ronload/zipkit) 的領域核心,提供 UPU 格式地址英譯、六碼郵遞區號(3+3)特異性比對,以及共用型別。純函式、無副作用,可用於任何 JavaScript / TypeScript 環境。 + +ESM-only。以 [tsdown](https://tsdown.dev/) 建置,輸出 ESM 與型別宣告。 + +## 安裝 + +```bash +pnpm add @zipkit/core +``` + +## API + +### `formatEnglishAddress(city, district, road, detail): string` + +將中文地址格式化為 UPU 標準英譯地址。輸出順序為 `[Room], [Floor], No. [Number], [Alley], [Lane], [Road], [District], [City] [Zip], Taiwan (R.O.C.)`。 + +```ts +import { formatEnglishAddress } from "@zipkit/core"; + +formatEnglishAddress( + { name: "臺北市", en: "Taipei City", districts: [] }, + { name: "中正區", en: "Zhongzheng Dist.", zip3: "100" }, + { name: "忠孝東路一段", en: "Sec. 1, Zhongxiao E. Rd." }, + { lane: "", alley: "", number: "5之1", floor: "3", room: "" }, +); +// => "3F., No. 5-1, Sec. 1, Zhongxiao E. Rd., Zhongzheng Dist., Taipei City 100, Taiwan (R.O.C.)" +``` + +### `lookupZip6(ranges, roadName, lane, alley, number, numberSub, floor): string | null` + +以特異性評分比對地址與郵遞區號範圍規則,回傳六碼郵遞區號;無對應時回傳 `null`。條件越多(巷段、弄段、門牌範圍、單雙號、樓層)的規則優先採用。`ranges` 為該行政區的範圍規則陣列(由資料來源載入)。 + +```ts +import { lookupZip6 } from "@zipkit/core"; + +// ranges: ZipRange[](該行政區的範圍規則) +const zip6 = lookupZip6(ranges, "忠孝東路一段", 0, 0, 5, 1, 3); +// => "100002" 或 null +``` + +### `parseNumber(input): { number: number; sub: number }` + +解析含「之」記法的門牌號字串。 + +```ts +import { parseNumber } from "@zipkit/core"; + +parseNumber("5之1"); // => { number: 5, sub: 1 } +parseNumber("33"); // => { number: 33, sub: 0 } +``` + +## 型別 + +匯出 `City`、`District`、`Road`、`ZipRange`、`AddressDetail` 五個領域型別,皆可作為 `import type` 引入。 + +```ts +import type { + City, + District, + Road, + ZipRange, + AddressDetail, +} from "@zipkit/core"; +``` + +## 授權 + +[MIT](./LICENSE) diff --git a/packages/core/package.json b/packages/core/package.json index e1ff02b..d1186fd 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,8 +1,31 @@ { "name": "@zipkit/core", - "version": "0.0.0", + "version": "0.1.0", + "description": "Framework-agnostic core for Taiwan address English (UPU) translation and 3+3 postal code lookup.", + "keywords": [ + "taiwan", + "postal-code", + "zipcode", + "zip-code", + "address", + "upu", + "3+3", + "english-translation" + ], + "license": "MIT", + "author": "ronload", + "homepage": "https://github.com/ronload/zipkit/tree/main/packages/core#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/ronload/zipkit.git", + "directory": "packages/core" + }, + "bugs": { + "url": "https://github.com/ronload/zipkit/issues" + }, "private": true, "type": "module", + "sideEffects": false, "exports": { ".": { "types": "./dist/index.d.ts", @@ -15,6 +38,9 @@ "files": [ "dist" ], + "publishConfig": { + "access": "public" + }, "scripts": { "build": "tsdown", "dev": "tsdown --watch",