import { zip, FlatArrayPairs } from '../../../deps'
import { isReal } from '../../primitive/nil'
import { isPairs } from '../../array/pairs/isPairs'
import isObj from '../../obj/check/isObj'
/* prettier-ignore */
function toFlatPairs(data: any, propertyIndexedObj?: Object) {
if (typeof data === 'number') {
return new FlatArrayPairs(data)
} else if (isReal(data)) {
// @NOTE meaning obj | array since arr is obj
// @TODO assert invariant without propertyIndexedObj || isPairs(data)
if (isObj(data)) {
const instance = new FlatArrayPairs()
// easier conditional logic
let pairs = data
if (isObj(data) && isObj(propertyIndexedObj)) {
pairs = zip(data, propertyIndexedObj)
}
if (isPairs(data)) {
// this is not a function...
// instance.addPair(pairs)
}
// no pairs at all... uh...
// else {}
return instance
}
/**
* .from is only `static` :-/
* and we want .addPairs > .fromPairs
*
* @todo with rollup this may not count the native extends...?
*/
return FlatArrayPairs.from(data)
}
// empty map
else {
return new FlatArrayPairs()
}
}
export { toFlatPairs }
export default toFlatPairs
// const TypedArray = (bits, signed) => {
// let name = ''
// if (signed) name += 'Int'
// else name += 'Uint'
// name += bits
// name += 'Array'
// return localGlobal()[name] || Array.of
// }
// var sa = new StringArray()
// sa.push('eh')
// sa[sa.length] = 'oh'