/* eslint-disable brace-style */
import toPairs from '../../array/pairs/toPairs'
// check
import { isString } from '../../primitive/string/isString'
import { isIterator } from '../../iterator/check/isIterator'
import { isMap, isSet } from '../../collection'
import { isArguments } from '../../NATIVE/builtin/isArguments'
import { isObj } from '../../obj/check/isObj'
// local
import isArray from '../check/isArray'
import isArrayLike from '../check/isArrayLike'
import toArr from './toArr'
import fromArgumentsToArray from './fromArgumentsToArray'
import fromMapToArray from './fromMapToArray'
import fromSetToArray from './fromSetToArray'
import fromStringToArray from './fromStringToArray'
import fromIteratorToArray from './fromIteratorToArray'
// eslint-disable-next-line
function toArray<Type extends any = any>(x: Type): Array<Type | Type[]> {
if (arguments.length > 1) {
return fromArgumentsToArray.apply(undefined, arguments)
} else if (isArray(x)) {
return x
} else if (isArguments(x)) {
return fromArgumentsToArray(x)
} else if (isArrayLike(x)) {
return Array.from(x)
// return isTrue(false) ? Array.from(x) : x
} else if (isString(x)) {
return fromStringToArray(x)
} else if (isIterator(x)) {
return fromIteratorToArray(x)
} else if (isMap(x)) {
return fromMapToArray(x)
} else if (isSet(x)) {
return fromSetToArray(x)
} else if (isObj(x)) {
return toPairs(x)
} else {
return toArr(x)
}
}
export { toArray }
export default toArray