@isofh/chuyen-doi-dia-chi-2-cap 1.0.3 → 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.
- package/dataXa.json +5 -1
- package/index.js +20 -2
- package/package.json +1 -1
package/dataXa.json
CHANGED
|
@@ -3054,7 +3054,11 @@
|
|
|
3054
3054
|
"ten": "Hồng Bàng",
|
|
3055
3055
|
"timKiem": "hongbang",
|
|
3056
3056
|
"satNhapTu": [
|
|
3057
|
-
{
|
|
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" },
|
package/index.js
CHANGED
|
@@ -146,6 +146,9 @@ const getVerifyOptions = (tinhOrOptions, maybeOptions) => {
|
|
|
146
146
|
};
|
|
147
147
|
};
|
|
148
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
|
+
|
|
149
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.
|
|
150
153
|
const getProvinceSearchKeys = (value = "") => {
|
|
151
154
|
const keys = [createUniqueText(value), normalizeAdministrativeCode(value)].filter(Boolean);
|
|
@@ -207,6 +210,7 @@ const verifyXaName = (tenXa, tinhOrOptions, maybeOptions) => {
|
|
|
207
210
|
const sourceDataXa = options.dataXa || getDataXaSync();
|
|
208
211
|
const normalizedXa = normalizeAdministrativeCode(tenXa);
|
|
209
212
|
const normalizedTinh = normalizeAdministrativeCode(tinh);
|
|
213
|
+
const normalizedHuyen = normalizeDistrictCode(options.huyen);
|
|
210
214
|
const matchedProvinces = getProvinceCandidates(tinh, sourceDataXa);
|
|
211
215
|
|
|
212
216
|
if (!normalizedXa) {
|
|
@@ -222,23 +226,36 @@ const verifyXaName = (tenXa, tinhOrOptions, maybeOptions) => {
|
|
|
222
226
|
|
|
223
227
|
const matches = [];
|
|
224
228
|
|
|
229
|
+
const isDistrictCompatible = (districtValue = "") => {
|
|
230
|
+
if (!normalizedHuyen || !districtValue) {
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return normalizeDistrictCode(districtValue) === normalizedHuyen;
|
|
235
|
+
};
|
|
236
|
+
|
|
225
237
|
matchedProvinces.forEach((province) => {
|
|
226
238
|
province.dsXa.forEach((xa) => {
|
|
227
|
-
if (xa.timKiem === normalizedXa) {
|
|
239
|
+
if (xa.timKiem === normalizedXa && isDistrictCompatible(xa.huyen)) {
|
|
228
240
|
matches.push({
|
|
229
241
|
matchType: "current",
|
|
230
242
|
tenXa: xa.ten,
|
|
231
243
|
tenTinh: province.ten,
|
|
244
|
+
huyen: xa.huyen || "",
|
|
232
245
|
});
|
|
233
246
|
}
|
|
234
247
|
|
|
235
248
|
xa.satNhapTu?.forEach((satNhapItem) => {
|
|
236
|
-
if (
|
|
249
|
+
if (
|
|
250
|
+
satNhapItem.timKiem === normalizedXa &&
|
|
251
|
+
isDistrictCompatible(satNhapItem.huyen || xa.huyen)
|
|
252
|
+
) {
|
|
237
253
|
matches.push({
|
|
238
254
|
matchType: "satNhapTu",
|
|
239
255
|
tenXa: xa.ten,
|
|
240
256
|
tenTinh: province.ten,
|
|
241
257
|
tenXaCu: satNhapItem.ten,
|
|
258
|
+
huyen: satNhapItem.huyen || xa.huyen || "",
|
|
242
259
|
});
|
|
243
260
|
}
|
|
244
261
|
});
|
|
@@ -252,6 +269,7 @@ const verifyXaName = (tenXa, tinhOrOptions, maybeOptions) => {
|
|
|
252
269
|
provinceInput: tinh || "",
|
|
253
270
|
normalizedInput: normalizedXa,
|
|
254
271
|
normalizedProvince: normalizedTinh,
|
|
272
|
+
normalizedDistrict: normalizedHuyen,
|
|
255
273
|
isValid: uniqueMatches.length > 0,
|
|
256
274
|
matches: uniqueMatches,
|
|
257
275
|
};
|