@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
@@ -1,58 +1,87 @@
1
- const Emote = require('./Emote');
2
- const Constants = require('../util/Constants');
3
-
4
- /** @extends Emote */
5
- class TwitchEmote extends Emote {
6
- /**
7
- * A Twitch emote.
8
- * @param {Channel} channel - Channel this emote belongs to.
9
- * @param {string} id - ID of the emote.
10
- * @param {data} data - The raw emote data.
11
- */
12
- constructor(channel, id, data) {
13
- super(channel, id, data);
14
- this.type = 'twitch';
15
- }
16
-
17
- /**
18
- * The channel of this emote's creator.
19
- * @readonly
20
- * @type {Channel}
21
- */
22
- get owner() {
23
- return this.channel;
24
- }
25
-
26
- _setup(data) {
27
- super._setup(data);
28
-
29
- /**
30
- * The set ID of the emote.
31
- * @type {?string}
32
- */
33
- this.set = data.emoticon_set;
34
-
35
- /**
36
- * If emote is animated.
37
- * @type {boolean}
38
- */
39
- this.animated = 'animated' in data.formats;
40
-
41
- /**
42
- * The image type of the emote.
43
- * @type {string}
44
- */
45
- this.imageType = 'animated' in data.formats ? 'gif' : 'png';
46
- }
47
-
48
- /**
49
- * Gets the image link of the emote.
50
- * @param {number} size - The size of the image, 0, 1, or 2.
51
- * @returns {string}
52
- */
53
- toLink(size = 0) {
54
- return Constants.Twitch.CDN(this.id, size); // eslint-disable-line new-cap
55
- }
56
- }
57
-
58
- module.exports = TwitchEmote;
1
+ const Emote = require('./Emote');
2
+ const Constants = require('../util/Constants');
3
+
4
+ /** @extends Emote */
5
+ class TwitchEmote extends Emote {
6
+ /**
7
+ * A Twitch emote.
8
+ * @param {Channel} channel - Channel this emote belongs to.
9
+ * @param {string} id - ID of the emote.
10
+ * @param {data} data - The raw emote data.
11
+ */
12
+ constructor(channel, id, data) {
13
+ super(channel, id, data);
14
+ this.type = 'twitch';
15
+ }
16
+
17
+ /**
18
+ * The channel of this emote's creator.
19
+ * @readonly
20
+ * @type {Channel}
21
+ */
22
+ get owner() {
23
+ return this.channel;
24
+ }
25
+
26
+ _setup(data) {
27
+ super._setup(data);
28
+
29
+ /**
30
+ * The set ID of the emote.
31
+ * @type {?string}
32
+ */
33
+ this.set = data.emoticon_set;
34
+
35
+ /**
36
+ * If emote is animated.
37
+ * @type {boolean}
38
+ */
39
+ this.animated = 'animated' in data.formats;
40
+
41
+ /**
42
+ * The image type of the emote.
43
+ * @type {string}
44
+ */
45
+ this.imageType = 'animated' in data.formats ? 'gif' : 'png';
46
+ }
47
+
48
+ /**
49
+ * Gets the image link of the emote.
50
+ * @param {number} size - The size of the image, 0, 1, or 2.
51
+ * @returns {string}
52
+ */
53
+ toLink(size = 0) {
54
+ return Constants.Twitch.CDN(this.id, size); // eslint-disable-line new-cap
55
+ }
56
+
57
+ /**
58
+ * Override for `toObject`.
59
+ * Will result in an Object representation of a TwitchEmote
60
+ * @returns {Object}
61
+ */
62
+ toObject() {
63
+ return Object.assign({}, super.toObject(), {
64
+ animated: this.animated,
65
+ set: this.set,
66
+ type: this.type
67
+ });
68
+ }
69
+
70
+ /**
71
+ * Converts an emote Object into a TwitchEmote
72
+ * @param {Object} [emoteObject] - Object representation of this emote
73
+ * @param {Channel} [channel=null] - Channel this emote belongs to.
74
+ * @returns {TwitchEmote}
75
+ */
76
+ static fromObject(emoteObject, channel = null) {
77
+ return new TwitchEmote(channel, emoteObject.id,
78
+ {
79
+ code: emoteObject.code,
80
+ animated: emoteObject.animated,
81
+ emoticon_set: emoteObject.set,
82
+ formats: emoteObject.animated ? { animated: emoteObject.animated } : {}
83
+ });
84
+ }
85
+ }
86
+
87
+ module.exports = TwitchEmote;
@@ -1,78 +1,78 @@
1
- /**
2
- * An extended Map with utility methods.
3
- * @class Collection
4
- */
5
- class Collection extends Map {
6
- /**
7
- * Finds first matching value by property or function.
8
- * Same as `Array#find`.
9
- * @param {string|Function} propOrFunc - Property or function to test.
10
- * @param {any} [value] - Value to find.
11
- * @returns {any}
12
- */
13
- find(propOrFunc, value) {
14
- if (typeof propOrFunc === 'string') {
15
- if (typeof value === 'undefined') return null;
16
- for (const item of this.values()) {
17
- if (item[propOrFunc] === value) return item;
18
- }
19
-
20
- return null;
21
- }
22
-
23
- if (typeof propOrFunc === 'function') {
24
- let i = 0;
25
- for (const item of this.values()) {
26
- if (propOrFunc(item, i, this)) return item;
27
- i++;
28
- }
29
-
30
- return null;
31
- }
32
-
33
- return null;
34
- }
35
-
36
- /**
37
- * Filters cache by function.
38
- * Same as `Array#filter`.
39
- * @param {Function} func - Function to test.
40
- * @param {any} [thisArg] - The context for the function.
41
- * @returns {Collection}
42
- */
43
- filter(func, thisArg) {
44
- if (thisArg) func = func.bind(thisArg);
45
-
46
- const results = new this.constructor();
47
-
48
- let i = 0;
49
- for (const [key, item] of this) {
50
- if (func(item, i, this)) results.set(key, item);
51
- i++;
52
- }
53
-
54
- return results;
55
- }
56
-
57
- /**
58
- * Maps cache by function.
59
- * Same as `Array#map`.
60
- * @param {Function} func - Function to use.
61
- * @param {any} [thisArg] - The context for the function.
62
- * @returns {any[]}
63
- */
64
- map(func, thisArg) {
65
- if (thisArg) func = func.bind(thisArg);
66
-
67
- const array = new Array(this.size);
68
- let i = 0;
69
- for (const item of this.values()) {
70
- array[i] = func(item, i, this);
71
- i++;
72
- }
73
-
74
- return array;
75
- }
76
- }
77
-
78
- module.exports = Collection;
1
+ /**
2
+ * An extended Map with utility methods.
3
+ * @class Collection
4
+ */
5
+ class Collection extends Map {
6
+ /**
7
+ * Finds first matching value by property or function.
8
+ * Same as `Array#find`.
9
+ * @param {string|Function} propOrFunc - Property or function to test.
10
+ * @param {any} [value] - Value to find.
11
+ * @returns {any}
12
+ */
13
+ find(propOrFunc, value) {
14
+ if (typeof propOrFunc === 'string') {
15
+ if (typeof value === 'undefined') return null;
16
+ for (const item of this.values()) {
17
+ if (item[propOrFunc] === value) return item;
18
+ }
19
+
20
+ return null;
21
+ }
22
+
23
+ if (typeof propOrFunc === 'function') {
24
+ let i = 0;
25
+ for (const item of this.values()) {
26
+ if (propOrFunc(item, i, this)) return item;
27
+ i++;
28
+ }
29
+
30
+ return null;
31
+ }
32
+
33
+ return null;
34
+ }
35
+
36
+ /**
37
+ * Filters cache by function.
38
+ * Same as `Array#filter`.
39
+ * @param {Function} func - Function to test.
40
+ * @param {any} [thisArg] - The context for the function.
41
+ * @returns {Collection}
42
+ */
43
+ filter(func, thisArg) {
44
+ if (thisArg) func = func.bind(thisArg);
45
+
46
+ const results = new this.constructor();
47
+
48
+ let i = 0;
49
+ for (const [key, item] of this) {
50
+ if (func(item, i, this)) results.set(key, item);
51
+ i++;
52
+ }
53
+
54
+ return results;
55
+ }
56
+
57
+ /**
58
+ * Maps cache by function.
59
+ * Same as `Array#map`.
60
+ * @param {Function} func - Function to use.
61
+ * @param {any} [thisArg] - The context for the function.
62
+ * @returns {any[]}
63
+ */
64
+ map(func, thisArg) {
65
+ if (thisArg) func = func.bind(thisArg);
66
+
67
+ const array = new Array(this.size);
68
+ let i = 0;
69
+ for (const item of this.values()) {
70
+ array[i] = func(item, i, this);
71
+ i++;
72
+ }
73
+
74
+ return array;
75
+ }
76
+ }
77
+
78
+ module.exports = Collection;
@@ -1,31 +1,31 @@
1
- module.exports = {
2
- Twitch: {
3
- CDN: (id, size) => `https://static-cdn.jtvnw.net/emoticons/v2/${id}/default/dark/${size + 1}.0`
4
- },
5
- BTTV: {
6
- Global: 'https://api.betterttv.net/3/cached/emotes/global',
7
- Channel: id => `https://api.betterttv.net/3/cached/users/twitch/${id}`,
8
- CDN: (id, size) => `https://cdn.betterttv.net/emote/${id}/${size + 1}x.webp`
9
- },
10
- SevenTV: {
11
- Global: 'https://7tv.io/v3/emote-sets/global',
12
- Channel: id => `https://7tv.io/v3/users/twitch/${id}`,
13
- CDN: (id, size) => `https://cdn.7tv.app/emote/${id}/${size}`
14
- },
15
- FFZ: {
16
- sets: {
17
- Global: 3,
18
- Modifiers: 1532818
19
- },
20
- Set: id => `https://api.frankerfacez.com/v1/set/${id}`,
21
- Channel: id => `https://api.frankerfacez.com/v1/room/id/${id}`,
22
- CDN: (id, size) => `https://cdn.frankerfacez.com/emote/${id}/${size}`,
23
- CDNAnimated: (id, size) => `https://cdn.frankerfacez.com/emote/${id}/animated/${size}.webp`
24
- },
25
- Templates: {
26
- html: '<img alt="{name}" title="{name}" class="twitch-emote twitch-emote-{size}" src="{link}">',
27
- markdown: '![{name}]({link} "{name}")',
28
- bbcode: '[img]{link}[/img]',
29
- plain: '{link}'
30
- }
31
- };
1
+ module.exports = {
2
+ Twitch: {
3
+ CDN: (id, size) => `https://static-cdn.jtvnw.net/emoticons/v2/${id}/default/dark/${size + 1}.0`
4
+ },
5
+ BTTV: {
6
+ Global: 'https://api.betterttv.net/3/cached/emotes/global',
7
+ Channel: id => `https://api.betterttv.net/3/cached/users/twitch/${id}`,
8
+ CDN: (id, size) => `https://cdn.betterttv.net/emote/${id}/${size + 1}x.webp`
9
+ },
10
+ SevenTV: {
11
+ Global: 'https://7tv.io/v3/emote-sets/global',
12
+ Channel: id => `https://7tv.io/v3/users/twitch/${id}`,
13
+ CDN: (id, size) => `https://cdn.7tv.app/emote/${id}/${size}`
14
+ },
15
+ FFZ: {
16
+ sets: {
17
+ Global: 3,
18
+ Modifiers: 1532818
19
+ },
20
+ Set: id => `https://api.frankerfacez.com/v1/set/${id}`,
21
+ Channel: id => `https://api.frankerfacez.com/v1/room/id/${id}`,
22
+ CDN: (id, size) => `https://cdn.frankerfacez.com/emote/${id}/${size}`,
23
+ CDNAnimated: (id, size) => `https://cdn.frankerfacez.com/emote/${id}/animated/${size}.webp`
24
+ },
25
+ Templates: {
26
+ html: '<img alt="{name}" title="{name}" class="twitch-emote twitch-emote-{size}" src="{link}">',
27
+ markdown: '![{name}]({link} "{name}")',
28
+ bbcode: '[img]{link}[/img]',
29
+ plain: '{link}'
30
+ }
31
+ };