Comparing version 0.1.7 to 0.1.8
{ | ||
"name": "rgb2hex", | ||
"main": "rgb2hex.js", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"homepage": "https://github.com/christian-bromann/rgb2hex", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -31,3 +31,3 @@ /** | ||
*/ | ||
var digits = /(.*?)rgb(a)??\((\d{1,3}),(\d{1,3}),(\d{1,3})(,[01]??\.([0-9]{0,3}))??\)/.exec(strippedColor); | ||
var digits = /(.*?)rgb(a)??\((\d{1,3}),(\d{1,3}),(\d{1,3})(,(1|0??\.([0-9]{0,3})))??\)/.exec(strippedColor); | ||
@@ -34,0 +34,0 @@ if(!digits) { |
{ | ||
"name": "rgb2hex", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "lightweight rgb/rgba to hex parser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
rgb2hex [![Build Status](https://travis-ci.org/christian-bromann/rgb2hex.svg?branch=master)](https://travis-ci.org/christian-bromann/rgb2hex) [![Coverage Status](https://coveralls.io/repos/christian-bromann/rgb2hex/badge.png)](https://coveralls.io/r/christian-bromann/rgb2hex) | ||
rgb2hex [![Build Status](https://travis-ci.org/christian-bromann/rgb2hex.svg?branch=master)](https://travis-ci.org/christian-bromann/rgb2hex) [![Coverage Status](https://coveralls.io/repos/christian-bromann/rgb2hex/badge.png)](https://coveralls.io/r/christian-bromann/rgb2hex) [![Known Vulnerabilities](https://snyk.io/test/github/christian-bromann/rgb2hex/badge.svg?targetFile=package.json)](https://snyk.io/test/github/christian-bromann/rgb2hex?targetFile=package.json) | ||
======= | ||
@@ -72,2 +72,3 @@ | ||
* 2018-07-05 v0.1.6 Prevent Regular Expression Denial of Service attacks | ||
* 2018-07-05 v0.1.7 Minor coverage fix | ||
* 2018-07-05 v0.1.7 Minor coverage fix | ||
* 2018-07-05 v0.1.8 Better handle alpha values |
@@ -24,3 +24,3 @@ ;(function(window) { | ||
*/ | ||
var digits = /(.*?)rgb(a)??\((\d{1,3}),(\d{1,3}),(\d{1,3})(,[01]??\.([0-9]{0,3}))??\)/.exec(strippedColor); | ||
var digits = /(.*?)rgb(a)??\((\d{1,3}),(\d{1,3}),(\d{1,3})(,(1|0??\.([0-9]{0,3})))??\)/.exec(strippedColor); | ||
@@ -27,0 +27,0 @@ if(!digits) { |
@@ -1,1 +0,1 @@ | ||
!function(r){var e=function(r){if("string"!=typeof r)throw new Error("color has to be type of `string`");if("#"===r.substr(0,1))return{hex:r,alpha:1};var e=r.replace(/\s+/g,""),t=/(.*?)rgb(a)??\((\d{1,3}),(\d{1,3}),(\d{1,3})(,[01]??\.([0-9]{0,3}))??\)/.exec(e);if(!t)throw new Error("given color ("+r+") isn't a valid rgb or rgba color");var n=parseInt(t[3],10),o=parseInt(t[4],10),a=parseInt(t[5],10),i=t[6]?/([0-9\.]+)/.exec(t[6])[0]:"1",s=(a|o<<8|n<<16|1<<24).toString(16).slice(1);return"."===i.substr(0,1)&&(i=parseFloat("0"+i)),1<i&&(i=1),i=parseFloat(Math.round(100*i))/100,{hex:"#"+s.toString(16),alpha:i}};"function"==typeof define&&define.amd?define("rgb2hex",function(){return e}):r.rgb2hex=e}(window); | ||
!function(r){var e=function(r){if("string"!=typeof r)throw new Error("color has to be type of `string`");if("#"===r.substr(0,1))return{hex:r,alpha:1};var e=r.replace(/\s+/g,""),t=/(.*?)rgb(a)??\((\d{1,3}),(\d{1,3}),(\d{1,3})(,(1|0??\.([0-9]{0,3})))??\)/.exec(e);if(!t)throw new Error("given color ("+r+") isn't a valid rgb or rgba color");var n=parseInt(t[3],10),o=parseInt(t[4],10),a=parseInt(t[5],10),i=t[6]?/([0-9\.]+)/.exec(t[6])[0]:"1",s=(a|o<<8|n<<16|1<<24).toString(16).slice(1);return"."===i.substr(0,1)&&(i=parseFloat("0"+i)),1<i&&(i=1),i=parseFloat(Math.round(100*i))/100,{hex:"#"+s.toString(16),alpha:i}};"function"==typeof define&&define.amd?define("rgb2hex",function(){return e}):r.rgb2hex=e}(window); |
@@ -83,3 +83,3 @@ const rgb2hex = require('../index') | ||
it('by limiting alpha value to 1', () => { | ||
var input = 'rgba(12,173,22,1.67)' | ||
var input = 'rgba(236,68,44,1)' | ||
expect(rgb2hex(input).alpha).not.toBeGreaterThan(1) | ||
@@ -99,2 +99,4 @@ }) | ||
expect(() => rgb2hex(input)).toThrow(invalidErrorMessage(input)) | ||
input = 'rgba(12,173,22,1.67)' | ||
expect(() => rgb2hex(input)).toThrow(invalidErrorMessage(input)) | ||
}) | ||
@@ -101,0 +103,0 @@ }) |
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
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
15632
250
73