@@ -43,10 +43,10 @@ function setup(env) {
43
43
createDebug . outputFormatters = { } ;
44
44
45
45
/**
46
- * Map %m to outputting diff
46
+ * Map %m to applying formatters to arguments
47
47
*/
48
48
49
- createDebug . outputFormatters . m = function ( format , args ) {
49
+ createDebug . outputFormatters . m = function ( _ , args ) {
50
50
args [ 0 ] = createDebug . coerce ( args [ 0 ] ) ;
51
51
52
52
if ( typeof args [ 0 ] !== 'string' ) {
@@ -80,41 +80,40 @@ function setup(env) {
80
80
} ) ;
81
81
82
82
return args ;
83
- }
83
+ } ;
84
84
85
85
/**
86
86
* Map %+ to humanize()'s defaults (1000ms diff => "1s")
87
87
*/
88
88
89
- createDebug . outputFormatters [ '+' ] = function ( format , args ) {
89
+ createDebug . outputFormatters [ '+' ] = function ( ) {
90
90
return '+' + createDebug . humanize ( this . diff ) ;
91
- }
91
+ } ;
92
92
93
93
/**
94
94
* Map %d to returning milliseconds
95
95
8000
*/
96
96
97
- createDebug . outputFormatters . d = function ( format , args ) {
98
- return '+' + this . diff + "ms" ;
99
- }
97
+ createDebug . outputFormatters . d = function ( ) {
98
+ return '+' + this . diff + 'ms' ;
99
+ } ;
100
100
101
101
/**
102
102
* Map %n to outputting namespace prefix
103
103
*/
104
104
105
- createDebug . outputFormatters . n = function ( format , args ) {
105
+ createDebug . outputFormatters . n = function ( ) {
106
106
return this . namespace ;
107
- }
107
+ } ;
108
108
109
109
/**
110
110
* Map %_time to handling time...?
111
111
*/
112
112
113
- createDebug . outputFormatters . _time = function ( format , args ) {
114
- //browser doesn't have date
113
+ createDebug . outputFormatters . _time = function ( format ) {
114
+ // Browser doesn't have date
115
115
return new Date ( ) . toISOString ( ) ;
116
- }
117
-
116
+ } ;
118
117
119
118
/**
120
119
* Map of meta-formatters which are applied to outputFormatters
@@ -125,33 +124,33 @@ function setup(env) {
125
124
* Map %J* to `JSON.stringify()`
126
125
*/
127
126
128
- createDebug . outputFormatters . J = function ( v ) {
127
+ createDebug . outputFormatters . J = function ( v ) {
129
128
return JSON . stringify ( v ) ;
130
- }
129
+ } ;
131
130
132
131
/**
133
132
* Map %c* to to `applyColor()`
134
133
*/
135
134
136
- createDebug . outputFormatters . c = function ( v ) {
135
+ createDebug . outputFormatters . c = function ( v ) {
137
136
if ( this . useColors ) {
138
137
return this . applyColor ( v ) ;
139
138
} else {
140
139
return v ;
141
140
}
142
- }
141
+ } ;
143
142
144
143
/**
145
144
* Map %C* to to `applyColor(arg, bold = true)` (node)
146
145
*/
147
146
148
- createDebug . outputFormatters . C = function ( v ) {
147
+ createDebug . outputFormatters . C = function ( v ) {
149
148
if ( this . useColors ) {
150
149
return this . applyColor ( v , true ) ;
151
150
} else {
152
151
return v ;
153
152
}
154
- }
153
+ } ;
155
154
156
155
/**
157
156
* Selects a color for a debug namespace
@@ -198,28 +197,33 @@ function setup(env) {
198
197
prevTime = curr ;
199
198
200
199
// Apply relevant `outputFormatters` to `format`
201
- let reg = / % ( [ a - z A - Z + ] + | [ a - z A - Z ] * ?\{ .+ \} ) / , formattedArgs = [ ] , res ;
202
- let outputFormat = self . format ; //make a copy of the format
200
+ const reg = / % ( [ a - z A - Z + ] + | [ a - z A - Z ] * ?\{ .+ \} ) / ;
201
+ let formattedArgs = [ ] ;
202
+ let res ;
203
+ let outputFormat = self . format ; // Make a copy of the format
203
204
while ( res = outputFormat . match ( reg ) ) {
204
- let [ matched , formatToken ] = res , formatter , formatted ;
205
- //split out the part before the matched format token
206
- let split = outputFormat . slice ( 0 , res . index ) ;
205
+ let [ matched , formatToken ] = res ;
206
+ let formatter ;
207
+ let formatted ;
208
+
209
+ // Split out the part before the matched format token
210
+ const split = outputFormat . slice ( 0 , res . index ) ;
207
211
outputFormat = outputFormat . slice ( res . index + matched . length ) ;
208
212
209
- //and add it to the arguments
213
+ // And add it to the arguments
210
214
if ( split . length > 0 ) {
211
215
formattedArgs . push ( split ) ;
212
216
}
213
217
214
- let metaFormatters = [ ] ;
218
+ const metaFormatters = [ ] ;
215
219
// Extract metaformatters
216
220
while ( formatToken . length > 1 && ! formatToken . startsWith ( '{' ) ) {
217
221
const metaFormatterToken = formatToken . slice ( 0 , 1 ) ;
218
222
formatToken = formatToken . slice ( 1 ) ;
219
223
metaFormatters . push ( createDebug . outputFormatters [ metaFormatterToken ] ) ;
220
224
}
221
225
222
- //not really sure how to handle time at this point
226
+ // Not really sure how to handle time at this point
223
227
if ( formatToken . startsWith ( '{' ) ) {
224
228
formatter = createDebug . outputFormatters . _time ;
225
229
} else {
@@ -230,12 +234,12 @@ function setup(env) {
230
234
231
235
// Apply metaFormatters
232
236
metaFormatters . forEach ( metaFormatter => {
233
- if ( typeof metaFormatter === " function" ) {
237
+ if ( typeof metaFormatter === ' function' ) {
234
238
formatted = metaFormatter . call ( self , formatted ) ;
235
239
}
236
240
} ) ;
237
241
238
- if ( Array . isArray ( formatted ) ) { //intended to concatenate %m's args in the middle of the format
242
+ if ( Array . isArray ( formatted ) ) { // Intended to concatenate %m's args in the middle of the format
239
243
formattedArgs = formattedArgs . concat ( formatted ) ;
240
244
} else {
241
245
formattedArgs . push ( formatted ) ;
@@ -250,7 +254,7 @@ function setup(env) {
250
254
debug . namespace = namespace ;
251
255
debug . enabled = createDebug . enabled ( namespace ) ;
252
256
debug . useColors = createDebug . useColors ( ) ;
253
- debug . format = createDebug . getFormat ( ) || '%{H:M-Z}%n%m%+' ; //' %n%m%+'
257
+ debug . format = createDebug . getFormat ( ) || '%{H:M-Z}%n%m%+' ; // ' %n%m%+'
254
258
debug . color = selectColor ( namespace ) ;
255
259
debug . applyColor = createDebug . applyColor . bind ( debug ) ;
256
260
debug . destroy = destroy ;
0 commit comments