lib/sinon-doublist-fs/index.js
function intermediatePaths(sparse) {
  const dense = {};
  [].concat(sparse).forEach(function forEachPath(path) {
    path = rtrimSlash(path);
    dense[path] = {}; // Store as keys to omit dupes
    const curParts = trimSlash(path).split('/');
    const gapParts = [];
    curParts.forEach(function forEachPart(part) {
      const parent = '/' + gapParts.join('/');

      gapParts.push(part); // Incrementally include all parts to collect gaps
      const intermediate = '/' + gapParts.join('/');

      if (!dense[intermediate]) { dense[intermediate] = {}; } // Collect gap

      if (!dense[parent]) { dense[parent] = {}; } // Store its relatinship
      if (parent === '/') {
        dense[parent][trimSlash(intermediate.slice(1))] = 1;
      } else {
        // Guard against '' child name from sparse path w/ trailing slash
        const childName = intermediate.replace(parent + '/', '');
        if (childName) {
          dense[parent][childName] = 1;
        }
      }
    });
  });
  Object.keys(dense).forEach(function forEachDensePath(name) {
    dense[name] = Object.keys(dense[name]);
  });
  return dense;
}
function intermediatePaths(sparse) {
  const dense = {};
  [].concat(sparse).forEach(function forEachPath(path) {
    path = rtrimSlash(path);
    dense[path] = {}; // Store as keys to omit dupes
    const curParts = trimSlash(path).split('/');
    const gapParts = [];
    curParts.forEach(function forEachPart(part) {
      const parent = '/' + gapParts.join('/');

      gapParts.push(part); // Incrementally include all parts to collect gaps
      const intermediate = '/' + gapParts.join('/');

      if (!dense[intermediate]) { dense[intermediate] = {}; } // Collect gap

      if (!dense[parent]) { dense[parent] = {}; } // Store its relatinship
      if (parent === '/') {
        dense[parent][trimSlash(intermediate.slice(1))] = 1;
      } else {
        // Guard against '' child name from sparse path w/ trailing slash
        const childName = intermediate.replace(parent + '/', '');
        if (childName) {
          dense[parent][childName] = 1;
        }
      }
    });
  });
  Object.keys(dense).forEach(function forEachDensePath(name) {
    dense[name] = Object.keys(dense[name]);
  });
  return dense;
}
function intermediatePaths ( sparse ) { const dense = { } ; [ ] . concat ( sparse ) . forEach ( function forEachPath ( path ) { path = rtrimSlash ( path ) ; dense [ path ] = { } ; // Store as keys to omit dupes const curParts = trimSlash ( path ) . split ( '/' ) ; const gapParts = [ ] ; curParts . forEach ( function forEachPart ( part ) { const parent = '/' + gapParts . join ( '/' ) ; gapParts . push ( part ) ; // Incrementally include all parts to collect gaps const intermediate = '/' + gapParts . join ( '/' ) ; if ( ! dense [ intermediate ] ) { dense [ intermediate ] = { } ; } // Collect gap if ( ! dense [ parent ] ) { dense [ parent ] = { } ; } // Store its relatinship if ( parent === '/' ) { dense [ parent ] [ trimSlash ( intermediate . slice ( 1 ) ) ] = 1 ; } else { // Guard against '' child name from sparse path w/ trailing slash const childName = intermediate . replace ( parent + '/' , '' ) ; if ( childName ) { dense [ parent ] [ childName ] = 1 ; } } } ) ; } ) ; Object . keys ( dense ) . forEach ( function forEachDensePath ( name ) { dense [ name ] = Object . keys ( dense [ name ] ) ; } ) ; return dense ; }
Given an array files and directories, in any order and relationship,
return an object describing how to build file trees that contain them
all with no directory gaps.

Ex. given just '/path/to/file.js', it include '/path' and '/to' in the
results.

@param {string|array} sparse Normalized, absolute paths
@return {object}
Keys: Absolute paths including 'sparse' and any filled 'gaps'.
Values: Arrays of direct descendants' absolute paths.
@api private
Given an array files and directories in any order and relationship return an object describing how to build file trees that contain them all with no directory gaps .