latest-ph-address-thanks-to-anehan 1.0.1 → 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/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,166 @@ 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
|
+
The package exports an object with functions. You can name the imported object anything you want:
|
|
36
29
|
|
|
37
|
-
|
|
30
|
+
```typescript
|
|
31
|
+
// ES6 Import (Recommended)
|
|
32
|
+
// 'phAddress' is just a variable name - you can use any name you prefer
|
|
33
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
34
|
+
// OR: import address from 'latest-ph-address-thanks-to-anehan';
|
|
35
|
+
// OR: import philippines from 'latest-ph-address-thanks-to-anehan';
|
|
36
|
+
|
|
37
|
+
// ES6 Named Imports (Import specific functions)
|
|
38
|
+
import { getRegions, getProvincesByRegion, getBarangaysByCityOrMun } from 'latest-ph-address-thanks-to-anehan';
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
// CommonJS (Node.js)
|
|
40
41
|
const phAddress = require('latest-ph-address-thanks-to-anehan');
|
|
42
|
+
// OR: const address = require('latest-ph-address-thanks-to-anehan');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Note:** `phAddress` stands for "Philippine Address" - it's just a suggested variable name. You can use any name you prefer!
|
|
46
|
+
|
|
47
|
+
### Basic Usage
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
// Using default import (object with all functions)
|
|
51
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
41
52
|
|
|
42
53
|
// Get all regions
|
|
43
54
|
const regions = phAddress.getRegions();
|
|
44
55
|
// Returns: Array of 18 regions (sorted A-Z)
|
|
56
|
+
// Type: Array<{ psgc: string; name: string; correspondenceCode: string; geographicLevel: string }>
|
|
45
57
|
|
|
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)
|
|
58
|
+
// Get provinces for a region
|
|
59
|
+
const provinces = phAddress.getProvincesByRegion('1400000000'); // CAR
|
|
60
|
+
// Returns: Array of provinces (sorted A-Z)
|
|
61
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
54
62
|
|
|
55
63
|
// Get provinces for NCR
|
|
56
|
-
const ncrProvinces = phAddress.getProvincesByRegion('1300000000');
|
|
64
|
+
const ncrProvinces = phAddress.getProvincesByRegion('1300000000');
|
|
57
65
|
// Returns: "-NO PROVINCE-" (string)
|
|
66
|
+
// Type: string
|
|
58
67
|
|
|
59
|
-
// Get
|
|
68
|
+
// Get all provinces (includes "-NO PROVINCE-" option)
|
|
69
|
+
const allProvinces = phAddress.getProvincesByRegion();
|
|
70
|
+
// Returns: Array of 83 items ("-NO PROVINCE-" appears first)
|
|
71
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
72
|
+
|
|
73
|
+
// Get cities and municipalities for a province
|
|
60
74
|
const cities = phAddress.getCitiesAndMunsByProvince('1401100000'); // Benguet
|
|
61
|
-
// Returns: Array
|
|
62
|
-
//
|
|
75
|
+
// Returns: Array including City of Baguio (HUC) + all municipalities
|
|
76
|
+
// Type: Array<{ psgc: string; name: string; cityClass?: string; ... }>
|
|
63
77
|
|
|
64
|
-
// Get cities
|
|
78
|
+
// Get cities for NCR
|
|
65
79
|
const ncrCities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', '1300000000');
|
|
66
|
-
// Returns: Array of NCR cities and municipalities
|
|
80
|
+
// Returns: Array of NCR cities and municipalities
|
|
81
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
67
82
|
|
|
68
|
-
// Get barangays
|
|
83
|
+
// Get barangays
|
|
69
84
|
const barangays = phAddress.getBarangaysByCityOrMun('1430300000'); // Baguio City
|
|
70
85
|
// Returns: Array of barangays (sorted A-Z)
|
|
71
|
-
//
|
|
86
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
72
87
|
```
|
|
73
88
|
|
|
74
|
-
|
|
89
|
+
## 📋 Cascading Dropdown Example
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
75
93
|
|
|
76
|
-
```javascript
|
|
77
94
|
// Step 1: Load regions
|
|
78
95
|
const regions = phAddress.getRegions();
|
|
79
96
|
|
|
80
97
|
// Step 2: User selects region → Get provinces
|
|
98
|
+
const regionPsgc: string = '1400000000'; // Example: CAR
|
|
81
99
|
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
100
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
101
|
+
if (provinces === '-NO PROVINCE-') {
|
|
102
|
+
// NCR case: Skip province dropdown
|
|
103
|
+
const cities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', regionPsgc);
|
|
104
|
+
} else {
|
|
105
|
+
// Regular region: Show provinces
|
|
106
|
+
// Step 3: User selects province → Get cities
|
|
107
|
+
const provincePsgc: string = '1401100000'; // Example: Benguet
|
|
136
108
|
const cities = phAddress.getCitiesAndMunsByProvince(provincePsgc);
|
|
137
|
-
// Populate city/municipality dropdown
|
|
138
109
|
}
|
|
139
110
|
|
|
140
|
-
// Step 4:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
// Populate barangay dropdown
|
|
144
|
-
}
|
|
111
|
+
// Step 4: User selects city → Get barangays
|
|
112
|
+
const cityMunPsgc: string = '1430300000'; // Example: Baguio City
|
|
113
|
+
const barangays = phAddress.getBarangaysByCityOrMun(cityMunPsgc);
|
|
145
114
|
```
|
|
146
115
|
|
|
147
|
-
###
|
|
116
|
+
### Province-First Flow (Auto-detect Region)
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
148
120
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
// "-NO PROVINCE-" appears first in the list
|
|
121
|
+
// User selects province first
|
|
122
|
+
const provinces = phAddress.getProvincesByRegion(); // All provinces + "-NO PROVINCE-"
|
|
123
|
+
const provincePsgc: string = '1401100000'; // Example: Benguet
|
|
153
124
|
|
|
154
|
-
// Step 2: When user selects "-NO PROVINCE-"
|
|
155
125
|
if (provincePsgc === '-NO PROVINCE-') {
|
|
126
|
+
// NCR case
|
|
156
127
|
const cities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', '1300000000');
|
|
157
|
-
// Show NCR cities/municipalities
|
|
158
128
|
} 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
|
-
);
|
|
129
|
+
// Auto-detect region
|
|
130
|
+
const region = phAddress.getRegionByProvince(provincePsgc);
|
|
131
|
+
if (region) {
|
|
132
|
+
const cities = phAddress.getCitiesAndMunsByProvince(provincePsgc);
|
|
133
|
+
}
|
|
262
134
|
}
|
|
263
135
|
```
|
|
264
136
|
|
|
265
137
|
## 📚 API Reference
|
|
266
138
|
|
|
267
|
-
This package provides **4 simple functions** for cascading dropdowns:
|
|
268
|
-
|
|
269
139
|
### `getRegions()`
|
|
270
140
|
|
|
271
141
|
Get all regions in the Philippines.
|
|
272
142
|
|
|
273
|
-
**Parameters:** None
|
|
274
|
-
|
|
275
143
|
**Returns:** Array of 18 regions (sorted A-Z)
|
|
276
144
|
|
|
277
|
-
|
|
278
|
-
|
|
145
|
+
```typescript
|
|
146
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
147
|
+
|
|
279
148
|
const regions = phAddress.getRegions();
|
|
280
|
-
//
|
|
149
|
+
// Type: Array<{ psgc: string; name: string; correspondenceCode: string; geographicLevel: string }>
|
|
281
150
|
```
|
|
282
151
|
|
|
283
152
|
---
|
|
284
153
|
|
|
285
154
|
### `getProvincesByRegion(regionPsgc)`
|
|
286
155
|
|
|
287
|
-
Get provinces in a selected region.
|
|
156
|
+
Get provinces in a selected region.
|
|
288
157
|
|
|
289
158
|
**Parameters:**
|
|
290
159
|
- `regionPsgc` (string, optional): Region PSGC code
|
|
291
160
|
|
|
292
|
-
**Returns:**
|
|
161
|
+
**Returns:**
|
|
293
162
|
- Array of provinces (sorted A-Z) when region is provided
|
|
294
|
-
- Array of all provinces + "-NO PROVINCE-" (83 items
|
|
163
|
+
- Array of all provinces + "-NO PROVINCE-" (83 items) when no parameter
|
|
295
164
|
- `"-NO PROVINCE-"` (string) when region is NCR
|
|
296
165
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
- NCR region returns `"-NO PROVINCE-"` string instead of array
|
|
166
|
+
```typescript
|
|
167
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
300
168
|
|
|
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' }, ...]
|
|
169
|
+
const provinces = phAddress.getProvincesByRegion('1400000000'); // CAR
|
|
170
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
306
171
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
// Returns: [{ psgc: '1400100000', name: 'Abra' }, ...]
|
|
172
|
+
const allProvinces = phAddress.getProvincesByRegion(); // All + "-NO PROVINCE-"
|
|
173
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
310
174
|
|
|
311
|
-
//
|
|
312
|
-
|
|
313
|
-
// Returns: "-NO PROVINCE-" (string)
|
|
175
|
+
const ncr = phAddress.getProvincesByRegion('1300000000'); // Returns "-NO PROVINCE-"
|
|
176
|
+
// Type: string
|
|
314
177
|
```
|
|
315
178
|
|
|
316
179
|
---
|
|
317
180
|
|
|
318
181
|
### `getCitiesAndMunsByProvince(provincePsgc, regionPsgc)`
|
|
319
182
|
|
|
320
|
-
Get all cities and municipalities geographically located in selected province. Includes HUCs
|
|
183
|
+
Get all cities and municipalities geographically located in selected province. Includes HUCs.
|
|
321
184
|
|
|
322
185
|
**Parameters:**
|
|
323
186
|
- `provincePsgc` (string): Province PSGC code or `"-NO PROVINCE-"`
|
|
@@ -325,21 +188,14 @@ Get all cities and municipalities geographically located in selected province. I
|
|
|
325
188
|
|
|
326
189
|
**Returns:** Array of cities and municipalities (sorted A-Z)
|
|
327
190
|
|
|
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
|
|
191
|
+
```typescript
|
|
192
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
333
193
|
|
|
334
|
-
**Example:**
|
|
335
|
-
```javascript
|
|
336
|
-
// Get cities/municipalities for a province
|
|
337
194
|
const cities = phAddress.getCitiesAndMunsByProvince('1401100000'); // Benguet
|
|
338
|
-
//
|
|
195
|
+
// Type: Array<{ psgc: string; name: string; cityClass?: string; ... }>
|
|
339
196
|
|
|
340
|
-
// Get cities/municipalities for NCR (when "-NO PROVINCE-" is selected)
|
|
341
197
|
const ncrCities = phAddress.getCitiesAndMunsByProvince('-NO PROVINCE-', '1300000000');
|
|
342
|
-
//
|
|
198
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
343
199
|
```
|
|
344
200
|
|
|
345
201
|
---
|
|
@@ -353,23 +209,11 @@ Get all barangays located in selected city or municipality.
|
|
|
353
209
|
|
|
354
210
|
**Returns:** Array of barangays (sorted A-Z)
|
|
355
211
|
|
|
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, ...]
|
|
212
|
+
```typescript
|
|
213
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
365
214
|
|
|
366
|
-
|
|
367
|
-
|
|
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)
|
|
215
|
+
const barangays = phAddress.getBarangaysByCityOrMun('1430300000'); // Baguio City
|
|
216
|
+
// Type: Array<{ psgc: string; name: string; ... }>
|
|
373
217
|
```
|
|
374
218
|
|
|
375
219
|
---
|
|
@@ -383,180 +227,69 @@ Get the region for a given province. Useful for auto-selecting region when user
|
|
|
383
227
|
|
|
384
228
|
**Returns:** Region object or null if not found
|
|
385
229
|
|
|
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
|
|
230
|
+
```typescript
|
|
231
|
+
import phAddress from 'latest-ph-address-thanks-to-anehan';
|
|
390
232
|
|
|
391
|
-
**Example:**
|
|
392
|
-
```javascript
|
|
393
|
-
// Get region for Benguet province
|
|
394
233
|
const region = phAddress.getRegionByProvince('1401100000'); // Benguet
|
|
395
234
|
// 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
|
-
}
|
|
235
|
+
// Type: { psgc: string; name: string; ... } | null
|
|
412
236
|
```
|
|
413
237
|
|
|
238
|
+
## ⚠️ Important Notes
|
|
239
|
+
|
|
240
|
+
- **NCR Handling:** When region is NCR, `getProvincesByRegion()` returns `"-NO PROVINCE-"` (string) instead of an array
|
|
241
|
+
- **"-NO PROVINCE-" Option:** Appears first in sorted lists when getting all provinces
|
|
242
|
+
- **HUCs:** Highly Urbanized Cities (like Baguio, Manila) are included in their geographic province
|
|
243
|
+
- **All Lists:** Returned arrays are sorted A-Z by name
|
|
244
|
+
- **PSGC Format:** Uses 10-digit PSGC codes (PSGC Revision 1)
|
|
245
|
+
|
|
414
246
|
## 📐 Data Structure
|
|
415
247
|
|
|
416
248
|
Each address object contains:
|
|
417
249
|
|
|
418
|
-
```
|
|
419
|
-
{
|
|
420
|
-
psgc:
|
|
421
|
-
name:
|
|
422
|
-
correspondenceCode:
|
|
423
|
-
geographicLevel: '
|
|
424
|
-
|
|
425
|
-
cityClass: null // City class (HUC, etc.) for cities
|
|
250
|
+
```typescript
|
|
251
|
+
interface Address {
|
|
252
|
+
psgc: string; // 10-digit PSGC code
|
|
253
|
+
name: string; // Name
|
|
254
|
+
correspondenceCode: string; // Correspondence code
|
|
255
|
+
geographicLevel: 'Reg' | 'Prov' | 'City' | 'Mun' | 'Bgy';
|
|
256
|
+
cityClass?: string | null; // City class (HUC, CC, ICC) for cities
|
|
426
257
|
}
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
## 🗺️ Geographic Levels
|
|
430
|
-
|
|
431
|
-
- **Reg**: Region
|
|
432
|
-
- **Prov**: Province
|
|
433
|
-
- **City**: City
|
|
434
|
-
- **Mun**: Municipality
|
|
435
|
-
- **Bgy**: Barangay
|
|
436
258
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
259
|
+
// Example:
|
|
260
|
+
const address: Address = {
|
|
261
|
+
psgc: '1380100001',
|
|
262
|
+
name: 'Barangay 1',
|
|
263
|
+
correspondenceCode: '137501001',
|
|
264
|
+
geographicLevel: 'Bgy',
|
|
265
|
+
cityClass: null
|
|
266
|
+
};
|
|
267
|
+
```
|
|
440
268
|
|
|
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 |
|
|
269
|
+
## 🔢 PSGC Code Structure
|
|
447
270
|
|
|
448
|
-
|
|
271
|
+
10-digit PSGC code format: `XX` (Region) + `XXX` (Province) + `XX` (City/Mun) + `XXX` (Barangay)
|
|
449
272
|
|
|
450
273
|
**Example:** `1400101001`
|
|
451
|
-
- Digits 1-2: `14` =
|
|
274
|
+
- Digits 1-2: `14` = CAR
|
|
452
275
|
- Digits 3-5: `001` = Abra Province
|
|
453
276
|
- Digits 6-7: `01` = Bangued Municipality
|
|
454
277
|
- Digits 8-10: `001` = Agtangao Barangay
|
|
455
278
|
|
|
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
279
|
## 💼 Use Cases
|
|
543
280
|
|
|
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
|
|
281
|
+
- E-commerce & Delivery - Address forms, shipping validation
|
|
282
|
+
- Government Services - Public forms, voter registration
|
|
283
|
+
- Financial Services - KYC forms, address verification
|
|
284
|
+
- Real Estate - Property listings, location search
|
|
285
|
+
- Healthcare - Patient registration, medical records
|
|
286
|
+
- Logistics - Shipping management, delivery tracking
|
|
554
287
|
|
|
555
|
-
|
|
288
|
+
## 🙏 Credits
|
|
556
289
|
|
|
557
|
-
|
|
290
|
+
Data from **Philippine Standard Geographic Code (PSGC) database (3Q 2025)**.
|
|
558
291
|
|
|
559
|
-
|
|
292
|
+
Special thanks to the [anehan.online](https://anehan.online) Tech Team! 🇵🇭
|
|
560
293
|
|
|
561
294
|
## 📄 License
|
|
562
295
|
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for latest-ph-address-thanks-to-anehan
|
|
3
|
+
* Complete Philippine addresses database with PSGC codes
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface AddressItem {
|
|
7
|
+
psgc: string;
|
|
8
|
+
name: string;
|
|
9
|
+
correspondenceCode?: string;
|
|
10
|
+
geographicLevel?: string;
|
|
11
|
+
cityClass?: string | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface PhAddress {
|
|
15
|
+
/**
|
|
16
|
+
* Get all regions in the Philippines
|
|
17
|
+
* @returns Array of all regions (sorted A-Z)
|
|
18
|
+
*/
|
|
19
|
+
getRegions(): AddressItem[];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get provinces in a selected region
|
|
23
|
+
* @param regionPsgc - Optional: Region PSGC code
|
|
24
|
+
* @returns Array of provinces (sorted A-Z) when region is provided,
|
|
25
|
+
* Array of all provinces + "-NO PROVINCE-" (83 items) when no parameter,
|
|
26
|
+
* or "-NO PROVINCE-" (string) when region is NCR
|
|
27
|
+
*/
|
|
28
|
+
getProvincesByRegion(regionPsgc?: string): AddressItem[] | string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get all cities and municipalities geographically located in selected province
|
|
32
|
+
* Includes HUCs (Highly Urbanized Cities) that are geographically located in the province
|
|
33
|
+
* @param provincePsgc - Province PSGC code or "-NO PROVINCE-"
|
|
34
|
+
* @param regionPsgc - Optional: Region PSGC code (required when provincePsgc is "-NO PROVINCE-")
|
|
35
|
+
* @returns Array of cities and municipalities (sorted A-Z)
|
|
36
|
+
*/
|
|
37
|
+
getCitiesAndMunsByProvince(provincePsgc: string, regionPsgc?: string): AddressItem[];
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get all barangays located in selected city or municipality
|
|
41
|
+
* Works for all cities and municipalities including HUCs (Manila, Baguio, etc.)
|
|
42
|
+
* @param cityMunPsgc - City/Municipality PSGC code
|
|
43
|
+
* @returns Array of barangays (sorted A-Z)
|
|
44
|
+
*/
|
|
45
|
+
getBarangaysByCityOrMun(cityMunPsgc: string): AddressItem[];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get the region for a given province
|
|
49
|
+
* Useful for auto-selecting region when user chooses province first (province-first flow)
|
|
50
|
+
* @param provincePsgc - Province PSGC code
|
|
51
|
+
* @returns Region object or null if not found
|
|
52
|
+
*/
|
|
53
|
+
getRegionByProvince(provincePsgc: string): AddressItem | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare const phAddress: PhAddress;
|
|
57
|
+
export default phAddress;
|
|
58
|
+
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "latest-ph-address-thanks-to-anehan",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Latest Philippine addresses database with complete coverage of all Regions, Provinces, Cities, Municipalities, and Barangays. Perfect for address forms and location-based applications.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"optimize": "node scripts/optimize-data.js",
|
|
8
9
|
"compress": "node scripts/compress-data.js",
|