@elara-services/packages 5.3.1 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/package.json +44 -0
  2. package/dist/src/index.d.ts +1 -0
  3. package/dist/src/index.js +17 -0
  4. package/dist/src/interfaces/discord.d.ts +91 -0
  5. package/dist/src/interfaces/discord.js +2 -0
  6. package/dist/src/interfaces/index.d.ts +1 -0
  7. package/dist/src/interfaces/index.js +17 -0
  8. package/dist/src/lib/AES.d.ts +7 -0
  9. package/dist/src/lib/AES.js +82 -0
  10. package/dist/src/lib/discord.d.ts +136 -0
  11. package/dist/src/lib/discord.js +381 -0
  12. package/dist/src/lib/index.d.ts +8 -0
  13. package/dist/src/lib/index.js +24 -0
  14. package/dist/src/lib/languages.d.ts +220 -0
  15. package/dist/src/lib/languages.js +125 -0
  16. package/dist/src/lib/minesweeper.d.ts +20 -0
  17. package/dist/src/lib/minesweeper.js +81 -0
  18. package/dist/src/lib/misc.d.ts +1 -0
  19. package/dist/src/lib/misc.js +73 -0
  20. package/dist/src/lib/random.d.ts +16 -0
  21. package/dist/src/lib/random.js +2035 -0
  22. package/dist/src/lib/tasks.d.ts +9 -0
  23. package/dist/src/lib/tasks.js +72 -0
  24. package/docs/.nojekyll +1 -0
  25. package/docs/assets/highlight.css +22 -0
  26. package/docs/assets/main.js +58 -0
  27. package/docs/assets/search.js +1 -0
  28. package/docs/assets/style.css +1367 -0
  29. package/docs/classes/AES.html +144 -0
  30. package/docs/classes/Minesweeper.html +205 -0
  31. package/docs/classes/Tasks.html +141 -0
  32. package/docs/functions/fetch.html +89 -0
  33. package/docs/functions/randomWeight.html +79 -0
  34. package/docs/functions/randomWords.html +74 -0
  35. package/docs/index.html +163 -0
  36. package/docs/interfaces/ButtonOptions.html +154 -0
  37. package/docs/interfaces/ModalOptions.html +124 -0
  38. package/docs/interfaces/RandomWord.html +153 -0
  39. package/docs/interfaces/SelectOptions.html +159 -0
  40. package/docs/interfaces/Slash.html +138 -0
  41. package/docs/interfaces/SlashOptions.html +187 -0
  42. package/docs/interfaces/TaskCreate.html +103 -0
  43. package/docs/interfaces/TextInputOptions.html +180 -0
  44. package/docs/modules.html +101 -0
  45. package/docs/types/ButtonNumberStyles.html +65 -0
  46. package/docs/types/ButtonStyles.html +65 -0
  47. package/docs/types/ChannelTypes.html +65 -0
  48. package/docs/types/Lang.html +65 -0
  49. package/docs/types/LangName.html +65 -0
  50. package/docs/variables/ButtonStyle.html +88 -0
  51. package/docs/variables/Duration.html +109 -0
  52. package/docs/variables/Interactions.html +159 -0
  53. package/docs/variables/Languages.html +294 -0
  54. package/docs/variables/SlashBuilder.html +238 -0
  55. package/package.json +44 -10
  56. package/.github/renovate.json +0 -5
  57. package/CHANGELOG +0 -62
  58. package/index.d.ts +0 -247
  59. package/index.js +0 -11
  60. package/packages/Interactions.js +0 -76
  61. package/packages/SlashBuilder.js +0 -58
  62. package/packages/Tasks.js +0 -22
  63. package/packages/aes256.js +0 -62
  64. package/packages/duration.js +0 -74
  65. package/packages/fetch.js +0 -30
  66. package/packages/languages.js +0 -119
  67. package/packages/minesweeper.js +0 -77
  68. package/packages/random/weight.js +0 -8
  69. package/packages/random/words.js +0 -300
package/CHANGELOG DELETED
@@ -1,62 +0,0 @@
1
- # v5.2.0
2
- - Added `textInput` for `Interactions`
3
- - Added typings for `textInput` helper function.
4
-
5
- # v5.1.0
6
- - Added `name_localizations` for `SlashBuilder.choice`
7
- - Added typings for `min_length` and `max_length` for `SlashBuilder.option` for STRING options.
8
- - Fixed typings for `Interactions.button` to have `label` and `title`
9
- - Fixed `Interactions.button` to allow for `title` and `label`
10
-
11
-
12
- # v5.0.0
13
- ### BREAKING CHANGES
14
- - `locale` option for `SlashBuilder.context.user` and `SlashBuilder.context.message` was turned into `options` taking in more options (to support both permissions and locale)
15
- - `defaultPermission`/`default_permission` was removed, since it's deprecated. (if you want to use it then stay on v4.8.1)
16
-
17
- # v4.8.0/v4.8.1
18
- - Added: `dmPermission` (`dm_permission`) for SlashBuilder.create
19
- - Added: `defaultMemberPermissions` (`default_member_permissions`) for SlashBuilder.create
20
- - Deprecated `defaultPermission` (`default_permission`) for SlashBuilder.create
21
- - Updated: Typings for SlashBuilder.create
22
-
23
- # v4.7.0
24
- Added `locale` option for `<SlashBuilder>.create`, `<SlashBuilder>.option`, `<SlashBuilder.context.user/message>`
25
-
26
-
27
- # v4.0.3, v4.0.2
28
- Added
29
- - fetch (useful with `@elara-services/fetch`)
30
-
31
- # v4.0.1
32
- Added
33
- - Languages.find
34
- - Languages.langs
35
-
36
- # v4.0.0
37
- __Breaking Change__
38
- The following functions & methods for `SlashBuilder` was moved to `static`
39
- > So you no longer need to do `new (require("@elara-services/packages").SlashBuilder)()`
40
-
41
-
42
- # v3.0.3
43
- Added 'types.context.user', 'types.context.message' and the typings for SlashBuilder
44
-
45
-
46
- # v3.0.1, v3.0.2
47
-
48
- Fixed the typings for modal and added the typings for "ButtonStyle"
49
-
50
-
51
- # v3.0.0
52
-
53
- __Breaking Changes__
54
- Removed `UserFlags`, `Permissions` and `BitField`
55
-
56
-
57
- __Added__
58
- `Interactions`
59
- -> button
60
- -> select
61
- -> modal
62
- And the typings.
package/index.d.ts DELETED
@@ -1,247 +0,0 @@
1
- declare module "@elara-services/packages" {
2
- type array = string[];
3
-
4
- export class AES {
5
- public constructor(key: string);
6
- private key: string;
7
- private header: string;
8
- public encrypt(input: string): string
9
- public decrypt(encrypted: string): string;
10
- }
11
-
12
- export const Languages: {
13
- find(name: string): string | null;
14
- langs: object
15
- }
16
-
17
- export class Minesweeper {
18
- public constructor(options?: {
19
- rows?: number;
20
- columns?: number;
21
- mines?: number;
22
- emote?: string
23
- });
24
-
25
- public rows: number;
26
- public columns: number;
27
- public mines: number;
28
- public matrix: array;
29
- public types: {
30
- mine: string;
31
- numbers: array
32
- };
33
-
34
- public generateEmptyMatrix(): void;
35
- public plantMines(): void;
36
- public getNumberOfMines(x: number, y: number): string;
37
- public start(): string | array[] | null;
38
- }
39
-
40
- export class Interactions extends null {
41
- public static button(options: ButtonOptions): Button;
42
- public static select(options: SelectOptions): Select;
43
- public static modal(options: ModalOptions): Modal;
44
- public static textInput(options: TextInputOptions, row?: boolean): TextInput | { type: number, components: [ TextInput ] };
45
- }
46
-
47
- export type ChannelTypes = 'GUILD_TEXT' | 'DM' | 'GUILD_VOICE' | 'GROUP_DM' | 'GUILD_CATEGORY' | 'GUILD_NEWS' | 'GUILD_STORE' | 'GUILD_NEWS_THREAD' | 'GUILD_PUBLIC_THREAD' | 'GUILD_PRIVATE_THREAD' | 'GUILD_STAGE_VOICE';
48
-
49
- export type TextInputOptions = {
50
- id?: string;
51
- type?: number;
52
- title?: string;
53
- style?: number;
54
- min?: number;
55
- max?: number;
56
- holder?: string;
57
- } & TextInput;
58
-
59
- export type TextInput = {
60
- custom_id?: string;
61
- type?: number;
62
- label?: string;
63
- style?: number;
64
- min_length?: number;
65
- max_length?: number;
66
- placeholder?: string;
67
- value?: string;
68
- required?: boolean;
69
- }
70
-
71
- export type SlashOptions = {
72
- type: number;
73
- name: string;
74
- description: string;
75
- required?: boolean;
76
- channel_types?: ChannelTypes[];
77
- autocomplete?: boolean;
78
- min_value?: number;
79
- max_value?: number;
80
- min_length?: number;
81
- max_length?: number;
82
- choices?: { name: string, value: string }[];
83
- options?: SlashOptions[];
84
- locale?: {
85
- names?: object;
86
- descriptions?: object;
87
- }
88
- }
89
-
90
- export type Slash = {
91
- type?: number;
92
-
93
- dmPermission?: boolean;
94
- dm_permission?: boolean;
95
-
96
- defaultMemberPermissions?: string;
97
- default_member_permissions?: string;
98
-
99
- options?: SlashOptions[];
100
- locale?: {
101
- names?: object;
102
- descriptions?: object;
103
- }
104
- }
105
-
106
- export class SlashBuilder {
107
-
108
- public static TEXT_BASED_CHANNELS: number[];
109
-
110
- public static types: {
111
- sub_command: number,
112
- sub_group: number,
113
- string: number,
114
- integer: number,
115
- boolean: number,
116
- user: number,
117
- channel: number,
118
- role: number,
119
- mentionable: number,
120
- number: number,
121
- context: {
122
- user: number;
123
- message: number;
124
- }
125
- };
126
-
127
- public static context: {
128
- user(name: string, options?: Omit<Slash, "options"|"type">): Slash;
129
- message(name: string, options?: Omit<Slash, "options"|"type">): Slash;
130
- };
131
-
132
- public static choice(name: string, value: string|number, name_localizations?: object): { name: string, value: string|number, name_localizations: object };
133
- public static option(data: SlashOptions): Slash;
134
- public static create(name: string, description: string, options: Slash): Slash;
135
- }
136
-
137
- export type Button = {
138
- custom_id?: string;
139
- label?: string;
140
- type?: number;
141
- style?: number;
142
- disabled?: boolean;
143
- emoji?: { name?: string, id?: string, animated?: boolean };
144
- url?: string
145
- }
146
-
147
- export type ButtonOptions = {
148
- id?: Button['custom_id'];
149
- title?: Button['label'];
150
- label?: Button['label'];
151
- custom_id?: Button['custom_id'];
152
- type?: Button['type'];
153
- style?: ButtonStyles | Button['style'];
154
- disabled?: Button['disabled'];
155
- emoji?: Button['emoji'];
156
- url?: Button['url']
157
- }
158
-
159
- export type ButtonStyles = 'PRIMARY' | 'BLURPLE' | 'SECONDARY' | 'GREY' | 'SUCCESS' | 'GREEN' | 'DANGER' | 'RED' | 'LINK' | 'URL'
160
-
161
- export type Select = {
162
- custom_id: string;
163
- placeholder: string;
164
- min_values: number;
165
- max_values: number;
166
- type: number;
167
- disabled: boolean;
168
- options: {
169
- label: string;
170
- value: string;
171
- description?: string;
172
- emoji?: Button['emoji'],
173
- default?: boolean;
174
- }[]
175
- }
176
-
177
- export type SelectOptions = {
178
- id?: Select['custom_id'];
179
- custom_id?: Select['custom_id'];
180
- holder?: Select['placeholder'];
181
- min?: Select['min_values'];
182
- max?: Select['max_values'];
183
- type?: Select['type'];
184
- options: Select['options'];
185
- disabled?: Select['disabled'];
186
- }
187
-
188
- export type Modal = {
189
- title: string;
190
- custom_id: string;
191
- components: {
192
- type: number,
193
- components: {
194
- type: number;
195
- custom_id: string;
196
- label: string;
197
- style: 1 | 2 | number;
198
- min_length?: number;
199
- max_length?: number;
200
- required?: boolean;
201
- value?: string;
202
- placeholder?: string;
203
- }[]
204
- }[]
205
- }
206
-
207
- export type ModalOptions = {
208
- id?: Modal['custom_id'];
209
- custom_id?: Modal['custom_id'];
210
- title?: Modal['title'];
211
- label?: Modal['title'];
212
- components: Modal['components']
213
- }
214
-
215
-
216
- export function randomWeight(objects: object[]): object
217
- export function randomWords(options?: {
218
- exactly?: boolean;
219
- maxLength?: number;
220
- min?: number;
221
- max?: number;
222
- wordsPerString?: number;
223
- formatter(word: string): void;
224
- separator: string;
225
- join: string;
226
- }): string | string[]
227
-
228
- export async function fetch(url: string, key?: string, body?: any, postRequest?: boolean, returnRaw?: boolean): Promise<object|string|null>;
229
-
230
-
231
- export class Duration extends null {
232
- static get timeIds(): Set<string>;
233
- static validate(value: string): boolean;
234
- static parse(value: string): number | null;
235
- static determineTimeType(str: string): number;
236
- };
237
-
238
- export class Tasks extends null {
239
- static create(options: {
240
- id: string;
241
- time: string;
242
- shouldCancel?: boolean
243
- }, run: Function): void;
244
-
245
- static delete(id: string): void;
246
- }
247
- }
package/index.js DELETED
@@ -1,11 +0,0 @@
1
-
2
- exports.AES = require("./packages/aes256");
3
- exports.Minesweeper = require("./packages/minesweeper");
4
- exports.randomWords = require("./packages/random/words");
5
- exports.randomWeight = require("./packages/random/weight");
6
- exports.Languages = require("./packages/languages");
7
- exports.SlashBuilder = require("./packages/SlashBuilder");
8
- exports.Interactions = require("./packages/Interactions");
9
- exports.fetch = require("./packages/fetch");
10
- exports.Duration = require("./packages/duration");
11
- exports.Tasks = require("./packages/Tasks");
@@ -1,76 +0,0 @@
1
- module.exports = class Interactions extends null {
2
- static button(options = {}) {
3
- if (typeof options.style === "string") {
4
- let styles = { PRIMARY: 1, BLURPLE: 1, SECONDARY: 2, GREY: 2, SUCCESS: 3, GREEN: 3, DANGER: 4, RED: 4, LINK: 5, URL: 5 };
5
- let style = styles[options.style?.toUpperCase()];
6
- if (!style) options.style = 2;
7
- else options.style = style;
8
- };
9
- if (typeof options.url === "string" && options.url.match(/(https?|discord):\/\//gi)) {
10
- options.style = 5;
11
- options.id = "";
12
- }
13
- return {
14
- custom_id: options?.id ?? options?.custom_id ?? "",
15
- label: options?.title ?? options?.label ?? "",
16
- type: options?.type ?? 2,
17
- style: options?.style ? options.style : 2,
18
- disabled: Boolean(options.disabled),
19
- emoji: options?.emoji ?? undefined,
20
- url: options?.url ?? undefined
21
- };
22
- }
23
-
24
- static select(options = {}) {
25
- if (!options.options || !Array.isArray(options.options)) throw new Error(`[Dropdown#options]: isn't an array.`);
26
- return {
27
- custom_id: options?.id ?? options?.custom_id ?? "",
28
- placeholder: options?.holder ?? "",
29
- min_values: options?.min ?? 1,
30
- max_values: options?.max ?? 1,
31
- options: options?.options,
32
- type: options?.type ?? 3,
33
- disabled: typeof options?.disabled === "boolean" ? options.disabled : false
34
- }
35
- }
36
-
37
- static modal(options = {}) {
38
- if (!options.components || !Array.isArray(options.components)) throw new Error(`[Modal#components]: isn't an array!`);
39
- return {
40
- custom_id: options?.id ?? options?.custom_id,
41
- title: options?.title ?? options?.label,
42
- components: options.components
43
- };
44
- };
45
-
46
- static textInput(options = {}, row = false) {
47
- let data = {};
48
-
49
- if (options.type) data.type = options.type;
50
- else data.type = 4;
51
-
52
- if (options.id) data.custom_id = options.id;
53
- else if (options.custom_id) data.custom_id = options.custom_id;
54
-
55
- if (options.label) data.label = options.label;
56
- else if (options.title) data.label = options.title;
57
-
58
- if (options.style) data.style = options.style;
59
- else data.style = 1;
60
-
61
- if (options.min) data.min_length = options.min;
62
- else if (options.min_length) data.min_length = options.min_length;
63
-
64
- if (options.max) data.max_length = options.max;
65
- else if (options.max_length) data.max_length = options.max_length;
66
-
67
- if (options.holder) data.placeholder = options.holder;
68
- else if (options.placeholder) data.placeholder = options.placeholder;
69
-
70
- if (typeof options.required === "boolean") data.required = options.required;
71
- if (options.value) data.value = options.value;
72
-
73
- if (row) return data;
74
- return { type: 1, components: [ data ] };
75
- };
76
- };
@@ -1,58 +0,0 @@
1
- module.exports = class SlashBuilder extends null {
2
- static get TEXT_BASED_CHANNELS() {
3
- return [ 0, 5, 11, 12 ]
4
- }
5
-
6
- static get types() {
7
- return {
8
- sub_command: 1,
9
- sub_group: 2,
10
- string: 3,
11
- integer: 4,
12
- boolean: 5,
13
- user: 6,
14
- channel: 7,
15
- role: 8,
16
- mentionable: 9,
17
- number: 10,
18
- context: {
19
- user: 2,
20
- message: 3
21
- }
22
- };
23
- }
24
-
25
- static get context() {
26
- return {
27
- user: (name, options) => this.create(name, "", { type: this.types.context.user, ...options }),
28
- message: (name, options) => this.create(name, "", { type: this.types.context.message, ...options })
29
- }
30
- };
31
-
32
- static choice(name, value, name_localizations) {
33
- return { name, value, name_localizations };
34
- };
35
-
36
- static option(data) {
37
- let _data = { ...data };
38
- if (_data.locale?.names) _data.name_localizations = _data.locale.names;
39
- if (_data.locale?.descriptions) _data.description_localizations = _data.locale.descriptions;
40
- if ("locale" in _data) delete _data["locale"];
41
- return _data;
42
- };
43
-
44
- static create(name, description, options = { }) {
45
- let obj = { name, description };
46
- if (options?.locale?.names) obj.name_localizations = options.locale.names;
47
- if (options?.locale?.descriptions) obj.description_localizations = options.locale.descriptions;
48
- if (options?.options?.length) obj.options = options.options;
49
- if (options?.type) obj.type = options.type;
50
-
51
- if ("dmPermission" in options) obj.dm_permission = options.dmPermission;
52
- else if ("dm_permission" in options) obj.dm_permission = options.dm_permission;
53
-
54
- if ("default_member_permissions" in options) obj.default_member_permissions = options.default_member_permissions;
55
- else if ("defaultMemberPermissions" in options) obj.default_member_permissions = options.defaultMemberPermissions;
56
- return obj;
57
- };
58
- };
package/packages/Tasks.js DELETED
@@ -1,22 +0,0 @@
1
- let nodeSchedule;
2
-
3
- try {
4
- nodeSchedule = require("node-schedule");
5
- } catch { };
6
-
7
- module.exports = class Tasks extends null {
8
- static create({ id = "", time = "", shouldCancel = true } = {}, run) {
9
- if (!nodeSchedule) return `[Tasks:Create:ERROR]: I was unable to locate the 'node-schedule' package!`;
10
- if (!id || !time || !run) return `[Tasks:Create:ERROR]: You didn't provide a valid ID, Time or Run function`;
11
- if (nodeSchedule.scheduledJobs[id]) return `[Tasks:Create:ERROR]: Found (${id}) already in the scheduledJobs object.`;
12
- return nodeSchedule.scheduleJob(id, time, () => {
13
- run();
14
- if (shouldCancel) return nodeSchedule.cancelJob(id);
15
- });
16
- };
17
-
18
- static delete(id) {
19
- if (!nodeSchedule) return null;
20
- return nodeSchedule.cancelJob(id);
21
- };
22
- };
@@ -1,62 +0,0 @@
1
- const crypto = require("node:crypto"),
2
- CIPHER_ALGORITHM = 'aes-256-ctr';
3
-
4
- module.exports = class AES256 {
5
- constructor(key) {
6
- if (!key || typeof key !== "string") throw new Error(`${this.header} 'key' is invalid or not a string.`);
7
- /** @private */
8
- this.key = key;
9
- };
10
- /** @private */
11
- get header() {
12
- return `[SECURITY]:`;
13
- };
14
-
15
- encrypt(input) {
16
- let isString = typeof input === 'string',
17
- isBuffer = Buffer.isBuffer(input);
18
- if (!(isString || isBuffer) || (isString && !input) || (isBuffer && !Buffer.byteLength(input))) {
19
- throw new Error(`${this.header} Provided invalid 'input', must be a non-empty string or buffer.`);
20
- };
21
-
22
- let sha = crypto.createHash("sha256");
23
- sha.update(this.key);
24
-
25
- let iv = crypto.randomBytes(16),
26
- cipher = crypto.createCipheriv(CIPHER_ALGORITHM, sha.digest(), iv),
27
- buffer = input;
28
-
29
- if (isString) buffer = Buffer.from(input);
30
- let text = cipher.update(buffer),
31
- encrypted = Buffer.concat([ iv, text, cipher.final() ]);
32
-
33
- if (isString) encrypted = encrypted.toString('base64');
34
- return encrypted;
35
- };
36
-
37
- decrypt(encrypted) {
38
- let [ isString, isBuffer ] = [
39
- typeof encrypted === 'string',
40
- Buffer.isBuffer(encrypted)
41
- ];
42
- if (!(isString || isBuffer) || (isString && !encrypted) || (isBuffer && !Buffer.byteLength(encrypted))) throw new Error(`${this.header} Provided "encrypted" must be a non-empty string or buffer`);
43
- let sha256 = crypto.createHash('sha256');
44
- sha256.update(this.key);
45
-
46
- let input = encrypted;
47
- if (isString) {
48
- input = Buffer.from(encrypted, 'base64');
49
- if (input.length < 17) throw new Error(`${this.header} Provided "encrypted" must decrypt to a non-empty string or buffer`);
50
- } else {
51
- if (Buffer.byteLength(encrypted) < 17) throw new Error(`${this.header} Provided "encrypted" must decrypt to a non-empty string or buffer`);
52
- }
53
-
54
- let iv = input.slice(0, 16),
55
- decipher = crypto.createDecipheriv(CIPHER_ALGORITHM, sha256.digest(), iv),
56
- ciphertext = input.slice(16),
57
- output;
58
- if (isString) output = decipher.update(ciphertext) + decipher.final();
59
- else output = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
60
- return output;
61
- };
62
- };
@@ -1,74 +0,0 @@
1
- module.exports = class Duration extends null {
2
- static parse(value) {
3
- const MATCHES_ALL = value.match(/\d+\s*[A-Za-z]+/g);
4
- if (MATCHES_ALL) {
5
- let totalTime = 0;
6
- for (const dur of MATCHES_ALL) {
7
- const [ num, str ] = [
8
- parseInt(dur.match(/\d+/g)[0]),
9
- dur.match(/[A-Za-z]+/g)[0]
10
- ];
11
- if (isNaN(num)) totalTime = 0;
12
- else totalTime += num * module.exports.determineTimeType(str);
13
- }
14
- if (totalTime) return totalTime;
15
- }
16
-
17
- return null;
18
- };
19
-
20
- static determineTimeType(str) {
21
- switch (str) {
22
- case "ms": case "millisecond": case "milliseconds": return 1;
23
-
24
- case "s": case "second": case "seconds": return 1000;
25
-
26
- case "m": case "min": case "mins": case "minute": case "minutes": return 60 * 1000;
27
-
28
- case "h": case "hr": case "hour": case "hours": return 60 * 60 * 1000;
29
-
30
- case "d": case "day": case "days": return 24 * 60 * 60 * 1000;
31
-
32
- case "w": case "week": case "weeks": return 7 * 24 * 60 * 60 * 1000;
33
-
34
- case "mo": case "month": case "months": return 30 * 24 * 60 * 60 * 1000;
35
-
36
- case "y": case "year": case "years": return 365 * 24 * 60 * 60 * 1000;
37
-
38
- default: return 1;
39
- }
40
- };
41
-
42
- static validate(value) {
43
- const MATCHES_ALL = value.match(/\d+\s*[A-Za-z]+/g);
44
- if (MATCHES_ALL) {
45
- for (const match of MATCHES_ALL) {
46
- let [ num, str ] = [
47
- match.match(/\d+/g),
48
- match.match(/[A-Za-z]+/g)
49
- ]
50
- if (!num || (num.length !== 1)) return false;
51
- if (!str || (str.length !== 1)) return false;
52
- if (!Number.isInteger(parseInt(num[0]))) return false;
53
- if (!module.exports.timeIds.has(str[0])) return false;
54
- }
55
-
56
- return true;
57
- }
58
-
59
- return false;
60
- }
61
-
62
- static get timeIds() {
63
- return new Set([
64
- "ms", "millisecond", "milliseconds",
65
- "s", "second", "seconds",
66
- "m", "min", "mins", "minute", "minutes",
67
- "h", "hr", "hrs", "hour", "hours",
68
- "d", "day", "days",
69
- "w", "week", "weeks",
70
- "mo", "month", "months",
71
- "y", "year", "years"
72
- ])
73
- }
74
- }
package/packages/fetch.js DELETED
@@ -1,30 +0,0 @@
1
- let fetch;
2
-
3
- try {
4
- fetch = require("@elara-services/fetch");
5
- if ("fetch" in fetch) {
6
- fetch = fetch.fetch;
7
- }
8
- } catch {
9
-
10
- }
11
-
12
- module.exports = async (url, key = "", body = undefined, postRequest = false, returnRaw = false) => {
13
- if (!fetch) throw new Error(`Unable to find @elara-services/fetch package`);
14
- try {
15
- let headers = {
16
- "User-Agent": `Services v${Math.floor(Math.random() * 999999)}`
17
- };
18
- if (key !== "" && key) headers.Authorization = key;
19
- let res = await fetch(url, postRequest ? "POST" : "GET")
20
- .header(headers)
21
- .body(body, "json")
22
- .send()
23
- .catch(() => ({ statusCode: 500 }));
24
- if (res.statusCode !== 200) return null;
25
- if (returnRaw) return res.body;
26
- return res.json();
27
- } catch {
28
- return null;
29
- }
30
- }