@@ -50,6 +50,8 @@ function writeHelp() {
5050 console . log ( " -f, --format <svg|png> Format of generated icon. Otherwise detected from output path. (default: png)" ) ;
5151 console . log ( " -b, --back-color <value> Background color on format #rgb, #rgba, #rrggbb or #rrggbbaa. (default: transparent)" ) ;
5252 console . log ( " -p, --padding <value> Padding in percent in range 0 to 0.5. (default: 0.08)" ) ;
53+ console . log ( " --lightness-color <min,max> Lightness range of colored shapes in [0,1]. (default: 0.4,0.8)" ) ;
54+ console . log ( " --lightness-grayscale <min,max> Lightness range of grayscale shapes in [0,1]. (default: 0.3,0.9)" ) ;
5355 console . log ( " -v, --version Gets the version of Jdenticon." ) ;
5456 console . log ( " -h, --help Show this help information." ) ;
5557 console . log ( "" ) ;
@@ -117,10 +119,33 @@ function parseArgs(args) {
117119 format : consume ( [ "-f" , "--format" ] , true ) ,
118120 padding : consume ( [ "-p" , "--padding" ] , true ) ,
119121 backColor : consume ( [ "-b" , "--back-color" ] , true ) ,
122+ lightnessColor : consume ( [ "--lightness-color" ] , true ) ,
123+ lightnessGrayscale : consume ( [ "--lightness-grayscale" ] , true ) ,
120124 value : args
121125 } ;
122126}
123127
128+ function parseLightnessRange ( value ) {
129+ var parts = value . split ( "," ) ;
130+ if ( parts . length !== 2 ) {
131+ return ;
132+ }
133+
134+ var min = Number ( parts [ 0 ] ) ;
135+ var max = Number ( parts [ 1 ] ) ;
136+
137+ if (
138+ isNaN ( min ) || isNaN ( max ) ||
139+ min < 0 || min > 1 ||
140+ max < 0 || max > 1 ||
141+ min > max
142+ ) {
143+ return ;
144+ }
145+
146+ return [ min , max ] ;
147+ }
148+
124149function validateArgs ( args ) {
125150 if ( args . value . length ) {
126151
@@ -153,7 +178,34 @@ function validateArgs(args) {
153178 console . warn ( "WARN Invalid background color specified. Defaults to transparent." ) ;
154179 }
155180 }
156-
181+
182+ // Lightness
183+ var lightnessColor ;
184+ if ( args . lightnessColor != null ) {
185+ lightnessColor = parseLightnessRange ( args . lightnessColor ) ;
186+ if ( ! lightnessColor ) {
187+ lightnessColor = [ 0.4 , 0.8 ] ;
188+ console . warn ( "WARN Invalid lightness range of colored shapes specified. Defaults to 0.4,0.8." ) ;
189+ }
190+ }
191+
192+ var lightnessGrayscale ;
193+ if ( args . lightnessGrayscale != null ) {
194+ lightnessGrayscale = parseLightnessRange ( args . lightnessGrayscale ) ;
195+ if ( ! lightnessGrayscale ) {
196+ lightnessGrayscale = [ 0.3 , 0.9 ] ;
197+ console . warn ( "WARN Invalid lightness range of grayscale shapes specified. Defaults to 0.3,0.9." ) ;
198+ }
199+ }
200+
201+ var lightness ;
202+ if ( lightnessColor || lightnessGrayscale ) {
203+ lightness = {
204+ color : lightnessColor ,
205+ grayscale : lightnessGrayscale
206+ } ;
207+ }
208+
157209 // Format
158210 var generateSvg =
159211 args . format ? / ^ s v g $ / i. test ( args . format ) :
@@ -166,7 +218,8 @@ function validateArgs(args) {
166218 return {
167219 config : {
168220 padding : padding ,
169- backColor : backColor
221+ backColor : backColor ,
222+ lightness : lightness
170223 } ,
171224 output : args . output ,
172225 size : size ,
0 commit comments