Skip to content

Commit

Permalink
Push updated lib files
Browse files Browse the repository at this point in the history
  • Loading branch information
ehasnain committed Oct 6, 2020
1 parent ad87944 commit 42be3fa
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/route-blocker.js
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand All @@ -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() {
Expand Down
9 changes: 9 additions & 0 deletions lib/utils/logger.d.ts
Original file line number Diff line number Diff line change
@@ -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;
29 changes: 29 additions & 0 deletions lib/utils/logger.js
Original file line number Diff line number Diff line change
@@ -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;
File renamed without changes.
File renamed without changes.

0 comments on commit 42be3fa

Please sign in to comment.