diff --git a/@types/index.d.ts b/@types/index.d.ts new file mode 100644 index 0000000..6df5a06 --- /dev/null +++ b/@types/index.d.ts @@ -0,0 +1,62 @@ +declare interface ISO3166CitiesMunicipality { + name: string; + fullName: string; + altName?: string; + province: string; + classification: 'Mun' | 'CC' | 'ICC' | 'HUC'; + isCapital: boolean; +} + +declare interface ISO3166Province { + code: string; + name: string; + altName?: string; + nameTL: string; + region: string; +} + +declare interface ISO3166Region { + code: string; + name: string; + altName?: string; + nameTL: string; +} + +declare interface PSGCCitiesMunicipality { + code: string; + name: string; + fullName: string; + altName?: string; + province: string; + classification: 'MUNICIPALITY' | 'CITY'; + isCapital: boolean; +} + +declare interface PSGCProvince { + code: string; + name: string; + altName?: string; + region: string; +} + +declare interface PSGCRegion { + code: string; + name: string; + altName?: string; +} + +declare module 'ph-locations' { + export var citiesMunicipalities: ISO3166CitiesMunicipality[]; + export var provinces: ISO3166Province[]; + export var regions: ISO3166Region[]; + export var iso3166: { + citiesMunicipalities: ISO3166CitiesMunicipality[]; + provinces: ISO3166Province[]; + regions: ISO3166Region[]; + }; + export var psgc: { + citiesMunicipalities: PSGCCitiesMunicipality[]; + provinces: PSGCProvince[]; + regions: PSGCRegion[]; + }; +} diff --git a/README.md b/README.md index 0d502dc..26db9c7 100644 --- a/README.md +++ b/README.md @@ -22,19 +22,64 @@ yarn add ph-locations ### Import +**Default (ISO 3166)** + +```js +// CommonJS +const { + regions, + provinces, + citiesMunicipalities, +} = require('ph-locations'); + +// ES6 +import { + regions, + provinces, + citiesMunicipalities, +} from 'ph-locations'; +``` + +**PSGC** + +```js +// CommonJS +const { + regions, + provinces, + citiesMunicipalities, +} = require('ph-locations').psgc; + +// ES6 +import { psgc } from 'ph-locations'; +const { + regions, + provinces, + citiesMunicipalities, +} = psgc; + +``` + +**ISO 3166 (same result as default)** + ```js // CommonJS -const regions = require('ph-locations/json/iso3166/regions'); -const provinces = require('ph-locations/json/iso3166/provinces'); -const citiesMunicipalities = require('ph-locations/json/iso3166/citiesMunicipalities'); +const { + regions, + provinces, + citiesMunicipalities, +} = require('ph-locations').iso3166; // ES6 -import regions from 'ph-locations/json/iso3166/regions'; -import provinces from 'ph-locations/json/iso3166/provinces'; -import citiesMunicipalities from 'ph-locations/json/iso3166/citiesMunicipalities'; +import { iso3166 } from 'ph-locations'; +const { + regions, + provinces, + citiesMunicipalities, +} = iso3166; ``` -## Source +## Sources ### ISO 3166 & Wikipedia @@ -47,20 +92,22 @@ import citiesMunicipalities from 'ph-locations/json/iso3166/citiesMunicipalities * [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 +## Automatic Checking + +GitHub Actions ([ISO 3166](https://github.com/hyubs/ph-locations/actions?query=workflow%3A%22Data+Updated+ISO3166%22), [PSGC](https://github.com/hyubs/ph-locations/actions?query=workflow%3A%22Data+Updated+PSGC%22)) automatically runs everyday to check if the data is updated. -A [GitHub Action](https://github.com/hyubs/ph-locations/actions?query=workflow%3A%22Data+Updated%22) automatically checks everyday if the data is updated. +## Properties -## Regions +### Regions | Property | Description | ISO 3166 | PSGC | | - | - | :-: | :-: | | code | ISO 3166 or PSGC code | ✓ | ✓ | | name | English name | ✓ | ✓ | | nameTL | Tagalog name | ✓ | ✗ | -| acronym | Acronym or roman number | ✓ | ✓ | +| altName | Alternative name, often the roman number or acronym of the region | ✓ | ✓ | -## Provinces +### Provinces | Property | Description | ISO 3166 | PSGC | | - | - | :-: | :-: | @@ -70,7 +117,7 @@ A [GitHub Action](https://github.com/hyubs/ph-locations/actions?query=workflow%3 | nameTL | Tagalog name | ✓ | ✗ | | region | ISO 3166 or PSGC code of the province's region | ✓ | ✓ | -## Cities and Municipalities +### Cities and Municipalities | Property | Description | ISO 3166 | PSGC | | - | - | :-: | :-: | @@ -82,7 +129,7 @@ A [GitHub Action](https://github.com/hyubs/ph-locations/actions?query=workflow%3 | classification | Classification of the city or municipality (see below) | ✓ | ✓ | | isCapital | Is the city or municipality the capital of the province | ✓ | ✓ | -### Classification +#### Classification **ISO 3166** @@ -98,4 +145,8 @@ A [GitHub Action](https://github.com/hyubs/ph-locations/actions?query=workflow%3 | Value | Description | | - | - | | MUNICIPALITY | Municipality | -| CITY | City | \ No newline at end of file +| CITY | City | + +## License + +Licensed under [MIT License](https://github.com/hyubs/ph-locations/blob/master/LICENSE) \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..453e777 --- /dev/null +++ b/index.js @@ -0,0 +1,21 @@ +/* eslint-disable global-require */ + +const iso3166 = { + citiesMunicipalities: require('./json/iso3166/citiesMunicipalities.json'), + provinces: require('./json/iso3166/provinces.json'), + regions: require('./json/iso3166/regions.json'), +}; + +const psgc = { + citiesMunicipalities: require('./json/psgc/citiesMunicipalities.json'), + provinces: require('./json/psgc/provinces.json'), + regions: require('./json/psgc/regions.json'), +}; + +module.exports = { + citiesMunicipalities: iso3166.citiesMunicipalities, + provinces: iso3166.provinces, + regions: iso3166.regions, + iso3166, + psgc, +}; diff --git a/json/iso3166/regions.json b/json/iso3166/regions.json index fe617cf..604a991 100644 --- a/json/iso3166/regions.json +++ b/json/iso3166/regions.json @@ -3,102 +3,102 @@ "code": "PH-14", "name": "Autonomous Region in Muslim Mindanao", "nameTL": "Nagsasariling Rehiyon ng Muslim sa Mindanaw", - "acronym": "ARMM" + "altName": "ARMM" }, { "code": "PH-05", "name": "Bicol", "nameTL": "Rehiyon ng Bikol", - "acronym": "V" + "altName": "V" }, { "code": "PH-02", "name": "Cagayan Valley", "nameTL": "Rehiyon ng Lambak ng Kagayan", - "acronym": "II" + "altName": "II" }, { "code": "PH-40", "name": "Calabarzon", "nameTL": "Rehiyon ng Calabarzon", - "acronym": "IV-A" + "altName": "IV-A" }, { "code": "PH-13", "name": "Caraga", "nameTL": "Rehiyon ng Karaga", - "acronym": "XIII" + "altName": "XIII" }, { "code": "PH-03", "name": "Central Luzon", "nameTL": "Rehiyon ng Gitnang Luson", - "acronym": "III" + "altName": "III" }, { "code": "PH-07", "name": "Central Visayas", "nameTL": "Rehiyon ng Gitnang Bisaya", - "acronym": "VII" + "altName": "VII" }, { "code": "PH-15", "name": "Cordillera Administrative Region", "nameTL": "Rehiyon ng Administratibo ng Kordilyera", - "acronym": "CAR" + "altName": "CAR" }, { "code": "PH-11", "name": "Davao", "nameTL": "Rehiyon ng Dabaw", - "acronym": "XI" + "altName": "XI" }, { "code": "PH-08", "name": "Eastern Visayas", "nameTL": "Rehiyon ng Silangang Bisaya", - "acronym": "VIII" + "altName": "VIII" }, { "code": "PH-01", "name": "Ilocos", "nameTL": "Rehiyon ng Iloko", - "acronym": "I" + "altName": "I" }, { "code": "PH-41", "name": "Mimaropa", "nameTL": "Rehiyon ng Mimaropa", - "acronym": "IV-B" + "altName": "IV-B" }, { "code": "PH-00", "name": "National Capital Region", "nameTL": "Pambansang Punong Rehiyon", - "acronym": "NCR" + "altName": "NCR" }, { "code": "PH-10", "name": "Northern Mindanao", "nameTL": "Rehiyon ng Hilagang Mindanaw", - "acronym": "X" + "altName": "X" }, { "code": "PH-12", "name": "Soccsksargen", "nameTL": "Rehiyon ng Soccsksargen", - "acronym": "XII" + "altName": "XII" }, { "code": "PH-06", "name": "Western Visayas", "nameTL": "Rehiyon ng Kanlurang Bisaya", - "acronym": "VI" + "altName": "VI" }, { "code": "PH-09", "name": "Zamboanga Peninsula", "nameTL": "Rehiyon ng Tangway ng Sambuwangga", - "acronym": "IX" + "altName": "IX" } ] \ No newline at end of file diff --git a/json/psgc/regions.json b/json/psgc/regions.json index 26ea480..64c4002 100644 --- a/json/psgc/regions.json +++ b/json/psgc/regions.json @@ -2,86 +2,86 @@ { "code": "130000000", "name": "NATIONAL CAPITAL REGION", - "acronym": "NCR" + "altName": "NCR" }, { "code": "140000000", "name": "CORDILLERA ADMINISTRATIVE REGION", - "acronym": "CAR" + "altName": "CAR" }, { "code": "010000000", "name": "ILOCOS REGION", - "acronym": "REGION I" + "altName": "REGION I" }, { "code": "020000000", "name": "CAGAYAN VALLEY", - "acronym": "REGION II" + "altName": "REGION II" }, { "code": "030000000", "name": "CENTRAL LUZON", - "acronym": "REGION III" + "altName": "REGION III" }, { "code": "040000000", "name": "CALABARZON", - "acronym": "REGION IV-A" + "altName": "REGION IV-A" }, { "code": "170000000", "name": "MIMAROPA REGION", - "acronym": "MIMAROPA" + "altName": "MIMAROPA" }, { "code": "050000000", "name": "BICOL REGION", - "acronym": "REGION V" + "altName": "REGION V" }, { "code": "060000000", "name": "WESTERN VISAYAS", - "acronym": "REGION VI" + "altName": "REGION VI" }, { "code": "070000000", "name": "CENTRAL VISAYAS", - "acronym": "REGION VII" + "altName": "REGION VII" }, { "code": "080000000", "name": "EASTERN VISAYAS", - "acronym": "REGION VIII" + "altName": "REGION VIII" }, { "code": "090000000", "name": "ZAMBOANGA PENINSULA", - "acronym": "REGION IX" + "altName": "REGION IX" }, { "code": "100000000", "name": "NORTHERN MINDANAO", - "acronym": "REGION X" + "altName": "REGION X" }, { "code": "110000000", "name": "DAVAO REGION", - "acronym": "REGION XI" + "altName": "REGION XI" }, { "code": "120000000", "name": "SOCCSKSARGEN", - "acronym": "REGION XII" + "altName": "REGION XII" }, { "code": "160000000", "name": "CARAGA", - "acronym": "REGION XIII" + "altName": "REGION XIII" }, { "code": "150000000", "name": "AUTONOMOUS REGION IN MUSLIM MINDANAO", - "acronym": "ARMM" + "altName": "ARMM" } ] \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 2544ecd..7a585e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ph-locations", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2dd729d..cd08af4 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "ph-locations", - "version": "1.1.0", + "version": "1.1.1", "description": "Library of locations in the Philippines", - "main": "build/index.js", + "main": "index.js", "scripts": { "build": "node -r esm -e \"import build from './src/build'; build();\"", "lint": "eslint .", "test": "mocha", - "prepublish": "npm run lint && npm run test", + "prepublishOnly": "npm run lint && npm run test", "diff:iso3166": "node -r esm bin/diffISO3166.js", "diff:psgc": "node -r esm bin/diffPSGC.js" }, @@ -51,5 +51,6 @@ "mocha": "^7.1.1", "sinon": "^9.0.2", "sinon-chai": "^3.5.0" - } + }, + "types": "@types/index.d.ts" } diff --git a/src/iso3166/getRegions.js b/src/iso3166/getRegions.js index b88c41c..c5c803b 100644 --- a/src/iso3166/getRegions.js +++ b/src/iso3166/getRegions.js @@ -19,13 +19,13 @@ export default async function getRegions() { const code = sanitize($cells.eq(0).text()); const name = sanitize($cells.eq(1).text()); const nameTL = sanitize($cells.eq(2).text()); - const acronym = sanitize($cells.eq(3).text()); + const altName = sanitize($cells.eq(3).text()); regions.push({ code, name, nameTL, - acronym, + altName, }); }); diff --git a/src/psgc/getRegions.js b/src/psgc/getRegions.js index 6cd4d66..aeece07 100644 --- a/src/psgc/getRegions.js +++ b/src/psgc/getRegions.js @@ -11,7 +11,7 @@ export default async function getRegions() { $('#classifytable').each(function () { const nameFull = $('tr > th', this).eq(0).text().replace(/^(Region:\s)/i, ''); const code = $('tr > th', this).eq(1).text().replace(/^(Code:\s)/i, ''); - let acronym = (nameFull.includes('(')) + let altName = (nameFull.includes('(')) ? nameFull.substring(0, nameFull.indexOf('(') - 1) : nameFull; let name = (nameFull.includes('(')) @@ -20,18 +20,18 @@ export default async function getRegions() { if (['ARMM', 'CAR', 'NCR'].includes(name)) { const tmpName = name; - name = acronym; - acronym = tmpName; + name = altName; + altName = tmpName; } - if (acronym.endsWith(' REGION')) { - acronym = acronym.replace(/(\sREGION)$/i, ''); + if (altName.endsWith(' REGION')) { + altName = altName.replace(/(\sREGION)$/i, ''); } regions.push({ code, name, - acronym, + altName, }); }); diff --git a/test/specs/iso3166/getRegions.spec.js b/test/specs/iso3166/getRegions.spec.js index 9ef9e47..70fca65 100644 --- a/test/specs/iso3166/getRegions.spec.js +++ b/test/specs/iso3166/getRegions.spec.js @@ -32,8 +32,8 @@ export default () => { expect(element).to.have.property('nameTL'); }); - it('should have a property "acronym"', async () => { - expect(element).to.have.property('acronym'); + it('should have a property "altName"', async () => { + expect(element).to.have.property('altName'); }); }); }); diff --git a/test/specs/psgc/getRegions.spec.js b/test/specs/psgc/getRegions.spec.js index e02d6a7..4327656 100644 --- a/test/specs/psgc/getRegions.spec.js +++ b/test/specs/psgc/getRegions.spec.js @@ -28,8 +28,8 @@ export default () => { expect(element).to.have.property('name'); }); - it('should have a property "acronym"', async () => { - expect(element).to.have.property('acronym'); + it('should have a property "altName"', async () => { + expect(element).to.have.property('altName'); }); }); });