@isofh/chuyen-doi-dia-chi-2-cap 1.0.2 → 1.0.4

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.
Files changed (3) hide show
  1. package/dataXa.json +9 -5
  2. package/index.js +28 -3
  3. package/package.json +2 -2
package/dataXa.json CHANGED
@@ -3054,7 +3054,11 @@
3054
3054
  "ten": "Hồng Bàng",
3055
3055
  "timKiem": "hongbang",
3056
3056
  "satNhapTu": [
3057
- { "ten": "Hoàng Văn Thụ", "timKiem": "hoangvanthu" },
3057
+ {
3058
+ "ten": "Hoàng Văn Thụ",
3059
+ "timKiem": "hoangvanthu",
3060
+ "huyen": "hongbang"
3061
+ },
3058
3062
  { "ten": "Minh Khai", "timKiem": "minhkhai" },
3059
3063
  { "ten": "Phan Bội Châu", "timKiem": "phanboichau" },
3060
3064
  { "ten": "Thượng Lý", "timKiem": "thuongly" },
@@ -24501,9 +24505,9 @@
24501
24505
  "ten": "Long Nguyên",
24502
24506
  "timKiem": "longnguyen",
24503
24507
  "satNhapTu": [
24504
- { "ten": "An Điền", "timKiem": "andien" },
24505
- { "ten": "Long Nguyên", "timKiem": "longnguyen" },
24506
- { "ten": "Mỹ Phước", "timKiem": "myphuoc" }
24508
+ { "ten": "An Điền", "timKiem": "andien", "huyen": "bencat" },
24509
+ { "ten": "Long Nguyên", "timKiem": "longnguyen", "huyen": "baubang" },
24510
+ { "ten": "Mỹ Phước", "timKiem": "myphuoc", "huyen": "bencat" }
24507
24511
  ]
24508
24512
  },
24509
24513
  {
@@ -24512,7 +24516,7 @@
24512
24516
  "satNhapTu": [
24513
24517
  { "ten": "Tân Hưng", "timKiem": "tanhung" },
24514
24518
  { "ten": "Lai Hưng", "timKiem": "laihung" },
24515
- { "ten": "Mỹ Phước", "timKiem": "myphuoc" }
24519
+ { "ten": "Mỹ Phước", "timKiem": "myphuoc", "huyen": "bencat" }
24516
24520
  ]
24517
24521
  },
24518
24522
  {
package/index.js CHANGED
@@ -1,4 +1,11 @@
1
- require("mainam-react-native-string-utils");
1
+ // Chỉ nạp string-utils khi runtime hiện tại chưa có đủ prototype cần dùng.
2
+ // Cách này tránh ghi đè lại `String.prototype.toAddress` của app host nếu app đã nạp một bản mới hơn.
3
+ if (
4
+ typeof "".createUniqueText !== "function" ||
5
+ typeof "".toAddress !== "function"
6
+ ) {
7
+ require("mainam-react-native-string-utils");
8
+ }
2
9
 
3
10
  let dataXa = null;
4
11
  let dataXaPromise = null;
@@ -139,6 +146,9 @@ const getVerifyOptions = (tinhOrOptions, maybeOptions) => {
139
146
  };
140
147
  };
141
148
 
149
+ // Chuẩn hóa tên huyện/quận để so khớp với metadata `huyen` trong dataset khi cần phân biệt xã với số nhà.
150
+ const normalizeDistrictCode = (value = "") => normalizeAdministrativeCode(value);
151
+
142
152
  // Tạo tập khóa tìm kiếm của tỉnh từ cả tên gốc lẫn tên đã bỏ prefix.
143
153
  const getProvinceSearchKeys = (value = "") => {
144
154
  const keys = [createUniqueText(value), normalizeAdministrativeCode(value)].filter(Boolean);
@@ -200,6 +210,7 @@ const verifyXaName = (tenXa, tinhOrOptions, maybeOptions) => {
200
210
  const sourceDataXa = options.dataXa || getDataXaSync();
201
211
  const normalizedXa = normalizeAdministrativeCode(tenXa);
202
212
  const normalizedTinh = normalizeAdministrativeCode(tinh);
213
+ const normalizedHuyen = normalizeDistrictCode(options.huyen);
203
214
  const matchedProvinces = getProvinceCandidates(tinh, sourceDataXa);
204
215
 
205
216
  if (!normalizedXa) {
@@ -215,23 +226,36 @@ const verifyXaName = (tenXa, tinhOrOptions, maybeOptions) => {
215
226
 
216
227
  const matches = [];
217
228
 
229
+ const isDistrictCompatible = (districtValue = "") => {
230
+ if (!normalizedHuyen || !districtValue) {
231
+ return true;
232
+ }
233
+
234
+ return normalizeDistrictCode(districtValue) === normalizedHuyen;
235
+ };
236
+
218
237
  matchedProvinces.forEach((province) => {
219
238
  province.dsXa.forEach((xa) => {
220
- if (xa.timKiem === normalizedXa) {
239
+ if (xa.timKiem === normalizedXa && isDistrictCompatible(xa.huyen)) {
221
240
  matches.push({
222
241
  matchType: "current",
223
242
  tenXa: xa.ten,
224
243
  tenTinh: province.ten,
244
+ huyen: xa.huyen || "",
225
245
  });
226
246
  }
227
247
 
228
248
  xa.satNhapTu?.forEach((satNhapItem) => {
229
- if (satNhapItem.timKiem === normalizedXa) {
249
+ if (
250
+ satNhapItem.timKiem === normalizedXa &&
251
+ isDistrictCompatible(satNhapItem.huyen || xa.huyen)
252
+ ) {
230
253
  matches.push({
231
254
  matchType: "satNhapTu",
232
255
  tenXa: xa.ten,
233
256
  tenTinh: province.ten,
234
257
  tenXaCu: satNhapItem.ten,
258
+ huyen: satNhapItem.huyen || xa.huyen || "",
235
259
  });
236
260
  }
237
261
  });
@@ -245,6 +269,7 @@ const verifyXaName = (tenXa, tinhOrOptions, maybeOptions) => {
245
269
  provinceInput: tinh || "",
246
270
  normalizedInput: normalizedXa,
247
271
  normalizedProvince: normalizedTinh,
272
+ normalizedDistrict: normalizedHuyen,
248
273
  isValid: uniqueMatches.length > 0,
249
274
  matches: uniqueMatches,
250
275
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isofh/chuyen-doi-dia-chi-2-cap",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Chuan hoa dia chi hanh chinh cu sang format 2 cap moi",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -18,7 +18,7 @@
18
18
  "isofh"
19
19
  ],
20
20
  "dependencies": {
21
- "mainam-react-native-string-utils": "^4.0.13"
21
+ "mainam-react-native-string-utils": "^4.0.14"
22
22
  },
23
23
  "author": "ISOFH",
24
24
  "license": "ISC"