"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var fs_1 = require("fs");
var path_1 = require("path");
var defaultConfig = Object.freeze({
    inReg: '(.*)',
    outReg: '{1}',
    cwd: process.cwd(),
    options: {
        renameDir: true,
        verbose: true
    }
});
var bame = function (config) {
    if (config === void 0) { config = defaultConfig; }
    config = Object.assign({}, defaultConfig, config);
    var logger = config.options.verbose ? console.log : function () { };
    var files = fs_1.readdirSync(config.cwd);
    if (files) {
        files
            .filter(function (n) { return config.options.renameDir ? true : !fs_1.statSync(n).isDirectory(); })
            .sort()
            .forEach(function (file) {
            var matches = new RegExp(config.inReg).exec(file);
            if (matches) {
                var newFile = config.outReg.replace(/{([0-9]+)}/g, function (_, i) {
                    return matches[parseInt(i)];
                });
                logger(file + "     -->     " + newFile);
                fs_1.renameSync(path_1.join(config.cwd, file), path_1.join(config.cwd, newFile));
            }
        });
    }
    else {
        logger("No file matching " + config.inReg + " to rename");
    }
};
exports.bame = bame;
