hierarchy-js
Version:
Elegant and lightweight library for working with data structures
26 lines (19 loc) • 959 B
JavaScript
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var defaultOptions = require('../constants');
var OPTIONS = {};
var id = function id(item) {
return item && item[OPTIONS.id];
};
var parentId = function parentId(item) {
return item && item[OPTIONS.parentId];
};
var childrenKey = function childrenKey() {
return OPTIONS.children;
};
var mergeOptionsBeforeCreateHierarchy = function mergeOptionsBeforeCreateHierarchy() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
OPTIONS = _extends({}, defaultOptions, options);
return OPTIONS;
};
module.exports = { id: id, parentId: parentId, childrenKey: childrenKey, mergeOptionsBeforeCreateHierarchy: mergeOptionsBeforeCreateHierarchy };
;