hex-to-rgba
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -8,3 +8,3 @@ 'use strict'; | ||
var parseHex = function parseHex(nakedHex) { | ||
var isShort = 3 === nakedHex.length || 4 === nakedHex.length; | ||
var isShort = nakedHex.length === 3 || nakedHex.length === 4; | ||
@@ -45,3 +45,3 @@ var twoDigitHexR = isShort ? '' + nakedHex.slice(0, 1) + nakedHex.slice(0, 1) : nakedHex.slice(0, 2); | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
}; | ||
}; // eslint-disable-line no-restricted-globals, max-len | ||
@@ -48,0 +48,0 @@ var formatRgb = function formatRgb(decimalObject, parameterA) { |
declare function hexToRgba(color: string, alpha?: string | number): string; | ||
export default hexToRgba; | ||
export = hexToRgba; |
{ | ||
"name": "hex-to-rgba", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Converts hexadecimal color codes to rgb()/rgba() values.", | ||
@@ -8,4 +8,6 @@ "main": "build/index.js", | ||
"build": "babel src -d build", | ||
"lint": "eslint src", | ||
"mocha": "mocha --compilers js:babel-core/register", | ||
"prepublish": "npm run build && npm test", | ||
"test": "./node_modules/mocha/bin/mocha --compilers js:babel-core/register" | ||
"test": "npm run lint && npm run mocha" | ||
}, | ||
@@ -32,9 +34,9 @@ "repository": { | ||
"babel-register": "^6.26.0", | ||
"eslint": "4.8.0", | ||
"eslint-config-airbnb": "15.1.0", | ||
"eslint-plugin-import": "2.7.0", | ||
"eslint-plugin-jsx-a11y": "5.1.1", | ||
"eslint-plugin-react": "7.4.0", | ||
"mocha": "^3.5.3" | ||
"eslint": "4.19.1", | ||
"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" | ||
} | ||
} |
[](https://travis-ci.org/misund/hex-to-rgba) | ||
[](https://greenkeeper.io/) | ||
`hex-to-rgba` turns an old-fashioned css hex color value string into an rgba() string. | ||
@@ -55,16 +57,2 @@ | ||
## Changelog | ||
**1.0.1** | ||
- Use charAt() instead of startsWith() for the sake of IE11 (props [@eltonjuan](https://github.com/misund/hex-to-rgba/pull/9)) | ||
**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](https://github.com/misund/hex-to-rgba/pull/5)) | ||
**0.2.0** | ||
- Support 8-digit hexes | ||
**0.1.0** | ||
- Initial release | ||
- Support 6-digit hexes | ||
- Support 3-digit hexes | ||
See the [releases page on GitHub](https://github.com/misund/hex-to-rgba/releases). |
@@ -5,4 +5,4 @@ const removeHash = hex => (hex.charAt(0) === '#' ? hex.slice(1) : hex); | ||
const isShort = ( | ||
3 === nakedHex.length | ||
|| 4 === nakedHex.length | ||
nakedHex.length === 3 | ||
|| nakedHex.length === 4 | ||
); | ||
@@ -27,3 +27,5 @@ | ||
const hexesToDecimals = ({ r, g, b, a }) => ({ | ||
const hexesToDecimals = ({ | ||
r, g, b, a, | ||
}) => ({ | ||
r: hexToDecimal(r), | ||
@@ -35,6 +37,8 @@ g: hexToDecimal(g), | ||
const isNumeric = n => !isNaN(parseFloat(n)) && isFinite(n); | ||
const isNumeric = n => !isNaN(parseFloat(n)) && isFinite(n); // eslint-disable-line no-restricted-globals, max-len | ||
const formatRgb = (decimalObject, parameterA) => { | ||
const { r, g, b, a: parsedA } = decimalObject; | ||
const { | ||
r, g, b, a: parsedA, | ||
} = decimalObject; | ||
const a = isNumeric(parameterA) ? parameterA : parsedA; | ||
@@ -41,0 +45,0 @@ |
Sorry, the diff of this file is not supported yet
253
49160
58