@@ -8,37 +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
37
var allChunks = [ ] ;
37
38
return through ( function ( chunk , enc , next ) {
38
39
allChunks . push ( chunk ) ;
39
40
next ( ) ;
40
41
} , function ( done ) {
41
- this . push ( Buffer . concat ( allChunks ) . toString ( ) . replace ( regex , '' ) ) ;
42
+ var str = Buffer . concat ( allChunks ) . toString ( 'utf-8' ) ;
43
+ this . push (
44
+ str
45
+ . replace ( makeStringRegex ( 'description' ) , '' )
46
+ . replace ( makeJoinedArrayRegex ( 'description' ) , '' )
47
+ . replace ( makeArrayRegex ( 'requiredOpts' ) , '' )
48
+ . replace ( makeArrayRegex ( 'otherOpts' ) , '' )
49
+ . replace ( makeStringRegex ( 'hrName' ) , '' )
50
+ ) ;
42
51
done ( ) ;
43
52
} ) ;
44
53
} ;
0 commit comments