wili 0.7.0 → 0.8.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 -19
- package/README.md +4 -19
- package/lib/index.cjs +1 -0
- package/lib/index.d.cts +49 -0
- package/lib/index.d.ts +49 -0
- package/lib/index.js +1 -0
- package/package.json +30 -28
- package/types/index.d.ts +40 -31
- package/lib/wili.mjs +0 -60
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
|
+

|
|
6
6
|
|
|
7
7
|
[English](README.md) | **Deutsch**
|
|
8
8
|
|
|
@@ -25,22 +25,7 @@ const options = {
|
|
|
25
25
|
relatedLine: ['U2', 'U4', 'U6']
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
wili.trafficInfoList(options)
|
|
30
|
-
.then( data => {
|
|
31
|
-
console.log(data.trafficInfos);
|
|
32
|
-
})
|
|
33
|
-
.catch( error => {
|
|
34
|
-
console.error(error);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// async/await
|
|
38
|
-
try {
|
|
39
|
-
const data = await wili.trafficInfoList(options);
|
|
40
|
-
console.log(data.trafficInfos);
|
|
41
|
-
} catch (output) {
|
|
42
|
-
console.error(error);
|
|
43
|
-
}
|
|
28
|
+
const { trafficInfos } = await wili.trafficInfoList(options);
|
|
44
29
|
```
|
|
45
30
|
|
|
46
31
|
:warning: Für NodeJS-Versionen unterhalb v18, muss die Klasse mit einer `fetch`-Implementierung instanziert werden.
|
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
|
+

|
|
6
6
|
|
|
7
7
|
**English** | [Deutsch](README.de.md)
|
|
8
8
|
|
|
@@ -25,22 +25,7 @@ const options = {
|
|
|
25
25
|
relatedLine: ['U2', 'U4', 'U6']
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
wili.trafficInfoList(options)
|
|
30
|
-
.then( data => {
|
|
31
|
-
console.log(data.trafficInfos);
|
|
32
|
-
})
|
|
33
|
-
.catch( error => {
|
|
34
|
-
console.error(error);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// async/await
|
|
38
|
-
try {
|
|
39
|
-
const data = await wili.trafficInfoList(options);
|
|
40
|
-
console.log(data.trafficInfos);
|
|
41
|
-
} catch (output) {
|
|
42
|
-
console.error(error);
|
|
43
|
-
}
|
|
28
|
+
const { trafficInfos } = await wili.trafficInfoList(options);
|
|
44
29
|
```
|
|
45
30
|
|
|
46
31
|
:warning: For NodeJS versions lower than v18, the class needs to be instantiated with a `fetch`-implementation
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e=globalThis.fetch){if(typeof e!=`function`)throw TypeError(`The supplied fetch parameter is not a function`);async function t(e,t={}){return await o(`/monitor`,{...t,rbl:e})}async function n(e={}){return await o(`newsList`,e)}async function r(e={}){return await o(`trafficInfoList`,e)}function i(e,t){let n=new URLSearchParams;for(let[e,r]of Object.entries(t))if(Array.isArray(r))for(let t of r)n.append(e,String(t));else n.set(e,String(r));return new URL(`https://www.wienerlinien.at/ogd_realtime/${e}?${n.toString()}`)}async function a(e){if(e.ok)return e;throw Error(`HTTP ${e.status}: ${e.statusText} (${e.url})`)}async function o(t,n){return(await(await a(await e(i(t,n).href))).json()).data}return{monitor:t,newsList:n,trafficInfoList:r}}exports.createWienerLinien=e;
|
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region types/index.d.ts
|
|
2
|
+
declare namespace Wili {
|
|
3
|
+
type Fetch = (input: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
|
|
4
|
+
type StringNumbers = number | string | number[] | string[];
|
|
5
|
+
type UrlParams = MonitorOptions | NewsListOptions | TrafficInfoOptions;
|
|
6
|
+
type MonitorOptions = {
|
|
7
|
+
activateTrafficInfo?: string | string[];
|
|
8
|
+
};
|
|
9
|
+
interface MonitorParams extends MonitorOptions {
|
|
10
|
+
rbl?: StringNumbers;
|
|
11
|
+
}
|
|
12
|
+
type NewsListOptions = {
|
|
13
|
+
name?: string | string[];
|
|
14
|
+
relatedLine?: StringNumbers;
|
|
15
|
+
relatedStop?: StringNumbers;
|
|
16
|
+
};
|
|
17
|
+
type TrafficInfoOptions = {
|
|
18
|
+
name?: string | string[];
|
|
19
|
+
relatedLine?: StringNumbers;
|
|
20
|
+
relatedStop?: StringNumbers;
|
|
21
|
+
};
|
|
22
|
+
type MonitorResponse = {
|
|
23
|
+
monitors: unknown[];
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
};
|
|
26
|
+
type NewsListResponse = {
|
|
27
|
+
pois: unknown[];
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
};
|
|
30
|
+
type TrafficInfoListResponse = {
|
|
31
|
+
trafficInfos: unknown[];
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/index.d.ts
|
|
37
|
+
/**
|
|
38
|
+
* Creates an instance of the WienerLinien API client.
|
|
39
|
+
* @param {function} fetchParam - The fetch function to use for making HTTP requests.
|
|
40
|
+
* @throws {TypeError} - If the supplied fetch parameter is not a function.
|
|
41
|
+
* @returns {Object} - The WienerLinien API client.
|
|
42
|
+
*/
|
|
43
|
+
declare function createWienerLinien(fetchParam?: typeof fetch): {
|
|
44
|
+
monitor: (rbl: Wili.StringNumbers, options?: {}) => Promise<Wili.MonitorResponse>;
|
|
45
|
+
newsList: (options?: {}) => Promise<Wili.NewsListResponse>;
|
|
46
|
+
trafficInfoList: (options?: {}) => Promise<Wili.TrafficInfoListResponse>;
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { createWienerLinien };
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region types/index.d.ts
|
|
2
|
+
declare namespace Wili {
|
|
3
|
+
type Fetch = (input: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
|
|
4
|
+
type StringNumbers = number | string | number[] | string[];
|
|
5
|
+
type UrlParams = MonitorOptions | NewsListOptions | TrafficInfoOptions;
|
|
6
|
+
type MonitorOptions = {
|
|
7
|
+
activateTrafficInfo?: string | string[];
|
|
8
|
+
};
|
|
9
|
+
interface MonitorParams extends MonitorOptions {
|
|
10
|
+
rbl?: StringNumbers;
|
|
11
|
+
}
|
|
12
|
+
type NewsListOptions = {
|
|
13
|
+
name?: string | string[];
|
|
14
|
+
relatedLine?: StringNumbers;
|
|
15
|
+
relatedStop?: StringNumbers;
|
|
16
|
+
};
|
|
17
|
+
type TrafficInfoOptions = {
|
|
18
|
+
name?: string | string[];
|
|
19
|
+
relatedLine?: StringNumbers;
|
|
20
|
+
relatedStop?: StringNumbers;
|
|
21
|
+
};
|
|
22
|
+
type MonitorResponse = {
|
|
23
|
+
monitors: unknown[];
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
};
|
|
26
|
+
type NewsListResponse = {
|
|
27
|
+
pois: unknown[];
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
};
|
|
30
|
+
type TrafficInfoListResponse = {
|
|
31
|
+
trafficInfos: unknown[];
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/index.d.ts
|
|
37
|
+
/**
|
|
38
|
+
* Creates an instance of the WienerLinien API client.
|
|
39
|
+
* @param {function} fetchParam - The fetch function to use for making HTTP requests.
|
|
40
|
+
* @throws {TypeError} - If the supplied fetch parameter is not a function.
|
|
41
|
+
* @returns {Object} - The WienerLinien API client.
|
|
42
|
+
*/
|
|
43
|
+
declare function createWienerLinien(fetchParam?: typeof fetch): {
|
|
44
|
+
monitor: (rbl: Wili.StringNumbers, options?: {}) => Promise<Wili.MonitorResponse>;
|
|
45
|
+
newsList: (options?: {}) => Promise<Wili.NewsListResponse>;
|
|
46
|
+
trafficInfoList: (options?: {}) => Promise<Wili.TrafficInfoListResponse>;
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { createWienerLinien };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e=globalThis.fetch){if(typeof e!=`function`)throw TypeError(`The supplied fetch parameter is not a function`);async function t(e,t={}){return await o(`/monitor`,{...t,rbl:e})}async function n(e={}){return await o(`newsList`,e)}async function r(e={}){return await o(`trafficInfoList`,e)}function i(e,t){let n=new URLSearchParams;for(let[e,r]of Object.entries(t))if(Array.isArray(r))for(let t of r)n.append(e,String(t));else n.set(e,String(r));return new URL(`https://www.wienerlinien.at/ogd_realtime/${e}?${n.toString()}`)}async function a(e){if(e.ok)return e;throw Error(`HTTP ${e.status}: ${e.statusText} (${e.url})`)}async function o(t,n){return(await(await a(await e(i(t,n).href))).json()).data}return{monitor:t,newsList:n,trafficInfoList:r}}export{e as createWienerLinien};
|
package/package.json
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wili",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
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
|
-
"exports":
|
|
9
|
-
|
|
8
|
+
"exports": {
|
|
9
|
+
"types": "./lib/index.d.ts",
|
|
10
|
+
"import": "./lib/index.js"
|
|
11
|
+
},
|
|
12
|
+
"main": "./lib/index.cjs",
|
|
13
|
+
"types": "./lib/index.d.cts",
|
|
10
14
|
"engines": {
|
|
11
|
-
"node": ">=
|
|
15
|
+
"node": ">=20"
|
|
12
16
|
},
|
|
13
17
|
"files": [
|
|
14
18
|
"lib/",
|
|
@@ -18,17 +22,7 @@
|
|
|
18
22
|
],
|
|
19
23
|
"repository": {
|
|
20
24
|
"type": "git",
|
|
21
|
-
"url": "https://github.com/idleberg/node-wili.git"
|
|
22
|
-
},
|
|
23
|
-
"scripts": {
|
|
24
|
-
"build": "esbuild src/index.ts --bundle --platform=node --outfile=lib/wili.mjs --format=esm --external:isomorphic-fetch --external:query-string",
|
|
25
|
-
"dev": "npm run start",
|
|
26
|
-
"lint:fix": "eslint --fix ./src",
|
|
27
|
-
"lint": "eslint ./src",
|
|
28
|
-
"prepack": "npm run build",
|
|
29
|
-
"prepare": "husky install",
|
|
30
|
-
"start": "npm run build -- --watch",
|
|
31
|
-
"test": "uvu -r tsm tests"
|
|
25
|
+
"url": "git+https://github.com/idleberg/node-wili.git"
|
|
32
26
|
},
|
|
33
27
|
"keywords": [
|
|
34
28
|
"wiener linien",
|
|
@@ -38,20 +32,28 @@
|
|
|
38
32
|
"public transport"
|
|
39
33
|
],
|
|
40
34
|
"devDependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
35
|
+
"@commitlint/cli": "^20.1.0",
|
|
36
|
+
"@commitlint/config-conventional": "^20.0.0",
|
|
37
|
+
"@idleberg/configs": "^0.3.1",
|
|
38
|
+
"@types/node": "^24.8.1",
|
|
39
|
+
"concurrently": "^9.2.1",
|
|
40
|
+
"execa": "^9.6.0",
|
|
41
|
+
"knip": "^5.65.0",
|
|
42
|
+
"np": "^10.2.0",
|
|
43
|
+
"publint": "^0.3.14",
|
|
44
|
+
"tsdown": "^0.15.6",
|
|
50
45
|
"tsm": "^2.3.0",
|
|
51
|
-
"typescript": "^5.
|
|
46
|
+
"typescript": "^5.9.3",
|
|
52
47
|
"uvu": "^0.5.6"
|
|
53
48
|
},
|
|
54
|
-
"
|
|
55
|
-
"
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsdown",
|
|
51
|
+
"dev": "tsdown --watch",
|
|
52
|
+
"lint": "concurrently --prefix-colors blue,green,magenta npm:lint:*",
|
|
53
|
+
"lint:biome": "biome check",
|
|
54
|
+
"lint:knip": "knip --cache --production",
|
|
55
|
+
"lint:publint": "publint",
|
|
56
|
+
"publish:npm": "np --any-branch",
|
|
57
|
+
"test": "uvu -r tsm tests"
|
|
56
58
|
}
|
|
57
|
-
}
|
|
59
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,34 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
1
|
declare namespace Wili {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
2
|
+
type Fetch = (input: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
|
|
3
|
+
type StringNumbers = number | string | number[] | string[];
|
|
4
|
+
type UrlParams = MonitorOptions | NewsListOptions | TrafficInfoOptions;
|
|
5
|
+
|
|
6
|
+
type MonitorOptions = {
|
|
7
|
+
activateTrafficInfo?: string | string[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
interface MonitorParams extends MonitorOptions {
|
|
11
|
+
rbl?: StringNumbers;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type NewsListOptions = {
|
|
15
|
+
name?: string | string[];
|
|
16
|
+
relatedLine?: StringNumbers;
|
|
17
|
+
relatedStop?: StringNumbers;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type TrafficInfoOptions = {
|
|
21
|
+
name?: string | string[];
|
|
22
|
+
relatedLine?: StringNumbers;
|
|
23
|
+
relatedStop?: StringNumbers;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type MonitorResponse = {
|
|
27
|
+
monitors: unknown[];
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type NewsListResponse = {
|
|
32
|
+
pois: unknown[];
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type TrafficInfoListResponse = {
|
|
37
|
+
trafficInfos: unknown[];
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
};
|
|
31
40
|
}
|
|
32
41
|
|
|
33
|
-
export
|
|
34
|
-
export
|
|
42
|
+
export default Wili;
|
|
43
|
+
export { Wili };
|
package/lib/wili.mjs
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
function createWienerLinien(fetchParam = globalThis.fetch) {
|
|
3
|
-
if (typeof fetchParam !== "function") {
|
|
4
|
-
throw new TypeError("The supplied fetch parameter is not a function");
|
|
5
|
-
}
|
|
6
|
-
async function monitor(rbl, options = {}) {
|
|
7
|
-
const urlParams = {
|
|
8
|
-
...options,
|
|
9
|
-
rbl
|
|
10
|
-
};
|
|
11
|
-
return await apiCall("/monitor", urlParams);
|
|
12
|
-
}
|
|
13
|
-
async function newsList(options = {}) {
|
|
14
|
-
return await apiCall("newsList", options);
|
|
15
|
-
}
|
|
16
|
-
async function trafficInfoList(options = {}) {
|
|
17
|
-
return await apiCall("trafficInfoList", options);
|
|
18
|
-
}
|
|
19
|
-
function buildUrl(urlPath, urlParams) {
|
|
20
|
-
const searchParams = new URLSearchParams();
|
|
21
|
-
for (const [key, value] of Object.entries(urlParams)) {
|
|
22
|
-
if (Array.isArray(value)) {
|
|
23
|
-
for (const item of value) {
|
|
24
|
-
searchParams.append(key, String(item));
|
|
25
|
-
}
|
|
26
|
-
} else {
|
|
27
|
-
searchParams.set(key, String(value));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return new URL(`https://www.wienerlinien.at/ogd_realtime/${urlPath}?${searchParams.toString()}`);
|
|
31
|
-
}
|
|
32
|
-
async function checkStatus(response) {
|
|
33
|
-
if (response.ok) {
|
|
34
|
-
return response;
|
|
35
|
-
} else {
|
|
36
|
-
throw new Error(response.statusText);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
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
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
monitor,
|
|
52
|
-
newsList,
|
|
53
|
-
trafficInfoList
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
var WienerLinien = createWienerLinien();
|
|
57
|
-
export {
|
|
58
|
-
WienerLinien,
|
|
59
|
-
createWienerLinien
|
|
60
|
-
};
|