@haiku/player
Version:
Haiku Player is a JavaScript library for building user interfaces
33 lines • 1.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var BasicUtils_1 = require("./BasicUtils");
var objectPath_1 = require("./objectPath");
function flattenTree(node, options, unique, list, depth, index) {
if (unique === void 0) { unique = true; }
if (list === void 0) { list = []; }
if (depth === void 0) { depth = 0; }
if (index === void 0) { index = 0; }
list.push(node);
if (typeof node !== 'string') {
node.__depth = depth;
node.__index = index;
}
var children = objectPath_1.default(node, options.children);
if (!children || children.length < 1 || typeof children === 'string') {
return list;
}
if (Array.isArray(children)) {
for (var i = 0; i < children.length; i++) {
flattenTree(children[i], options, false, list, depth + 1, i);
}
}
else if (typeof children === 'object') {
children.__depth = depth + 1;
children.__index = 0;
list.push(children);
return list;
}
return unique ? BasicUtils_1.default.uniq(list) : list;
}
exports.default = flattenTree;
//# sourceMappingURL=manaFlattenTree.js.map