hk-bus-eta 1.9.3 → 2.0.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/README.md CHANGED
@@ -1,4 +1,118 @@
1
1
  # HK Bus ETA
2
-
3
- It's a npm package for querying bus ETA (Estimated Time of Arrival) in Hong Kong. The ETA data structure is based on [hkbus/hk-bus-crawling](https://github.com/hkbus/hk-bus-crawling) and a live demo is in [chunlaw/hk-independent-bus-eta](https://chunlaw.github.io/hk-independent-bus-eta).
4
2
 
3
+ Bus ETAs in Hong Kong is now available as open data in Hong Kong, while there is no format normalization across different transport provider. This package is a js package (typescript supported) for querying normalized public traffic ETA (Estimated Time of Arrival) in Hong Kong. The ETA data structure is based on [hkbus/hk-bus-crawling](https://github.com/hkbus/hk-bus-crawling) and a well-established open-source project is known as [hkbus.app](https://hkbus.app/).
4
+
5
+ ## Demo
6
+
7
+ Live demo is available [here](https://hk-bus-eta.chunlaw.io/).
8
+
9
+ ## Install
10
+
11
+ `npm install hk-bus-eta`
12
+ or
13
+ `yarn add hk-bus-eta`
14
+
15
+
16
+ ## Usage
17
+
18
+ __Crawling traffic database:__
19
+ ```ts
20
+ import { fetchEtaObj } from "hk-bus-eta";
21
+ import type { BusDb } from "hk-bus-eta";
22
+
23
+ fetchEtaDb().then((db: BusDb) => {
24
+ console.log(db)
25
+ })
26
+ ```
27
+
28
+ __Crawling ETA__
29
+ ```ts
30
+ import { fetchEtas } from "hk-bus-eta";
31
+ import tyep { Eta } from "hk-bus-eta";
32
+
33
+ // busDb is the BusDb object fetched by fetchEtaObj
34
+
35
+ fetchEtas({
36
+ ...busDb.routeList["1+1+CHUK YUEN ESTATE+STAR FERRY"],
37
+ seq: 0,
38
+ language: "en",
39
+ }).then(etas => {
40
+ console.log(etas)
41
+ })
42
+ ```
43
+
44
+ ## Data Structure
45
+ The data structure of _EtaDb_ is as follows:
46
+ ```ts
47
+ {
48
+ holidays: string[];
49
+ routeList: {
50
+ [routeId: string]: {
51
+ route: string,
52
+ co: Company[],
53
+ orig: {
54
+ en: string,
55
+ zh: string
56
+ },
57
+ dest: {
58
+ en: string,
59
+ zh: string
60
+ },
61
+ fares: string[] | null,
62
+ faresHoliday: string[] | null,
63
+ freq: {
64
+ [type: string]: {
65
+ [startTime: string]: [string, string] | null
66
+ }
67
+ } | null,
68
+ jt: string | null,
69
+ seq: number,
70
+ serviceType: string,
71
+ stops: {
72
+ [company: string]: string[]
73
+ },
74
+ bound: {
75
+ [company: string]: "O" | "I" | "OI" | "IO"
76
+ },
77
+ gtfsId: string,
78
+ nlbId: string
79
+ }
80
+ }
81
+ stopList: {
82
+ [stopId: string]: {
83
+ location: {
84
+ lat: number,
85
+ lng: number,
86
+ },
87
+ name: {
88
+ en: string,
89
+ zh: string
90
+ }
91
+ }
92
+ }
93
+ stopMap: {
94
+ [stopId: string]: Array<{
95
+ [company: string]: string
96
+ }>
97
+ }
98
+ }
99
+ ```
100
+
101
+ The data structure of _Eta_ is as follows:
102
+ ```ts
103
+ {
104
+ eta: string,
105
+ remark: {
106
+ zh: string,
107
+ en: string
108
+ },
109
+ co: string
110
+ }
111
+ ```
112
+
113
+ ## Contribute
114
+ Project owner [chunlaw](https://github.com/chunlaw) is the initiator of the whole project. Everyone is welcome to contribute.
115
+
116
+ ## License
117
+
118
+ GPL-3.0 license
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type Company = "kmb" | "nlb" | "ctb" | "nwfb" | 'lrtfeeder' | 'gmb' | 'lightRail' | 'mtr'
1
+ export type Company = "kmb" | "nlb" | "ctb" | 'lrtfeeder' | 'gmb' | 'lightRail' | 'mtr'
2
2
 
3
3
  export type Terminal = {
4
4
  en: string,
@@ -55,7 +55,7 @@ export type StopList = Record<string, StopListEntry>
55
55
 
56
56
  export type StopMap = Record<string, StopTuple[]>
57
57
 
58
- export type BusDb = {
58
+ export type EtaDb = {
59
59
  holidays: string[],
60
60
  routeList: RouteList,
61
61
  stopList: StopList,
@@ -73,6 +73,6 @@ export type Eta = {
73
73
 
74
74
  export declare function fetchEtas(route: RouteListEntry & {seq: number, language: "zh" | "en"}): Promise<Eta[]>
75
75
 
76
- export declare function fetchEtaObj(): Promise<BusDb>
76
+ export declare function fetchEtaDb(): Promise<EtaDb>
77
77
 
78
- export declare function fetchEtaObjMd5(): Promise<string>
78
+ export declare function fetchEtaDbMd5(): Promise<string>
package/index.js CHANGED
@@ -44,6 +44,6 @@ module.exports = {
44
44
  return []
45
45
  }
46
46
  },
47
- fetchEtaObj: () => fetch("https://hkbus.github.io/hk-bus-crawling/routeFareList.min.json").then(r => r.json()),
48
- fetchEtaObjMd5: () => fetch('https://hkbus.github.io/hk-bus-crawling/routeFareList.md5').then(r => r.text())
47
+ fetchEtaDb: () => fetch("https://hkbus.github.io/hk-bus-crawling/routeFareList.min.json").then(r => r.json()),
48
+ fetchEtaDbMd5: () => fetch('https://hkbus.github.io/hk-bus-crawling/routeFareList.md5').then(r => r.text())
49
49
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hk-bus-eta",
3
- "version": "1.9.3",
4
- "description": "Query the ETA (Estimated Time of Arrival) of HK Bus/Minibus/Lightrail",
3
+ "version": "2.0.0",
4
+ "description": "Query the ETA (Estimated Time of Arrival) of HK Bus/Minibus/MTR/Lightrail",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "node test.js"