# parseEmotes

## Example

```typescript
import { parseEmotes } from "emotettv";

const parsedMessage = await parseEmotes(
    "hello world! VoHiYo",
    { "81274": [13-18] },
    { channelId: "98776633" }
);
const messageArr = parsedMessage.toArray();
console.log(messageArr); 
```

## API

* [`parseEmotes(...)`](#parseemotes)
* [`.toArray()`](#toarray)
* [`.toHTML(...)`](#tohtml)

### parseEmotes(...)

```typescript
parseEmotes: (
    message: string,
    _emotePositions?: EmotePositions | null,
    _options?: Partial<ParserOptions> | null
) => Promise<{
    toArray: () => ParsedEmotesMessage;
    toHTML: (scale?: number, inlineStyles?: boolean, escapeHTML?: boolean) => string;
}>
```

Parse emotes in a message and return multiple methods to manage the results.

| Param                  | Type                                |
| ---------------------- | ----------------------------------- |
| **`message`**          | `string`                            |
| **`_emotePositions?`** | [`EmotePositions`](#emotepositions) |
| **`_options?`**        | [`ParserOptions`](#parseroptions)   |

**Returns:** `Promise<{`[`toArray()`](#toarray)`,` [`toHTML(...)`](#tohtml)`}>`

### .toArray()

```typescript
toArray: () => ParsedEmotesMessage;
```

Converts parsed message into an array of words and emotes.

**Returns:** [`ParsedEmotesMessage`](#parsedemotesmessage)

### .toHTML(...)

```typescript
toHTML: (scale?: number, inlineStyles?: boolean, escapeHTML?: boolean) => string;
```

Converts parsed message into a ready-to-use HTML string.

| Param               | Type      |
| ------------------- | --------- |
| **`scale?`**        | `number`  |
| **`inlineStyles?`** | `boolean` |
| **`escapeHTML?`**   | `boolean` |

**Returns:** `string`

## Types

### EmotePositions

{% hint style="info" %}
This is the same type used by TMI.js when returning emote offsets, so you can use it directly when needed.
{% endhint %}

Object map of:

| Prop      | Type     | Description                                                          |
| --------- | -------- | -------------------------------------------------------------------- |
| **key**   | `string` | ID of emote                                                          |
| **value** | `string` | Starting and ending position of emote on text formatted as `{x}-{y}` |

### ParsedEmotesMessage

Array of:

| Prop           | Type                          | Description                                                                   |
| -------------- | ----------------------------- | ----------------------------------------------------------------------------- |
| **`content`**  | `string`                      | Word                                                                          |
| **`position`** | `string`                      | Starting and ending position of word on text formatted as `{x}-{y}`           |
| **`emote?`**   | [`ParsedEmote`](#parsedemote) | Parsed emote details, this suggests this word should be rendered as an emote. |

### ParsedEmote

| Prop               | Type                              | Description                                                        |
| ------------------ | --------------------------------- | ------------------------------------------------------------------ |
| **`images`**       | `string[]`                        | Image URLs of the emote in different scales (asc)                  |
| **`overlays`**     | [`ParsedOverlay`](#parsedoverlay) | List of emotes that should be rendered on top of the current emote |
| **`isZeroWidth?`** | `boolean`                         | If the emote is an overlay, only used internally                   |

### ParsedOverlay

| Prop         | Type       |                                                   |
| ------------ | ---------- | ------------------------------------------------- |
| **`images`** | `string[]` | Image URLs of the emote in different scales (asc) |
| **`alt`**    | `string`   | Original emote code                               |

### ParserOptions

| Prop            | Type                      | Description                                                 |
| --------------- | ------------------------- | ----------------------------------------------------------- |
| **`channelId`** | `string \| null`          | ID of channel emotes will be fetched from                   |
| **`providers`** | [`Providers`](#providers) | List of enabled emote providers. All are active by default. |

### Providers

{% hint style="info" %}
You can also add any providers you create. See [custom emotes/badges](/emotettv/guides/custom-emotes-badges.md) guide for more information.
{% endhint %}

| Prop          | Type      | Description          |
| ------------- | --------- | -------------------- |
| **`twitch`**  | `boolean` | Enable Twitch emotes |
| **`bttv`**    | `boolean` | Enable BTTV emotes   |
| **`ffz`**     | `boolean` | Enable FFZ emotes    |
| **`seventv`** | `boolean` | Enable 7TV emotes    |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://emotettv.gitbook.io/emotettv/api-reference/parseemotes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
