UNPKG

hk-bus-eta-skpracta

Version:

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

25 lines 948 B
import { isSafari } from "./utils"; export default function fetchEtas({ stopId, route, bound, stopList, }) { return fetch(`https://rt.data.gov.hk/v1/transport/mtr/getSchedule.php?line=${route}&sta=${stopId}`, { cache: isSafari ? "default" : "no-store", }) .then((response) => response.json()) .then(({ data, status }) => status === 0 ? [] : data[`${route}-${stopId}`][bound.endsWith("UT") ? "UP" : "DOWN"].reduce((acc, { time, plat, dest }) => [ ...acc, { eta: time.replace(" ", "T") + "+08:00", remark: { zh: `${plat}號月台`, en: `Platform ${plat}`, }, dest: { zh: stopList[dest].name.zh, en: stopList[dest].name.en, }, co: "mtr", }, ], [])); } //# sourceMappingURL=mtr.js.map