Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support multiple decimal places #20

Merged
merged 1 commit into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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