Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit f5c58b7

Browse files
author
Ray Arayilakath
authored
Major Refactors to ReplAPI.it
Check pull request 28 for a full list of all commits.
2 parents f07ac2d + 5b427c2 commit f5c58b7

21 files changed

+3722
-1364
lines changed

.eslintrc.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"commonjs": true,
5+
"es2021": true
6+
},
7+
"extends": [
8+
"airbnb-base"
9+
],
10+
"parserOptions": {
11+
"ecmaVersion": 12
12+
},
13+
"rules": {
14+
}
15+
}

index.js

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,60 @@
1-
let _defaultInitVariables = {
1+
import replapi from './src/source.js';
2+
3+
const defaultInitVariables = {
24
username: undefined,
5+
captcha: {
6+
token: undefined,
7+
},
38
endpoints: {
49
gql: undefined,
510
restful: undefined,
6-
login: undefined
7-
}
8-
}
11+
login: undefined,
12+
},
13+
markdown: {
14+
length: undefined,
15+
removeMarkdown: undefined,
16+
},
17+
previewCount: {
18+
comments: undefined,
19+
},
20+
experimentalFeatures: undefined,
21+
};
922

10-
module.exports = function(initVariables) {
11-
if(initVariables) {
12-
global.initVariables = initVariables;
23+
export default function ReplAPI(initVariables) {
24+
if (initVariables) {
25+
for (const [key, value] of Object.entries(initVariables)) {
26+
if (typeof value === 'object') {
27+
for (const [nestedKey, nestedValue] of Object.entries(value)) {
28+
if (typeof nestedValue !== 'string' && typeof nestedValue !== 'number') {
29+
throw new Error(`Invalid type for value of ${nestedKey}.`);
30+
} else if (defaultInitVariables[key][nestedKey] === undefined) {
31+
defaultInitVariables[key][nestedKey] = nestedValue;
32+
}
33+
}
34+
} else if (typeof value !== 'string' && typeof value !== 'number') {
35+
throw new Error(`Invalid type for value of ${key}.`);
36+
} else if (defaultInitVariables[key] === undefined) {
37+
defaultInitVariables[key] = value;
38+
}
39+
}
40+
global.initVariables = defaultInitVariables;
1341
} else {
14-
global.initVariables = _defaultInitVariables;
42+
global.initVariables = defaultInitVariables;
1543
}
16-
17-
const replapi = require('./src');
18-
44+
1945
return {
2046
defaults: global.initVariables,
21-
User: replapi.User,
22-
Post: replapi.Post,
23-
Repl: replapi.Repl,
24-
Comment: replapi.Comment,
25-
Leaderboard: replapi.Leaderboard,
47+
Board: replapi.Board,
48+
Comment: replapi.Comment,
49+
CustomDataQuery: replapi.CustomDataQuery,
50+
CustomRecursiveQuery: replapi.CustomRecursiveQuery,
51+
Database: replapi.Database,
2652
Languages: replapi.Languages,
27-
Board: replapi.Board,
28-
Notifications: replapi.Notifications,
29-
Misc: replapi.Misc,
30-
Login: replapi.Login,
31-
CustomDataQuery: replapi.CustomDataQuery,
32-
CustomRecursiveQuery: replapi.CustomRecursiveQuery
33-
}
34-
};
53+
Leaderboard: replapi.Leaderboard,
54+
Login: replapi.Login,
55+
Notifications: replapi.Notifications,
56+
Post: replapi.Post,
57+
Repl: replapi.Repl,
58+
User: replapi.User,
59+
};
60+
}

0 commit comments

Comments
 (0)