3
3
/**
4
4
* This is the web browser implementation of `debug()`.
5
5
*/
6
+ import humanize from 'ms' ;
6
7
7
- exports . formatArgs = formatArgs ;
8
- exports . save = save ;
9
- exports . load = load ;
10
- exports . useColors = useColors ;
11
- exports . storage = localstorage ( ) ;
12
- exports . destroy = ( ( ) => {
13
- let warned = false ;
8
+ export {
9
+ formatArgs , save , load , useColors , setupFormatters ,
10
+ } ;
14
11
15
- return ( ) => {
16
- if ( ! warned ) {
17
- warned = true ;
18
- console . warn ( 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.' ) ;
19
- }
20
- } ;
21
- } ) ( ) ;
12
+ export const storage = localstorage ( ) ;
22
13
23
14
/**
24
15
* Colors.
25
16
*/
26
-
27
- exports . colors = [
17
+ export const colors = [
28
18
'#0000CC' ,
29
19
'#0000FF' ,
30
20
'#0033CC' ,
@@ -100,7 +90,7 @@ exports.colors = [
100
90
'#FF9900' ,
101
91
'#FF9933' ,
102
92
'#FFCC00' ,
103
- '#FFCC33'
93
+ '#FFCC33' ,
104
94
] ;
105
95
106
96
/**
@@ -142,14 +132,13 @@ function useColors() {
142
132
*
143
133
* @api public
144
134
*/
145
-
146
135
function formatArgs ( args ) {
147
136
args [ 0 ] = ( this . useColors ? '%c' : '' ) +
148
137
this . namespace +
149
138
( this . useColors ? ' %c' : ' ' ) +
150
139
args [ 0 ] +
151
140
( this . useColors ? '%c ' : ' ' ) +
152
- '+' + module . exports . humanize ( this . diff ) ;
141
+ '+' + humanize ( this . diff ) ;
153
142
154
143
if ( ! this . useColors ) {
155
144
return ;
@@ -186,7 +175,7 @@ function formatArgs(args) {
186
175
*
187
176
* @api public
188
177
*/
189
- exports . log = console . debug || console . log || ( ( ) => { } ) ;
178
+ export const log = console . debug || console . log || ( ( ) => { } ) ;
190
179
191
180
/**
192
181
* Save `namespaces`.
@@ -197,9 +186,9 @@ exports.log = console.debug || console.log || (() => {});
197
186
function save ( namespaces ) {
198
187
try {
199
188
if ( namespaces ) {
200
- exports . storage . setItem ( 'debug' , namespaces ) ;
189
+ storage . setItem ( 'debug' , namespaces ) ;
201
190
} else {
202
- exports . storage . removeItem ( 'debug' ) ;
191
+ storage . removeItem ( 'debug' ) ;
203
192
}
204
193
} catch ( error ) {
205
194
// Swallow
@@ -216,7 +205,7 @@ function save(namespaces) {
216
205
function load ( ) {
217
206
let r ;
218
207
try {
219
- r = exports . storage . getItem ( 'debug' ) ;
208
+ r = storage . getItem ( 'debug' ) ;
220
209
} catch ( error ) {
221
210
// Swallow
222
211
// XXX (@Qix-) should we be logging these?
@@ -240,7 +229,6 @@ function load() {
240
229
* @return {LocalStorage }
241
230
* @api private
242
231
*/
243
-
244
232
function localstorage ( ) {
245
233
try {
246
234
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
@@ -252,18 +240,15 @@ function localstorage() {
252
240
}
253
241
}
254
242
255
- module . exports = require ( './common' ) ( exports ) ;
256
-
257
- const { formatters} = module . exports ;
258
-
259
- /**
260
- * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
261
- */
262
-
263
- formatters . j = function ( v ) {
264
- try {
265
- return JSON . stringify ( v ) ;
266
- } catch ( error ) {
267
- return '[UnexpectedJSONParseError]: ' + error . message ;
268
- }
269
- } ;
243
+ function setupFormatters ( formatters ) {
244
+ /**
245
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
246
+ */
247
+ formatters . j = function ( v ) {
248
+ try {
249
+ return JSON . stringify ( v ) ;
250
+ } catch ( error ) {
251
+ return '[UnexpectedJSONParseError]: ' + error . message ;
252
+ }
253
+ } ;
254
+ }
0 commit comments