hex-to-rgba
Advanced tools
Comparing version 1.0.2 to 2.0.0
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -9,10 +9,7 @@ var removeHash = function removeHash(hex) { | ||
var isShort = nakedHex.length === 3 || nakedHex.length === 4; | ||
var twoDigitHexR = isShort ? "".concat(nakedHex.slice(0, 1)).concat(nakedHex.slice(0, 1)) : nakedHex.slice(0, 2); | ||
var twoDigitHexG = isShort ? "".concat(nakedHex.slice(1, 2)).concat(nakedHex.slice(1, 2)) : nakedHex.slice(2, 4); | ||
var twoDigitHexB = isShort ? "".concat(nakedHex.slice(2, 3)).concat(nakedHex.slice(2, 3)) : nakedHex.slice(4, 6); | ||
var twoDigitHexA = (isShort ? "".concat(nakedHex.slice(3, 4)).concat(nakedHex.slice(3, 4)) : nakedHex.slice(6, 8)) || 'ff'; // const numericA = +((parseInt(a, 16) / 255).toFixed(2)); | ||
var twoDigitHexR = isShort ? '' + nakedHex.slice(0, 1) + nakedHex.slice(0, 1) : nakedHex.slice(0, 2); | ||
var twoDigitHexG = isShort ? '' + nakedHex.slice(1, 2) + nakedHex.slice(1, 2) : nakedHex.slice(2, 4); | ||
var twoDigitHexB = isShort ? '' + nakedHex.slice(2, 3) + nakedHex.slice(2, 3) : nakedHex.slice(4, 6); | ||
var twoDigitHexA = (isShort ? '' + nakedHex.slice(3, 4) + nakedHex.slice(3, 4) : nakedHex.slice(6, 8)) || 'ff'; | ||
// const numericA = +((parseInt(a, 16) / 255).toFixed(2)); | ||
return { | ||
@@ -47,2 +44,3 @@ r: twoDigitHexR, | ||
var formatRgb = function formatRgb(decimalObject, parameterA) { | ||
@@ -53,8 +51,5 @@ var r = decimalObject.r, | ||
parsedA = decimalObject.a; | ||
var a = isNumeric(parameterA) ? parameterA : parsedA; | ||
return 'rgba(' + r + ', ' + g + ', ' + b + ', ' + a + ')'; | ||
return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(a, ")"); | ||
}; | ||
/** | ||
@@ -69,2 +64,4 @@ * Turns an old-fashioned css hex color value into a rgb color value. | ||
*/ | ||
var hexToRgba = function hexToRgba(hex, a) { | ||
@@ -74,3 +71,2 @@ var hashlessHex = removeHash(hex); | ||
var decimalObject = hexesToDecimals(hexObject); | ||
return formatRgb(decimalObject, a); | ||
@@ -77,0 +73,0 @@ }; |
{ | ||
"name": "hex-to-rgba", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Converts hexadecimal color codes to rgb()/rgba() values.", | ||
@@ -9,5 +9,6 @@ "main": "build/index.js", | ||
"lint": "eslint src", | ||
"mocha": "mocha --compilers js:babel-core/register", | ||
"prepublish": "npm run build && npm test", | ||
"test": "npm run lint && npm run mocha" | ||
"mocha": "mocha --require @babel/register", | ||
"prepublish": "yarn build && yarn test", | ||
"release": "np", | ||
"test": "yarn lint && yarn mocha" | ||
}, | ||
@@ -31,12 +32,14 @@ "repository": { | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-register": "^6.26.0", | ||
"eslint": "4.19.1", | ||
"@babel/cli": "7.4.4", | ||
"@babel/core": "7.4.5", | ||
"@babel/preset-env": "7.4.5", | ||
"@babel/register": "7.4.4", | ||
"eslint": "5.16.0", | ||
"eslint-config-airbnb": "17.1.0", | ||
"eslint-plugin-import": "2.13.0", | ||
"eslint-plugin-jsx-a11y": "6.1.1", | ||
"eslint-plugin-react": "7.11.1", | ||
"mocha": "^5.0.4" | ||
"eslint-plugin-import": "2.17.3", | ||
"eslint-plugin-jsx-a11y": "6.1.2", | ||
"eslint-plugin-react": "7.13.0", | ||
"mocha": "6.1.4", | ||
"np": "5.0.2" | ||
} | ||
} |
@@ -15,7 +15,14 @@ [![Build Status](https://travis-ci.org/misund/hex-to-rgba.svg?branch=master)](https://travis-ci.org/misund/hex-to-rgba) | ||
``` | ||
or | ||
```sh | ||
$ yarn add hex-to-rgba | ||
``` | ||
## Usage | ||
```js | ||
var hexToRgba = require("hex-to-rgba"); | ||
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)" | ||
@@ -42,10 +49,7 @@ hexToRgba('#112233'); // "rgba(17, 34, 51, 1)" | ||
Testing | ||
``` | ||
npm run build && npm test | ||
``` | ||
## Signature | ||
`hexToRgba(hex, a=1)` | ||
Returns an rgba() string. (examples: `'rgba(11, 22, 33, 1)'`, `'rgba(11, 22, 33, 0.5)'`) | ||
## Parameters | ||
@@ -55,6 +59,18 @@ * `hex`: The hex color value to convert to rgba. (examples: `'123456'`, `'#123456'`, `'123'`, `'#123'`) | ||
## Returns | ||
An rgba() string. (examples: `'rgba(11, 22, 33, 1)'`, `'rgba(11, 22, 33, 0.5)'`) | ||
## 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). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74
41031
11
5
60
1