# hex-to-rgba

> Converts hexadecimal color codes to rgb()/rgba() values.

Latest version **2.0.1** (published 2019-07-15) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install hex-to-rgba
pnpm add hex-to-rgba
yarn add hex-to-rgba
bun add hex-to-rgba
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2019-07-15 |
| First published | 2017-02-01 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 40.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 61 |
| Author | Just Thomas Hiorth Misund |
| Maintainers | misund |
| Keywords | colors, hex, rgba, css |

## Links

- npm: https://www.npmjs.com/package/hex-to-rgba
- Repository: https://github.com/misund/hex-to-rgba
- Homepage: https://github.com/misund/hex-to-rgba#readme
- Issues: https://github.com/misund/hex-to-rgba/issues
- npm.io page: https://npm.io/package/hex-to-rgba

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 2.0.1 (latest) — 2019-07-15
- 2.0.0 — 2019-06-04
- 1.0.2 — 2018-09-20
- 1.0.1 — 2017-12-19
- 1.0.0 — 2017-11-01
- 0.2.0 — 2017-02-11
- 0.1.4 — 2017-02-05
- 0.1.3 — 2017-02-02
- 0.1.2 — 2017-02-02
- 0.1.1 — 2017-02-02
- 0.1.0 — 2017-02-02
- 0.0.2 — 2017-02-02
- 0.0.1 — 2017-02-01

## README

[![Build Status](https://travis-ci.org/misund/hex-to-rgba.svg?branch=master)](https://travis-ci.org/misund/hex-to-rgba)
[![Greenkeeper badge](https://badges.greenkeeper.io/misund/hex-to-rgba.svg)](https://greenkeeper.io/)


`hex-to-rgba` turns an old-fashioned css hex color value string into an rgba() string.

Optionally pass in an alpha value. The passed alpha value will override any alpha value from 4- or 8-digit hexes. If you don't pass in an alpha value at all, we will default to an alpha value of 1 (completely opaque).

Supports 3-, 4-, 6- and 8-digit hex values with or without a leading hash.

## Installation
```sh
$ npm install --save hex-to-rgba
```
or
```sh
$ yarn add hex-to-rgba
```

## Usage
```js
import hexToRgba from 'hex-to-rgba';

// Or if you're so inclined:
// var hexToRgba = require("hex-to-rgba");

hexToRgba('112233'); // "rgba(17, 34, 51, 1)"
hexToRgba('#112233'); // "rgba(17, 34, 51, 1)"
hexToRgba('112233', '0.5'); // "rgba(17, 34, 51, 0.5)"
hexToRgba('#112233', 0.75); // "rgba(17, 34, 51, 0.75)"

hexToRgba('11223344') // "rgba(17, 34, 51, 0.27)"
hexToRgba('#11223344') // "rgba(17, 34, 51, 0.27)"
hexToRgba('11223344', '0.5') // "rgba(17, 34, 51, 0.5)"
hexToRgba('#11223344', 0.75) // "rgba(17, 34, 51, 0.75)"

hexToRgba('123'); // "rgba(17, 34, 51, 1)"
hexToRgba('#123'); // "rgba(17, 34, 51, 1)"
hexToRgba('123', 0.2) // "rgba(17, 34, 51, 0.2)"
hexToRgba('#123', 0.2) // "rgba(17, 34, 51, 0.2)"

hexToRgba('1234'); // "rgba(17, 34, 51, 0.27)"
hexToRgba('#1234'); // "rgba(17, 34, 51, 0.27)"
hexToRgba('1234', 0.5) // "rgba(17, 34, 51, 0.5)"
hexToRgba('#1234', 0.75) // "rgba(17, 34, 51, 0.75)"
```

## Signature
`hexToRgba(hex, a=1)`

Returns an rgba() string. (examples: `'rgba(11, 22, 33, 1)'`, `'rgba(11, 22, 33, 0.5)'`)

## Parameters
* `hex`: The hex color value to convert to rgba. (examples: `'123456'`, `'#123456'`, `'123'`, `'#123'`)
* `a`: An alpha value to apply. (optional, default: 1) (examples: `'0.5'`, `0.25`)


## Contributing
I appreciate your issues and PRs [on Github](https://github.com/misund/hex-to-rgba)!

### Testing
```
yarn build && yarn test
```

### Releasing
This project uses [np](https://github.com/sindresorhus/np).
1. Make sure your changes are in master
2. Run `yarn release`
3. Follow the interactive release guide

## Changelog
See the [releases page on GitHub](https://github.com/misund/hex-to-rgba/releases).

---
_Source: https://npm.io/package/hex-to-rgba · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
