@mkody/twitch-emoticons 2.9.2 → 2.9.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.
@@ -29,7 +29,7 @@
29
29
  <nav >
30
30
 
31
31
 
32
- <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BTTVEmote.html">BTTVEmote</a><ul class='methods'><li data-type='method'><a href="BTTVEmote.html#toLink">toLink</a></li><li data-type='method'><a href="BTTVEmote.html#toObject">toObject</a></li><li data-type='method'><a href="BTTVEmote.html#.fromObject">fromObject</a></li></ul></li><li><a href="Channel.html">Channel</a><ul class='methods'><li data-type='method'><a href="Channel.html#fetchBTTVEmotes">fetchBTTVEmotes</a></li><li data-type='method'><a href="Channel.html#fetchFFZEmotes">fetchFFZEmotes</a></li><li data-type='method'><a href="Channel.html#fetchSevenTVEmotes">fetchSevenTVEmotes</a></li></ul></li><li><a href="Collection.html">Collection</a><ul class='methods'><li data-type='method'><a href="Collection.html#filter">filter</a></li><li data-type='method'><a href="Collection.html#find">find</a></li><li data-type='method'><a href="Collection.html#map">map</a></li></ul></li><li><a href="Emote.html">Emote</a><ul class='methods'><li data-type='method'><a href="Emote.html#toObject">toObject</a></li></ul></li><li><a href="EmoteFetcher.html">EmoteFetcher</a><ul class='methods'><li data-type='method'><a href="EmoteFetcher.html#_cacheBTTVEmote">_cacheBTTVEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheFFZEmote">_cacheFFZEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheSevenTVEmote">_cacheSevenTVEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheTwitchEmote">_cacheTwitchEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawBTTVEmotes">_getRawBTTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawFFZEmoteSet">_getRawFFZEmoteSet</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawFFZEmotes">_getRawFFZEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawSevenTVEmotes">_getRawSevenTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawTwitchEmotes">_getRawTwitchEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_setupChannel">_setupChannel</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchBTTVEmotes">fetchBTTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchFFZEmotes">fetchFFZEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchSevenTVEmotes">fetchSevenTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchTwitchEmotes">fetchTwitchEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fromObject">fromObject</a></li></ul></li><li><a href="EmoteParser.html">EmoteParser</a><ul class='methods'><li data-type='method'><a href="EmoteParser.html#parse">parse</a></li></ul></li><li><a href="FFZEmote.html">FFZEmote</a><ul class='methods'><li data-type='method'><a href="FFZEmote.html#toLink">toLink</a></li><li data-type='method'><a href="FFZEmote.html#toObject">toObject</a></li><li data-type='method'><a href="FFZEmote.html#.fromObject">fromObject</a></li></ul></li><li><a href="SevenTVEmote.html">SevenTVEmote</a><ul class='methods'><li data-type='method'><a href="SevenTVEmote.html#toLink">toLink</a></li><li data-type='method'><a href="SevenTVEmote.html#toObject">toObject</a></li><li data-type='method'><a href="SevenTVEmote.html#.fromObject">fromObject</a></li></ul></li><li><a href="TwitchEmote.html">TwitchEmote</a><ul class='methods'><li data-type='method'><a href="TwitchEmote.html#toLink">toLink</a></li><li data-type='method'><a href="TwitchEmote.html#toObject">toObject</a></li><li data-type='method'><a href="TwitchEmote.html#.fromObject">fromObject</a></li></ul></li></ul>
32
+ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BTTVEmote.html">BTTVEmote</a><ul class='methods'><li data-type='method'><a href="BTTVEmote.html#toLink">toLink</a></li><li data-type='method'><a href="BTTVEmote.html#toObject">toObject</a></li><li data-type='method'><a href="BTTVEmote.html#.fromObject">fromObject</a></li></ul></li><li><a href="Channel.html">Channel</a><ul class='methods'><li data-type='method'><a href="Channel.html#fetchBTTVEmotes">fetchBTTVEmotes</a></li><li data-type='method'><a href="Channel.html#fetchFFZEmotes">fetchFFZEmotes</a></li><li data-type='method'><a href="Channel.html#fetchSevenTVEmotes">fetchSevenTVEmotes</a></li></ul></li><li><a href="Collection.html">Collection</a><ul class='methods'><li data-type='method'><a href="Collection.html#filter">filter</a></li><li data-type='method'><a href="Collection.html#find">find</a></li><li data-type='method'><a href="Collection.html#map">map</a></li></ul></li><li><a href="Emote.html">Emote</a><ul class='methods'><li data-type='method'><a href="Emote.html#toObject">toObject</a></li></ul></li><li><a href="EmoteFetcher.html">EmoteFetcher</a><ul class='methods'><li data-type='method'><a href="EmoteFetcher.html#_cacheBTTVEmote">_cacheBTTVEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheFFZEmote">_cacheFFZEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheSevenTVEmote">_cacheSevenTVEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_cacheTwitchEmote">_cacheTwitchEmote</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawBTTVEmotes">_getRawBTTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawFFZEmoteSet">_getRawFFZEmoteSet</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawFFZEmotes">_getRawFFZEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawSevenTVEmotes">_getRawSevenTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_getRawTwitchEmotes">_getRawTwitchEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#_setupChannel">_setupChannel</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchBTTVEmotes">fetchBTTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchFFZEmotes">fetchFFZEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchSevenTVEmotes">fetchSevenTVEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fetchTwitchEmotes">fetchTwitchEmotes</a></li><li data-type='method'><a href="EmoteFetcher.html#fromObject">fromObject</a></li></ul></li><li><a href="EmoteParser.html">EmoteParser</a><ul class='methods'><li data-type='method'><a href="EmoteParser.html#_validateOptions">_validateOptions</a></li><li data-type='method'><a href="EmoteParser.html#parse">parse</a></li></ul></li><li><a href="FFZEmote.html">FFZEmote</a><ul class='methods'><li data-type='method'><a href="FFZEmote.html#toLink">toLink</a></li><li data-type='method'><a href="FFZEmote.html#toObject">toObject</a></li><li data-type='method'><a href="FFZEmote.html#.fromObject">fromObject</a></li></ul></li><li><a href="SevenTVEmote.html">SevenTVEmote</a><ul class='methods'><li data-type='method'><a href="SevenTVEmote.html#toLink">toLink</a></li><li data-type='method'><a href="SevenTVEmote.html#toObject">toObject</a></li><li data-type='method'><a href="SevenTVEmote.html#.fromObject">fromObject</a></li></ul></li><li><a href="TwitchEmote.html">TwitchEmote</a><ul class='methods'><li data-type='method'><a href="TwitchEmote.html#toLink">toLink</a></li><li data-type='method'><a href="TwitchEmote.html#toObject">toObject</a></li><li data-type='method'><a href="TwitchEmote.html#.fromObject">fromObject</a></li></ul></li></ul>
33
33
 
34
34
  </nav>
35
35
 
@@ -45,7 +45,8 @@
45
45
 
46
46
  <section>
47
47
  <article>
48
- <pre class="prettyprint source linenums"><code>/**
48
+ <pre class="prettyprint source linenums"><code>/* eslint-disable jsdoc/reject-function-type, jsdoc/reject-any-type */
49
+ /**
49
50
  * An extended Map with utility methods.
50
51
  * @class Collection
51
52
  */
@@ -137,7 +138,7 @@ module.exports = Collection;
137
138
  <br class="clear">
138
139
 
139
140
  <footer>
140
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
141
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
141
142
  </footer>
142
143
 
143
144
  <script>prettyPrint();</script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mkody/twitch-emoticons",
3
- "version": "2.9.2",
3
+ "version": "2.9.4",
4
4
  "description": "Gets Twitch, BTTV, FFZ and 7TV emotes as well as parsing text to emotes!",
5
5
  "main": "src/index.js",
6
6
  "typings": "typings/index.d.ts",
@@ -26,21 +26,21 @@
26
26
  ],
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "@twurple/api": "^7.3.0",
30
- "@twurple/auth": "^7.3.0",
31
- "axios": "^1.9.0"
29
+ "@twurple/api": "^7.4.0",
30
+ "@twurple/auth": "^7.4.0",
31
+ "axios": "^1.12.2"
32
32
  },
33
33
  "devDependencies": {
34
- "@eslint/js": "^9.27.0",
35
- "@jest/globals": "^29.7.0",
34
+ "@eslint/js": "^9.38.0",
35
+ "@jest/globals": "^30.2.0",
36
36
  "@microsoft/eslint-formatter-sarif": "^3.1.0",
37
37
  "docdash": "^2.0.2",
38
- "esbuild": "^0.25.4",
39
- "eslint": "^9.27.0",
40
- "eslint-plugin-jsdoc": "^50.6.17",
41
- "globals": "^16.1.0",
42
- "jest": "^29.7.0",
43
- "jsdoc": "^4.0.4"
38
+ "esbuild": "^0.25.11",
39
+ "eslint": "^9.38.0",
40
+ "eslint-plugin-jsdoc": "^61.1.5",
41
+ "globals": "^16.4.0",
42
+ "jest": "^30.2.0",
43
+ "jsdoc": "^4.0.5"
44
44
  },
45
45
  "scripts": {
46
46
  "all": "pnpm run lint && pnpm run test && pnpm run build && pnpm run docs",
@@ -65,10 +65,11 @@
65
65
  "node": ">=18.0.0",
66
66
  "pnpm": ">=9"
67
67
  },
68
- "packageManager": "pnpm@10.11.0",
68
+ "packageManager": "pnpm@10.18.3",
69
69
  "pnpm": {
70
70
  "onlyBuiltDependencies": [
71
- "esbuild"
71
+ "esbuild",
72
+ "unrs-resolver"
72
73
  ]
73
74
  }
74
75
  }
@@ -5,6 +5,7 @@ class Emote {
5
5
  * @param {Channel} channel - Channel this emote belongs to.
6
6
  * @param {string} id - ID of the emote.
7
7
  * @param {data} data - The raw emote data.
8
+ * @throws {Error} When trying to use the base Emote class directly.
8
9
  */
9
10
  constructor(channel, id, data) {
10
11
  if (new.target.name === Emote.name) {
@@ -65,6 +65,7 @@ class EmoteFetcher {
65
65
  * @private
66
66
  * @param {int} channel_id - ID of the channel.
67
67
  * @param {string} [format=null] - The type file format to use (webp/avif).
68
+ * @throws {Error} When Twitch Client ID or Client Secret were not provided.
68
69
  * @returns {Channel}
69
70
  */
70
71
  _setupChannel(channel_id, format = null) {
@@ -326,6 +327,7 @@ class EmoteFetcher {
326
327
  /**
327
328
  * Converts emote Objects to emotes
328
329
  * @param {object} [emotesArray] - An array of emote objects
330
+ * @throws {TypeError} When an emote has an unknown type.
329
331
  * @returns {Emote[]}
330
332
  */
331
333
  fromObject(emotesArray) {
@@ -5,7 +5,7 @@ class EmoteParser {
5
5
  * A parser to replace text with emotes.
6
6
  * @param {EmoteFetcher} fetcher - The fetcher to use the cache of.
7
7
  * @param {object} [options={}] - Options for the parser.
8
- * @param {string} [options.template] - The template to be used.
8
+ * @param {string} [options.template=''] - The template to be used.
9
9
  * The strings that can be interpolated are:
10
10
  * - `{link}` The link of the emote.
11
11
  * - `{name}` The name of the emote.
@@ -37,6 +37,25 @@ class EmoteParser {
37
37
  this._validateOptions(this.options);
38
38
  }
39
39
 
40
+ /**
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.
58
+ */
40
59
  _validateOptions(options) {
41
60
  if (options.template && typeof options.template !== 'string') {
42
61
  throw new TypeError('Template must be a string');
@@ -1,3 +1,4 @@
1
+ /* eslint-disable jsdoc/reject-function-type, jsdoc/reject-any-type */
1
2
  /**
2
3
  * An extended Map with utility methods.
3
4
  * @class Collection
@@ -15,12 +15,12 @@ describe('Test 7TV emotes', () => {
15
15
 
16
16
  test('Get emote (EZ)', () => {
17
17
  const emote = emoteFetcher.emotes.get('EZ');
18
- expect(emote.toLink(2)).toBe('https://cdn.7tv.app/emote/01GB9W6V0000098BZVD7GKTW0F/3x.webp');
18
+ expect(emote.toLink(2)).toBe('https://cdn.7tv.app/emote/01K6WWG0R4T5A9FVNN4TWCWXA7/3x.webp');
19
19
  });
20
20
 
21
21
  test('Parse string with emote (EZ)', () => {
22
22
  const text = emoteParser.parse('This is a test string with :EZ: in it.');
23
- expect(text).toBe('This is a test string with ![EZ](https://cdn.7tv.app/emote/01GB9W6V0000098BZVD7GKTW0F/1x.webp "EZ") in it.');
23
+ expect(text).toBe('This is a test string with ![EZ](https://cdn.7tv.app/emote/01K6WWG0R4T5A9FVNN4TWCWXA7/1x.webp "EZ") in it.');
24
24
  });
25
25
  });
26
26
 
@@ -37,12 +37,12 @@ describe('Test 7TV emotes', () => {
37
37
 
38
38
  test('Get emote (Clap)', () => {
39
39
  const emote = emoteFetcher.emotes.get('Clap');
40
- expect(emote.toLink(2)).toBe('https://cdn.7tv.app/emote/01GAM8EFQ00004MXFXAJYKA859/3x.avif');
40
+ expect(emote.toLink(2)).toBe('https://cdn.7tv.app/emote/01GF9MNXQ8000E85YTZ0P4TWJ7/3x.avif');
41
41
  });
42
42
 
43
43
  test('Parse string with emote (Clap)', () => {
44
44
  const text = emoteParser.parse('This is a test string with :Clap: in it.');
45
- expect(text).toBe('This is a test string with ![Clap](https://cdn.7tv.app/emote/01GAM8EFQ00004MXFXAJYKA859/1x.avif "Clap") in it.');
45
+ expect(text).toBe('This is a test string with ![Clap](https://cdn.7tv.app/emote/01GF9MNXQ8000E85YTZ0P4TWJ7/1x.avif "Clap") in it.');
46
46
  });
47
47
  });
48
48
 
@@ -1,13 +1,13 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
1
+ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2
2
 
3
3
  exports[`Test toObject 7TV Global Emote (AVIF) 1`] = `
4
4
  {
5
5
  "animated": false,
6
6
  "channel_id": null,
7
7
  "code": "EZ",
8
- "id": "01GB9W6V0000098BZVD7GKTW0F",
8
+ "id": "01K6WWG0R4T5A9FVNN4TWCWXA7",
9
9
  "imageType": "avif",
10
- "ownerName": "Kh4N_02",
10
+ "ownerName": "TrippyColour",
11
11
  "sizes": [
12
12
  "1x.avif",
13
13
  "2x.avif",
@@ -1,5 +1,5 @@
1
1
  const { describe, expect, test } = require('@jest/globals');
2
- const { Emote } = require('../src/index.js');
2
+ const { Emote, EmoteFetcher, EmoteParser } = require('../src/index.js');
3
3
 
4
4
  describe('Emote class', () => {
5
5
  test('Base Emote class should not be used by itself', () => {
@@ -11,3 +11,62 @@ describe('Emote class', () => {
11
11
  );
12
12
  });
13
13
  });
14
+
15
+ describe('EmoteParser\'s _validateOptions', () => {
16
+ const fetcher = new EmoteFetcher();
17
+
18
+ test('Should not throw on valid options', () => {
19
+ expect(() => {
20
+ // eslint-disable-next-line no-unused-vars
21
+ const parser = new EmoteParser(fetcher, {
22
+ template: '![{name}]({link} "{name}")',
23
+ type: 'markdown',
24
+ match: /:(.+?):/g
25
+ });
26
+ }).not.toThrow();
27
+ });
28
+
29
+ test('Should throw on invalid template', () => {
30
+ expect(() => {
31
+ // eslint-disable-next-line no-unused-vars
32
+ const parser = new EmoteParser(fetcher, {
33
+ template: () => { return 'test'; }
34
+ });
35
+ }).toThrow(
36
+ new TypeError('Template must be a string')
37
+ );
38
+ });
39
+
40
+ test('Should throw on invalid type', () => {
41
+ expect(() => {
42
+ // eslint-disable-next-line no-unused-vars
43
+ const parser = new EmoteParser(fetcher, {
44
+ type: 'invalid-type'
45
+ });
46
+ }).toThrow(
47
+ new TypeError('Parse type must be one of `markdown`, `html`, `bbcode`, or `plain`')
48
+ );
49
+ });
50
+
51
+ test('Should throw when not using a global regex', () => {
52
+ expect(() => {
53
+ // eslint-disable-next-line no-unused-vars
54
+ const parser = new EmoteParser(fetcher, {
55
+ match: /:(.+?):/
56
+ });
57
+ }).toThrow(
58
+ new TypeError('Match must be a global RegExp.')
59
+ );
60
+ });
61
+
62
+ test('Should throw when not using a regex object', () => {
63
+ expect(() => {
64
+ // eslint-disable-next-line no-unused-vars
65
+ const parser = new EmoteParser(fetcher, {
66
+ match: 'not-a-regex'
67
+ });
68
+ }).toThrow(
69
+ new TypeError('Match must be a global RegExp.')
70
+ );
71
+ });
72
+ });
@@ -45,7 +45,7 @@ declare module '@mkody/twitch-emoticons' {
45
45
  fetcher: EmoteFetcher,
46
46
  options: {
47
47
  template?: string,
48
- type?: string,
48
+ type?: 'html' | 'markdown' | 'bbcode' | 'plain',
49
49
  match?: RegExp
50
50
  }
51
51
  );