How to use the is-stream.stdio function in is-stream

To help you get started, we’ve selected a few is-stream examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github catdad / grandma / lib / is-stream.js View on Github external
var isStream = require('is-stream');

function assertType(type) {
    if (type !== 'readable' && type !== 'writable') {
        throw new Error(type + ' is not a known stream type');
    }
}

function assertObjectMode(stream, state, errStr) {
    if (!stream[state] || !stream[state].objectMode) {
        throw new TypeError(errStr);
    }
}

isStream.stdio = function isStdio(stream) {
    return stream === process.stdin ||
           stream === process.stdout ||
           stream === process.stderr;
};

isStream.assertStream = function assertStream(stream, type, errStr) {
    assertType(type);

    // When redirecting to a file, for some reason, this is not
    // detected as a writable stream, even though it is.
    //
    //   `grandma run testname -d 2ms -c 1 > file.log`
    //
    // So we are just going to manually make this pass...
    //
    // https://github.com/nodejs/node/issues/8828

is-stream

Check if something is a Node.js stream

MIT
Latest version published 2 months ago

Package Health Score

83 / 100
Full package analysis