|
1 | | -let _defaultInitVariables = { |
| 1 | +import replapi from './src/source.js'; |
| 2 | + |
| 3 | +const defaultInitVariables = { |
2 | 4 | username: undefined, |
3 | 5 | captcha: { |
4 | | - token: undefined |
| 6 | + token: undefined, |
5 | 7 | }, |
6 | 8 | endpoints: { |
7 | 9 | gql: undefined, |
8 | 10 | restful: undefined, |
9 | | - login: undefined |
| 11 | + login: undefined, |
10 | 12 | }, |
11 | 13 | markdown: { |
12 | 14 | length: undefined, |
13 | | - removeMarkdown: undefined |
| 15 | + removeMarkdown: undefined, |
14 | 16 | }, |
15 | 17 | previewCount: { |
16 | | - comments: undefined |
17 | | - } |
18 | | -} |
| 18 | + comments: undefined, |
| 19 | + }, |
| 20 | +}; |
19 | 21 |
|
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 | + } |
27 | 32 | } |
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; |
31 | 37 | } |
32 | 38 | } |
33 | | - global.initVariables = _defaultInitVariables |
| 39 | + global.initVariables = defaultInitVariables; |
34 | 40 | } else { |
35 | | - global.initVariables = _defaultInitVariables; |
| 41 | + global.initVariables = defaultInitVariables; |
36 | 42 | } |
37 | | - |
38 | | - const replapi = require('./src'); |
39 | | - |
| 43 | + |
40 | 44 | return { |
41 | 45 | 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, |
47 | 51 | 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