@@ -6,7 +6,7 @@ var supportsColor = require('supports-color');
66const chalk = {
77 enabled : supportsColor . stdout ,
88 use256 : supportsColor . stdout && supportsColor . stdout . has256 ,
9- themes : { } ,
9+ themes : new Map ( ) ,
1010 theme : { }
1111} ;
1212
@@ -26,7 +26,7 @@ const DEFAULT = {
2626} ;
2727
2828chalk . setTheme = function ( name ) {
29- const theme = this . themes [ name ] || this . themes . default || { } ;
29+ const theme = this . themes . get ( name ) || this . themes . get ( ' default' ) || { } ;
3030 this . theme = _ . extendOwn ( DEFAULT , theme ) ;
3131} ;
3232
@@ -52,26 +52,26 @@ chalk.wrap = function(pre, post) {
5252const bgName = x => 'bg' + x [ 0 ] . toUpperCase ( ) + x . substr ( 1 ) ;
5353
5454chalk . init = function ( ) {
55- require ( './helper' ) . getCodeDirData ( 'colors' ) . forEach ( function ( f ) {
56- const o = { } ;
55+ const h = require ( './helper' ) ;
56+ for ( let f of h . getCodeDirData ( 'colors' ) ) {
57+ const theme = { } ;
5758 _ . pairs ( f . data ) . forEach ( function ( x ) {
5859 const k = x [ 0 ] ;
5960 const v = x [ 1 ] ;
6061 const bgK = bgName ( k ) ;
6162
6263 if ( chalk . use256 ) {
63- o [ k ] = style . color . ansi256 . hex ( v ) ;
64- o [ bgK ] = style . bgColor . ansi256 . hex ( v ) ;
64+ theme [ k ] = style . color . ansi256 . hex ( v ) ;
65+ theme [ bgK ] = style . bgColor . ansi256 . hex ( v ) ;
6566 } else {
66- o [ k ] = style . color . ansi . hex ( v ) ;
67- o [ bgK ] = style . bgColor . ansi . hex ( v ) ;
67+ theme [ k ] = style . color . ansi . hex ( v ) ;
68+ theme [ bgK ] = style . bgColor . ansi . hex ( v ) ;
6869 }
6970 } ) ;
70- chalk . themes [ f . name ] = o ;
71- } ) ;
71+ chalk . themes . set ( f . name , theme ) ;
72+ }
7273
73- _ . chain ( [ 'black' , 'blue' , 'cyan' , 'gray' , 'green' , 'magenta' , 'red' , 'white' , 'yellow' ] )
74- . each ( function ( color ) {
74+ for ( let color of [ 'black' , 'blue' , 'cyan' , 'gray' , 'green' , 'magenta' , 'red' , 'white' , 'yellow' ] ) {
7575 Object . defineProperty ( chalk , color , {
7676 get : ( ) => chalk . wrap ( chalk . theme [ color ] , style . color . close ) ,
7777 configurable : true
@@ -81,15 +81,14 @@ chalk.init = function() {
8181 get : ( ) => chalk . wrap ( chalk . theme [ bgcolor ] , style . bgColor . close ) ,
8282 configurable : true
8383 } ) ;
84- } ) ;
84+ }
8585
86- _ . chain ( [ 'bold' , 'dim' , 'italic' , 'inverse' , 'strikethrough' , 'underline' ] )
87- . each ( function ( modifier ) {
86+ for ( let modifier of [ 'bold' , 'dim' , 'italic' , 'inverse' , 'strikethrough' , 'underline' ] ) {
8887 Object . defineProperty ( chalk , modifier , {
8988 get : ( ) => chalk . wrap ( style [ modifier ] . open , style [ modifier ] . close ) ,
9089 configurable : true
9190 } ) ;
92- } ) ;
91+ }
9392} ;
9493
9594module . exports = chalk ;
0 commit comments