'use strict';

require('../../../universalify/index.js');
require('../fs/index.js');
var Path = require('path');
var index$2 = require('../mkdirs/index.js');
var index$3 = require('../remove/index.js');
var index = require('../../../../_virtual/index21.js');
var index$1 = require('../../../../_virtual/index20.js');

const u = index.__exports.fromPromise;
const fs = index$1.__exports;
const path = Path;
const mkdir = index$2.mkdirs;
const remove = index$3.remove_1;

const emptyDir = u(async function emptyDir (dir) {
  let items;
  try {
    items = await fs.readdir(dir);
  } catch {
    return mkdir.mkdirs(dir)
  }

  return Promise.all(items.map(item => remove.remove(path.join(dir, item))))
});

function emptyDirSync (dir) {
  let items;
  try {
    items = fs.readdirSync(dir);
  } catch {
    return mkdir.mkdirsSync(dir)
  }

  items.forEach(item => {
    item = path.join(dir, item);
    remove.removeSync(item);
  });
}

var empty = {
  emptyDirSync,
  emptydirSync: emptyDirSync,
  emptyDir,
  emptydir: emptyDir
};

exports.empty = empty;
