mirror of
				https://github.com/flynx/colors.js.git
				synced 2025-10-31 20:10:09 +00:00 
			
		
		
		
	Make stylize() work for non-ASCI styles (#155)
This commit is contained in:
		
							parent
							
								
									a1407aee04
								
							
						
					
					
						commit
						b4d964b514
					
				| @ -62,7 +62,16 @@ var stylize = colors.stylize = function stylize(str, style) { | ||||
|     return str+''; | ||||
|   } | ||||
| 
 | ||||
|   return ansiStyles[style].open + str + ansiStyles[style].close; | ||||
|   var styleMap = ansiStyles[style]; | ||||
| 
 | ||||
|   // Stylize should work for non-ANSI styles, too
 | ||||
|   if(!styleMap && style in colors){ | ||||
|     // Style maps like trap operate as functions on strings;
 | ||||
|     // they don't have properties like open or close.
 | ||||
|     return colors[style](str); | ||||
|   } | ||||
| 
 | ||||
|   return styleMap.open + str + styleMap.close; | ||||
| }; | ||||
| 
 | ||||
| var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g; | ||||
|  | ||||
| @ -30,6 +30,12 @@ assert.equal(s.inverse, '\x1B[7m' + s + '\x1B[27m'); | ||||
| 
 | ||||
| assert.ok(s.rainbow); | ||||
| 
 | ||||
| assert.equal(colors.stylize("foo", "rainbow"), '\u001b[31mf\u001b[39m\u001b[33mo\u001b[39m\u001b[32mo\u001b[39m'); | ||||
| assert.ok(colors.stylize(s, "america")); | ||||
| assert.ok(colors.stylize(s, "zebra")); | ||||
| assert.ok(colors.stylize(s, "trap")); | ||||
| assert.ok(colors.stylize(s, "random")); | ||||
| 
 | ||||
| aE(s, 'white', 37); | ||||
| aE(s, 'grey', 90); | ||||
| aE(s, 'black', 30); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user