From 7567458bf111e3139eebb8ac29c08f15e530fa95 Mon Sep 17 00:00:00 2001 From: Matthias Pfeil Date: Wed, 4 Jan 2023 12:55:52 +0100 Subject: [PATCH] Add klassifizierungs parameter (#22) --- README.md | 1 + index.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 352fafb..4372b58 100644 --- a/README.md +++ b/README.md @@ -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** diff --git a/index.js b/index.js index c924801..5f07f09 100644 --- a/index.js +++ b/index.js @@ -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 @@ -43,6 +53,7 @@ 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 @@ -50,11 +61,12 @@ const query = (url, options = {}) => { 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!')