hk-bus-eta 1.3.1 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Ctb.js CHANGED
@@ -1,8 +1,10 @@
1
+ const utils = require('./utils');
2
+
1
3
  module.exports = {
2
4
  co: 'ctb',
3
5
  fetchEtas: ({stopId, route, bound }) => (
4
6
  fetch(`https://rt.data.gov.hk//v1/transport/citybus-nwfb/eta/CTB/${stopId}/${route}`, {
5
- cache: "reload"
7
+ cache: utils.isSafari ? 'default' : 'no-store'
6
8
  }).then(
7
9
  response => response.json()
8
10
  ).then(({data}) => data.filter(eta => eta.eta && eta.dir === bound).map(e => ({
@@ -17,7 +19,7 @@ module.exports = {
17
19
  ),
18
20
  fetchStopEtas: ( stopId ) => (
19
21
  fetch(`https://rt.data.gov.hk/v1/transport/batch/stop-eta/CTB/${stopId}`, {
20
- cache: "reload"
22
+ cache: utils.isSafari ? 'default' : 'no-store'
21
23
  }).then(
22
24
  response => response.json()
23
25
  ).then(({data}) => data.map( e => ({
package/Kmb.js CHANGED
@@ -1,10 +1,11 @@
1
+ const utils = require('./utils');
2
+
1
3
  module.exports = {
2
4
  co: 'kmb',
3
5
  fetchEtas: ({stopId, route, seq, serviceType, bound}) => (
4
- fetch(
5
- `https://data.etabus.gov.hk/v1/transport/kmb/eta/${stopId}/${route}/${serviceType}`,
6
- { cache: "reload" }
7
- ).then( response => response.json() )
6
+ fetch(`https://data.etabus.gov.hk/v1/transport/kmb/eta/${stopId}/${route}/${serviceType}`,{
7
+ cache: utils.isSafari ? 'default' : 'no-store'
8
+ }).then( response => response.json() )
8
9
  .then(({data}) => data.filter(e =>
9
10
  e.dir === bound
10
11
  && e.seq === seq + 1 // api return 1-based seq
@@ -20,7 +21,7 @@ module.exports = {
20
21
  ),
21
22
  fetchStopEtas: ( stopId ) => (
22
23
  fetch(`https://data.etabus.gov.hk/v1/transport/kmb/stop-eta/${stopId}`, {
23
- cache: "reload"
24
+ cache: utils.isSafari ? 'default' : 'no-store'
24
25
  })
25
26
  .then(response => response.json())
26
27
  .then(({data}) => data.map( e => ({
package/Lrtfeeder.js CHANGED
@@ -1,9 +1,11 @@
1
+ const utils = require('./utils');
2
+
1
3
  module.exports = {
2
4
  co: 'lrtfeeder',
3
5
  fetchEtas: ({stopId, route, language}) => (
4
6
  fetch(`https://rt.data.gov.hk/v1/transport/mtr/bus/getSchedule`, {
5
7
  method: "POST",
6
- cache: "reload",
8
+ cache: utils.isSafari ? 'default' : 'no-store',
7
9
  headers: {
8
10
  'Content-Type': 'application/json'
9
11
  },
@@ -15,14 +17,14 @@ module.exports = {
15
17
  .then(({busStop}) =>
16
18
  busStop.filter(({busStopId}) => busStopId === stopId)
17
19
  .reduce((ret, {bus: buses}) => ([...ret, ...buses.reduce( (etas, bus) => {
18
- const etaDate = new Date(Date.now() + parseInt(bus.arrivalTimeInSecond, 10) * 1000)
19
- if ( bus.arrivalTimeInSecond === "108000" ) return [...etas];
20
+ const etaDate = new Date(Date.now() + parseInt(bus.arrivalTimeInSecond === "108000" ? bus.departureTimeInSecond : bus.arrivalTimeInSecond, 10) * 1000);
20
21
  return [
21
22
  ...etas,
22
23
  {
23
- eta: etaDate.toISOString(),
24
+ eta: `${etaDate.getFullYear()}-${`0${etaDate.getMonth() + 1}`.slice(-2)}-${`0${etaDate.getDate()}`.slice(-2)}`
25
+ +`T${`0${etaDate.getHours()}`.slice(-2)}:${`0${etaDate.getMinutes()}`.slice(-2)}:${`0${etaDate.getSeconds()}`.slice(-2)}+08:00`,
24
26
  remark: {
25
- [language]: bus.busRemark
27
+ [language]: bus.busRemark || ( bus.isScheduled === "1" ? ( language === "en" ? "Scheduled" : "預定班次" ) : "" )
26
28
  },
27
29
  co: 'lrtfeeder'
28
30
  }
package/Nlb.js CHANGED
@@ -1,3 +1,5 @@
1
+ const utils = require('./utils');
2
+
1
3
  module.exports = {
2
4
  co: 'nlb',
3
5
  fetchEtas: ({stopId, nlbId }) => (
package/Nwfb.js CHANGED
@@ -1,8 +1,10 @@
1
+ const utils = require('./utils');
2
+
1
3
  module.exports = {
2
4
  co: 'nwfb',
3
5
  fetchEtas: ({stopId, route, bound }) => (
4
6
  fetch(`https://rt.data.gov.hk//v1/transport/citybus-nwfb/eta/NWFB/${stopId}/${route}`, {
5
- cache: "reload"
7
+ cache: utils.isSafari ? 'default' : 'no-store'
6
8
  }).then(
7
9
  response => response.json()
8
10
  ).then(({data}) => data.filter(eta => eta.eta && eta.dir === bound).map(e => ({
@@ -17,7 +19,7 @@ module.exports = {
17
19
  ),
18
20
  fetchStopEtas: ( stopId ) => (
19
21
  fetch(`https://rt.data.gov.hk/v1/transport/batch/stop-eta/NWFB/${stopId}`, {
20
- cache: "reload"
22
+ cache: utils.isSafari ? 'default' : 'no-store'
21
23
  }).then(
22
24
  response => response.json()
23
25
  ).then(({data}) => data.map( e => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hk-bus-eta",
3
- "version": "1.3.1",
3
+ "version": "1.3.5",
4
4
  "description": "Query the ETA (Estimated Time of Arrival) of HK Bus",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils.js ADDED
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ isSafari: navigator
3
+ && navigator.userAgent
4
+ && navigator.userAgent.includes('Safari/')
5
+ && !(navigator.userAgent.includes('Chrome/') || navigator.userAgent.includes('Chromium/'))
6
+ }