hk-bus-eta-skpracta
Version:
Query the ETA (Estimated Time of Arrival) of HK Bus/Minibus/MTR/Lightrail (skpracta flavored)
38 lines • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
function fetchEtas({ stopId, nlbId, }) {
return fetch(`https://rt.data.gov.hk/v1/transport/nlb/stop.php?action=estimatedArrivals`, {
body: JSON.stringify({
routeId: nlbId,
stopId,
language: "zh",
}),
headers: {
"Content-Type": "text/plain",
},
method: "POST",
cache: utils_1.isSafari ? "default" : "no-store",
})
.then((response) => response.json())
.then(({ estimatedArrivals }) => {
if (!estimatedArrivals)
return [];
return estimatedArrivals
.filter((eta) => eta.estimatedArrivalTime)
.map((e) => ({
eta: e.estimatedArrivalTime.replace(" ", "T") + ".000+08:00",
remark: {
zh: "",
en: "",
},
dest: {
zh: "",
en: "",
},
co: "nlb",
}));
});
}
exports.default = fetchEtas;
//# sourceMappingURL=nlb.js.map