File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,12 @@ module.exports = Stringify
16
16
function Stringify ( options ) {
17
17
if ( ! ( this instanceof Stringify ) )
18
18
return new Stringify ( options || { } )
19
-
19
+ if ( options && options . replacer ) {
20
+ this . replacer = options . replacer ;
21
+ }
22
+ if ( options && options . space !== undefined ) {
23
+ this . space = options . space ;
24
+ }
20
25
Transform . call ( this , options || { } )
21
26
this . _writableState . objectMode = true
22
27
}
Original file line number Diff line number Diff line change @@ -105,4 +105,55 @@ describe('Streamify()', function () {
105
105
106
106
stream . end ( obj )
107
107
} )
108
+ it ( 'should allow a space argument to JSON.stringify()' , function ( done ) {
109
+ var stream = new PassThrough ( {
110
+ objectMode : true
111
+ } )
112
+
113
+ var stringify = Stringify ( { space :2 } )
114
+
115
+ var obj = {
116
+ a : 1
117
+ }
118
+
119
+ stream
120
+ . pipe ( stringify )
121
+ . pipe ( cat ( function ( err , buf ) {
122
+ assert . ifError ( err )
123
+ assert . equal ( buf . toString ( 'utf8' ) , '[\n' + JSON . stringify ( obj , null , 2 ) + '\n]\n' )
124
+
125
+ done ( )
126
+ } ) )
127
+
128
+ stream . end ( obj )
129
+ } )
130
+
131
+ it ( 'should allow a space argument to JSON.stringify()' , function ( done ) {
132
+ var stream = new PassThrough ( {
133
+ objectMode : true
134
+ } )
135
+
136
+ var replacer = function ( key , value ) {
137
+ if ( key === 'a' ) return undefined
138
+ return value
139
+ }
140
+
141
+ var stringify = Stringify ( { replacer :replacer } )
142
+
143
+ var obj = {
144
+ a : 1
145
+ }
146
+
147
+ stream
148
+ . pipe ( stringify )
149
+ . pipe ( cat ( function ( err , buf ) {
150
+ assert . ifError ( err )
151
+ assert . equal ( buf . toString ( 'utf8' ) , '[\n' + JSON . stringify ( { } , null , 2 ) + '\n]\n' )
152
+
153
+ done ( )
154
+ } ) )
155
+
156
+ stream . end ( obj )
157
+ } )
158
+
108
159
} )
You can’t perform that action at this time.
0 commit comments