hk-bus-eta-skpracta
Version:
Query the ETA (Estimated Time of Arrival) of HK Bus/Minibus/MTR/Lightrail (skpracta flavored)
27 lines • 938 B
JavaScript
import { isSafari } from "./utils";
export default function fetchEtas({ stopId, route, bound, seq, }) {
return fetch(`https://rt.data.gov.hk//v2/transport/citybus/eta/CTB/${stopId}/${route}`, {
cache: 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",
})));
}
//# sourceMappingURL=ctb.js.map