diff --git a/index.js b/index.js index 3d40eb1..ceba9ae 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,7 @@ var rgb2hex = module.exports = function rgb2hex(color) { /** * parse input */ - var digits = /(.*?)rgb(a)??\((\d{1,3}),(\d{1,3}),(\d{1,3})(,([01]|0??\.([0-9]{0,3})))??\)/.exec(strippedColor); + var digits = /(.*?)rgb(a)??\((\d{1,3}),(\d{1,3}),(\d{1,3})(,([01]|0??\.([0-9]{0,})))??\)/.exec(strippedColor); if(!digits) { // or throw error if input isn't a valid rgb(a) color diff --git a/rgb2hex.js b/rgb2hex.js index 2112549..cd68c8d 100644 --- a/rgb2hex.js +++ b/rgb2hex.js @@ -21,7 +21,7 @@ /** * parse input */ - var digits = /(.*?)rgb(a)??\((\d{1,3}),(\d{1,3}),(\d{1,3})(,([01]|0??\.([0-9]{0,3})))??\)/.exec(strippedColor); + var digits = /(.*?)rgb(a)??\((\d{1,3}),(\d{1,3}),(\d{1,3})(,([01]|0??\.([0-9]{0,})))??\)/.exec(strippedColor); if(!digits) { // or throw error if input isn't a valid rgb(a) color diff --git a/rgb2hex.min.js b/rgb2hex.min.js index 18b7089..fd02b6e 100644 --- a/rgb2hex.min.js +++ b/rgb2hex.min.js @@ -1 +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??\.([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 { expect(parsedValue.alpha).toEqual(1) }) - it('converting rgba(12,173,22,.67)', () => { - const input = 'rgba(12,173,22,.67)' + it('converting rgba(12,173,22,.67313)', () => { + const input = 'rgba(12,173,22,.67313)' const parsedValue = rgb2hex(input) expect(parsedValue).toHaveProperty('hex')