@mkody/twitch-emoticons 2.9.6 → 3.0.0-beta.2

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 (80) hide show
  1. package/README.md +530 -169
  2. package/dist/TwitchEmoticons.cjs +950 -0
  3. package/dist/TwitchEmoticons.esm.min.js +7 -0
  4. package/dist/TwitchEmoticons.esm.min.js.map +7 -0
  5. package/dist/TwitchEmoticons.min.js +2 -20
  6. package/dist/TwitchEmoticons.min.js.map +4 -4
  7. package/package.json +99 -72
  8. package/src/index.js +38 -12
  9. package/src/struct/BTTVEmote.js +72 -74
  10. package/src/struct/Channel.js +48 -48
  11. package/src/struct/Emote.js +71 -71
  12. package/src/struct/EmoteFetcher.js +358 -322
  13. package/src/struct/EmoteParser.js +95 -84
  14. package/src/struct/EmoteTypeMapper.js +9 -9
  15. package/src/struct/FFZEmote.js +91 -93
  16. package/src/struct/SevenTVEmote.js +88 -90
  17. package/src/struct/TwitchEmote.js +72 -71
  18. package/src/util/Collection.js +69 -55
  19. package/src/util/Constants.js +30 -30
  20. package/typings/index.d.cts +254 -0
  21. package/typings/index.d.ts +216 -99
  22. package/.jsdoc.json +0 -46
  23. package/.nvmrc +0 -1
  24. package/docs/BTTVEmote.html +0 -1532
  25. package/docs/Channel.html +0 -824
  26. package/docs/Collection.html +0 -798
  27. package/docs/Emote.html +0 -832
  28. package/docs/EmoteFetcher.html +0 -3741
  29. package/docs/EmoteParser.html +0 -1187
  30. package/docs/FFZEmote.html +0 -1686
  31. package/docs/SevenTVEmote.html +0 -1596
  32. package/docs/TwitchEmote.html +0 -1528
  33. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  34. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  35. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  36. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  37. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  38. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  39. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  40. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  41. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  42. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -978
  43. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  44. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  45. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  46. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  47. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -1049
  48. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  49. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  50. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  51. package/docs/index.html +0 -233
  52. package/docs/scripts/collapse.js +0 -39
  53. package/docs/scripts/commonNav.js +0 -28
  54. package/docs/scripts/linenumber.js +0 -25
  55. package/docs/scripts/nav.js +0 -12
  56. package/docs/scripts/polyfill.js +0 -4
  57. package/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
  58. package/docs/scripts/prettify/lang-css.js +0 -2
  59. package/docs/scripts/prettify/prettify.js +0 -28
  60. package/docs/scripts/search.js +0 -99
  61. package/docs/struct_BTTVEmote.js.html +0 -162
  62. package/docs/struct_Channel.js.html +0 -132
  63. package/docs/struct_Emote.js.html +0 -159
  64. package/docs/struct_EmoteFetcher.js.html +0 -429
  65. package/docs/struct_EmoteParser.js.html +0 -172
  66. package/docs/struct_FFZEmote.js.html +0 -185
  67. package/docs/struct_SevenTVEmote.js.html +0 -180
  68. package/docs/struct_TwitchEmote.js.html +0 -159
  69. package/docs/styles/jsdoc.css +0 -776
  70. package/docs/styles/prettify.css +0 -80
  71. package/docs/util_Collection.js.html +0 -151
  72. package/eslint.config.mjs +0 -215
  73. package/jest.config.js +0 -198
  74. package/test/BTTV.test.js +0 -48
  75. package/test/FFZ.test.js +0 -71
  76. package/test/SevenTV.test.js +0 -71
  77. package/test/ToFromObject.test.js +0 -156
  78. package/test/Twitch.test.js +0 -64
  79. package/test/__snapshots__/ToFromObject.test.js.snap +0 -121
  80. package/test/other.test.js +0 -72
@@ -1,100 +1,111 @@
1
- const Constants = require('../util/Constants');
1
+ import Constants from '../util/Constants.js'
2
2
 
3
3
  class EmoteParser {
4
+ /**
5
+ * A parser to replace text with emotes.
6
+ * @param {EmoteFetcher} fetcher - The fetcher to use the cache of.
7
+ * @param {object} [options={}] - Options for the parser.
8
+ * @param {string} [options.template=''] - The template to be used.
9
+ * The strings that can be interpolated are:
10
+ * - `{link}` The link of the emote.
11
+ * - `{name}` The name of the emote.
12
+ * - `{size}` The size index of the image.
13
+ * - `{creator}` The channel/owner name of the emote.
14
+ * @param {'html' | 'markdown' | 'bbcode' | 'plain'} [options.type='html'] - The type of the parser.
15
+ * Can be one of `html`, `markdown`, `bbcode`, or `plain`.
16
+ * If the `template` option is provided, this is ignored.
17
+ * @param {RegExp} [options.match=/(\w+)/g] - The regular expression that matches an emote.
18
+ * Must be a global regex, with one capture group for the emote code.
19
+ */
20
+ constructor (fetcher, options = {}) {
4
21
  /**
5
- * A parser to replace text with emotes.
6
- * @param {EmoteFetcher} fetcher - The fetcher to use the cache of.
7
- * @param {object} [options={}] - Options for the parser.
8
- * @param {string} [options.template=''] - The template to be used.
9
- * The strings that can be interpolated are:
10
- * - `{link}` The link of the emote.
11
- * - `{name}` The name of the emote.
12
- * - `{size}` The size of the image.
13
- * - `{creator}` The channel/owner name of the emote.
14
- * @param {string} [options.type='markdown'] - The type of the parser.
15
- * Can be one of `markdown`, `html`, `bbcode`, or `plain`.
16
- * If the `template` option is provided, this is ignored.
17
- * @param {RegExp} [options.match=/:(.+?):/g] - The regular expression that matches an emote.
18
- * Must be a global regex, with one capture group for the emote code.
22
+ * The emote fetcher being used.
23
+ * @type {EmoteFetcher}
19
24
  */
20
- constructor(fetcher, options = {}) {
21
- /**
22
- * The emote fetcher being used.
23
- * @type {EmoteFetcher}
24
- */
25
- this.fetcher = fetcher;
26
-
27
- /**
28
- * The parser options.
29
- * @type {object}
30
- */
31
- this.options = Object.assign({
32
- template: '',
33
- type: 'markdown',
34
- match: /:(.+?):/g
35
- }, options);
36
-
37
- this._validateOptions(this.options);
38
- }
25
+ this.fetcher = fetcher
39
26
 
40
27
  /**
41
- * Validates the parser options.
42
- * @private
43
- * @param {object} [options] - Options for the parser.
44
- * @param {string} [options.template] - The template to be used.
45
- * The strings that can be interpolated are:
46
- * - `{link}` The link of the emote.
47
- * - `{name}` The name of the emote.
48
- * - `{size}` The size of the image.
49
- * - `{creator}` The channel/owner name of the emote.
50
- * @param {string} [options.type] - The type of the parser.
51
- * Can be one of `markdown`, `html`, `bbcode`, or `plain`.
52
- * If the `template` option is provided, this is ignored.
53
- * @param {RegExp} [options.match] - The regular expression that matches an emote.
54
- * Must be a global regex, with one capture group for the emote code.
55
- * @throws {TypeError} When template is not a string.
56
- * @throws {TypeError} When type is not one of the supported types.
57
- * @throws {TypeError} When match is not a global RegExp.
28
+ * The parser options.
29
+ * @type {object}
58
30
  */
59
- _validateOptions(options) {
60
- if (options.template && typeof options.template !== 'string') {
61
- throw new TypeError('Template must be a string');
62
- }
31
+ this.options = {
32
+ template: '',
33
+ type: 'html',
34
+ match: /(\w+)/g,
35
+ ...options,
36
+ }
63
37
 
64
- if (!['markdown', 'html', 'bbcode', 'plain'].includes(options.type)) {
65
- throw new TypeError('Parse type must be one of `markdown`, `html`, `bbcode`, or `plain`');
66
- }
38
+ this._validateOptions(this.options)
39
+ }
67
40
 
68
- if (!(options.match instanceof RegExp) || !options.match.global) {
69
- throw new TypeError('Match must be a global RegExp.');
70
- }
41
+ /**
42
+ * Validates the parser options.
43
+ * @private
44
+ * @param {object} [options] - Options for the parser.
45
+ * @param {string} [options.template] - The template to be used.
46
+ * The strings that can be interpolated are:
47
+ * - `{link}` The link of the emote.
48
+ * - `{name}` The name of the emote.
49
+ * - `{size}` The size of the image.
50
+ * - `{creator}` The channel/owner name of the emote.
51
+ * @param {'html' | 'markdown' | 'bbcode' | 'plain'} [options.type] - The type of the parser.
52
+ * Can be one of `html`, `markdown`, `bbcode`, or `plain`.
53
+ * If the `template` option is provided, this is ignored.
54
+ * @param {RegExp} [options.match] - The regular expression that matches an emote.
55
+ * Must be a global regex, with one capture group for the emote code.
56
+ * @throws {TypeError} When template is not a string.
57
+ * @throws {TypeError} When type is not one of the supported types.
58
+ * @throws {TypeError} When match is not a global RegExp.
59
+ */
60
+ _validateOptions (options) {
61
+ if (options.template && typeof options.template !== 'string') {
62
+ throw new TypeError('Template must be a string')
71
63
  }
72
64
 
73
- /**
74
- * Parses text.
75
- * @param {string} text - Text to parse.
76
- * @param {number} size - Size for emotes.
77
- * @returns {string}
78
- */
79
- parse(text, size = 0) {
80
- const parsed = text.replace(this.options.match, (matched, id) => {
81
- const emote = this.fetcher.emotes.get(id);
82
- if (!emote) return matched;
83
- if (emote.modifier) return '';
65
+ if (!['html', 'markdown', 'bbcode', 'plain'].includes(options.type)) {
66
+ throw new TypeError('Parse type must be one of `html`, `markdown`, `bbcode`, or `plain`')
67
+ }
84
68
 
85
- const template = this.options.template || Constants.Templates[this.options.type];
86
- const link = emote.toLink(size);
87
- const res = template
88
- .replace(/{link}/g, link)
89
- .replace(/{name}/g, emote.code)
90
- .replace(/{size}/g, size)
91
- .replace(/{creator}/g, emote.ownerName || 'global');
69
+ if (!(options.match instanceof RegExp) || !options.match.global) {
70
+ throw new TypeError('Match must be a global RegExp.')
71
+ }
72
+ }
92
73
 
93
- return res;
94
- });
74
+ /**
75
+ * Parses text.
76
+ * @param {string} text - Text to parse.
77
+ * @param {object} [options] - Parameters for parsing.
78
+ * @param {number} [options.size] - Size (scale) for emotes.
79
+ * @param {boolean} [options.forceStatic] - Whether to force the emote to be static (non-animated). Defaults to the fetcher's forceStatic or `false`.
80
+ * @param {'dark' | 'light'} [options.themeMode] - Only for Twitch: the preferred theme mode. Defaults to the fetcher's twitchThemeMode or `dark`.
81
+ * @returns {string} - The parsed text.
82
+ */
83
+ parse (text, options) {
84
+ // @NOTE(kody): Not setting defaults here, they'll be handled by each emote's toLink method.
85
+ const {
86
+ size,
87
+ forceStatic,
88
+ themeMode,
89
+ } = options || {}
95
90
 
96
- return parsed;
97
- }
91
+ const parsed = text.replace(this.options.match, (matched, id) => {
92
+ const emote = this.fetcher.emotes.get(id)
93
+ if (!emote) return matched
94
+ if (emote.modifier) return ''
95
+
96
+ const template = this.options.template || Constants.Templates[this.options.type]
97
+ const link = emote.toLink({ size, forceStatic, themeMode })
98
+ const res = template
99
+ .replaceAll('{link}', link)
100
+ .replaceAll('{name}', emote.code)
101
+ .replaceAll('{size}', size)
102
+ .replaceAll('{creator}', emote.ownerName || 'global')
103
+
104
+ return res
105
+ })
106
+
107
+ return parsed
108
+ }
98
109
  }
99
110
 
100
- module.exports = EmoteParser;
111
+ export default EmoteParser
@@ -1,13 +1,13 @@
1
- const BTTVEmote = require('./BTTVEmote');
2
- const FFZEmote = require('./FFZEmote');
3
- const SevenTVEmote = require('./SevenTVEmote');
4
- const TwitchEmote = require('./TwitchEmote');
1
+ import BTTVEmote from './BTTVEmote.js'
2
+ import FFZEmote from './FFZEmote.js'
3
+ import SevenTVEmote from './SevenTVEmote.js'
4
+ import TwitchEmote from './TwitchEmote.js'
5
5
 
6
6
  class EmoteTypeMapper {
7
- static getClassByType(type) {
8
- const classMap = { BTTVEmote, FFZEmote, SevenTVEmote, TwitchEmote };
9
- return classMap[type] || null;
10
- }
7
+ static getClassByType (type) {
8
+ const classMap = { BTTVEmote, FFZEmote, SevenTVEmote, TwitchEmote }
9
+ return classMap[type] || null
10
+ }
11
11
  }
12
12
 
13
- module.exports = EmoteTypeMapper;
13
+ export default EmoteTypeMapper
@@ -1,113 +1,111 @@
1
- const Emote = require('./Emote');
2
- const Constants = require('../util/Constants');
1
+ import Emote from './Emote.js'
2
+ import Constants from '../util/Constants.js'
3
3
 
4
4
  /** @augments Emote */
5
5
  class FFZEmote extends Emote {
6
+ /**
7
+ * An FFZ 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 = 'ffz'
15
+ }
16
+
17
+ _setup (data) {
18
+ super._setup(data)
19
+ this.code = data.name
20
+
6
21
  /**
7
- * An FFZ 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.
22
+ * The name of the emote creator's channel.
23
+ * @type {?string}
11
24
  */
12
- constructor(channel, id, data) {
13
- super(channel, id, data);
14
- this.type = 'ffz';
15
- }
25
+ this.ownerName = 'owner' in data ? data.owner.name : null
16
26
 
17
27
  /**
18
- * The channel of this emote's creator.
19
- * Not guaranteed to contain the emote, or be cached.
20
- * @readonly
21
- * @type {?Channel}
28
+ * Available image sizes.
29
+ * @type {string[]}
22
30
  */
23
- get owner() {
24
- return this.fetcher.channels.get(this.ownerName);
25
- }
26
-
27
- _setup(data) {
28
- super._setup(data);
29
- this.code = data.name;
30
-
31
- /**
32
- * The name of the emote creator's channel.
33
- * @type {?string}
34
- */
35
- this.ownerName = 'owner' in data ? data.owner.name : null;
36
-
37
- /**
38
- * Available image sizes.
39
- * @type {string[]}
40
- */
41
- this.sizes = 'animated' in data ? Object.keys(data.animated) : Object.keys(data.urls);
42
-
43
- /**
44
- * If emote is animated.
45
- * @type {boolean}
46
- */
47
- this.animated = 'animated' in data;
48
-
49
- /**
50
- * The image type of the emote.
51
- * @type {string}
52
- */
53
- this.imageType = 'animated' in data ? 'webp' : 'png';
54
-
55
- /**
56
- * If the emote is a modifier and should be hidden.
57
- * @type {boolean}
58
- */
59
- this.modifier = data.modifier && (data.modifier_flags & 1) !== 0;
60
- }
31
+ this.sizes = 'animated' in data ? Object.keys(data.animated) : Object.keys(data.urls)
61
32
 
62
33
  /**
63
- * Gets the image link of the emote.
64
- * @param {number} size - The size of the image.
65
- * @returns {string}
34
+ * If emote is animated.
35
+ * @type {boolean}
66
36
  */
67
- toLink(size = 0) {
68
- size = this.sizes[size];
69
- if (this.animated) return Constants.FFZ.CDNAnimated(this.id, size); // eslint-disable-line new-cap
70
- return Constants.FFZ.CDN(this.id, size); // eslint-disable-line new-cap
71
- }
37
+ this.animated = 'animated' in data
72
38
 
73
39
  /**
74
- * Override for `toObject`.
75
- * Will result in an Object representation of a FFZEmote
76
- * @returns {object}
40
+ * The image type of the emote.
41
+ * @type {string}
77
42
  */
78
- toObject() {
79
- return Object.assign({}, super.toObject(), {
80
- animated: this.animated,
81
- sizes: this.sizes,
82
- ownerName: this.ownerName,
83
- type: this.type,
84
- modifier: this.modifier
85
- });
86
- }
43
+ this.imageType = 'animated' in data ? 'webp' : 'png'
87
44
 
88
45
  /**
89
- * Converts an emote Object into a FFZEmote
90
- * @param {object} [emoteObject] - Object representation of this emote
91
- * @param {Channel} [channel=null] - Channel this emote belongs to.
92
- * @returns {FFZEmote}
46
+ * If the emote is a modifier and should be hidden.
47
+ * @type {boolean}
93
48
  */
94
- static fromObject(emoteObject, channel = null) {
95
- // Need to convert sizes array to object, e.g. [1, 2, 4] -> { 1: '1', 2: '2', 4: '4' }
96
- const sizes_obj = emoteObject.sizes.reduce((acc, curr) => {
97
- acc[curr] = curr;
98
- return acc;
99
- }, {});
100
- return new FFZEmote(channel, emoteObject.id,
101
- {
102
- code: emoteObject.code,
103
- name: emoteObject.code,
104
- urls: sizes_obj,
105
- ...emoteObject.animated ? { animated: sizes_obj } : {},
106
- owner: { name: emoteObject.ownerName },
107
- modifier: emoteObject.modifier,
108
- modifier_flags: emoteObject.modifier
109
- });
49
+ this.modifier = data.modifier && (data.modifier_flags & 1) !== 0
50
+ }
51
+
52
+ /**
53
+ * Gets the image link of the emote.
54
+ * @param {object} [options] - Options for the link.
55
+ * @param {number} [options.size=0] - Size (scale) for the emote.
56
+ * @param {boolean} [options.forceStatic] - Whether to force the emote to be static (non-animated). Defaults to the fetcher's forceStatic or `false`.
57
+ * @returns {string} - The URL to the emote.
58
+ */
59
+ toLink (options) {
60
+ const {
61
+ size = 0,
62
+ forceStatic = this.fetcher.forceStatic || false,
63
+ } = options || {}
64
+
65
+ const sizeKey = this.sizes[size]
66
+ if (this.animated && !forceStatic) return Constants.FFZ.CDNAnimated(this.id, sizeKey)
67
+ return Constants.FFZ.CDN(this.id, sizeKey)
68
+ }
69
+
70
+ /**
71
+ * Override for `toObject`.
72
+ * Will result in an Object representation of a FFZEmote
73
+ * @returns {object} - Object representation of the FFZEmote.
74
+ */
75
+ toObject () {
76
+ return {
77
+ ...super.toObject(),
78
+ animated: this.animated,
79
+ sizes: this.sizes,
80
+ ownerName: this.ownerName,
81
+ type: this.type,
82
+ modifier: this.modifier,
110
83
  }
84
+ }
85
+
86
+ /**
87
+ * Converts an emote Object into a FFZEmote
88
+ * @param {object} [emoteObject] - Object representation of this emote
89
+ * @param {Channel} [channel] - Channel this emote belongs to.
90
+ * @returns {FFZEmote} - A FFZEmote instance.
91
+ */
92
+ static fromObject (emoteObject, channel) {
93
+ // Need to convert sizes array to object, e.g. [1, 2, 4] -> { 1: '1', 2: '2', 4: '4' }
94
+ const sizesObj = emoteObject.sizes.reduce((acc, curr) => {
95
+ acc[curr] = curr
96
+ return acc
97
+ }, {})
98
+ return new FFZEmote(channel, emoteObject.id,
99
+ {
100
+ code: emoteObject.code,
101
+ name: emoteObject.code,
102
+ urls: sizesObj,
103
+ ...emoteObject.animated ? { animated: sizesObj } : {},
104
+ owner: { name: emoteObject.ownerName },
105
+ modifier: emoteObject.modifier,
106
+ modifier_flags: emoteObject.modifier,
107
+ })
108
+ }
111
109
  }
112
110
 
113
- module.exports = FFZEmote;
111
+ export default FFZEmote
@@ -1,108 +1,106 @@
1
- const Emote = require('./Emote');
2
- const Constants = require('../util/Constants');
1
+ import Emote from './Emote.js'
2
+ import Constants from '../util/Constants.js'
3
3
 
4
4
  /** @augments Emote */
5
5
  class SevenTVEmote extends Emote {
6
- /**
7
- * A 7TV 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 = '7tv';
15
- }
6
+ /**
7
+ * A 7TV 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 = '7tv'
15
+ }
16
+
17
+ _setup (data) {
18
+ super._setup(data)
19
+ this.code = data.name
16
20
 
17
21
  /**
18
- * The channel of this emote's creator.
19
- * Not guaranteed to contain the emote, or be cached.
20
- * @readonly
21
- * @type {?Channel}
22
+ * The name of the emote creator's channel.
23
+ * @type {?string}
22
24
  */
23
- get owner() {
24
- return this.fetcher.channels.get(this.ownerName);
25
- }
26
-
27
- _setup(data) {
28
- super._setup(data);
29
- this.code = data.name;
30
-
31
- /**
32
- * The name of the emote creator's channel.
33
- * @type {?string}
34
- */
35
- this.ownerName = 'owner' in data.data ? data.data.owner.display_name : null;
36
-
37
- /**
38
- * Available image sizes.
39
- * @type {string[]}
40
- */
41
- this.sizes = data.data.host.files
42
- .filter(el => el.format === this.channel.format.toUpperCase())
43
- .map(el => el.name);
44
-
45
- /**
46
- * If emote is animated.
47
- * @type {boolean}
48
- */
49
- this.animated = data.data.animated;
50
-
51
- /**
52
- * The image type of the emote.
53
- * @type {string}
54
- */
55
- this.imageType = this.channel.format;
56
- }
25
+ this.ownerName = 'owner' in data.data ? data.data.owner.display_name : null
57
26
 
58
27
  /**
59
- * Gets the image link of the emote.
60
- * @param {number} size - The size of the image.
61
- * @returns {string}
28
+ * Available image sizes.
29
+ * @type {string[]}
62
30
  */
63
- toLink(size = 0) {
64
- size = this.sizes[size];
65
- return Constants.SevenTV.CDN(this.id, size); // eslint-disable-line new-cap
66
- }
31
+ this.sizes = data.data.host.files
32
+ .filter((el) => el.format === this.channel.format.toUpperCase())
33
+ .map((el) => el.name.replace(/x\.(\w+)/, ''))
67
34
 
68
35
  /**
69
- * Override for `toObject`.
70
- * Will result in an Object representation of a SevenTVEmote
71
- * @returns {object}
36
+ * If emote is animated.
37
+ * @type {boolean}
72
38
  */
73
- toObject() {
74
- return Object.assign({}, super.toObject(), {
75
- animated: this.animated,
76
- sizes: this.sizes,
77
- ownerName: this.ownerName,
78
- type: this.type,
79
- imageType: this.imageType
80
- });
81
- }
39
+ this.animated = data.data.animated
82
40
 
83
41
  /**
84
- * Converts an emote Object into a SevenTVEmote
85
- * @param {object} [emoteObject] - Object representation of this emote
86
- * @param {Channel} [channel] - Channel this emote belongs to.
87
- * @returns {SevenTVEmote}
42
+ * The image type of the emote.
43
+ * @type {string}
88
44
  */
89
- static fromObject(emoteObject, channel) {
90
- const sizes = emoteObject.sizes.map(size => { return { format: channel.format.toUpperCase(), name: size }; });
91
- return new SevenTVEmote(channel, emoteObject.id,
92
- {
93
- code: emoteObject.code,
94
- name: emoteObject.code,
95
- data: {
96
- animated: emoteObject.animated,
97
- owner: {
98
- display_name: emoteObject.ownerName
99
- },
100
- host: {
101
- files: sizes
102
- }
103
- }
104
- });
45
+ this.imageType = this.channel.format
46
+ }
47
+
48
+ /**
49
+ * Gets the image link of the emote.
50
+ * @param {object} [options] - Options for the link.
51
+ * @param {number} [options.size=0] - Size (scale) for the emote.
52
+ * @param {boolean} [options.forceStatic] - Whether to force the emote to be static (non-animated). Defaults to the fetcher's forceStatic or `false`.
53
+ * @returns {string} - The URL to the emote.
54
+ */
55
+ toLink (options) {
56
+ const {
57
+ size = 0,
58
+ forceStatic = this.fetcher.forceStatic || false,
59
+ } = options || {}
60
+
61
+ const sizeKey = this.sizes[size]
62
+ return Constants.SevenTV.CDN(this.id, this.imageType, sizeKey, forceStatic)
63
+ }
64
+
65
+ /**
66
+ * Override for `toObject`.
67
+ * Will result in an Object representation of a SevenTVEmote
68
+ * @returns {object} - Object representation of the SevenTVEmote.
69
+ */
70
+ toObject () {
71
+ return {
72
+ ...super.toObject(),
73
+ animated: this.animated,
74
+ sizes: this.sizes,
75
+ ownerName: this.ownerName,
76
+ type: this.type,
77
+ imageType: this.imageType,
105
78
  }
79
+ }
80
+
81
+ /**
82
+ * Converts an emote Object into a SevenTVEmote
83
+ * @param {object} [emoteObject] - Object representation of this emote
84
+ * @param {Channel} [channel] - Channel this emote belongs to.
85
+ * @returns {SevenTVEmote} - A SevenTVEmote instance.
86
+ */
87
+ static fromObject (emoteObject, channel) {
88
+ const sizes = emoteObject.sizes.map((size) => { return { format: channel.format.toUpperCase(), name: size } })
89
+ return new SevenTVEmote(channel, emoteObject.id,
90
+ {
91
+ code: emoteObject.code,
92
+ name: emoteObject.code,
93
+ data: {
94
+ animated: emoteObject.animated,
95
+ owner: {
96
+ display_name: emoteObject.ownerName,
97
+ },
98
+ host: {
99
+ files: sizes,
100
+ },
101
+ },
102
+ })
103
+ }
106
104
  }
107
105
 
108
- module.exports = SevenTVEmote;
106
+ export default SevenTVEmote