hk-bus-eta 1.5.2 → 1.6.0

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/LightRail.js ADDED
@@ -0,0 +1,31 @@
1
+ const utils = require('./utils');
2
+
3
+ module.exports = {
4
+ co: 'lightRail',
5
+ fetchEtas: ({stopId, route, dest }) => (
6
+ fetch(`https://rt.data.gov.hk/v1/transport/mtr/lrt/getSchedule?station_id=${stopId.slice(2)}`, {
7
+ cache: utils.isSafari ? 'default' : 'no-store',
8
+
9
+ }).then( response => response.json() )
10
+ .then(({platform_list}) => (
11
+ platform_list
12
+ .reduce((acc, {route_list, platform_id}) => [
13
+ ...acc,
14
+ ...route_list
15
+ .filter(({route_no, dest_ch, stop}) => route === route_no && dest_ch === dest.zh && stop === 0)
16
+ .map( ({time_en}) => {
17
+ const etaDate = new Date(Date.now() + parseInt(time_en, 10) * 60 * 1000).toISOString();
18
+ return {
19
+ eta: etaDate,
20
+ remark: {
21
+ zh: `${platform_id}號平台`,
22
+ en: `Platform ${platform_id}`
23
+ },
24
+ co: 'lightRail'
25
+ }
26
+ }, [])
27
+ ], [])
28
+ ))
29
+ ),
30
+ fetchStopEtas: ( stopId ) => []
31
+ }
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type Company = "kmb" | "nlb" | "ctb" | "nwfb" | 'lrtfeeder' | 'gmb'
1
+ export type Company = "kmb" | "nlb" | "ctb" | "nwfb" | 'lrtfeeder' | 'gmb' | 'lightRail'
2
2
 
3
3
  export type Terminal = {
4
4
  en: string,
package/index.js CHANGED
@@ -4,10 +4,11 @@ const CtbApi = require('./Ctb')
4
4
  const NlbApi = require('./Nlb')
5
5
  const LrtfeederApi = require('./Lrtfeeder')
6
6
  const GmbApi = require('./Gmb')
7
+ const LightRailApi = require('./LightRail')
7
8
 
8
9
  module.exports = {
9
10
  // seq is 0-based here
10
- fetchEtas: async ( {route, stops, bound, seq, serviceType, co, nlbId, gtfsId, language }) => {
11
+ fetchEtas: async ( {route, stops, bound, dest, seq, serviceType, co, nlbId, gtfsId, language }) => {
11
12
  let _etas = []
12
13
  for ( const company_id of co ) {
13
14
  if (company_id === 'kmb' && stops.kmb ){
@@ -27,6 +28,8 @@ module.exports = {
27
28
  _etas = _etas.concat( await LrtfeederApi.fetchEtas({stopId: stops.lrtfeeder[seq], route, language}))
28
29
  } else if ( company_id === 'gmb' && stops.gmb ) {
29
30
  _etas = _etas.concat( await GmbApi.fetchEtas({stopId: stops.gmb[seq], gtfsId, seq, bound: bound[company_id]}) )
31
+ } else if ( company_id === 'lightRail' && stops.lightRail ) {
32
+ _etas = _etas.concat( await LightRailApi.fetchEtas({ stopId: stops.lightRail[seq], route, dest }) )
30
33
  }
31
34
  }
32
35
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hk-bus-eta",
3
- "version": "1.5.2",
3
+ "version": "1.6.0",
4
4
  "description": "Query the ETA (Estimated Time of Arrival) of HK Bus",
5
5
  "main": "index.js",
6
6
  "scripts": {