File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ export const isEmpty = (x) => {
1010 }
1111
1212 if ( ! x ) return true ;
13- if ( x === "" ) return true ;
1413 if ( x === { } ) return true ;
1514 if ( x === [ ] ) return true ;
1615 if ( x == null ) return true ;
@@ -85,8 +84,30 @@ export const parseColor = (color) => {
8584 } else {
8685 colors = [ 0 , 0 , 0 , 0 ] ;
8786 }
88- isNaN ( colors [ 3 ] ) && ( colors [ 3 ] = 1 ) ;
89- return colors . slice ( 0 , 4 ) ;
87+
88+ // Add alpha if missing
89+ if ( isNaN ( colors [ 3 ] ) ) {
90+ colors [ 3 ] = 255 ;
91+ }
92+
93+ return colors ;
94+ } ;
95+
96+ /**
97+ * Parsed colors to hex code
98+ * @param colors
99+ * @returns {string }
100+ */
101+ export const colorsToHex = ( colors ) => {
102+ const hexColors = colors . map ( ( color ) => {
103+ color = color . toString ( 16 ) ;
104+ while ( color . length < 2 ) {
105+ color += "0" ;
106+ }
107+ return color ;
108+ } ) ;
109+
110+ return "#" + hexColors . join ( "" ) ;
90111} ;
91112
92113/**
You can’t perform that action at this time.
0 commit comments