'use strict';

// MODULES //

var isObject = require( '@stdlib/utils/is-object' ); // TODO: is-plain-object
var copy = require( '@stdlib/utils/copy' );
var Stream = require( './stream.js' );


// FACTORY //

/**
* Creates a reusable debug stream factory.
*
* @param {Options} [options] - stream options
* @param {boolean} [options.objectMode=false] - specifies whether the stream should operate in object mode
* @param {NonNegativeNumber} [options.highWaterMark] - specifies the `Buffer` level for when `write()` starts returning `false`
* @param {boolean} [options.allowHalfOpen=false] - specifies whether the stream should remain open even if one side ends
* @param {boolean} [options.readableObjectMode=false] - specifies whether the readable side should be in object mode
* @returns {Function} debug stream factory
*
* @example
* var opts = {
*     'objectMode': true,
*     'highWaterMark': 64
* };
*
* var factory = streamFactory( opts );
*
* // Assign each stream to a separate debug namespace...
* var streams = [];
* var i;
* for ( i = 0; i < 10; i++ ) {
*     streams.push( factory( 'stream '+i ) );
* }
*/
function streamFactory( options ) {
	var opts;
	if ( arguments.length ) {
		if ( !isObject( options ) ) {
			throw new TypeError( 'invalid input argument. `options` argument must be a plain object. Value: `' + options + '`.' );
		}
		opts = copy( options );
	} else {
		opts = {};
	}
	/**
	* Creates a transform stream for debugging stream pipelines.
	*
	* @private
	* @param {string} name - debug namespace
	* @param {Callback} [clbk] - callback to invoke upon receiving data
	* @throws {TypeError} must provide valid options
	* @throws {TypeError} must provide a valid callback argument
	* @returns {DebugStream} debug stream
	*/
	return function debugStream( name, clbk ) {
		opts.name = name;
		if ( arguments.length > 1 ) {
			return new Stream( opts, clbk );
		}
		return new Stream( opts );
	};
} // end FUNCTION streamFactory()


// EXPORTS //

module.exports = streamFactory;

'use strict';

// MODULES //

var isObject = require( '@stdlib/utils/is-plain-object' );
var copy = require( '@stdlib/utils/copy' );
var Stream = require( './stream.js' );


// FACTORY //

/**
* Creates a reusable debug stream factory.
*
* @param {Options} [options] - stream options
* @param {boolean} [options.objectMode=false] - specifies whether the stream should operate in object mode
* @param {NonNegativeNumber} [options.highWaterMark] - specifies the `Buffer` level for when `write()` starts returning `false`
* @param {boolean} [options.allowHalfOpen=false] - specifies whether the stream should remain open even if one side ends
* @param {boolean} [options.readableObjectMode=false] - specifies whether the readable side should be in object mode
* @returns {Function} debug stream factory
*
* @example
* var opts = {
*     'objectMode': true,
*     'highWaterMark': 64
* };
*
* var factory = streamFactory( opts );
*
* // Assign each stream to a separate debug namespace...
* var streams = [];
* var i;
* for ( i = 0; i < 10; i++ ) {
*     streams.push( factory( 'stream '+i ) );
* }
*/
function streamFactory( options ) {
	var opts;
	if ( arguments.length ) {
		if ( !isObject( options ) ) {
			throw new TypeError( 'invalid input argument. `options` argument must be a plain object. Value: `' + options + '`.' );
		}
		opts = copy( options );
	} else {
		opts = {};
	}
	/**
	* Creates a transform stream for debugging stream pipelines.
	*
	* @private
	* @param {string} name - debug namespace
	* @param {Callback} [clbk] - callback to invoke upon receiving data
	* @throws {TypeError} must provide valid options
	* @throws {TypeError} must provide a valid callback argument
	* @returns {DebugStream} debug stream
	*/
	return function debugStream( name, clbk ) {
		opts.name = name;
		if ( arguments.length > 1 ) {
			return new Stream( opts, clbk );
		}
		return new Stream( opts );
	};
} // end FUNCTION streamFactory()


// EXPORTS //

module.exports = streamFactory;

Use utility to test if a value is a plain object