Skip to content

Commit

Permalink
Merge pull request #3 from hyubs/develop
Browse files Browse the repository at this point in the history
Added PSGC
  • Loading branch information
hubertursua committed Apr 23, 2020
2 parents 5121757 + 0b38309 commit b3ebe36
Show file tree
Hide file tree
Showing 41 changed files with 15,905 additions and 335 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"root": true,
"rules": {
"class-methods-use-this": 0,
"func-names": 0,
"import/extensions": 0,
"mocha/no-mocha-arrows": 0
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Data Updated
name: Data Updated ISO3166

on:
schedule:
Expand All @@ -12,17 +12,13 @@ jobs:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
node-version: 12.x
- run: npm ci
- run: npm run check:diff
- run: npm run diff:iso3166
env:
CI: true
24 changes: 24 additions & 0 deletions .github/workflows/data-updated-psgc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Data Updated PSGC

on:
schedule:
- cron: 0 11 * * *

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: 12.x
- run: npm ci
- run: npm run diff:psgc
env:
CI: true
90 changes: 51 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

[![NPM version](https://img.shields.io/npm/v/ph-locations.svg)](https://www.npmjs.com/package/ph-locations)
![CI](https://github.com/hyubs/ph-locations/workflows/CI/badge.svg)
![Data Updated](https://github.com/hyubs/ph-locations/workflows/Data%20Updated/badge.svg)
![ISO 3166](https://github.com/hyubs/ph-locations/workflows/Data%20Updated%20ISO3166/badge.svg)
![PSGC](https://github.com/hyubs/ph-locations/workflows/Data%20Updated%20PSGC/badge.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://raw.githubusercontent.com/hyubs/ph-locations/master/LICENSE)

Library of locations in the Philippines
Expand All @@ -23,67 +24,78 @@ yarn add ph-locations

```js
// CommonJS
const {
regions,
provinces,
citiesMunicipalities,
} = require('ph-locations');
const regions = require('ph-locations/json/iso3166/regions');
const provinces = require('ph-locations/json/iso3166/provinces');
const citiesMunicipalities = require('ph-locations/json/iso3166/citiesMunicipalities');

// ES6
import {
regions,
provinces,
citiesMunicipalities,
} from 'ph-locations';
import regions from 'ph-locations/json/iso3166/regions';
import provinces from 'ph-locations/json/iso3166/provinces';
import citiesMunicipalities from 'ph-locations/json/iso3166/citiesMunicipalities';
```

## Source

This library is following [ISO 3166-2:PH](https://en.wikipedia.org/wiki/ISO_3166-2:PH).
### ISO 3166 & Wikipedia

This may be inconsistent with other data sources such as the [Philippine Standard Geographic Code (PSGC)](https://psa.gov.ph/classification/psgc/) of the Philippine Statistics Authority (PSA).
* [ISO 3166-2:PH](https://en.wikipedia.org/wiki/ISO_3166-2:PH)
* [List of cities and municipalities in the Philippines](https://en.wikipedia.org/wiki/List_of_cities_and_municipalities_in_the_Philippines)

### Philippine Standard Geographic Code (PSGC)

* [Regions](https://psa.gov.ph/classification/psgc/?q=psgc/regions)
* [Provinces](https://psa.gov.ph/classification/psgc/?q=psgc/provinces)
* Cities (e.g. [Camarines Sur](https://psa.gov.ph/classification/psgc/?q=psgc/citimuni/051700000))

### Automatic Checking

A [GitHub Action](https://github.com/hyubs/ph-locations/actions?query=workflow%3A%22Data+Updated%22) automatically checks everyday if the data is updated.

## Regions

| Property | Description |
| - | - |
| code | ISO 3166-2:PH code |
| name | English name |
| nameTL | Tagalog name |
| acronym | Acronym or roman number |
| Property | Description | ISO 3166 | PSGC |
| - | - | :-: | :-: |
| code | ISO 3166 or PSGC code || |
| name | English name |||
| nameTL | Tagalog name |||
| acronym | Acronym or roman number |||

## Provinces

| Property | Description |
| - | - |
| code | ISO 3166-2:PH code |
| name | English name |
| altName | Alternative name, often its former name |
| nameTL | Tagalog name |
| region | ISO 3166-2:PH code of the province's region |
| Property | Description | ISO 3166 | PSGC |
| - | - | :-: | :-: |
| code | ISO 3166 or PSGC code || |
| name | English name |||
| altName | Alternative name, often its former name |||
| nameTL | Tagalog name |||
| region | ISO 3166 or PSGC code of the province's region || |

## Cities and Municipalities

| Property | Description |
| - | - |
| name | Name |
| fullName | Complete name. All cities will have names end with "City" |
| altName | Alternative name, often its former name |
| province | ISO 3166-2:PH code of the city's / municipality's province |
| classification | Classification of the city / municipality (see below) |
| isCapital | Is the city / municipality the capital of the province |
| Property | Description | ISO 3166 | PSGC |
| - | - | :-: | :-: |
| code | PSGC code |||
| name | Name |||
| fullName | Complete name. For ISO 3166, all cities will have names end with "City". For PSGC, this will be the complete name as listed in the PSGC website. |||
| altName | Alternative name, often its former name |||
| province | ISO 3166 or PSGC code of the city's or municipality's province |||
| classification | Classification of the city or municipality (see below) |||
| isCapital | Is the city or municipality the capital of the province |||

### Classification

**Mun** - Municipalities

**CC** - Component cities
**ISO 3166**

**ICC** - Independent component cities
| Value | Description |
| - | - |
| Mun | Municipality |
| CC | Component city |
| ICC | Independent component city |
| HUC | Highly urbanized city |

**HUC** - Highly urbanized cities
**PSGC**

| Value | Description |
| - | - |
| MUNICIPALITY | Municipality |
| CITY | City |
54 changes: 54 additions & 0 deletions bin/diffISO3166.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-disable import/no-extraneous-dependencies */
import md5 from 'md5';
import fs from 'fs';
import { resolve } from 'path';
import { buildLib } from '../src/build';
import iso3166 from '../src/iso3166';

function getFileMD5(filePath) {
return md5(fs.readFileSync(filePath, { encoding: 'utf-8' }));
}

(async () => {
const errors = [];

const filePathRegions = resolve(__dirname, '../json/iso3166/regions.json');
const filePathProvinces = resolve(__dirname, '../json/iso3166/provinces.json');
const filePathCitiesMunicipalities = resolve(__dirname, '../json/iso3166/citiesMunicipalities.json');

const oldHashRegions = getFileMD5(filePathRegions);
const oldHashProvinces = getFileMD5(filePathProvinces);
const oldHashCitiesMunicipalities = getFileMD5(filePathCitiesMunicipalities);

try {
await buildLib('iso3166', iso3166);
} catch (err) {
errors.push(err.message);
}

const newHashRegions = getFileMD5(filePathRegions);
const newHashProvinces = getFileMD5(filePathProvinces);
const newHashCitiesMunicipalities = getFileMD5(filePathCitiesMunicipalities);

if (oldHashRegions !== newHashRegions) {
errors.push('List of regions is outdated.');
}

if (oldHashProvinces !== newHashProvinces) {
errors.push('List of provinces is outdated.');
}

if (oldHashCitiesMunicipalities !== newHashCitiesMunicipalities) {
errors.push('List of cities and municipalities is outdated.');
}

if (errors.length > 0) {
// eslint-disable-next-line no-console
console.error('Errors', errors);
process.exit(1);
}

// eslint-disable-next-line no-console
console.log('Everything is updated.');
process.exit(0);
})();
11 changes: 6 additions & 5 deletions bin/diff.js → bin/diffPSGC.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import md5 from 'md5';
import fs from 'fs';
import { resolve } from 'path';
import build from '../src/build';
import { buildLib } from '../src/build';
import psgc from '../src/psgc';

function getFileMD5(filePath) {
return md5(fs.readFileSync(filePath, { encoding: 'utf-8' }));
Expand All @@ -11,16 +12,16 @@ function getFileMD5(filePath) {
(async () => {
const errors = [];

const filePathRegions = resolve(__dirname, '../build/regions.json');
const filePathProvinces = resolve(__dirname, '../build/provinces.json');
const filePathCitiesMunicipalities = resolve(__dirname, '../build/citiesMunicipalities.json');
const filePathRegions = resolve(__dirname, '../json/psgc/regions.json');
const filePathProvinces = resolve(__dirname, '../json/psgc/provinces.json');
const filePathCitiesMunicipalities = resolve(__dirname, '../json/psgc/citiesMunicipalities.json');

const oldHashRegions = getFileMD5(filePathRegions);
const oldHashProvinces = getFileMD5(filePathProvinces);
const oldHashCitiesMunicipalities = getFileMD5(filePathCitiesMunicipalities);

try {
await build();
await buildLib('psgc', psgc);
} catch (err) {
errors.push(err.message);
}
Expand Down
9 changes: 0 additions & 9 deletions build/index.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit b3ebe36

Please sign in to comment.