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

Commit 1735bcd

Browse files
author
Ray Arayilakath
committed
Upgraded to ES6 and Used Linter on Files
1 parent 4be56f3 commit 1735bcd

File tree

19 files changed

+2229
-578
lines changed

19 files changed

+2229
-578
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: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,58 @@
1-
let _defaultInitVariables = {
1+
import replapi from './src/source.js';
2+
3+
const defaultInitVariables = {
24
username: undefined,
35
captcha: {
4-
token: undefined
6+
token: undefined,
57
},
68
endpoints: {
79
gql: undefined,
810
restful: undefined,
9-
login: undefined
11+
login: undefined,
1012
},
1113
markdown: {
1214
length: undefined,
13-
removeMarkdown: undefined
15+
removeMarkdown: undefined,
1416
},
1517
previewCount: {
16-
comments: undefined
17-
}
18-
}
18+
comments: undefined,
19+
},
20+
};
1921

20-
module.exports = function(initVariables) {
21-
if(initVariables) {
22-
for([key, value] of Object.entries(initVariables)) {
23-
if(typeof value == 'object') {
24-
for([nestedKey, nestedValue] of Object.entries(value)) {
25-
if(typeof nestedValue != 'string' && typeof nestedValue != 'number') throw new Error(`Invalid type for value of ${nestedKey}.`);
26-
else if(_defaultInitVariables[key][nestedKey] === undefined) _defaultInitVariables[key][nestedKey] = nestedValue;
22+
export default function ReplAPI(initVariables) {
23+
if (initVariables) {
24+
for (const [key, value] of Object.entries(initVariables)) {
25+
if (typeof value === 'object') {
26+
for (const [nestedKey, nestedValue] of Object.entries(value)) {
27+
if (typeof nestedValue !== 'string' && typeof nestedValue !== 'number') {
28+
throw new Error(`Invalid type for value of ${nestedKey}.`);
29+
} else if (defaultInitVariables[key][nestedKey] === undefined) {
30+
defaultInitVariables[key][nestedKey] = nestedValue;
31+
}
2732
}
28-
} else {
29-
if(typeof value != 'string' && typeof value != 'number') throw new Error(`Invalid type for value of ${key}.`);
30-
else if(_defaultInitVariables[key] === undefined) _defaultInitVariables[key] = value;
33+
} else if (typeof value !== 'string' && typeof value !== 'number') {
34+
throw new Error(`Invalid type for value of ${key}.`);
35+
} else if (defaultInitVariables[key] === undefined) {
36+
defaultInitVariables[key] = value;
3137
}
3238
}
33-
global.initVariables = _defaultInitVariables
39+
global.initVariables = defaultInitVariables;
3440
} else {
35-
global.initVariables = _defaultInitVariables;
41+
global.initVariables = defaultInitVariables;
3642
}
37-
38-
const replapi = require('./src');
39-
43+
4044
return {
4145
defaults: global.initVariables,
42-
User: replapi.User,
43-
Post: replapi.Post,
44-
Repl: replapi.Repl,
45-
Comment: replapi.Comment,
46-
Leaderboard: replapi.Leaderboard,
46+
User: replapi.User,
47+
Post: replapi.Post,
48+
Repl: replapi.Repl,
49+
Comment: replapi.Comment,
50+
Leaderboard: replapi.Leaderboard,
4751
Languages: replapi.Languages,
48-
Board: replapi.Board,
49-
Notifications: replapi.Notifications,
50-
Misc: replapi.Misc,
51-
Login: replapi.Login,
52-
CustomDataQuery: replapi.CustomDataQuery,
53-
CustomRecursiveQuery: replapi.CustomRecursiveQuery
54-
}
55-
};
52+
Board: replapi.Board,
53+
Notifications: replapi.Notifications,
54+
Login: replapi.Login,
55+
CustomDataQuery: replapi.CustomDataQuery,
56+
CustomRecursiveQuery: replapi.CustomRecursiveQuery,
57+
};
58+
}

0 commit comments

Comments
 (0)