emotesjs 0.0.9 → 0.0.10
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.
- package/index.js +14 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -7,20 +7,22 @@ class EmotesJS {
|
|
|
7
7
|
height = "1.65rem"
|
|
8
8
|
format = "WEBP"
|
|
9
9
|
allowedOrigins = "https://cdn.7tv.app"
|
|
10
|
-
instance
|
|
10
|
+
static instance
|
|
11
11
|
|
|
12
12
|
constructor(opts) {
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
13
|
+
if (EmotesJS.instance) {
|
|
14
|
+
return EmotesJS.instance
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
if (opts) {
|
|
18
|
+
this.channelId = opts.channelId || this.channelId
|
|
19
|
+
this.requireColon = opts.requireColon || this.requireColon
|
|
20
|
+
this.height = opts.height || this.height
|
|
21
|
+
this.format = opts.format || this.format
|
|
22
|
+
}
|
|
21
23
|
|
|
22
24
|
this.isLoading = this.load()
|
|
23
|
-
|
|
25
|
+
EmotesJS.instance = this
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
async load() {
|
|
@@ -70,8 +72,8 @@ class EmotesJS {
|
|
|
70
72
|
this.isReady = true
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
parse(text) {
|
|
74
|
-
if (!text || !
|
|
75
|
+
static parse(text) {
|
|
76
|
+
if (!text || !EmotesJS.isReady) {
|
|
75
77
|
return text
|
|
76
78
|
}
|
|
77
79
|
let words = text.split(' ')
|
|
@@ -80,12 +82,12 @@ class EmotesJS {
|
|
|
80
82
|
for (let i = 0; i < words.length; i++) {
|
|
81
83
|
let word = words[i]
|
|
82
84
|
|
|
83
|
-
if (
|
|
85
|
+
if (EmotesJS.requireColon && !word.startsWith(":")) {
|
|
84
86
|
continue
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
let wordKey = word.replace(':', '')
|
|
88
|
-
let emote =
|
|
90
|
+
let emote = EmotesJS.cachedEmotes.get(wordKey)
|
|
89
91
|
|
|
90
92
|
if (emote) {
|
|
91
93
|
fullText += emote + ' '
|