"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const fs_1 = tslib_1.__importDefault(require("fs"));
const path_1 = tslib_1.__importDefault(require("path"));
const pify_1 = tslib_1.__importDefault(require("pify"));
const pfs = pify_1.default(fs_1.default);
const prettify = obj => {
    return typeof obj === 'string' ? obj : JSON.stringify(obj, null, 2);
};
exports.read = file => fs_1.default.readFileSync(file, { encoding: 'utf8' });
exports.maybeRead = file => {
    if (exports.exists(file))
        return exports.read(file);
};
exports.readJSON = file => JSON.parse(exports.read(file));
exports.maybeReadJSON = file => {
    const result = exports.maybeRead(file);
    if (result)
        return JSON.parse(result);
};
exports.write = (file, data) => fs_1.default.writeFileSync(file, prettify(data));
exports.pwrite = (file, data) => pfs.writeFile(file, prettify(data));
exports.exists = file => fs_1.default.existsSync(file);
exports.readDirOfJSONs = dir => fs_1.default.readdirSync(dir)
    .filter(file => file.endsWith('.json'))
    .map(file => require(path_1.default.resolve(dir, file)));
//# sourceMappingURL=fs.js.map