README.md (2431B)
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 # isIterableLike 22 23 > Test if a value is [`iterable`][mdn-iterable-protocol]-like. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isIterableLike = require( '@stdlib/assert/is-iterable-like' ); 31 ``` 32 33 #### isIterableLike( value ) 34 35 Tests if a `value` is [`iterable`][mdn-iterator-protocol]-like. 36 37 ```javascript 38 var bool = isIterableLike( [] ); 39 // returns <boolean> 40 41 bool = isIterableLike( {} ); 42 // returns false 43 ``` 44 45 </section> 46 47 <!-- /.usage --> 48 49 <section class="notes"> 50 51 ## Notes 52 53 - In order to be [iterable][mdn-iterable-protocol], an `object` must implement the `@@iterator` method, which, when called, returns an [iterator protocol-compliant object][mdn-iterator-protocol]. 54 - An [iterator protocol-compliant object][mdn-iterator-protocol] is an `object` having a `next` method following the [iterator protocol][mdn-iterator-protocol]. 55 - As full [iterator][mdn-iterator-protocol] compliance is **impossible** to achieve without evaluating an [iterator][mdn-iterator-protocol], this function checks **only** for interface compliance. 56 - In environments lacking `Symbol.iterator` support, this function always returns `false`. 57 58 </section> 59 60 <!-- /.notes --> 61 62 <section class="examples"> 63 64 ## Examples 65 66 <!-- eslint no-undef: "error" --> 67 68 ```javascript 69 var isIterableLike = require( '@stdlib/assert/is-iterable-like' ); 70 71 var bool = isIterableLike( [] ); 72 // returns <boolean> 73 74 bool = isIterableLike( {} ); 75 // returns false 76 77 bool = isIterableLike( null ); 78 // returns false 79 ``` 80 81 </section> 82 83 <!-- /.examples --> 84 85 <section class="links"> 86 87 [mdn-iterable-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol 88 89 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol 90 91 </section> 92 93 <!-- /.links -->