@mkody/twitch-emoticons 2.7.0 → 2.8.0

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 (45) hide show
  1. package/.eslintrc.json +143 -143
  2. package/.github/codeql/codeql-config.yml +4 -4
  3. package/.github/workflows/codeql.yml +50 -50
  4. package/.github/workflows/eslint.yml +50 -50
  5. package/.github/workflows/release.yml +22 -0
  6. package/.github/workflows/yarn-test.yml +17 -17
  7. package/.jsdoc.json +39 -39
  8. package/.nvmrc +1 -0
  9. package/LICENSE +22 -22
  10. package/README.md +36 -4
  11. package/docs/BTTVEmote.html +1641 -1319
  12. package/docs/Channel.html +823 -823
  13. package/docs/Collection.html +797 -797
  14. package/docs/Emote.html +906 -801
  15. package/docs/EmoteFetcher.html +3680 -2946
  16. package/docs/EmoteParser.html +811 -811
  17. package/docs/FFZEmote.html +1795 -1473
  18. package/docs/SevenTV.html +1190 -1190
  19. package/docs/SevenTVEmote.html +1705 -1395
  20. package/docs/TwitchEmote.html +1637 -1315
  21. package/docs/index.html +230 -206
  22. package/docs/struct_BTTVEmote.js.html +162 -132
  23. package/docs/struct_Channel.js.html +127 -127
  24. package/docs/struct_Emote.js.html +151 -138
  25. package/docs/struct_EmoteFetcher.js.html +427 -399
  26. package/docs/struct_EmoteParser.js.html +153 -153
  27. package/docs/struct_FFZEmote.js.html +185 -146
  28. package/docs/struct_SevenTVEmote.js.html +178 -141
  29. package/docs/struct_TwitchEmote.js.html +159 -130
  30. package/docs/util_Collection.js.html +150 -150
  31. package/package.json +57 -57
  32. package/src/index.js +12 -12
  33. package/src/struct/BTTVEmote.js +90 -60
  34. package/src/struct/Channel.js +55 -55
  35. package/src/struct/Emote.js +79 -66
  36. package/src/struct/EmoteFetcher.js +355 -327
  37. package/src/struct/EmoteParser.js +81 -81
  38. package/src/struct/EmoteTypeMapper.js +13 -0
  39. package/src/struct/FFZEmote.js +113 -74
  40. package/src/struct/SevenTVEmote.js +106 -69
  41. package/src/struct/TwitchEmote.js +87 -58
  42. package/src/util/Collection.js +78 -78
  43. package/src/util/Constants.js +31 -31
  44. package/test/index.js +482 -174
  45. package/typings/index.d.ts +115 -98
package/test/index.js CHANGED
@@ -1,174 +1,482 @@
1
- /* eslint-disable no-console */
2
-
3
- const assert = require('assert');
4
- const { env } = require('process');
5
- const { EmoteFetcher, EmoteParser } = require('../src/index.js');
6
-
7
- /**
8
- * If environement variables are set, test Twitch fetching and parsing.
9
- *
10
- * Tests:
11
- * - Fetch emotes
12
- * - Twitch Global
13
- * - Twitch Channel (twitchplayspokemon)
14
- * - Link to Kappa
15
- * - Parse to Markdown
16
- * - Twitch Global emote (CoolCat)
17
- * - Twitch Channel emote (tppD)
18
- */
19
- if (env.TWITCH_ID !== undefined && env.TWITCH_SECRET !== undefined) {
20
- const twitchFetcher = new EmoteFetcher(env.TWITCH_ID, env.TWITCH_SECRET);
21
- const twitchParser = new EmoteParser(twitchFetcher, {
22
- type: 'markdown',
23
- match: /:(.+?):/g
24
- });
25
-
26
- Promise.all([
27
- twitchFetcher.fetchTwitchEmotes(),
28
- twitchFetcher.fetchTwitchEmotes(56648155)
29
- ]).then(() => {
30
- const kappa = twitchFetcher.emotes.get('Kappa');
31
- assert.strictEqual(kappa.toLink(2), 'https://static-cdn.jtvnw.net/emoticons/v2/25/default/dark/3.0');
32
-
33
- const text = twitchParser.parse(':CoolCat:\n:tppD:');
34
- assert.strictEqual(text, [
35
- '![CoolCat](https://static-cdn.jtvnw.net/emoticons/v2/58127/default/dark/1.0 "CoolCat")',
36
- '![tppD](https://static-cdn.jtvnw.net/emoticons/v2/307609315/default/dark/1.0 "tppD")'
37
- ].join('\n'));
38
- }).then(() => {
39
- console.log('Twitch emotes test was successful.');
40
- }).catch(err => {
41
- console.error('Twitch emotes test failed!');
42
- console.error(err);
43
- });
44
- } else {
45
- console.log('Notice: Twitch client id/secret missing.');
46
- }
47
-
48
- /*
49
- * Code should throw if we try to fetch Twitch emotes without a Client ID and Secret
50
- */
51
- const twitchFaultyFetcher = new EmoteFetcher();
52
-
53
- try {
54
- assert.throws(() => {
55
- twitchFaultyFetcher.fetchTwitchEmotes();
56
- }, new Error('Client id or client secret not provided.'));
57
- console.log('Twitch emotes test (without API keys) was successful.');
58
- } catch (err) {
59
- console.error('Twitch emotes test (without API keys) failed!');
60
- console.error(err);
61
- }
62
-
63
- /**
64
- * Test BetterTTV fetching and parsing.
65
- *
66
- * Tests:
67
- * - Fetch emotes
68
- * - BTTV Global
69
- * - BTTV Channel (twitchplayspokemon)
70
- * - Parse to Markdown
71
- * - BTTV Global emote (SourPls)
72
- * - BTTV Channel emote (tppUrn)
73
- * - BTTV Shared emote (MODS)
74
- */
75
- const bttvFetcher = new EmoteFetcher();
76
- const bttvParser = new EmoteParser(bttvFetcher, {
77
- type: 'markdown',
78
- match: /:(.+?):/g
79
- });
80
-
81
- Promise.all([
82
- bttvFetcher.fetchBTTVEmotes(),
83
- bttvFetcher.fetchBTTVEmotes(56648155)
84
- ]).then(() => {
85
- const text = bttvParser.parse(':SourPls:\n:tppUrn:\n:MODS:');
86
- assert.strictEqual(text, [
87
- '![SourPls](https://cdn.betterttv.net/emote/566ca38765dbbdab32ec0560/1x.webp "SourPls")',
88
- '![tppUrn](https://cdn.betterttv.net/emote/5f5f7d5f68d9d86c020e8672/1x.webp "tppUrn")',
89
- '![MODS](https://cdn.betterttv.net/emote/5f2c4f9e65fe924464ef6d61/1x.webp "MODS")'
90
- ].join('\n'));
91
- }).then(() => {
92
- console.log('BTTV emotes test was successful.');
93
- }).catch(err => {
94
- console.error('BTTV emotes test failed!');
95
- console.error(err);
96
- });
97
-
98
-
99
- /**
100
- * Test FrankerFaceZ fetching and parsing.
101
- *
102
- * Tests:
103
- * - Fetch emotes
104
- * - FFZ Global
105
- * - FFZ Channel (0kody)
106
- * - FFZ Channel (shizuka_natsume)
107
- * - Parse to Markdown
108
- * - FFZ Global emote (CatBag)
109
- * - FFZ Channel emote (5Head)
110
- * - FFZ Channel animated emote (MikuSway)
111
- * - FFZ Channel emote (SanaeSip)
112
- * - FFZ modifier (ffzHyper)
113
- */
114
- const ffzFetcher = new EmoteFetcher();
115
- const ffzParser = new EmoteParser(ffzFetcher, {
116
- type: 'markdown',
117
- match: /:(.+?):/g
118
- });
119
-
120
- Promise.all([
121
- ffzFetcher.fetchFFZEmotes(),
122
- ffzFetcher.fetchFFZEmotes(44317909),
123
- ffzFetcher.fetchFFZEmotes(13638332)
124
- ]).then(() => {
125
- const text = ffzParser.parse(':CatBag:\n:5Head:\n:MikuSway:\n:SanaeSip: :ffzHyper:');
126
- assert.strictEqual(text, [
127
- '![CatBag](https://cdn.frankerfacez.com/emote/25927/1 "CatBag")',
128
- '![5Head](https://cdn.frankerfacez.com/emote/239504/1 "5Head")',
129
- '![MikuSway](https://cdn.frankerfacez.com/emote/723102/animated/1.webp "MikuSway")',
130
- // Note the trailing space as ffZHyper is removed but not the space before
131
- '![SanaeSip](https://cdn.frankerfacez.com/emote/305078/1 "SanaeSip") '
132
- ].join('\n'));
133
- }).then(() => {
134
- console.log('FFZ emotes test was successful.');
135
- }).catch(err => {
136
- console.error('FFZ emotes test failed!');
137
- console.error(err);
138
- });
139
-
140
- /**
141
- * Test 7TV fetching and parsing.
142
- *
143
- * Tests:
144
- * - Fetch emotes
145
- * - 7TV Global (in AVIF format)
146
- * - 7TV Channel (0kody)
147
- * - Parse to Markdown
148
- * - 7TV Global emote (EZ)
149
- * - 7TV Global emote (Clap)
150
- * - 7TV Channel emote (modCheck)
151
- */
152
- const sevenFetcher = new EmoteFetcher();
153
- const sevenParser = new EmoteParser(sevenFetcher, {
154
- type: 'markdown',
155
- match: /:(.+?):/g
156
- });
157
-
158
- Promise.all([
159
- sevenFetcher.fetchSevenTVEmotes(null, 'avif'),
160
- sevenFetcher.fetchSevenTVEmotes(44317909)
161
- ]).then(() => {
162
- const text = sevenParser.parse(':EZ:\n:Clap:\n:modCheck:');
163
- assert.strictEqual(text, [
164
- '![EZ](https://cdn.7tv.app/emote/63071b80942ffb69e13d700f/1x.avif "EZ")',
165
- '![Clap](https://cdn.7tv.app/emote/62fc0a0c4a75fd54bd3520a9/1x.avif "Clap")',
166
- '![modCheck](https://cdn.7tv.app/emote/60abf171870d317bef23d399/1x.webp "modCheck")'
167
- ].join('\n'));
168
- }).then(() => {
169
- console.log('7TV emotes test was successful.');
170
- }).catch(err => {
171
- console.error('7TV emotes test failed!');
172
- console.error('(Note that they might be different during certain events like Halloween.)');
173
- console.error(err);
174
- });
1
+ /* eslint-disable no-console */
2
+
3
+ const assert = require('assert');
4
+ const { env } = require('process');
5
+ const { EmoteFetcher, EmoteParser } = require('../src/index.js');
6
+
7
+ let returnCode = 0;
8
+
9
+ /**
10
+ * Test Twitch fetching and parsing if environment variables are set.
11
+ *
12
+ * Tests:
13
+ * - Fetch emotes
14
+ * - Twitch Global
15
+ * - Twitch Channel (twitchplayspokemon)
16
+ * - Link to Kappa
17
+ * - Parse to Markdown
18
+ * - Twitch Global emote (CoolCat)
19
+ * - Twitch Channel emote (tppD)
20
+ */
21
+ async function testTwitch() {
22
+ if (env.TWITCH_ID === undefined || env.TWITCH_SECRET === undefined
23
+ || env.TWITCH_ID === '' || env.TWITCH_SECRET === '') {
24
+ console.log('Notice: Twitch client id/secret missing.');
25
+ return;
26
+ }
27
+
28
+ const emoteFetcher = new EmoteFetcher(env.TWITCH_ID, env.TWITCH_SECRET);
29
+ const emoteParser = new EmoteParser(emoteFetcher, {
30
+ type: 'markdown',
31
+ match: /:(.+?):/g
32
+ });
33
+
34
+ try {
35
+ await Promise.all([
36
+ emoteFetcher.fetchTwitchEmotes(),
37
+ emoteFetcher.fetchTwitchEmotes(56648155)
38
+ ]);
39
+
40
+ const kappaEmote = emoteFetcher.emotes.get('Kappa');
41
+ assert.strictEqual(
42
+ kappaEmote.toLink(2),
43
+ 'https://static-cdn.jtvnw.net/emoticons/v2/25/default/dark/3.0'
44
+ );
45
+
46
+ const text = emoteParser.parse(':CoolCat:\n:tppD:');
47
+ assert.strictEqual(
48
+ text,
49
+ [
50
+ '![CoolCat](https://static-cdn.jtvnw.net/emoticons/v2/58127/default/dark/1.0 "CoolCat")',
51
+ '![tppD](https://static-cdn.jtvnw.net/emoticons/v2/307609315/default/dark/1.0 "tppD")'
52
+ ].join('\n')
53
+ );
54
+
55
+ console.log('Twitch emotes test was successful.');
56
+ } catch (err) {
57
+ console.error('Twitch emotes test failed!');
58
+ console.error(err);
59
+ returnCode = 1;
60
+ }
61
+ }
62
+
63
+ /*
64
+ * Test for a throw if we try to fetch Twitch emotes without a Client ID and Secret
65
+ */
66
+ function testTwitchFaulty() {
67
+ const emoteFetcher = new EmoteFetcher();
68
+
69
+ try {
70
+ assert.throws(
71
+ () => {
72
+ emoteFetcher.fetchTwitchEmotes();
73
+ },
74
+ new Error('Client id or client secret not provided.')
75
+ );
76
+ console.log('Twitch emotes test (without API keys) was successful.');
77
+ } catch (err) {
78
+ console.error('Twitch emotes test (without API keys) failed!');
79
+ console.error(err);
80
+ returnCode = 1;
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Test BetterTTV fetching and parsing.
86
+ *
87
+ * Tests:
88
+ * - Fetch emotes
89
+ * - BTTV Global
90
+ * - BTTV Channel (twitchplayspokemon)
91
+ * - Parse to Markdown
92
+ * - BTTV Global emote (SourPls)
93
+ * - BTTV Channel emote (tppUrn)
94
+ * - BTTV Shared emote (MODS)
95
+ */
96
+ async function testBTTV() {
97
+ const emoteFetcher = new EmoteFetcher();
98
+ const emoteParser = new EmoteParser(emoteFetcher, {
99
+ type: 'markdown',
100
+ match: /:(.+?):/g
101
+ });
102
+
103
+ try {
104
+ await Promise.all([
105
+ emoteFetcher.fetchBTTVEmotes(),
106
+ emoteFetcher.fetchBTTVEmotes(56648155)
107
+ ]);
108
+
109
+ const text = emoteParser.parse(':SourPls:\n:tppUrn:\n:MODS:');
110
+ assert.strictEqual(
111
+ text,
112
+ [
113
+ '![SourPls](https://cdn.betterttv.net/emote/566ca38765dbbdab32ec0560/1x.webp "SourPls")',
114
+ '![tppUrn](https://cdn.betterttv.net/emote/5f5f7d5f68d9d86c020e8672/1x.webp "tppUrn")',
115
+ '![MODS](https://cdn.betterttv.net/emote/5f2c4f9e65fe924464ef6d61/1x.webp "MODS")'
116
+ ].join('\n')
117
+ );
118
+
119
+ console.log('BTTV emotes test was successful.');
120
+ } catch (err) {
121
+ console.error('BTTV emotes test failed!');
122
+ console.error(err);
123
+ returnCode = 1;
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Test FrankerFaceZ fetching and parsing.
129
+ *
130
+ * Tests:
131
+ * - Fetch emotes
132
+ * - FFZ Global
133
+ * - FFZ Channel (0kody)
134
+ * - FFZ Channel (shizuka_natsume)
135
+ * - Parse to Markdown
136
+ * - FFZ Global emote (CatBag)
137
+ * - FFZ Channel emote (5Head)
138
+ * - FFZ Channel animated emote (MikuSway)
139
+ * - FFZ Channel emote (SanaeSip)
140
+ * - FFZ modifier (ffzHyper)
141
+ */
142
+ async function testFFZ() {
143
+ const emoteFetcher = new EmoteFetcher();
144
+ const emoteParser = new EmoteParser(emoteFetcher, {
145
+ type: 'markdown',
146
+ match: /:(.+?):/g
147
+ });
148
+
149
+ try {
150
+ await Promise.all([
151
+ emoteFetcher.fetchFFZEmotes(),
152
+ emoteFetcher.fetchFFZEmotes(44317909),
153
+ emoteFetcher.fetchFFZEmotes(13638332)
154
+ ]);
155
+
156
+ const text = emoteParser.parse(':CatBag:\n:5Head:\n:MikuSway:\n:SanaeSip: :ffzHyper:');
157
+ assert.strictEqual(
158
+ text,
159
+ [
160
+ '![CatBag](https://cdn.frankerfacez.com/emote/25927/1 "CatBag")',
161
+ '![5Head](https://cdn.frankerfacez.com/emote/239504/1 "5Head")',
162
+ '![MikuSway](https://cdn.frankerfacez.com/emote/723102/animated/1.webp "MikuSway")',
163
+ // Note the trailing space as ffZHyper is removed but not the space before
164
+ '![SanaeSip](https://cdn.frankerfacez.com/emote/305078/1 "SanaeSip") '
165
+ ].join('\n')
166
+ );
167
+
168
+ console.log('FFZ emotes test was successful.');
169
+ } catch (err) {
170
+ console.error('FFZ emotes test failed!');
171
+ console.error(err);
172
+ returnCode = 1;
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Test 7TV fetching and parsing.
178
+ *
179
+ * Tests:
180
+ * - Fetch emotes
181
+ * - 7TV Global (in AVIF format)
182
+ * - 7TV Channel (0kody)
183
+ * - Parse to Markdown
184
+ * - 7TV Global emote (EZ)
185
+ * - 7TV Global emote (Clap)
186
+ * - 7TV Channel emote (modCheck)
187
+ */
188
+ async function testSevenTV() {
189
+ const emoteFetcher = new EmoteFetcher();
190
+ const emoteParser = new EmoteParser(emoteFetcher, {
191
+ type: 'markdown',
192
+ match: /:(.+?):/g
193
+ });
194
+
195
+ try {
196
+ await Promise.all([
197
+ emoteFetcher.fetchSevenTVEmotes(null, 'avif'),
198
+ emoteFetcher.fetchSevenTVEmotes(44317909)
199
+ ]);
200
+
201
+ const text = emoteParser.parse(':EZ:\n:Clap:\n:modCheck:');
202
+ assert.strictEqual(
203
+ text, [
204
+ '![EZ](https://cdn.7tv.app/emote/63071b80942ffb69e13d700f/1x.avif "EZ")',
205
+ '![Clap](https://cdn.7tv.app/emote/62fc0a0c4a75fd54bd3520a9/1x.avif "Clap")',
206
+ '![modCheck](https://cdn.7tv.app/emote/60abf171870d317bef23d399/1x.webp "modCheck")'
207
+ ].join('\n')
208
+ );
209
+
210
+ console.log('7TV emotes test was successful.');
211
+ } catch (err) {
212
+ console.error('7TV emotes test failed!');
213
+ console.error('(Note that emotes might have been updated.)');
214
+ console.error(err);
215
+ returnCode = 1;
216
+ }
217
+ }
218
+
219
+ /**
220
+ * Test toObject functionality.
221
+ *
222
+ * Tests:
223
+ * - Converting select emotes from each type to Object
224
+ */
225
+ async function testToObject() {
226
+ const emoteFetcher = new EmoteFetcher(env.TWITCH_ID, env.TWITCH_SECRET);
227
+
228
+ const emoteFetch = [
229
+ emoteFetcher.fetchBTTVEmotes(),
230
+ emoteFetcher.fetchBTTVEmotes(56648155),
231
+ emoteFetcher.fetchFFZEmotes(),
232
+ emoteFetcher.fetchFFZEmotes(44317909),
233
+ emoteFetcher.fetchFFZEmotes(13638332),
234
+ emoteFetcher.fetchSevenTVEmotes(null, 'avif'),
235
+ emoteFetcher.fetchSevenTVEmotes(44317909)
236
+ ];
237
+
238
+ if (env.TWITCH_ID && env.TWITCH_SECRET) {
239
+ emoteFetch.push(
240
+ emoteFetcher.fetchTwitchEmotes(),
241
+ emoteFetcher.fetchTwitchEmotes(56648155)
242
+ );
243
+ }
244
+
245
+ try {
246
+ await Promise.all(emoteFetch);
247
+
248
+ assert.deepStrictEqual(emoteFetcher.emotes.get('SourPls').toObject(), {
249
+ id: '566ca38765dbbdab32ec0560',
250
+ type: 'bttv',
251
+ code: 'SourPls',
252
+ ownerName: null,
253
+ animated: true,
254
+ channel_id: null
255
+ });
256
+
257
+ assert.deepStrictEqual(emoteFetcher.emotes.get('tppUrn').toObject(), {
258
+ id: '5f5f7d5f68d9d86c020e8672',
259
+ type: 'bttv',
260
+ code: 'tppUrn',
261
+ ownerName: null,
262
+ animated: false,
263
+ channel_id: 56648155
264
+ });
265
+
266
+ assert.deepStrictEqual(emoteFetcher.emotes.get('MODS').toObject(), {
267
+ id: '5f2c4f9e65fe924464ef6d61',
268
+ type: 'bttv',
269
+ code: 'MODS',
270
+ ownerName: 'bearrrr_',
271
+ animated: true,
272
+ channel_id: 56648155
273
+ });
274
+
275
+ assert.deepStrictEqual(emoteFetcher.emotes.get('CatBag').toObject(), {
276
+ id: 25927,
277
+ type: 'ffz',
278
+ code: 'CatBag',
279
+ ownerName: 'wolsk',
280
+ animated: false,
281
+ modifier: false,
282
+ channel_id: undefined,
283
+ sizes: ['1', '2', '4']
284
+ });
285
+
286
+ assert.deepStrictEqual(emoteFetcher.emotes.get('5Head').toObject(), {
287
+ id: 239504,
288
+ type: 'ffz',
289
+ code: '5Head',
290
+ ownerName: 'sublimedtv',
291
+ animated: false,
292
+ modifier: false,
293
+ channel_id: 44317909,
294
+ sizes: ['1', '2', '4']
295
+ });
296
+
297
+ assert.deepStrictEqual(emoteFetcher.emotes.get('MikuSway').toObject(), {
298
+ id: 723102,
299
+ type: 'ffz',
300
+ code: 'MikuSway',
301
+ ownerName: 'brian6932',
302
+ animated: true,
303
+ modifier: false,
304
+ channel_id: 44317909,
305
+ sizes: ['1', '2', '4']
306
+ });
307
+
308
+ assert.deepStrictEqual(emoteFetcher.emotes.get('SanaeSip').toObject(), {
309
+ id: 305078,
310
+ type: 'ffz',
311
+ code: 'SanaeSip',
312
+ ownerName: 'shizuka_natsume',
313
+ animated: false,
314
+ modifier: false,
315
+ channel_id: 13638332,
316
+ sizes: ['1', '2', '4']
317
+ });
318
+
319
+ assert.deepStrictEqual(emoteFetcher.emotes.get('EZ').toObject(), {
320
+ id: '63071b80942ffb69e13d700f',
321
+ type: '7tv',
322
+ code: 'EZ',
323
+ ownerName: 'Kh4N_02',
324
+ animated: false,
325
+ channel_id: null,
326
+ sizes: ['1x.avif', '2x.avif', '3x.avif', '4x.avif'],
327
+ imageType: 'avif'
328
+ });
329
+
330
+ assert.deepStrictEqual(emoteFetcher.emotes.get('Clap').toObject(), {
331
+ id: '62fc0a0c4a75fd54bd3520a9',
332
+ type: '7tv',
333
+ code: 'Clap',
334
+ ownerName: 'sunkhaskasis',
335
+ animated: true,
336
+ channel_id: null,
337
+ sizes: ['1x.avif', '2x.avif', '3x.avif', '4x.avif'],
338
+ imageType: 'avif'
339
+ });
340
+
341
+ assert.deepStrictEqual(emoteFetcher.emotes.get('modCheck').toObject(), {
342
+ id: '60abf171870d317bef23d399',
343
+ type: '7tv',
344
+ code: 'modCheck',
345
+ ownerName: 'Laden',
346
+ animated: true,
347
+ channel_id: 44317909,
348
+ sizes: ['1x.webp', '2x.webp', '3x.webp', '4x.webp'],
349
+ imageType: 'webp'
350
+ });
351
+
352
+ if (env.TWITCH_ID && env.TWITCH_SECRET) {
353
+ assert.deepStrictEqual(emoteFetcher.emotes.get('Kappa').toObject(), {
354
+ id: '25',
355
+ type: 'twitch',
356
+ code: 'Kappa',
357
+ animated: false,
358
+ channel_id: null,
359
+ set: undefined
360
+ });
361
+
362
+ assert.deepStrictEqual(emoteFetcher.emotes.get('CoolCat').toObject(), {
363
+ id: '58127',
364
+ type: 'twitch',
365
+ code: 'CoolCat',
366
+ animated: false,
367
+ channel_id: null,
368
+ set: undefined
369
+ });
370
+
371
+ assert.deepStrictEqual(emoteFetcher.emotes.get('tppD').toObject(), {
372
+ id: '307609315',
373
+ type: 'twitch',
374
+ code: 'tppD',
375
+ animated: false,
376
+ channel_id: 56648155,
377
+ set: undefined
378
+ });
379
+ }
380
+
381
+ console.log('toObject test was successful.');
382
+ } catch (err) {
383
+ console.error('toObject test failed!');
384
+ console.error('(Note that emotes might have been updated.)');
385
+ console.error(err);
386
+ returnCode = 1;
387
+ }
388
+ }
389
+
390
+
391
+ /**
392
+ * Test fromOobject functionality.
393
+ *
394
+ * Tests:
395
+ * - Converting select emotes from each type from Object
396
+ * - Testing parser output
397
+ */
398
+ function testFromObject() {
399
+ const emoteFetcher = new EmoteFetcher();
400
+ const emoteParser = new EmoteParser(emoteFetcher, {
401
+ type: 'markdown',
402
+ match: /(\w+)+?/g
403
+ });
404
+
405
+ const emotes_obj = [
406
+ {
407
+ code: 'tppD',
408
+ id: '307609315',
409
+ channel_id: 56648155,
410
+ animated: false,
411
+ set: undefined,
412
+ type: 'twitch'
413
+ },
414
+ {
415
+ code: 'SourPls',
416
+ id: '566ca38765dbbdab32ec0560',
417
+ channel_id: null,
418
+ animated: true,
419
+ ownerName: null,
420
+ type: 'bttv'
421
+ },
422
+ {
423
+ code: 'modCheck',
424
+ id: '60abf171870d317bef23d399',
425
+ channel_id: 44317909,
426
+ animated: true,
427
+ sizes: ['1x.webp', '2x.webp', '3x.webp', '4x.webp'],
428
+ ownerName: 'Laden',
429
+ type: '7tv',
430
+ imageType: 'webp'
431
+ },
432
+ {
433
+ code: 'MikuSway',
434
+ id: 723102,
435
+ channel_id: 44317909,
436
+ animated: true,
437
+ sizes: ['1', '2', '4'],
438
+ ownerName: 'brian6932',
439
+ type: 'ffz',
440
+ modifier: false
441
+ }
442
+ ];
443
+
444
+ try {
445
+ emoteFetcher.fromObject(emotes_obj);
446
+
447
+ const text = emoteParser.parse('tppD SourPls modCheck MikuSway');
448
+ assert.strictEqual(
449
+ text,
450
+ [
451
+ '![tppD](https://static-cdn.jtvnw.net/emoticons/v2/307609315/default/dark/1.0 "tppD")',
452
+ '![SourPls](https://cdn.betterttv.net/emote/566ca38765dbbdab32ec0560/1x.webp "SourPls")',
453
+ '![modCheck](https://cdn.7tv.app/emote/60abf171870d317bef23d399/1x.webp "modCheck")',
454
+ '![MikuSway](https://cdn.frankerfacez.com/emote/723102/animated/1.webp "MikuSway")'
455
+ ].join(' ')
456
+ );
457
+
458
+ console.log('fromObject test was successful.');
459
+ } catch (err) {
460
+ console.error('fromObject test failed!');
461
+ console.error(err);
462
+ returnCode = 1;
463
+ }
464
+ }
465
+
466
+ /**
467
+ * Execute our tests and exit with our final code.
468
+ */
469
+ Promise.all([
470
+ testTwitch(),
471
+ testTwitchFaulty(),
472
+ testBTTV(),
473
+ testFFZ(),
474
+ testSevenTV(),
475
+ testToObject(),
476
+ testFromObject()
477
+ ]).then(() => {
478
+ process.exit(returnCode);
479
+ }).catch(err => {
480
+ console.error(err);
481
+ process.exit(1);
482
+ });