mirror of
http://100.103.83.12:3003/fegger/time_to_leave.git
synced 2026-09-17 09:42:44 +00:00
Add JSDoc documentation to all TypeScript files
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
// ── API Client ──
|
||||
// Thin wrapper around the server-side API routes. Handles journey search,
|
||||
// geocoding, bike/walk routing, calendar fetching, and WienerLinien monitoring.
|
||||
|
||||
import type {
|
||||
GeocodeResult,
|
||||
NearbyStop,
|
||||
@@ -16,6 +20,11 @@ type SearchJourneyOptions = {
|
||||
arriveBy?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fallback window (2 hours) to search backwards when an arrive-by query
|
||||
* returns no journeys. HAFAS sometimes fails to find connections if the
|
||||
* target time is too tight.
|
||||
*/
|
||||
const ARRIVE_BY_FALLBACK_WINDOW_MS = 2 * 60 * 60 * 1000;
|
||||
|
||||
function buildUrl(base: string, path: string, params: Record<string, string> = {}): string {
|
||||
@@ -51,11 +60,19 @@ function buildTripSearchBody(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize HAFAS coordinates. HAFAS may return coordinates in either
|
||||
* decimal degrees or micro-degrees (1e6 factor). This detects and fixes it.
|
||||
*/
|
||||
function normalizeHafasCoordinate(value: number | undefined): number | undefined {
|
||||
if (value == null) return undefined;
|
||||
return Math.abs(value) > 1000 ? value / 1e6 : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Client for the TimeToLeave server API. Proxy requests to HAFAS, OSRM,
|
||||
* Nominatim, and WienerLinien backends. Set `baseUrl` to your deployed app.
|
||||
*/
|
||||
export class ApiClient {
|
||||
private readonly baseUrl: string;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user