UNPKG

brolog

Version:

Npmlog like logger for Browser

58 lines 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BROLOG_PREFIX = exports.BROLOG_LEVEL = exports.VERSION = void 0; var version_js_1 = require("./version.js"); Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_js_1.VERSION; } }); /** * BROLOG_LEVEL */ const DEFAULT_LEVEL = 'info'; const BROLOG_LEVEL_VAR_NAME = 'BROLOG_LEVEL'; const BROLOG_PREFIX_VAR_NAME = 'BROLOG_PREFIX'; let level; let debugModule; /** * * Sometimes there's a `process` in browser (ionic3 & angular5) * Sometimes there's a window in Node.js (browserify) * */ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (typeof process !== 'undefined' && process['env']) { /** * Node.js */ if (!level) { level = process.env[BROLOG_LEVEL_VAR_NAME]; } if (!debugModule) { debugModule = process.env[BROLOG_PREFIX_VAR_NAME]; } } // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (typeof window !== 'undefined' && typeof window?.location?.search === 'string') { /** * Browser */ if (!level) { level = getJsonFromUrl()[BROLOG_LEVEL_VAR_NAME]; } if (!debugModule) { debugModule = getJsonFromUrl()[BROLOG_LEVEL_VAR_NAME]; } } function getJsonFromUrl() { // https://stackoverflow.com/questions/8486099/how-do-i-parse-a-url-query-parameters-in-javascript const query = location.search.substr(1); const result = {}; query.split('&').forEach(function (part) { const [key, val] = part.split('='); if (typeof key !== 'undefined' && typeof val !== 'undefined') { result[key] = decodeURIComponent(val); } }); return result; } exports.BROLOG_LEVEL = level || DEFAULT_LEVEL; exports.BROLOG_PREFIX = debugModule || '*'; //# sourceMappingURL=config.js.map