wili 0.6.1 → 0.7.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.de.md +4 -4
- package/README.md +4 -4
- package/lib/wili.mjs +32 -38
- package/package.json +3 -3
- package/types/index.d.ts +25 -25
package/README.de.md
CHANGED
|
@@ -17,9 +17,9 @@ Node Wrapper für die Echtzeitdaten-API der Wiener Linien
|
|
|
17
17
|
Beispielanwendung:
|
|
18
18
|
|
|
19
19
|
```js
|
|
20
|
-
import {
|
|
20
|
+
import { createWienerLinien } from 'wili';
|
|
21
21
|
|
|
22
|
-
const wili =
|
|
22
|
+
const wili = createWienerLinien();
|
|
23
23
|
|
|
24
24
|
const options = {
|
|
25
25
|
relatedLine: ['U2', 'U4', 'U6']
|
|
@@ -48,10 +48,10 @@ try {
|
|
|
48
48
|
**Beispiel**
|
|
49
49
|
|
|
50
50
|
```js
|
|
51
|
-
import {
|
|
51
|
+
import { createWienerLinien } from 'wili';
|
|
52
52
|
import fetch from 'isomorphic-fetch';
|
|
53
53
|
|
|
54
|
-
const wili =
|
|
54
|
+
const wili = createWienerLinien(fetch);
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
## API
|
package/README.md
CHANGED
|
@@ -17,9 +17,9 @@ A Node wrapper for the Wiener Linien public transport API
|
|
|
17
17
|
Example usage in script:
|
|
18
18
|
|
|
19
19
|
```js
|
|
20
|
-
import {
|
|
20
|
+
import { createWienerLinien } from 'wili';
|
|
21
21
|
|
|
22
|
-
const wili =
|
|
22
|
+
const wili = createWienerLinien();
|
|
23
23
|
|
|
24
24
|
const options = {
|
|
25
25
|
relatedLine: ['U2', 'U4', 'U6']
|
|
@@ -48,10 +48,10 @@ try {
|
|
|
48
48
|
**Example**
|
|
49
49
|
|
|
50
50
|
```js
|
|
51
|
-
import {
|
|
51
|
+
import { createWienerLinien } from 'wili';
|
|
52
52
|
import fetch from 'isomorphic-fetch';
|
|
53
53
|
|
|
54
|
-
const wili =
|
|
54
|
+
const wili = createWienerLinien(fetch);
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
## API
|
package/lib/wili.mjs
CHANGED
|
@@ -1,42 +1,22 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (typeof fetch !== "function") {
|
|
6
|
-
throw new TypeError("The supplied fetch parameter is not a function");
|
|
7
|
-
}
|
|
8
|
-
this.#fetch = fetchParam;
|
|
2
|
+
function createWienerLinien(fetchParam = globalThis.fetch) {
|
|
3
|
+
if (typeof fetchParam !== "function") {
|
|
4
|
+
throw new TypeError("The supplied fetch parameter is not a function");
|
|
9
5
|
}
|
|
10
|
-
|
|
11
|
-
* Returns real-time data for a station
|
|
12
|
-
* @param {StringNumbers} rbl - RBL number
|
|
13
|
-
* @param {MonitorOptions} options
|
|
14
|
-
* @returns {object}
|
|
15
|
-
*/
|
|
16
|
-
monitor(rbl, options = {}) {
|
|
6
|
+
async function monitor(rbl, options = {}) {
|
|
17
7
|
const urlParams = {
|
|
18
8
|
...options,
|
|
19
9
|
rbl
|
|
20
10
|
};
|
|
21
|
-
return
|
|
11
|
+
return await apiCall("/monitor", urlParams);
|
|
22
12
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* @param {NewsListOptions} options
|
|
26
|
-
* @returns {object}
|
|
27
|
-
*/
|
|
28
|
-
newsList(options = {}) {
|
|
29
|
-
return this.#apiCall("newsList", options);
|
|
13
|
+
async function newsList(options = {}) {
|
|
14
|
+
return await apiCall("newsList", options);
|
|
30
15
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* @param {TrafficInfoOptions} options
|
|
34
|
-
* @returns {object}
|
|
35
|
-
*/
|
|
36
|
-
trafficInfoList(options = {}) {
|
|
37
|
-
return this.#apiCall("trafficInfoList", options);
|
|
16
|
+
async function trafficInfoList(options = {}) {
|
|
17
|
+
return await apiCall("trafficInfoList", options);
|
|
38
18
|
}
|
|
39
|
-
|
|
19
|
+
function buildUrl(urlPath, urlParams) {
|
|
40
20
|
const searchParams = new URLSearchParams();
|
|
41
21
|
for (const [key, value] of Object.entries(urlParams)) {
|
|
42
22
|
if (Array.isArray(value)) {
|
|
@@ -49,18 +29,32 @@ var WienerLinien = class {
|
|
|
49
29
|
}
|
|
50
30
|
return new URL(`https://www.wienerlinien.at/ogd_realtime/${urlPath}?${searchParams.toString()}`);
|
|
51
31
|
}
|
|
52
|
-
|
|
32
|
+
async function checkStatus(response) {
|
|
53
33
|
if (response.ok) {
|
|
54
|
-
return
|
|
34
|
+
return response;
|
|
55
35
|
} else {
|
|
56
|
-
|
|
36
|
+
throw new Error(response.statusText);
|
|
57
37
|
}
|
|
58
38
|
}
|
|
59
|
-
|
|
60
|
-
const url =
|
|
61
|
-
|
|
39
|
+
async function apiCall(urlPath, urlParams) {
|
|
40
|
+
const url = buildUrl(urlPath, urlParams);
|
|
41
|
+
try {
|
|
42
|
+
const response = await fetchParam(url.href);
|
|
43
|
+
const checkedResponse = await checkStatus(response);
|
|
44
|
+
const json = await checkedResponse.json();
|
|
45
|
+
return json.data;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error(error);
|
|
48
|
+
}
|
|
62
49
|
}
|
|
63
|
-
|
|
50
|
+
return {
|
|
51
|
+
monitor,
|
|
52
|
+
newsList,
|
|
53
|
+
trafficInfoList
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
var WienerLinien = createWienerLinien();
|
|
64
57
|
export {
|
|
65
|
-
WienerLinien
|
|
58
|
+
WienerLinien,
|
|
59
|
+
createWienerLinien
|
|
66
60
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wili",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A Node client for the Wiener Linien public transport API",
|
|
5
5
|
"author": "Jan T. Sott",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"prepack": "npm run build",
|
|
29
29
|
"prepare": "husky install",
|
|
30
30
|
"start": "npm run build -- --watch",
|
|
31
|
-
"test": "uvu tests"
|
|
31
|
+
"test": "uvu -r tsm tests"
|
|
32
32
|
},
|
|
33
33
|
"keywords": [
|
|
34
34
|
"wiener linien",
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
"öpvn",
|
|
38
38
|
"public transport"
|
|
39
39
|
],
|
|
40
|
-
"dependencies": {},
|
|
41
40
|
"devDependencies": {
|
|
42
41
|
"@types/isomorphic-fetch": "^0.0.36",
|
|
43
42
|
"@types/node": "^18.15.5",
|
|
@@ -48,6 +47,7 @@
|
|
|
48
47
|
"husky": "^8.0.3",
|
|
49
48
|
"lint-staged": "^13.2.0",
|
|
50
49
|
"tslib": "^2.5.0",
|
|
50
|
+
"tsm": "^2.3.0",
|
|
51
51
|
"typescript": "^5.0.2",
|
|
52
52
|
"uvu": "^0.5.6"
|
|
53
53
|
},
|
package/types/index.d.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
type StringNumbers = number | string | number[] | string[];
|
|
2
1
|
|
|
3
|
-
declare class WienerLinien {
|
|
4
|
-
constructor(API_KEY?: string);
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
declare namespace Wili {
|
|
4
|
+
function monitor(rbl: StringNumbers, options: MonitorOptions): Promise<Record<string, unknown>>;
|
|
5
|
+
function newsList(options: NewsListOptions): Promise<Record<string, unknown>>;
|
|
6
|
+
function trafficInfoList(options: TrafficInfoOptions): Promise<Record<string, unknown>>;
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
type Fetch = (input: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
|
|
9
|
+
type StringNumbers = number | string | number[] | string[];
|
|
10
|
+
type UrlParams = MonitorOptions | NewsListOptions | TrafficInfoOptions;
|
|
13
11
|
|
|
14
|
-
type MonitorOptions = {
|
|
15
|
-
|
|
16
|
-
}
|
|
12
|
+
type MonitorOptions = {
|
|
13
|
+
activateTrafficInfo?: string | string[];
|
|
14
|
+
}
|
|
17
15
|
|
|
18
|
-
interface MonitorParams extends MonitorOptions {
|
|
19
|
-
|
|
20
|
-
}
|
|
16
|
+
interface MonitorParams extends MonitorOptions {
|
|
17
|
+
rbl?: StringNumbers;
|
|
18
|
+
}
|
|
21
19
|
|
|
22
|
-
type NewsListOptions = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
20
|
+
type NewsListOptions = {
|
|
21
|
+
name?: string | string[];
|
|
22
|
+
relatedLine?: StringNumbers;
|
|
23
|
+
relatedStop?: StringNumbers;
|
|
24
|
+
}
|
|
27
25
|
|
|
28
|
-
type TrafficInfoOptions = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
type TrafficInfoOptions = {
|
|
27
|
+
name?: string | string[];
|
|
28
|
+
relatedLine?: StringNumbers;
|
|
29
|
+
relatedStop?: StringNumbers;
|
|
30
|
+
}
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
export = Wili;
|
|
34
|
+
export as namespace Wili;
|