Add readable, writable and duplex
This commit is contained in:
10
test/isDuplexStream/isDuplexStream.js
Normal file
10
test/isDuplexStream/isDuplexStream.js
Normal file
@ -0,0 +1,10 @@
|
||||
const isDuplexStream = val =>
|
||||
val !== null &&
|
||||
typeof val === 'object' &&
|
||||
typeof val.pipe === 'function' &&
|
||||
typeof val.pipe === 'function' &&
|
||||
typeof val._read === 'function' &&
|
||||
typeof val._readableState === 'object' &&
|
||||
typeof val._write === 'function' &&
|
||||
typeof val._writableState === 'object';
|
||||
module.exports = isDuplexStream;
|
||||
20
test/isDuplexStream/isDuplexStream.test.js
Normal file
20
test/isDuplexStream/isDuplexStream.test.js
Normal file
@ -0,0 +1,20 @@
|
||||
const expect = require('expect');
|
||||
const isDuplexStream = require('./isDuplexStream.js');
|
||||
const fs = require('fs');
|
||||
const Stream = require('stream');
|
||||
|
||||
test('isDuplexStream is a Function', () => {
|
||||
expect(isDuplexStream).toBeInstanceOf(Function);
|
||||
});
|
||||
test('isDuplexStream returns true for read streams', () => {
|
||||
expect(isDuplexStream(fs.createReadStream('isDuplexStream.js'))).toBeTruthy();
|
||||
});
|
||||
test('isDuplexStream returns true for write streams', () => {
|
||||
expect(isDuplexStream(fs.createWriteStream('isDuplexStream.js'))).toBeTruthy();
|
||||
});
|
||||
test('isDuplexStream returns true for duplex streams', () => {
|
||||
expect(isDuplexStream(new Stream.Duplex())).toBeTruthy();
|
||||
});
|
||||
test('isDuplexStream returns false for non-streams', () => {
|
||||
expect(isDuplexStream({})).toBeFalsy();
|
||||
});
|
||||
7
test/isReadableStream/isReadableStream.js
Normal file
7
test/isReadableStream/isReadableStream.js
Normal file
@ -0,0 +1,7 @@
|
||||
const isReadableStream = val =>
|
||||
val !== null &&
|
||||
typeof val === 'object' &&
|
||||
typeof val.pipe === 'function' &&
|
||||
typeof val._read === 'function' &&
|
||||
typeof val._readableState === 'object';
|
||||
module.exports = isReadableStream;
|
||||
20
test/isReadableStream/isReadableStream.test.js
Normal file
20
test/isReadableStream/isReadableStream.test.js
Normal file
@ -0,0 +1,20 @@
|
||||
const expect = require('expect');
|
||||
const isReadableStream = require('./isReadableStream.js');
|
||||
const fs = require('fs');
|
||||
const Stream = require('stream');
|
||||
|
||||
test('isReadableStream is a Function', () => {
|
||||
expect(isReadableStream).toBeInstanceOf(Function);
|
||||
});
|
||||
test('isReadableStream returns true for read streams', () => {
|
||||
expect(isReadableStream(fs.createReadStream('isReadableStream.js'))).toBeTruthy();
|
||||
});
|
||||
test('isReadableStream returns false for write streams', () => {
|
||||
expect(isReadableStream(fs.createWriteStream('isReadableStream.js'))).toBeFalsy();
|
||||
});
|
||||
test('isReadableStream returns true for duplex streams', () => {
|
||||
expect(isReadableStream(new Stream.Duplex())).toBeTruthy();
|
||||
});
|
||||
test('isReadableStream returns false for non-streams', () => {
|
||||
expect(isReadableStream({})).toBeFalsy();
|
||||
});
|
||||
@ -1,13 +1,20 @@
|
||||
const expect = require('expect');
|
||||
const isStream = require('./isStream.js');
|
||||
const fs = require('fs');
|
||||
const Stream = require('stream');
|
||||
|
||||
test('isStream is a Function', () => {
|
||||
expect(isStream).toBeInstanceOf(Function);
|
||||
});
|
||||
test('isStream returns true for streams', () => {
|
||||
test('isStream returns true for read streams', () => {
|
||||
expect(isStream(fs.createReadStream('isStream.js'))).toBeTruthy();
|
||||
});
|
||||
test('isStream returns true for write streams', () => {
|
||||
expect(isStream(fs.createWriteStream('isStream.js'))).toBeTruthy();
|
||||
});
|
||||
test('isStream returns true for duplex streams', () => {
|
||||
expect(isStream(new Stream.Duplex())).toBeTruthy();
|
||||
});
|
||||
test('isStream returns false for non-streams', () => {
|
||||
expect(isStream({})).toBeFalsy();
|
||||
});
|
||||
|
||||
7
test/isWritableStream/isWritableStream.js
Normal file
7
test/isWritableStream/isWritableStream.js
Normal file
@ -0,0 +1,7 @@
|
||||
const isWritableStream = val =>
|
||||
val !== null &&
|
||||
typeof val === 'object' &&
|
||||
typeof val.pipe === 'function' &&
|
||||
typeof val._write === 'function' &&
|
||||
typeof val._writableState === 'object';
|
||||
module.exports = isWritableStream;
|
||||
20
test/isWritableStream/isWritableStream.test.js
Normal file
20
test/isWritableStream/isWritableStream.test.js
Normal file
@ -0,0 +1,20 @@
|
||||
const expect = require('expect');
|
||||
const isWritableStream = require('./isWritableStream.js');
|
||||
const fs = require('fs');
|
||||
const Stream = require('stream');
|
||||
|
||||
test('isWritableStream is a Function', () => {
|
||||
expect(isWritableStream).toBeInstanceOf(Function);
|
||||
});
|
||||
test('isWritableStream returns false for read streams', () => {
|
||||
expect(isWritableStream(fs.createReadStream('isWritableStream.js'))).toBeFalsy();
|
||||
});
|
||||
test('isWritableStream returns true for write streams', () => {
|
||||
expect(isWritableStream(fs.createWriteStream('isWritableStream.js'))).toBeTruthy();
|
||||
});
|
||||
test('isWritableStream returns true for duplex streams', () => {
|
||||
expect(isWritableStream(new Stream.Duplex())).toBeTruthy();
|
||||
});
|
||||
test('isWritableStream returns false for non-streams', () => {
|
||||
expect(isWritableStream({})).toBeFalsy();
|
||||
});
|
||||
@ -1,2 +1,3 @@
|
||||
const takeRightWhile = (arr, func) => arr.reduceRight((acc, el) => func(el) ? acc : [el, ...acc], []);
|
||||
const takeRightWhile = (arr, func) =>
|
||||
arr.reduceRight((acc, el) => (func(el) ? acc : [el, ...acc]), []);
|
||||
module.exports = takeRightWhile;
|
||||
|
||||
Reference in New Issue
Block a user