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