1
- ! function ( e ) { if ( "object" == typeof exports && "undefined" != typeof module ) module . exports = e ( ) ; else if ( "function" == typeof define && define . amd ) define ( [ ] , e ) ; else { var f ; "undefined" != typeof window ? f = window : "undefined" != typeof global ? f = global : "undefined" != typeof self && ( f = self ) , f . debug = e ( ) } } ( function ( ) { var define , module , exports ; return ( function e ( t , n , r ) { function s ( o , u ) { if ( ! n [ o ] ) { if ( ! t [ o ] ) { var a = typeof require == "function" && require ; if ( ! u && a ) return a ( o , ! 0 ) ; if ( i ) return i ( o , ! 0 ) ; var f = new Error ( "Cannot find module '" + o + "'" ) ; throw f . code = "MODULE_NOT_FOUND" , f } var l = n [ o ] = { exports :{ } } ; t [ o ] [ 0 ] . call ( l . exports , function ( e ) { var n = t [ o ] [ 1 ] [ e ] ; return s ( n ?n :e ) } , l , l . exports , e , t , n , r ) } return n [ o ] . exports } var i = typeof require == "function" && require ; for ( var o = 0 ; o < r . length ; o ++ ) s ( r [ o ] ) ; return s } ) ( { 1 :[ function ( require , module , exports ) {
1
+ ( function ( f ) { if ( typeof exports === "object" && typeof module !== "undefined" ) { module . exports = f ( ) } else if ( typeof define === "function" && define . amd ) { define ( [ ] , f ) } else { var g ; if ( typeof window !== "undefined" ) { g = window } else if ( typeof global !== "undefined" ) { g = global } else if ( typeof self !== "undefined" ) { g = self } else { g = this } g . debug = f ( ) } } ) ( function ( ) { var define , module , exports ; return ( function e ( t , n , r ) { function s ( o , u ) { if ( ! n [ o ] ) { if ( ! t [ o ] ) { var a = typeof require == "function" && require ; if ( ! u && a ) return a ( o , ! 0 ) ; if ( i ) return i ( o , ! 0 ) ; var f = new Error ( "Cannot find module '" + o + "'" ) ; throw f . code = "MODULE_NOT_FOUND" , f } var l = n [ o ] = { exports :{ } } ; t [ o ] [ 0 ] . call ( l . exports , function ( e ) { var n = t [ o ] [ 1 ] [ e ] ; return s ( n ?n :e ) } , l , l . exports , e , t , n , r ) } return n [ o ] . exports } var i = typeof require == "function" && require ; for ( var o = 0 ; o < r . length ; o ++ ) s ( r [ o ] ) ; return s } ) ( { 1 :[ function ( require , module , exports ) {
2
2
module . exports = exports = require ( './' )
3
- exports . init ( )
4
3
5
4
} , { "./" :2 } ] , 2 :[ function ( require , module , exports ) {
6
5
( function ( global ) {
7
- module . exports = exports = debug
8
-
9
- exports . names = [ ]
10
- exports . skips = [ ]
6
+ module . exports = exports = Debug
11
7
12
8
var colors = 'lightseagreen forestgreen goldenrod dodgerblue darkorchid crimson' . split ( ' ' )
13
9
var colorIndex = 0
14
-
15
- exports . prefix = ''
16
-
17
- function noop ( ) { }
18
-
19
- function enable ( namespaces ) {
20
- if ( ! namespaces ) return
21
- var split = namespaces . split ( / [ \s , ] + / )
22
- for ( var i = 0 ; i < split . length ; i ++ ) {
23
- if ( ! split [ i ] ) continue
24
- namespaces = split [ i ] . replace ( / \* / g, '.*?' )
25
- if ( '-' == namespaces [ 0 ] )
26
- exports . skips . push ( new RegExp ( '^' + namespaces . substr ( 1 ) + '$' ) )
27
- else
28
- exports . names . push ( new RegExp ( '^' + namespaces + '$' ) )
29
- }
30
- }
31
-
32
- function enabled ( name ) {
33
- var i = 0 , reg
34
- for ( i = 0 ; reg = exports . skips [ i ++ ] ; ) {
35
- if ( reg . test ( name ) ) return false
36
- }
37
- for ( i = 0 ; reg = exports . names [ i ++ ] ; ) {
38
- if ( reg . test ( name ) ) return true
39
- }
40
- }
41
-
42
- function getColor ( ) {
43
- return colors [ colorIndex ++ % colors . length ]
44
- }
45
-
46
10
var prev
47
11
var inherit = 'color:inherit'
48
12
var console = global . console
13
+ var doc = global . document
14
+ var names = [ ]
15
+ var skips = [ ]
16
+
17
+ init ( )
18
+
19
+ exports . prefix = ''
49
20
50
21
exports . log = function ( namespace , args , color ) {
51
- var curr = + new Date ( )
22
+ var curr = + new Date
52
23
var ms = curr - ( prev || curr )
53
24
prev = curr
54
25
@@ -65,20 +36,21 @@ exports.log = function(namespace, args, color) {
65
36
console . debug . apply ( console , arr )
66
37
}
67
38
68
- function debug ( namespace ) {
39
+ exports . init = init
40
+
41
+ function Debug ( namespace ) {
69
42
var color = 'color:' + getColor ( )
70
43
return enabled ( namespace ) ? function ( ) {
71
44
exports . log ( namespace , arguments , color )
72
45
} : noop
73
46
}
74
47
75
- exports . init = function ( key ) {
48
+ function init ( key ) {
76
49
key = key || 'debug'
77
50
var reg = new RegExp ( key + '=(\\S+)' )
78
51
var res = reg . exec ( location . href )
79
52
if ( res ) {
80
53
enable ( res [ 1 ] )
81
- var doc = document
82
54
var elem = doc . createElement ( 'textarea' )
83
55
elem . style . cssText = 'width:100%;height:300px;overflow:auto;line-height:1.4;background:#333;color:#fff;font:16px Consolas;border:none'
84
56
var box = doc . body || doc . documentElement
@@ -91,7 +63,7 @@ exports.init = function(key) {
91
63
try {
92
64
val = JSON . stringify ( val , 0 , 4 )
93
65
} catch ( e ) {
94
- val = val + ''
66
+ val += ''
95
67
}
96
68
ret . push ( val )
97
69
}
@@ -106,6 +78,37 @@ exports.init = function(key) {
106
78
}
107
79
}
108
80
81
+ function noop ( ) { }
82
+
83
+ function enable ( namespaces ) {
84
+ if ( ! namespaces ) return
85
+ skips = [ ]
86
+ names = [ ]
87
+ var split = namespaces . split ( / [ \s , ] + / )
88
+ for ( var i = 0 ; i < split . length ; i ++ ) {
89
+ if ( ! split [ i ] ) continue
90
+ namespaces = split [ i ] . replace ( / \* / g, '.*?' )
91
+ if ( '-' == namespaces [ 0 ] )
92
+ skips . push ( new RegExp ( '^' + namespaces . substr ( 1 ) + '$' ) )
93
+ else
94
+ names . push ( new RegExp ( '^' + namespaces + '$' ) )
95
+ }
96
+ }
97
+
98
+ function enabled ( name ) {
99
+ var i = 0 , reg
100
+ for ( i = 0 ; reg = skips [ i ++ ] ; ) {
101
+ if ( reg . test ( name ) ) return false
102
+ }
103
+ for ( i = 0 ; reg = names [ i ++ ] ; ) {
104
+ if ( reg . test ( name ) ) return true
105
+ }
106
+ }
107
+
108
+ function getColor ( ) {
109
+ return colors [ colorIndex ++ % colors . length ]
110
+ }
111
+
109
112
} ) . call ( this , typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : { } )
110
113
} , { } ] } , { } , [ 1 ] ) ( 1 )
111
114
} ) ;
0 commit comments