@discordjs/builders 0.15.0-dev.1654430642-7a1095b → 0.15.0-dev.1654517016-e1176fa
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.
- package/dist/index.d.ts +15 -12
- package/dist/index.js +33 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -80,6 +80,14 @@ var embedFooterPredicate = s.object({
|
|
|
80
80
|
var timestampPredicate = s.union(s.number, s.date).nullable;
|
|
81
81
|
var titlePredicate = fieldNamePredicate.nullable;
|
|
82
82
|
|
|
83
|
+
// src/util/normalizeArray.ts
|
|
84
|
+
function normalizeArray(arr) {
|
|
85
|
+
if (Array.isArray(arr[0]))
|
|
86
|
+
return arr[0];
|
|
87
|
+
return arr;
|
|
88
|
+
}
|
|
89
|
+
__name(normalizeArray, "normalizeArray");
|
|
90
|
+
|
|
83
91
|
// src/messages/embed/UnsafeEmbed.ts
|
|
84
92
|
var UnsafeEmbedBuilder = class {
|
|
85
93
|
constructor(data = {}) {
|
|
@@ -88,7 +96,8 @@ var UnsafeEmbedBuilder = class {
|
|
|
88
96
|
if (data.timestamp)
|
|
89
97
|
this.data.timestamp = new Date(data.timestamp).toISOString();
|
|
90
98
|
}
|
|
91
|
-
addFields(fields) {
|
|
99
|
+
addFields(...fields) {
|
|
100
|
+
fields = normalizeArray(fields);
|
|
92
101
|
if (this.data.fields)
|
|
93
102
|
this.data.fields.push(...fields);
|
|
94
103
|
else
|
|
@@ -102,8 +111,8 @@ var UnsafeEmbedBuilder = class {
|
|
|
102
111
|
this.data.fields = fields;
|
|
103
112
|
return this;
|
|
104
113
|
}
|
|
105
|
-
setFields(fields) {
|
|
106
|
-
this.spliceFields(0, this.data.fields?.length ?? 0, ...fields);
|
|
114
|
+
setFields(...fields) {
|
|
115
|
+
this.spliceFields(0, this.data.fields?.length ?? 0, ...normalizeArray(fields));
|
|
107
116
|
return this;
|
|
108
117
|
}
|
|
109
118
|
setAuthor(options) {
|
|
@@ -163,9 +172,10 @@ __name(UnsafeEmbedBuilder, "UnsafeEmbedBuilder");
|
|
|
163
172
|
|
|
164
173
|
// src/messages/embed/Embed.ts
|
|
165
174
|
var EmbedBuilder = class extends UnsafeEmbedBuilder {
|
|
166
|
-
addFields(fields) {
|
|
175
|
+
addFields(...fields) {
|
|
176
|
+
fields = normalizeArray(fields);
|
|
167
177
|
validateFieldLength(fields.length, this.data.fields);
|
|
168
|
-
return super.addFields(embedFieldsArrayPredicate.parse(fields));
|
|
178
|
+
return super.addFields(...embedFieldsArrayPredicate.parse(fields));
|
|
169
179
|
}
|
|
170
180
|
spliceFields(index, deleteCount, ...fields) {
|
|
171
181
|
validateFieldLength(fields.length - deleteCount, this.data.fields);
|
|
@@ -448,12 +458,12 @@ var ActionRowBuilder = class extends ComponentBuilder {
|
|
|
448
458
|
__publicField(this, "components");
|
|
449
459
|
this.components = components?.map((c) => createComponentBuilder(c)) ?? [];
|
|
450
460
|
}
|
|
451
|
-
addComponents(components) {
|
|
452
|
-
this.components.push(...components);
|
|
461
|
+
addComponents(...components) {
|
|
462
|
+
this.components.push(...normalizeArray(components));
|
|
453
463
|
return this;
|
|
454
464
|
}
|
|
455
|
-
setComponents(components) {
|
|
456
|
-
this.components.splice(0, this.components.length, ...components);
|
|
465
|
+
setComponents(...components) {
|
|
466
|
+
this.components.splice(0, this.components.length, ...normalizeArray(components));
|
|
457
467
|
return this;
|
|
458
468
|
}
|
|
459
469
|
toJSON() {
|
|
@@ -653,12 +663,12 @@ var UnsafeModalBuilder = class {
|
|
|
653
663
|
this.data.custom_id = customId;
|
|
654
664
|
return this;
|
|
655
665
|
}
|
|
656
|
-
addComponents(components) {
|
|
657
|
-
this.components.push(...components.map((component) => component instanceof ActionRowBuilder ? component : new ActionRowBuilder(component)));
|
|
666
|
+
addComponents(...components) {
|
|
667
|
+
this.components.push(...normalizeArray(components).map((component) => component instanceof ActionRowBuilder ? component : new ActionRowBuilder(component)));
|
|
658
668
|
return this;
|
|
659
669
|
}
|
|
660
|
-
setComponents(components) {
|
|
661
|
-
this.components.splice(0, this.components.length, ...components);
|
|
670
|
+
setComponents(...components) {
|
|
671
|
+
this.components.splice(0, this.components.length, ...normalizeArray(components));
|
|
662
672
|
return this;
|
|
663
673
|
}
|
|
664
674
|
toJSON() {
|
|
@@ -731,12 +741,12 @@ var UnsafeSelectMenuBuilder = class extends ComponentBuilder {
|
|
|
731
741
|
this.data.disabled = disabled;
|
|
732
742
|
return this;
|
|
733
743
|
}
|
|
734
|
-
addOptions(options) {
|
|
735
|
-
this.options.push(...options.map((option) => option instanceof UnsafeSelectMenuOptionBuilder ? option : new UnsafeSelectMenuOptionBuilder(option)));
|
|
744
|
+
addOptions(...options) {
|
|
745
|
+
this.options.push(...normalizeArray(options).map((option) => option instanceof UnsafeSelectMenuOptionBuilder ? option : new UnsafeSelectMenuOptionBuilder(option)));
|
|
736
746
|
return this;
|
|
737
747
|
}
|
|
738
|
-
setOptions(options) {
|
|
739
|
-
this.options.splice(0, this.options.length, ...options.map((option) => option instanceof UnsafeSelectMenuOptionBuilder ? option : new UnsafeSelectMenuOptionBuilder(option)));
|
|
748
|
+
setOptions(...options) {
|
|
749
|
+
this.options.splice(0, this.options.length, ...normalizeArray(options).map((option) => option instanceof UnsafeSelectMenuOptionBuilder ? option : new UnsafeSelectMenuOptionBuilder(option)));
|
|
740
750
|
return this;
|
|
741
751
|
}
|
|
742
752
|
toJSON() {
|
|
@@ -765,12 +775,14 @@ var SelectMenuBuilder = class extends UnsafeSelectMenuBuilder {
|
|
|
765
775
|
setDisabled(disabled = true) {
|
|
766
776
|
return super.setDisabled(disabledValidator.parse(disabled));
|
|
767
777
|
}
|
|
768
|
-
addOptions(options) {
|
|
778
|
+
addOptions(...options) {
|
|
779
|
+
options = normalizeArray(options);
|
|
769
780
|
optionsLengthValidator.parse(this.options.length + options.length);
|
|
770
781
|
this.options.push(...options.map((option) => option instanceof UnsafeSelectMenuOptionBuilder ? option : new UnsafeSelectMenuOptionBuilder(optionValidator.parse(option))));
|
|
771
782
|
return this;
|
|
772
783
|
}
|
|
773
|
-
setOptions(options) {
|
|
784
|
+
setOptions(...options) {
|
|
785
|
+
options = normalizeArray(options);
|
|
774
786
|
optionsLengthValidator.parse(options.length);
|
|
775
787
|
this.options.splice(0, this.options.length, ...options.map((option) => option instanceof UnsafeSelectMenuOptionBuilder ? option : new UnsafeSelectMenuOptionBuilder(optionValidator.parse(option))));
|
|
776
788
|
return this;
|
|
@@ -1596,6 +1608,7 @@ export {
|
|
|
1596
1608
|
isEquatable,
|
|
1597
1609
|
isJSONEncodable,
|
|
1598
1610
|
italic,
|
|
1611
|
+
normalizeArray,
|
|
1599
1612
|
quote,
|
|
1600
1613
|
roleMention,
|
|
1601
1614
|
spoiler,
|