2 * Convert an array-like object into an `Array`.
3 * If `collection` is already an `Array`, then will return a clone of `collection`.
5 * @param {Array | Mixed} collection An `Array` or array-like object to convert e.g. `arguments` or `NodeList`
6 * @return {Array} Naive conversion of `collection` to a new `Array`.
10 module.exports = function toArray(collection) {
11 if (typeof collection === 'undefined') return []
12 if (collection === null) return [null]
13 if (collection === window) return [window]
14 if (typeof collection === 'string') return [collection]
15 if (Array.isArray(collection)) return collection.slice()
16 if (typeof collection.length != 'number') return [collection]
17 if (typeof collection === 'function') return [collection]
20 for (var i = 0; i < collection.length; i++) {
21 if (collection.hasOwnProperty(i) || i in collection) {
22 arr.push(collection[i])
25 if (!arr.length) return []