wili 0.6.1 → 0.7.1
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 +7 -7
- package/README.md +7 -7
- package/lib/index.d.ts +11 -0
- package/lib/wili.mjs +96 -62
- package/lib/wili.mjs.map +1 -0
- package/package.json +16 -13
- package/types/index.d.ts +29 -29
package/README.de.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# wili
|
|
2
2
|
|
|
3
|
-
[](https://github.com/idleberg/node-wili/blob/main/LICENSE)
|
|
4
|
+
[](https://www.npmjs.org/package/wili)
|
|
5
|
+
[](https://github.com/idleberg/node-wili/actions)
|
|
6
6
|
|
|
7
7
|
[English](README.md) | **Deutsch**
|
|
8
8
|
|
|
@@ -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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# wili
|
|
2
2
|
|
|
3
|
-
[](https://github.com/idleberg/node-wili/blob/main/LICENSE)
|
|
4
|
+
[](https://www.npmjs.org/package/wili)
|
|
5
|
+
[](https://github.com/idleberg/node-wili/actions)
|
|
6
6
|
|
|
7
7
|
**English** | [Deutsch](README.de.md)
|
|
8
8
|
|
|
@@ -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/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an instance of the WienerLinien API client.
|
|
3
|
+
* @param {function} fetchParam - The fetch function to use for making HTTP requests.
|
|
4
|
+
* @throws {TypeError} - If the supplied fetch parameter is not a function.
|
|
5
|
+
* @returns {Object} - The WienerLinien API client.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createWienerLinien(fetchParam?: typeof fetch): {
|
|
8
|
+
monitor: (rbl: Wili.StringNumbers, options?: {}) => Promise<any>;
|
|
9
|
+
newsList: (options?: {}) => Promise<any>;
|
|
10
|
+
trafficInfoList: (options?: {}) => Promise<any>;
|
|
11
|
+
};
|
package/lib/wili.mjs
CHANGED
|
@@ -1,66 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Creates an instance of the WienerLinien API client.
|
|
3
|
+
* @param {function} fetchParam - The fetch function to use for making HTTP requests.
|
|
4
|
+
* @throws {TypeError} - If the supplied fetch parameter is not a function.
|
|
5
|
+
* @returns {Object} - The WienerLinien API client.
|
|
6
|
+
*/
|
|
7
|
+
function createWienerLinien(fetchParam = globalThis.fetch) {
|
|
8
|
+
if (typeof fetchParam !== 'function') {
|
|
9
|
+
throw new TypeError('The supplied fetch parameter is not a function');
|
|
7
10
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Returns real-time data for a station.
|
|
13
|
+
* @param {string} rbl - The RBL number.
|
|
14
|
+
* @param {Object} options - The monitor options.
|
|
15
|
+
* @returns {Promise<Object>} - The real-time data for the station.
|
|
16
|
+
*/
|
|
17
|
+
async function monitor(rbl, options = {}) {
|
|
18
|
+
const urlParams = {
|
|
19
|
+
...options,
|
|
20
|
+
rbl: rbl
|
|
21
|
+
};
|
|
22
|
+
return await apiCall('/monitor', urlParams);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns news, elevator maintenance, and other information.
|
|
26
|
+
* @param {Object} options - The news list options.
|
|
27
|
+
* @returns {Promise<Object>} - The news and information.
|
|
28
|
+
*/
|
|
29
|
+
async function newsList(options = {}) {
|
|
30
|
+
return await apiCall('newsList', options);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns interruptions of operations and elevator outages.
|
|
34
|
+
* @param {Object} options - The traffic info options.
|
|
35
|
+
* @returns {Promise<Object>} - The traffic information.
|
|
36
|
+
*/
|
|
37
|
+
async function trafficInfoList(options = {}) {
|
|
38
|
+
return await apiCall('trafficInfoList', options);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Builds the URL for making API requests.
|
|
42
|
+
* @param {string} urlPath - The URL path.
|
|
43
|
+
* @param {Object} urlParams - The URL parameters.
|
|
44
|
+
* @returns {URL} - The constructed URL.
|
|
45
|
+
*/
|
|
46
|
+
function buildUrl(urlPath, urlParams) {
|
|
47
|
+
const searchParams = new URLSearchParams();
|
|
48
|
+
for (const [key, value] of Object.entries(urlParams)) {
|
|
49
|
+
if (Array.isArray(value)) {
|
|
50
|
+
for (const item of value) {
|
|
51
|
+
searchParams.append(key, String(item));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
searchParams.set(key, String(value));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return new URL(`https://www.wienerlinien.at/ogd_realtime/${urlPath}?${searchParams.toString()}`);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Checks the response status and throws an error if it's not OK.
|
|
62
|
+
* @param {Response} response - The HTTP response.
|
|
63
|
+
* @returns {Promise<Response>} - The resolved response if the status is OK.
|
|
64
|
+
* @throws {Error} - If the response status is not OK.
|
|
65
|
+
*/
|
|
66
|
+
async function checkStatus(response) {
|
|
67
|
+
if (response.ok) {
|
|
68
|
+
return response;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
throw new Error(response.statusText);
|
|
45
72
|
}
|
|
46
|
-
} else {
|
|
47
|
-
searchParams.set(key, String(value));
|
|
48
|
-
}
|
|
49
73
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Makes an API call to the specified URL path with the given parameters.
|
|
76
|
+
* @param {string} urlPath - The URL path.
|
|
77
|
+
* @param {Object} urlParams - The URL parameters.
|
|
78
|
+
* @returns {Promise<Object>} - The API response data.
|
|
79
|
+
*/
|
|
80
|
+
async function apiCall(urlPath, urlParams) {
|
|
81
|
+
const url = buildUrl(urlPath, urlParams);
|
|
82
|
+
try {
|
|
83
|
+
const response = await fetchParam(url.href);
|
|
84
|
+
const checkedResponse = await checkStatus(response);
|
|
85
|
+
const json = await checkedResponse.json();
|
|
86
|
+
return json.data;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error(error);
|
|
90
|
+
}
|
|
57
91
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
92
|
+
return {
|
|
93
|
+
monitor,
|
|
94
|
+
newsList,
|
|
95
|
+
trafficInfoList
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { createWienerLinien };
|
|
100
|
+
//# sourceMappingURL=wili.mjs.map
|
package/lib/wili.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wili.mjs","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;AAKG;SACa,kBAAkB,CAAC,UAAU,GAAG,UAAU,CAAC,KAAK,EAAA;AAC9D,IAAA,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE;AACpC,QAAA,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;AACvE,KAAA;AAED;;;;;AAKG;AACH,IAAA,eAAe,OAAO,CAAC,GAAuB,EAAE,OAAO,GAAG,EAAE,EAAA;AAC1D,QAAA,MAAM,SAAS,GAAuB;AACpC,YAAA,GAAG,OAAO;AACV,YAAA,GAAG,EAAE,GAAG;SACT,CAAC;AAEF,QAAA,OAAO,MAAM,OA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;AACtC,SAAA;KACF;AAED;;;;;AAKG;AACH,IAAA,eAAe,OAAO,CAAC,OAAe,EAAE,SAAyB,EAAA;QAC/D,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAEzC,IAAI;YACF,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC5C,YAAA,MAAM,eAAe,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC,CAAC;AACpD,YAAA,MAAM,IAAI,GAAG,MAAM,eAAe,CAAC,IAAI,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC,IAAI,CAAC;AAClB,SAAA;AAAC,QAAA,OAAO,KAAK,EAAE;AACd,YAAA,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACtB,SAAA;KACF;IAED,OAAO;QACL,OAAO;QACP,QAAQ;QACR,eAAe;KAChB,CAAC;AACJ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wili",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "A Node client for the Wiener Linien public transport API",
|
|
5
5
|
"author": "Jan T. Sott",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
8
|
+
"typings": "./types",
|
|
9
|
+
"exports": {
|
|
10
|
+
"import": "./lib/wili.mjs"
|
|
11
|
+
},
|
|
10
12
|
"engines": {
|
|
11
13
|
"node": ">=16.13 || >=18"
|
|
12
14
|
},
|
|
@@ -21,14 +23,14 @@
|
|
|
21
23
|
"url": "https://github.com/idleberg/node-wili.git"
|
|
22
24
|
},
|
|
23
25
|
"scripts": {
|
|
24
|
-
"build": "
|
|
26
|
+
"build": "rollup -c",
|
|
25
27
|
"dev": "npm run start",
|
|
26
28
|
"lint:fix": "eslint --fix ./src",
|
|
27
29
|
"lint": "eslint ./src",
|
|
28
30
|
"prepack": "npm run build",
|
|
29
31
|
"prepare": "husky install",
|
|
30
32
|
"start": "npm run build -- --watch",
|
|
31
|
-
"test": "uvu tests"
|
|
33
|
+
"test": "uvu -r tsm tests"
|
|
32
34
|
},
|
|
33
35
|
"keywords": [
|
|
34
36
|
"wiener linien",
|
|
@@ -37,18 +39,19 @@
|
|
|
37
39
|
"öpvn",
|
|
38
40
|
"public transport"
|
|
39
41
|
],
|
|
40
|
-
"dependencies": {},
|
|
41
42
|
"devDependencies": {
|
|
43
|
+
"@rollup/plugin-typescript": "^11.1.2",
|
|
42
44
|
"@types/isomorphic-fetch": "^0.0.36",
|
|
43
45
|
"@types/node": "^18.15.5",
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
45
|
-
"@typescript-eslint/parser": "^
|
|
46
|
-
"
|
|
47
|
-
"eslint": "^8.36.0",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
|
47
|
+
"@typescript-eslint/parser": "^6.2.1",
|
|
48
|
+
"eslint": "^8.46.0",
|
|
48
49
|
"husky": "^8.0.3",
|
|
49
|
-
"lint-staged": "^13.2.
|
|
50
|
-
"
|
|
51
|
-
"
|
|
50
|
+
"lint-staged": "^13.2.3",
|
|
51
|
+
"rollup": "^3.27.0",
|
|
52
|
+
"tslib": "^2.6.1",
|
|
53
|
+
"tsm": "^2.3.0",
|
|
54
|
+
"typescript": "^5.1.6",
|
|
52
55
|
"uvu": "^0.5.6"
|
|
53
56
|
},
|
|
54
57
|
"lint-staged": {
|
package/types/index.d.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare class WienerLinien {
|
|
4
|
-
constructor(API_KEY?: string);
|
|
5
|
-
|
|
1
|
+
declare namespace Wili {
|
|
2
|
+
function createWienerLinien(fetchParam?: (input: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>): {
|
|
6
3
|
monitor(rbl: StringNumbers, options: MonitorOptions): Promise<Record<string, unknown>>;
|
|
7
4
|
newsList(options: NewsListOptions): Promise<Record<string, unknown>>;
|
|
8
5
|
trafficInfoList(options: TrafficInfoOptions): Promise<Record<string, unknown>>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type Fetch = (input: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
|
|
9
|
+
type StringNumbers = number | string | number[] | string[];
|
|
10
|
+
type UrlParams = MonitorOptions | NewsListOptions | TrafficInfoOptions;
|
|
11
|
+
|
|
12
|
+
type MonitorOptions = {
|
|
13
|
+
activateTrafficInfo?: string | string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface MonitorParams extends MonitorOptions {
|
|
17
|
+
rbl?: StringNumbers;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type NewsListOptions = {
|
|
21
|
+
name?: string | string[];
|
|
22
|
+
relatedLine?: StringNumbers;
|
|
23
|
+
relatedStop?: StringNumbers;
|
|
24
|
+
}
|
|
25
|
+
|
|
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;
|