Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / socket.io-client / components / timoxley-to-array / index.js
1 /**
2  * Convert an array-like object into an `Array`.
3  * If `collection` is already an `Array`, then will return a clone of `collection`.
4  *
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`.
7  * @api private
8  */
9
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]
18
19   var arr = []
20   for (var i = 0; i < collection.length; i++) {
21     if (collection.hasOwnProperty(i) || i in collection) {
22       arr.push(collection[i])
23     }
24   }
25   if (!arr.length) return []
26   return arr
27 }