Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update devDependencies * Add eslint * Lint * Support 4-digit hexes and refactor * BREAKING CHANGE: Always return rgba() values Before this change, hex-to-rgba would sometimes return rgb() values if the the color was completely opaque. After this change, hex-to-rgba will always return an rgba() value - if the color is opaque, the a value will simply be set to 1. * Update documentation * Update changelog * Remove lockfile * Add node 8 and 9 to test environments * Stop breaking node 5 support * 1.0.0
- Loading branch information
Showing
7 changed files
with
163 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "airbnb" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,6 @@ jspm_packages | |
|
||
# Build | ||
build/ | ||
|
||
# Lockfile | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
language: node_js | ||
node_js: | ||
- "9" | ||
- "8" | ||
- "7" | ||
- "7.4" | ||
- "7.3" | ||
- "6" | ||
- "6.1" | ||
- "5.11" | ||
- "5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,64 @@ | ||
[![Build Status](https://travis-ci.org/misund/hex-to-rgba.svg?branch=master)](https://travis-ci.org/misund/hex-to-rgba) | ||
|
||
`hex-to-rgba` turns an old-fashioned css hex color value string into an rgb() string. | ||
`hex-to-rgba` turns an old-fashioned css hex color value string into an rgba() string. | ||
|
||
If you specify an alpha value, you'll get a rgba() string instead. | ||
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). | ||
|
||
## Install | ||
Supports 3-, 4-, 6- and 8-digit hex values with or without a leading hash. | ||
|
||
## Installation | ||
```sh | ||
$ npm install --save hex-to-rgba | ||
``` | ||
|
||
## Usage | ||
```js | ||
var hexToRgba = require("hex-to-rgba"); | ||
|
||
hexToRgba('112233'); // "rgb(17, 34, 51)" | ||
hexToRgba('#112233'); // "rgb(17, 34, 51)" | ||
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('123'); // "rgb(17, 34, 51)" | ||
hexToRgba('#123'); // "rgb(17, 34, 51)" | ||
hexToRgba('123', 0.2) // "rgba(17, 34, 51, 0.2)" | ||
hexToRgba('#123', 0.2) // "rgba(17, 34, 51, 0.2)" | ||
|
||
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)" | ||
``` | ||
|
||
Testing | ||
``` | ||
npm run build && npm test | ||
``` | ||
|
||
## Signature | ||
`hexToRgba(hex, a)` | ||
`hexToRgba(hex, a=1)` | ||
|
||
## Parameters | ||
* `hex`: The hex value to convert. (examples: `'123456'`, `'#123456'`, `'123'`, `'#123'`) | ||
* `a`: An alpha value to apply. (optional) (examples: `'0.5'`, `0.25`) | ||
* `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`) | ||
|
||
## Returns | ||
An rgb or rgba value. (examples: `'rgb(11, 22, 33)'`, `'rgba(11, 22, 33, 0.5)'`) | ||
An rgba() string. (examples: `'rgba(11, 22, 33, 1)'`, `'rgba(11, 22, 33, 0.5)'`) | ||
|
||
## Changelog | ||
**1.0.0** | ||
- BREAKING CHANGE: Always return rgba(); even if the color is completely opaque | ||
- Support 4-digit hexes | ||
- Add typescript type declaration (props @gillchristian) | ||
**0.2.0** | ||
- Support 8-digit hexes | ||
**0.1.0** | ||
- Initial release | ||
- Support 6-digit hexes | ||
- Support 3-digit hexes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.