Skip to content

Commit 673a5a3

Browse files
committed
Require Node.js 8
1 parent da81433 commit 673a5a3

4 files changed

Lines changed: 50 additions & 50 deletions

File tree

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ language: node_js
22
node_js:
33
- '10'
44
- '8'
5-
- '6'

index.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ const hook = (stream, options, transform) => {
66
options = {};
77
}
88

9-
options = Object.assign({
9+
options = {
1010
silent: true,
11-
once: false
12-
}, options);
11+
once: false,
12+
...options
13+
};
1314

14-
let unhookFn;
15+
let unhookFunction;
1516

1617
const promise = new Promise(resolve => {
1718
const {write} = stream;
@@ -21,31 +22,31 @@ const hook = (stream, options, transform) => {
2122
resolve();
2223
};
2324

24-
stream.write = (output, enc, cb) => {
25-
const cbRet = transform(String(output), unhook);
25+
stream.write = (output, encoding, callback) => {
26+
const callbackReturnValue = transform(String(output), unhook);
2627

2728
if (options.once) {
2829
unhook();
2930
}
3031

3132
if (options.silent) {
32-
return typeof cbRet === 'boolean' ? cbRet : true;
33+
return typeof callbackReturnValue === 'boolean' ? callbackReturnValue : true;
3334
}
3435

35-
let ret;
36-
if (typeof cbRet === 'string') {
37-
ret = typeof enc === 'string' ? Buffer.from(cbRet).toString(enc) : cbRet;
36+
let returnValue;
37+
if (typeof callbackReturnValue === 'string') {
38+
returnValue = typeof encoding === 'string' ? Buffer.from(callbackReturnValue).toString(encoding) : callbackReturnValue;
3839
}
3940

40-
ret = ret || (Buffer.isBuffer(cbRet) ? cbRet : output);
41+
returnValue = returnValue || (Buffer.isBuffer(callbackReturnValue) ? callbackReturnValue : output);
4142

42-
return write.call(stream, ret, enc, cb);
43+
return write.call(stream, returnValue, encoding, callback);
4344
};
4445

45-
unhookFn = unhook;
46+
unhookFunction = unhook;
4647
});
4748

48-
promise.unhook = unhookFn;
49+
promise.unhook = unhookFunction;
4950

5051
return promise;
5152
};
@@ -64,7 +65,7 @@ const hookStd = (options, transform) => {
6465
return promise;
6566
};
6667

67-
hookStd.stdout = (...args) => hook(process.stdout, ...args);
68-
hookStd.stderr = (...args) => hook(process.stderr, ...args);
68+
hookStd.stdout = (...arguments_) => hook(process.stdout, ...arguments_);
69+
hookStd.stderr = (...arguments_) => hook(process.stderr, ...arguments_);
6970

7071
module.exports = hookStd;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url": "sindresorhus.com"
1111
},
1212
"engines": {
13-
"node": ">=6"
13+
"node": ">=8"
1414
},
1515
"scripts": {
1616
"test": "xo && ava && tsd"

test.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ test.cb('hook stdout & stderr', t => {
2727

2828
let i = 0;
2929

30-
const promise = hookStd(str => {
31-
if (str === 'foo' || str === 'bar') {
30+
const promise = hookStd(string => {
31+
if (string === 'foo' || string === 'bar') {
3232
t.pass();
3333
}
3434

@@ -45,8 +45,8 @@ test.cb('hook stdout & stderr', t => {
4545
test.cb('hook stdout', t => {
4646
t.plan(1);
4747

48-
const promise = hookStd.stdout(str => {
49-
t.is(str, 'foo');
48+
const promise = hookStd.stdout(string => {
49+
t.is(string, 'foo');
5050
promise.unhook();
5151
t.end();
5252
});
@@ -57,8 +57,8 @@ test.cb('hook stdout', t => {
5757
test.cb('hook stderr', t => {
5858
t.plan(1);
5959

60-
const promise = hookStd.stderr(str => {
61-
t.is(str, 'foo');
60+
const promise = hookStd.stderr(string => {
61+
t.is(string, 'foo');
6262
promise.unhook();
6363
t.end();
6464
});
@@ -72,8 +72,8 @@ test.cb('hook custom stream', t => {
7272

7373
let i = 0;
7474

75-
const promise = hookStd({streams}, str => {
76-
if (str === 'foo') {
75+
const promise = hookStd({streams}, string => {
76+
if (string === 'foo') {
7777
t.pass();
7878
}
7979

@@ -86,15 +86,15 @@ test.cb('hook custom stream', t => {
8686
streams[0].write('foo');
8787
});
8888

89-
function loggingWrite(log, retVal) {
89+
function loggingWrite(log, returnValueValue) {
9090
return (...items) => {
9191
while (items[items.length - 1] === undefined) {
9292
items.pop();
9393
}
9494

9595
log.push(items);
9696

97-
return retVal();
97+
return returnValueValue();
9898
};
9999
}
100100

@@ -108,7 +108,7 @@ test('passes through the return value of the underlying write call', t => {
108108
write: loggingWrite(log, () => returnValue)
109109
};
110110

111-
hookStd.stdout({silent: false}, str => str);
111+
hookStd.stdout({silent: false}, string => string);
112112

113113
t.false(process.stdout.write('foo'));
114114
returnValue = true;
@@ -124,9 +124,9 @@ test('if silent, returns true by default', t => {
124124
write: () => t.fail()
125125
};
126126

127-
hookStd.stdout(str => {
128-
log.push(str);
129-
return str;
127+
hookStd.stdout(string => {
128+
log.push(string);
129+
return string;
130130
});
131131

132132
t.true(process.stdout.write('foo'));
@@ -142,8 +142,8 @@ test('if silent, callback can return a boolean', t => {
142142
write: () => t.fail()
143143
};
144144

145-
hookStd.stdout(str => {
146-
log.push(str);
145+
hookStd.stdout(string => {
146+
log.push(string);
147147
return returnValue;
148148
});
149149

@@ -161,7 +161,7 @@ test('callback can return a buffer', t => {
161161
write: loggingWrite(log, () => true)
162162
};
163163

164-
hookStd.stdout({silent: false}, str => Buffer.from(str));
164+
hookStd.stdout({silent: false}, string => Buffer.from(string));
165165

166166
t.true(process.stdout.write('foo'));
167167
t.true(process.stdout.write('bar'));
@@ -177,7 +177,7 @@ test('if no options are assigned, behave as silent', t => {
177177
write: loggingWrite(log, () => returnValue)
178178
};
179179

180-
hookStd.stdout(str => str);
180+
hookStd.stdout(string => string);
181181

182182
process.stdout.write('foo');
183183
returnValue = true;
@@ -193,7 +193,7 @@ test('if once option is true, only the first write is silent', t => {
193193
write: loggingWrite(log, () => returnValue)
194194
};
195195

196-
hookStd.stdout({once: true}, str => str);
196+
hookStd.stdout({once: true}, string => string);
197197

198198
process.stdout.write('foo');
199199
process.stdout.write('bar');
@@ -211,9 +211,9 @@ test('if once option is true and silent is false, hook only prints the first wri
211211
write: loggingWrite(log, () => true)
212212
};
213213

214-
hookStd.stdout({silent: false, once: true}, str => {
215-
hookReturnValue = str;
216-
return str;
214+
hookStd.stdout({silent: false, once: true}, string => {
215+
hookReturnValue = string;
216+
return string;
217217
});
218218

219219
process.stdout.write('foo');
@@ -231,7 +231,7 @@ test('output is converted to string', t => {
231231
t.plan(4);
232232
const log = [];
233233

234-
hookStd.stdout(str => log.push(str));
234+
hookStd.stdout(string => log.push(string));
235235

236236
process.stdout.write('foo');
237237
t.deepEqual(log, ['foo']);
@@ -278,7 +278,7 @@ test('promise resolves when stdout & stderr are hooked and released via promise
278278
t.plan(1);
279279
const log = [];
280280

281-
const promise = hookStd(str => log.push(str));
281+
const promise = hookStd(string => log.push(string));
282282

283283
process.stdout.write('foo');
284284
process.stderr.write('bar');
@@ -292,8 +292,8 @@ test('promise resolves when stdout & stderr are hooked and released via callback
292292
t.plan(1);
293293
const log = [];
294294

295-
const promise = hookStd((str, unhook) => {
296-
log.push(str);
295+
const promise = hookStd((string, unhook) => {
296+
log.push(string);
297297
unhook();
298298
});
299299

@@ -306,8 +306,8 @@ test('promise resolves when stdout & stderr are hooked and released via callback
306306

307307
test('promise resolves when stdout is released via promise unhook method', async t => {
308308
t.plan(1);
309-
const promise = hookStd.stdout(str => {
310-
t.is(str, 'foo');
309+
const promise = hookStd.stdout(string => {
310+
t.is(string, 'foo');
311311
});
312312
process.stdout.write('foo');
313313
promise.unhook();
@@ -316,8 +316,8 @@ test('promise resolves when stdout is released via promise unhook method', async
316316

317317
test('promise resolves when stderr is released via promise unhook method', async t => {
318318
t.plan(1);
319-
const promise = hookStd.stderr(str => {
320-
t.is(str, 'foo');
319+
const promise = hookStd.stderr(string => {
320+
t.is(string, 'foo');
321321
});
322322
process.stderr.write('foo');
323323
promise.unhook();
@@ -329,8 +329,8 @@ test('promise resolves when streams are hooked and released via callback', async
329329
const log = [];
330330
const streams = [{write: () => {}}, {write: () => {}}];
331331

332-
const promise = hookStd({streams}, (str, unhook) => {
333-
log.push(str);
332+
const promise = hookStd({streams}, (string, unhook) => {
333+
log.push(string);
334334
unhook();
335335
});
336336

0 commit comments

Comments
 (0)