latest-ph-address-thanks-to-anehan 1.0.0 → 1.0.2
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 +128 -404
- package/data/by-level.json.gz +0 -0
- package/data/by-psgc.json.gz +0 -0
- package/index.js +26 -3
- package/package.json +4 -3
- package/data/addresses.json +0 -350154
- package/data/by-level.json +0 -350036
- package/data/by-psgc.json +0 -350154
- package/data/hierarchy.json +0 -3458
package/README.md
CHANGED
|
@@ -3,16 +3,14 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/latest-ph-address-thanks-to-anehan)
|
|
4
4
|
[](https://opensource.org/licenses/ISC)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Complete Philippine addresses database with 43,769+ addresses. Perfect for building address forms and cascading dropdowns.
|
|
7
7
|
|
|
8
8
|
**Features:**
|
|
9
|
-
- ✅ **43,769+ addresses** - Complete coverage
|
|
9
|
+
- ✅ **43,769+ addresses** - Complete coverage (18 Regions, 82 Provinces, 149 Cities, 1,493 Municipalities, 42,011 Barangays)
|
|
10
10
|
- ✅ **Official PSGC codes** - Philippine Standard Geographic Code support
|
|
11
|
-
- ✅ **Cascading dropdowns** - Built-in helpers for Region → Province → City/Municipality → Barangay
|
|
12
11
|
- ✅ **NCR support** - Automatic handling of National Capital Region (no provinces)
|
|
13
12
|
- ✅ **HUC support** - Highly Urbanized Cities with geographic province mapping
|
|
14
|
-
- ✅ **
|
|
15
|
-
- ✅ **Zero dependencies** - Lightweight and fast
|
|
13
|
+
- ✅ **Zero dependencies** - Lightweight (~1.2 MB)
|
|
16
14
|
- ✅ **Latest data** - 3Q 2025 PSGC data
|
|
17
15
|
|
|
18
16
|
All thanks to the [anehan.online](https://anehan.online) Tech Team! 🇵🇭
|
|
@@ -23,301 +21,157 @@ All thanks to the [anehan.online](https://anehan.online) Tech Team! 🇵🇭
|
|
|
23
21
|
npm install latest-ph-address-thanks-to-anehan
|
|
24
22
|
```
|
|
25
23
|
|
|
26
|
-
##
|
|
24
|
+
## 🚀 Quick Start
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
- **82 Provinces**
|
|
30
|
-
- **149 Cities** (including HUC, CC, ICC)
|
|
31
|
-
- **1,493 Municipalities**
|
|
32
|
-
- **42,011 Barangays**
|
|
33
|
-
- **Total: 43,769 addresses**
|
|
26
|
+
### Import
|
|
34
27
|
|
|
35
|
-
|
|
28
|
+
```typescript
|
|
29
|
+
// ES6 Import (Recommended)
|
|
30
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
36
31
|
|
|
37
|
-
|
|
32
|
+
// ES6 Named Imports
|
|
33
|
+
import { getRegions, getProvincesByRegion, getBarangaysByCityOrMun } from 'latest-ph-address-thanks-to-anehan';
|
|
38
34
|
|
|
39
|
-
|
|
35
|
+
// CommonJS (Node.js)
|
|
40
36
|
const phAddress = require('latest-ph-address-thanks-to-anehan');
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Basic Usage
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
41
43
|
|
|
42
44
|
// Get all regions
|
|
43
45
|
const regions = phAddress.getRegions();
|
|
44
46
|
// Returns: Array of 18 regions (sorted A-Z)
|
|
47
|
+
// Type: Array<{ psgc: string; name: string; correspondenceCode: string; geographicLevel: string }>
|
|
45
48
|
|
|
46
|
-
// Get provinces
|
|
47
|
-
const provinces = phAddress.getProvincesByRegion();
|
|
48
|
-
// Returns: Array of
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
// Get provinces in a specific region
|
|
52
|
-
const carProvinces = phAddress.getProvincesByRegion('1400000000'); // CAR
|
|
53
|
-
// Returns: Array of provinces in CAR (sorted A-Z)
|
|
49
|
+
// Get provinces for a region
|
|
50
|
+
const provinces = phAddress.getProvincesByRegion('1400000000'); // CAR
|
|
51
|
+
// Returns: Array of provinces (sorted A-Z)
|
|
52
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
54
53
|
|
|
55
54
|
// Get provinces for NCR
|
|
56
|
-
const ncrProvinces = phAddress.getProvincesByRegion('1300000000');
|
|
55
|
+
const ncrProvinces = phAddress.getProvincesByRegion('1300000000');
|
|
57
56
|
// Returns: "-NO PROVINCE-" (string)
|
|
57
|
+
// Type: string
|
|
58
|
+
|
|
59
|
+
// Get all provinces (includes "-NO PROVINCE-" option)
|
|
60
|
+
const allProvinces = phAddress.getProvincesByRegion();
|
|
61
|
+
// Returns: Array of 83 items ("-NO PROVINCE-" appears first)
|
|
62
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
58
63
|
|
|
59
|
-
// Get cities and municipalities
|
|
64
|
+
// Get cities and municipalities for a province
|
|
60
65
|
const cities = phAddress.getCitiesAndMunsByProvince('1401100000'); // Benguet
|
|
61
|
-
// Returns: Array
|
|
62
|
-
//
|
|
66
|
+
// Returns: Array including City of Baguio (HUC) + all municipalities
|
|
67
|
+
// Type: Array<{ psgc: string; name: string; cityClass?: string; ... }>
|
|
63
68
|
|
|
64
|
-
// Get cities
|
|
69
|
+
// Get cities for NCR
|
|
65
70
|
const ncrCities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', '1300000000');
|
|
66
|
-
// Returns: Array of NCR cities and municipalities
|
|
71
|
+
// Returns: Array of NCR cities and municipalities
|
|
72
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
67
73
|
|
|
68
|
-
// Get barangays
|
|
74
|
+
// Get barangays
|
|
69
75
|
const barangays = phAddress.getBarangaysByCityOrMun('1430300000'); // Baguio City
|
|
70
76
|
// Returns: Array of barangays (sorted A-Z)
|
|
71
|
-
//
|
|
77
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
72
78
|
```
|
|
73
79
|
|
|
74
|
-
|
|
80
|
+
## 📋 Cascading Dropdown Example
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
75
84
|
|
|
76
|
-
```javascript
|
|
77
85
|
// Step 1: Load regions
|
|
78
86
|
const regions = phAddress.getRegions();
|
|
79
87
|
|
|
80
88
|
// Step 2: User selects region → Get provinces
|
|
89
|
+
const regionPsgc: string = '1400000000'; // Example: CAR
|
|
81
90
|
const provinces = phAddress.getProvincesByRegion(regionPsgc);
|
|
82
|
-
// For NCR: Returns "-NO PROVINCE-" (string)
|
|
83
|
-
// For other regions: Returns array of provinces
|
|
84
|
-
|
|
85
|
-
// Step 3: User selects province → Get cities/municipalities
|
|
86
|
-
// If user selected "-NO PROVINCE-" (NCR case):
|
|
87
|
-
const ncrCities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', '1300000000');
|
|
88
|
-
// If user selected a regular province:
|
|
89
|
-
const cities = phAddress.getCitiesAndMunsByProvince(provincePsgc);
|
|
90
|
-
// Includes all cities (HUC, CC, ICC) and municipalities geographically in province
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
**Flow 1: Region → Province → City/Municipality → Barangay**
|
|
101
|
-
**Flow 2: Province → City/Municipality → Barangay** (when user doesn't know region)
|
|
102
|
-
|
|
103
|
-
### Key Features:
|
|
104
|
-
- ✅ Automatically handles **NCR** (returns "-NO PROVINCE-" instead of provinces)
|
|
105
|
-
- ✅ Shows **all city types** (HUC, CC, ICC) geographically located in selected province
|
|
106
|
-
- ✅ Includes **HUCs** in their geographic province (e.g., Baguio appears in Benguet)
|
|
107
|
-
- ✅ **"-NO PROVINCE-"** appears first in province list (sorted A-Z)
|
|
108
|
-
- ✅ Works for all HUCs including Manila, Baguio, and others
|
|
109
|
-
|
|
110
|
-
### Basic Dropdown Flow
|
|
111
|
-
|
|
112
|
-
```javascript
|
|
113
|
-
const phAddress = require('latest-ph-address-thanks-to-anehan');
|
|
114
|
-
|
|
115
|
-
// Step 1: Load regions
|
|
116
|
-
const regions = phAddress.getRegions();
|
|
117
|
-
// Populate first dropdown with regions
|
|
118
|
-
|
|
119
|
-
// Step 2: When user selects a region
|
|
120
|
-
function onRegionSelected(regionPsgc) {
|
|
121
|
-
const provinces = phAddress.getProvincesByRegion(regionPsgc);
|
|
122
|
-
|
|
123
|
-
if (provinces === '-NO PROVINCE-') {
|
|
124
|
-
// NCR case: Skip province dropdown, show cities/municipalities directly
|
|
125
|
-
const cities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', regionPsgc);
|
|
126
|
-
// Populate city/municipality dropdown (skip province dropdown)
|
|
127
|
-
} else {
|
|
128
|
-
// Regular region: Show provinces
|
|
129
|
-
// Populate province dropdown with provinces array
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Step 3: When user selects a province (if applicable)
|
|
134
|
-
function onProvinceSelected(provincePsgc, regionPsgc) {
|
|
135
|
-
// Get all cities (including HUCs) and municipalities geographically in province
|
|
92
|
+
if (provinces === '-NO PROVINCE-') {
|
|
93
|
+
// NCR case: Skip province dropdown
|
|
94
|
+
const cities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', regionPsgc);
|
|
95
|
+
} else {
|
|
96
|
+
// Regular region: Show provinces
|
|
97
|
+
// Step 3: User selects province → Get cities
|
|
98
|
+
const provincePsgc: string = '1401100000'; // Example: Benguet
|
|
136
99
|
const cities = phAddress.getCitiesAndMunsByProvince(provincePsgc);
|
|
137
|
-
// Populate city/municipality dropdown
|
|
138
100
|
}
|
|
139
101
|
|
|
140
|
-
// Step 4:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
// Populate barangay dropdown
|
|
144
|
-
}
|
|
102
|
+
// Step 4: User selects city → Get barangays
|
|
103
|
+
const cityMunPsgc: string = '1430300000'; // Example: Baguio City
|
|
104
|
+
const barangays = phAddress.getBarangaysByCityOrMun(cityMunPsgc);
|
|
145
105
|
```
|
|
146
106
|
|
|
147
|
-
###
|
|
107
|
+
### Province-First Flow (Auto-detect Region)
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
148
111
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
// "-NO PROVINCE-" appears first in the list
|
|
112
|
+
// User selects province first
|
|
113
|
+
const provinces = phAddress.getProvincesByRegion(); // All provinces + "-NO PROVINCE-"
|
|
114
|
+
const provincePsgc: string = '1401100000'; // Example: Benguet
|
|
153
115
|
|
|
154
|
-
// Step 2: When user selects "-NO PROVINCE-"
|
|
155
116
|
if (provincePsgc === '-NO PROVINCE-') {
|
|
117
|
+
// NCR case
|
|
156
118
|
const cities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', '1300000000');
|
|
157
|
-
// Show NCR cities/municipalities
|
|
158
119
|
} else {
|
|
159
|
-
//
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
### React Example
|
|
166
|
-
|
|
167
|
-
```jsx
|
|
168
|
-
import React, { useState } from 'react';
|
|
169
|
-
const phAddress = require('latest-ph-address-thanks-to-anehan');
|
|
170
|
-
|
|
171
|
-
function AddressDropdown() {
|
|
172
|
-
const [selectedRegion, setSelectedRegion] = useState(null);
|
|
173
|
-
const [selectedProvince, setSelectedProvince] = useState(null);
|
|
174
|
-
const [selectedCityMun, setSelectedCityMun] = useState(null);
|
|
175
|
-
const [selectedBarangay, setSelectedBarangay] = useState(null);
|
|
176
|
-
|
|
177
|
-
const [provinceOptions, setProvinceOptions] = useState([]);
|
|
178
|
-
const [cityMunOptions, setCityMunOptions] = useState([]);
|
|
179
|
-
const [barangayOptions, setBarangayOptions] = useState([]);
|
|
180
|
-
|
|
181
|
-
const [showProvince, setShowProvince] = useState(false);
|
|
182
|
-
|
|
183
|
-
// Load regions on mount
|
|
184
|
-
const regions = phAddress.getRegions();
|
|
185
|
-
|
|
186
|
-
const handleRegionChange = (regionPsgc) => {
|
|
187
|
-
setSelectedRegion(regionPsgc);
|
|
188
|
-
setSelectedProvince(null);
|
|
189
|
-
setSelectedCityMun(null);
|
|
190
|
-
setSelectedBarangay(null);
|
|
191
|
-
|
|
192
|
-
const provinces = phAddress.getProvincesByRegion(regionPsgc);
|
|
193
|
-
|
|
194
|
-
if (provinces === '-NO PROVINCE-') {
|
|
195
|
-
// NCR case - skip province dropdown
|
|
196
|
-
const cities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', regionPsgc);
|
|
197
|
-
setCityMunOptions(cities);
|
|
198
|
-
setShowProvince(false);
|
|
199
|
-
} else {
|
|
200
|
-
// Regular region - show province dropdown
|
|
201
|
-
setProvinceOptions(provinces);
|
|
202
|
-
setShowProvince(true);
|
|
203
|
-
setCityMunOptions([]);
|
|
204
|
-
}
|
|
205
|
-
setBarangayOptions([]);
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
const handleProvinceChange = (provincePsgc, regionPsgc) => {
|
|
209
|
-
setSelectedProvince(provincePsgc);
|
|
210
|
-
setSelectedCityMun(null);
|
|
211
|
-
setSelectedBarangay(null);
|
|
212
|
-
|
|
213
|
-
// Get cities and municipalities for selected province
|
|
214
|
-
const cities = phAddress.getCitiesAndMunsByProvince(provincePsgc, regionPsgc);
|
|
215
|
-
setCityMunOptions(cities);
|
|
216
|
-
setBarangayOptions([]);
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const handleCityMunChange = (cityMunPsgc) => {
|
|
220
|
-
setSelectedCityMun(cityMunPsgc);
|
|
221
|
-
setSelectedBarangay(null);
|
|
222
|
-
|
|
223
|
-
const barangays = phAddress.getBarangaysByCityOrMun(cityMunPsgc);
|
|
224
|
-
setBarangayOptions(barangays);
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
return (
|
|
228
|
-
<div>
|
|
229
|
-
<select onChange={(e) => handleRegionChange(e.target.value)}>
|
|
230
|
-
<option value="">Select Region</option>
|
|
231
|
-
{regions.map(r => (
|
|
232
|
-
<option key={r.psgc} value={r.psgc}>{r.name}</option>
|
|
233
|
-
))}
|
|
234
|
-
</select>
|
|
235
|
-
|
|
236
|
-
{showProvince && (
|
|
237
|
-
<select onChange={(e) => handleProvinceChange(e.target.value, selectedRegion)}>
|
|
238
|
-
<option value="">Select Province</option>
|
|
239
|
-
{provinceOptions.map(p => (
|
|
240
|
-
<option key={p.psgc} value={p.psgc}>{p.name}</option>
|
|
241
|
-
))}
|
|
242
|
-
</select>
|
|
243
|
-
)}
|
|
244
|
-
|
|
245
|
-
<select onChange={(e) => handleCityMunChange(e.target.value)}>
|
|
246
|
-
<option value="">Select City/Municipality</option>
|
|
247
|
-
{cityMunOptions.map(cm => (
|
|
248
|
-
<option key={cm.psgc} value={cm.psgc}>
|
|
249
|
-
{cm.name}{cm.cityClass ? ` (${cm.cityClass})` : ''}
|
|
250
|
-
</option>
|
|
251
|
-
))}
|
|
252
|
-
</select>
|
|
253
|
-
|
|
254
|
-
<select onChange={(e) => setSelectedBarangay(e.target.value)}>
|
|
255
|
-
<option value="">Select Barangay</option>
|
|
256
|
-
{barangayOptions.map(b => (
|
|
257
|
-
<option key={b.psgc} value={b.psgc}>{b.name}</option>
|
|
258
|
-
))}
|
|
259
|
-
</select>
|
|
260
|
-
</div>
|
|
261
|
-
);
|
|
120
|
+
// Auto-detect region
|
|
121
|
+
const region = phAddress.getRegionByProvince(provincePsgc);
|
|
122
|
+
if (region) {
|
|
123
|
+
const cities = phAddress.getCitiesAndMunsByProvince(provincePsgc);
|
|
124
|
+
}
|
|
262
125
|
}
|
|
263
126
|
```
|
|
264
127
|
|
|
265
128
|
## 📚 API Reference
|
|
266
129
|
|
|
267
|
-
This package provides **4 simple functions** for cascading dropdowns:
|
|
268
|
-
|
|
269
130
|
### `getRegions()`
|
|
270
131
|
|
|
271
132
|
Get all regions in the Philippines.
|
|
272
133
|
|
|
273
|
-
**Parameters:** None
|
|
274
|
-
|
|
275
134
|
**Returns:** Array of 18 regions (sorted A-Z)
|
|
276
135
|
|
|
277
|
-
|
|
278
|
-
|
|
136
|
+
```typescript
|
|
137
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
138
|
+
|
|
279
139
|
const regions = phAddress.getRegions();
|
|
280
|
-
//
|
|
140
|
+
// Type: Array<{ psgc: string; name: string; correspondenceCode: string; geographicLevel: string }>
|
|
281
141
|
```
|
|
282
142
|
|
|
283
143
|
---
|
|
284
144
|
|
|
285
145
|
### `getProvincesByRegion(regionPsgc)`
|
|
286
146
|
|
|
287
|
-
Get provinces in a selected region.
|
|
147
|
+
Get provinces in a selected region.
|
|
288
148
|
|
|
289
149
|
**Parameters:**
|
|
290
150
|
- `regionPsgc` (string, optional): Region PSGC code
|
|
291
151
|
|
|
292
|
-
**Returns:**
|
|
152
|
+
**Returns:**
|
|
293
153
|
- Array of provinces (sorted A-Z) when region is provided
|
|
294
|
-
- Array of all provinces + "-NO PROVINCE-" (83 items
|
|
154
|
+
- Array of all provinces + "-NO PROVINCE-" (83 items) when no parameter
|
|
295
155
|
- `"-NO PROVINCE-"` (string) when region is NCR
|
|
296
156
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
- NCR region returns `"-NO PROVINCE-"` string instead of array
|
|
157
|
+
```typescript
|
|
158
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
300
159
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
// Get all provinces (for users who don't know their region)
|
|
304
|
-
const allProvinces = phAddress.getProvincesByRegion();
|
|
305
|
-
// Returns: [{ psgc: '-NO PROVINCE-', name: '-NO PROVINCE-' }, { psgc: '1400100000', name: 'Abra' }, ...]
|
|
160
|
+
const provinces = phAddress.getProvincesByRegion('1400000000'); // CAR
|
|
161
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
306
162
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
// Returns: [{ psgc: '1400100000', name: 'Abra' }, ...]
|
|
163
|
+
const allProvinces = phAddress.getProvincesByRegion(); // All + "-NO PROVINCE-"
|
|
164
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
310
165
|
|
|
311
|
-
//
|
|
312
|
-
|
|
313
|
-
// Returns: "-NO PROVINCE-" (string)
|
|
166
|
+
const ncr = phAddress.getProvincesByRegion('1300000000'); // Returns "-NO PROVINCE-"
|
|
167
|
+
// Type: string
|
|
314
168
|
```
|
|
315
169
|
|
|
316
170
|
---
|
|
317
171
|
|
|
318
172
|
### `getCitiesAndMunsByProvince(provincePsgc, regionPsgc)`
|
|
319
173
|
|
|
320
|
-
Get all cities and municipalities geographically located in selected province. Includes HUCs
|
|
174
|
+
Get all cities and municipalities geographically located in selected province. Includes HUCs.
|
|
321
175
|
|
|
322
176
|
**Parameters:**
|
|
323
177
|
- `provincePsgc` (string): Province PSGC code or `"-NO PROVINCE-"`
|
|
@@ -325,21 +179,14 @@ Get all cities and municipalities geographically located in selected province. I
|
|
|
325
179
|
|
|
326
180
|
**Returns:** Array of cities and municipalities (sorted A-Z)
|
|
327
181
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
- Includes HUCs geographically located in the province (e.g., Baguio City appears in Benguet)
|
|
331
|
-
- Works for all city types: HUC, CC, ICC, and municipalities
|
|
332
|
-
- Returns empty array if no parameters provided
|
|
182
|
+
```typescript
|
|
183
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
333
184
|
|
|
334
|
-
**Example:**
|
|
335
|
-
```javascript
|
|
336
|
-
// Get cities/municipalities for a province
|
|
337
185
|
const cities = phAddress.getCitiesAndMunsByProvince('1401100000'); // Benguet
|
|
338
|
-
//
|
|
186
|
+
// Type: Array<{ psgc: string; name: string; cityClass?: string; ... }>
|
|
339
187
|
|
|
340
|
-
// Get cities/municipalities for NCR (when "-NO PROVINCE-" is selected)
|
|
341
188
|
const ncrCities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', '1300000000');
|
|
342
|
-
//
|
|
189
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
343
190
|
```
|
|
344
191
|
|
|
345
192
|
---
|
|
@@ -353,23 +200,11 @@ Get all barangays located in selected city or municipality.
|
|
|
353
200
|
|
|
354
201
|
**Returns:** Array of barangays (sorted A-Z)
|
|
355
202
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
- Handles different PSGC patterns automatically (7-digit and 6-digit fallback)
|
|
359
|
-
|
|
360
|
-
**Example:**
|
|
361
|
-
```javascript
|
|
362
|
-
// Get barangays for a regular city/municipality
|
|
363
|
-
const barangays = phAddress.getBarangaysByCityOrMun('1400101000'); // Bangued, Abra
|
|
364
|
-
// Returns: [Agtangao, Angad, Bañacao, ...]
|
|
365
|
-
|
|
366
|
-
// Get barangays for HUC (Manila)
|
|
367
|
-
const manilaBarangays = phAddress.getBarangaysByCityOrMun('1380600000'); // Manila City
|
|
368
|
-
// Returns: [Barangay 1, Barangay 10, ...] (655 barangays)
|
|
203
|
+
```typescript
|
|
204
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
369
205
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
// Returns: [A. Bonifacio-Caguioa-Rimando, Abanao-Zandueta-Kayong-Chugum-Otek, ...] (129 barangays)
|
|
206
|
+
const barangays = phAddress.getBarangaysByCityOrMun('1430300000'); // Baguio City
|
|
207
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
373
208
|
```
|
|
374
209
|
|
|
375
210
|
---
|
|
@@ -383,180 +218,69 @@ Get the region for a given province. Useful for auto-selecting region when user
|
|
|
383
218
|
|
|
384
219
|
**Returns:** Region object or null if not found
|
|
385
220
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
- Returns `null` if province PSGC is invalid or if `"-NO PROVINCE-"` is provided
|
|
389
|
-
- Perfect for province-first flow to auto-select region in UI
|
|
221
|
+
```typescript
|
|
222
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
390
223
|
|
|
391
|
-
**Example:**
|
|
392
|
-
```javascript
|
|
393
|
-
// Get region for Benguet province
|
|
394
224
|
const region = phAddress.getRegionByProvince('1401100000'); // Benguet
|
|
395
225
|
// Returns: { psgc: '1400000000', name: 'Cordillera Administrative Region (CAR)', ... }
|
|
396
|
-
|
|
397
|
-
// Auto-select region when user selects province
|
|
398
|
-
function onProvinceSelected(provincePsgc) {
|
|
399
|
-
if (provincePsgc === '-NO PROVINCE-') {
|
|
400
|
-
// NCR case
|
|
401
|
-
const regionPsgc = '1300000000';
|
|
402
|
-
} else {
|
|
403
|
-
// Auto-detect region
|
|
404
|
-
const region = phAddress.getRegionByProvince(provincePsgc);
|
|
405
|
-
if (region) {
|
|
406
|
-
// Auto-select region in UI
|
|
407
|
-
// region.psgc = '1400000000'
|
|
408
|
-
// region.name = 'Cordillera Administrative Region (CAR)'
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
226
|
+
// Type: { psgc: string; name: string; ... } | null
|
|
412
227
|
```
|
|
413
228
|
|
|
229
|
+
## ⚠️ Important Notes
|
|
230
|
+
|
|
231
|
+
- **NCR Handling:** When region is NCR, `getProvincesByRegion()` returns `"-NO PROVINCE-"` (string) instead of an array
|
|
232
|
+
- **"-NO PROVINCE-" Option:** Appears first in sorted lists when getting all provinces
|
|
233
|
+
- **HUCs:** Highly Urbanized Cities (like Baguio, Manila) are included in their geographic province
|
|
234
|
+
- **All Lists:** Returned arrays are sorted A-Z by name
|
|
235
|
+
- **PSGC Format:** Uses 10-digit PSGC codes (PSGC Revision 1)
|
|
236
|
+
|
|
414
237
|
## 📐 Data Structure
|
|
415
238
|
|
|
416
239
|
Each address object contains:
|
|
417
240
|
|
|
418
|
-
```
|
|
419
|
-
{
|
|
420
|
-
psgc:
|
|
421
|
-
name:
|
|
422
|
-
correspondenceCode:
|
|
423
|
-
geographicLevel: '
|
|
424
|
-
|
|
425
|
-
cityClass: null // City class (HUC, etc.) for cities
|
|
241
|
+
```typescript
|
|
242
|
+
interface Address {
|
|
243
|
+
psgc: string; // 10-digit PSGC code
|
|
244
|
+
name: string; // Name
|
|
245
|
+
correspondenceCode: string; // Correspondence code
|
|
246
|
+
geographicLevel: 'Reg' | 'Prov' | 'City' | 'Mun' | 'Bgy';
|
|
247
|
+
cityClass?: string | null; // City class (HUC, CC, ICC) for cities
|
|
426
248
|
}
|
|
427
|
-
```
|
|
428
249
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
The 10-digit PSGC code follows **PSGC Revision 1** structure:
|
|
250
|
+
// Example:
|
|
251
|
+
const address: Address = {
|
|
252
|
+
psgc: '1380100001',
|
|
253
|
+
name: 'Barangay 1',
|
|
254
|
+
correspondenceCode: '137501001',
|
|
255
|
+
geographicLevel: 'Bgy',
|
|
256
|
+
cityClass: null
|
|
257
|
+
};
|
|
258
|
+
```
|
|
440
259
|
|
|
441
|
-
|
|
442
|
-
|-----------|--------|----------|---------|
|
|
443
|
-
| **Region** | 1-2 | `XX00000000` | `14` = CAR |
|
|
444
|
-
| **Province/HUC** | 3-5 | `XXXXX00000` | `011` = Benguet |
|
|
445
|
-
| **City/Municipality** | 6-7 | `XXXXXXX000` | `01` = Bangued |
|
|
446
|
-
| **Barangay** | 8-10 | `XXXXXXXXXX` | `001` = Agtangao |
|
|
260
|
+
## 🔢 PSGC Code Structure
|
|
447
261
|
|
|
448
|
-
|
|
262
|
+
10-digit PSGC code format: `XX` (Region) + `XXX` (Province) + `XX` (City/Mun) + `XXX` (Barangay)
|
|
449
263
|
|
|
450
264
|
**Example:** `1400101001`
|
|
451
|
-
- Digits 1-2: `14` =
|
|
265
|
+
- Digits 1-2: `14` = CAR
|
|
452
266
|
- Digits 3-5: `001` = Abra Province
|
|
453
267
|
- Digits 6-7: `01` = Bangued Municipality
|
|
454
268
|
- Digits 8-10: `001` = Agtangao Barangay
|
|
455
269
|
|
|
456
|
-
## 🙏 Credits
|
|
457
|
-
|
|
458
|
-
This package uses data from the **Philippine Standard Geographic Code (PSGC) database (3Q 2025)**.
|
|
459
|
-
|
|
460
|
-
Special thanks to the [anehan.online](https://anehan.online) Tech Team for making this data available! Mabuhay! 🇵🇭
|
|
461
|
-
|
|
462
|
-
## 🔄 Two Flexible Usage Flows
|
|
463
|
-
|
|
464
|
-
This package supports **two flexible flows** for address selection:
|
|
465
|
-
|
|
466
|
-
### Flow 1: Region First (Standard)
|
|
467
|
-
**Region → Province → City/Municipality → Barangay**
|
|
468
|
-
|
|
469
|
-
```javascript
|
|
470
|
-
// 1. Load regions
|
|
471
|
-
const regions = phAddress.getRegions();
|
|
472
|
-
|
|
473
|
-
// 2. User selects region → Get provinces
|
|
474
|
-
const provinces = phAddress.getProvincesByRegion(regionPsgc);
|
|
475
|
-
// For NCR: Returns "-NO PROVINCE-" (string)
|
|
476
|
-
// For other regions: Returns array of provinces
|
|
477
|
-
|
|
478
|
-
// 3. User selects province → Get cities/municipalities
|
|
479
|
-
if (provincePsgc === '-NO PROVINCE-') {
|
|
480
|
-
// NCR case
|
|
481
|
-
const cities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', regionPsgc);
|
|
482
|
-
} else {
|
|
483
|
-
// Regular province
|
|
484
|
-
const cities = phAddress.getCitiesAndMunsByProvince(provincePsgc);
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
// 4. User selects city/municipality → Get barangays
|
|
488
|
-
const barangays = phAddress.getBarangaysByCityOrMun(cityMunPsgc);
|
|
489
|
-
```
|
|
490
|
-
|
|
491
|
-
### Flow 2: Province First (Alternative)
|
|
492
|
-
**Province → City/Municipality → Barangay** (when user doesn't know region)
|
|
493
|
-
|
|
494
|
-
```javascript
|
|
495
|
-
// 1. Load all provinces (includes "-NO PROVINCE-" option)
|
|
496
|
-
const allProvinces = phAddress.getProvincesByRegion();
|
|
497
|
-
// "-NO PROVINCE-" appears first in the list
|
|
498
|
-
|
|
499
|
-
// 2. User selects province → Auto-select region
|
|
500
|
-
let selectedRegion = null;
|
|
501
|
-
if (provincePsgc === '-NO PROVINCE-') {
|
|
502
|
-
// User selected "-NO PROVINCE-" (NCR)
|
|
503
|
-
selectedRegion = '1300000000'; // Auto-select NCR
|
|
504
|
-
const cities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', selectedRegion);
|
|
505
|
-
} else {
|
|
506
|
-
// User selected a regular province → Auto-detect region
|
|
507
|
-
const region = phAddress.getRegionByProvince(provincePsgc);
|
|
508
|
-
selectedRegion = region ? region.psgc : null;
|
|
509
|
-
|
|
510
|
-
// Get cities/municipalities for the selected province
|
|
511
|
-
const cities = phAddress.getCitiesAndMunsByProvince(provincePsgc);
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
// 3. User selects city/municipality → Get barangays
|
|
515
|
-
const barangays = phAddress.getBarangaysByCityOrMun(cityMunPsgc);
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
**Auto-Select Region Example:**
|
|
519
|
-
```javascript
|
|
520
|
-
// When user selects a province, automatically determine the region
|
|
521
|
-
function onProvinceSelected(provincePsgc) {
|
|
522
|
-
if (provincePsgc === '-NO PROVINCE-') {
|
|
523
|
-
// NCR case - region is automatically NCR
|
|
524
|
-
const regionPsgc = '1300000000';
|
|
525
|
-
const cities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', regionPsgc);
|
|
526
|
-
// Update UI: Set region to NCR, show cities
|
|
527
|
-
} else {
|
|
528
|
-
// Regular province - auto-detect region
|
|
529
|
-
const region = phAddress.getRegionByProvince(provincePsgc);
|
|
530
|
-
if (region) {
|
|
531
|
-
// Auto-select the region in the UI
|
|
532
|
-
// region.psgc = region PSGC code
|
|
533
|
-
// region.name = region name (e.g., "Cordillera Administrative Region (CAR)")
|
|
534
|
-
|
|
535
|
-
const cities = phAddress.getCitiesAndMunsByProvince(provincePsgc);
|
|
536
|
-
// Update UI: Set region to detected region, show cities
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
```
|
|
541
|
-
|
|
542
270
|
## 💼 Use Cases
|
|
543
271
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
-
|
|
547
|
-
-
|
|
548
|
-
-
|
|
549
|
-
-
|
|
550
|
-
- **Healthcare** - Patient registration, medical records, service delivery
|
|
551
|
-
- **Logistics** - Shipping management, route optimization, delivery tracking
|
|
552
|
-
- **Mobile Apps** - Address selection, location-based features
|
|
553
|
-
- **Data Analysis** - Geographic reporting, user distribution, market research
|
|
272
|
+
- E-commerce & Delivery - Address forms, shipping validation
|
|
273
|
+
- Government Services - Public forms, voter registration
|
|
274
|
+
- Financial Services - KYC forms, address verification
|
|
275
|
+
- Real Estate - Property listings, location search
|
|
276
|
+
- Healthcare - Patient registration, medical records
|
|
277
|
+
- Logistics - Shipping management, delivery tracking
|
|
554
278
|
|
|
555
|
-
|
|
279
|
+
## 🙏 Credits
|
|
556
280
|
|
|
557
|
-
|
|
281
|
+
Data from **Philippine Standard Geographic Code (PSGC) database (3Q 2025)**.
|
|
558
282
|
|
|
559
|
-
|
|
283
|
+
Special thanks to the [anehan.online](https://anehan.online) Tech Team! 🇵🇭
|
|
560
284
|
|
|
561
285
|
## 📄 License
|
|
562
286
|
|