Skip to content

Commit

Permalink
Add shared/is-iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
caiogondim committed Sep 6, 2020
1 parent 04e6cbe commit e9d16fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/_shared/is-iterable/index.js
@@ -1,8 +1,8 @@
function isIterable(obj) {
if (!obj) {
return false;
return false
}
return typeof obj[Symbol.iterator] === 'function';
return typeof obj[Symbol.iterator] === 'function'
}

module.exports = isIterable
14 changes: 9 additions & 5 deletions src/_shared/is-iterable/test.js
Expand Up @@ -4,10 +4,14 @@ it('returns true for iterable objects', () => {
expect(isIterable([1, 2])).toBe(true)
expect(isIterable(new Set([1, 2]))).toBe(true)
expect(isIterable(new Set([1, 2]))).toBe(true)
expect(isIterable({ *[Symbol.iterator]() {
yield 1;
yield 2;
}})).toBe(true)
expect(
isIterable({
*[Symbol.iterator]() {
yield 1
yield 2
},
})
).toBe(true)
})

it('returns false for non-iterable objects', () => {
Expand All @@ -18,4 +22,4 @@ it('returns false for non-iterable objects', () => {
expect(isIterable(undefined)).toBe(false)
expect(isIterable(false)).toBe(false)
expect(isIterable(true)).toBe(false)
})
})

0 comments on commit e9d16fc

Please sign in to comment.