From 42be3fada4ef90243e02d1674131c31b0713d53d Mon Sep 17 00:00:00 2001 From: Ehtesham Hasnain Date: Tue, 6 Oct 2020 21:07:59 +0200 Subject: [PATCH] Push updated lib files --- lib/route-blocker.js | 18 +++++++++------ lib/utils/logger.d.ts | 9 ++++++++ lib/utils/logger.js | 29 ++++++++++++++++++++++++ lib/{utils.d.ts => utils/validator.d.ts} | 0 lib/{utils.js => utils/validator.js} | 0 5 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 lib/utils/logger.d.ts create mode 100644 lib/utils/logger.js rename lib/{utils.d.ts => utils/validator.d.ts} (100%) rename lib/{utils.js => utils/validator.js} (100%) diff --git a/lib/route-blocker.js b/lib/route-blocker.js index 59e5217..ca9c4b6 100644 --- a/lib/route-blocker.js +++ b/lib/route-blocker.js @@ -1,7 +1,11 @@ "use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.routeBlocker = void 0; -const utils_1 = require("./utils"); +const validator_1 = require("./utils/validator"); +const logger_1 = __importDefault(require("./utils/logger")); class RouteBlocker { constructor() { this.routesBlockingMap = {}; @@ -22,21 +26,21 @@ class RouteBlocker { }; } disableRoute(route) { - if (utils_1.isValidString(route)) { + if (validator_1.isValidString(route)) { this.routesBlockingMap[route] = true; - console.warn(`Route "${route}": disabled ⛔️`); + logger_1.default.warn(`Route "${route}": disabled ⛔️`); } else { - console.error("Invalid route key 🤡!"); + logger_1.default.error("Invalid route key 🤡!"); } } enableRoute(route) { - if (utils_1.isValidString(route)) { - console.info(`Route "${route}": enabled ✅`); + if (validator_1.isValidString(route)) { + logger_1.default.info(`Route "${route}": enabled ✅`); this.routesBlockingMap[route] = false; } else { - console.error("Invalid route key 🤡!"); + logger_1.default.error("Invalid route key 🤡!"); } } clearBlockings() { diff --git a/lib/utils/logger.d.ts b/lib/utils/logger.d.ts new file mode 100644 index 0000000..7a621a6 --- /dev/null +++ b/lib/utils/logger.d.ts @@ -0,0 +1,9 @@ +declare class Logger { + info(message: string): void; + warn(message: string): void; + error(message: string): void; + debug(message: string): void; + private decorate; +} +declare const log: Logger; +export default log; diff --git a/lib/utils/logger.js b/lib/utils/logger.js new file mode 100644 index 0000000..4b3a576 --- /dev/null +++ b/lib/utils/logger.js @@ -0,0 +1,29 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var LogType; +(function (LogType) { + LogType["ERROR"] = "error"; + LogType["WARN"] = "warn"; + LogType["INFO"] = "info"; + LogType["DEBUG"] = "debug"; +})(LogType || (LogType = {})); +class Logger { + info(message) { + console.info(this.decorate(message, LogType.INFO)); + } + warn(message) { + console.warn(this.decorate(message, LogType.WARN)); + } + error(message) { + console.error(this.decorate(message, LogType.ERROR)); + } + debug(message) { + console.debug(this.decorate(message, LogType.DEBUG)); + } + decorate(message, logType) { + const timestamp = new Date().toISOString(); + return `${timestamp}: [Route blocker: ${logType}] ${message}`; + } +} +const log = new Logger(); +exports.default = log; diff --git a/lib/utils.d.ts b/lib/utils/validator.d.ts similarity index 100% rename from lib/utils.d.ts rename to lib/utils/validator.d.ts diff --git a/lib/utils.js b/lib/utils/validator.js similarity index 100% rename from lib/utils.js rename to lib/utils/validator.js