@@ -8,37 +8,46 @@ var through = require('through2');
88
99// one line string with or without trailing comma
1010function makeStringRegex ( attr ) {
11- return attr + ': \'.*\'' + ',?' ;
11+ return makeRegex (
12+ attr + ': \'.*\'' + ',?'
13+ ) ;
1214}
1315
1416// joined array of strings with or without trailing comma
1517function makeJoinedArrayRegex ( attr ) {
16- return attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + ',?' ;
18+ return makeRegex (
19+ attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + ',?'
20+ ) ;
1721}
1822
1923// array with or without trailing comma
2024function makeArrayRegex ( attr ) {
21- return attr + ': \\[[\\s\\S]*?\\]' + ',?' ;
25+ return makeRegex (
26+ attr + ': \\[[\\s\\S]*?\\]' + ',?'
27+ ) ;
2228}
2329
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+ }
3435
3536module . exports = function ( ) {
3637 var allChunks = [ ] ;
3738 return through ( function ( chunk , enc , next ) {
3839 allChunks . push ( chunk ) ;
3940 next ( ) ;
4041 } , 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+ ) ;
4251 done ( ) ;
4352 } ) ;
4453} ;
0 commit comments