src/index.js
function childNodesFromPaths (files, parent, renderLabelFn, originalFiles, baseDir) {
  // Group by first path element
  var groups = _.groupBy(files, file => file.match(/^[^/]*\/?/))
  return Object.keys(groups).map(function (groupKey) {
    const group = groups[groupKey]
    // Is this group explicitly part of the result, or
    // just implicit through its children
    const explicit = group.indexOf(groupKey) >= 0
    let index = -1
    if (explicit) {
      index = originalFiles.indexOf(parent.replace(baseDir, '') + groupKey)
    }

    return {
      label: renderLabelFn(parent, groupKey, explicit, explicit ? index : -1),
      nodes: childNodesFromPaths(
        // Remove parent directory from file paths
        group
          .map(node => node.substr(groupKey.length))
          // Skip the empty path
          .filter(node => node),
        // New parent..., normalize to one trailing slash
        parent + groupKey,
        renderLabelFn,
        originalFiles,
        baseDir
      )
    }
  })
}
function childNodesFromPaths (files, parent, renderLabelFn, originalFiles, baseDir) {
  // Group by first path element
  var groups = _.groupBy(files, file => file.match(/^[^/]*\/?/))
  return Object.keys(groups).map(function (groupKey) {
    const group = groups[groupKey]
    // Is this group explicitly part of the result, or
    // just implicit through its children
    const explicit = group.indexOf(groupKey) >= 0
    let index = -1
    if (explicit) {
      index = originalFiles.indexOf(parent.replace(baseDir, '') + groupKey)
    }

    return {
      label: renderLabelFn(parent, groupKey, explicit, explicit ? index : -1),
      nodes: childNodesFromPaths(
        // Remove parent directory from file paths
        group
          .map(node => node.substr(groupKey.length))
          // Skip the empty path
          .filter(node => node),
        // New parent..., normalize to one trailing slash
        parent + groupKey,
        renderLabelFn,
        originalFiles,
        baseDir
      )
    }
  })
}
function childNodesFromPaths ( files , parent , renderLabelFn , originalFiles , baseDir ) { // Group by first path element var groups = _ . groupBy ( files , file => file . match ( / ^[^/]*\/? / ) ) return Object . keys ( groups ) . map ( function ( groupKey ) { const group = groups [ groupKey ] // Is this group explicitly part of the result, or // just implicit through its children const explicit = group . indexOf ( groupKey ) >= 0 let index = - 1 if ( explicit ) { index = originalFiles . indexOf ( parent . replace ( baseDir , '' ) + groupKey ) } return { label : renderLabelFn ( parent , groupKey , explicit , explicit ? index : - 1 ) , nodes : childNodesFromPaths ( // Remove parent directory from file paths group . map ( node => node . substr ( groupKey . length ) ) // Skip the empty path . filter ( node => node ) , // New parent..., normalize to one trailing slash parent + groupKey , renderLabelFn , originalFiles , baseDir ) } } ) }
Compute the child nodes of a node, given a list of paths
@param files
@param parent
@param renderLabelFn
@returns {Array}
Compute the child nodes of a node given a list of paths