@@ -3,13 +3,13 @@ const escapeStringRegexp = require('escape-string-regexp');
3
3
const ansiStyles = require ( 'ansi-styles' ) ;
4
4
const supportsColor = require ( 'supports-color' ) ;
5
5
6
- const defineProps = Object . defineProperties ;
7
6
const isSimpleWindowsTerm = process . platform === 'win32' && ! process . env . TERM . toLowerCase ( ) . startsWith ( 'xterm' ) ;
8
7
9
8
// `supportsColor.level` → `ansiStyles.color[name]` mapping
10
9
const levelMapping = [ 'ansi' , 'ansi' , 'ansi256' , 'ansi16m' ] ;
10
+
11
11
// `color-convert` models to exclude from the Chalk API due to conflicts and such
12
- const skipModels = [ 'gray' ] ;
12
+ const skipModels = new Set ( [ 'gray' ] ) ;
13
13
14
14
function Chalk ( options ) {
15
15
// Detect level if not set manually
@@ -36,7 +36,7 @@ for (const key of Object.keys(ansiStyles)) {
36
36
37
37
ansiStyles . color . closeRe = new RegExp ( escapeStringRegexp ( ansiStyles . color . close ) , 'g' ) ;
38
38
for ( const model of Object . keys ( ansiStyles . color . ansi ) ) {
39
- if ( skipModels . indexOf ( model ) !== - 1 ) {
39
+ if ( skipModels . has ( model ) ) {
40
40
continue ;
41
41
}
42
42
@@ -58,11 +58,11 @@ for (const model of Object.keys(ansiStyles.color.ansi)) {
58
58
59
59
ansiStyles . bgColor . closeRe = new RegExp ( escapeStringRegexp ( ansiStyles . bgColor . close ) , 'g' ) ;
60
60
for ( const model of Object . keys ( ansiStyles . bgColor . ansi ) ) {
61
- if ( skipModels . indexOf ( model ) !== - 1 ) {
61
+ if ( skipModels . has ( model ) ) {
62
62
continue ;
63
63
}
64
64
65
- const bgModel = 'bg' + model . charAt ( 0 ) . toUpperCase ( ) + model . slice ( 1 ) ;
65
+ const bgModel = 'bg' + model [ 0 ] . toUpperCase ( ) + model . slice ( 1 ) ;
66
66
styles [ bgModel ] = {
67
67
get ( ) {
68
68
const level = this . level ;
@@ -79,8 +79,7 @@ for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
79
79
} ;
80
80
}
81
81
82
- // eslint-disable-next-line func-names
83
- const proto = defineProps ( ( ) => { } , styles ) ;
82
+ const proto = Object . defineProperties ( ( ) => { } , styles ) ;
84
83
85
84
function build ( _styles , key ) {
86
85
const builder = function ( ) {
@@ -127,9 +126,6 @@ function applyStyle() {
127
126
return str ;
128
127
}
129
128
130
- const nestedStyles = this . _styles ;
131
- let i = nestedStyles . length ;
132
-
133
129
// Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
134
130
// see https://github.com/chalk/chalk/issues/58
135
131
// If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
@@ -138,9 +134,7 @@ function applyStyle() {
138
134
ansiStyles . dim . open = '' ;
139
135
}
140
136
141
- while ( i -- ) {
142
- const code = nestedStyles [ i ] ;
143
-
137
+ for ( const code of this . _styles . slice ( ) . reverse ( ) ) {
144
138
// Replace any instances already present with a re-opening code
145
139
// otherwise only the part of the string until said closing code
146
140
// will be colored, and the rest will simply be 'plain'.
@@ -152,13 +146,13 @@ function applyStyle() {
152
146
str = str . replace ( / \r ? \n / g, `${ code . close } $&${ code . open } ` ) ;
153
147
}
154
148
155
- // Reset the original ' dim' if we changed it to work around the Windows dimmed gray issue
149
+ // Reset the original ` dim` if we changed it to work around the Windows dimmed gray issue
156
150
ansiStyles . dim . open = originalDim ;
157
151
158
152
return str ;
159
153
}
160
154
161
- defineProps ( Chalk . prototype , styles ) ;
155
+ Object . defineProperties ( Chalk . prototype , styles ) ;
162
156
163
157
module . exports = new Chalk ( ) ;
164
158
module . exports . styles = ansiStyles ;
0 commit comments