https://github.com/lamansky/is-iterator
[Node.js] Returns true if an object is an iterator.
https://github.com/lamansky/is-iterator
Last synced: 3 months ago
JSON representation
[Node.js] Returns true if an object is an iterator.
- Host: GitHub
- URL: https://github.com/lamansky/is-iterator
- Owner: lamansky
- License: mit
- Created: 2017-12-21T12:53:47.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-21T13:45:44.000Z (over 8 years ago)
- Last Synced: 2025-03-23T10:19:48.502Z (over 1 year ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# is-iterator
Returns true if an object is an iterator.
Remember that iterators are not the same thing as iterables! This module only checks for the former.
The ECMAScript standard [defines an iterator](https://tc39.github.io/ecma262/#sec-iterator-interface) to be an object with a `next()` method. To avoid false-positives from objects with `next()` methods, this module additionally checks to make sure that the iterator is an iterable that points to itself, since this is a characteristic of built-in iterators.
## Installation
```bash
npm install is-iterator --save
```
## Usage Example
```javascript
const isIterator = require('is-iterator')
const array = [] // An array is an iterable, but not by itself an iterator
isIterator(array) // false
isIterator(array[Symbol.iterator]()) // true
```