transaction-logger
Version:
This is a custom logging library based on winston.
45 lines (44 loc) • 1.53 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var path_1 = __importDefault(require("path"));
var fs_1 = __importDefault(require("fs"));
var getFolderAndFilename = function (globalFilename) {
throwErrorIfPathNotExists(globalFilename);
var array = globalFilename.split(path_1.default.sep);
var name = array.pop();
var folder = array.pop();
return "../".concat(folder, "/").concat(name);
};
var getFolderPath = function (globalFilename) {
throwErrorIfPathNotExists(globalFilename);
var folders = globalFilename.split(path_1.default.sep);
var folderPath = '';
for (var posArray = 0; posArray < folders.length - 2; posArray++) {
folderPath += folders[posArray] + '/';
}
var lastFolder = folders[folders.length - 2];
folderPath += lastFolder;
return folderPath;
};
var throwErrorIfPathNotExists = function (filePath) {
if (!fileExist(filePath)) {
throw new Error('La dirección de archivo ' + filePath + ' no existe');
}
};
var fileExist = function (filePath) {
return fs_1.default.existsSync(filePath);
};
var createFile = function (filePath) {
if (!fileExist(filePath)) {
fs_1.default.mkdirSync(filePath);
}
};
exports.default = {
getFolderAndFilename: getFolderAndFilename,
getFolderPath: getFolderPath,
fileExist: fileExist,
createFile: createFile,
};