|
1 | | -let _defaultInitVariables = { |
| 1 | +import replapi from './src/source.js'; |
| 2 | + |
| 3 | +const defaultInitVariables = { |
2 | 4 | username: undefined, |
| 5 | + captcha: { |
| 6 | + token: undefined, |
| 7 | + }, |
3 | 8 | endpoints: { |
4 | 9 | gql: undefined, |
5 | 10 | 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 | +}; |
9 | 22 |
|
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; |
13 | 41 | } else { |
14 | | - global.initVariables = _defaultInitVariables; |
| 42 | + global.initVariables = defaultInitVariables; |
15 | 43 | } |
16 | | - |
17 | | - const replapi = require('./src'); |
18 | | - |
| 44 | + |
19 | 45 | return { |
20 | 46 | 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, |
26 | 52 | 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