ph-municipalities
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -37,3 +37,3 @@ { | ||
"region_num": "", | ||
"provinces": ["Metro Manila"] | ||
"provinces": ["Metropolitan Manila"] | ||
}, | ||
@@ -40,0 +40,0 @@ { |
{ | ||
"name": "ph-municipalities", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "List and write the `municipalities` of Philippines provinces or regions into JSON files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -91,6 +91,8 @@ ## ph-municipalities | ||
- Loads and parses the local excel file in `/data/day1.xlsx` by default. | ||
- Loads and parses the downloaded excel file in `/data/datasource.xlsx` if download URL input is provided. | ||
- Loads and parses the downloaded excel file in `/data/datasource.xlsx` if download URL in the class constructor is provided. | ||
- Displays a list of available PH **region** names. | ||
- Lists all provinces and municipalities of a specified region via commandline input. | ||
- Asks for an option to write results to a JSON file. | ||
- Run the script as follows if installed using `npm i ph-municipalities`: | ||
- `node .\node_modules\ph-municipalities\src\scripts\by_region.js` | ||
@@ -101,5 +103,7 @@ ### `npm run list:province` | ||
- Loads and parses the local excel file in `/data/day1.xlsx` by default. | ||
- Loads and parses the downloaded excel file in `/data/datasource.xlsx` if download URL input is provided. | ||
- Loads and parses the downloaded excel file in `/data/datasource.xlsx` if download URL in the class constructor is provided. | ||
- Lists all municipalities under specified province(s) via commandline input. | ||
- Asks for an option to write results to a JSON file. | ||
- Run the script as follows if installed using `npm i ph-municipalities`: | ||
- `node .\node_modules\ph-municipalities\src\scripts\by_province.js` | ||
@@ -177,8 +181,8 @@ ### `npm run example` | ||
// for each province | ||
const municipalitiesFromProvince = | ||
file.listMunicipalities(['Albay','Masbate','Sorsogon']) | ||
const provinces = ['Albay','Masbate','Sorsogon'] | ||
const municipalitiesFromProvince = file.listMunicipalities(provinces) | ||
// writeMunicipalities() writes municipalities data in a JSON file | ||
// writeMunicipalities() writes municipalities data to a JSON file | ||
file.writeMunicipalities({ | ||
provinces: municipalitiesFromProvince, | ||
provinces, | ||
fileName: path.join(__dirname, 'municipalities.json'), | ||
@@ -188,3 +192,3 @@ prettify: true | ||
// JSON data of the parsed excel file will be accessible on | ||
// JSON data of the parsed excel file will is accessible on | ||
// file.datalist | ||
@@ -191,0 +195,0 @@ console.log(file.datalist) |
@@ -256,4 +256,4 @@ const https = require('https') | ||
* Lists municipalities by by provinces. | ||
* @param {String} provinces - Array of case-sensitive province names. Starts with an upper case. | ||
* @param {String} filName - Full file path to a JSON file | ||
* @param {String[]} provinces - Array of case-sensitive province names. Starts with an upper case. | ||
* @param {String} fielName - Full file path to a JSON file | ||
* @param {Bool} prettify - Write the JSON content with proper spacings and newlines | ||
@@ -267,8 +267,15 @@ * @returns | ||
if (!/\.(json)$/i.test(fileName)) { | ||
throw new Error('Please enter a filename ending in .json') | ||
} | ||
try { | ||
// List the municipalities | ||
const municipalities = this.listMunicipalities({ provinces }) | ||
const url = (this.#url) ? this.#url : `local datasource cache from ${process.env.DEFAULT_EXCEL_FILE_URL}` | ||
const str = { | ||
metadata: { | ||
source: process.env.EXCEL_FILE_URL || '', | ||
source: url || '', | ||
title: 'List of PH Municipalities By Province and Region', | ||
@@ -275,0 +282,0 @@ description: 'This dataset generated with reference to the excel file contents from the source URL.', |
@@ -17,3 +17,3 @@ const path = require('path') | ||
if (url === undefined) { | ||
const askDownload = await prompt('\nWould you like to download and use a remote Excel file?\nPress enter to ignore. Press Y and enter to proceed. [n/Y]:') | ||
const askDownload = await prompt('\nWould you like to download and use a remote Excel file?\nPress enter to ignore. Press Y and enter to proceed. [n/Y]: ') | ||
@@ -20,0 +20,0 @@ if (askDownload === 'Y') { |
@@ -10,7 +10,9 @@ const path = require('path') | ||
let exit = false | ||
let ExcelHandler | ||
let ExcelHandler = null | ||
while (!exit) { | ||
// Prompt to enter the download URL of a remote excel file or use the default local excel file | ||
ExcelHandler = await selectDataSource() | ||
if (ExcelHandler === null) { | ||
ExcelHandler = await selectDataSource() | ||
} | ||
@@ -24,25 +26,34 @@ if (ExcelHandler !== null) { | ||
const { total, data } = formatDisplay(ExcelHandler.listMunicipalities({ provinces })) | ||
console.log(data) | ||
console.log(`\nTotal: ${total}`) | ||
} | ||
// Prompt to write results to a JSON file | ||
const write = await prompt('\nWrite results to a JSON file? [n/Y]: ') | ||
if (total === 0) { | ||
await prompt('No municipalities to show.\n') | ||
} else { | ||
console.log(data) | ||
console.log(`\nTotal: ${total}`) | ||
if (write === 'Y') { | ||
const fileName = await prompt('\nEnter the JSON filename: ') | ||
// Prompt to write results to a JSON file | ||
const write = await prompt('\nWrite results to a JSON file?\nPress enter to ignore. Press Y and enter to proceed. [n/Y]: ') | ||
// Use process.cwd() to enable file paths when building with "pkg" | ||
const filePath = path.join(process.cwd(), fileName) | ||
if (write === 'Y') { | ||
const fileName = await prompt('\nEnter the JSON filename: ') | ||
ExcelHandler.writeMunicipalities({ | ||
provinces, | ||
fileName: filePath | ||
}) | ||
// Use process.cwd() to enable file paths when building with "pkg" | ||
const filePath = path.join(process.cwd(), fileName) | ||
console.log(`JSON file created in ${filePath}`) | ||
try { | ||
ExcelHandler.writeMunicipalities({ | ||
provinces, | ||
fileName: filePath | ||
}) | ||
console.log(`JSON file created in ${filePath}\n`) | ||
} catch (err) { | ||
console.log(err.message) | ||
} | ||
const ex = await prompt('Exit? (Enter X to exit): ') | ||
exit = (ex === 'X') | ||
} | ||
} | ||
} | ||
const ex = await prompt('\nExit? (Enter X to exit): ') | ||
exit = (ex === 'X') | ||
} | ||
@@ -49,0 +60,0 @@ } |
@@ -11,7 +11,10 @@ const path = require('path') | ||
let exit = false | ||
let ExcelHandler | ||
let ExcelHandler = null | ||
let idx | ||
while (!exit) { | ||
// Prompt to enter the download URL of a remote excel file or use the default local excel file | ||
ExcelHandler = await selectDataSource() | ||
if (ExcelHandler === null) { | ||
ExcelHandler = await selectDataSource() | ||
} | ||
@@ -30,6 +33,6 @@ if (ExcelHandler !== null) { | ||
// Check if the region name exists in the masterlist | ||
const idx = regions.data.findIndex(item => item.name === region) | ||
idx = regions.data.findIndex(item => item.name === region) | ||
if (idx === -1) { | ||
console.log('Region name not found.') | ||
await prompt('Region name not found.\n') | ||
} else { | ||
@@ -53,8 +56,12 @@ // List the provinces of a target region | ||
ExcelHandler.writeMunicipalities({ | ||
provinces, | ||
fileName: filePath | ||
}) | ||
try { | ||
ExcelHandler.writeMunicipalities({ | ||
provinces, | ||
fileName: filePath | ||
}) | ||
console.log(`JSON file created in ${filePath}`) | ||
console.log(`JSON file created in ${filePath}`) | ||
} catch (err) { | ||
console.log(err.message) | ||
} | ||
} | ||
@@ -64,4 +71,6 @@ } | ||
const ex = await prompt('\nExit? (Enter X to exit): ') | ||
exit = (ex === 'X') | ||
if (idx >= 0) { | ||
const ex = await prompt('\nExit? (Enter X to exit): ') | ||
exit = (ex === 'X') | ||
} | ||
} | ||
@@ -68,0 +77,0 @@ } |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
661904
642
279