import { FILE_TYPE } from '.';
function sortByComparator(nodes, compareFunction) {
  nodes.sort(compareFunction);
  nodes.forEach(node => {
    if (node.content) {
      sortByComparator(node.content, compareFunction);
    }
  });
  return nodes;
}
export function compareByName(nodes) {
  return sortByComparator(nodes, (a, b) => a.name.localeCompare(b.name));
}
export function compareByNameAndType(nodes) {
  return sortByComparator(nodes, (a, b) => {
    if (a.type !== b.type) {
      return a.type === FILE_TYPE.FOLDER ? -1 : 1;
    }
    return a.name.localeCompare(b.name);
  });
}