@0xd33p/vietnam-divisions 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -0
- package/dist/__tests__/vn.test.d.ts +2 -0
- package/dist/__tests__/vn.test.d.ts.map +1 -0
- package/dist/__tests__/vn.test.js +1107 -0
- package/dist/__tests__/vn.test.js.map +1 -0
- package/dist/data/legacy/commune.json +11077 -0
- package/dist/data/legacy/district.json +730 -0
- package/dist/data/legacy/province.json +65 -0
- package/dist/data/v3/commune.json +16607 -0
- package/dist/data/v3/province.json +240 -0
- package/dist/data/v3/province_merges.json +256 -0
- package/dist/data/v3/ward_mappings.json +98795 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +332 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/address.d.ts +37 -0
- package/dist/internal/address.d.ts.map +1 -0
- package/dist/internal/address.js +164 -0
- package/dist/internal/address.js.map +1 -0
- package/dist/internal/helpers.d.ts +24 -0
- package/dist/internal/helpers.d.ts.map +1 -0
- package/dist/internal/helpers.js +55 -0
- package/dist/internal/helpers.js.map +1 -0
- package/dist/internal/legacy/index.d.ts +21 -0
- package/dist/internal/legacy/index.d.ts.map +1 -0
- package/dist/internal/legacy/index.js +60 -0
- package/dist/internal/legacy/index.js.map +1 -0
- package/dist/internal/legacy/types.d.ts +18 -0
- package/dist/internal/legacy/types.d.ts.map +1 -0
- package/dist/internal/legacy/types.js +2 -0
- package/dist/internal/legacy/types.js.map +1 -0
- package/dist/internal/v3/index.d.ts +21 -0
- package/dist/internal/v3/index.d.ts.map +1 -0
- package/dist/internal/v3/index.js +55 -0
- package/dist/internal/v3/index.js.map +1 -0
- package/dist/internal/v3/types.d.ts +33 -0
- package/dist/internal/v3/types.d.ts.map +1 -0
- package/dist/internal/v3/types.js +2 -0
- package/dist/internal/v3/types.js.map +1 -0
- package/dist/types.d.ts +37 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @0xd33p/vietnam-divisions — Dữ liệu hành chính Việt Nam
|
|
2
|
+
|
|
3
|
+
Package nội bộ — zero runtime dependencies. Quản lý 2 hệ thống dữ liệu (v3 hiện tại &
|
|
4
|
+
legacy cũ) với auto-detect và auto-resolve ID.
|
|
5
|
+
|
|
6
|
+
## API
|
|
7
|
+
|
|
8
|
+
1 object `vn` — unified deep module. 3 methods, 3 types.
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
import { vn } from '@0xd33p/vietnam-divisions';
|
|
12
|
+
import type { GeoUnit, GeoError, GeoResult } from '@0xd33p/vietnam-divisions';
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
| Method | Input | Output |
|
|
16
|
+
| ------------------------------------ | ---------------- | ------------------------------------------ |
|
|
17
|
+
| `vn.divisions()` | — | 34 tỉnh (v3) |
|
|
18
|
+
| `vn.divisions(provinceId)` | `string` | Xã/phường theo tỉnh |
|
|
19
|
+
| `vn.lookup(query)` | `string` | Tra cứu ID/mã/tên — auto-resolve legacy ID |
|
|
20
|
+
| `vn.search(name)` | `string` | Tìm tỉnh theo tên |
|
|
21
|
+
| `vn.search(name, provinceId)` | `string, string` | Tìm xã theo tên trong tỉnh |
|
|
22
|
+
| `vn.legacy.divisions()` | — | 63 tỉnh (legacy) |
|
|
23
|
+
| `vn.legacy.divisions(provinceId)` | `string` | Huyện theo tỉnh |
|
|
24
|
+
| `vn.legacy.lookup(query)` | `string` | Tra cứu legacy ID (tỉnh/huyện/xã) |
|
|
25
|
+
| `vn.legacy.search(name)` | `string` | Tìm tỉnh legacy theo tên |
|
|
26
|
+
| `vn.legacy.search(name, provinceId)` | `string, string` | Tìm huyện theo tên trong tỉnh |
|
|
27
|
+
|
|
28
|
+
Output type cho tất cả method: `GeoResult<T> | GeoErrorResult` (legacy methods cũng
|
|
29
|
+
vậy — unified error handling).
|
|
30
|
+
|
|
31
|
+
## Types
|
|
32
|
+
|
|
33
|
+
| Type | Mô tả |
|
|
34
|
+
| ---------------- | --------------------------------------------------------------- |
|
|
35
|
+
| `GeoUnit` | `{ id: string; name: string }` |
|
|
36
|
+
| `GeoError` | `'province_not_found' \| 'commune_not_found' \| ...` (9 errors) |
|
|
37
|
+
| `GeoResult<T>` | `{ data: T }` — success |
|
|
38
|
+
| `GeoErrorResult` | `{ data: null; error: GeoError }` — failure |
|
|
39
|
+
|
|
40
|
+
## Ví dụ
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// 34 tỉnh mới
|
|
44
|
+
const { data: provinces } = vn.divisions();
|
|
45
|
+
|
|
46
|
+
// Xã/phường theo tỉnh (cần 2-char ID)
|
|
47
|
+
const { data: communes } = vn.divisions('79');
|
|
48
|
+
|
|
49
|
+
// Tra cứu — auto-resolve old ID → new ID
|
|
50
|
+
const result = vn.lookup('79'); // province by ID → { name: 'Hồ Chí Minh', kind: 'province' }
|
|
51
|
+
const hcm = vn.lookup('HCM'); // province by code
|
|
52
|
+
const hn = vn.lookup('01'); // province by ID
|
|
53
|
+
const ward = vn.lookup('27148'); // commune by ID
|
|
54
|
+
|
|
55
|
+
// Tìm kiếm
|
|
56
|
+
const found = vn.search('Hồ Chí Minh');
|
|
57
|
+
const wards = vn.search('Phường', '79');
|
|
58
|
+
|
|
59
|
+
// Legacy — 63 tỉnh, 3 cấp (province → district → commune)
|
|
60
|
+
const { data: oldProvinces } = vn.legacy.divisions();
|
|
61
|
+
const { data: huyen } = vn.legacy.divisions('01');
|
|
62
|
+
const { data: oldWard } = vn.legacy.lookup('00100');
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Hidden
|
|
66
|
+
|
|
67
|
+
- **Auto-detect**: `lookup()` nhận ID 2-char (tỉnh), 3-char (mã), 5-char (xã), hoặc tên
|
|
68
|
+
- **Auto-resolve**: old province/commune IDs → new IDs qua merge/mapping data
|
|
69
|
+
|
|
70
|
+
## File structure
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
src/
|
|
74
|
+
├── index.ts # vn object (public API)
|
|
75
|
+
├── types.ts # GeoUnit, GeoError, GeoResult, GeoErrorResult
|
|
76
|
+
├── data/
|
|
77
|
+
│ ├── v3/ # 34 tỉnh (NQ 202/2025/QH15)
|
|
78
|
+
│ └── legacy/ # 63 tỉnh, 696 huyện, 10,051 xã (cũ)
|
|
79
|
+
└── internal/ # Implementation
|
|
80
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vn.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/vn.test.ts"],"names":[],"mappings":""}
|