Skip to content

Commit

Permalink
fix: support multiple decimal places
Browse files Browse the repository at this point in the history
  • Loading branch information
jeoy authored and christian-bromann committed Nov 13, 2019
1 parent ed5b661 commit 9749822
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rgb2hex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rgb2hex.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/rgb2hex.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ describe('rgb2hex should', () => {
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')
Expand Down

0 comments on commit 9749822

Please sign in to comment.