Skip to content

Commit 1781f5a

Browse files
committed
Simplified Stringer.
1 parent be4af52 commit 1781f5a

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

Stringer.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22

33
const {Transform} = require('stream');
44

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-
135
class Stringer extends Transform {
146
static make(options) {
157
return new Stringer(options);
@@ -25,7 +17,7 @@ class Stringer extends Transform {
2517
'useValues' in options && (this._useStringValues = options.useValues);
2618
'useStringValues' in options && (this._useStringValues = options.useStringValues);
2719
this._separator = options.separator || ',';
28-
const sep = this._separator.replace(/[#-.]|[[-^]|[?|{}]/g, '\\$&')
20+
const sep = this._separator.replace(/[#-.]|[[-^]|[?|{}]/g, '\\$&');
2921
this._containsQuotables = new RegExp(this._containsQuotables.source.replace('[,', '[' + sep));
3022
}
3123

@@ -48,7 +40,7 @@ class Stringer extends Transform {
4840
} else {
4941
this.push(this._separator);
5042
}
51-
// intentional fall through
43+
// intentional fall through
5244
case 'endString':
5345
this.push('"');
5446
break;
@@ -85,15 +77,20 @@ class Stringer extends Transform {
8577
}
8678
break;
8779
case 'startString':
88-
this._transform = skipValue('endString');
89-
// case 'stringChunk':
90-
// case 'endString':
80+
this._transform = this._skipString;
9181
break; // skip
9282
default:
9383
return callback(new Error('Unexpected token: ' + chunk.name));
9484
}
9585
callback(null);
9686
}
87+
88+
_skipString(chunk, encoding, callback) {
89+
if (chunk.name === 'endString') {
90+
this._transform = this._valueTransform;
91+
}
92+
callback(null);
93+
}
9794
}
9895
Stringer.stringer = Stringer.make;
9996
Stringer.make.Constructor = Stringer;

0 commit comments

Comments
 (0)