Skip to content

Commit cc3be4b

Browse files
committed
Small refactoring
1 parent 134512b commit cc3be4b

21 files changed

+2168
-2279
lines changed

.github/workflows/test.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name: Tests
22
on: [push, pull_request]
33
jobs:
4-
build:
5-
runs-on: ubuntu-latest
6-
steps:
7-
- uses: actions/checkout@v2
8-
- name: Install modules
9-
run: yarn
10-
- name: Run tests
11-
run: yarn test
4+
build:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v2
8+
- name: Install modules
9+
run: yarn
10+
- name: Run tests
11+
run: yarn test

.jsdoc.json

+24-26
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
{
2-
"tags": {
3-
"allowUnknownTags": true,
4-
"dictionaries": ["jsdoc"]
5-
},
6-
"source": {
7-
"include": ["package.json", "Readme.md"],
8-
"includePattern": ".js$",
9-
"excludePattern": "(node_modules/|docs)"
10-
},
11-
"plugins": [
12-
"plugins/markdown"
13-
],
14-
"templates": {
15-
"cleverLinks": false,
16-
"monospaceLinks": true,
17-
"useLongnameInNav": false,
18-
"showInheritedInNav": true
19-
},
20-
"opts": {
21-
"destination": "./doc/",
22-
"encoding": "utf8",
23-
"private": false,
24-
"recurse": true,
25-
"template": "./node_modules/minami"
26-
}
27-
}
2+
"tags": {
3+
"allowUnknownTags": true,
4+
"dictionaries": ["jsdoc"]
5+
},
6+
"source": {
7+
"include": ["package.json", "Readme.md"],
8+
"includePattern": ".js$",
9+
"excludePattern": "(node_modules/|docs)"
10+
},
11+
"plugins": ["plugins/markdown"],
12+
"templates": {
13+
"cleverLinks": false,
14+
"monospaceLinks": true,
15+
"useLongnameInNav": false,
16+
"showInheritedInNav": true
17+
},
18+
"opts": {
19+
"destination": "./doc/",
20+
"encoding": "utf8",
21+
"private": false,
22+
"recurse": true,
23+
"template": "./node_modules/minami"
24+
}
25+
}

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode
2+
docs

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"tabWidth": 4,
3+
"singleQuote": true,
4+
"printWidth": 120
5+
}

Base64.js

+42-39
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
1-
21
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
32
const Base64 = {
4-
btoa: (input = '') => {
5-
let str = input;
6-
let output = '';
7-
8-
for (let block = 0, charCode, i = 0, map = chars;
9-
str.charAt(i | 0) || (map = '=', i % 1);
10-
output += map.charAt(63 & block >> 8 - i % 1 * 8)) {
11-
12-
charCode = str.charCodeAt(i += 3/4);
13-
14-
if (charCode > 0xFF) {
15-
throw new Error("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");
16-
}
17-
18-
block = block << 8 | charCode;
19-
}
20-
21-
return output;
22-
},
23-
24-
atob: (input = '') => {
25-
let str = input.replace(/=+$/, '');
26-
let output = '';
27-
28-
if (str.length % 4 == 1) {
29-
throw new Error("'atob' failed: The string to be decoded is not correctly encoded.");
30-
}
31-
for (let bc = 0, bs = 0, buffer, i = 0;
32-
buffer = str.charAt(i++);
33-
34-
~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,
35-
bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0
36-
) {
37-
buffer = chars.indexOf(buffer);
38-
}
39-
40-
return output;
41-
}
3+
btoa: (input = '') => {
4+
let str = input;
5+
let output = '';
6+
7+
for (
8+
let block = 0, charCode, i = 0, map = chars;
9+
str.charAt(i | 0) || ((map = '='), i % 1);
10+
output += map.charAt(63 & (block >> (8 - (i % 1) * 8)))
11+
) {
12+
charCode = str.charCodeAt((i += 3 / 4));
13+
14+
if (charCode > 0xff) {
15+
throw new Error(
16+
"'btoa' failed: The string to be encoded contains characters outside of the Latin1 range."
17+
);
18+
}
19+
20+
block = (block << 8) | charCode;
21+
}
22+
23+
return output;
24+
},
25+
26+
atob: (input = '') => {
27+
let str = input.replace(/=+$/, '');
28+
let output = '';
29+
30+
if (str.length % 4 == 1) {
31+
throw new Error("'atob' failed: The string to be decoded is not correctly encoded.");
32+
}
33+
for (
34+
let bc = 0, bs = 0, buffer, i = 0;
35+
(buffer = str.charAt(i++));
36+
~buffer && ((bs = bc % 4 ? bs * 64 + buffer : buffer), bc++ % 4)
37+
? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6))))
38+
: 0
39+
) {
40+
buffer = chars.indexOf(buffer);
41+
}
42+
43+
return output;
44+
},
4245
};
4346

4447
module.exports = Base64;

Readme.md

+33-47
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,16 @@ In case you need the Untis API Spec (pdf) where those JSON responses are explain
1313
```javascript
1414
const WebUntis = require('webuntis');
1515

16-
const untis = new WebUntis(
17-
'school',
18-
'username',
19-
'password',
20-
'xyz.webuntis.com'
21-
);
16+
const untis = new WebUntis('school', 'username', 'password', 'xyz.webuntis.com');
2217

2318
untis
24-
.login()
25-
.then(() => {
26-
return untis.getOwnTimetableForToday();
27-
})
28-
.then(timetable => {
29-
// profit
30-
});
19+
.login()
20+
.then(() => {
21+
return untis.getOwnTimetableForToday();
22+
})
23+
.then((timetable) => {
24+
// profit
25+
});
3126
```
3227

3328
### QR Code Login
@@ -36,19 +31,18 @@ untis
3631
const WebUntisLib = require('webuntis');
3732

3833
// The result of the scanned QR Code
39-
const QRCodeData =
40-
'untis://setschool?url=[...]&school=[...]&user=[...]&key=[...]&schoolNumber=[...]';
34+
const QRCodeData = 'untis://setschool?url=[...]&school=[...]&user=[...]&key=[...]&schoolNumber=[...]';
4135

4236
const untis = new WebUntisLib.WebUntisQR(QRCodeData);
4337

4438
untis
45-
.login()
46-
.then(() => {
47-
return untis.getOwnTimetableForToday();
48-
})
49-
.then(timetable => {
50-
// profit
51-
});
39+
.login()
40+
.then(() => {
41+
return untis.getOwnTimetableForToday();
42+
})
43+
.then((timetable) => {
44+
// profit
45+
});
5246
```
5347

5448
### User/Secret Login
@@ -58,21 +52,16 @@ const WebUntisLib = require('webuntis');
5852

5953
const secret = 'NL04FGY4FSY5';
6054

61-
const untis = new WebUntisLib.WebUntisSecretAuth(
62-
'school',
63-
'username',
64-
secret,
65-
'xyz.webuntis.com'
66-
);
55+
const untis = new WebUntisLib.WebUntisSecretAuth('school', 'username', secret, 'xyz.webuntis.com');
6756

6857
untis
69-
.login()
70-
.then(() => {
71-
return untis.getOwnTimetableForToday();
72-
})
73-
.then(timetable => {
74-
// profit
75-
});
58+
.login()
59+
.then(() => {
60+
return untis.getOwnTimetableForToday();
61+
})
62+
.then((timetable) => {
63+
// profit
64+
});
7665
```
7766

7867
### Anonymous Login
@@ -82,23 +71,20 @@ Only if your school supports public access.
8271
```javascript
8372
const WebUntisLib = require('webuntis');
8473

85-
const untis = new WebUntisLib.WebUntisAnonymousAuth(
86-
'school',
87-
'xyz.webuntis.com'
88-
);
74+
const untis = new WebUntisLib.WebUntisAnonymousAuth('school', 'xyz.webuntis.com');
8975

9076
untis
91-
.login()
92-
.then(() => {
93-
return untis.getClasses();
94-
})
95-
.then(classes => {
77+
.login()
78+
.then(() => {
79+
return untis.getClasses();
80+
})
81+
.then((classes) => {
9682
// Get timetable for the first class
9783
return untis.getTimetableForToday(classes[0].id, WebUntisLib.TYPES.CLASS);
9884
})
99-
.then(timetable => {
100-
// profit
101-
});
85+
.then((timetable) => {
86+
// profit
87+
});
10288
```
10389

10490
### Installation

0 commit comments

Comments
 (0)