https://github.com/joshmerlino/minecraft-text
Parse text formatted with Minecraft formatting codes into many formats including HTML.
https://github.com/joshmerlino/minecraft-text
Last synced: 12 months ago
JSON representation
Parse text formatted with Minecraft formatting codes into many formats including HTML.
- Host: GitHub
- URL: https://github.com/joshmerlino/minecraft-text
- Owner: JoshMerlino
- Created: 2020-11-09T03:15:42.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-10-21T10:10:58.000Z (over 1 year ago)
- Last Synced: 2024-10-21T14:45:55.915Z (over 1 year ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/minecraft-text
- Size: 1.71 MB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# minecraft-text
Parse Minecraft text into many formats including HTML.
## Parse
Parse a string of encoded text to a JSON chat component.
`parse(String: text, String: delimiter = "§")`
```js
import { parse } from "minecraft-text";
const json = parse("&7[&c-&7] &3[&bWARRIOR&3]&b &fJack", "&");
```
```json
{"text":"","extra":[{"text":"[","extra":[{"text":"-","extra":[{"text":"] ","extra":[{"text":"[","extra":[{"text":"WARRIOR","extra":[{"text":"]","extra":[{"text":" ","extra":[{"text":"Jack","extra":[],"color":"white"}],"color":"aqua"}],"color":"dark_aqua"}],"color":"aqua"}],"color":"dark_aqua"}],"color":"gray"}],"color":"red"}],"color":"gray"}]}
```
## Render
Render a string of encoded text to HTML.
`render(String: text, String: delimiter = "§")`
```js
import { render } from "minecraft-text";
import "~minecraft-text/style.css"; // Browser only
const html = render("&7[&c-&7] &3[&bWARRIOR&3]&b &fJack", "&");
```
```html
[-] [WARRIOR] Jack
```
## Strip Formats
Removes all formatting codes form a string.
`stripFormats(String: text, String: delimiter = "§")`
```js
import { stripFormats } from "minecraft-text";
const text = stripFormats("&7[&c-&7] &3[&bWARRIOR&3]&b &fJack", "&");
```
```js
"[-] [WARRIOR] Jack"
```