@mkody/twitch-emoticons 2.5.0 → 2.6.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 (42) hide show
  1. package/.github/codeql/codeql-config.yml +5 -0
  2. package/.github/workflows/codeql.yml +50 -0
  3. package/.github/workflows/eslint.yml +51 -0
  4. package/.github/workflows/yarn-test.yml +0 -1
  5. package/.jsdoc.json +5 -0
  6. package/LICENSE +1 -0
  7. package/README.md +85 -13
  8. package/docs/BTTVEmote.html +1241 -1191
  9. package/docs/Channel.html +823 -700
  10. package/docs/Collection.html +797 -791
  11. package/docs/Emote.html +801 -768
  12. package/docs/EmoteFetcher.html +2694 -2075
  13. package/docs/EmoteParser.html +811 -792
  14. package/docs/FFZEmote.html +1317 -1263
  15. package/docs/SevenTV.html +1191 -0
  16. package/docs/SevenTVEmote.html +1318 -0
  17. package/docs/TwitchEmote.html +1237 -1189
  18. package/docs/index.html +201 -132
  19. package/docs/scripts/collapse.js +38 -19
  20. package/docs/scripts/commonNav.js +28 -0
  21. package/docs/scripts/search.js +98 -82
  22. package/docs/struct_BTTVEmote.js.html +72 -69
  23. package/docs/struct_Channel.js.html +88 -77
  24. package/docs/struct_Emote.js.html +73 -70
  25. package/docs/struct_EmoteFetcher.js.html +168 -109
  26. package/docs/struct_EmoteParser.js.html +72 -69
  27. package/docs/struct_FFZEmote.js.html +72 -69
  28. package/docs/struct_SevenTVEmote.js.html +135 -0
  29. package/docs/struct_TwitchEmote.js.html +72 -69
  30. package/docs/styles/jsdoc.css +776 -765
  31. package/docs/styles/prettify.css +80 -79
  32. package/docs/util_Collection.js.html +72 -69
  33. package/package.json +15 -13
  34. package/src/index.js +4 -3
  35. package/src/struct/Channel.js +16 -8
  36. package/src/struct/Emote.js +1 -1
  37. package/src/struct/EmoteFetcher.js +96 -40
  38. package/src/struct/SevenTVEmote.js +63 -0
  39. package/src/util/Constants.js +5 -1
  40. package/test/index.js +39 -3
  41. package/typings/index.d.ts +35 -18
  42. package/typings/test.ts +0 -24
@@ -0,0 +1,5 @@
1
+ name: "CodeQL config"
2
+
3
+ paths-ignore:
4
+ - docs
5
+ - test
@@ -0,0 +1,50 @@
1
+ name: "CodeQL"
2
+
3
+ on:
4
+ push:
5
+ branches: [ "master" ]
6
+ pull_request:
7
+ # The branches below must be a subset of the branches above
8
+ branches: [ "master" ]
9
+ schedule:
10
+ - cron: '23 11 * * 0'
11
+
12
+ jobs:
13
+ analyze:
14
+ name: Analyze
15
+ runs-on: ubuntu-latest
16
+ permissions:
17
+ actions: read
18
+ contents: read
19
+ security-events: write
20
+
21
+ strategy:
22
+ fail-fast: false
23
+ matrix:
24
+ language: [ 'javascript' ]
25
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
26
+ # Use only 'java' to analyze code written in Java, Kotlin or both
27
+ # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
28
+ # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
29
+
30
+ steps:
31
+ - name: Checkout repository
32
+ uses: actions/checkout@v3
33
+
34
+ # Initializes the CodeQL tools for scanning.
35
+ - name: Initialize CodeQL
36
+ uses: github/codeql-action/init@v2
37
+ with:
38
+ languages: ${{ matrix.language }}
39
+ config-file: ./.github/codeql/codeql-config.yml
40
+ # If you wish to specify custom queries, you can do so here or in a config file.
41
+ # By default, queries listed here will override any specified in a config file.
42
+ # Prefix the list here with "+" to use these queries and those in the config file.
43
+
44
+ # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
45
+ # queries: security-extended,security-and-quality
46
+
47
+ - name: Perform CodeQL Analysis
48
+ uses: github/codeql-action/analyze@v2
49
+ with:
50
+ category: "/language:${{matrix.language}}"
@@ -0,0 +1,51 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # ESLint is a tool for identifying and reporting on patterns
6
+ # found in ECMAScript/JavaScript code.
7
+ # More details at https://github.com/eslint/eslint
8
+ # and https://eslint.org
9
+
10
+ name: ESLint
11
+
12
+ on:
13
+ push:
14
+ branches: [ "master" ]
15
+ pull_request:
16
+ # The branches below must be a subset of the branches above
17
+ branches: [ "master" ]
18
+ schedule:
19
+ - cron: '26 14 * * 6'
20
+
21
+ jobs:
22
+ eslint:
23
+ name: Run eslint scanning
24
+ runs-on: ubuntu-latest
25
+ permissions:
26
+ contents: read
27
+ security-events: write
28
+ actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
29
+ steps:
30
+ - name: Checkout code
31
+ uses: actions/checkout@v3
32
+
33
+ - name: Install ESLint
34
+ run: |
35
+ npm install eslint@8.29.0
36
+ npm install @microsoft/eslint-formatter-sarif@3.0.0
37
+
38
+ - name: Run ESLint
39
+ run: npx eslint ./src ./test
40
+ --config .eslintrc.json
41
+ --ext .js,.jsx,.ts,.tsx
42
+ --format @microsoft/eslint-formatter-sarif
43
+ --output-file eslint-results.sarif
44
+ continue-on-error: true
45
+
46
+ - name: Upload analysis results to GitHub
47
+ uses: github/codeql-action/upload-sarif@v2
48
+ if: ${{ !env.ACT }}
49
+ with:
50
+ sarif_file: eslint-results.sarif
51
+ wait-for-processing: true
@@ -11,7 +11,6 @@ jobs:
11
11
  with:
12
12
  node-version: 16
13
13
  - run: yarn
14
- - run: yarn lint
15
14
  - run: yarn test
16
15
  env:
17
16
  TWITCH_ID: ${{ secrets.TWITCH_ID }}
package/.jsdoc.json CHANGED
@@ -30,5 +30,10 @@
30
30
  "plugins": ["plugins/markdown"],
31
31
  "markdown": {
32
32
  "hardwrap": true
33
+ },
34
+ "docdash": {
35
+ "scopeInOutputPath": false,
36
+ "nameInOutputPath": false,
37
+ "versionInOutputPath": false
33
38
  }
34
39
  }
package/LICENSE CHANGED
@@ -1,6 +1,7 @@
1
1
  MIT License
2
2
 
3
3
  Copyright (c) 2017 1Computer1
4
+ Copyright (c) 2019 André "Kody" Fernandes
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,18 +1,13 @@
1
1
  # twitch-emoticons
2
2
 
3
- Gets Twitch, BTTV and FFZ emotes as well as parsing text to emotes!
3
+ Gets Twitch, BTTV, FFZ and 7TV emotes as well as parsing text to emotes!
4
4
 
5
- ### About this fork's 2.3.0+
5
+ ### Migrating from upstream
6
6
  You must now use a Twitch user ID instead of the username to fetch user's emotes.
7
7
  You can use [this page to quickly grab it](https://s.kdy.ch/twitchid/).
8
8
 
9
- _FFZ still supports names, but usage of the ID is recommended._
10
-
11
- ### About this fork's 2.4.0+
12
- You now need to use the official Twitch API to get emotes. For this you need to provide your client id and client secret.
13
- To get a client and secret create a Twitch app [here](https://dev.twitch.tv/console/apps/create), it's free.
14
-
15
- If you are only using BetterTTV and FrankerFaceZ you don't need to provide anything as they are independent from the Twitch API.
9
+ To fetch Twitch emotes you need to get a client and secret from Twitch [here](https://dev.twitch.tv/console/apps/create), it's free.
10
+ If you are only using BetterTTV, FrankerFaceZ and 7TV you don't need to provide Twitch app keys as they are independent from the Twitch API.
16
11
 
17
12
  ### Install
18
13
  ```sh
@@ -21,11 +16,18 @@ npm install @mkody/twitch-emoticons
21
16
  yarn add @mkody/twitch-emoticons
22
17
  ```
23
18
 
24
- ### Example
19
+ ### Examples
20
+
21
+ #### Basic Twitch emote parsing
25
22
 
26
23
  ```js
24
+ // With ESM import
25
+ import TwitchEmoticons from '@mkody/twitch-emoticons';
26
+ const { EmoteFetcher, EmoteParser } = TwitchEmoticons;
27
+ // ... or require()
27
28
  const { EmoteFetcher, EmoteParser } = require('@mkody/twitch-emoticons');
28
29
 
30
+ // Your Twitch app keys
29
31
  const clientId = '<your client id>';
30
32
  const clientSecret = '<your client secret>';
31
33
 
@@ -38,13 +40,82 @@ const parser = new EmoteParser(fetcher, {
38
40
  fetcher.fetchTwitchEmotes(null).then(() => {
39
41
  const kappa = fetcher.emotes.get('Kappa').toLink();
40
42
  console.log(kappa);
41
- // https://static-cdn.jtvnw.net/emoticons/v1/25/1.0
43
+ // https://static-cdn.jtvnw.net/emoticons/v2/25/default/dark/1.0
42
44
 
43
45
  const text = 'Hello :CoolCat:!';
44
46
  const parsed = parser.parse(text);
45
47
  console.log(parsed);
46
- // Hello ![CoolCat](https://static-cdn.jtvnw.net/emoticons/v1/58127/1.0 "CoolCat")!
48
+ // Hello ![CoolCat](https://static-cdn.jtvnw.net/emoticons/v2/58127/default/dark/1.0 "CoolCat")!
49
+ });
50
+ ```
51
+
52
+ #### All providers, global + channel, custom template and match pattern
53
+
54
+ ```js
55
+ const { EmoteFetcher, EmoteParser } = require('@mkody/twitch-emoticons');
56
+
57
+ // Your channel ID
58
+ const channelId = 44317909;
59
+
60
+ // Your Twitch app keys
61
+ const clientId = '<your client id>';
62
+ const clientSecret = '<your client secret>';
63
+
64
+ const fetcher = new EmoteFetcher(clientId, clientSecret);
65
+ const parser = new EmoteParser(fetcher, {
66
+ template: '<img class="emote" alt="{name}" src="{link}">', // Custom HTML format
67
+ match: /(\w+)+?/g // Match without :colons:
47
68
  });
69
+
70
+ Promise.all([
71
+ // Twitch global
72
+ fetcher.fetchTwitchEmotes(),
73
+ // Twitch channel
74
+ fetcher.fetchTwitchEmotes(channelId),
75
+ // BTTV global
76
+ fetcher.fetchBTTVEmotes(),
77
+ // BTTV channel
78
+ fetcher.fetchBTTVEmotes(channelId),
79
+ // 7TV global
80
+ fetcher.fetchSevenTVEmotes(),
81
+ // 7TV channel
82
+ fetcher.fetchSevenTVEmotes(channelId),
83
+ // FFZ channel
84
+ fetcher.fetchFFZEmotes(channelId)
85
+ ]).then(() => {
86
+ const globalEmotes = parser.parse('EZ Clap way too easy LUL now for the last bost monkaS');
87
+ console.log(globalEmotes);
88
+ // <img class="emote" alt="EZ" src="https://cdn.7tv.app/emote/6320bf2ad461b9ebf9413812/1x.webp"> <img class="emote" alt="Clap" src="https://cdn.7tv.app/emote/636b877aada75990352334c7/1x.webp"> way too easy <img class="emote" alt="LUL" src="https://static-cdn.jtvnw.net/emoticons/v2/425618/default/dark/1.0"> now for the last bost <img class="emote" alt="monkaS" src="https://cdn.betterttv.net/emote/56e9f494fff3cc5c35e5287e/1x">
89
+
90
+ const channelEmotes = parser.parse('KEKW that was 3Head TeriPoint');
91
+ console.log(channelEmotes);
92
+ // <img class="emote" alt="KEKW" src="https://cdn.betterttv.net/emote/5e9c6c187e090362f8b0b9e8/1x"> that was <img class="emote" alt="3Head" src="https://cdn.frankerfacez.com/emote/274406/1"> <img class="emote" alt="TeriPoint" src="https://cdn.7tv.app/emote/61dc299b600369a98b38ebef/1x.webp">
93
+ }).catch(err => {
94
+ console.error('Error loading emotes...');
95
+ console.error(err);
96
+ });
97
+ ```
98
+
99
+ #### 7TV formats
100
+
101
+ 7TV v3 delivers emotes in either WEBP or AVIF.
102
+ By default we'll return WEBP emotes but you can override this.
103
+
104
+ ```js
105
+ const { EmoteFetcher } = require('@mkody/twitch-emoticons');
106
+ const fetcher = new EmoteFetcher();
107
+
108
+ // Fetch global emotes in AVIF (channel id has to be `null` for global)
109
+ fetcher.fetchSevenTVEmotes(null, 'avif');
110
+
111
+ // Fetch 0kody's emotes with the package's default format (WEBP)
112
+ fetcher.fetchSevenTVEmotes(44317909);
113
+
114
+ // ... which is currently the same as
115
+ fetcher.fetchSevenTVEmotes(44317909, 'webp');
116
+
117
+ // Fetch Anatole's emotes in AVIF
118
+ fetcher.fetchSevenTVEmotes(24377667, 'avif');
48
119
  ```
49
120
 
50
121
  ### Links
@@ -55,4 +126,5 @@ fetcher.fetchTwitchEmotes(null).then(() => {
55
126
 
56
127
  This library uses the following:
57
128
  - [BetterTTV API](https://betterttv.com/)
58
- - [FrankerFaceZ API](http://www.frankerfacez.com/developers)
129
+ - [FrankerFaceZ API](https://www.frankerfacez.com/developers)
130
+ - [7TV API](https://7tv.app/)