Skip to content

Commit c21f919

Browse files
committed
Core: Compress parsers a little
1 parent 2d1a90b commit c21f919

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

jquery.color.js

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,48 +54,30 @@
5454
}, {
5555

5656
// this regex ignores A-F because it's compared against an already lowercased string
57-
re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,
57+
re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})?/,
5858
parse: function( execResult ) {
5959
return [
6060
parseInt( execResult[ 1 ], 16 ),
6161
parseInt( execResult[ 2 ], 16 ),
6262
parseInt( execResult[ 3 ], 16 ),
63-
( parseInt( execResult[ 4 ], 16 ) / 255.0 ).toFixed( 2 )
63+
execResult[ 4 ] ?
64+
( parseInt( execResult[ 4 ], 16 ) / 255 ).toFixed( 2 ) :
65+
1
6466
];
6567
}
6668
}, {
6769

6870
// this regex ignores A-F because it's compared against an already lowercased string
69-
re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,
70-
parse: function( execResult ) {
71-
return [
72-
parseInt( execResult[ 1 ], 16 ),
73-
parseInt( execResult[ 2 ], 16 ),
74-
parseInt( execResult[ 3 ], 16 )
75-
];
76-
}
77-
}, {
78-
79-
// this regex ignores A-F because it's compared against an already lowercased string
80-
re: /#([a-f0-9])([a-f0-9])([a-f0-9])([a-f0-9])/,
71+
re: /#([a-f0-9])([a-f0-9])([a-f0-9])([a-f0-9])?/,
8172
parse: function( execResult ) {
8273
return [
8374
parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ),
8475
parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ),
8576
parseInt( execResult[ 3 ] + execResult[ 3 ], 16 ),
86-
( parseInt( execResult[ 4 ] + execResult[ 4 ], 16 ) / 255 )
87-
.toFixed( 2 )
88-
];
89-
}
90-
}, {
91-
92-
// this regex ignores A-F because it's compared against an already lowercased string
93-
re: /#([a-f0-9])([a-f0-9])([a-f0-9])/,
94-
parse: function( execResult ) {
95-
return [
96-
parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ),
97-
parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ),
98-
parseInt( execResult[ 3 ] + execResult[ 3 ], 16 )
77+
execResult[ 4 ] ?
78+
( parseInt( execResult[ 4 ] + execResult[ 4 ], 16 ) / 255 )
79+
.toFixed( 2 ) :
80+
1
9981
];
10082
}
10183
}, {

0 commit comments

Comments
 (0)