-
Notifications
You must be signed in to change notification settings - Fork 17
/
emoji-packer.cjs
113 lines (106 loc) · 2.33 KB
/
emoji-packer.cjs
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
110
111
112
113
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;
function write16(numb){
view.setUint16(i,numb);
i+=2;
}
function write8(numb){
view.setUint8(i,numb);
i+=1;
}
function writeString8(str){
const encode=new TextEncoder("utf-8").encode(str);
write8(encode.length);
for(const thing of encode){
write8(thing);
}
}
function writeString16(str){
const encode=new TextEncoder("utf-8").encode(str);
write16(encode.length);
for(const thing of encode){
write8(thing);
}
}
function writeStringNo(str){
const encode=new TextEncoder("utf-8").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);
write8(new TextEncoder("utf-8").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(i,ar);
function decodeEmojiList(buffer){
const view = new DataView(buffer, 0);
let i=0;
function read16(){
const int=view.getUint16(i);
i+=2;
return int;
}
function read8(){
const int=view.getUint8(i);
i+=1;
return int;
}
function readString8(){
return readStringNo(read8());
}
function readString16(){
return readStringNo(read16());
}
function readStringNo(length){
const array=new Uint8Array(length);
for(let i=0;i<length;i++){
array[i]=read8();
}
//console.log(array);
return new TextDecoder("utf-8").decode(array.buffer);
}
const build=[];
let cats=read16();
for(;cats!==0;cats--){
const name=readString16();
const emojis=[];
let emojinumber=read16();
for(;emojinumber!==0;emojinumber--){
//console.log(emojis);
const name=readString8();
const len=read8();
const skin_tone_support=len>127;
const emoji=readStringNo(len-skin_tone_support*128);
emojis.push({
name,
skin_tone_support,
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),_=>{
});