bianco.is-iterable

Function returning true if an object could be looped


Keywords
es6, es2015, loops, iterable, for-of
License
MIT
Install
npm install bianco.is-iterable@0.0.3

Documentation

bianco.is-iterable

Build Status

NPM version NPM downloads MIT License

Usage

import isIterable from 'bianco.is-iterable'

// An array should be iterable
const arr = [1, 2, 3]
isIterable(arr) // => true of course

// A generator should be iterable
const gen = (function *() {
  yield Math.random()
})()
isIterable(gen) // => true

// A DOM nodes list should be iterable
const lis = document.querySelectorAll('li')
isIterable(lis)  // => depends on the browser

// An object should not be iterable
const obj = { foo: 'foo', bar: 'bar' }
isIterable(obj) // => false

API

  • isIterable returns true if the object could be looped in a "for of" otherwise false