UNPKG

hk-bus-eta-skpracta

Version:

Query the ETA (Estimated Time of Arrival) of HK Bus/Minibus/MTR/Lightrail (skpracta flavored)

30 lines 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("./utils"); function fetchEtas({ stopId, route, bound, seq, }) { return fetch(`https://rt.data.gov.hk//v2/transport/citybus/eta/CTB/${stopId}/${route}`, { cache: utils_1.isSafari ? "default" : "no-store", }) .then((response) => response.json()) .then(({ data }) => data .filter((eta) => eta.eta && bound.includes(eta.dir)) // filter the eta by the stop sequence information // as the route data may not 100% match // use the nearest seq .sort((a, b) => Math.abs(a.seq - seq) < Math.abs(b.seq - seq) ? -1 : 1) .filter((eta, _, self) => eta.seq === self[0].seq) .map((e) => ({ eta: e.eta, remark: { zh: e.rmk_tc, en: e.rmk_en, }, dest: { zh: e.dest_tc, en: e.dest_en, }, co: "ctb", }))); } exports.default = fetchEtas; //# sourceMappingURL=ctb.js.map