@mkody/twitch-emoticons 3.0.0-beta.3 → 3.0.0-beta.4
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/README.md +5 -4
- package/dist/TwitchEmoticons.cjs +50 -38
- package/dist/TwitchEmoticons.esm.min.js +3 -3
- package/dist/TwitchEmoticons.esm.min.js.map +3 -3
- package/dist/TwitchEmoticons.min.js +3 -3
- package/dist/TwitchEmoticons.min.js.map +3 -3
- package/package.json +1 -1
- package/src/struct/BTTVEmote.js +14 -11
- package/src/struct/Emote.js +4 -3
- package/src/struct/EmoteFetcher.js +38 -17
- package/src/struct/FFZEmote.js +15 -12
- package/src/struct/SevenTVEmote.js +14 -14
- package/src/struct/TwitchEmote.js +15 -12
- package/typings/index.d.cts +105 -42
- package/typings/index.d.ts +105 -42
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ Gets Twitch, BTTV, FFZ and 7TV emotes as well as parsing text to emotes!
|
|
|
25
25
|
- The defaults for `EmoteParser` changed to use the `html` template, and it does not require `:colons:` by default (using `/(\w+)/` to match any words).
|
|
26
26
|
- The default `html` template does not have `twitch-emote-{size}` anymore in its `class` attribute.
|
|
27
27
|
*The `size` is inconsistent between the different sources, so it cannot be reliably used.*
|
|
28
|
+
- If you somehow used `EmoteFetcher.globalChannel`, it has now been removed.
|
|
28
29
|
- The `EmoteFetcher.fetchSevenTVEmotes()`, `Emote.toLink()`, and `EmoteParse.parse()` methods now have their options as an object.
|
|
29
30
|
- `fetcher.fetchSevenTVEmotes(null, { format: 'avif' })` - The first parameter is still the Twitch user ID (or `null` for global).
|
|
30
31
|
- `emote.toLink({ size: 1, forceStatic: true, themeMode: 'light' })`
|
|
@@ -122,12 +123,12 @@ pnpm add jsr:@mkody/twitch-emoticons
|
|
|
122
123
|
# or
|
|
123
124
|
yarn add jsr:@mkody/twitch-emoticons
|
|
124
125
|
# or (version has to be specified while it is a pre-release)
|
|
125
|
-
deno add jsr:@mkody/twitch-emoticons@3.0.0-beta.
|
|
126
|
+
deno add jsr:@mkody/twitch-emoticons@3.0.0-beta.4
|
|
126
127
|
```
|
|
127
128
|
|
|
128
|
-
[npm]: https://www.npmjs.com/package/@mkody/twitch-emoticons/v/3.0.0-beta.
|
|
129
|
-
[browse on npmx]: https://npmx.dev/package/@mkody/twitch-emoticons/v/3.0.0-beta.
|
|
130
|
-
[jsr]: https://jsr.io/@mkody/twitch-emoticons@3.0.0-beta.
|
|
129
|
+
[npm]: https://www.npmjs.com/package/@mkody/twitch-emoticons/v/3.0.0-beta.4
|
|
130
|
+
[browse on npmx]: https://npmx.dev/package/@mkody/twitch-emoticons/v/3.0.0-beta.4
|
|
131
|
+
[jsr]: https://jsr.io/@mkody/twitch-emoticons@3.0.0-beta.4
|
|
131
132
|
|
|
132
133
|
|
|
133
134
|
## Quick docs
|
package/dist/TwitchEmoticons.cjs
CHANGED
|
@@ -63,7 +63,7 @@ var Emote = class _Emote {
|
|
|
63
63
|
*/
|
|
64
64
|
/* c8 ignore next 3 */
|
|
65
65
|
toLink() {
|
|
66
|
-
return
|
|
66
|
+
return "";
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Override for `toString`.
|
|
@@ -83,7 +83,8 @@ var Emote = class _Emote {
|
|
|
83
83
|
return {
|
|
84
84
|
code: this.code,
|
|
85
85
|
id: this.id,
|
|
86
|
-
channel_id: this.channel
|
|
86
|
+
channel_id: this.channel?.channel_id || null,
|
|
87
|
+
type: this.type
|
|
87
88
|
};
|
|
88
89
|
}
|
|
89
90
|
};
|
|
@@ -185,8 +186,8 @@ var BTTVEmote = class _BTTVEmote extends Emote_default {
|
|
|
185
186
|
_setup(data) {
|
|
186
187
|
super._setup(data);
|
|
187
188
|
this.ownerName = "user" in data ? data.user.name : null;
|
|
188
|
-
this.animated = data.animated;
|
|
189
189
|
this.imageType = "webp";
|
|
190
|
+
this.animated = data.animated;
|
|
190
191
|
}
|
|
191
192
|
/**
|
|
192
193
|
* Gets the image link of the emote.
|
|
@@ -210,9 +211,9 @@ var BTTVEmote = class _BTTVEmote extends Emote_default {
|
|
|
210
211
|
toObject() {
|
|
211
212
|
return {
|
|
212
213
|
...super.toObject(),
|
|
213
|
-
|
|
214
|
+
type: this.type,
|
|
214
215
|
ownerName: this.ownerName,
|
|
215
|
-
|
|
216
|
+
animated: this.animated
|
|
216
217
|
};
|
|
217
218
|
}
|
|
218
219
|
/**
|
|
@@ -368,8 +369,8 @@ var FFZEmote = class _FFZEmote extends Emote_default {
|
|
|
368
369
|
this.code = data.name;
|
|
369
370
|
this.ownerName = "owner" in data ? data.owner.name : null;
|
|
370
371
|
this.sizes = "animated" in data ? Object.keys(data.animated) : Object.keys(data.urls);
|
|
371
|
-
this.animated = "animated" in data;
|
|
372
372
|
this.imageType = "animated" in data ? "webp" : "png";
|
|
373
|
+
this.animated = "animated" in data;
|
|
373
374
|
this.zeroWidth = data.modifier && data.modifier_flags === 0;
|
|
374
375
|
this.modifier = data.modifier && (data.modifier_flags & 1) !== 0;
|
|
375
376
|
}
|
|
@@ -397,10 +398,10 @@ var FFZEmote = class _FFZEmote extends Emote_default {
|
|
|
397
398
|
toObject() {
|
|
398
399
|
return {
|
|
399
400
|
...super.toObject(),
|
|
400
|
-
animated: this.animated,
|
|
401
|
-
sizes: this.sizes,
|
|
402
|
-
ownerName: this.ownerName,
|
|
403
401
|
type: this.type,
|
|
402
|
+
ownerName: this.ownerName,
|
|
403
|
+
sizes: this.sizes,
|
|
404
|
+
animated: this.animated,
|
|
404
405
|
zeroWidth: this.zeroWidth,
|
|
405
406
|
modifier: this.modifier
|
|
406
407
|
};
|
|
@@ -481,10 +482,10 @@ var SevenTVEmote = class _SevenTVEmote extends Emote_default {
|
|
|
481
482
|
if (this.sizes.length === 0) {
|
|
482
483
|
this.sizes = ["1", "2", "3", "4"];
|
|
483
484
|
}
|
|
485
|
+
this.imageType = this.channel.format;
|
|
484
486
|
this.animated = Boolean(data.data.animated);
|
|
485
|
-
this.nsfw = (data.data.flags & EmoteFlags.Sexual) !== 0 || (data.data.flags & EmoteFlags.TwitchDisallowed) !== 0;
|
|
486
487
|
this.zeroWidth = (data.flags & ActiveEmoteFlags.ZeroWidth) !== 0 || (data.data.flags & EmoteFlags.ZeroWidth) !== 0;
|
|
487
|
-
this.
|
|
488
|
+
this.nsfw = (data.data.flags & EmoteFlags.Sexual) !== 0 || (data.data.flags & EmoteFlags.TwitchDisallowed) !== 0;
|
|
488
489
|
}
|
|
489
490
|
/**
|
|
490
491
|
* Gets the image link of the emote.
|
|
@@ -509,13 +510,13 @@ var SevenTVEmote = class _SevenTVEmote extends Emote_default {
|
|
|
509
510
|
toObject() {
|
|
510
511
|
return {
|
|
511
512
|
...super.toObject(),
|
|
513
|
+
type: this.type,
|
|
514
|
+
ownerName: this.ownerName,
|
|
515
|
+
sizes: this.sizes,
|
|
516
|
+
imageType: this.imageType,
|
|
512
517
|
animated: this.animated,
|
|
513
|
-
nsfw: this.nsfw,
|
|
514
518
|
zeroWidth: this.zeroWidth,
|
|
515
|
-
|
|
516
|
-
ownerName: this.ownerName,
|
|
517
|
-
type: this.type,
|
|
518
|
-
imageType: this.imageType
|
|
519
|
+
nsfw: this.nsfw
|
|
519
520
|
};
|
|
520
521
|
}
|
|
521
522
|
/**
|
|
@@ -564,9 +565,9 @@ var TwitchEmote = class _TwitchEmote extends Emote_default {
|
|
|
564
565
|
}
|
|
565
566
|
_setup(data) {
|
|
566
567
|
super._setup(data);
|
|
567
|
-
this.set = data.emoticon_set;
|
|
568
|
-
this.animated = data.formats?.includes("animated") || false;
|
|
568
|
+
this.set = data.emoticon_set || null;
|
|
569
569
|
this.imageType = data.formats?.includes("animated") ? "gif" : "png";
|
|
570
|
+
this.animated = data.formats?.includes("animated") || false;
|
|
570
571
|
}
|
|
571
572
|
/**
|
|
572
573
|
* Gets the image link of the emote.
|
|
@@ -592,9 +593,9 @@ var TwitchEmote = class _TwitchEmote extends Emote_default {
|
|
|
592
593
|
toObject() {
|
|
593
594
|
return {
|
|
594
595
|
...super.toObject(),
|
|
595
|
-
|
|
596
|
+
type: this.type,
|
|
596
597
|
set: this.set,
|
|
597
|
-
|
|
598
|
+
animated: this.animated
|
|
598
599
|
};
|
|
599
600
|
}
|
|
600
601
|
/**
|
|
@@ -644,14 +645,6 @@ var EmoteFetcher = class {
|
|
|
644
645
|
this.channels = new Collection_default();
|
|
645
646
|
this.ffzModifiersFetched = false;
|
|
646
647
|
}
|
|
647
|
-
/**
|
|
648
|
-
* The global channel for Twitch, BTTV and 7TV.
|
|
649
|
-
* @readonly
|
|
650
|
-
* @type {?Channel}
|
|
651
|
-
*/
|
|
652
|
-
get globalChannel() {
|
|
653
|
-
return this.channels.get(null);
|
|
654
|
-
}
|
|
655
648
|
/**
|
|
656
649
|
* Sets up a channel
|
|
657
650
|
* @private
|
|
@@ -824,13 +817,17 @@ var EmoteFetcher = class {
|
|
|
824
817
|
* @returns {Promise<Collection<string, TwitchEmote>>} - A promise that resolves to a collection of TwitchEmotes.
|
|
825
818
|
*/
|
|
826
819
|
fetchTwitchEmotes(channel) {
|
|
820
|
+
if (!channel) channel = null;
|
|
827
821
|
return this._getRawTwitchEmotes(channel).then((rawEmotes) => {
|
|
828
822
|
for (const emote of rawEmotes) {
|
|
829
|
-
this._cacheTwitchEmote(
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
823
|
+
this._cacheTwitchEmote(
|
|
824
|
+
channel,
|
|
825
|
+
{
|
|
826
|
+
code: emote.name,
|
|
827
|
+
id: emote.id,
|
|
828
|
+
formats: emote.formats
|
|
829
|
+
}
|
|
830
|
+
);
|
|
834
831
|
}
|
|
835
832
|
return this.channels.get(channel).emotes.filter((e) => e.type === "twitch");
|
|
836
833
|
});
|
|
@@ -842,6 +839,7 @@ var EmoteFetcher = class {
|
|
|
842
839
|
* @returns {Promise<Collection<string, BTTVEmote>>} - A promise that resolves to a collection of BTTVEmotes.
|
|
843
840
|
*/
|
|
844
841
|
fetchBTTVEmotes(channel) {
|
|
842
|
+
if (!channel) channel = null;
|
|
845
843
|
return this._getRawBTTVEmotes(channel).then((rawEmotes) => {
|
|
846
844
|
for (const data of rawEmotes) {
|
|
847
845
|
this._cacheBTTVEmote(channel, data);
|
|
@@ -855,6 +853,7 @@ var EmoteFetcher = class {
|
|
|
855
853
|
* @returns {Promise<Collection<string, FFZEmote>>} - A promise that resolves to a collection of FFZEmotes.
|
|
856
854
|
*/
|
|
857
855
|
async fetchFFZEmotes(channel) {
|
|
856
|
+
if (!channel) channel = null;
|
|
858
857
|
if (!this.ffzModifiersFetched) {
|
|
859
858
|
this.ffzModifiersFetched = true;
|
|
860
859
|
await this._getRawFFZEmoteSet(Constants_default.FFZ.sets.Modifiers).then((rawEmotes) => {
|
|
@@ -886,6 +885,7 @@ var EmoteFetcher = class {
|
|
|
886
885
|
* @returns {Promise<Collection<string, SevenTVEmote>>} - A promise that resolves to a collection of SevenTVEmotes.
|
|
887
886
|
*/
|
|
888
887
|
fetchSevenTVEmotes(channel, options) {
|
|
888
|
+
if (!channel) channel = null;
|
|
889
889
|
const {
|
|
890
890
|
format = "webp"
|
|
891
891
|
} = options || {};
|
|
@@ -899,17 +899,29 @@ var EmoteFetcher = class {
|
|
|
899
899
|
}
|
|
900
900
|
/**
|
|
901
901
|
* Converts emote Objects to emotes
|
|
902
|
-
* @param {object} [emotesArray] - An array of emote objects
|
|
902
|
+
* @param {object[]} [emotesArray] - An array of emote objects
|
|
903
903
|
* @throws {TypeError} When an emote has an unknown type.
|
|
904
904
|
* @returns {Emote[]} - An array of Emote instances.
|
|
905
905
|
*/
|
|
906
906
|
fromObject(emotesArray) {
|
|
907
907
|
const emotes = [];
|
|
908
908
|
const classMap = {
|
|
909
|
-
"bttv": {
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
909
|
+
"bttv": {
|
|
910
|
+
class: BTTVEmote_default,
|
|
911
|
+
cache: (_, channelId, existingEmote) => this._cacheBTTVEmote(channelId, null, existingEmote)
|
|
912
|
+
},
|
|
913
|
+
"ffz": {
|
|
914
|
+
class: FFZEmote_default,
|
|
915
|
+
cache: (_, channelId, existingEmote) => this._cacheFFZEmote(channelId, null, existingEmote)
|
|
916
|
+
},
|
|
917
|
+
"7tv": {
|
|
918
|
+
class: SevenTVEmote_default,
|
|
919
|
+
cache: (emoteObject, channelId, existingEmote) => this._cacheSevenTVEmote(channelId, null, emoteObject.imageType, existingEmote)
|
|
920
|
+
},
|
|
921
|
+
"twitch": {
|
|
922
|
+
class: TwitchEmote_default,
|
|
923
|
+
cache: (_, channelId, existingEmote) => this._cacheTwitchEmote(channelId, null, existingEmote)
|
|
924
|
+
}
|
|
913
925
|
};
|
|
914
926
|
for (const emoteObject of emotesArray) {
|
|
915
927
|
const { type } = emoteObject;
|