Skip to content

Commit

Permalink
Add klassifizierungs parameter (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpfeil authored Jan 4, 2023
1 parent cb9d32c commit 7567458
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Optionally accepts an `options` object as first parameter:

- `ort` search for a specifc city
- `kurzname` search for specific short name of stations
- `klassifizierung: alle|verkehr|industrie|hintergrund|ohne+zuordnung`
- `status: aktiv|inaktiv|alle` returns stations with the specified status
- `allStations: true` returns all active and inactive stations. Overrides the `status` option **Deprecated**

Expand Down
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ const messwerteUrl = 'https://www.lanuv.nrw.de/fileadmin/lanuv/luft/immissionen/
const MIN_KUERZEL_LENGTH = 4
const MAX_KUERZEL_LENGTH = 6

function capitalizeFirstLetter (string) {
if (string.includes('+')) {
const splitted = string.split('+')
const first = capitalizeFirstLetter(splitted[0])
const second = capitalizeFirstLetter(splitted[1])
return `${first}+${second}`
}
return string.charAt(0).toUpperCase() + string.slice(1)
}

/**
* Helper function to query a url and load
* response with cheeriojs
Expand Down Expand Up @@ -43,18 +53,20 @@ const query = (url, options = {}) => {
*
* @param ort
* @param kurzname
* @param klassifizierung
* @param status
* @param options.allStations return all stations if true
* @returns Promise resolves with an array of all luqs stations
*/
const luqs = (options = {}) => {
return new Promise((resolve, reject) => {
const formData = {}
const { ort, kurzname, status, allStations } = options
const { ort, kurzname, klassifizierung, status, allStations } = options

if (ort) formData.suche_ort = ort
if (kurzname) formData.suche_kurzname = kurzname
if (status) formData.auswahl_status = status
if (klassifizierung) formData.auswahl_klassifizierung = capitalizeFirstLetter(klassifizierung)

if (allStations) {
console.info('Option allStations is deprecated and will be removed in a future release!')
Expand Down

0 comments on commit 7567458

Please sign in to comment.