UNPKG

hk-bus-eta

Version:

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

45 lines 1.7 kB
import { isSafari } from "./utils"; export default function fetchEtas({ gtfsId, stopId, bound, seq, }) { return fetch(`https://data.etagmb.gov.hk/eta/route-stop/${gtfsId}/${stopId}`, { cache: isSafari ? "default" : "no-store", }) .then((response) => response.json()) .then(({ data }) => data .filter(({ route_seq }) => (bound === "O" && route_seq === 1) || (bound === "I" && route_seq === 2)) .filter(({ stop_seq }) => stop_seq === seq + 1) .reduce((acc, { enabled, eta, description_tc, description_en }) => [ ...acc, ...(enabled ? eta.map((data) => { var _a, _b; return { eta: data.timestamp, remark: { zh: (_a = data.remarks_tc) !== null && _a !== void 0 ? _a : "", en: (_b = data.remarks_en) !== null && _b !== void 0 ? _b : "", }, dest: { zh: "", en: "", }, co: "gmb", }; }) : [ { eta: "", remark: { zh: description_tc !== null && description_tc !== void 0 ? description_tc : "", en: description_en !== null && description_en !== void 0 ? description_en : "", }, dest: { zh: "", en: "", }, co: "gmb", }, ]), ], [])); } //# sourceMappingURL=gmb.js.map