File tree 1 file changed +11
-9
lines changed 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -230,28 +230,30 @@ function format(f) {
230
230
return str ;
231
231
}
232
232
233
- var debugs = { } ;
234
- var debugEnviron ;
233
+ const debugs = { } ;
234
+ let debugEnviron ;
235
235
236
236
const regExpSpecialChars = / [ | \\ { } ( ) [ \] ^ $ + ? . ] / g;
237
237
238
- function stringToRegExp ( string ) {
238
+ function arrayToRegExp ( strArr ) {
239
239
// Escape special chars except wildcard.
240
- string = string . replace ( regExpSpecialChars , '\\$&' ) ;
241
- // Transform wildcard to "match anything"
242
- string = string . replace ( / \* / g, '.*' ) ;
243
- return new RegExp ( `^${ string } $` ) ;
240
+ strArr = strArr . map ( ( str ) => {
241
+ return str . replace ( regExpSpecialChars , '\\$&' )
242
+ . replace ( / \* / g, '.*' ) ;
243
+ } ) ;
244
+
245
+ return new RegExp ( strArr . join ( '|' ) , 'i' ) ;
244
246
}
245
247
246
248
function debuglog ( set ) {
247
249
if ( debugEnviron === undefined ) {
248
250
debugEnviron = Array . from ( new Set (
249
251
( process . env . NODE_DEBUG || '' ) . split ( ',' ) . map ( ( s ) => s . toUpperCase ( ) ) ) ) ;
250
- debugEnviron = debugEnviron . map ( stringToRegExp ) ;
251
252
}
252
253
set = set . toUpperCase ( ) ;
253
254
if ( ! debugs [ set ] ) {
254
- if ( debugEnviron . some ( ( name ) => name . test ( set ) ) ) {
255
+ const regex = arrayToRegExp ( debugEnviron ) ;
256
+ if ( regex . test ( set ) ) {
255
257
var pid = process . pid ;
256
258
debugs [ set ] = function ( ) {
257
259
var msg = exports . format . apply ( exports , arguments ) ;
You can’t perform that action at this time.
0 commit comments