# @xmcl/text-component

> Parse Minecraft text component and render it to css.

Latest version **2.1.3** (published 2023-10-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @xmcl/text-component
pnpm add @xmcl/text-component
yarn add @xmcl/text-component
bun add @xmcl/text-component
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.3 |
| Published | 2023-10-22 |
| First published | 2019-07-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16 |
| Dependencies | 0 |
| Unpacked size | 69.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | cijhn@hotmail.com |
| Maintainers | ci010 |
| Keywords | minecraft, typescript, minecraft-launcher, nodejs, text-component, electron |

## Links

- npm: https://www.npmjs.com/package/@xmcl/text-component
- Repository: https://github.com/Voxelum/minecraft-launcher-core-node
- Homepage: https://github.com/Voxelum/minecraft-launcher-core-node#readme
- Issues: https://github.com/Voxelum/minecraft-launcher-core-node/issues
- npm.io page: https://npm.io/package/@xmcl/text-component

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 2.1.3 (latest) — 2023-10-22
- 2.1.2 — 2023-04-24
- 2.1.1 — 2020-03-14
- 2.1.0 — 2020-02-25
- 2.0.1-alpha.1 — 2020-02-10
- 2.0.1-alpha.0 — 2020-01-23
- 2.0.0-alpha.0 — 2020-01-22
- 1.0.3 — 2019-11-26
- 1.0.2 — 2019-11-25
- 1.0.1 — 2019-11-24
- 1.0.0 — 2019-11-16
- 0.0.5 — 2019-11-05
- 0.0.4 — 2019-10-27
- 0.0.3 — 2019-09-21
- 0.0.2 — 2019-09-15
- … 1 more at https://npm.io/package/@xmcl/text-component/versions

## README

# Text-component Module

[![npm version](https://img.shields.io/npm/v/@xmcl/text-component.svg)](https://www.npmjs.com/package/@xmcl/text-component)
[![Downloads](https://img.shields.io/npm/dm/@xmcl/text-component.svg)](https://npmjs.com/@xmcl/text-component)
[![Install size](https://packagephobia.now.sh/badge?p=@xmcl/text-component)](https://packagephobia.now.sh/result?p=@xmcl/text-component)
[![npm](https://img.shields.io/npm/l/@xmcl/minecraft-launcher-core.svg)](https://github.com/voxelum/minecraft-launcher-core-node/blob/master/LICENSE)
[![Build Status](https://github.com/voxelum/minecraft-launcher-core-node/workflows/Build/badge.svg)](https://github.com/Voxelum/minecraft-launcher-core-node/actions?query=workflow%3ABuild)

Provide functions to parse Minecraft text component.

## Usage

### TextComponent

Create TextComponent from string OR Minecraft's formatted string, like `'§cThis is red'`:

```ts
import { TextComponent, fromFormattedString } from "@xmcl/text-component";
const formattedString: string;
const fromFormatted: TextComponent = fromFormattedString(formattedString);
```

Render the TextComponent to css:

```ts
import { TextComponent, render, RenderNode } from "@xmcl/text-component";
const yourComponent: TextComponent;
const node: RenderNode = render(yourComponent);

node.text; // the text of the node
node.style; // style of the node
node.children; // children

// you can render in dom like this:

function renderToDom(node: RenderNode) {
    const span = document.createElement('span');
    span.style = node.style;
    span.textContent = node.text;
    for (const child of node.children) {
        span.appendChild(renderToDom(child));
    }
} 
```

Iterate the TextComponent and its children:

```ts
import { TextComponent, flat } from "@xmcl/text-component";
const yourComponent: TextComponent;
const selfAndAllChildren: Array<TextComponent> = flat(yourComponent);
```

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