forked from MathMan05/JankClient
-
Notifications
You must be signed in to change notification settings - Fork 1
/
buildEmojis.js
109 lines (97 loc) · 2.42 KB
/
buildEmojis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const emojilist = require("./EmojiList/data-by-group.json")
console.log(emojilist)
const buffer = new ArrayBuffer(2 ** 26)
const view = new DataView(buffer, 0)
let i = 0
const write16 = numb => {
view.setUint16(i, numb)
i += 2
}
const write8 = numb => {
view.setUint8(i, numb)
i += 1
}
const textEncoder = new TextEncoder("utf8")
const writeString8 = str => {
const encode = textEncoder.encode(str)
write8(encode.length)
for (const thing of encode) write8(thing)
}
const writeString16 = str => {
const encode = textEncoder.encode(str)
write16(encode.length)
for (const thing of encode) write8(thing)
}
const writeStringNo = str => {
const encode = textEncoder.encode(str)
for (const thing of encode) write8(thing)
}
write16(emojilist.length)
for (const thing of emojilist) {
writeString16(thing.name)
write16(thing.emojis.length)
for (const emoji of thing.emojis) {
writeString8(emoji.name)
writeString8(emoji.slug)
write8(textEncoder.encode(emoji.emoji).length + 128 * emoji.skin_tone_support)
writeStringNo(emoji.emoji)
}
}
const out = new ArrayBuffer(i)
const ar = new Uint8Array(out)
const br = new Uint8Array(buffer)
for (const thing in ar) {
ar[thing] = br[thing]
}
console.log(ar)
const decodeEmojiList = bufferDecode => {
const viewDecode = new DataView(bufferDecode, 0)
let j = 0
const read16 = () => {
const int = viewDecode.getUint16(j)
j += 2
return int
}
const read8 = () => {
const int = viewDecode.getUint8(j)
j += 1
return int
}
const readStringNo = length => {
const array = new Uint8Array(length)
for (let k = 0; k < length; k++) {
array[k] = read8()
}
return new TextDecoder("utf8").decode(array.buffer)
}
const readString8 = () => readStringNo(read8())
const readString16 = () => readStringNo(read16())
const build = []
let cats = read16()
for (; cats > 0; cats--) {
const name = readString16()
const emojis = []
let emojinumber = read16()
for (; emojinumber > 0; emojinumber--) {
const name8 = readString8()
const slug8 = readString8()
const len = read8()
const skinToneSupport = len > 127
const emoji = readStringNo(len - skinToneSupport * 128)
emojis.push({
name: name8,
slug: slug8,
skin_tone_support: skinToneSupport,
emoji
})
}
build.push({
name,
emojis
})
}
return build
}
console.log(JSON.stringify(decodeEmojiList(out)))
const fs = require("node:fs")
fs.writeFile("./webpage/emoji.bin", new Uint8Array(out), () => {})