# FormattingHelper

`com.jsmacrosce.jsmacros.client.api.helper.FormattingHelper`

**Since:** 1.8.4

Wraps one of Minecraft's text color or formatting codes.  

`RESET` is neither a color nor a modifier, so [isColor()](#com.jsmacrosce.jsmacros.client.api.helper.FormattingHelper_isColor-) and
[isModifier()](#com.jsmacrosce.jsmacros.client.api.helper.FormattingHelper_isModifier-) are both false for it.  

The color index and RGB value are `-1` for modifiers and `RESET`.  

A [StyleHelper](StyleHelper.md) returns this only for legacy formatting values; arbitrary RGB colors do
not have a formatting code.  
```js
const line = Chat.createTextBuilder().append("a colored run").withColor(0xc).build();  
line.visit(JavaWrapper.methodToJava(function (style, run) {
  if (style.hasColor()) {
    const formatting = style.getFormatting();  
    if (formatting !== null) {
      Chat.log(`${run}: ${formatting.getName()}, index ${formatting.getColorIndex()}, rgb ${formatting.getColorValue()}`);  
    }
  }
}));  
```

## Constructors

### new FormattingHelper {#com.jsmacrosce.jsmacros.client.api.helper.FormattingHelper_constructor-ChatFormatting-}

```js
new FormattingHelper(ChatFormatting base)
```

Wraps the supplied formatting value without copying or parsing it.

**Parameters:**
- `base`: raw text color or formatting code to wrap

## Methods

### getCode {#com.jsmacrosce.jsmacros.client.api.helper.FormattingHelper_getCode-}

```js
getCode(): char
```

Returns the legacy formatting code character. Prefix it with the section symbol (`§`)
to form a legacy formatting sequence; color codes are `0`–`9` and `a`–
`f`, modifiers are `k`–`o`, and `RESET` is `r`.

**Returns:** the formatting code character.

**Since:** 1.8.4

### getColorIndex {#com.jsmacrosce.jsmacros.client.api.helper.FormattingHelper_getColorIndex-}

```js
getColorIndex(): int
```

**Returns:** the legacy color index (`0`–`15`), or `-1` for a modifier or
        `RESET`.

**Since:** 1.8.4

### getColorValue {#com.jsmacrosce.jsmacros.client.api.helper.FormattingHelper_getColorValue-}

```js
getColorValue(): int
```

Returns the RGB value for one of the sixteen colors; modifiers and `RESET` return
`-1`.

**Returns:** the color value, or `-1` for non-color formats.

**Since:** 1.8.4

### getName {#com.jsmacrosce.jsmacros.client.api.helper.FormattingHelper_getName-}

```js
getName(): String
```

**Returns:** the lowercase name of this formatting.

**Since:** 1.8.4

### isColor {#com.jsmacrosce.jsmacros.client.api.helper.FormattingHelper_isColor-}

```js
isColor(): boolean
```

**Returns:** `true` for one of the sixteen colors; `false` for modifiers and
        `RESET`.

**Since:** 1.8.4

### isModifier {#com.jsmacrosce.jsmacros.client.api.helper.FormattingHelper_isModifier-}

```js
isModifier(): boolean
```

**Returns:** `true` for one of the five modifiers; `false` for colors and
        `RESET`.

**Since:** 1.8.4

### toString {#com.jsmacrosce.jsmacros.client.api.helper.FormattingHelper_toString-}

```js
toString(): String
```

Returns a diagnostic string containing this formatting's index, color value, name, code,  
and color and modifier flags.

**Returns:** diagnostic representation of the wrapped formatting
