@mkody/twitch-emoticons 2.7.0 → 2.7.1

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 (43) 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/docs/BTTVEmote.html +1319 -1319
  11. package/docs/Channel.html +823 -823
  12. package/docs/Collection.html +797 -797
  13. package/docs/Emote.html +801 -801
  14. package/docs/EmoteFetcher.html +2946 -2946
  15. package/docs/EmoteParser.html +811 -811
  16. package/docs/FFZEmote.html +1473 -1473
  17. package/docs/SevenTV.html +1190 -1190
  18. package/docs/SevenTVEmote.html +1395 -1395
  19. package/docs/TwitchEmote.html +1315 -1315
  20. package/docs/index.html +206 -206
  21. package/docs/struct_BTTVEmote.js.html +132 -132
  22. package/docs/struct_Channel.js.html +127 -127
  23. package/docs/struct_Emote.js.html +138 -138
  24. package/docs/struct_EmoteFetcher.js.html +395 -399
  25. package/docs/struct_EmoteParser.js.html +153 -153
  26. package/docs/struct_FFZEmote.js.html +146 -146
  27. package/docs/struct_SevenTVEmote.js.html +141 -141
  28. package/docs/struct_TwitchEmote.js.html +130 -130
  29. package/docs/util_Collection.js.html +150 -150
  30. package/package.json +57 -57
  31. package/src/index.js +12 -12
  32. package/src/struct/BTTVEmote.js +60 -60
  33. package/src/struct/Channel.js +55 -55
  34. package/src/struct/Emote.js +66 -66
  35. package/src/struct/EmoteFetcher.js +323 -327
  36. package/src/struct/EmoteParser.js +81 -81
  37. package/src/struct/FFZEmote.js +74 -74
  38. package/src/struct/SevenTVEmote.js +69 -69
  39. package/src/struct/TwitchEmote.js +58 -58
  40. package/src/util/Collection.js +78 -78
  41. package/src/util/Constants.js +31 -31
  42. package/test/index.js +174 -174
  43. package/typings/index.d.ts +98 -98
@@ -1,81 +1,81 @@
1
- const Constants = require('../util/Constants');
2
-
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 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.
19
- */
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
- }
39
-
40
- _validateOptions(options) {
41
- if (options.template && typeof options.template !== 'string') {
42
- throw new TypeError('Template must be a string');
43
- }
44
-
45
- if (!['markdown', 'html', 'bbcode', 'plain'].includes(options.type)) {
46
- throw new TypeError('Parse type must be one of `markdown`, `html`, `bbcode`, or `plain`');
47
- }
48
-
49
- if (!(options.match instanceof RegExp) || !options.match.global) {
50
- throw new TypeError('Match must be a global RegExp.');
51
- }
52
- }
53
-
54
- /**
55
- * Parses text.
56
- * @param {string} text - Text to parse.
57
- * @param {number} size - Size for emotes.
58
- * @returns {string}
59
- */
60
- parse(text, size = 0) {
61
- const parsed = text.replace(this.options.match, (matched, id) => {
62
- const emote = this.fetcher.emotes.get(id);
63
- if (!emote) return matched;
64
- if (emote.modifier) return '';
65
-
66
- const template = this.options.template || Constants.Templates[this.options.type];
67
- const link = emote.toLink(size);
68
- const res = template
69
- .replace(/{link}/g, link)
70
- .replace(/{name}/g, emote.code)
71
- .replace(/{size}/g, size)
72
- .replace(/{creator}/g, emote.ownerName || 'global');
73
-
74
- return res;
75
- });
76
-
77
- return parsed;
78
- }
79
- }
80
-
81
- module.exports = EmoteParser;
1
+ const Constants = require('../util/Constants');
2
+
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 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.
19
+ */
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
+ }
39
+
40
+ _validateOptions(options) {
41
+ if (options.template && typeof options.template !== 'string') {
42
+ throw new TypeError('Template must be a string');
43
+ }
44
+
45
+ if (!['markdown', 'html', 'bbcode', 'plain'].includes(options.type)) {
46
+ throw new TypeError('Parse type must be one of `markdown`, `html`, `bbcode`, or `plain`');
47
+ }
48
+
49
+ if (!(options.match instanceof RegExp) || !options.match.global) {
50
+ throw new TypeError('Match must be a global RegExp.');
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Parses text.
56
+ * @param {string} text - Text to parse.
57
+ * @param {number} size - Size for emotes.
58
+ * @returns {string}
59
+ */
60
+ parse(text, size = 0) {
61
+ const parsed = text.replace(this.options.match, (matched, id) => {
62
+ const emote = this.fetcher.emotes.get(id);
63
+ if (!emote) return matched;
64
+ if (emote.modifier) return '';
65
+
66
+ const template = this.options.template || Constants.Templates[this.options.type];
67
+ const link = emote.toLink(size);
68
+ const res = template
69
+ .replace(/{link}/g, link)
70
+ .replace(/{name}/g, emote.code)
71
+ .replace(/{size}/g, size)
72
+ .replace(/{creator}/g, emote.ownerName || 'global');
73
+
74
+ return res;
75
+ });
76
+
77
+ return parsed;
78
+ }
79
+ }
80
+
81
+ module.exports = EmoteParser;
@@ -1,74 +1,74 @@
1
- const Emote = require('./Emote');
2
- const Constants = require('../util/Constants');
3
-
4
- /** @extends Emote */
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
- /**
18
- * The channel of this emote's creator.
19
- * Not guaranteed to contain the emote, or be cached.
20
- * @readonly
21
- * @type {?Channel}
22
- */
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 = data.owner.name;
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
- }
61
-
62
- /**
63
- * Gets the image link of the emote.
64
- * @param {number} size - The size of the image.
65
- * @returns {string}
66
- */
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
- }
72
- }
73
-
74
- module.exports = FFZEmote;
1
+ const Emote = require('./Emote');
2
+ const Constants = require('../util/Constants');
3
+
4
+ /** @extends Emote */
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
+ /**
18
+ * The channel of this emote's creator.
19
+ * Not guaranteed to contain the emote, or be cached.
20
+ * @readonly
21
+ * @type {?Channel}
22
+ */
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
+ }
61
+
62
+ /**
63
+ * Gets the image link of the emote.
64
+ * @param {number} size - The size of the image.
65
+ * @returns {string}
66
+ */
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
+ }
72
+ }
73
+
74
+ module.exports = FFZEmote;
@@ -1,69 +1,69 @@
1
- const Emote = require('./Emote');
2
- const Constants = require('../util/Constants');
3
-
4
- /** @extends Emote */
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
- }
16
-
17
- /**
18
- * The channel of this emote's creator.
19
- * Not guaranteed to contain the emote, or be cached.
20
- * @readonly
21
- * @type {?Channel}
22
- */
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 = data.owner.display_name;
36
-
37
- /**
38
- * Available image sizes.
39
- * @type {string[]}
40
- */
41
- this.sizes = 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.animated;
50
-
51
- /**
52
- * The image type of the emote.
53
- * @type {string}
54
- */
55
- this.imageType = this.channel.format;
56
- }
57
-
58
- /**
59
- * Gets the image link of the emote.
60
- * @param {number} size - The size of the image.
61
- * @returns {string}
62
- */
63
- toLink(size = 0) {
64
- size = this.sizes[size];
65
- return Constants.SevenTV.CDN(this.id, size); // eslint-disable-line new-cap
66
- }
67
- }
68
-
69
- module.exports = SevenTVEmote;
1
+ const Emote = require('./Emote');
2
+ const Constants = require('../util/Constants');
3
+
4
+ /** @extends Emote */
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
+ }
16
+
17
+ /**
18
+ * The channel of this emote's creator.
19
+ * Not guaranteed to contain the emote, or be cached.
20
+ * @readonly
21
+ * @type {?Channel}
22
+ */
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.display_name : null;
36
+
37
+ /**
38
+ * Available image sizes.
39
+ * @type {string[]}
40
+ */
41
+ this.sizes = 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.animated;
50
+
51
+ /**
52
+ * The image type of the emote.
53
+ * @type {string}
54
+ */
55
+ this.imageType = this.channel.format;
56
+ }
57
+
58
+ /**
59
+ * Gets the image link of the emote.
60
+ * @param {number} size - The size of the image.
61
+ * @returns {string}
62
+ */
63
+ toLink(size = 0) {
64
+ size = this.sizes[size];
65
+ return Constants.SevenTV.CDN(this.id, size); // eslint-disable-line new-cap
66
+ }
67
+ }
68
+
69
+ module.exports = SevenTVEmote;
@@ -1,58 +1,58 @@
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
+ module.exports = TwitchEmote;