---
description: Convert a map of badges into a list of badge images
---

# parseBadges

## Example

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

const parsedBadges = await parseBadges(
    {
        broadcaster: "1",
        subscriber: "12",
        turbo: "1",
    },
    "doceazedo911",
    { channelId: "98776633" }
);
const badgesArr = parsedBadges.toArray();
console.log(badgesArr);
```

## API

* [`parseBadges(...)`](#parsebadges)
* [`.toArray()`](#toarray)
* [`.toHTML(...)`](#tohtml)

### parseBadges(...)

```typescript
parseBadges: (
    badges: BadgeVersions | null,
    username?: string | null,
    _options?: Partial<ParserOptions> | null
): Promise<{
    toArray: () => ParsedBadges;
    toHTML: (scale?: number, inlineStyles?: boolean) => string;
}>
```

Parse badges and return multiple methods to manage the results.

| Param           | Type                              |
| --------------- | --------------------------------- |
| **`badges`**    | [`BadgeVersions`](#badgeversions) |
| **`username?`** | `string`                          |
| **`_options?`** | [`ParserOptions`](#parseroptions) |

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

### .toArray()

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

Converts parsed badges into an array of badges info.

**Returns:** [`ParsedBadges`](#parsedbadges)

### .toHTML(...)

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

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

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

**Returns:** `string`

## Types

### BadgeVersions

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

Object map of:

| Prop      | Type     | Description      |
| --------- | -------- | ---------------- |
| **key**   | `string` | Badge ID         |
| **value** | `string` | Badge version ID |

### ParsedBadges

Array of:

| Prop            | Type       | Description                                                      |
| --------------- | ---------- | ---------------------------------------------------------------- |
| **`id`**        | `string`   | Badge ID                                                         |
| **`title`**     | `string`   | Title/description                                                |
| **`slot?`**     | `number`   | Position badge should be rendered                                |
| **`replaces?`** | `string`   | Suggests that badge should replace another, only used internally |
| **`color?`**    | `string`   | Badge background color                                           |
| **`images`**    | `string[]` | Image URLs of the badge in different scales (asc)                |

### ParserOptions

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

### Providers

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

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