time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

main.js (1639B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 // MAIN //
     22 
     23 /**
     24 * Tests if a value is Node stream-like.
     25 *
     26 * @param {*} value - value to test
     27 * @returns {boolean} boolean indicating if a value is Node stream-like
     28 *
     29 * @example
     30 * var transformStream = require( '@stdlib/streams/node/transform' );
     31 *
     32 * var stream = transformStream();
     33 *
     34 * var bool = isNodeStreamLike( stream );
     35 * // returns true
     36 *
     37 * bool = isNodeStreamLike( {} );
     38 * // returns false
     39 */
     40 function isNodeStreamLike( value ) {
     41 	return (
     42 		// Must be an object:
     43 		value !== null &&
     44 		typeof value === 'object' &&
     45 
     46 		// Should be an event emitter:
     47 		typeof value.on === 'function' &&
     48 		typeof value.once === 'function' &&
     49 		typeof value.emit === 'function' &&
     50 		typeof value.addListener === 'function' &&
     51 		typeof value.removeListener === 'function' &&
     52 		typeof value.removeAllListeners === 'function' &&
     53 
     54 		// Should have a `pipe` method (Node streams inherit from `Stream`, including writable streams):
     55 		typeof value.pipe === 'function'
     56 	);
     57 }
     58 
     59 
     60 // EXPORTS //
     61 
     62 module.exports = isNodeStreamLike;