/**
* Source: https://github.com/timoxley/to-array
*
* Convert an array-like object into an `Array`.
* If `collection` is already an `Array`, then will return a clone of `collection`.
*
* @param {Array | Mixed} collection An `Array` or array-like object to convert e.g. `arguments` or `NodeList`
* @return {Array} Naive conversion of `collection` to a new `Array`.
* @api public
*/
module.exports = function toArray(collection) {
Iif (typeof collection === 'undefined') return [];
Iif (collection === null) return [null];
Iif (collection === window) return [window];
Iif (typeof collection === 'string') return [collection];
Iif (isArray(collection)) return collection;
if (typeof collection.length != 'number') return [collection];
Iif (typeof collection === 'function' && collection instanceof Function) return [collection];
var arr = [];
for (var i = 0; i < collection.length; i++) {
Eif (Object.prototype.hasOwnProperty.call(collection, i) || i in collection) {
arr.push(collection[i]);
}
}
if (!arr.length) return [];
return arr;
};
function isArray(arr) {
return Object.prototype.toString.call(arr) === "[object Array]";
}
|