@@ -11,18 +11,7 @@ import * as weave from './misc/weave'
11
11
import * as colors from './misc/colors'
12
12
import * as scopes from './misc/scopes'
13
13
14
- export default {
15
- // TODO remove these from the export default and export them directly (prevents expensive copy)
16
- // TODO don't use this.message use message directly (prevents expensive copy)
17
- paths : paths ,
18
- blocks : blocks ,
19
- cells : cells ,
20
- words : words ,
21
- weave : weave ,
22
- colors : colors ,
23
- scopes : scopes ,
24
-
25
- bufferLines ( t , f ) {
14
+ export function bufferLines ( t , f ) {
26
15
if ( ! f ) { [ t , f ] = [ null , t ] ; }
27
16
const buffer = [ '' ] ;
28
17
const flush = ( t == null ) ? ( ) => { } : debounce ( ( ( ) => {
@@ -39,41 +28,41 @@ export default {
39
28
}
40
29
flush ( ) ;
41
30
} ;
42
- } ,
31
+ }
43
32
44
- time ( desc , p ) {
33
+ export function time ( desc , p ) {
45
34
const s = ( ) => new Date ( ) . getTime ( ) / 1000 ;
46
35
const t = s ( ) ;
47
36
p . then ( ( ) => console . log ( `${ desc } : ${ ( s ( ) - t ) . toFixed ( 2 ) } s` ) )
48
37
. catch ( ( ) => { } ) ;
49
38
return p ;
50
- } ,
39
+ }
51
40
52
- hook ( obj , method , f ) {
41
+ export function hook ( obj , method , f ) {
53
42
const souper = obj [ method ] . bind ( obj ) ;
54
43
return obj [ method ] = ( ...a ) => f ( souper , ...a ) ;
55
- } ,
44
+ }
56
45
57
- once ( f ) {
46
+ export function once ( f ) {
58
47
let done = false ;
59
48
return function ( ...args ) {
60
49
if ( done ) { return ; }
61
50
done = true ;
62
51
return f . call ( this , ...args ) ;
63
52
} ;
64
- } ,
53
+ }
65
54
66
- mutex ( ) {
55
+ export function mutex ( ) {
67
56
let wait = Promise . resolve ( ) ;
68
57
return function ( f ) {
69
58
const current = wait ;
70
59
let release = null ;
71
60
wait = new Promise ( resolve => release = resolve ) . catch ( function ( ) { } ) ;
72
61
return current . then ( ( ) => f . call ( this , release ) ) ;
73
62
} ;
74
- } ,
63
+ }
75
64
76
- exclusive ( f ) {
65
+ export function exclusive ( f ) {
77
66
const lock = module . exports . mutex ( ) ;
78
67
return function ( ...args ) {
79
68
return lock ( release => {
@@ -82,10 +71,10 @@ export default {
82
71
return result ;
83
72
} ) ;
84
73
} ;
85
- } ,
74
+ }
86
75
87
- // takes a time period in seconds and formats it as hh:mm:ss
88
- formatTimePeriod ( dt ) {
76
+ // takes a time period in seconds and formats it as hh:mm:ss
77
+ export function formatTimePeriod ( dt ) {
89
78
if ( dt <= 1 ) { return ; }
90
79
const h = Math . floor ( dt / ( 60 * 60 ) ) ;
91
80
const m = Math . floor ( ( dt -= h * 60 * 60 ) / 60 ) ;
@@ -96,5 +85,12 @@ export default {
96
85
parts [ i ] = dt < 10 ? `0${ dt } ` : `${ dt } ` ;
97
86
}
98
87
return parts . join ( ':' ) ;
99
- }
100
- } ;
88
+ }
89
+
90
+ exports . paths = paths
91
+ exports . blocks = blocks
92
+ exports . cells = cells
93
+ exports . words = words
94
+ exports . weave = weave
95
+ exports . colors = colors
96
+ exports . scopes = scopes
0 commit comments