"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.compareByName = compareByName;
exports.compareByNameAndType = compareByNameAndType;
var _ = require(".");
function sortByComparator(nodes, compareFunction) {
  nodes.sort(compareFunction);
  nodes.forEach(node => {
    if (node.content) {
      sortByComparator(node.content, compareFunction);
    }
  });
  return nodes;
}
function compareByName(nodes) {
  return sortByComparator(nodes, (a, b) => a.name.localeCompare(b.name));
}
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);
  });
}