private-thailand-address 1.0.4 → 1.0.6

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 (2) hide show
  1. package/index.js +17 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -77,11 +77,19 @@ function toAddress(rawData) {
77
77
  const remapped = []
78
78
 
79
79
  for (const item of rawData) {
80
- for (const province of (item?.provinceList || [])) {
81
- const districtList = item?.districtList?.filter((dl) => dl.proviceId === province.provinceId) || []
80
+ if (!('provinceList' in item) || !item.provinceList) {
81
+ continue
82
+ }
83
+
84
+ for (const province of (item.provinceList || [])) {
85
+ const districtList = (('districtList' in item) && item.districtList)
86
+ ? item.districtList.filter((dl) => dl.proviceId === province.provinceId)
87
+ : []
82
88
 
83
89
  for (const district of districtList) {
84
- const subDistrictList = item?.subDistrictList?.filter((sdl) => sdl.provinceId === district.proviceId && sdl.districtId === district.districtId) || []
90
+ const subDistrictList = (('subDistrictList' in item) && item.subDistrictList)
91
+ ? item.subDistrictList.filter((sdl) => sdl.provinceId === district.proviceId && sdl.districtId === district.districtId)
92
+ : []
85
93
 
86
94
  for (const subDistrict of subDistrictList) {
87
95
  remapped.push({
@@ -122,9 +130,9 @@ function getAutoSuggestion(search, limit = 10) {
122
130
  data.forEach((item) => {
123
131
  if (
124
132
  regex.test(item.zipCode)
125
- || item?.subDistrictList?.some((subDistrict) => regex.test(subDistrict.subDistrictName))
126
- || item?.districtList?.some((district) => regex.test(district.districtName))
127
- || item?.provinceList?.some((province) => regex.test(province.provinceName))
133
+ || (item.subDistrictList && item.subDistrictList.some((subDistrict) => regex.test(subDistrict.subDistrictName)))
134
+ || (item.districtList && item.districtList.some((district) => regex.test(district.districtName)))
135
+ || (item.provinceList && item.provinceList.some((province) => regex.test(province.provinceName)))
128
136
  ) {
129
137
  results.push(item)
130
138
  }
@@ -153,7 +161,7 @@ function getSubDistricts(search, limit = 10) {
153
161
  const results = []
154
162
 
155
163
  data.forEach((item) => {
156
- if (item?.subDistrictList?.some((subDistrict) => regex.test(subDistrict.subDistrictName))) {
164
+ if (item.subDistrictList && item.subDistrictList.some((subDistrict) => regex.test(subDistrict.subDistrictName))) {
157
165
  results.push(item)
158
166
  }
159
167
  })
@@ -169,7 +177,7 @@ function getDistricts(search, limit = 10) {
169
177
  const results = []
170
178
 
171
179
  data.forEach((item) => {
172
- if (item?.districtList?.some((district) => regex.test(district.districtName))) {
180
+ if (item.districtList && item.districtList.some((district) => regex.test(district.districtName))) {
173
181
  results.push(item)
174
182
  }
175
183
  })
@@ -185,7 +193,7 @@ function getProvinces(search, limit = 10) {
185
193
  const results = []
186
194
 
187
195
  data.forEach((item) => {
188
- if (item?.provinceList?.some((province) => regex.test(province.provinceName))) {
196
+ if (item.provinceList && item.provinceList.some((province) => regex.test(province.provinceName))) {
189
197
  results.push(item)
190
198
  }
191
199
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "private-thailand-address",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Private Thailand Address. Required node version 16 or later.",
5
5
  "main": "index.js",
6
6
  "scripts": {