latest-ph-address-thanks-to-anehan 1.0.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 +569 -0
- package/data/addresses.json +350154 -0
- package/data/by-level.json +350036 -0
- package/data/by-psgc.json +350154 -0
- package/data/hierarchy.json +3458 -0
- package/index.js +178 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
# latest-ph-address
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/latest-ph-address-thanks-to-anehan)
|
|
4
|
+
[](https://opensource.org/licenses/ISC)
|
|
5
|
+
|
|
6
|
+
The latest Philippine addresses database with complete coverage of all Regions, Provinces, Cities, Municipalities, and Barangays. Perfect for building address forms, dropdowns, and location-based applications.
|
|
7
|
+
|
|
8
|
+
**Features:**
|
|
9
|
+
- ✅ **43,769+ addresses** - Complete coverage of the Philippines
|
|
10
|
+
- ✅ **Official PSGC codes** - Philippine Standard Geographic Code support
|
|
11
|
+
- ✅ **Cascading dropdowns** - Built-in helpers for Region → Province → City/Municipality → Barangay
|
|
12
|
+
- ✅ **NCR support** - Automatic handling of National Capital Region (no provinces)
|
|
13
|
+
- ✅ **HUC support** - Highly Urbanized Cities with geographic province mapping
|
|
14
|
+
- ✅ **Two flexible flows** - Start with Region or Province
|
|
15
|
+
- ✅ **Zero dependencies** - Lightweight and fast
|
|
16
|
+
- ✅ **Latest data** - 3Q 2025 PSGC data
|
|
17
|
+
|
|
18
|
+
All thanks to the [anehan.online](https://anehan.online) Tech Team! 🇵🇭
|
|
19
|
+
|
|
20
|
+
## 📦 Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install latest-ph-address-thanks-to-anehan
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 📊 Data Coverage
|
|
27
|
+
|
|
28
|
+
- **18 Regions**
|
|
29
|
+
- **82 Provinces**
|
|
30
|
+
- **149 Cities** (including HUC, CC, ICC)
|
|
31
|
+
- **1,493 Municipalities**
|
|
32
|
+
- **42,011 Barangays**
|
|
33
|
+
- **Total: 43,769 addresses**
|
|
34
|
+
|
|
35
|
+
## 🚀 Quick Start
|
|
36
|
+
|
|
37
|
+
### Basic Usage
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
const phAddress = require('latest-ph-address-thanks-to-anehan');
|
|
41
|
+
|
|
42
|
+
// Get all regions
|
|
43
|
+
const regions = phAddress.getRegions();
|
|
44
|
+
// Returns: Array of 18 regions (sorted A-Z)
|
|
45
|
+
|
|
46
|
+
// Get provinces (all provinces + "-NO PROVINCE-" option)
|
|
47
|
+
const provinces = phAddress.getProvincesByRegion();
|
|
48
|
+
// Returns: Array of 82 provinces + "-NO PROVINCE-" (83 items, sorted A-Z)
|
|
49
|
+
// "-NO PROVINCE-" appears first in the list
|
|
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)
|
|
54
|
+
|
|
55
|
+
// Get provinces for NCR
|
|
56
|
+
const ncrProvinces = phAddress.getProvincesByRegion('1300000000'); // NCR
|
|
57
|
+
// Returns: "-NO PROVINCE-" (string)
|
|
58
|
+
|
|
59
|
+
// Get cities and municipalities in a province (includes HUCs geographically located)
|
|
60
|
+
const cities = phAddress.getCitiesAndMunsByProvince('1401100000'); // Benguet
|
|
61
|
+
// Returns: Array of cities and municipalities (sorted A-Z)
|
|
62
|
+
// Includes: City of Baguio (HUC) + all municipalities
|
|
63
|
+
|
|
64
|
+
// Get cities and municipalities for NCR (when "-NO PROVINCE-" is selected)
|
|
65
|
+
const ncrCities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', '1300000000');
|
|
66
|
+
// Returns: Array of NCR cities and municipalities (sorted A-Z)
|
|
67
|
+
|
|
68
|
+
// Get barangays in a city/municipality
|
|
69
|
+
const barangays = phAddress.getBarangaysByCityOrMun('1430300000'); // Baguio City
|
|
70
|
+
// Returns: Array of barangays (sorted A-Z)
|
|
71
|
+
// Works for all cities including HUCs (Manila, Baguio, etc.)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Complete Dropdown Flow
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
// Step 1: Load regions
|
|
78
|
+
const regions = phAddress.getRegions();
|
|
79
|
+
|
|
80
|
+
// Step 2: User selects region → Get provinces
|
|
81
|
+
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
|
+
|
|
92
|
+
// Step 4: User selects city/municipality → Get barangays
|
|
93
|
+
const barangays = phAddress.getBarangaysByCityOrMun(cityMunPsgc);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## 📋 Main Use Case: Cascading Dropdowns
|
|
97
|
+
|
|
98
|
+
This package is designed for building cascading dropdowns with two flexible flows:
|
|
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
|
|
136
|
+
const cities = phAddress.getCitiesAndMunsByProvince(provincePsgc);
|
|
137
|
+
// Populate city/municipality dropdown
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Step 4: When user selects a city/municipality
|
|
141
|
+
function onCityMunSelected(cityMunPsgc) {
|
|
142
|
+
const barangays = phAddress.getBarangaysByCityOrMun(cityMunPsgc);
|
|
143
|
+
// Populate barangay dropdown
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Alternative Flow: Province First (No Region)
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
// Step 1: Load all provinces (includes "-NO PROVINCE-" option)
|
|
151
|
+
const provinces = phAddress.getProvincesByRegion();
|
|
152
|
+
// "-NO PROVINCE-" appears first in the list
|
|
153
|
+
|
|
154
|
+
// Step 2: When user selects "-NO PROVINCE-"
|
|
155
|
+
if (provincePsgc === '-NO PROVINCE-') {
|
|
156
|
+
const cities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', '1300000000');
|
|
157
|
+
// Show NCR cities/municipalities
|
|
158
|
+
} else {
|
|
159
|
+
// User selected a regular province
|
|
160
|
+
const cities = phAddress.getCitiesAndMunsByProvince(provincePsgc);
|
|
161
|
+
// Show cities/municipalities for that province
|
|
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
|
+
);
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## 📚 API Reference
|
|
266
|
+
|
|
267
|
+
This package provides **4 simple functions** for cascading dropdowns:
|
|
268
|
+
|
|
269
|
+
### `getRegions()`
|
|
270
|
+
|
|
271
|
+
Get all regions in the Philippines.
|
|
272
|
+
|
|
273
|
+
**Parameters:** None
|
|
274
|
+
|
|
275
|
+
**Returns:** Array of 18 regions (sorted A-Z)
|
|
276
|
+
|
|
277
|
+
**Example:**
|
|
278
|
+
```javascript
|
|
279
|
+
const regions = phAddress.getRegions();
|
|
280
|
+
// Returns: [{ psgc: '1300000000', name: 'National Capital Region (NCR)', ... }, ...]
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
### `getProvincesByRegion(regionPsgc)`
|
|
286
|
+
|
|
287
|
+
Get provinces in a selected region. If no region is provided, returns all provinces plus "-NO PROVINCE-" option.
|
|
288
|
+
|
|
289
|
+
**Parameters:**
|
|
290
|
+
- `regionPsgc` (string, optional): Region PSGC code
|
|
291
|
+
|
|
292
|
+
**Returns:**
|
|
293
|
+
- Array of provinces (sorted A-Z) when region is provided
|
|
294
|
+
- Array of all provinces + "-NO PROVINCE-" (83 items, sorted A-Z) when no parameter
|
|
295
|
+
- `"-NO PROVINCE-"` (string) when region is NCR
|
|
296
|
+
|
|
297
|
+
**Special Notes:**
|
|
298
|
+
- `-NO PROVINCE-` appears first in the list (sorted A-Z)
|
|
299
|
+
- NCR region returns `"-NO PROVINCE-"` string instead of array
|
|
300
|
+
|
|
301
|
+
**Example:**
|
|
302
|
+
```javascript
|
|
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' }, ...]
|
|
306
|
+
|
|
307
|
+
// Get provinces for a specific region
|
|
308
|
+
const carProvinces = phAddress.getProvincesByRegion('1400000000'); // CAR
|
|
309
|
+
// Returns: [{ psgc: '1400100000', name: 'Abra' }, ...]
|
|
310
|
+
|
|
311
|
+
// Get provinces for NCR
|
|
312
|
+
const ncrProvinces = phAddress.getProvincesByRegion('1300000000'); // NCR
|
|
313
|
+
// Returns: "-NO PROVINCE-" (string)
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
### `getCitiesAndMunsByProvince(provincePsgc, regionPsgc)`
|
|
319
|
+
|
|
320
|
+
Get all cities and municipalities geographically located in selected province. Includes HUCs that are geographically located in the province.
|
|
321
|
+
|
|
322
|
+
**Parameters:**
|
|
323
|
+
- `provincePsgc` (string): Province PSGC code or `"-NO PROVINCE-"`
|
|
324
|
+
- `regionPsgc` (string, optional): Region PSGC code (required when `provincePsgc` is `"-NO PROVINCE-"`)
|
|
325
|
+
|
|
326
|
+
**Returns:** Array of cities and municipalities (sorted A-Z)
|
|
327
|
+
|
|
328
|
+
**Special Notes:**
|
|
329
|
+
- When `provincePsgc` is `"-NO PROVINCE-"`, returns cities/municipalities for NCR Region
|
|
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
|
|
333
|
+
|
|
334
|
+
**Example:**
|
|
335
|
+
```javascript
|
|
336
|
+
// Get cities/municipalities for a province
|
|
337
|
+
const cities = phAddress.getCitiesAndMunsByProvince('1401100000'); // Benguet
|
|
338
|
+
// Returns: [City of Baguio (HUC), Atok, Bakun, Bokod, ...]
|
|
339
|
+
|
|
340
|
+
// Get cities/municipalities for NCR (when "-NO PROVINCE-" is selected)
|
|
341
|
+
const ncrCities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', '1300000000');
|
|
342
|
+
// Returns: [City of Caloocan, City of Las Piñas, City of Makati, ...]
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
### `getBarangaysByCityOrMun(cityMunPsgc)`
|
|
348
|
+
|
|
349
|
+
Get all barangays located in selected city or municipality.
|
|
350
|
+
|
|
351
|
+
**Parameters:**
|
|
352
|
+
- `cityMunPsgc` (string): City/Municipality PSGC code
|
|
353
|
+
|
|
354
|
+
**Returns:** Array of barangays (sorted A-Z)
|
|
355
|
+
|
|
356
|
+
**Special Notes:**
|
|
357
|
+
- Works for all cities and municipalities including HUCs (Manila, Baguio, etc.)
|
|
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)
|
|
369
|
+
|
|
370
|
+
// Get barangays for HUC (Baguio)
|
|
371
|
+
const baguioBarangays = phAddress.getBarangaysByCityOrMun('1430300000'); // Baguio City
|
|
372
|
+
// Returns: [A. Bonifacio-Caguioa-Rimando, Abanao-Zandueta-Kayong-Chugum-Otek, ...] (129 barangays)
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
### `getRegionByProvince(provincePsgc)`
|
|
378
|
+
|
|
379
|
+
Get the region for a given province. Useful for auto-selecting region when user chooses province first.
|
|
380
|
+
|
|
381
|
+
**Parameters:**
|
|
382
|
+
- `provincePsgc` (string): Province PSGC code
|
|
383
|
+
|
|
384
|
+
**Returns:** Region object or null if not found
|
|
385
|
+
|
|
386
|
+
**Special Notes:**
|
|
387
|
+
- Automatically determines the region based on province PSGC
|
|
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
|
|
390
|
+
|
|
391
|
+
**Example:**
|
|
392
|
+
```javascript
|
|
393
|
+
// Get region for Benguet province
|
|
394
|
+
const region = phAddress.getRegionByProvince('1401100000'); // Benguet
|
|
395
|
+
// 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
|
+
}
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
## 📐 Data Structure
|
|
415
|
+
|
|
416
|
+
Each address object contains:
|
|
417
|
+
|
|
418
|
+
```javascript
|
|
419
|
+
{
|
|
420
|
+
psgc: '1380100001', // 10-digit PSGC code
|
|
421
|
+
name: 'Barangay 1', // Name
|
|
422
|
+
correspondenceCode: '137501001', // Correspondence code
|
|
423
|
+
geographicLevel: 'Bgy', // Reg, Prov, City, Mun, or Bgy
|
|
424
|
+
oldNames: null, // Old names (if any)
|
|
425
|
+
cityClass: null // City class (HUC, etc.) for cities
|
|
426
|
+
}
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
## 🗺️ Geographic Levels
|
|
430
|
+
|
|
431
|
+
- **Reg**: Region
|
|
432
|
+
- **Prov**: Province
|
|
433
|
+
- **City**: City
|
|
434
|
+
- **Mun**: Municipality
|
|
435
|
+
- **Bgy**: Barangay
|
|
436
|
+
|
|
437
|
+
## 🔢 PSGC Code Structure (Revision 1)
|
|
438
|
+
|
|
439
|
+
The 10-digit PSGC code follows **PSGC Revision 1** structure:
|
|
440
|
+
|
|
441
|
+
| Component | Digits | Structure | Example |
|
|
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 |
|
|
447
|
+
|
|
448
|
+
**Full Structure:** `XX` (Region) + `XXX` (Province) + `XX` (City/Mun) + `XXX` (Barangay)
|
|
449
|
+
|
|
450
|
+
**Example:** `1400101001`
|
|
451
|
+
- Digits 1-2: `14` = Cordillera Administrative Region (CAR)
|
|
452
|
+
- Digits 3-5: `001` = Abra Province
|
|
453
|
+
- Digits 6-7: `01` = Bangued Municipality
|
|
454
|
+
- Digits 8-10: `001` = Agtangao Barangay
|
|
455
|
+
|
|
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
|
+
## 💼 Use Cases
|
|
543
|
+
|
|
544
|
+
This package is perfect for:
|
|
545
|
+
|
|
546
|
+
- **E-commerce & Delivery** - Address forms, shipping validation, delivery services
|
|
547
|
+
- **Government Services** - Public forms, voter registration, census data
|
|
548
|
+
- **Financial Services** - KYC forms, bank applications, address verification
|
|
549
|
+
- **Real Estate** - Property listings, location search, address display
|
|
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
|
|
554
|
+
|
|
555
|
+
See [USE_CASES.md](./USE_CASES.md) for detailed use cases and integration examples.
|
|
556
|
+
|
|
557
|
+
## 🤝 Contributing
|
|
558
|
+
|
|
559
|
+
Contributions, issues, and feature requests are welcome! Feel free to check the [issues page](https://github.com/aldrinPA/latest-ph-address/issues).
|
|
560
|
+
|
|
561
|
+
## 📄 License
|
|
562
|
+
|
|
563
|
+
ISC © [Anehan Tech Team by Aldrin](https://github.com/aldrinPA)
|
|
564
|
+
|
|
565
|
+
## 🔗 Links
|
|
566
|
+
|
|
567
|
+
- **Repository:** [https://github.com/aldrinPA/latest-ph-address](https://github.com/aldrinPA/latest-ph-address)
|
|
568
|
+
- **NPM Package:** [https://www.npmjs.com/package/latest-ph-address-thanks-to-anehan](https://www.npmjs.com/package/latest-ph-address-thanks-to-anehan)
|
|
569
|
+
- **Thanks to:** [anehan.online](https://anehan.online)
|