2
2
3
3
const { Transform} = require ( 'stream' ) ;
4
4
5
- const skipValue = endName =>
6
- function ( chunk , encoding , callback ) {
7
- if ( chunk . name === endName ) {
8
- this . _transform = this . _valueTransform ;
9
- }
10
- callback ( null ) ;
11
- } ;
12
-
13
5
class Stringer extends Transform {
14
6
static make ( options ) {
15
7
return new Stringer ( options ) ;
@@ -25,7 +17,7 @@ class Stringer extends Transform {
25
17
'useValues' in options && ( this . _useStringValues = options . useValues ) ;
26
18
'useStringValues' in options && ( this . _useStringValues = options . useStringValues ) ;
27
19
this . _separator = options . separator || ',' ;
28
- const sep = this . _separator . replace ( / [ # - . ] | [ [ - ^ ] | [ ? | { } ] / g, '\\$&' )
20
+ const sep = this . _separator . replace ( / [ # - . ] | [ [ - ^ ] | [ ? | { } ] / g, '\\$&' ) ;
29
21
this . _containsQuotables = new RegExp ( this . _containsQuotables . source . replace ( '[,' , '[' + sep ) ) ;
30
22
}
31
23
@@ -48,7 +40,7 @@ class Stringer extends Transform {
48
40
} else {
49
41
this . push ( this . _separator ) ;
50
42
}
51
- // intentional fall through
43
+ // intentional fall through
52
44
case 'endString' :
53
45
this . push ( '"' ) ;
54
46
break ;
@@ -85,15 +77,20 @@ class Stringer extends Transform {
85
77
}
86
78
break ;
87
79
case 'startString' :
88
- this . _transform = skipValue ( 'endString' ) ;
89
- // case 'stringChunk':
90
- // case 'endString':
80
+ this . _transform = this . _skipString ;
91
81
break ; // skip
92
82
default :
93
83
return callback ( new Error ( 'Unexpected token: ' + chunk . name ) ) ;
94
84
}
95
85
callback ( null ) ;
96
86
}
87
+
88
+ _skipString ( chunk , encoding , callback ) {
89
+ if ( chunk . name === 'endString' ) {
90
+ this . _transform = this . _valueTransform ;
91
+ }
92
+ callback ( null ) ;
93
+ }
97
94
}
98
95
Stringer . stringer = Stringer . make ;
99
96
Stringer . make . Constructor = Stringer ;
0 commit comments