@zoodogood/utils 1.0.7-change.903 → 1.0.9-change.946

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.
@@ -0,0 +1,17 @@
1
+ export type APIBaseButton = import("discord-api-types/v10").APIButtonComponentBase<any>;
2
+ /**
3
+ * @typedef {import("discord-api-types/v10").APIButtonComponentBase} APIBaseButton
4
+ */
5
+ /**
6
+ *
7
+ * @param {APIBaseButton[]} resolable
8
+ */
9
+ export function justButtonComponents(resolable: import("discord-api-types/v10").APIButtonComponentBase<any>[]): {
10
+ label?: string | undefined;
11
+ style: any;
12
+ emoji?: import("discord-api-types/v10").APIMessageComponentEmoji | undefined;
13
+ disabled?: boolean | undefined;
14
+ type: import("discord-api-types/v10").ComponentType.Button;
15
+ customId: string;
16
+ }[];
17
+ export function justSendMessage(target: any, options: any): Promise<any>;
@@ -0,0 +1,48 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { BaseInteraction, ButtonStyle, ComponentType } from "discord.js";
11
+ import { CreateMessage } from "./simplify.js";
12
+ const DEFAULTS_FOR_BUTTON = {
13
+ type: ComponentType.Button,
14
+ style: ButtonStyle.Secondary,
15
+ };
16
+ /**
17
+ * @typedef {import("discord-api-types/v10").APIButtonComponentBase} APIBaseButton
18
+ */
19
+ /**
20
+ *
21
+ * @param {APIBaseButton[]} resolable
22
+ */
23
+ function justButtonComponents(resolable) {
24
+ const buttons = resolable.map((data, i) => (Object.assign(Object.assign(Object.assign({}, DEFAULTS_FOR_BUTTON), { customId: `button.${i + 1}` }), data)));
25
+ return buttons;
26
+ }
27
+ function justSendMessage(target, options) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const messagePayload = CreateMessage(options);
30
+ const message = target instanceof BaseInteraction
31
+ ? yield (options.edit
32
+ ? target.replied
33
+ ? target.editReply(messagePayload)
34
+ : target.update(messagePayload)
35
+ : target.reply(messagePayload))
36
+ : yield (options.edit
37
+ ? target.edit(messagePayload)
38
+ : target.send(messagePayload));
39
+ if (options.delete) {
40
+ setTimeout(() => message.delete(), options.delete);
41
+ }
42
+ if (options.reactions) {
43
+ options.reactions.filter(Boolean).forEach((react) => message.react(react));
44
+ }
45
+ return message;
46
+ });
47
+ }
48
+ export { justButtonComponents, justSendMessage };
@@ -1,54 +1,2 @@
1
- /**
2
- * Create a message object for Discord.
3
- *
4
- * @param {Object} params = Parameters for creating the message.
5
- * @param {string} [params.content] - The message content.
6
- * @param {string} [params.title] - The title of the embed.
7
- * @param {string} [params.url] - The URL of the embed.
8
- * @param {Object} [params.author] - The author of the embed.
9
- * @param {string} [params.thumbnail] - The thumbnail URL of the embed.
10
- * @param {string} [params.description] - The description of the embed.
11
- * @param {string} [params.color] - The color of the embed.
12
- * @param {Object[]} [params.fields] - The fields of the embed.
13
- * @param {string} [params.image] - The image URL of the embed.
14
- * @param {string} [params.video] - The video URL of the embed.
15
- * @param {Object} [params.footer] - The footer of the embed.
16
- * @param {string} [params.timestamp] - The timestamp of the embed.
17
- * @param {boolean} [params.ephemeral] - Whether the message should be ephemeral.
18
- * @param {boolean} [params.fetchReply] - Whether to fetch the message reply.
19
- * @param {Object[] | Object} [params.components] - The message components.
20
- * @param {Object[] | Object[]} [params.files] - The message files.
21
- * @param {string} [params.reference] - The message reference.
22
- * @returns {Object} - The message object.
23
- */
24
- export function CreateMessage({ content, title, url, author, thumbnail, description, color, fields, image, video, footer, timestamp, ephemeral, fetchReply, components, files, reference, }: {
25
- content?: string | undefined;
26
- title?: string | undefined;
27
- url?: string | undefined;
28
- author?: Object | undefined;
29
- thumbnail?: string | undefined;
30
- description?: string | undefined;
31
- color?: string | undefined;
32
- fields?: Object[] | undefined;
33
- image?: string | undefined;
34
- video?: string | undefined;
35
- footer?: Object | undefined;
36
- timestamp?: string | undefined;
37
- ephemeral?: boolean | undefined;
38
- fetchReply?: boolean | undefined;
39
- components?: Object | Object[] | undefined;
40
- files?: Object[] | undefined;
41
- reference?: string | undefined;
42
- }): Object;
43
- export function CreateModal({ title, customId, components }: {
44
- title: any;
45
- customId: any;
46
- components: any;
47
- }): import("discord.js").APIModalInteractionResponseCallbackData;
48
- export function SimplifyComponents(data: any): any;
49
- /**
50
- *
51
- * @param {*} embed
52
- * @returns {boolean}
53
- */
54
- export function isEmptyEmbed(embed: any): boolean;
1
+ export * from "./helpers.js";
2
+ export * from "./simplify.js";
@@ -1,116 +1,2 @@
1
- import { EmbedBuilder, ModalBuilder, resolveColor, ActionRow, } from "discord.js";
2
- import { ComponentType } from "discord-api-types/v10";
3
- /**
4
- *
5
- * @param {*} embed
6
- * @returns {boolean}
7
- */
8
- function isEmptyEmbed(embed) {
9
- const DEFAULT_PROPERTIES = {
10
- title: undefined,
11
- author: undefined,
12
- thumbnail: undefined,
13
- description: undefined,
14
- fields: undefined,
15
- image: undefined,
16
- footer: undefined,
17
- timestamp: undefined,
18
- video: undefined,
19
- };
20
- // in isEmptyEmbed context is a good compare
21
- const isEqualDefault = (key) => String(embed[key]) === String(DEFAULT_PROPERTIES[key]);
22
- const isEveryPropertyDefault = Object.keys(DEFAULT_PROPERTIES).every(isEqualDefault);
23
- return isEveryPropertyDefault;
24
- }
25
- /**
26
- * Create a message object for Discord.
27
- *
28
- * @param {Object} params = Parameters for creating the message.
29
- * @param {string} [params.content] - The message content.
30
- * @param {string} [params.title] - The title of the embed.
31
- * @param {string} [params.url] - The URL of the embed.
32
- * @param {Object} [params.author] - The author of the embed.
33
- * @param {string} [params.thumbnail] - The thumbnail URL of the embed.
34
- * @param {string} [params.description] - The description of the embed.
35
- * @param {string} [params.color] - The color of the embed.
36
- * @param {Object[]} [params.fields] - The fields of the embed.
37
- * @param {string} [params.image] - The image URL of the embed.
38
- * @param {string} [params.video] - The video URL of the embed.
39
- * @param {Object} [params.footer] - The footer of the embed.
40
- * @param {string} [params.timestamp] - The timestamp of the embed.
41
- * @param {boolean} [params.ephemeral] - Whether the message should be ephemeral.
42
- * @param {boolean} [params.fetchReply] - Whether to fetch the message reply.
43
- * @param {Object[] | Object} [params.components] - The message components.
44
- * @param {Object[] | Object[]} [params.files] - The message files.
45
- * @param {string} [params.reference] - The message reference.
46
- * @returns {Object} - The message object.
47
- */
48
- function CreateMessage({ content, title, url, author, thumbnail, description, color, fields, image, video, footer, timestamp, ephemeral, fetchReply, components, files, reference, }) {
49
- const message = {};
50
- thumbnail && (thumbnail = { url: thumbnail });
51
- image && (image = { url: image });
52
- video && (video = { url: video });
53
- color = resolveColor(color !== null && color !== void 0 ? color : "Random");
54
- const embed = new EmbedBuilder({
55
- title,
56
- url,
57
- author,
58
- thumbnail,
59
- description,
60
- color,
61
- fields,
62
- image,
63
- video,
64
- footer,
65
- timestamp,
66
- });
67
- if (!isEmptyEmbed(embed.data)) {
68
- message.embeds = [embed];
69
- }
70
- if (files) {
71
- message.files = files;
72
- }
73
- if (reference)
74
- message.reply = {
75
- messageReference: reference,
76
- };
77
- message.components = components ? SimplifyComponents(components) : null;
78
- message.content = content;
79
- message.ephemeral = ephemeral;
80
- message.fetchReply = fetchReply;
81
- return message;
82
- }
83
- function CreateModal({ title, customId, components }) {
84
- components = SimplifyComponents(components);
85
- return new ModalBuilder({ title, customId, components }).toJSON();
86
- }
87
- function SimplifyComponents(data) {
88
- if (data instanceof Array && data.length === 0)
89
- return [];
90
- const isComponent = (component) => "type" in component && component.type !== ComponentType.ActionRow;
91
- const isActionRow = (component) => (component instanceof Array && isComponent(component.at(0))) ||
92
- component instanceof ActionRow;
93
- const isComponents = (component) => component instanceof Array && isActionRow(component.at(0));
94
- const argumentType = [
95
- isComponent(data),
96
- isActionRow(data),
97
- isComponents(data),
98
- ].findIndex(Boolean);
99
- if (argumentType === -1)
100
- throw new TypeError("expected component");
101
- const wrapToArray = (component) => [component];
102
- const arrayToActionRow = (componentsArray) => {
103
- const isActionRow = "type" in componentsArray &&
104
- componentsArray.type === ComponentType.ActionRow;
105
- if (isActionRow)
106
- return componentsArray;
107
- return { type: ComponentType.ActionRow, components: componentsArray };
108
- };
109
- if (argumentType <= 0)
110
- data = wrapToArray(data);
111
- if (argumentType <= 1)
112
- data = wrapToArray(data);
113
- data = data.map(arrayToActionRow);
114
- return data;
115
- }
116
- export { CreateMessage, CreateModal, SimplifyComponents, isEmptyEmbed };
1
+ export * from "./helpers.js";
2
+ export * from "./simplify.js";
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Create a message object for Discord.
3
+ *
4
+ * @param {Object} params = Parameters for creating the message.
5
+ * @param {string} [params.content] - The message content.
6
+ * @param {string} [params.title] - The title of the embed.
7
+ * @param {string} [params.url] - The URL of the embed.
8
+ * @param {Object} [params.author] - The author of the embed.
9
+ * @param {string} [params.thumbnail] - The thumbnail URL of the embed.
10
+ * @param {string} [params.description] - The description of the embed.
11
+ * @param {string} [params.color] - The color of the embed.
12
+ * @param {Object[]} [params.fields] - The fields of the embed.
13
+ * @param {string} [params.image] - The image URL of the embed.
14
+ * @param {string} [params.video] - The video URL of the embed.
15
+ * @param {Object} [params.footer] - The footer of the embed.
16
+ * @param {string} [params.timestamp] - The timestamp of the embed.
17
+ * @param {boolean} [params.ephemeral] - Whether the message should be ephemeral.
18
+ * @param {boolean} [params.fetchReply] - Whether to fetch the message reply.
19
+ * @param {Object[] | Object} [params.components] - The message components.
20
+ * @param {Object[] | Object[]} [params.files] - The message files.
21
+ * @param {string} [params.reference] - The message reference.
22
+ * @returns {Object} - The message object.
23
+ */
24
+ export function CreateMessage({ content, title, url, author, thumbnail, description, color, fields, image, video, footer, timestamp, ephemeral, fetchReply, components, files, reference, }: {
25
+ content?: string | undefined;
26
+ title?: string | undefined;
27
+ url?: string | undefined;
28
+ author?: Object | undefined;
29
+ thumbnail?: string | undefined;
30
+ description?: string | undefined;
31
+ color?: string | undefined;
32
+ fields?: Object[] | undefined;
33
+ image?: string | undefined;
34
+ video?: string | undefined;
35
+ footer?: Object | undefined;
36
+ timestamp?: string | undefined;
37
+ ephemeral?: boolean | undefined;
38
+ fetchReply?: boolean | undefined;
39
+ components?: Object | Object[] | undefined;
40
+ files?: Object[] | undefined;
41
+ reference?: string | undefined;
42
+ }): Object;
43
+ export function CreateModal({ title, customId, components }: {
44
+ title: any;
45
+ customId: any;
46
+ components: any;
47
+ }): import("discord.js").APIModalInteractionResponseCallbackData;
48
+ export function SimplifyComponents(data: any): any;
49
+ /**
50
+ *
51
+ * @param {*} embed
52
+ * @returns {boolean}
53
+ */
54
+ export function isEmptyEmbed(embed: any): boolean;
@@ -0,0 +1,116 @@
1
+ import { EmbedBuilder, ModalBuilder, resolveColor, ActionRow, } from "discord.js";
2
+ import { ComponentType } from "discord-api-types/v10";
3
+ /**
4
+ *
5
+ * @param {*} embed
6
+ * @returns {boolean}
7
+ */
8
+ function isEmptyEmbed(embed) {
9
+ const DEFAULT_PROPERTIES = {
10
+ title: undefined,
11
+ author: undefined,
12
+ thumbnail: undefined,
13
+ description: undefined,
14
+ fields: undefined,
15
+ image: undefined,
16
+ footer: undefined,
17
+ timestamp: undefined,
18
+ video: undefined,
19
+ };
20
+ // in isEmptyEmbed context is a good compare
21
+ const isEqualDefault = (key) => String(embed[key]) === String(DEFAULT_PROPERTIES[key]);
22
+ const isEveryPropertyDefault = Object.keys(DEFAULT_PROPERTIES).every(isEqualDefault);
23
+ return isEveryPropertyDefault;
24
+ }
25
+ /**
26
+ * Create a message object for Discord.
27
+ *
28
+ * @param {Object} params = Parameters for creating the message.
29
+ * @param {string} [params.content] - The message content.
30
+ * @param {string} [params.title] - The title of the embed.
31
+ * @param {string} [params.url] - The URL of the embed.
32
+ * @param {Object} [params.author] - The author of the embed.
33
+ * @param {string} [params.thumbnail] - The thumbnail URL of the embed.
34
+ * @param {string} [params.description] - The description of the embed.
35
+ * @param {string} [params.color] - The color of the embed.
36
+ * @param {Object[]} [params.fields] - The fields of the embed.
37
+ * @param {string} [params.image] - The image URL of the embed.
38
+ * @param {string} [params.video] - The video URL of the embed.
39
+ * @param {Object} [params.footer] - The footer of the embed.
40
+ * @param {string} [params.timestamp] - The timestamp of the embed.
41
+ * @param {boolean} [params.ephemeral] - Whether the message should be ephemeral.
42
+ * @param {boolean} [params.fetchReply] - Whether to fetch the message reply.
43
+ * @param {Object[] | Object} [params.components] - The message components.
44
+ * @param {Object[] | Object[]} [params.files] - The message files.
45
+ * @param {string} [params.reference] - The message reference.
46
+ * @returns {Object} - The message object.
47
+ */
48
+ function CreateMessage({ content, title, url, author, thumbnail, description, color, fields, image, video, footer, timestamp, ephemeral, fetchReply, components, files, reference, }) {
49
+ const message = {};
50
+ thumbnail && (thumbnail = { url: thumbnail });
51
+ image && (image = { url: image });
52
+ video && (video = { url: video });
53
+ color = resolveColor(color !== null && color !== void 0 ? color : "Random");
54
+ const embed = new EmbedBuilder({
55
+ title,
56
+ url,
57
+ author,
58
+ thumbnail,
59
+ description,
60
+ color,
61
+ fields,
62
+ image,
63
+ video,
64
+ footer,
65
+ timestamp,
66
+ });
67
+ if (!isEmptyEmbed(embed.data)) {
68
+ message.embeds = [embed];
69
+ }
70
+ if (files) {
71
+ message.files = files;
72
+ }
73
+ if (reference)
74
+ message.reply = {
75
+ messageReference: reference,
76
+ };
77
+ message.components = components ? SimplifyComponents(components) : null;
78
+ message.content = content;
79
+ message.ephemeral = ephemeral;
80
+ message.fetchReply = fetchReply;
81
+ return message;
82
+ }
83
+ function CreateModal({ title, customId, components }) {
84
+ components = SimplifyComponents(components);
85
+ return new ModalBuilder({ title, customId, components }).toJSON();
86
+ }
87
+ function SimplifyComponents(data) {
88
+ if (data instanceof Array && data.length === 0)
89
+ return [];
90
+ const isComponent = (component) => "type" in component && component.type !== ComponentType.ActionRow;
91
+ const isActionRow = (component) => (component instanceof Array && isComponent(component.at(0))) ||
92
+ component instanceof ActionRow;
93
+ const isComponents = (component) => component instanceof Array && isActionRow(component.at(0));
94
+ const argumentType = [
95
+ isComponent(data),
96
+ isActionRow(data),
97
+ isComponents(data),
98
+ ].findIndex(Boolean);
99
+ if (argumentType === -1)
100
+ throw new TypeError("expected component");
101
+ const wrapToArray = (component) => [component];
102
+ const arrayToActionRow = (componentsArray) => {
103
+ const isActionRow = "type" in componentsArray &&
104
+ componentsArray.type === ComponentType.ActionRow;
105
+ if (isActionRow)
106
+ return componentsArray;
107
+ return { type: ComponentType.ActionRow, components: componentsArray };
108
+ };
109
+ if (argumentType <= 0)
110
+ data = wrapToArray(data);
111
+ if (argumentType <= 1)
112
+ data = wrapToArray(data);
113
+ data = data.map(arrayToActionRow);
114
+ return data;
115
+ }
116
+ export { CreateMessage, CreateModal, SimplifyComponents, isEmptyEmbed };
@@ -2,8 +2,8 @@ export * from './TextTableBuilder.js';
2
2
  function ending(quantity = 0, base, multiple, alone, double, options = {}) {
3
3
  if (isNaN(quantity))
4
4
  return NaN;
5
- const numbers = quantity % 100 > 20 ? quantity % 20 : quantity % 10;
6
- const end = numbers >= 5 || numbers === 0 ? multiple : numbers > 1 ? double : alone;
5
+ const target = quantity % 100 < 20 ? quantity % 20 : quantity % 10;
6
+ const end = target >= 5 || target === 0 ? multiple : target > 1 ? double : alone;
7
7
  const word = base + end;
8
8
  options.unite || (options.unite = (quantity, word) => `${quantity} ${word}`);
9
9
  const input = options.unite(quantity, word);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zoodogood/utils",
3
3
  "type": "module",
4
- "version": "1.0.7-change.903",
4
+ "version": "1.0.9-change.946",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -30,13 +30,20 @@
30
30
  "license": "ISC",
31
31
  "devDependencies": {
32
32
  "@types/node": "^20.5.9",
33
+ "@typescript-eslint/eslint-plugin": "^6.13.1",
34
+ "@typescript-eslint/parser": "^6.13.1",
35
+ "discord-api-types": "^0.37.65",
33
36
  "discord.js": "^14.13.0",
37
+ "eslint": "^8.54.0",
38
+ "eslint-config-prettier": "^9.0.0",
39
+ "eslint-plugin-prettier": "^5.0.1",
40
+ "prettier": "^3.1.0",
34
41
  "retypeapp-linux-x64": "^3.3.0",
35
42
  "typescript": "^5.2.2",
36
43
  "vitest": "^0.34.5"
37
44
  },
38
45
  "peerDependencies": {
39
- "discord.js": "=>14.x.x"
46
+ "discord.js": ">=14.x.x"
40
47
  },
41
48
  "files": [
42
49
  "/lib/**/*"