Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/core/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
72 changes: 72 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
@@ -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)
28 changes: 27 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -15,6 +38,9 @@
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsdown",
"dev": "tsdown --watch",
Expand Down
Loading