wili 0.7.1 → 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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![License](https://img.shields.io/github/license/idleberg/node-wili?color=blue&style=for-the-badge)](https://github.com/idleberg/node-wili/blob/main/LICENSE)
4
4
  [![Version](https://img.shields.io/npm/v/wili?style=for-the-badge)](https://www.npmjs.org/package/wili)
5
- [![Build](https://img.shields.io/github/actions/workflow/status/idleberg/node-wili/default.yml?style=for-the-badge)](https://github.com/idleberg/node-wili/actions)
5
+ ![GitHub branch check runs](https://img.shields.io/github/check-runs/idleberg/node-wili/main?style=for-the-badge)
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
- // Promise API
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![License](https://img.shields.io/github/license/idleberg/node-wili?color=blue&style=for-the-badge)](https://github.com/idleberg/node-wili/blob/main/LICENSE)
4
4
  [![Version](https://img.shields.io/npm/v/wili?style=for-the-badge)](https://www.npmjs.org/package/wili)
5
- [![Build](https://img.shields.io/github/actions/workflow/status/idleberg/node-wili/default.yml?style=for-the-badge)](https://github.com/idleberg/node-wili/actions)
5
+ ![GitHub branch check runs](https://img.shields.io/github/check-runs/idleberg/node-wili/main?style=for-the-badge)
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
- // Promise API
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;
@@ -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 CHANGED
@@ -1,11 +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
1
37
  /**
2
38
  * Creates an instance of the WienerLinien API client.
3
39
  * @param {function} fetchParam - The fetch function to use for making HTTP requests.
4
40
  * @throws {TypeError} - If the supplied fetch parameter is not a function.
5
41
  * @returns {Object} - The WienerLinien API client.
6
42
  */
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>;
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>;
11
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,16 +1,18 @@
1
1
  {
2
2
  "name": "wili",
3
- "version": "0.7.1",
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
- "typings": "./types",
9
8
  "exports": {
10
- "import": "./lib/wili.mjs"
9
+ "types": "./lib/index.d.ts",
10
+ "import": "./lib/index.js"
11
11
  },
12
+ "main": "./lib/index.cjs",
13
+ "types": "./lib/index.d.cts",
12
14
  "engines": {
13
- "node": ">=16.13 || >=18"
15
+ "node": ">=20"
14
16
  },
15
17
  "files": [
16
18
  "lib/",
@@ -20,17 +22,7 @@
20
22
  ],
21
23
  "repository": {
22
24
  "type": "git",
23
- "url": "https://github.com/idleberg/node-wili.git"
24
- },
25
- "scripts": {
26
- "build": "rollup -c",
27
- "dev": "npm run start",
28
- "lint:fix": "eslint --fix ./src",
29
- "lint": "eslint ./src",
30
- "prepack": "npm run build",
31
- "prepare": "husky install",
32
- "start": "npm run build -- --watch",
33
- "test": "uvu -r tsm tests"
25
+ "url": "git+https://github.com/idleberg/node-wili.git"
34
26
  },
35
27
  "keywords": [
36
28
  "wiener linien",
@@ -40,21 +32,28 @@
40
32
  "public transport"
41
33
  ],
42
34
  "devDependencies": {
43
- "@rollup/plugin-typescript": "^11.1.2",
44
- "@types/isomorphic-fetch": "^0.0.36",
45
- "@types/node": "^18.15.5",
46
- "@typescript-eslint/eslint-plugin": "^6.2.1",
47
- "@typescript-eslint/parser": "^6.2.1",
48
- "eslint": "^8.46.0",
49
- "husky": "^8.0.3",
50
- "lint-staged": "^13.2.3",
51
- "rollup": "^3.27.0",
52
- "tslib": "^2.6.1",
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",
53
45
  "tsm": "^2.3.0",
54
- "typescript": "^5.1.6",
46
+ "typescript": "^5.9.3",
55
47
  "uvu": "^0.5.6"
56
48
  },
57
- "lint-staged": {
58
- "*.ts": "eslint --cache --fix"
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"
59
58
  }
60
- }
59
+ }
package/types/index.d.ts CHANGED
@@ -1,34 +1,43 @@
1
1
  declare namespace Wili {
2
- function createWienerLinien(fetchParam?: (input: URL | RequestInfo, init?: RequestInit | undefined) => Promise<Response>): {
3
- monitor(rbl: StringNumbers, options: MonitorOptions): Promise<Record<string, unknown>>;
4
- newsList(options: NewsListOptions): Promise<Record<string, unknown>>;
5
- trafficInfoList(options: TrafficInfoOptions): Promise<Record<string, unknown>>;
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
- }
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 = Wili;
34
- export as namespace Wili;
42
+ export default Wili;
43
+ export { Wili };
package/lib/wili.mjs DELETED
@@ -1,100 +0,0 @@
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');
10
- }
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);
72
- }
73
- }
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
- }
91
- }
92
- return {
93
- monitor,
94
- newsList,
95
- trafficInfoList
96
- };
97
- }
98
-
99
- export { createWienerLinien };
100
- //# sourceMappingURL=wili.mjs.map
package/lib/wili.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"wili.mjs","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;A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