hk-bus-eta 1.2.0 → 1.2.4
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 +8 -2
- package/Kmb.js +6 -2
- package/Nlb.js +6 -3
- package/Nwfb.js +8 -2
- package/index.d.ts +9 -5
- package/index.js +1 -1
- package/package.json +1 -1
- package/utils.js +3 -0
package/Ctb.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
const utils = require('./utils')
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
co: 'ctb',
|
|
3
5
|
fetchEtas: ({stopId, route, bound }) => (
|
|
4
|
-
fetch(`https://rt.data.gov.hk//v1/transport/citybus-nwfb/eta/CTB/${stopId}/${route}`, {
|
|
6
|
+
fetch(`https://rt.data.gov.hk//v1/transport/citybus-nwfb/eta/CTB/${stopId}/${route}`, {
|
|
7
|
+
cache: utils.isSafari ? 'default' : 'no-store'
|
|
8
|
+
}).then(
|
|
5
9
|
response => response.json()
|
|
6
10
|
).then(({data}) => data.filter(eta => eta.eta && eta.dir === bound).map(e => ({
|
|
7
11
|
eta: e.eta,
|
|
@@ -14,7 +18,9 @@ module.exports = {
|
|
|
14
18
|
)
|
|
15
19
|
),
|
|
16
20
|
fetchStopEtas: ( stopId ) => (
|
|
17
|
-
fetch(`https://rt.data.gov.hk/v1/transport/batch/stop-eta/CTB/${stopId}`, {
|
|
21
|
+
fetch(`https://rt.data.gov.hk/v1/transport/batch/stop-eta/CTB/${stopId}`, {
|
|
22
|
+
cache: utils.isSafari ? 'default' : 'no-store'
|
|
23
|
+
}).then(
|
|
18
24
|
response => response.json()
|
|
19
25
|
).then(({data}) => data.map( e => ({
|
|
20
26
|
route: e.route,
|
package/Kmb.js
CHANGED
|
@@ -1,9 +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
6
|
fetch(
|
|
5
7
|
`https://data.etabus.gov.hk/v1/transport/kmb/eta/${stopId}/${route}/${serviceType}`,
|
|
6
|
-
{ cache:
|
|
8
|
+
{ cache: utils.isSafari ? 'default' : 'no-store' }
|
|
7
9
|
).then( response => response.json() )
|
|
8
10
|
.then(({data}) => data.filter(e =>
|
|
9
11
|
e.dir === bound
|
|
@@ -19,7 +21,9 @@ module.exports = {
|
|
|
19
21
|
)
|
|
20
22
|
),
|
|
21
23
|
fetchStopEtas: ( stopId ) => (
|
|
22
|
-
fetch(`https://data.etabus.gov.hk/v1/transport/kmb/stop-eta/${stopId}`, {
|
|
24
|
+
fetch(`https://data.etabus.gov.hk/v1/transport/kmb/stop-eta/${stopId}`, {
|
|
25
|
+
cache: utils.isSafari ? 'default' : 'no-store'
|
|
26
|
+
})
|
|
23
27
|
.then(response => response.json())
|
|
24
28
|
.then(({data}) => data.map( e => ({
|
|
25
29
|
route: e.route,
|
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 }) => (
|
|
@@ -11,7 +13,7 @@ module.exports = {
|
|
|
11
13
|
"Content-Type": "text/plain"
|
|
12
14
|
},
|
|
13
15
|
method: "POST",
|
|
14
|
-
cache: 'no-store'
|
|
16
|
+
cache: utils.isSafari ? 'default' : 'no-store'
|
|
15
17
|
}).then(
|
|
16
18
|
response => response.json()
|
|
17
19
|
).then(({estimatedArrivals}) => {
|
|
@@ -27,8 +29,9 @@ module.exports = {
|
|
|
27
29
|
})
|
|
28
30
|
),
|
|
29
31
|
fetchStopEtas: ( stopId ) => (
|
|
30
|
-
fetch(`https://rt.data.gov.hk/v1/transport/batch/stop-eta/NLB/${stopId}`, {
|
|
31
|
-
|
|
32
|
+
fetch(`https://rt.data.gov.hk/v1/transport/batch/stop-eta/NLB/${stopId}`, {
|
|
33
|
+
cache: utils.isSafari ? 'default' : 'no-store'
|
|
34
|
+
}).then( response => {
|
|
32
35
|
if (response.ok)
|
|
33
36
|
return response.json()
|
|
34
37
|
// special handle for NLB API
|
package/Nwfb.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
const utils = require('./utils')
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
co: 'nwfb',
|
|
3
5
|
fetchEtas: ({stopId, route, bound }) => (
|
|
4
|
-
fetch(`https://rt.data.gov.hk//v1/transport/citybus-nwfb/eta/NWFB/${stopId}/${route}`, {
|
|
6
|
+
fetch(`https://rt.data.gov.hk//v1/transport/citybus-nwfb/eta/NWFB/${stopId}/${route}`, {
|
|
7
|
+
cache: utils.isSafari ? 'default' : 'no-store'
|
|
8
|
+
}).then(
|
|
5
9
|
response => response.json()
|
|
6
10
|
).then(({data}) => data.filter(eta => eta.eta && eta.dir === bound).map(e => ({
|
|
7
11
|
eta: e.eta,
|
|
@@ -14,7 +18,9 @@ module.exports = {
|
|
|
14
18
|
)
|
|
15
19
|
),
|
|
16
20
|
fetchStopEtas: ( stopId ) => (
|
|
17
|
-
fetch(`https://rt.data.gov.hk/v1/transport/batch/stop-eta/NWFB/${stopId}`, {
|
|
21
|
+
fetch(`https://rt.data.gov.hk/v1/transport/batch/stop-eta/NWFB/${stopId}`, {
|
|
22
|
+
cache: utils.isSafari ? 'default' : 'no-store'
|
|
23
|
+
}).then(
|
|
18
24
|
response => response.json()
|
|
19
25
|
).then(({data}) => data.map( e => ({
|
|
20
26
|
route: e.route,
|
package/index.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ export type Terminal = {
|
|
|
7
7
|
|
|
8
8
|
export type FreqId = "31" | "287" | "415" | "63" | "319" | "447" | "416" | "480" | "266" | "271" | "272" | "288" | "320" | "448" | "511"
|
|
9
9
|
|
|
10
|
+
export type Freq = {
|
|
11
|
+
[key in FreqId]: {
|
|
12
|
+
[startTime: string]: [string, string] | null
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
export type RouteListEntry = {
|
|
11
17
|
readonly route: string,
|
|
12
18
|
readonly co: Company[],
|
|
@@ -14,11 +20,8 @@ export type RouteListEntry = {
|
|
|
14
20
|
readonly dest: Terminal,
|
|
15
21
|
readonly fares: string[] | null,
|
|
16
22
|
readonly faresHoliday: string[] | null,
|
|
17
|
-
readonly freq:
|
|
18
|
-
|
|
19
|
-
[startTime: string]: string[]
|
|
20
|
-
}
|
|
21
|
-
},
|
|
23
|
+
readonly freq: Freq | null,
|
|
24
|
+
readonly jt: string | null,
|
|
22
25
|
readonly seq: number,
|
|
23
26
|
readonly serviceType: string,
|
|
24
27
|
readonly stops: {
|
|
@@ -52,6 +55,7 @@ export type StopList = Record<string, StopListEntry>
|
|
|
52
55
|
export type StopMap = Record<string, StopTuple[]>
|
|
53
56
|
|
|
54
57
|
export type BusDb = {
|
|
58
|
+
holidays: string[],
|
|
55
59
|
routeList: RouteList,
|
|
56
60
|
stopList: StopList,
|
|
57
61
|
stopMap: StopMap
|
package/index.js
CHANGED
package/package.json
CHANGED
package/utils.js
ADDED