From 90308411fcfe6a5637930254a9e68a6dea8a8cf5 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Wed, 29 Dec 2021 16:59:31 +0100 Subject: [PATCH] =?UTF-8?q?docs:=20.then/.catch=20->=20await=20?= =?UTF-8?q?=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ci skip] --- docs/arrivals.md | 2 +- docs/departures.md | 8 +++----- docs/journeys.md | 27 ++++++++++----------------- docs/lines.md | 2 +- docs/locations.md | 6 ++---- docs/nearby.md | 6 ++---- docs/radar.md | 6 ++---- docs/reachable-from.md | 8 +++----- docs/readme.md | 4 +--- docs/refresh-journey.md | 12 ++++-------- docs/remarks.md | 2 +- docs/server-info.md | 2 +- docs/stop.md | 6 ++---- docs/trip.md | 19 ++++++++----------- docs/trips-by-name.md | 4 ++-- 15 files changed, 43 insertions(+), 71 deletions(-) diff --git a/docs/arrivals.md b/docs/arrivals.md index 683c47ed..ebd1ec86 100644 --- a/docs/arrivals.md +++ b/docs/arrivals.md @@ -1,3 +1,3 @@ # `arrivals(station, [opt])` -Just like [`departures(station, [opt])`](departures.md), except that it gives arrival times instead of departure times. +Just like [`departures(station, [opt])`](departures.md), except that it resolves with arrival times instead of departure times. diff --git a/docs/departures.md b/docs/departures.md index ca9cd904..5c5dcac3 100644 --- a/docs/departures.md +++ b/docs/departures.md @@ -48,7 +48,7 @@ const vbbProfile = require('hafas-client/p/vbb') const client = createClient(vbbProfile, 'my-awesome-program') // will query with these products: suburban, subway, bus, express, regional -client.departures('900000024101', {products: {tram: false, ferry: false}}) +await client.departures('900000024101', {products: {tram: false, ferry: false}}) ``` ## Response @@ -66,12 +66,10 @@ const vbbProfile = require('hafas-client/p/vbb') const client = createClient(vbbProfile, 'my-awesome-program') // S Charlottenburg -client.departures('900000024101', {duration: 3}) -.then(console.log) -.catch(console.error) +await client.departures('900000024101', {duration: 3}) ``` -The response may look like this: +The result may look like this: ```js [ { diff --git a/docs/journeys.md b/docs/journeys.md index 34ed7b85..cbd61db1 100644 --- a/docs/journeys.md +++ b/docs/journeys.md @@ -91,15 +91,13 @@ const vbbProfile = require('hafas-client/p/vbb') const client = createClient(vbbProfile, 'my-awesome-program') // Hauptbahnhof to Heinrich-Heine-Str. -client.journeys('900000003201', '900000100008', { +await client.journeys('900000003201', '900000100008', { results: 1, stopovers: true }) -.then(console.log) -.catch(console.error) ``` -The `Promise` returned by `journeys()` will resolve with an object with the `journeys` & `earlierRef`/`laterRef` fields. It might look like this: +`journeys()` will resolve with an object with the `journeys` & `earlierRef`/`laterRef` fields. It might look like this: ```js { @@ -317,21 +315,16 @@ To get more journeys earlier/later than the current set of results, pass `earlie const hbf = '900000003201' const heinrichHeineStr = '900000100008' -client.journeys(hbf, heinrichHeineStr) -.then((res) => { - const lastJourney = res.journeys[res.journeys.length - 1] - console.log('departure of last journey', lastJourney.legs[0].departure) +const res1 = await client.journeys(hbf, heinrichHeineStr) +const lastJourney = res1.journeys[res1.journeys.length - 1] +console.log('departure of last journey', lastJourney.legs[0].departure) - // get later journeys - return client.journeys(hbf, heinrichHeineStr, { - laterThan: res.laterRef - }) +// get later journeys +const res2 = await client.journeys(hbf, heinrichHeineStr, { + laterThan: res1.laterRef }) -.then((laterRes) => { - const firstLaterJourney = laterRes.journeys[laterRes.journeys.length - 1] - console.log('departure of first (later) journey', firstLaterJourney.legs[0].departure) -}) -.catch(console.error) +const firstLaterJourney = res2.journeys[res2.journeys.length - 1] +console.log('departure of first (later) journey', firstLaterJourney.legs[0].departure) ``` ``` diff --git a/docs/lines.md b/docs/lines.md index 451c4053..e787727a 100644 --- a/docs/lines.md +++ b/docs/lines.md @@ -12,7 +12,7 @@ const svvProfile = require('hafas-client/p/svv') const client = createClient(svvProfile, 'my-awesome-program') -console.log(await client.lines('S1')) +await client.lines('S1') ``` ```js diff --git a/docs/locations.md b/docs/locations.md index f8ba31f2..1b189ba2 100644 --- a/docs/locations.md +++ b/docs/locations.md @@ -28,12 +28,10 @@ const vbbProfile = require('hafas-client/p/vbb') const client = createClient(vbbProfile, 'my-awesome-program') -client.locations('Alexanderplatz', {results: 3}) -.then(console.log) -.catch(console.error) +await client.locations('Alexanderplatz', {results: 3}) ``` -The response may look like this: +The result may look like this: ```js [ { diff --git a/docs/nearby.md b/docs/nearby.md index c2db0060..cc9332a1 100644 --- a/docs/nearby.md +++ b/docs/nearby.md @@ -29,16 +29,14 @@ const vbbProfile = require('hafas-client/p/vbb') const client = createClient(vbbProfile, 'my-awesome-program') -client.nearby({ +await client.nearby({ type: 'location', latitude: 52.5137344, longitude: 13.4744798 }, {distance: 400}) -.then(console.log) -.catch(console.error) ``` -The response may look like this: +The result may look like this: ```js [ { diff --git a/docs/radar.md b/docs/radar.md index 1be49d05..994cc3a3 100644 --- a/docs/radar.md +++ b/docs/radar.md @@ -30,17 +30,15 @@ const vbbProfile = require('hafas-client/p/vbb') const client = createClient(vbbProfile, 'my-awesome-program') -client.radar({ +await client.radar({ north: 52.52411, west: 13.41002, south: 52.51942, east: 13.41709 }, {results: 5}) -.then(console.log) -.catch(console.error) ``` -The response may look like this: +The result may look like this: ```js [ { diff --git a/docs/reachable-from.md b/docs/reachable-from.md index 6f81fff5..87103a00 100644 --- a/docs/reachable-from.md +++ b/docs/reachable-from.md @@ -36,19 +36,17 @@ const vbbProfile = require('hafas-client/p/vbb') const client = createClient(vbbProfile, 'my-awesome-program') -client.reachableFrom({ +console.log(await client.reachableFrom({ type: 'location', address: '13353 Berlin-Wedding, Torfstr. 17', latitude: 52.541797, longitude: 13.350042 }, { maxDuration: 10 // minutes -}) -.then(console.log) -.catch(console.error) +})) ``` -The response may look like this: +The result may look like this: ```js [ diff --git a/docs/readme.md b/docs/readme.md index 11877c5e..b97d175b 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -19,9 +19,7 @@ const dbProfile = require('hafas-client/p/db') const client = createClient(withThrottling(dbProfile), 'my-awesome-program') // Berlin Jungfernheide to München Hbf -client.journeys('8011167', '8000261', {results: 1}) -.then(console.log) -.catch(console.error) +await client.journeys('8011167', '8000261', {results: 1}) ``` You can pass custom values for the nr of requests (`limit`) per interval into `withThrottling`: diff --git a/docs/refresh-journey.md b/docs/refresh-journey.md index 675ae889..31445937 100644 --- a/docs/refresh-journey.md +++ b/docs/refresh-journey.md @@ -27,14 +27,10 @@ const vbbProfile = require('hafas-client/p/vbb') const client = createClient(vbbProfile) // Hauptbahnhof to Heinrich-Heine-Str. -client.journeys('900000003201', '900000100008', {results: 1}) -.then(([journey]) => { - // later, fetch up-to-date info on the journey - client.refreshJourney(journey.refreshToken, {stopovers: true, remarks: true}) - .then(console.log) - .catch(console.error) -}) -.catch(console.error) +const {journeys} = await client.journeys('900000003201', '900000100008', {results: 1}) + +// later, fetch up-to-date info on the journey +await client.refreshJourney(journeys[0].refreshToken, {stopovers: true, remarks: true}) ``` `refreshJourney()` will return a *single* [*Friendly Public Transport Format* v2 draft](https://github.com/public-transport/friendly-public-transport-format/blob/3bd36faa721e85d9f5ca58fb0f38cdbedb87bbca/spec/readme.md) `journey`, in the same format as with `journeys()`. diff --git a/docs/remarks.md b/docs/remarks.md index cc72fd7d..b5800105 100644 --- a/docs/remarks.md +++ b/docs/remarks.md @@ -25,7 +25,7 @@ const svvProfile = require('hafas-client/p/svv') const client = createClient(svvProfile, 'my-awesome-program') -console.log(await client.remarks()) +await client.remarks() ``` ```js diff --git a/docs/server-info.md b/docs/server-info.md index 86db86f5..a2d2938c 100644 --- a/docs/server-info.md +++ b/docs/server-info.md @@ -21,7 +21,7 @@ const svvProfile = require('hafas-client/p/svv') const client = createClient(svvProfile, 'my-awesome-program') -console.log(await client.serverInfo()) +await client.serverInfo() ``` ```js diff --git a/docs/stop.md b/docs/stop.md index 0e9f11ee..e0b4c1ea 100644 --- a/docs/stop.md +++ b/docs/stop.md @@ -40,12 +40,10 @@ const vbbProfile = require('hafas-client/p/vbb') const client = createClient(vbbProfile, 'my-awesome-program') -client.stop('900000042101') // U Spichernstr. -.then(console.log) -.catch(console.error) +await client.stop('900000042101') // U Spichernstr. ``` -The response may look like this: +The result may look like this: ```js { diff --git a/docs/trip.md b/docs/trip.md index 639a83f3..75bcb3fd 100644 --- a/docs/trip.md +++ b/docs/trip.md @@ -13,13 +13,10 @@ const vbbProfile = require('hafas-client/p/vbb') const client = createClient(vbbProfile, 'my-awesome-program') // Hauptbahnhof to Heinrich-Heine-Str. -client.journeys('900000003201', '900000100008', {results: 1}) -.then(([journey]) => { - const leg = journey.legs[0] - return client.trip(leg.tripId, leg.line.name) -}) -.then(console.log) -.catch(console.error) +const {journeys} = client.journeys('900000003201', '900000100008', {results: 1}) +const leg = journeys[0].legs[0] + +await client.trip(leg.tripId, leg.line.name) ``` With `opt`, you can override the default options, which look like this: @@ -47,12 +44,12 @@ const vbbProfile = require('hafas-client/p/vbb') const client = createClient(vbbProfile) -client.trip('1|31431|28|86|17122017', 'S9', {when: 1513534689273}) -.then(console.log) -.catch(console.error) +console.log(await client.trip('1|31431|28|86|17122017', 'S9', { + when: 1513534689273, +})) ``` -The response looked like this: +The result looked like this: ```js { diff --git a/docs/trips-by-name.md b/docs/trips-by-name.md index ae3e8d17..09eb69e2 100644 --- a/docs/trips-by-name.md +++ b/docs/trips-by-name.md @@ -12,7 +12,7 @@ const vbbProfile = require('hafas-client/p/vbb') const client = createClient(vbbProfile, 'my-awesome-program') -console.log(await client.tripsByName('S1')) +await client.tripsByName('S1') ``` With `opt`, you can override the default options, which look like this: @@ -42,7 +42,7 @@ With `opt`, you can override the default options, which look like this: } ``` -The response may look like this: +The result may look like this: ```js [