Constructor
new ExcelFile(params)
Initialize an ExcelFile object
- Source:
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
params |
Object
|
Constructor parameter Object
|
Members
EVENTS :Object.<string, string>
List of EventEmitter events.
- Source:
Type:
-
Object.<string, string>
(private) data :Array.<Object>|null
Objects[] Array corresponding to excel rows extracted from the excel sheet by sheetjs.
- Source:
Type:
-
Array.<Object>
|null
(private) datalist :Array.<Object>|null
Object[] Array of processed string corresponding to the column in the excel file that contains the list of municipalities following the pattern: "municipalityName (provinceName)" Content: [{ municipality, province }, ... ]
- Source:
Type:
-
Array.<Object>
|null
events :function
Node event emitter for listening to custom events.
- Source:
Type:
-
function
(private) metadata :Object.<string, (string|null)>
10-day Excel file information
- Source:
Type:
-
Object.<string, (string|null)>
(private) options :Object.<string, (string|number)>
Other class settings and configurations
- Source:
Type:
-
Object.<string, (string|number)>
(private) pathToFile :string|null
Full file path to excel file on local storage
- Source:
Type:
-
string
|null
(private) settings :Object|null
Region information from the /app/config/regions.json
or other JSON config file.
- Source:
Type:
-
Object
|null
(private) sheets :Array.<string>|null
Excel sheet names parsed by sheetjs.
- Source:
Type:
-
Array.<string>
|null
(private) url :string|null
Remote download URL of an excel file
- Source:
Type:
-
string
|null
(private) workbook :Array.<Object>|null
Excel workbook object parsed by sheetjs
- Source:
Type:
-
Array.<Object>
|null
Methods
download()
Downloads a remote excel file to this.#pathToFile and loads sheetjs parsed-content
- Source:
followsStringPattern(str) → {boolean}
Checks if a string follows the pattern: "municipalityName (provinceName)"
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
string
|
String to check |
Returns:
- Type:
-
boolean
true | false
getMunicipalityName(str) → {string}
Extracts the municipality name from a string following the pattern: "municipalityName (provinceName)"
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
string
|
Returns:
- Type:
-
string
municipality name
getProvinceName(str) → {string|null}
Extracts the province name from a string following the pattern: "municipalityName (provinceName)"
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
string
|
Returns:
-
- Type:
-
string
province name
-
- Type:
-
null
Returns null if "provinceName" is not found
(async) init()
Loads an existing excel file contents to a JSON object. Downloads a remote excel file if a remote this.#url is provided on the constructor
- Source:
listAllProvinces(region, fromExcel) → {Array.<String>}
Lists the province names of a region defined in the settings (PAGASA seasonal config) file or from the parsed Excel file
- Source:
Parameters:
Name | Type | Description |
---|---|---|
region |
string
|
Region name that matches with the |
fromExcel |
boolean
|
Flag to return the province names from the parsed 10-day Excel file. Defaults to
|
Returns:
- Type:
-
Array.<String>
List of all provinces from a 10-day Excel file.
listMunicipalities(provinces) → {Object}
List the municipalities of given province(s)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
provinces |
Array.<String>
|
Array of case-sensitive province names. Starts with an upper case. |
Returns:
- Type:
-
Object
Returns an object with the format: [ { province1: ['municipality1', 'municipality2', .... ] }, { province2: ['municipality1', 'municipality2', .... ] }, ... ]
listProvinces(regionName) → {Array.<String>}
Lists the province names of a region defined in the settings file
- Source:
Parameters:
Name | Type | Description |
---|---|---|
regionName |
string
|
Region name that matches with the |
Returns:
- Type:
-
Array.<String>
List provinces under the regionName
.
listRegions(key) → {Array.<String>}
Lists the region names defined in the settings file
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
key |
Object
|
null |
Key name of the region data definition key.
|
Returns:
- Type:
-
Array.<String>
A list of province information by key
load()
Loads an excel file from a local directory using sheetjs. Store excel file data as JSON in this.#data
- Source:
setOptions(options) → {boolean}
Sets the local this.#options settings
- Source:
Parameters:
Name | Type | Description |
---|---|---|
options |
Object
|
Miscellaneous app settings defined in this.#options |
Returns:
- Type:
-
boolean
shapeJsonData(provinces) → {Object}
Get the requested data with other misc data
- Source:
Parameters:
Name | Type | Description |
---|---|---|
provinces |
Array.<String>
|
List of provinces |
Returns:
- Type:
-
Object
Formatted raw data with misc. metadata
writeMunicipalities(provinces, fielName, prettify) → {Object}
Writes queried municipalities data to a JSON file. Lists municipalities by by provinces.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
provinces |
Array.<String>
|
Array of case-sensitive province names. Starts with an upper case. |
fielName |
string
|
Full file path to a JSON file |
prettify |
boolean
|
Write the JSON content with proper spacings and newlines |
Returns:
- Type:
-
Object
Formatted raw data with misc. metadata
(static) hasSpecialChars(str) → {boolean}
Checks if a string contains special characters
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
string
|
String to check |
Returns:
- Type:
-
boolean
(static) removeGarbledText(str) → {string}
Cleans/removes default-known special characters and garbled text defined in config from string.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
str |
string
|
String to clean |
Returns:
- Type:
-
string
- Clean string