Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/lib/isRgbColor.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import assertString from './util/assertString';

const rgbColor = /^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/;
const rgbaColor = /^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/;
const rgbaColor = /^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d\d?|1(\.0)?|0(\.0)?)\)$/;
const rgbColorPercent = /^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)$/;
const rgbaColorPercent = /^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/;
const rgbaColorPercent = /^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d\d?|1(\.0)?|0(\.0)?)\)$/;

export default function isRgbColor(str, includePercentValues = true) {
assertString(str);
Expand Down
5 changes: 4 additions & 1 deletion test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4508,8 +4508,10 @@ describe('Validators', () => {
'rgba(255,255,255,1)',
'rgba(255,255,255,.1)',
'rgba(255,255,255,0.1)',
'rgba(255,255,255,.12)',
'rgb(5%,5%,5%)',
'rgba(5%,5%,5%,.3)',
'rgba(5%,5%,5%,.32)',
],
invalid: [
'rgb(0,0,0,)',
Expand All @@ -4518,11 +4520,12 @@ describe('Validators', () => {
'rgb()',
'rgba(0,0,0)',
'rgba(255,255,255,2)',
'rgba(255,255,255,.12)',
'rgba(255,255,255,.123)',
'rgba(255,255,256,0.1)',
'rgb(4,4,5%)',
'rgba(5%,5%,5%)',
'rgba(3,3,3%,.3)',
'rgba(5%,5%,5%,.321)',
'rgb(101%,101%,101%)',
'rgba(3%,3%,101%,0.3)',
'rgb(101%,101%,101%) additional invalid string part',
Expand Down