@mkody/twitch-emoticons 2.9.3 → 2.9.5

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.
@@ -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
  );
@@ -117,8 +117,8 @@ declare module '@mkody/twitch-emoticons' {
117
117
  }
118
118
 
119
119
  export class Collection<K, V> extends Map<K, V> {
120
- public find(propOrFunc: string | ((item: K, index: number, coll: this) => boolean), value?: any): K;
121
- public filter(func: (item: K, index: number, coll: this) => boolean): Collection<K, V>;
122
- public map(func: (item: K, index: number, coll: this) => any): Array<any>;
120
+ public find(propOrFunc: string | ((item: V, index: number, coll: this) => boolean), value?: any): V;
121
+ public filter(func: (item: V, index: number, coll: this) => boolean): Collection<K, V>;
122
+ public map(func: (item: V, index: number, coll: this) => any): Array<any>;
123
123
  }
124
124
  }