0.0.3 • Published 7 years ago
bianco.is-iterable v0.0.3
bianco.is-iterable
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
returnstrue
if the object could be looped in a "for of" otherwisefalse