UNPKG

1.37 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.safeConsole = void 0;
4/**
5 * workaround for missing console object in IE9 when dev tools haven't been opened o_O
6 * @packageDocumentation
7 */
8/* tslint:disable:no-console */
9var common_1 = require("./common");
10var noopConsoleStub = { log: common_1.noop, error: common_1.noop, table: common_1.noop };
11function ie9Console(console) {
12 var bound = function (fn) { return Function.prototype.bind.call(fn, console); };
13 return {
14 log: bound(console.log),
15 error: bound(console.log),
16 table: bound(console.log),
17 };
18}
19function fallbackConsole(console) {
20 var log = console.log.bind(console);
21 var error = console.error ? console.error.bind(console) : log;
22 var table = console.table ? console.table.bind(console) : log;
23 return { log: log, error: error, table: table };
24}
25function getSafeConsole() {
26 // @ts-ignore
27 var isIE9 = typeof document !== 'undefined' && document.documentMode && document.documentMode === 9;
28 if (isIE9) {
29 return window && window.console ? ie9Console(window.console) : noopConsoleStub;
30 }
31 else if (!console.table || !console.error) {
32 return fallbackConsole(console);
33 }
34 else {
35 return console;
36 }
37}
38exports.safeConsole = getSafeConsole();
39//# sourceMappingURL=safeConsole.js.map
\No newline at end of file