UNPKG

hk-bus-eta

Version:

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

51 lines 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("./utils"); function fetchEtas({ route, bound, freq, seq, holidays, serviceDayMap, }) { if (seq === 0) { const now = new Date(); return Promise.resolve((0, utils_1.getUpcomingFerry)({ holidays, serviceDayMap, freq, date: new Date() }) .filter((v) => new Date(v).getTime() - now.getTime() < 180 * 60 * 1000) .map((eta) => ({ eta: eta, remark: { zh: "預定班次", en: "Scheduled", }, dest: { zh: "", en: "", }, co: "hkkf", }))); } else if (seq === 1) { return fetch(`https://www.hkkfeta.com/opendata/eta/${route.slice(2)}/${bound === "I" ? "inbound" : "outbound"}`, { cache: utils_1.isSafari ? "default" : "no-store", }) .then((response) => response.json()) .then(({ data }) => { if (!data) return []; return data.map(({ ETA }) => { return { eta: ETA, remark: { zh: "", en: "", }, dest: { zh: "", en: "", }, co: "hkkf", }; }); }); } else { return Promise.resolve([]); } } exports.default = fetchEtas; //# sourceMappingURL=hkkf.js.map