-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.js
More file actions
109 lines (92 loc) · 2.5 KB
/
example.js
File metadata and controls
109 lines (92 loc) · 2.5 KB
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 { parseJSON, parseString, parseExtra } = require('./index')(735/*735 is the 1.16 protocol number*/)// for your usage change "./index" to "minecraft-protocol-chat-parser"
console.log(parseString("§eHello §kWorld"))
// output
// {
// text: 'Hello ',
// color: 'yellow',
// bold: false,
// italic: false,
// underlined: false,
// strikethrough: false,
// obfuscated: false
// extra: [
// {
// text: 'World',
// color: 'yellow',
// bold: false,
// italic: false,
// underlined: false,
// strikethrough: false,
// obfuscated: true
// }
// ]
// }
let parsed = parseJSON({
text: "Hello ",
extra: [
{
text: "Grooble ",
color: "black",
bold: false,
italic: false,
underlined: false,
strikethrough: false,
obfuscated: false
},
{
text: "How are u ",
color: "dark_purple",
bold: false,
italic: true,
underlined: true,
strikethrough: false,
obfuscated: false
},
{
text: "?",
color: "yellow",
bold: true,
italic: false,
underlined: false,
strikethrough: false,
obfuscated: false
}
]
})
console.log(parsed); //Hello §0Grooble §5§o§nHow are u §e§l?
let parsedExtra = parseExtra({
text: "I'm an extra",
color: "green",
bold: false,
italic: false,
underlined: true,
strikethrough: false,
obfuscated: false
})
console.log(parsedExtra); //§a§nI'm an extra
parsedExtra = parseExtra(`{
"text": "I'm a JSON like String",
"color": "white",
"bold": false,
"italic": false,
"underlined": false,
"strikethrough": false,
"obfuscated": false
}`, true)// when set to true replace "§" by "&" in the result
console.log(parsedExtra); //&fI'm a JSON like String
parsedExtra = parseExtra({
text: "Team...Team...Team... I like this word !",
color: "blue",
bold: false,
italic: true,
underlined: false,
strikethrough: false,
obfuscated: false
}, true)
console.log(parsedExtra); //&9&oTeam...Team...Team... I like this word !
let noExtraMsg = parseJSON({
text: "With 0 extra & only some properties",
color: "dark_red",
underlined: true
})
console.log(noExtraMsg); //§4§nWith 0 extra & only some properties