@bablr/helpers 0.15.2 → 0.15.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/source.js +35 -0
- package/package.json +1 -1
package/lib/source.js
CHANGED
|
@@ -171,3 +171,38 @@ export function* fillGapsWith(expressions, stream) {
|
|
|
171
171
|
throw new Error('too many expressions for gaps');
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
+
|
|
175
|
+
const none = Symbol('none');
|
|
176
|
+
|
|
177
|
+
function* __stripTrailingNewline(stream) {
|
|
178
|
+
const iter = getStreamIterator(stream);
|
|
179
|
+
let step = iter.next();
|
|
180
|
+
let lastValue = none;
|
|
181
|
+
|
|
182
|
+
for (;;) {
|
|
183
|
+
if (step instanceof Promise) {
|
|
184
|
+
step = yield step;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// TODO: handle \r\n line endings
|
|
188
|
+
if (step.done && lastValue === '\n') {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (lastValue !== none) {
|
|
193
|
+
yield lastValue;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (step.done) break;
|
|
197
|
+
|
|
198
|
+
lastValue = step.value;
|
|
199
|
+
|
|
200
|
+
step = iter.next();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (lastValue !== none) {
|
|
204
|
+
yield lastValue;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export const stripTrailingNewline = (stream) => new StreamIterable(__stripTrailingNewline(stream));
|