hierarchy-js
Version:
Elegant and lightweight library for working with data structures
15 lines (10 loc) • 424 B
JavaScript
const defaultOptions = require('../constants')
let OPTIONS = {}
const id = (item) => item && item[OPTIONS.id]
const parentId = (item) => item && item[OPTIONS.parentId]
const childrenKey = () => OPTIONS.children
const mergeOptionsBeforeCreateHierarchy = (options = {}) => {
OPTIONS = { ...defaultOptions, ...options }
return OPTIONS
}
module.exports = { id, parentId, childrenKey, mergeOptionsBeforeCreateHierarchy }