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