mirror of
				https://github.com/flynx/colors.js.git
				synced 2025-10-31 03:50:11 +00:00 
			
		
		
		
	fixed spacing, condensed line replacement call
This commit is contained in:
		
							parent
							
								
									00ee8f1ecd
								
							
						
					
					
						commit
						01bb5cf845
					
				| @ -42,14 +42,14 @@ if (typeof colors.enabled === "undefined") { | |||||||
|   colors.enabled = colors.supportsColor() !== false; |   colors.enabled = colors.supportsColor() !== false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| colors.stripColors = colors.strip = function (str) { | colors.stripColors = colors.strip = function(str){ | ||||||
|   return ("" + str).replace(/\x1B\[\d+m/g, ''); |   return ("" + str).replace(/\x1B\[\d+m/g, ''); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| var stylize = colors.stylize = function stylize(str, style) { | var stylize = colors.stylize = function stylize (str, style) { | ||||||
|   if (!colors.enabled) { |   if (!colors.enabled) { | ||||||
|     return str + ''; |     return str+''; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   return ansiStyles[style].open + str + ansiStyles[style].close; |   return ansiStyles[style].open + str + ansiStyles[style].close; | ||||||
| @ -60,7 +60,7 @@ var escapeStringRegexp = function (str) { | |||||||
|   if (typeof str !== 'string') { |   if (typeof str !== 'string') { | ||||||
|     throw new TypeError('Expected a string'); |     throw new TypeError('Expected a string'); | ||||||
|   } |   } | ||||||
|   return str.replace(matchOperatorsRe, '\\$&'); |   return str.replace(matchOperatorsRe,  '\\$&'); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function build(_styles) { | function build(_styles) { | ||||||
| @ -88,7 +88,7 @@ var styles = (function () { | |||||||
|   return ret; |   return ret; | ||||||
| })(); | })(); | ||||||
| 
 | 
 | ||||||
| var proto = defineProps(function colors() { }, styles); | var proto = defineProps(function colors() {}, styles); | ||||||
| 
 | 
 | ||||||
| function applyStyle() { | function applyStyle() { | ||||||
|   var args = arguments; |   var args = arguments; | ||||||
| @ -107,25 +107,13 @@ function applyStyle() { | |||||||
|   var nestedStyles = this._styles; |   var nestedStyles = this._styles; | ||||||
| 
 | 
 | ||||||
|   var i = nestedStyles.length; |   var i = nestedStyles.length; | ||||||
| 
 |  | ||||||
|   var rebuiltString = ''; |  | ||||||
| 
 |  | ||||||
|   while (i--) { |   while (i--) { | ||||||
|     var code = ansiStyles[nestedStyles[i]]; |     var code = ansiStyles[nestedStyles[i]]; | ||||||
| 
 |     str = code.open + str.replace(code.closeRe, code.open) + code.close; | ||||||
|     // multiline handling functionality
 |     str = str.replace(new RegExp(/[\r\n]+/, 'g'), code.close + '\n' + code.open); | ||||||
|     var lines = str.split(/[\r\n]+/) |  | ||||||
|     if (lines == 1) { |  | ||||||
|       rebuiltString += code.open + line.replace(code.closeRe, code.open) + code.close |  | ||||||
|     } else { |  | ||||||
|       lines.forEach(line => { |  | ||||||
|         rebuiltString += code.open + line.replace(code.closeRe, code.open) + code.close + '\n' |  | ||||||
|       }) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   return rebuiltString; |   return str; | ||||||
|    |    | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -138,11 +126,11 @@ colors.setTheme = function (theme) { | |||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|   for (var style in theme) { |   for (var style in theme) { | ||||||
|     (function (style) { |     (function(style){ | ||||||
|       colors[style] = function (str) { |       colors[style] = function(str){ | ||||||
|         if (typeof theme[style] === 'object') { |         if (typeof theme[style] === 'object'){ | ||||||
|           var out = str; |           var out = str; | ||||||
|           for (var i in theme[style]) { |           for (var i in theme[style]){ | ||||||
|             out = colors[theme[style][i]](out); |             out = colors[theme[style][i]](out); | ||||||
|           } |           } | ||||||
|           return out; |           return out; | ||||||
| @ -165,7 +153,7 @@ function init() { | |||||||
|   return ret; |   return ret; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| var sequencer = function sequencer(map, str) { | var sequencer = function sequencer (map, str) { | ||||||
|   var exploded = str.split(""), i = 0; |   var exploded = str.split(""), i = 0; | ||||||
|   exploded = exploded.map(map); |   exploded = exploded.map(map); | ||||||
|   return exploded.join(""); |   return exploded.join(""); | ||||||
| @ -183,7 +171,7 @@ colors.maps.rainbow = require('./maps/rainbow'); | |||||||
| colors.maps.random = require('./maps/random') | colors.maps.random = require('./maps/random') | ||||||
| 
 | 
 | ||||||
| for (var map in colors.maps) { | for (var map in colors.maps) { | ||||||
|   (function (map) { |   (function(map){ | ||||||
|     colors[map] = function (str) { |     colors[map] = function (str) { | ||||||
|       return sequencer(colors.maps[map], str); |       return sequencer(colors.maps[map], str); | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user