README.md (2230B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # Stream-like 22 23 > Test if a value is Node [stream][nodejs-stream]-like. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isNodeStreamLike = require( '@stdlib/assert/is-node-stream-like' ); 31 ``` 32 33 #### isNodeStreamLike( value ) 34 35 Tests if a `value` is Node [stream][nodejs-stream]-like. 36 37 ```javascript 38 var transformStream = require( '@stdlib/streams/node/transform' ); 39 40 var bool = isNodeStreamLike( transformStream() ); 41 // returns true 42 ``` 43 44 </section> 45 46 <!-- /.usage --> 47 48 <section class="notes"> 49 50 </section> 51 52 <!-- /.notes --> 53 54 <section class="examples"> 55 56 ## Examples 57 58 <!-- eslint no-undef: "error" --> 59 60 ```javascript 61 var stream = require( 'stream' ); 62 var transformStream = require( '@stdlib/streams/node/transform' ); 63 var isNodeStreamLike = require( '@stdlib/assert/is-node-stream-like' ); 64 65 var bool = isNodeStreamLike( new stream.Stream() ); 66 // returns true 67 68 bool = isNodeStreamLike( new stream.Readable() ); 69 // returns true 70 71 bool = isNodeStreamLike( new stream.Writable() ); 72 // returns true 73 74 bool = isNodeStreamLike( new stream.Duplex() ); 75 // returns true 76 77 bool = isNodeStreamLike( new stream.Transform() ); 78 // returns true 79 80 bool = isNodeStreamLike( transformStream() ); 81 // returns true 82 83 bool = isNodeStreamLike( {} ); 84 // returns false 85 86 bool = isNodeStreamLike( [] ); 87 // returns false 88 89 bool = isNodeStreamLike( null ); 90 // returns false 91 92 function Stream() { 93 return this; 94 } 95 96 bool = isNodeStreamLike( Stream ); 97 // returns false 98 99 bool = isNodeStreamLike( new Stream() ); 100 // returns false 101 ``` 102 103 </section> 104 105 <!-- /.examples --> 106 107 <section class="links"> 108 109 [nodejs-stream]: https://nodejs.org/api/stream.html 110 111 </section> 112 113 <!-- /.links -->