@mkody/twitch-emoticons 2.8.1 → 2.8.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.
Files changed (40) hide show
  1. package/dist/TwitchEmoticons.min.js +22 -0
  2. package/dist/TwitchEmoticons.min.js.map +7 -0
  3. package/docs/BTTVEmote.html +1 -111
  4. package/docs/Channel.html +4 -4
  5. package/docs/Collection.html +1 -1
  6. package/docs/Emote.html +2 -107
  7. package/docs/EmoteFetcher.html +1 -1
  8. package/docs/EmoteParser.html +1 -1
  9. package/docs/FFZEmote.html +1 -111
  10. package/docs/SevenTVEmote.html +1 -111
  11. package/docs/TwitchEmote.html +1 -111
  12. package/docs/index.html +2 -2
  13. package/docs/struct_BTTVEmote.js.html +1 -1
  14. package/docs/struct_Channel.js.html +6 -1
  15. package/docs/struct_Emote.js.html +8 -1
  16. package/docs/struct_EmoteFetcher.js.html +2 -2
  17. package/docs/struct_EmoteParser.js.html +1 -1
  18. package/docs/struct_FFZEmote.js.html +1 -1
  19. package/docs/struct_SevenTVEmote.js.html +1 -1
  20. package/docs/struct_TwitchEmote.js.html +1 -1
  21. package/docs/util_Collection.js.html +1 -1
  22. package/jest.config.js +198 -0
  23. package/package.json +12 -8
  24. package/src/struct/Channel.js +5 -0
  25. package/src/struct/Emote.js +7 -0
  26. package/src/struct/EmoteFetcher.js +1 -1
  27. package/test/BTTV.test.js +48 -0
  28. package/test/FFZ.test.js +71 -0
  29. package/test/SevenTV.test.js +70 -0
  30. package/test/ToFromObject.test.js +155 -0
  31. package/test/Twitch.test.js +64 -0
  32. package/test/__snapshots__/ToFromObject.test.js.snap +121 -0
  33. package/test/other.test.js +13 -0
  34. package/typings/index.d.ts +1 -1
  35. package/.github/codeql/codeql-config.yml +0 -5
  36. package/.github/workflows/codeql.yml +0 -50
  37. package/.github/workflows/eslint.yml +0 -51
  38. package/.github/workflows/release.yml +0 -22
  39. package/.github/workflows/yarn-test.yml +0 -17
  40. package/test/index.js +0 -482
package/test/index.js DELETED
@@ -1,482 +0,0 @@
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
- });