Repository URL to install this package:
|
Version:
1.2.9 ▾
|
"use strict";
const isReal = require("../is/real");
const isArray = require("../is/array");
const isPairs = require("../is/arrayOfPairs");
const isObj = require("../is/obj");
const zip = require("../util/zip");
const FlatArrayPairs = require("../structured/FlatArrayPairs");
/* prettier-ignore */
function toFlatPairs(data, propertyIndexedObj) {
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)) {
instance.addPairs(pairs);
} // no pairs at all... uh...
// else {}
return instance;
} // .from is only `static` :-/
// and we want .addPairs > .fromPairs
return FlatArrayPairs.from(data);
} // empty map
else {
return new FlatArrayPairs();
}
}
module.exports = 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'