/**
 * This is the common logic for both the Node.js and web browser
 * implementations of `debug()`.
 */ export function setup ( env ) { param { String } namespace return { Function } api const createDebug = ( namespace , logger ) => { let prevTime ; let enableOverride = null ; let namespacesCache ; let enabledCache ; const debug = ( ... args ) => { const self = debug ; const curr = Number ( new Date ( ) ) ; const ms = curr - ( prevTime || curr ) ; self . diff = ms ; self . prev = prevTime ; self . curr = curr ; prevTime = curr ; args [ 0 ] = createDebug . coerce ( args [ 0 ] ) ; if ( typeof args [ 0 ] !== 'string' ) { args . unshift ( '%O' ) ; } let index = 0 ; args [ 0 ] = args [ 0 ] . replace ( /%([a-zA-Z%])/g , ( match , format ) => { if ( match === '%%' ) { return '%' ; } index ++ ; const formatter = createDebug . formatters [ format ] ; if ( typeof formatter === 'function' ) { const val = args [ index ] ; match = formatter . call ( self , val ) ; args . splice ( index , 1 ) ; index -- ; } return match ; } ) ; createDebug . formatArgs . call ( self , args ) ; if ( logger && typeof logger === 'function' ) { logger . apply ( self , args ) ; } if ( debug . enabled ) { const logFn = self . log || createDebug . log ; logFn . apply ( self , args ) ; } } ; debug . namespace = namespace ; debug . useColors = createDebug . useColors ( ) ; debug . color = createDebug . selectColor ( namespace ) ; debug . extend = extend ; debug . destroy = createDebug . destroy ; Object . defineProperty ( debug , 'enabled' , { enumerable : true , configurable : false , get : ( ) => { if ( enableOverride !== null ) { return enableOverride ; } if ( namespacesCache !== createDebug . namespaces ) { namespacesCache = createDebug . namespaces ; enabledCache = createDebug . enabled ( namespace ) ; } return enabledCache ; } , set : ( v ) => { enableOverride = v ; } , } ) ; if ( typeof createDebug . init === 'function' ) { createDebug . init ( debug ) ; } return debug ; } ; createDebug . debug = createDebug ; createDebug . default = createDebug ; createDebug . coerce = coerce ; createDebug . disable = disable ; createDebug . enable = enable ; createDebug . enabled = enabled ; createDebug . humanize = require ( 'ms' ) ; createDebug . destroy = destroy ; Object . keys ( env ) . forEach ( ( key ) => { createDebug [ key ] = env [ key ] ; } ) ; /**
     * The currently active debug mode names, and names to skip.
     */ createDebug . names = [ ] ; createDebug . skips = [ ] ; /**
     * Map of special "%n" handling functions, for the debug "format" argument.
     *
     * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
     */ createDebug . formatters = { } ; param { String } namespace return { Number | String } api function selectColor ( namespace ) { let hash = 0 ; for ( let i = 0 ; i < namespace . length ; i ++ ) { hash = ( hash << 5 ) - hash + namespace . charCodeAt ( i ) ; hash |= 0 ; } return createDebug . colors [ Math . abs ( hash ) % createDebug . colors . length ] ; } createDebug . selectColor = selectColor ; function extend ( this , namespace , delimiter ) { const newDebug = createDebug ( this . namespace + ( typeof delimiter === 'undefined' ? ':' : delimiter ) + namespace ) ; newDebug . log = this . log ; return newDebug ; } param { String } namespaces api function enable ( namespaces ) { createDebug . save ( namespaces ) ; createDebug . namespaces = namespaces ; createDebug . names = [ ] ; createDebug . skips = [ ] ; let i ; const split = ( typeof namespaces === 'string' ? namespaces : '' ) . split ( /[\s,]+/ ) ; const len = split . length ; for ( i = 0 ; i < len ; i ++ ) { if ( ! split [ i ] ) { continue ; } namespaces = split [ i ] . replace ( /\*/g , '.*?' ) ; if ( namespaces [ 0 ] === '-' ) { createDebug . skips . push ( new RegExp ( '^' + namespaces . substr ( 1 ) + '$' ) ) ; } else { createDebug . names . push ( new RegExp ( '^' + namespaces + '$' ) ) ; } } } return { String } api function disable ( ) { const namespaces = [ ... createDebug . names . map ( toNamespace ) , ... createDebug . skips . map ( toNamespace ) . map ( ( namespace ) => '-' + namespace ) , ] . join ( ',' ) ; createDebug . enable ( '' ) ; return namespaces ; } param { String } name return { Boolean } api function enabled ( name ) { if ( name [ name . length - 1 ] === '*' ) { return true ; } let i ; let len ; for ( i = 0 , len = createDebug . skips . length ; i < len ; i ++ ) { if ( createDebug . skips [ i ] . test ( name ) ) { return false ; } } for ( i = 0 , len = createDebug . names . length ; i < len ; i ++ ) { if ( createDebug . names [ i ] . test ( name ) ) { return true ; } } return false ; } param { RegExp } regxep return { String } api function toNamespace ( regexp ) { return regexp . toString ( ) . substring ( 2 , regexp . toString ( ) . length - 2 ) . replace ( /\.\*\?$/ , '*' ) ; } param { Mixed } val return { Mixed } api function coerce ( val ) { if ( val instanceof Error ) { return val . stack || val . message ; } return val ; } /**
     * XXX DO NOT USE. This is a temporary stub function.
     * XXX It WILL be removed in the next major release.
     */ function destroy ( ) { console . warn ( 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.' ) ; } createDebug . enable ( createDebug . load ( ) ) ; return createDebug ; }