wili 0.3.1 → 0.5.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/.eslintrc.cjs ADDED
@@ -0,0 +1,16 @@
1
+ /* eslint-disable */
2
+ module.exports = {
3
+ root: true,
4
+ parser: '@typescript-eslint/parser',
5
+ plugins: [
6
+ '@typescript-eslint',
7
+ ],
8
+ extends: [
9
+ 'eslint:recommended',
10
+ 'plugin:@typescript-eslint/recommended',
11
+ ],
12
+ rules: {
13
+ // temporary
14
+ "@typescript-eslint/no-explicit-any": "off"
15
+ }
16
+ };
@@ -0,0 +1,44 @@
1
+ name: CI
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ default:
7
+ runs-on: ${{ matrix.os }}
8
+ strategy:
9
+ matrix:
10
+ node-version: ['lts/*', '*']
11
+ os: [ubuntu-latest]
12
+
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ with:
16
+ fetch-depth: 1
17
+
18
+ - uses: actions/setup-node@v3
19
+ with:
20
+ node-version: ${{ matrix.node-version }}
21
+
22
+ - name: Cache pnpm modules
23
+ uses: actions/cache@v3
24
+ with:
25
+ path: ~/.pnpm-store
26
+ key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
27
+ restore-keys: |
28
+ ${{ runner.os }}-
29
+
30
+ - uses: pnpm/action-setup@v2
31
+ with:
32
+ version: 6
33
+ run_install: |
34
+ - recursive: true
35
+ - args: [--frozen-lockfile, --strict-peer-dependencies]
36
+
37
+ - name: Lint Source
38
+ run: pnpm run lint --if-present
39
+
40
+ - name: Build Source
41
+ run: pnpm run build --if-present
42
+
43
+ - name: Run Tests
44
+ run: pnpm run test --if-present
@@ -0,0 +1,21 @@
1
+ name: 'Stale issues and PR'
2
+ on:
3
+ schedule:
4
+ - cron: '30 1 * * *'
5
+
6
+ jobs:
7
+ stale:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/stale@v4
11
+ with:
12
+ stale-issue-label: stale
13
+ stale-pr-label: stale
14
+ stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days.'
15
+ stale-pr-message: 'This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days.'
16
+ close-issue-message: 'This issue was closed because it has been stalled for 14 days with no activity.'
17
+ close-pr-message: 'This PR was closed because it has been stalled for 14 days with no activity.'
18
+ days-before-issue-stale: 90
19
+ days-before-pr-stale: 90
20
+ days-before-issue-close: 30
21
+ days-before-pr-close: 30
@@ -0,0 +1,19 @@
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+ {
5
+ "label": "Development",
6
+ "type": "npm",
7
+ "script": "start",
8
+ "presentation": {
9
+ "clear": true,
10
+ "focus": false,
11
+ "panel": "shared",
12
+ "showReuseMessage": true
13
+ },
14
+ "runOptions": {
15
+ "runOn": "folderOpen"
16
+ }
17
+ }
18
+ ]
19
+ }
package/README.de.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  [![npm](https://flat.badgen.net/npm/license/wili)](https://www.npmjs.org/package/wili)
4
4
  [![npm](https://flat.badgen.net/npm/v/wili)](https://www.npmjs.org/package/wili)
5
- [![CircleCI](https://flat.badgen.net/circleci/github/idleberg/node-wili)](https://circleci.com/gh/idleberg/node-wili)
6
- [![David](https://flat.badgen.net/david/dep/idleberg/node-wili)](https://david-dm.org/idleberg/node-wili)
7
- [![David](https://flat.badgen.net/david/dev/idleberg/node-wili)](https://david-dm.org/idleberg/node-wili?type=dev)
5
+ [![CI](https://img.shields.io/github/workflow/status/idleberg/node-wili/CI?style=flat-square)](https://github.com/idleberg/node-wili/actions)
8
6
 
9
7
  [English](README.md) | **Deutsch**
10
8
 
@@ -20,47 +18,33 @@ Node Wrapper für das Echtzeitdaten API der Wiener Linien
20
18
 
21
19
  ## Anwendung
22
20
 
23
- Das Modul lässt sich per ES6 Imports oder `require()` importieren:
24
-
25
- ```js
26
- // ECMAScript Import
27
- import WienerLinien from 'wili';
28
-
29
- // CommonJS Require
30
- const WienerLinien = require('wili');
31
- ```
32
-
33
21
  Beispielanwendung:
34
22
 
35
23
  ```js
36
- import WienerLinien from 'wili';
24
+ import { WienerLinien } from 'wili';
37
25
 
38
- // Der API-Key kann weggelassen werden, wenn
39
- // process.env.WIENER_LINIEN_API_KEY gesetzt ist
40
- const wl = new WienerLinien(API_KEY);
26
+ const wili = new WienerLinien();
41
27
 
42
28
  const options = {
43
29
  relatedLine: ['U2', 'U4', 'U6']
44
30
  };
45
31
 
46
32
  // Promise API
47
- wl.trafficInfoList(options)
48
- .then( data => {
49
- console.log(data.trafficInfos);
50
- })
51
- .catch( error => {
52
- console.error(error);
53
- });
54
-
55
- // async/await
56
- (async () => {
57
- try {
58
- let data = await wl.trafficInfoList(options);
33
+ wili.trafficInfoList(options)
34
+ .then( data => {
59
35
  console.log(data.trafficInfos);
60
- } catch (output) {
36
+ })
37
+ .catch( error => {
61
38
  console.error(error);
62
- }
63
- })();
39
+ });
40
+
41
+ // async/await
42
+ try {
43
+ let data = await wili.trafficInfoList(options);
44
+ console.log(data.trafficInfos);
45
+ } catch (output) {
46
+ console.error(error);
47
+ }
64
48
  ```
65
49
 
66
50
  ## API
package/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  [![npm](https://flat.badgen.net/npm/license/wili)](https://www.npmjs.org/package/wili)
4
4
  [![npm](https://flat.badgen.net/npm/v/wili)](https://www.npmjs.org/package/wili)
5
- [![CircleCI](https://flat.badgen.net/circleci/github/idleberg/node-wili)](https://circleci.com/gh/idleberg/node-wili)
6
- [![David](https://flat.badgen.net/david/dep/idleberg/node-wili)](https://david-dm.org/idleberg/node-wili)
7
- [![David](https://flat.badgen.net/david/dev/idleberg/node-wili)](https://david-dm.org/idleberg/node-wili?type=dev)
5
+ [![CI](https://img.shields.io/github/workflow/status/idleberg/node-wili/CI?style=flat-square)](https://github.com/idleberg/node-wili/actions)
8
6
 
9
7
  **English** | [Deutsch](README.de.md)
10
8
 
@@ -20,47 +18,33 @@ A Node wrapper for the Wiener Linien public transport API
20
18
 
21
19
  ## Usage
22
20
 
23
- Use ES6 imports or `require()` to include the module:
24
-
25
- ```js
26
- // ECMAScript Import
27
- import WienerLinien from 'wili';
28
-
29
- // CommonJS Require
30
- const WienerLinien = require('wili');
31
- ```
32
-
33
21
  Example usage in script:
34
22
 
35
23
  ```js
36
- import WienerLinien from 'wili';
24
+ import { WienerLinien } from 'wili';
37
25
 
38
- // The API key can be omitted when
39
- // process.env.WIENER_LINIEN_API_KEY is set
40
- const wl = new WienerLinien(API_KEY);
26
+ const wili = new WienerLinien();
41
27
 
42
28
  const options = {
43
29
  relatedLine: ['U2', 'U4', 'U6']
44
30
  };
45
31
 
46
32
  // Promise API
47
- wl.trafficInfoList(options)
48
- .then( data => {
49
- console.log(data.trafficInfos);
50
- })
51
- .catch( error => {
52
- console.error(error);
53
- });
54
-
55
- // async/await
56
- (async () => {
57
- try {
58
- let data = await wl.trafficInfoList(options);
33
+ wili.trafficInfoList(options)
34
+ .then( data => {
59
35
  console.log(data.trafficInfos);
60
- } catch (output) {
36
+ })
37
+ .catch( error => {
61
38
  console.error(error);
62
- }
63
- })();
39
+ });
40
+
41
+ // async/await
42
+ try {
43
+ let data = await wili.trafficInfoList(options);
44
+ console.log(data.trafficInfos);
45
+ } catch (output) {
46
+ console.error(error);
47
+ }
64
48
  ```
65
49
 
66
50
  ## API
@@ -140,7 +124,3 @@ Disruption type (`stoerungkurz`, `stoerunglang`, or `aufzugsinfo`)
140
124
  ## License
141
125
 
142
126
  This work is licensed under [The MIT License](https://opensource.org/licenses/MIT)
143
-
144
- ## Donate
145
-
146
- You are welcome to support this project using [Flattr](https://flattr.com/submit/auto?user_id=idleberg&url=https://github.com/idleberg/node-wili) or Bitcoin `17CXJuPsmhuTzFV2k4RKYwpEHVjskJktRd`
package/lib/wili.cjs ADDED
@@ -0,0 +1,106 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var fetch = require('isomorphic-fetch');
6
+ var queryString = require('query-string');
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+
10
+ var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
11
+ var queryString__default = /*#__PURE__*/_interopDefaultLegacy(queryString);
12
+
13
+ var WienerLinien = /** @class */ (function () {
14
+ function WienerLinien(API_KEY) {
15
+ if (API_KEY === void 0) { API_KEY = undefined; }
16
+ this.API_KEY = (API_KEY && API_KEY.length)
17
+ ? String(API_KEY)
18
+ : String(process.env.WIENER_LINIEN_API_KEY) || 'undefined';
19
+ }
20
+ /**
21
+ * Returns real-time data for a station
22
+ * @param rbl - RBL number
23
+ * @param options optional arguments
24
+ * @returns - JSON
25
+ */
26
+ WienerLinien.prototype.monitor = function (rbl, options) {
27
+ if (options === void 0) { options = {}; }
28
+ var urlParams = {
29
+ rbl: rbl
30
+ };
31
+ if (typeof options.activateTrafficInfo !== 'undefined' && options.activateTrafficInfo) {
32
+ urlParams['activateTrafficInfo'] = options.activateTrafficInfo;
33
+ }
34
+ if (this.API_KEY && this.API_KEY.trim().length) {
35
+ urlParams['sender'] = this.API_KEY;
36
+ }
37
+ return this.apiCall('/monitor', urlParams);
38
+ };
39
+ /**
40
+ * Returns news, elevator maintenance and other information
41
+ * @param options optional arguments
42
+ * @returns JSON
43
+ */
44
+ WienerLinien.prototype.newsList = function (options) {
45
+ if (options === void 0) { options = {}; }
46
+ var urlParams = {};
47
+ if (typeof options.relatedLine !== 'undefined' && options.relatedLine) {
48
+ urlParams['relatedLine'] = options.relatedLine;
49
+ }
50
+ if (typeof options.relatedStop !== 'undefined' && options.relatedStop) {
51
+ urlParams['relatedStop'] = options.relatedStop;
52
+ }
53
+ if (typeof options.name !== 'undefined' && options.name) {
54
+ urlParams['name'] = options.name;
55
+ }
56
+ if (this.API_KEY && this.API_KEY.trim().length) {
57
+ urlParams['sender'] = this.API_KEY;
58
+ }
59
+ return this.apiCall('newsList', urlParams);
60
+ };
61
+ /**
62
+ * Returns interruption of operations and elevator outage
63
+ * @param options optional arguments
64
+ * @returns JSON
65
+ */
66
+ WienerLinien.prototype.trafficInfoList = function (options) {
67
+ if (options === void 0) { options = {}; }
68
+ var urlParams = {};
69
+ if (typeof options.relatedLine !== 'undefined' && options.relatedLine) {
70
+ urlParams['relatedLine'] = options.relatedLine;
71
+ }
72
+ if (typeof options.relatedStop !== 'undefined' && options.relatedStop) {
73
+ urlParams['relatedStop'] = options.relatedStop;
74
+ }
75
+ if (typeof options.name !== 'undefined' && options.name) {
76
+ urlParams['name'] = options.name;
77
+ }
78
+ if (this.API_KEY && this.API_KEY.trim().length) {
79
+ urlParams['sender'] = this.API_KEY;
80
+ }
81
+ return this.apiCall('trafficInfoList', urlParams);
82
+ };
83
+ WienerLinien.prototype.checkStatus = function (response) {
84
+ if (response.status >= 200 && response.status < 300) {
85
+ return Promise.resolve(response);
86
+ }
87
+ else {
88
+ return Promise.reject(new Error(response.statusText));
89
+ }
90
+ };
91
+ WienerLinien.prototype.parseJson = function (response) {
92
+ return response.json();
93
+ };
94
+ WienerLinien.prototype.apiCall = function (urlPath, urlParams) {
95
+ var url = new URL('https://www.wienerlinien.at');
96
+ url.pathname = "/ogd_realtime/" + urlPath;
97
+ url.search = queryString__default['default'].stringify(urlParams);
98
+ return fetch__default['default'](url.href)
99
+ .then(this.checkStatus)
100
+ .then(this.parseJson)
101
+ .then(function (response) { return response.data; })["catch"](console.error);
102
+ };
103
+ return WienerLinien;
104
+ }());
105
+
106
+ exports.WienerLinien = WienerLinien;
@@ -1,24 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const fetch = require("isomorphic-fetch");
4
- const queryString = require("query-string");
5
- class WienerLinien {
6
- constructor(API_KEY = undefined) {
1
+ import fetch from 'isomorphic-fetch';
2
+ import queryString from 'query-string';
3
+
4
+ var WienerLinien = /** @class */ (function () {
5
+ function WienerLinien(API_KEY) {
6
+ if (API_KEY === void 0) { API_KEY = undefined; }
7
7
  this.API_KEY = (API_KEY && API_KEY.length)
8
- ? API_KEY
9
- : process.env.WIENER_LINIEN_API_KEY2 || undefined;
10
- console.log('process.env.WIENER_LINIEN_API_KEY', process.env.WIENER_LINIEN_API_KEY);
11
- console.log('API_KEY', this.API_KEY);
8
+ ? String(API_KEY)
9
+ : String(process.env.WIENER_LINIEN_API_KEY) || 'undefined';
12
10
  }
13
11
  /**
14
12
  * Returns real-time data for a station
15
- * @param {number|string|number[]|string[]} rbl - RBL number
16
- * @param {Object} [options] - optional arguments
17
- * @returns {Object} - JSON
13
+ * @param rbl - RBL number
14
+ * @param options optional arguments
15
+ * @returns - JSON
18
16
  */
19
- monitor(rbl, options = {}) {
20
- const urlParams = {
21
- rbl: rbl,
17
+ WienerLinien.prototype.monitor = function (rbl, options) {
18
+ if (options === void 0) { options = {}; }
19
+ var urlParams = {
20
+ rbl: rbl
22
21
  };
23
22
  if (typeof options.activateTrafficInfo !== 'undefined' && options.activateTrafficInfo) {
24
23
  urlParams['activateTrafficInfo'] = options.activateTrafficInfo;
@@ -27,14 +26,15 @@ class WienerLinien {
27
26
  urlParams['sender'] = this.API_KEY;
28
27
  }
29
28
  return this.apiCall('/monitor', urlParams);
30
- }
29
+ };
31
30
  /**
32
31
  * Returns news, elevator maintenance and other information
33
- * @param {Object} [options] - optional arguments
34
- * @returns {Object} - JSON
32
+ * @param options optional arguments
33
+ * @returns JSON
35
34
  */
36
- newsList(options = {}) {
37
- const urlParams = {};
35
+ WienerLinien.prototype.newsList = function (options) {
36
+ if (options === void 0) { options = {}; }
37
+ var urlParams = {};
38
38
  if (typeof options.relatedLine !== 'undefined' && options.relatedLine) {
39
39
  urlParams['relatedLine'] = options.relatedLine;
40
40
  }
@@ -48,14 +48,15 @@ class WienerLinien {
48
48
  urlParams['sender'] = this.API_KEY;
49
49
  }
50
50
  return this.apiCall('newsList', urlParams);
51
- }
51
+ };
52
52
  /**
53
53
  * Returns interruption of operations and elevator outage
54
- * @param {Object} [options] - optional arguments
55
- * @returns {Object} - JSON
54
+ * @param options optional arguments
55
+ * @returns JSON
56
56
  */
57
- trafficInfoList(options = {}) {
58
- const urlParams = {};
57
+ WienerLinien.prototype.trafficInfoList = function (options) {
58
+ if (options === void 0) { options = {}; }
59
+ var urlParams = {};
59
60
  if (typeof options.relatedLine !== 'undefined' && options.relatedLine) {
60
61
  urlParams['relatedLine'] = options.relatedLine;
61
62
  }
@@ -69,28 +70,28 @@ class WienerLinien {
69
70
  urlParams['sender'] = this.API_KEY;
70
71
  }
71
72
  return this.apiCall('trafficInfoList', urlParams);
72
- }
73
- checkStatus(response) {
73
+ };
74
+ WienerLinien.prototype.checkStatus = function (response) {
74
75
  if (response.status >= 200 && response.status < 300) {
75
76
  return Promise.resolve(response);
76
77
  }
77
78
  else {
78
79
  return Promise.reject(new Error(response.statusText));
79
80
  }
80
- }
81
- parseJson(response) {
81
+ };
82
+ WienerLinien.prototype.parseJson = function (response) {
82
83
  return response.json();
83
- }
84
- apiCall(urlPath, urlParams) {
85
- const url = new URL('https://www.wienerlinien.at');
86
- url.pathname = `/ogd_realtime/${urlPath}`;
84
+ };
85
+ WienerLinien.prototype.apiCall = function (urlPath, urlParams) {
86
+ var url = new URL('https://www.wienerlinien.at');
87
+ url.pathname = "/ogd_realtime/" + urlPath;
87
88
  url.search = queryString.stringify(urlParams);
88
89
  return fetch(url.href)
89
90
  .then(this.checkStatus)
90
91
  .then(this.parseJson)
91
- .then(response => response.data)
92
- .catch(console.error);
93
- }
94
- }
95
- exports.default = WienerLinien;
96
- //# sourceMappingURL=index.js.map
92
+ .then(function (response) { return response.data; })["catch"](console.error);
93
+ };
94
+ return WienerLinien;
95
+ }());
96
+
97
+ export { WienerLinien };
package/package.json CHANGED
@@ -1,18 +1,27 @@
1
1
  {
2
2
  "name": "wili",
3
- "version": "0.3.1",
3
+ "version": "0.5.1",
4
4
  "description": "A Node client for the Wiener Linien public transport API",
5
- "main": "lib/index.js",
5
+ "author": "Jan T. Sott",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "exports": {
9
+ "import": "./lib/wili.mjs",
10
+ "require": "./lib/wili.cjs"
11
+ },
12
+ "typings": "types/",
6
13
  "repository": {
7
14
  "type": "git",
8
15
  "url": "https://github.com/idleberg/node-wili.git"
9
16
  },
10
17
  "scripts": {
11
- "build": "tsc --pretty --project ./",
12
- "dev": "tsc --watch --pretty --project ./",
13
- "lint": "tslint --project ./",
14
- "precommit": "npm run lint && npm run test",
15
- "test": "ava ./test/test.js --verbose --fail-fast"
18
+ "build": "rollup -c",
19
+ "dev": "npm run start",
20
+ "lint": "eslint ./src",
21
+ "lint:fix": "eslint --fix ./src",
22
+ "start": "rollup -w -c",
23
+ "test": "ava ./test/test.*js --verbose --fail-fast",
24
+ "prepare": "husky install"
16
25
  },
17
26
  "keywords": [
18
27
  "wiener linien",
@@ -21,17 +30,28 @@
21
30
  "öpvn",
22
31
  "public transport"
23
32
  ],
24
- "author": "Jan T. Sott",
25
- "license": "MIT",
26
33
  "dependencies": {
27
- "isomorphic-fetch": "^2.2.1",
28
- "query-string": "^6.11.1"
34
+ "isomorphic-fetch": "^3.0.0",
35
+ "query-string": "^7.1.1"
29
36
  },
30
37
  "devDependencies": {
31
- "@types/node": "^13.9.2",
32
- "ava": "^2.4.0",
33
- "husky": "^4.2.3",
34
- "tslint": "^6.1.0",
35
- "typescript": "^3.8.3"
38
+ "@rollup/plugin-commonjs": "^22.0.1",
39
+ "@rollup/plugin-json": "^4.1.0",
40
+ "@rollup/plugin-node-resolve": "^13.3.0",
41
+ "@rollup/plugin-typescript": "^8.3.3",
42
+ "@types/node": "^16.11.45",
43
+ "@typescript-eslint/eslint-plugin": "^5.31.0",
44
+ "@typescript-eslint/parser": "^5.31.0",
45
+ "ava": "^4.3.1",
46
+ "encoding": "^0.1.13",
47
+ "eslint": "^8.20.0",
48
+ "husky": "^8.0.1",
49
+ "lint-staged": "^13.0.3",
50
+ "rollup": "^2.77.2",
51
+ "tslib": "^2.4.0",
52
+ "typescript": "^4.7.4"
53
+ },
54
+ "lint-staged": {
55
+ "*.ts": "eslint --cache --fix"
36
56
  }
37
57
  }