# color2k: Parse

## parseToRgba(color)

```ts
function parseToRgba(color: string): [number, number, number, number]
```

Parses a color into red, green, blue, and alpha channel values.

Reads hex (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`), comma-separated
`rgb()`, `rgba()`, `hsl()` and `hsla()`, CSS named colors, and
`transparent`.

This is a lenient parser, not a validator. Most strings in none of these
forms throw a `ColorError`, but not all: color names are matched by hash,
so about 3% of made-up, letters-only names are read as some color instead.
The numbers in `rgb()` and the alpha value are returned as written, without
clamping: `rgb(999, 0, 0)` gives `[999, 0, 0, 1]`.

```js
parseToRgba('rgba(255, 0, 0, 0.5)'); // [255, 0, 0, 0.5]
```

### Parameters

| Name | Type | Description |
| --- | --- | --- |
| `color` | `string` | The input color. |

### Returns

`[number, number, number, number]` - A tuple in the order `[red, green, blue, alpha]`.

[Source](https://github.com/ricokahler/color2k/blob/main/src/parseToRgba.ts)

## parseToHsla(color)

```ts
function parseToHsla(color: string): [number, number, number, number]
```

Parses a color into hue, saturation, lightness, and alpha channel values.

Hue is a number between 0 and 360. Saturation, lightness, and alpha are
decimal percentages between 0 and 1.

```js
parseToHsla('red'); // [0, 1, 0.5, 1]
```

### Parameters

| Name | Type | Description |
| --- | --- | --- |
| `color` | `string` | The input color. |

### Returns

`[number, number, number, number]` - A tuple in the order `[hue, saturation, lightness, alpha]`.

[Source](https://github.com/ricokahler/color2k/blob/main/src/parseToHsla.ts)
