Skip to content

Commit 5dfc5db

Browse files
committed
docs: 📝 add readme
1 parent a181753 commit 5dfc5db

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

README.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
1-
# MinecraftJS Template
1+
# Chat
22

3-
Fill with your own content
3+
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/MinecraftJS/Chat/Build?style=for-the-badge)
4+
![GitHub](https://img.shields.io/github/license/MinecraftJS/Chat?style=for-the-badge)
5+
![npm (scoped)](https://img.shields.io/npm/v/@minecraft-js/Chat?style=for-the-badge)
6+
7+
Parse and serialize Minecraft chat messages. Provides builders to make it easy to do.
8+
9+
# Documentation
10+
11+
## Installation
12+
13+
Install the package:
14+
15+
```bash
16+
$ npm install @minecraft-js/chat
17+
```
18+
19+
And then import it in your JavaScript/TypeScript file
20+
21+
```ts
22+
const chat = require('@minecraft-js/chat').default; // CommonJS
23+
24+
import * as chat from '@minecraft-js/chat'; // ES6
25+
```
26+
27+
## Build a message
28+
29+
```js
30+
const component = new chat.StringComponentBuilder();
31+
component
32+
.setText('Hello World') // Set the text to 'Hello World'
33+
.setColor(chat.MinecraftColor.RED) // Set the color to red
34+
.setBold(true); // Set the bold flag to true
35+
// And so on, all fields are handled by the builder
36+
```
37+
38+
## Parse a message
39+
40+
```js
41+
const message = '{"translate":"chat.type.text","with":[{"text":"Herobrine","clickEvent":{"action":"suggest_command","value":"/msg Herobrine "},"hoverEvent":{"action":"show_entity","value":"{id:f84c6a79-0a4e-45e0-879b-cd49ebd4c4e2,name:Herobrine}"},"insertion":"Herobrine"},{"text":"I don\'t exist"}]}'
42+
const parsed = chat.ComponentBuilder.parse(message);
43+
44+
console.log(parsed.component.translate); // chat.type.text
45+
parsed.setTranslate('chat.whatever');
46+
console.log(parsed.component.translate); // chat.whatever
47+
```
48+
49+
50+
Everything is typed and documented as well. (Most of the documentation is a copy paste from [Wiki.vg](https://wiki.vg/Chat)

0 commit comments

Comments
 (0)