@@ -8,36 +8,46 @@ var through = require('through2');
8
8
9
9
// one line string with or without trailing comma
10
10
function makeStringRegex ( attr ) {
11
- return attr + ': \'.*\'' + ',?' ;
11
+ return makeRegex (
12
+ attr + ': \'.*\'' + ',?'
13
+ ) ;
12
14
}
13
15
14
16
// joined array of strings with or without trailing comma
15
17
function makeJoinedArrayRegex ( attr ) {
16
- return attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + ',?' ;
18
+ return makeRegex (
19
+ attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + ',?'
20
+ ) ;
17
21
}
18
22
19
23
// array with or without trailing comma
20
24
function makeArrayRegex ( attr ) {
21
- return attr + ': \\[[\\s\\S]*?\\]' + ',?' ;
25
+ return makeRegex (
26
+ attr + ': \\[[\\s\\S]*?\\]' + ',?'
27
+ ) ;
22
28
}
23
29
24
- // ref: http://www.regexr.com/3cmac
25
- var regexStr = [
26
- makeStringRegex ( 'description' ) ,
27
- makeJoinedArrayRegex ( 'description' ) ,
28
- makeArrayRegex ( 'requiredOpts' ) ,
29
- makeArrayRegex ( 'otherOpts' ) ,
30
- makeStringRegex ( 'hrName' )
31
- ] . join ( '|' ) ;
32
-
33
- var regex = new RegExp ( regexStr , 'g' ) ;
30
+ function makeRegex ( regexStr ) {
31
+ return (
32
+ new RegExp ( regexStr , 'g' )
33
+ ) ;
34
+ }
34
35
35
36
module . exports = function ( ) {
36
- return through ( function ( buf , enc , next ) {
37
+ var allChunks = [ ] ;
38
+ return through ( function ( chunk , enc , next ) {
39
+ allChunks . push ( chunk ) ;
40
+ next ( ) ;
41
+ } , function ( done ) {
42
+ var str = Buffer . concat ( allChunks ) . toString ( 'utf-8' ) ;
37
43
this . push (
38
- buf . toString ( 'utf-8' )
39
- . replace ( regex , '' )
44
+ str
45
+ . replace ( makeStringRegex ( 'description' ) , '' )
46
+ . replace ( makeJoinedArrayRegex ( 'description' ) , '' )
47
+ . replace ( makeArrayRegex ( 'requiredOpts' ) , '' )
48
+ . replace ( makeArrayRegex ( 'otherOpts' ) , '' )
49
+ . replace ( makeStringRegex ( 'hrName' ) , '' )
40
50
) ;
41
- next ( ) ;
51
+ done ( ) ;
42
52
} ) ;
43
53
} ;
0 commit comments