# prismarine-chat

> Wrapper for a minecraft chat message

Latest version **1.13.0** (published 2026-03-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install prismarine-chat
pnpm add prismarine-chat
yarn add prismarine-chat
bun add prismarine-chat
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.13.0 |
| Published | 2026-03-30 |
| First published | 2020-07-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 70.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 38 |
| Author | Romain Beaumont |
| Maintainers | rom1504 |
| Keywords | prismarine, chat |

## Links

- npm: https://www.npmjs.com/package/prismarine-chat
- Repository: https://github.com/PrismarineJS/prismarine-chat
- Homepage: https://github.com/PrismarineJS/prismarine-chat#readme
- Issues: https://github.com/PrismarineJS/prismarine-chat/issues
- npm.io page: https://npm.io/package/prismarine-chat

## Dependencies (4)

- [debug](https://npm.io/package/debug.md) ^4.3.2
- [mojangson](https://npm.io/package/mojangson.md) ^2.0.1
- [prismarine-nbt](https://npm.io/package/prismarine-nbt.md) ^2.0.0
- [prismarine-registry](https://npm.io/package/prismarine-registry.md) ^1.4.0

## Alternatives

- [@oh-my-pi/pi-natives](https://npm.io/package/@oh-my-pi/pi-natives.md) — 51.8K weekly downloads
- [@capgo/capacitor-light-sensor](https://npm.io/package/@capgo/capacitor-light-sensor.md) — 3.0K weekly downloads
- [@heyhuynhgiabuu/pi-diff](https://npm.io/package/@heyhuynhgiabuu/pi-diff.md) — 492 weekly downloads
- [@lotsa/verdant-lang-asm](https://npm.io/package/@lotsa/verdant-lang-asm.md) — 38 weekly downloads
- [new-era-syntax](https://npm.io/package/new-era-syntax.md) — 20 weekly downloads

## Recent versions

- 1.13.0 (latest) — 2026-03-30
- 1.12.0 — 2025-09-14
- 1.11.0 — 2025-01-26
- 1.10.1 — 2024-05-04
- 1.10.0 — 2024-02-24
- 1.9.1 — 2023-08-17
- 1.9.0 — 2023-08-13
- 1.8.0 — 2023-01-19
- 1.7.2 — 2022-10-02
- 1.7.1 — 2022-10-01
- 1.7.0 — 2022-10-01
- 1.6.1 — 2022-04-11
- 1.6.0 — 2022-02-13
- 1.5.0 — 2021-12-29
- 1.4.1 — 2021-12-21
- … 12 more at https://npm.io/package/prismarine-chat/versions

## README

# prismarine-chat
[![NPM version](https://img.shields.io/npm/v/prismarine-chat.svg)](http://npmjs.com/package/prismarine-chat)
[![Build Status](https://github.com/PrismarineJS/prismarine-chat/workflows/CI/badge.svg)](https://github.com/PrismarineJS/prismarine-chat/actions?query=workflow%3A%22CI%22)
[![Discord](https://img.shields.io/badge/chat-on%20discord-brightgreen.svg)](https://discord.gg/GsEFRM8)
[![Gitter](https://img.shields.io/badge/chat-on%20gitter-brightgreen.svg)](https://gitter.im/PrismarineJS/general)
[![Irc](https://img.shields.io/badge/chat-on%20irc-brightgreen.svg)](https://irc.gitter.im/)
[![Try it on gitpod](https://img.shields.io/badge/try-on%20gitpod-brightgreen.svg)](https://gitpod.io/#https://github.com/PrismarineJS/prismarine-chat)

A parser for a minecraft chat message


## Usage

```js
const registry = require('prismarine-registry')('1.16')
const ChatMessage = require('prismarine-chat')(registry)

const msg = new ChatMessage({"text":"Example chat mesasge"})
console.log(msg.toString()) // Example chat message

```
## API

### ChatMessage(message,[displayWarning])
* `message` - Can be either text or a minecraft chat JSON object
* `displayWarning` - Display warnings if true, default to false

#### chat.toString([lang])

Flattens the message in to plain-text
 * `lang` - (optional) - Set a custom lang (defaults to registry.language)

#### chat.toMotd([lang], parent)

Converts to motd format
 * `lang` - (optional) - Set a custom lang (defaults to registry.language)
 * `parent` - Set a custom lang (defaults to mcData.language)

#### chat.getText(idx, [lang])

Returns a text part from the message
 * `idx` - Index of the part
 * `lang` - (optional) - Set a custom lang (defaults to registry.language)

#### chat.toAnsi([lang], [codes])

Converts to ansi format
 * `lang` - (optional) - Set a custom lang (defaults to registry.language)
 * `codes` - (optional) - Specify which ANSI formatting codes should be used for each Minecraft color code

#### chat.toHTML([lang], [codes], [allowedFormats])
Converts to escaped HTML
* `lang` - (optional) - Set a custom lang (defaults to registry.language)
* `codes` - (optional) - Specify which CSS style props should be used for each Minecraft color code
* `allowedFormats` - The set of allowed formats. Default is ['color', 'bold', 'strikethrough', 'underlined', 'italic']

#### chat.length()

Returns the count of text extras and child ChatMessages
Does not count recursively in to the children

#### chat.append(ChatMessage)

Appends another ChatMessage or a string

#### chat.clone()

Returns a clone of the ChatMessage

```js
const registry = require('prismarine-registry')('1.16')
const { MessageBuilder } = require('prismarine-chat')(registry)

const msg = new MessageBuilder().setText('Example chat mesasge')
console.log(JSON.stringify(msg)) // The string as a message component

```

#### static ChatMessage.fromNotch(msg)

Returns a prismarine-chat representation of the message recieved from the 'chat' packet, example shown [here](examples/minecraftprotocol_fromnotch/fromnotch.js)

#### static ChatMessage.fromNetwork(messageType, messageParameters)

(1.19+) Loads a chat message sent by server that needs to be formatted on client side.

### MessageBuilder()

#### setBold (val: boolean) : this
#### setItalic (val: boolean) : this
#### setUnderlined (val: boolean) : this
#### setStrikethrough (val: boolean) : this
#### setObfuscated (val: boolean) : this
#### setColor (val: string) : this
#### setText (val: string) : this

> check code for examples (and explanations) from here on

#### setFont (val: string) : this
#### setTranslate (val: string) : this
#### setInsertion (val: string) : this
#### setKeybind (val: string) : this
#### setScore (name: string, objective: string) : this
#### setClickEvent (action: string, value: object) : this
#### setHoverEvent (action: string, data: object, type?: 'contents'|'value') : this
#### addExtra (...val: MessageBuilder | string) : this
#### addWith (...val: MessageBuilder | string) : this
#### resetFormatting () : void
sets every one of the formatting options to false and sets text to `reset` type

#### toJSON () : object
`builder.toJSON()` is the same thing as `JSON.stringify(builder)`

#### toString () : string
runs `JSON.stringify()` on `this`

#### static MessageBuilder.fromString(str, {colorSeparator = '&'}) : MessageBuilder
convert string with color codes like `&4Hello&cWorld` to a `MessageBuilder` object

### processNbtMessage

This method is internally called by fromNotch.

mcpc 1.20.3 uses NBT instead of JSON in some places to store chat, so the schema is a bit different.
`processNbtMessage` normalizes the JS object obtained from nbt derealization to the old JSON schema,
so it can be used to instantiate a ChatMessage.

---
_Source: https://npm.io/package/prismarine-chat · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
