diff --git a/index.js b/index.js index 750465b..3ee9179 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ module.exports = function toArray(collection) { if (collection === window) return [window] if (typeof collection === 'string') return [collection] if (Array.isArray(collection)) return collection.slice() - if (collection !== null && !collection.length) return [collection] + if (typeof collection.length != 'number') return [collection] if (typeof collection === 'function') return [collection] var arr = [] for (var i = 0; i < collection.length; i++) { diff --git a/test/to-array.js b/test/to-array.js index d1b50a5..ca58403 100644 --- a/test/to-array.js +++ b/test/to-array.js @@ -35,6 +35,9 @@ describe('non-collections', function() { it('single element is empty for undefined', function() { assert.deepEqual([], toArray(undefined)); }) + it('detects `{length: true}` is not a collection', function() { + assert.deepEqual([{length: true}], toArray({length: true})); + }) }) describe('identifying collections', function() {