Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

probe.gl

Package Overview
Dependencies
Maintainers
7
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

probe.gl - npm Package Compare versions

Comparing version 3.1.1 to 3.2.0-beta.1

src/.DS_Store

73

dist/es5/env/get-browser.js

@@ -1,58 +0,69 @@

"use strict";
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
// This function is needed in initialization stages,
// make sure it can be imported in isolation
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isMobile = isMobile;
exports["default"] = getBrowser;
import { window } from './globals';
import isBrowser from './is-browser';
import isElectron from './is-electron';
var _globals = require("./globals");
var _isBrowser = _interopRequireDefault(require("./is-browser"));
var _isElectron = _interopRequireDefault(require("./is-electron"));
function isMobile() {
return typeof _globals.window.orientation !== 'undefined';
export function isMobile() {
return typeof window.orientation !== 'undefined';
}
function getBrowser(mockUserAgent) {
if (!mockUserAgent && !(0, _isBrowser["default"])()) {
// Simple browser detection
// `mockUserAgent` parameter allows user agent to be overridden for testing
/* eslint-disable complexity */
export default function getBrowser(mockUserAgent) {
if (!mockUserAgent && !isBrowser()) {
return 'Node';
}
if ((0, _isElectron["default"])(mockUserAgent)) {
if (isElectron(mockUserAgent)) {
return 'Electron';
}
var navigator_ = typeof navigator !== 'undefined' ? navigator : {};
var userAgent = mockUserAgent || navigator_.userAgent || '';
/* global navigator */
const navigator_ = typeof navigator !== 'undefined' ? navigator : {};
const userAgent = mockUserAgent || navigator_.userAgent || '';
// const appVersion = navigator_.appVersion || '';
// NOTE: Order of tests matter, as many agents list Chrome etc.
if (userAgent.indexOf('Edge') > -1) {
return 'Edge';
}
var isMSIE = userAgent.indexOf('MSIE ') !== -1;
var isTrident = userAgent.indexOf('Trident/') !== -1;
const isMSIE = userAgent.indexOf('MSIE ') !== -1;
const isTrident = userAgent.indexOf('Trident/') !== -1;
if (isMSIE || isTrident) {
return 'IE';
}
if (_globals.window.chrome) {
if (window.chrome) {
return 'Chrome';
}
if (_globals.window.safari) {
if (window.safari) {
return 'Safari';
}
if (_globals.window.mozInnerScreenX) {
if (window.mozInnerScreenX) {
return 'Firefox';
}
return 'Unknown';
}
//# sourceMappingURL=get-browser.js.map

@@ -1,13 +0,4 @@

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.console = exports.process = exports.document = exports.global = exports.window = exports.self = void 0;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var globals = {
/* global self, window, global, document, console, process */
/* eslint-disable no-restricted-globals */
const globals = {
self: typeof self !== 'undefined' && self,

@@ -17,16 +8,13 @@ window: typeof window !== 'undefined' && window,

document: typeof document !== 'undefined' && document,
process: (typeof process === "undefined" ? "undefined" : (0, _typeof2["default"])(process)) === 'object' && process
process: typeof process === 'object' && process
};
var self_ = globals.self || globals.window || globals.global;
exports.self = self_;
var window_ = globals.window || globals.self || globals.global;
exports.window = window_;
var global_ = globals.global || globals.self || globals.window;
exports.global = global_;
var document_ = globals.document || {};
exports.document = document_;
var process_ = globals.process || {};
exports.process = process_;
var console_ = console;
exports.console = console_;
const self_ = globals.self || globals.window || globals.global;
const window_ = globals.window || globals.self || globals.global;
const global_ = globals.global || globals.self || globals.window;
const document_ = globals.document || {};
const process_ = globals.process || {};
const console_ = console;
export { self_ as self, window_ as window, global_ as global, document_ as document, process_ as process, console_ as console };
//# sourceMappingURL=globals.js.map

@@ -1,84 +0,6 @@

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "self", {
enumerable: true,
get: function get() {
return _globals.self;
}
});
Object.defineProperty(exports, "window", {
enumerable: true,
get: function get() {
return _globals.window;
}
});
Object.defineProperty(exports, "global", {
enumerable: true,
get: function get() {
return _globals.global;
}
});
Object.defineProperty(exports, "document", {
enumerable: true,
get: function get() {
return _globals.document;
}
});
Object.defineProperty(exports, "process", {
enumerable: true,
get: function get() {
return _globals.process;
}
});
Object.defineProperty(exports, "console", {
enumerable: true,
get: function get() {
return _globals.console;
}
});
Object.defineProperty(exports, "isBrowser", {
enumerable: true,
get: function get() {
return _isBrowser["default"];
}
});
Object.defineProperty(exports, "isBrowserMainThread", {
enumerable: true,
get: function get() {
return _isBrowser.isBrowserMainThread;
}
});
Object.defineProperty(exports, "getBrowser", {
enumerable: true,
get: function get() {
return _getBrowser["default"];
}
});
Object.defineProperty(exports, "isMobile", {
enumerable: true,
get: function get() {
return _getBrowser.isMobile;
}
});
Object.defineProperty(exports, "isElectron", {
enumerable: true,
get: function get() {
return _isElectron["default"];
}
});
var _globals = require("./globals");
var _isBrowser = _interopRequireWildcard(require("./is-browser"));
var _getBrowser = _interopRequireWildcard(require("./get-browser"));
var _isElectron = _interopRequireDefault(require("./is-electron"));
// ENVIRONMENT
export { self, window, global, document, process, console } from './globals';
export { default as isBrowser, isBrowserMainThread } from './is-browser';
export { default as getBrowser, isMobile } from './get-browser';
export { default as isElectron } from './is-electron';
//# sourceMappingURL=index.js.map

@@ -1,23 +0,18 @@

"use strict";
// This function is needed in initialization stages,
// make sure it can be imported in isolation
/* global process */
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
import isElectron from './is-electron';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = isBrowser;
exports.isBrowserMainThread = isBrowserMainThread;
export default function isBrowser() {
// Check if in browser by duck-typing Node context
const isNode = typeof process === 'object' && String(process) === '[object process]' && !process.browser;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _isElectron = _interopRequireDefault(require("./is-electron"));
function isBrowser() {
var isNode = (typeof process === "undefined" ? "undefined" : (0, _typeof2["default"])(process)) === 'object' && String(process) === '[object process]' && !process.browser;
return !isNode || (0, _isElectron["default"])();
return !isNode || isElectron();
}
function isBrowserMainThread() {
// document does not exist on worker thread
export function isBrowserMainThread() {
return isBrowser() && typeof document !== 'undefined';
}
//# sourceMappingURL=is-browser.js.map

@@ -1,30 +0,22 @@

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = isElectron;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
function isElectron(mockUserAgent) {
if (typeof window !== 'undefined' && (0, _typeof2["default"])(window.process) === 'object' && window.process.type === 'renderer') {
// based on https://github.com/cheton/is-electron
// https://github.com/electron/electron/issues/2288
/* global window, process, navigator */
/* eslint-disable complexity */
export default function isElectron(mockUserAgent) {
// Renderer process
if (typeof window !== 'undefined' && typeof window.process === 'object' && window.process.type === 'renderer') {
return true;
}
if (typeof process !== 'undefined' && (0, _typeof2["default"])(process.versions) === 'object' && Boolean(process.versions.electron)) {
// Main process
if (typeof process !== 'undefined' && typeof process.versions === 'object' && Boolean(process.versions.electron)) {
return true;
}
var realUserAgent = (typeof navigator === "undefined" ? "undefined" : (0, _typeof2["default"])(navigator)) === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent;
var userAgent = mockUserAgent || realUserAgent;
// Detect the user agent when the `nodeIntegration` option is set to true
const realUserAgent = typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent;
const userAgent = mockUserAgent || realUserAgent;
if (userAgent && userAgent.indexOf('Electron') >= 0) {
return true;
}
return false;
}
//# sourceMappingURL=is-electron.js.map

@@ -1,185 +0,31 @@

"use strict";
import './init';
import { default as Log } from './lib/log';
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
export { VERSION } from './utils/globals';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
// ENVIRONMENT
export { self, window, global, document, process, console } from './env/globals';
export { default as isBrowser, isBrowserMainThread } from './env/is-browser';
export { default as getBrowser, isMobile } from './env/get-browser';
export { default as isElectron } from './env/is-electron';
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "Log", {
enumerable: true,
get: function get() {
return _log["default"];
}
});
Object.defineProperty(exports, "VERSION", {
enumerable: true,
get: function get() {
return _globals.VERSION;
}
});
Object.defineProperty(exports, "self", {
enumerable: true,
get: function get() {
return _globals2.self;
}
});
Object.defineProperty(exports, "window", {
enumerable: true,
get: function get() {
return _globals2.window;
}
});
Object.defineProperty(exports, "global", {
enumerable: true,
get: function get() {
return _globals2.global;
}
});
Object.defineProperty(exports, "document", {
enumerable: true,
get: function get() {
return _globals2.document;
}
});
Object.defineProperty(exports, "process", {
enumerable: true,
get: function get() {
return _globals2.process;
}
});
Object.defineProperty(exports, "console", {
enumerable: true,
get: function get() {
return _globals2.console;
}
});
Object.defineProperty(exports, "isBrowser", {
enumerable: true,
get: function get() {
return _isBrowser["default"];
}
});
Object.defineProperty(exports, "isBrowserMainThread", {
enumerable: true,
get: function get() {
return _isBrowser.isBrowserMainThread;
}
});
Object.defineProperty(exports, "getBrowser", {
enumerable: true,
get: function get() {
return _getBrowser["default"];
}
});
Object.defineProperty(exports, "isMobile", {
enumerable: true,
get: function get() {
return _getBrowser.isMobile;
}
});
Object.defineProperty(exports, "isElectron", {
enumerable: true,
get: function get() {
return _isElectron["default"];
}
});
Object.defineProperty(exports, "assert", {
enumerable: true,
get: function get() {
return _assert["default"];
}
});
Object.defineProperty(exports, "Stats", {
enumerable: true,
get: function get() {
return _stats["default"];
}
});
Object.defineProperty(exports, "Stat", {
enumerable: true,
get: function get() {
return _stat["default"];
}
});
Object.defineProperty(exports, "COLOR", {
enumerable: true,
get: function get() {
return _color.COLOR;
}
});
Object.defineProperty(exports, "addColor", {
enumerable: true,
get: function get() {
return _color.addColor;
}
});
Object.defineProperty(exports, "leftPad", {
enumerable: true,
get: function get() {
return _formatters.leftPad;
}
});
Object.defineProperty(exports, "rightPad", {
enumerable: true,
get: function get() {
return _formatters.rightPad;
}
});
Object.defineProperty(exports, "autobind", {
enumerable: true,
get: function get() {
return _autobind.autobind;
}
});
Object.defineProperty(exports, "LocalStorage", {
enumerable: true,
get: function get() {
return _localStorage["default"];
}
});
Object.defineProperty(exports, "getHiResTimestamp", {
enumerable: true,
get: function get() {
return _hiResTimestamp["default"];
}
});
exports["default"] = void 0;
// ENVIRONMENT'S ASSERT IS 5-15KB, SO WE PROVIDE OUR OWN
export { default as assert } from './utils/assert';
require("./init");
// LOGGING
export { default as Log } from './lib/log';
export { COLOR } from './utils/color';
var _log = _interopRequireDefault(require("./lib/log"));
// DEFAULT EXPORT IS A LOG INSTANCE
export default new Log({ id: 'probe.gl' });
var _globals = require("./utils/globals");
// UTILITIES
export { addColor } from './utils/color';
export { leftPad, rightPad } from './utils/formatters';
export { autobind } from './utils/autobind';
export { default as LocalStorage } from './utils/local-storage';
export { default as getHiResTimestamp } from './utils/hi-res-timestamp';
var _globals2 = require("./env/globals");
var _isBrowser = _interopRequireWildcard(require("./env/is-browser"));
var _getBrowser = _interopRequireWildcard(require("./env/get-browser"));
var _isElectron = _interopRequireDefault(require("./env/is-electron"));
var _assert = _interopRequireDefault(require("./utils/assert"));
var _stats = _interopRequireDefault(require("./lib/stats"));
var _stat = _interopRequireDefault(require("./lib/stat"));
var _color = require("./utils/color");
var _formatters = require("./utils/formatters");
var _autobind = require("./utils/autobind");
var _localStorage = _interopRequireDefault(require("./utils/local-storage"));
var _hiResTimestamp = _interopRequireDefault(require("./utils/hi-res-timestamp"));
var _default = new _log["default"]({
id: 'probe.gl'
});
exports["default"] = _default;
// DEPRECATED (Should be imported directly from @probe.gl/stats)
export { Stats, Stat } from '@probe.gl/stats';
//# sourceMappingURL=index.js.map

@@ -1,6 +0,3 @@

"use strict";
var _globals = require("./utils/globals");
_globals.global.probe = {};
import { global } from './utils/globals';
global.probe = {};
//# sourceMappingURL=init.js.map

@@ -1,36 +0,37 @@

"use strict";
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
/* eslint-disable no-console, no-try-catch */
/* global console */
import { VERSION, isBrowser } from '../utils/globals';
import LocalStorage from '../utils/local-storage';
import { formatImage, formatTime, leftPad } from '../utils/formatters';
import { addColor } from '../utils/color';
import { autobind } from '../utils/autobind';
import assert from '../utils/assert';
import getHiResTimestamp from '../utils/hi-res-timestamp';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
/* eslint-disable no-console */
/* global console, Image */
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _globals = require("../utils/globals");
var _localStorage = _interopRequireDefault(require("../utils/local-storage"));
var _formatters = require("../utils/formatters");
var _color = require("../utils/color");
var _autobind = require("../utils/autobind");
var _assert2 = _interopRequireDefault(require("../utils/assert"));
var _hiResTimestamp = _interopRequireDefault(require("../utils/hi-res-timestamp"));
var originalConsole = {
debug: _globals.isBrowser ? console.debug || console.log : console.log,
// Instrumentation in other packages may override console methods, so preserve them here
const originalConsole = {
debug: isBrowser ? console.debug || console.log : console.log,
log: console.log,

@@ -41,5 +42,6 @@ info: console.info,

};
var DEFAULT_SETTINGS = {
enabled: false,
priority: 0
const DEFAULT_SETTINGS = {
enabled: true,
level: 0
};

@@ -49,555 +51,415 @@

var cache = {};
const cache = {};
const ONCE = { once: true };
/*
function throttle(tag, timeout) {
const prevTime = cache[tag];
const time = Date.now();
if (!prevTime || (time - prevTime > timeout)) {
cache[tag] = time;
return true;
}
return false;
}
// Assertions don't generate standard exceptions and don't print nicely
function checkForAssertionErrors(args) {
const isAssertion =
args &&
args.length > 0 &&
typeof args[0] === 'object' &&
args[0] !== null &&
args[0].name === 'AssertionError';
if (isAssertion) {
args = Array.prototype.slice.call(args);
args.unshift(`assert(${args[0].message})`);
}
return args;
}
*/
function getTableHeader(table) {
for (var key in table) {
for (var title in table[key]) {
for (const key in table) {
for (const title in table[key]) {
return title || 'untitled';
}
}
return 'empty';
}
var Log = function () {
function Log() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
id = _ref.id;
// A console wrapper
(0, _classCallCheck2["default"])(this, Log);
export default class Log {
constructor({ id } = {}) {
this.id = id;
this.VERSION = _globals.VERSION;
this._startTs = (0, _hiResTimestamp["default"])();
this._deltaTs = (0, _hiResTimestamp["default"])();
this.LOG_THROTTLE_TIMEOUT = 0;
this._storage = new _localStorage["default"]("__probe-".concat(this.id, "__"), DEFAULT_SETTINGS);
this.VERSION = VERSION;
this._startTs = getHiResTimestamp();
this._deltaTs = getHiResTimestamp();
// TODO - fix support from throttling groups
this.LOG_THROTTLE_TIMEOUT = 0; // Time before throttled messages are logged again
this._storage = new LocalStorage(`__probe-${this.id}__`, DEFAULT_SETTINGS);
this.userData = {};
this.timeStamp("".concat(this.id, " started"));
(0, _autobind.autobind)(this);
this.timeStamp(`${this.id} started`);
autobind(this);
Object.seal(this);
}
(0, _createClass2["default"])(Log, [{
key: "isEnabled",
value: function isEnabled() {
return this._storage.config.enabled;
}
}, {
key: "getPriority",
value: function getPriority() {
return this._storage.config.priority;
}
}, {
key: "getLevel",
value: function getLevel() {
return this._storage.config.priority;
}
}, {
key: "getTotal",
value: function getTotal() {
return Number(((0, _hiResTimestamp["default"])() - this._startTs).toPrecision(10));
}
}, {
key: "getDelta",
value: function getDelta() {
return Number(((0, _hiResTimestamp["default"])() - this._deltaTs).toPrecision(10));
}
}, {
key: "enable",
value: function enable() {
var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
set level(newLevel) {
this.setLevel(newLevel);
}
this._storage.updateConfiguration({
enabled: enabled
});
get level() {
return this.getLevel();
}
return this;
}
}, {
key: "setLevel",
value: function setLevel(level) {
this._storage.updateConfiguration({
priority: level
});
isEnabled() {
return this._storage.config.enabled;
}
return this;
}
}, {
key: "assert",
value: function assert(condition, message) {
(0, _assert2["default"])(condition, message);
}
}, {
key: "warn",
value: function warn(message) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
getLevel() {
return this._storage.config.level;
}
return this._getLogFunction({
message: message,
args: args,
method: originalConsole.warn,
once: true
});
}
}, {
key: "error",
value: function error(message) {
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
// @return {Number} milliseconds, with fractions
getTotal() {
return Number((getHiResTimestamp() - this._startTs).toPrecision(10));
}
return this._getLogFunction({
message: message,
args: args,
method: originalConsole.error
});
}
}, {
key: "deprecated",
value: function deprecated(oldUsage, newUsage) {
return this.warn("`".concat(oldUsage, "` is deprecated and will be removed in a later version. Use `").concat(newUsage, "` instead"));
}
}, {
key: "removed",
value: function removed(oldUsage, newUsage) {
return this.error("`".concat(oldUsage, "` has been removed. Use `").concat(newUsage, "` instead"));
}
}, {
key: "probe",
value: function probe(priority, message) {
for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
args[_key3 - 2] = arguments[_key3];
}
// @return {Number} milliseconds, with fractions
getDelta() {
return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10));
}
return this._getLogFunction({
priority: priority,
message: message,
args: args,
method: originalConsole.log,
time: true,
once: true
});
}
}, {
key: "log",
value: function log(priority, message) {
for (var _len4 = arguments.length, args = new Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) {
args[_key4 - 2] = arguments[_key4];
}
// Deprecated
set priority(newPriority) {
this.level = newPriority;
}
return this._getLogFunction({
priority: priority,
message: message,
args: args,
method: originalConsole.debug
});
}
}, {
key: "info",
value: function info(priority, message) {
for (var _len5 = arguments.length, args = new Array(_len5 > 2 ? _len5 - 2 : 0), _key5 = 2; _key5 < _len5; _key5++) {
args[_key5 - 2] = arguments[_key5];
}
get priority() {
return this.level;
}
return this._getLogFunction({
priority: priority,
message: message,
args: args,
method: console.info
});
}
}, {
key: "once",
value: function once(priority, message) {
for (var _len6 = arguments.length, args = new Array(_len6 > 2 ? _len6 - 2 : 0), _key6 = 2; _key6 < _len6; _key6++) {
args[_key6 - 2] = arguments[_key6];
}
getPriority() {
return this.level;
}
return this._getLogFunction({
priority: priority,
message: message,
args: args,
method: originalConsole.debug || originalConsole.info,
once: true
// Configure
enable(enabled = true) {
this._storage.updateConfiguration({ enabled });
return this;
}
setLevel(level) {
this._storage.updateConfiguration({ level });
return this;
}
// Unconditional logging
assert(condition, message) {
assert(condition, message);
}
// Warn, but only once, no console flooding
warn(message) {
return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
}
// Print an error
error(message) {
return this._getLogFunction(0, message, originalConsole.error, arguments);
}
deprecated(oldUsage, newUsage) {
return this.warn(`\`${oldUsage}\` is deprecated and will be removed \
in a later version. Use \`${newUsage}\` instead`);
}
removed(oldUsage, newUsage) {
return this.error(`\`${oldUsage}\` has been removed. Use \`${newUsage}\` instead`);
}
// Conditional logging
// Log to a group
probe(logLevel, message) {
return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {
time: true,
once: true
});
}
// Log a debug message
log(logLevel, message) {
return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
}
// Log a normal message
info(logLevel, message) {
return this._getLogFunction(logLevel, message, console.info, arguments);
}
// Log a normal message, but only once, no console flooding
once(logLevel, message) {
return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);
}
// Logs an object as a table
table(logLevel, table, columns) {
if (table) {
return this._getLogFunction(logLevel, table, console.table || noop, columns && [columns], {
tag: getTableHeader(table)
});
}
}, {
key: "table",
value: function table(priority, _table, columns) {
if (_table) {
var tag = getTableHeader(_table);
return this._getLogFunction({
priority: priority,
message: _table,
args: columns && [columns],
tag: tag,
method: console.table || noop
});
}
return noop;
}
// logs an image under Chrome
image({ logLevel, priority, image, message = '', scale = 1 }) {
if (!this._shouldLog(logLevel || priority)) {
return noop;
}
}, {
key: "image",
value: function image(_ref2) {
var priority = _ref2.priority,
_image = _ref2.image,
_ref2$message = _ref2.message,
message = _ref2$message === void 0 ? '' : _ref2$message,
_ref2$scale = _ref2.scale,
scale = _ref2$scale === void 0 ? 1 : _ref2$scale;
return isBrowser ? logImageInBrowser({ image, message, scale }) : logImageInNode({ image, message, scale });
}
if (priority > this.getPriority()) {
return noop;
}
return _globals.isBrowser ? this._logImageInBrowser({
image: _image,
message: message,
scale: scale
}) : this._logImageInNode({
image: _image,
message: message,
scale: scale
});
// Logs the current settings as a table
settings() {
if (console.table) {
console.table(this._storage.config);
} else {
console.log(this._storage.config);
}
}, {
key: "settings",
value: function settings() {
if (console.table) {
console.table(this._storage.config);
} else {
console.log(this._storage.config);
}
}
}, {
key: "get",
value: function get(setting) {
return this._storage.config[setting];
}
}, {
key: "set",
value: function set(setting, value) {
this._storage.updateConfiguration((0, _defineProperty2["default"])({}, setting, value));
}
}, {
key: "_logImageInNode",
value: function _logImageInNode(_ref3) {
var image = _ref3.image,
_ref3$message = _ref3.message,
message = _ref3$message === void 0 ? '' : _ref3$message,
_ref3$scale = _ref3.scale,
scale = _ref3$scale === void 0 ? 1 : _ref3$scale;
var asciify = null;
}
try {
asciify = module.require('asciify-image');
} catch (error) {}
// logs the current status of the setting
get(setting) {
return this._storage.config[setting];
}
if (asciify) {
return function () {
return asciify(image, {
fit: 'box',
width: "".concat(Math.round(80 * scale), "%")
}).then(function (data) {
return console.log(data);
});
};
}
// update the status of the setting
set(setting, value) {
this._storage.updateConfiguration({ [setting]: value });
}
return noop;
}
}, {
key: "_logImageInBrowser",
value: function _logImageInBrowser(_ref4) {
var image = _ref4.image,
_ref4$message = _ref4.message,
message = _ref4$message === void 0 ? '' : _ref4$message,
_ref4$scale = _ref4.scale,
scale = _ref4$scale === void 0 ? 1 : _ref4$scale;
time(logLevel, message) {
return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);
}
if (typeof image === 'string') {
var img = new Image();
timeEnd(logLevel, message) {
return this._getLogFunction(logLevel, message, console.timeEnd ? console.timeEnd : console.info);
}
img.onload = function () {
var _console;
timeStamp(logLevel, message) {
return this._getLogFunction(logLevel, message, console.timeStamp || noop);
}
var args = (0, _formatters.formatImage)(img, message, scale);
group(logLevel, message, opts = { collapsed: false }) {
opts = normalizeArguments({ logLevel, message, opts });
const { collapsed } = opts;
opts.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
(_console = console).log.apply(_console, (0, _toConsumableArray2["default"])(args));
};
return this._getLogFunction(opts);
}
img.src = image;
return noop;
}
groupCollapsed(logLevel, message, opts = {}) {
return this.group(logLevel, message, Object.assign({}, opts, { collapsed: true }));
}
var element = image.nodeName || '';
groupEnd(logLevel) {
return this._getLogFunction(logLevel, '', console.groupEnd || noop);
}
if (element.toLowerCase() === 'img') {
var _console2;
// EXPERIMENTAL
(_console2 = console).log.apply(_console2, (0, _toConsumableArray2["default"])((0, _formatters.formatImage)(image, message, scale)));
withGroup(logLevel, message, func) {
this.group(logLevel, message)();
return noop;
}
try {
func();
} finally {
this.groupEnd(logLevel)();
}
}
if (element.toLowerCase() === 'canvas') {
var _img = new Image();
trace() {
if (console.trace) {
console.trace();
}
}
_img.onload = function () {
var _console3;
// PRIVATE METHODS
return (_console3 = console).log.apply(_console3, (0, _toConsumableArray2["default"])((0, _formatters.formatImage)(_img, message, scale)));
};
_shouldLog(logLevel) {
return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
}
_img.src = image.toDataURL();
return noop;
}
_getLogFunction(logLevel, message, method, args = [], opts) {
if (this._shouldLog(logLevel)) {
// normalized opts + timings
opts = normalizeArguments({ logLevel, message, args, opts });
method = method || opts.method;
assert(method);
return noop;
}
}, {
key: "time",
value: function time(priority, message) {
return this._getLogFunction({
priority: priority,
message: message,
method: console.time ? console.time : console.info
});
}
}, {
key: "timeEnd",
value: function timeEnd(priority, message) {
return this._getLogFunction({
priority: priority,
message: message,
method: console.timeEnd ? console.timeEnd : console.info
});
}
}, {
key: "timeStamp",
value: function timeStamp(priority, message) {
return this._getLogFunction({
priority: priority,
message: message,
method: console.timeStamp || noop
});
}
}, {
key: "group",
value: function group(priority, message) {
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
collapsed: false
};
opts = this._normalizeArguments({
priority: priority,
message: message,
opts: opts
});
var _opts = opts,
collapsed = _opts.collapsed;
return this._getLogFunction({
priority: priority,
message: message,
opts: opts,
method: (collapsed ? console.groupCollapsed : console.group) || console.info
});
}
}, {
key: "groupCollapsed",
value: function groupCollapsed(priority, message) {
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
return this.group(priority, message, Object.assign({}, opts, {
collapsed: true
}));
}
}, {
key: "groupEnd",
value: function groupEnd(priority) {
return this._getLogFunction({
priority: priority,
message: '',
method: console.groupEnd || noop
});
}
}, {
key: "withGroup",
value: function withGroup(priority, message, func) {
var opts = this._normalizeArguments({
priority: priority,
message: message
});
opts.total = this.getTotal();
opts.delta = this.getDelta();
// reset delta timer
this._deltaTs = getHiResTimestamp();
this.group(opts);
const tag = opts.tag || opts.message;
try {
func();
} finally {
this.groupEnd(opts.message);
}
}
}, {
key: "trace",
value: function trace() {
if (console.trace) {
console.trace();
}
}
}, {
key: "_shouldLog",
value: function _shouldLog(priority) {
priority = this._normalizePriority(priority);
return priority === 0 || this.isEnabled() && this.getPriority() >= priority;
}
}, {
key: "_getElapsedTime",
value: function _getElapsedTime() {
var total = this.getTotal();
var delta = this.getDelta();
this._deltaTs = (0, _hiResTimestamp["default"])();
return {
total: total,
delta: delta
};
}
}, {
key: "_getLogFunction",
value: function _getLogFunction(opts) {
if (this._shouldLog(opts.priority)) {
var _opts2 = opts,
method = _opts2.method;
opts = this._parseArguments(opts);
(0, _assert2["default"])(method);
var _opts3 = opts,
message = _opts3.message;
var tag = opts.tag || opts.message;
if (opts.once) {
if (!cache[tag]) {
cache[tag] = (0, _hiResTimestamp["default"])();
} else {
return noop;
}
if (opts.once) {
if (!cache[tag]) {
cache[tag] = getHiResTimestamp();
} else {
return noop;
}
message = this._decorateMessage(message, opts);
return method.bind.apply(method, [console, message].concat((0, _toConsumableArray2["default"])(opts.args)));
}
return noop;
}
}, {
key: "_parseArguments",
value: function _parseArguments(options) {
var normOpts = this._normalizeArguments(options);
// TODO - Make throttling work with groups
// if (opts.nothrottle || !throttle(tag, this.LOG_THROTTLE_TIMEOUT)) {
// return noop;
// }
var _this$_getElapsedTime = this._getElapsedTime(),
delta = _this$_getElapsedTime.delta,
total = _this$_getElapsedTime.total;
message = decorateMessage(this.id, opts.message, opts);
return Object.assign(options, normOpts, {
delta: delta,
total: total
});
// Bind console function so that it can be called after being returned
return method.bind(console, message, ...opts.args);
}
}, {
key: "_normalizePriority",
value: function _normalizePriority(priority) {
var resolvedPriority;
return noop;
}
}
switch ((0, _typeof2["default"])(priority)) {
case 'number':
resolvedPriority = priority;
break;
Log.VERSION = VERSION;
case 'object':
resolvedPriority = priority.priority || 0;
break;
// Get logLevel from first argument:
// - log(logLevel, message, args) => logLevel
// - log(message, args) => 0
// - log({logLevel, ...}, message, args) => logLevel
// - log({logLevel, message, args}) => logLevel
function normalizeLogLevel(logLevel) {
if (!logLevel) {
return 0;
}
let resolvedLevel;
default:
resolvedPriority = 0;
}
switch (typeof logLevel) {
case 'number':
resolvedLevel = logLevel;
break;
(0, _assert2["default"])(Number.isFinite(resolvedPriority) && resolvedPriority >= 0);
return resolvedPriority;
}
}, {
key: "_normalizeArguments",
value: function _normalizeArguments(_ref5) {
var priority = _ref5.priority,
message = _ref5.message,
_ref5$args = _ref5.args,
args = _ref5$args === void 0 ? [] : _ref5$args,
opts = _ref5.opts;
var newOpts = {
priority: this._normalizePriority(priority),
message: message,
args: args
};
case 'object':
// Backward compatibility
// TODO - deprecate `priority`
resolvedLevel = logLevel.logLevel || logLevel.priority || 0;
break;
switch ((0, _typeof2["default"])(priority)) {
case 'string':
case 'function':
if (message !== undefined) {
args.unshift(message);
}
default:
return 0;
}
// 'log level must be a number'
assert(Number.isFinite(resolvedLevel) && resolvedLevel >= 0);
Object.assign(newOpts, {
message: priority
});
break;
return resolvedLevel;
}
case 'object':
Object.assign(newOpts, priority);
break;
// "Normalizes" the various argument patterns into an object with known types
// - log(logLevel, message, args) => {logLevel, message, args}
// - log(message, args) => {logLevel: 0, message, args}
// - log({logLevel, ...}, message, args) => {logLevel, message, args}
// - log({logLevel, message, args}) => {logLevel, message, args}
export function normalizeArguments(opts) {
const { logLevel, message } = opts;
opts.logLevel = normalizeLogLevel(logLevel);
// We use `arguments` instead of rest parameters (...args) because IE
// does not support the syntax. Rest parameters is transpiled to code with
// perf impact. Doing it here instead avoids constructing args when logging is
// disabled.
// TODO - remove when/if IE support is dropped
const args = opts.args ? Array.from(opts.args) : [];
/* eslint-disable no-empty */
// args should only contain arguments that appear after `message`
while (args.length && args.shift() !== message) {}
/* eslint-enable no-empty */
opts.args = args;
default:
switch (typeof logLevel) {
case 'string':
case 'function':
if (message !== undefined) {
args.unshift(message);
}
opts.message = logLevel;
break;
if (typeof newOpts.message === 'function') {
newOpts.message = this._shouldLog(newOpts.priority) ? newOpts.message() : '';
}
case 'object':
Object.assign(opts, logLevel);
break;
(0, _assert2["default"])(typeof newOpts.message === 'string' || (0, _typeof2["default"])(newOpts.message) === 'object');
return Object.assign(newOpts, opts);
}
}, {
key: "_decorateMessage",
value: function _decorateMessage(message, opts) {
if (typeof message === 'string') {
var time = '';
default:
}
if (opts.time) {
var _this$_getElapsedTime2 = this._getElapsedTime(),
total = _this$_getElapsedTime2.total;
// Resolve functions into strings by calling them
if (typeof opts.message === 'function') {
opts.message = opts.message();
}
const messageType = typeof opts.message;
// 'log message must be a string' or object
assert(messageType === 'string' || messageType === 'object');
time = (0, _formatters.leftPad)((0, _formatters.formatTime)(total));
}
// original opts + normalized opts + opts arg + fixed up message
return Object.assign(opts, opts.opts);
}
message = opts.time ? "".concat(this.id, ": ").concat(time, " ").concat(message) : "".concat(this.id, ": ").concat(message);
message = (0, _color.addColor)(message, opts.color, opts.background);
}
function decorateMessage(id, message, opts) {
if (typeof message === 'string') {
const time = opts.time ? leftPad(formatTime(opts.total)) : '';
message = opts.time ? `${id}: ${time} ${message}` : `${id}: ${message}`;
message = addColor(message, opts.color, opts.background);
}
return message;
}
return message;
}
}, {
key: "priority",
set: function set(newPriority) {
this._storage.updateConfiguration({
priority: newPriority
});
// Use the asciify module to log an image under node.js
function logImageInNode({ image, message = '', scale = 1 }) {
// Note: Runtime load of the "asciify-image" module, avoids including in browser bundles
let asciify = null;
try {
asciify = module.require('asciify-image');
} catch (error) {
// asciify not installed, silently ignore
}
if (asciify) {
return () => asciify(image, { fit: 'box', width: `${Math.round(80 * scale)}%` }).then(data => console.log(data));
}
return noop;
}
return this;
},
get: function get() {
return this._storage.config.priority;
}
}]);
return Log;
}();
exports["default"] = Log;
Log.VERSION = _globals.VERSION;
function logImageInBrowser({ image, message = '', scale = 1 }) {
if (typeof image === 'string') {
const img = new Image();
img.onload = () => {
const args = formatImage(img, message, scale);
console.log(...args);
};
img.src = image;
return noop;
}
const element = image.nodeName || '';
if (element.toLowerCase() === 'img') {
console.log(...formatImage(image, message, scale));
return noop;
}
if (element.toLowerCase() === 'canvas') {
const img = new Image();
img.onload = () => console.log(...formatImage(img, message, scale));
img.src = image.toDataURL();
return noop;
}
return noop;
}
//# sourceMappingURL=log.js.map

@@ -1,9 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = assert;
function assert(condition, message) {
export default function assert(condition, message) {
if (!condition) {

@@ -10,0 +3,0 @@ throw new Error(message || 'Assertion failed');

@@ -1,47 +0,36 @@

"use strict";
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.autobind = autobind;
function autobind(obj) {
var predefined = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['constructor'];
var proto = Object.getPrototypeOf(obj);
var propNames = Object.getOwnPropertyNames(proto);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
var _loop = function _loop() {
var key = _step.value;
if (typeof obj[key] === 'function') {
if (!predefined.find(function (name) {
return key === name;
})) {
obj[key] = obj[key].bind(obj);
}
/**
* Binds the "this" argument of all functions on a class instance to the instance
* @param {Object} obj - class instance (typically a react component)
*/
export function autobind(obj, predefined = ['constructor']) {
const proto = Object.getPrototypeOf(obj);
const propNames = Object.getOwnPropertyNames(proto);
for (const key of propNames) {
if (typeof obj[key] === 'function') {
if (!predefined.find(name => key === name)) {
obj[key] = obj[key].bind(obj);
}
};
for (var _iterator = propNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
_loop();
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
_iterator["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
//# sourceMappingURL=autobind.js.map

@@ -1,12 +0,4 @@

"use strict";
import { isBrowser } from './globals';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addColor = addColor;
exports.COLOR = void 0;
var _globals = require("./globals");
var COLOR = {
export const COLOR = {
BLACK: 30,

@@ -20,2 +12,3 @@ RED: 31,

WHITE: 37,
BRIGHT_BLACK: 90,

@@ -30,3 +23,2 @@ BRIGHT_RED: 91,

};
exports.COLOR = COLOR;

@@ -37,17 +29,16 @@ function getColor(color) {

function addColor(string, color, background) {
if (!_globals.isBrowser && typeof string === 'string') {
export function addColor(string, color, background) {
if (!isBrowser && typeof string === 'string') {
if (color) {
color = getColor(color);
string = "\x1B[".concat(color, "m").concat(string, "\x1B[39m");
string = `\u001b[${color}m${string}\u001b[39m`;
}
if (background) {
// background colors values are +10
color = getColor(background);
string = "\x1B[".concat(background + 10, "m").concat(string, "\x1B[49m");
string = `\u001b[${background + 10}m${string}\u001b[49m`;
}
}
return string;
}
//# sourceMappingURL=color.js.map

@@ -1,93 +0,66 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.formatTime = formatTime;
exports.leftPad = leftPad;
exports.rightPad = rightPad;
exports.formatValue = formatValue;
exports.formatImage = formatImage;
function formatTime(ms) {
var formatted;
// TODO: Currently unused, keeping in case we want it later for log formatting
export function formatTime(ms) {
let formatted;
if (ms < 10) {
formatted = "".concat(ms.toFixed(2), "ms");
formatted = `${ms.toFixed(2)}ms`;
} else if (ms < 100) {
formatted = "".concat(ms.toFixed(1), "ms");
formatted = `${ms.toFixed(1)}ms`;
} else if (ms < 1000) {
formatted = "".concat(ms.toFixed(0), "ms");
formatted = `${ms.toFixed(0)}ms`;
} else {
formatted = "".concat((ms / 1000).toFixed(2), "s");
formatted = `${(ms / 1000).toFixed(2)}s`;
}
return formatted;
}
function leftPad(string) {
var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 8;
var padLength = Math.max(length - string.length, 0);
return "".concat(' '.repeat(padLength)).concat(string);
export function leftPad(string, length = 8) {
const padLength = Math.max(length - string.length, 0);
return `${' '.repeat(padLength)}${string}`;
}
function rightPad(string) {
var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 8;
var padLength = Math.max(length - string.length, 0);
return "".concat(string).concat(' '.repeat(padLength));
export function rightPad(string, length = 8) {
const padLength = Math.max(length - string.length, 0);
return `${string}${' '.repeat(padLength)}`;
}
function formatValue(v) {
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var EPSILON = 1e-16;
var _opts$isInteger = opts.isInteger,
isInteger = _opts$isInteger === void 0 ? false : _opts$isInteger;
export function formatValue(v, opts = {}) {
const EPSILON = 1e-16;
const { isInteger = false } = opts;
if (Array.isArray(v) || ArrayBuffer.isView(v)) {
return formatArrayValue(v, opts);
}
if (!Number.isFinite(v)) {
return String(v);
}
if (Math.abs(v) < EPSILON) {
return isInteger ? '0' : '0.';
}
if (isInteger) {
return v.toFixed(0);
}
if (Math.abs(v) > 100 && Math.abs(v) < 10000) {
return v.toFixed(0);
}
var string = v.toPrecision(2);
var decimal = string.indexOf('.0');
const string = v.toPrecision(2);
const decimal = string.indexOf('.0');
return decimal === string.length - 2 ? string.slice(0, -1) : string;
}
// Helper to formatValue
function formatArrayValue(v, opts) {
var _opts$maxElts = opts.maxElts,
maxElts = _opts$maxElts === void 0 ? 16 : _opts$maxElts,
_opts$size = opts.size,
size = _opts$size === void 0 ? 1 : _opts$size;
var string = '[';
for (var i = 0; i < v.length && i < maxElts; ++i) {
const { maxElts = 16, size = 1 } = opts;
let string = '[';
for (let i = 0; i < v.length && i < maxElts; ++i) {
if (i > 0) {
string += ",".concat(i % size === 0 ? ' ' : '');
string += `,${i % size === 0 ? ' ' : ''}`;
}
string += formatValue(v[i], opts);
}
var terminator = v.length > maxElts ? '...' : ']';
return "".concat(string).concat(terminator);
const terminator = v.length > maxElts ? '...' : ']';
return `${string}${terminator}`;
}
function formatImage(image, message, scale) {
var maxWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 600;
var imageUrl = image.src.replace(/\(/g, '%28').replace(/\)/g, '%29');
// Inspired by https://github.com/hughsk/console-image (MIT license)
export function formatImage(image, message, scale, maxWidth = 600) {
const imageUrl = image.src.replace(/\(/g, '%28').replace(/\)/g, '%29');

@@ -98,7 +71,9 @@ if (image.width > maxWidth) {

var width = image.width * scale;
var height = image.height * scale;
var style = ['font-size:1px;', "padding:".concat(Math.floor(height / 2), "px ").concat(Math.floor(width / 2), "px;"), "line-height:".concat(height, "px;"), "background:url(".concat(imageUrl, ");"), "background-size:".concat(width, "px ").concat(height, "px;"), 'color:transparent;'].join('');
return ["".concat(message, " %c+"), style];
const width = image.width * scale;
const height = image.height * scale;
const style = ['font-size:1px;', `padding:${Math.floor(height / 2)}px ${Math.floor(width / 2)}px;`, `line-height:${height}px;`, `background:url(${imageUrl});`, `background-size:${width}px ${height}px;`, 'color:transparent;'].join('');
return [`${message} %c+`, style];
}
//# sourceMappingURL=formatters.js.map

@@ -1,54 +0,10 @@

"use strict";
import checkIfBrowser from '../env/is-browser';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
export { self, window, global, document, process, console } from '../env/globals';
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "self", {
enumerable: true,
get: function get() {
return _globals.self;
}
});
Object.defineProperty(exports, "window", {
enumerable: true,
get: function get() {
return _globals.window;
}
});
Object.defineProperty(exports, "global", {
enumerable: true,
get: function get() {
return _globals.global;
}
});
Object.defineProperty(exports, "document", {
enumerable: true,
get: function get() {
return _globals.document;
}
});
Object.defineProperty(exports, "process", {
enumerable: true,
get: function get() {
return _globals.process;
}
});
Object.defineProperty(exports, "console", {
enumerable: true,
get: function get() {
return _globals.console;
}
});
exports.isBrowser = exports.VERSION = void 0;
// Extract injected version from package.json (injected by babel plugin)
/* global __VERSION__ */
export const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'untranspiled source';
var _isBrowser = _interopRequireDefault(require("../env/is-browser"));
var _globals = require("../env/globals");
var VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'untranspiled source';
exports.VERSION = VERSION;
var isBrowser = (0, _isBrowser["default"])();
exports.isBrowser = isBrowser;
export const isBrowser = checkIfBrowser();
//# sourceMappingURL=globals.js.map

@@ -1,18 +0,33 @@

"use strict";
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getHiResTimestamp;
/**
* Common environment setup
*/
import { window, process, isBrowser } from './globals';
var _globals = require("./globals");
function getHiResTimestamp() {
var timestamp;
if (_globals.isBrowser && _globals.window.performance) {
timestamp = _globals.window.performance.now();
} else if (_globals.process.hrtime) {
var timeParts = _globals.process.hrtime();
export default function getHiResTimestamp() {
let timestamp;
// Get best timer available.
if (isBrowser && window.performance) {
timestamp = window.performance.now();
} else if (process.hrtime) {
const timeParts = process.hrtime();
timestamp = timeParts[0] * 1000 + timeParts[1] / 1e6;

@@ -19,0 +34,0 @@ } else {

@@ -1,18 +0,26 @@

"use strict";
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
/* global window */
function getStorage(type) {
try {
var storage = window[type];
var x = '__storage_test__';
const storage = window[type];
const x = '__storage_test__';
storage.setItem(x, x);

@@ -26,6 +34,5 @@ storage.removeItem(x);

var LocalStorage = function () {
function LocalStorage(id, defaultSettings) {
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'sessionStorage';
(0, _classCallCheck2["default"])(this, LocalStorage);
// Store keys in local storage via simple interface
export default class LocalStorage {
constructor(id, defaultSettings, type = 'sessionStorage') {
this.storage = getStorage(type);

@@ -35,47 +42,34 @@ this.id = id;

Object.assign(this.config, defaultSettings);
this._loadConfiguration();
}
(0, _createClass2["default"])(LocalStorage, [{
key: "getConfiguration",
value: function getConfiguration() {
return this.config;
}
}, {
key: "setConfiguration",
value: function setConfiguration(configuration) {
this.config = {};
return this.updateConfiguration(configuration);
}
}, {
key: "updateConfiguration",
value: function updateConfiguration(configuration) {
Object.assign(this.config, configuration);
getConfiguration() {
return this.config;
}
if (this.storage) {
var serialized = JSON.stringify(this.config);
this.storage.setItem(this.id, serialized);
}
setConfiguration(configuration) {
this.config = {};
return this.updateConfiguration(configuration);
}
return this;
updateConfiguration(configuration) {
Object.assign(this.config, configuration);
if (this.storage) {
const serialized = JSON.stringify(this.config);
this.storage.setItem(this.id, serialized);
}
}, {
key: "_loadConfiguration",
value: function _loadConfiguration() {
var configuration = {};
return this;
}
if (this.storage) {
var serializedConfiguration = this.storage.getItem(this.id);
configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {};
}
Object.assign(this.config, configuration);
return this;
// Get config from persistent store, if available
_loadConfiguration() {
let configuration = {};
if (this.storage) {
const serializedConfiguration = this.storage.getItem(this.id);
configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {};
}
}]);
return LocalStorage;
}();
exports["default"] = LocalStorage;
Object.assign(this.config, configuration);
return this;
}
}
//# sourceMappingURL=local-storage.js.map

@@ -0,7 +1,35 @@

// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// This function is needed in initialization stages,
// make sure it can be imported in isolation
import { window } from './globals';
import isBrowser from './is-browser';
import isElectron from './is-electron';
export function isMobile() {
return typeof window.orientation !== 'undefined';
}
// Simple browser detection
// `mockUserAgent` parameter allows user agent to be overridden for testing
/* eslint-disable complexity */
export default function getBrowser(mockUserAgent) {

@@ -16,30 +44,27 @@ if (!mockUserAgent && !isBrowser()) {

/* global navigator */
const navigator_ = typeof navigator !== 'undefined' ? navigator : {};
const userAgent = mockUserAgent || navigator_.userAgent || '';
// const appVersion = navigator_.appVersion || '';
// NOTE: Order of tests matter, as many agents list Chrome etc.
if (userAgent.indexOf('Edge') > -1) {
return 'Edge';
}
const isMSIE = userAgent.indexOf('MSIE ') !== -1;
const isTrident = userAgent.indexOf('Trident/') !== -1;
if (isMSIE || isTrident) {
return 'IE';
}
if (window.chrome) {
return 'Chrome';
}
if (window.safari) {
return 'Safari';
}
if (window.mozInnerScreenX) {
return 'Firefox';
}
return 'Unknown';
}
//# sourceMappingURL=get-browser.js.map

@@ -0,1 +1,3 @@

/* global self, window, global, document, console, process */
/* eslint-disable no-restricted-globals */
const globals = {

@@ -8,2 +10,3 @@ self: typeof self !== 'undefined' && self,

};
const self_ = globals.self || globals.window || globals.global;

@@ -15,3 +18,4 @@ const window_ = globals.window || globals.self || globals.global;

const console_ = console;
export { self_ as self, window_ as window, global_ as global, document_ as document, process_ as process, console_ as console };
//# sourceMappingURL=globals.js.map

@@ -0,1 +1,2 @@

// ENVIRONMENT
export { self, window, global, document, process, console } from './globals';

@@ -2,0 +3,0 @@ export { default as isBrowser, isBrowserMainThread } from './is-browser';

@@ -0,6 +1,15 @@

// This function is needed in initialization stages,
// make sure it can be imported in isolation
/* global process */
import isElectron from './is-electron';
export default function isBrowser() {
// Check if in browser by duck-typing Node context
const isNode = typeof process === 'object' && String(process) === '[object process]' && !process.browser;
return !isNode || isElectron();
}
// document does not exist on worker thread
export function isBrowserMainThread() {

@@ -7,0 +16,0 @@ return isBrowser() && typeof document !== 'undefined';

@@ -0,19 +1,22 @@

// based on https://github.com/cheton/is-electron
// https://github.com/electron/electron/issues/2288
/* global window, process, navigator */
/* eslint-disable complexity */
export default function isElectron(mockUserAgent) {
// Renderer process
if (typeof window !== 'undefined' && typeof window.process === 'object' && window.process.type === 'renderer') {
return true;
}
// Main process
if (typeof process !== 'undefined' && typeof process.versions === 'object' && Boolean(process.versions.electron)) {
return true;
}
// Detect the user agent when the `nodeIntegration` option is set to true
const realUserAgent = typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent;
const userAgent = mockUserAgent || realUserAgent;
if (userAgent && userAgent.indexOf('Electron') >= 0) {
return true;
}
return false;
}
//# sourceMappingURL=is-electron.js.map
import './init';
import { default as Log } from './lib/log';
export { VERSION } from './utils/globals';
// ENVIRONMENT
export { self, window, global, document, process, console } from './env/globals';

@@ -8,10 +11,14 @@ export { default as isBrowser, isBrowserMainThread } from './env/is-browser';

export { default as isElectron } from './env/is-electron';
// ENVIRONMENT'S ASSERT IS 5-15KB, SO WE PROVIDE OUR OWN
export { default as assert } from './utils/assert';
export { default as Stats } from './lib/stats';
export { default as Stat } from './lib/stat';
// LOGGING
export { default as Log } from './lib/log';
export { COLOR } from './utils/color';
export default new Log({
id: 'probe.gl'
});
// DEFAULT EXPORT IS A LOG INSTANCE
export default new Log({ id: 'probe.gl' });
// UTILITIES
export { addColor } from './utils/color';

@@ -22,2 +29,5 @@ export { leftPad, rightPad } from './utils/formatters';

export { default as getHiResTimestamp } from './utils/hi-res-timestamp';
// DEPRECATED (Should be imported directly from @probe.gl/stats)
export { Stats, Stat } from '@probe.gl/stats';
//# sourceMappingURL=index.js.map

@@ -0,1 +1,23 @@

// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/* eslint-disable no-console, no-try-catch */
/* global console */
import { VERSION, isBrowser } from '../utils/globals';

@@ -8,2 +30,7 @@ import LocalStorage from '../utils/local-storage';

import getHiResTimestamp from '../utils/hi-res-timestamp';
/* eslint-disable no-console */
/* global console, Image */
// Instrumentation in other packages may override console methods, so preserve them here
const originalConsole = {

@@ -16,5 +43,6 @@ debug: isBrowser ? console.debug || console.log : console.log,

};
const DEFAULT_SETTINGS = {
enabled: false,
priority: 0
enabled: true,
level: 0
};

@@ -25,3 +53,32 @@

const cache = {};
const ONCE = { once: true };
/*
function throttle(tag, timeout) {
const prevTime = cache[tag];
const time = Date.now();
if (!prevTime || (time - prevTime > timeout)) {
cache[tag] = time;
return true;
}
return false;
}
// Assertions don't generate standard exceptions and don't print nicely
function checkForAssertionErrors(args) {
const isAssertion =
args &&
args.length > 0 &&
typeof args[0] === 'object' &&
args[0] !== null &&
args[0].name === 'AssertionError';
if (isAssertion) {
args = Array.prototype.slice.call(args);
args.unshift(`assert(${args[0].message})`);
}
return args;
}
*/
function getTableHeader(table) {

@@ -33,11 +90,9 @@ for (const key in table) {

}
return 'empty';
}
// A console wrapper
export default class Log {
constructor() {
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
id = _ref.id;
constructor({ id } = {}) {
this.id = id;

@@ -47,6 +102,9 @@ this.VERSION = VERSION;

this._deltaTs = getHiResTimestamp();
this.LOG_THROTTLE_TIMEOUT = 0;
this._storage = new LocalStorage("__probe-".concat(this.id, "__"), DEFAULT_SETTINGS);
// TODO - fix support from throttling groups
this.LOG_THROTTLE_TIMEOUT = 0; // Time before throttled messages are logged again
this._storage = new LocalStorage(`__probe-${this.id}__`, DEFAULT_SETTINGS);
this.userData = {};
this.timeStamp("".concat(this.id, " started"));
this.timeStamp(`${this.id} started`);
autobind(this);

@@ -56,12 +114,8 @@ Object.seal(this);

set priority(newPriority) {
this._storage.updateConfiguration({
priority: newPriority
});
return this;
set level(newLevel) {
this.setLevel(newLevel);
}
get priority() {
return this._storage.config.priority;
get level() {
return this.getLevel();
}

@@ -73,10 +127,7 @@

getPriority() {
return this._storage.config.priority;
}
getLevel() {
return this._storage.config.priority;
return this._storage.config.level;
}
// @return {Number} milliseconds, with fractions
getTotal() {

@@ -86,2 +137,3 @@ return Number((getHiResTimestamp() - this._startTs).toPrecision(10));

// @return {Number} milliseconds, with fractions
getDelta() {

@@ -91,9 +143,19 @@ return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10));

enable() {
let enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
// Deprecated
set priority(newPriority) {
this.level = newPriority;
}
this._storage.updateConfiguration({
enabled
});
get priority() {
return this.level;
}
getPriority() {
return this.level;
}
// Configure
enable(enabled = true) {
this._storage.updateConfiguration({ enabled });
return this;

@@ -103,9 +165,8 @@ }

setLevel(level) {
this._storage.updateConfiguration({
priority: level
});
this._storage.updateConfiguration({ level });
return this;
}
// Unconditional logging
assert(condition, message) {

@@ -115,45 +176,26 @@ assert(condition, message);

// Warn, but only once, no console flooding
warn(message) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return this._getLogFunction({
message,
args,
method: originalConsole.warn,
once: true
});
return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
}
// Print an error
error(message) {
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
return this._getLogFunction({
message,
args,
method: originalConsole.error
});
return this._getLogFunction(0, message, originalConsole.error, arguments);
}
deprecated(oldUsage, newUsage) {
return this.warn("`".concat(oldUsage, "` is deprecated and will be removed in a later version. Use `").concat(newUsage, "` instead"));
return this.warn(`\`${oldUsage}\` is deprecated and will be removed \
in a later version. Use \`${newUsage}\` instead`);
}
removed(oldUsage, newUsage) {
return this.error("`".concat(oldUsage, "` has been removed. Use `").concat(newUsage, "` instead"));
return this.error(`\`${oldUsage}\` has been removed. Use \`${newUsage}\` instead`);
}
probe(priority, message) {
for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
args[_key3 - 2] = arguments[_key3];
}
// Conditional logging
return this._getLogFunction({
priority,
message,
args,
method: originalConsole.log,
// Log to a group
probe(logLevel, message) {
return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {
time: true,

@@ -164,80 +206,36 @@ once: true

log(priority, message) {
for (var _len4 = arguments.length, args = new Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) {
args[_key4 - 2] = arguments[_key4];
}
return this._getLogFunction({
priority,
message,
args,
method: originalConsole.debug
});
// Log a debug message
log(logLevel, message) {
return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
}
info(priority, message) {
for (var _len5 = arguments.length, args = new Array(_len5 > 2 ? _len5 - 2 : 0), _key5 = 2; _key5 < _len5; _key5++) {
args[_key5 - 2] = arguments[_key5];
}
return this._getLogFunction({
priority,
message,
args,
method: console.info
});
// Log a normal message
info(logLevel, message) {
return this._getLogFunction(logLevel, message, console.info, arguments);
}
once(priority, message) {
for (var _len6 = arguments.length, args = new Array(_len6 > 2 ? _len6 - 2 : 0), _key6 = 2; _key6 < _len6; _key6++) {
args[_key6 - 2] = arguments[_key6];
}
return this._getLogFunction({
priority,
message,
args,
method: originalConsole.debug || originalConsole.info,
once: true
});
// Log a normal message, but only once, no console flooding
once(logLevel, message) {
return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);
}
table(priority, table, columns) {
// Logs an object as a table
table(logLevel, table, columns) {
if (table) {
const tag = getTableHeader(table);
return this._getLogFunction({
priority,
message: table,
args: columns && [columns],
tag,
method: console.table || noop
return this._getLogFunction(logLevel, table, console.table || noop, columns && [columns], {
tag: getTableHeader(table)
});
}
return noop;
}
image(_ref2) {
let priority = _ref2.priority,
image = _ref2.image,
_ref2$message = _ref2.message,
message = _ref2$message === void 0 ? '' : _ref2$message,
_ref2$scale = _ref2.scale,
scale = _ref2$scale === void 0 ? 1 : _ref2$scale;
if (priority > this.getPriority()) {
// logs an image under Chrome
image({ logLevel, priority, image, message = '', scale = 1 }) {
if (!this._shouldLog(logLevel || priority)) {
return noop;
}
return isBrowser ? this._logImageInBrowser({
image,
message,
scale
}) : this._logImageInNode({
image,
message,
scale
});
return isBrowser ? logImageInBrowser({ image, message, scale }) : logImageInNode({ image, message, scale });
}
// Logs the current settings as a table
settings() {

@@ -251,2 +249,3 @@ if (console.table) {

// logs the current status of the setting
get(setting) {

@@ -256,138 +255,44 @@ return this._storage.config[setting];

// update the status of the setting
set(setting, value) {
this._storage.updateConfiguration({
[setting]: value
});
this._storage.updateConfiguration({ [setting]: value });
}
_logImageInNode(_ref3) {
let image = _ref3.image,
_ref3$message = _ref3.message,
message = _ref3$message === void 0 ? '' : _ref3$message,
_ref3$scale = _ref3.scale,
scale = _ref3$scale === void 0 ? 1 : _ref3$scale;
let asciify = null;
try {
asciify = module.require('asciify-image');
} catch (error) {}
if (asciify) {
return () => asciify(image, {
fit: 'box',
width: "".concat(Math.round(80 * scale), "%")
}).then(data => console.log(data));
}
return noop;
time(logLevel, message) {
return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);
}
_logImageInBrowser(_ref4) {
let image = _ref4.image,
_ref4$message = _ref4.message,
message = _ref4$message === void 0 ? '' : _ref4$message,
_ref4$scale = _ref4.scale,
scale = _ref4$scale === void 0 ? 1 : _ref4$scale;
if (typeof image === 'string') {
const img = new Image();
img.onload = () => {
const args = formatImage(img, message, scale);
console.log(...args);
};
img.src = image;
return noop;
}
const element = image.nodeName || '';
if (element.toLowerCase() === 'img') {
console.log(...formatImage(image, message, scale));
return noop;
}
if (element.toLowerCase() === 'canvas') {
const img = new Image();
img.onload = () => console.log(...formatImage(img, message, scale));
img.src = image.toDataURL();
return noop;
}
return noop;
timeEnd(logLevel, message) {
return this._getLogFunction(logLevel, message, console.timeEnd ? console.timeEnd : console.info);
}
time(priority, message) {
return this._getLogFunction({
priority,
message,
method: console.time ? console.time : console.info
});
timeStamp(logLevel, message) {
return this._getLogFunction(logLevel, message, console.timeStamp || noop);
}
timeEnd(priority, message) {
return this._getLogFunction({
priority,
message,
method: console.timeEnd ? console.timeEnd : console.info
});
}
group(logLevel, message, opts = { collapsed: false }) {
opts = normalizeArguments({ logLevel, message, opts });
const { collapsed } = opts;
opts.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
timeStamp(priority, message) {
return this._getLogFunction({
priority,
message,
method: console.timeStamp || noop
});
return this._getLogFunction(opts);
}
group(priority, message) {
let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
collapsed: false
};
opts = this._normalizeArguments({
priority,
message,
opts
});
const _opts = opts,
collapsed = _opts.collapsed;
return this._getLogFunction({
priority,
message,
opts,
method: (collapsed ? console.groupCollapsed : console.group) || console.info
});
groupCollapsed(logLevel, message, opts = {}) {
return this.group(logLevel, message, Object.assign({}, opts, { collapsed: true }));
}
groupCollapsed(priority, message) {
let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
return this.group(priority, message, Object.assign({}, opts, {
collapsed: true
}));
groupEnd(logLevel) {
return this._getLogFunction(logLevel, '', console.groupEnd || noop);
}
groupEnd(priority) {
return this._getLogFunction({
priority,
message: '',
method: console.groupEnd || noop
});
}
// EXPERIMENTAL
withGroup(priority, message, func) {
const opts = this._normalizeArguments({
priority,
message
});
withGroup(logLevel, message, func) {
this.group(logLevel, message)();
this.group(opts);
try {
func();
} finally {
this.groupEnd(opts.message);
this.groupEnd(logLevel)();
}

@@ -402,25 +307,20 @@ }

_shouldLog(priority) {
priority = this._normalizePriority(priority);
return priority === 0 || this.isEnabled() && this.getPriority() >= priority;
}
// PRIVATE METHODS
_getElapsedTime() {
const total = this.getTotal();
const delta = this.getDelta();
this._deltaTs = getHiResTimestamp();
return {
total,
delta
};
_shouldLog(logLevel) {
return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
}
_getLogFunction(opts) {
if (this._shouldLog(opts.priority)) {
const _opts2 = opts,
method = _opts2.method;
opts = this._parseArguments(opts);
_getLogFunction(logLevel, message, method, args = [], opts) {
if (this._shouldLog(logLevel)) {
// normalized opts + timings
opts = normalizeArguments({ logLevel, message, args, opts });
method = method || opts.method;
assert(method);
let _opts3 = opts,
message = _opts3.message;
opts.total = this.getTotal();
opts.delta = this.getDelta();
// reset delta timer
this._deltaTs = getHiResTimestamp();
const tag = opts.tag || opts.message;

@@ -436,101 +336,144 @@

message = this._decorateMessage(message, opts);
// TODO - Make throttling work with groups
// if (opts.nothrottle || !throttle(tag, this.LOG_THROTTLE_TIMEOUT)) {
// return noop;
// }
message = decorateMessage(this.id, opts.message, opts);
// Bind console function so that it can be called after being returned
return method.bind(console, message, ...opts.args);
}
return noop;
}
}
_parseArguments(options) {
const normOpts = this._normalizeArguments(options);
Log.VERSION = VERSION;
const _this$_getElapsedTime = this._getElapsedTime(),
delta = _this$_getElapsedTime.delta,
total = _this$_getElapsedTime.total;
return Object.assign(options, normOpts, {
delta,
total
});
// Get logLevel from first argument:
// - log(logLevel, message, args) => logLevel
// - log(message, args) => 0
// - log({logLevel, ...}, message, args) => logLevel
// - log({logLevel, message, args}) => logLevel
function normalizeLogLevel(logLevel) {
if (!logLevel) {
return 0;
}
let resolvedLevel;
_normalizePriority(priority) {
let resolvedPriority;
switch (typeof logLevel) {
case 'number':
resolvedLevel = logLevel;
break;
switch (typeof priority) {
case 'number':
resolvedPriority = priority;
break;
case 'object':
// Backward compatibility
// TODO - deprecate `priority`
resolvedLevel = logLevel.logLevel || logLevel.priority || 0;
break;
case 'object':
resolvedPriority = priority.priority || 0;
break;
default:
resolvedPriority = 0;
}
assert(Number.isFinite(resolvedPriority) && resolvedPriority >= 0);
return resolvedPriority;
default:
return 0;
}
// 'log level must be a number'
assert(Number.isFinite(resolvedLevel) && resolvedLevel >= 0);
_normalizeArguments(_ref5) {
let priority = _ref5.priority,
message = _ref5.message,
_ref5$args = _ref5.args,
args = _ref5$args === void 0 ? [] : _ref5$args,
opts = _ref5.opts;
const newOpts = {
priority: this._normalizePriority(priority),
message,
args
};
return resolvedLevel;
}
switch (typeof priority) {
case 'string':
case 'function':
if (message !== undefined) {
args.unshift(message);
}
// "Normalizes" the various argument patterns into an object with known types
// - log(logLevel, message, args) => {logLevel, message, args}
// - log(message, args) => {logLevel: 0, message, args}
// - log({logLevel, ...}, message, args) => {logLevel, message, args}
// - log({logLevel, message, args}) => {logLevel, message, args}
export function normalizeArguments(opts) {
const { logLevel, message } = opts;
opts.logLevel = normalizeLogLevel(logLevel);
// We use `arguments` instead of rest parameters (...args) because IE
// does not support the syntax. Rest parameters is transpiled to code with
// perf impact. Doing it here instead avoids constructing args when logging is
// disabled.
// TODO - remove when/if IE support is dropped
const args = opts.args ? Array.from(opts.args) : [];
/* eslint-disable no-empty */
// args should only contain arguments that appear after `message`
while (args.length && args.shift() !== message) {}
/* eslint-enable no-empty */
opts.args = args;
Object.assign(newOpts, {
message: priority
});
break;
switch (typeof logLevel) {
case 'string':
case 'function':
if (message !== undefined) {
args.unshift(message);
}
opts.message = logLevel;
break;
case 'object':
Object.assign(newOpts, priority);
break;
case 'object':
Object.assign(opts, logLevel);
break;
default:
}
default:
}
if (typeof newOpts.message === 'function') {
newOpts.message = this._shouldLog(newOpts.priority) ? newOpts.message() : '';
}
assert(typeof newOpts.message === 'string' || typeof newOpts.message === 'object');
return Object.assign(newOpts, opts);
// Resolve functions into strings by calling them
if (typeof opts.message === 'function') {
opts.message = opts.message();
}
const messageType = typeof opts.message;
// 'log message must be a string' or object
assert(messageType === 'string' || messageType === 'object');
_decorateMessage(message, opts) {
if (typeof message === 'string') {
let time = '';
// original opts + normalized opts + opts arg + fixed up message
return Object.assign(opts, opts.opts);
}
if (opts.time) {
const _this$_getElapsedTime2 = this._getElapsedTime(),
total = _this$_getElapsedTime2.total;
function decorateMessage(id, message, opts) {
if (typeof message === 'string') {
const time = opts.time ? leftPad(formatTime(opts.total)) : '';
message = opts.time ? `${id}: ${time} ${message}` : `${id}: ${message}`;
message = addColor(message, opts.color, opts.background);
}
return message;
}
time = leftPad(formatTime(total));
}
// Use the asciify module to log an image under node.js
function logImageInNode({ image, message = '', scale = 1 }) {
// Note: Runtime load of the "asciify-image" module, avoids including in browser bundles
let asciify = null;
try {
asciify = module.require('asciify-image');
} catch (error) {
// asciify not installed, silently ignore
}
if (asciify) {
return () => asciify(image, { fit: 'box', width: `${Math.round(80 * scale)}%` }).then(data => console.log(data));
}
return noop;
}
message = opts.time ? "".concat(this.id, ": ").concat(time, " ").concat(message) : "".concat(this.id, ": ").concat(message);
message = addColor(message, opts.color, opts.background);
}
return message;
function logImageInBrowser({ image, message = '', scale = 1 }) {
if (typeof image === 'string') {
const img = new Image();
img.onload = () => {
const args = formatImage(img, message, scale);
console.log(...args);
};
img.src = image;
return noop;
}
const element = image.nodeName || '';
if (element.toLowerCase() === 'img') {
console.log(...formatImage(image, message, scale));
return noop;
}
if (element.toLowerCase() === 'canvas') {
const img = new Image();
img.onload = () => console.log(...formatImage(img, message, scale));
img.src = image.toDataURL();
return noop;
}
return noop;
}
Log.VERSION = VERSION;
//# sourceMappingURL=log.js.map

@@ -1,6 +0,28 @@

export function autobind(obj) {
let predefined = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['constructor'];
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/**
* Binds the "this" argument of all functions on a class instance to the instance
* @param {Object} obj - class instance (typically a react component)
*/
export function autobind(obj, predefined = ['constructor']) {
const proto = Object.getPrototypeOf(obj);
const propNames = Object.getOwnPropertyNames(proto);
for (const key of propNames) {

@@ -7,0 +29,0 @@ if (typeof obj[key] === 'function') {

import { isBrowser } from './globals';
export const COLOR = {

@@ -11,2 +12,3 @@ BLACK: 30,

WHITE: 37,
BRIGHT_BLACK: 90,

@@ -30,13 +32,12 @@ BRIGHT_RED: 91,

color = getColor(color);
string = "\x1B[".concat(color, "m").concat(string, "\x1B[39m");
string = `\u001b[${color}m${string}\u001b[39m`;
}
if (background) {
// background colors values are +10
color = getColor(background);
string = "\x1B[".concat(background + 10, "m").concat(string, "\x1B[49m");
string = `\u001b[${background + 10}m${string}\u001b[49m`;
}
}
return string;
}
//# sourceMappingURL=color.js.map

@@ -0,52 +1,44 @@

// TODO: Currently unused, keeping in case we want it later for log formatting
export function formatTime(ms) {
let formatted;
if (ms < 10) {
formatted = "".concat(ms.toFixed(2), "ms");
formatted = `${ms.toFixed(2)}ms`;
} else if (ms < 100) {
formatted = "".concat(ms.toFixed(1), "ms");
formatted = `${ms.toFixed(1)}ms`;
} else if (ms < 1000) {
formatted = "".concat(ms.toFixed(0), "ms");
formatted = `${ms.toFixed(0)}ms`;
} else {
formatted = "".concat((ms / 1000).toFixed(2), "s");
formatted = `${(ms / 1000).toFixed(2)}s`;
}
return formatted;
}
export function leftPad(string) {
let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 8;
export function leftPad(string, length = 8) {
const padLength = Math.max(length - string.length, 0);
return "".concat(' '.repeat(padLength)).concat(string);
return `${' '.repeat(padLength)}${string}`;
}
export function rightPad(string) {
let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 8;
export function rightPad(string, length = 8) {
const padLength = Math.max(length - string.length, 0);
return "".concat(string).concat(' '.repeat(padLength));
return `${string}${' '.repeat(padLength)}`;
}
export function formatValue(v) {
let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
export function formatValue(v, opts = {}) {
const EPSILON = 1e-16;
const _opts$isInteger = opts.isInteger,
isInteger = _opts$isInteger === void 0 ? false : _opts$isInteger;
const { isInteger = false } = opts;
if (Array.isArray(v) || ArrayBuffer.isView(v)) {
return formatArrayValue(v, opts);
}
if (!Number.isFinite(v)) {
return String(v);
}
if (Math.abs(v) < EPSILON) {
return isInteger ? '0' : '0.';
}
if (isInteger) {
return v.toFixed(0);
}
if (Math.abs(v) > 100 && Math.abs(v) < 10000) {
return v.toFixed(0);
}
const string = v.toPrecision(2);

@@ -57,23 +49,18 @@ const decimal = string.indexOf('.0');

// Helper to formatValue
function formatArrayValue(v, opts) {
const _opts$maxElts = opts.maxElts,
maxElts = _opts$maxElts === void 0 ? 16 : _opts$maxElts,
_opts$size = opts.size,
size = _opts$size === void 0 ? 1 : _opts$size;
const { maxElts = 16, size = 1 } = opts;
let string = '[';
for (let i = 0; i < v.length && i < maxElts; ++i) {
if (i > 0) {
string += ",".concat(i % size === 0 ? ' ' : '');
string += `,${i % size === 0 ? ' ' : ''}`;
}
string += formatValue(v[i], opts);
}
const terminator = v.length > maxElts ? '...' : ']';
return "".concat(string).concat(terminator);
return `${string}${terminator}`;
}
export function formatImage(image, message, scale) {
let maxWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 600;
// Inspired by https://github.com/hughsk/console-image (MIT license)
export function formatImage(image, message, scale, maxWidth = 600) {
const imageUrl = image.src.replace(/\(/g, '%28').replace(/\)/g, '%29');

@@ -87,5 +74,7 @@

const height = image.height * scale;
const style = ['font-size:1px;', "padding:".concat(Math.floor(height / 2), "px ").concat(Math.floor(width / 2), "px;"), "line-height:".concat(height, "px;"), "background:url(".concat(imageUrl, ");"), "background-size:".concat(width, "px ").concat(height, "px;"), 'color:transparent;'].join('');
return ["".concat(message, " %c+"), style];
const style = ['font-size:1px;', `padding:${Math.floor(height / 2)}px ${Math.floor(width / 2)}px;`, `line-height:${height}px;`, `background:url(${imageUrl});`, `background-size:${width}px ${height}px;`, 'color:transparent;'].join('');
return [`${message} %c+`, style];
}
//# sourceMappingURL=formatters.js.map
import checkIfBrowser from '../env/is-browser';
export { self, window, global, document, process, console } from '../env/globals';
// Extract injected version from package.json (injected by babel plugin)
/* global __VERSION__ */
export const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'untranspiled source';
export const isBrowser = checkIfBrowser();
//# sourceMappingURL=globals.js.map

@@ -0,5 +1,29 @@

// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/**
* Common environment setup
*/
import { window, process, isBrowser } from './globals';
export default function getHiResTimestamp() {
let timestamp;
// Get best timer available.
if (isBrowser && window.performance) {

@@ -6,0 +30,0 @@ timestamp = window.performance.now();

@@ -0,1 +1,22 @@

// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/* global window */
function getStorage(type) {

@@ -13,5 +34,5 @@ try {

// Store keys in local storage via simple interface
export default class LocalStorage {
constructor(id, defaultSettings) {
let type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'sessionStorage';
constructor(id, defaultSettings, type = 'sessionStorage') {
this.storage = getStorage(type);

@@ -21,3 +42,2 @@ this.id = id;

Object.assign(this.config, defaultSettings);
this._loadConfiguration();

@@ -37,3 +57,2 @@ }

Object.assign(this.config, configuration);
if (this.storage) {

@@ -43,9 +62,8 @@ const serialized = JSON.stringify(this.config);

}
return this;
}
// Get config from persistent store, if available
_loadConfiguration() {
let configuration = {};
if (this.storage) {

@@ -55,8 +73,6 @@ const serializedConfiguration = this.storage.getItem(this.id);

}
Object.assign(this.config, configuration);
return this;
}
}
//# sourceMappingURL=local-storage.js.map

@@ -0,7 +1,35 @@

// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// This function is needed in initialization stages,
// make sure it can be imported in isolation
import { window } from './globals';
import isBrowser from './is-browser';
import isElectron from './is-electron';
export function isMobile() {
return typeof window.orientation !== 'undefined';
}
// Simple browser detection
// `mockUserAgent` parameter allows user agent to be overridden for testing
/* eslint-disable complexity */
export default function getBrowser(mockUserAgent) {

@@ -16,30 +44,27 @@ if (!mockUserAgent && !isBrowser()) {

var navigator_ = typeof navigator !== 'undefined' ? navigator : {};
var userAgent = mockUserAgent || navigator_.userAgent || '';
/* global navigator */
const navigator_ = typeof navigator !== 'undefined' ? navigator : {};
const userAgent = mockUserAgent || navigator_.userAgent || '';
// const appVersion = navigator_.appVersion || '';
// NOTE: Order of tests matter, as many agents list Chrome etc.
if (userAgent.indexOf('Edge') > -1) {
return 'Edge';
}
var isMSIE = userAgent.indexOf('MSIE ') !== -1;
var isTrident = userAgent.indexOf('Trident/') !== -1;
const isMSIE = userAgent.indexOf('MSIE ') !== -1;
const isTrident = userAgent.indexOf('Trident/') !== -1;
if (isMSIE || isTrident) {
return 'IE';
}
if (window.chrome) {
return 'Chrome';
}
if (window.safari) {
return 'Safari';
}
if (window.mozInnerScreenX) {
return 'Firefox';
}
return 'Unknown';
}
//# sourceMappingURL=get-browser.js.map

@@ -1,3 +0,4 @@

import _typeof from "@babel/runtime/helpers/esm/typeof";
var globals = {
/* global self, window, global, document, console, process */
/* eslint-disable no-restricted-globals */
const globals = {
self: typeof self !== 'undefined' && self,

@@ -7,11 +8,13 @@ window: typeof window !== 'undefined' && window,

document: typeof document !== 'undefined' && document,
process: (typeof process === "undefined" ? "undefined" : _typeof(process)) === 'object' && process
process: typeof process === 'object' && process
};
var self_ = globals.self || globals.window || globals.global;
var window_ = globals.window || globals.self || globals.global;
var global_ = globals.global || globals.self || globals.window;
var document_ = globals.document || {};
var process_ = globals.process || {};
var console_ = console;
const self_ = globals.self || globals.window || globals.global;
const window_ = globals.window || globals.self || globals.global;
const global_ = globals.global || globals.self || globals.window;
const document_ = globals.document || {};
const process_ = globals.process || {};
const console_ = console;
export { self_ as self, window_ as window, global_ as global, document_ as document, process_ as process, console_ as console };
//# sourceMappingURL=globals.js.map

@@ -0,1 +1,2 @@

// ENVIRONMENT
export { self, window, global, document, process, console } from './globals';

@@ -2,0 +3,0 @@ export { default as isBrowser, isBrowserMainThread } from './is-browser';

@@ -1,7 +0,15 @@

import _typeof from "@babel/runtime/helpers/esm/typeof";
// This function is needed in initialization stages,
// make sure it can be imported in isolation
/* global process */
import isElectron from './is-electron';
export default function isBrowser() {
var isNode = (typeof process === "undefined" ? "undefined" : _typeof(process)) === 'object' && String(process) === '[object process]' && !process.browser;
// Check if in browser by duck-typing Node context
const isNode = typeof process === 'object' && String(process) === '[object process]' && !process.browser;
return !isNode || isElectron();
}
// document does not exist on worker thread
export function isBrowserMainThread() {

@@ -8,0 +16,0 @@ return isBrowser() && typeof document !== 'undefined';

@@ -1,20 +0,22 @@

import _typeof from "@babel/runtime/helpers/esm/typeof";
// based on https://github.com/cheton/is-electron
// https://github.com/electron/electron/issues/2288
/* global window, process, navigator */
/* eslint-disable complexity */
export default function isElectron(mockUserAgent) {
if (typeof window !== 'undefined' && _typeof(window.process) === 'object' && window.process.type === 'renderer') {
// Renderer process
if (typeof window !== 'undefined' && typeof window.process === 'object' && window.process.type === 'renderer') {
return true;
}
if (typeof process !== 'undefined' && _typeof(process.versions) === 'object' && Boolean(process.versions.electron)) {
// Main process
if (typeof process !== 'undefined' && typeof process.versions === 'object' && Boolean(process.versions.electron)) {
return true;
}
var realUserAgent = (typeof navigator === "undefined" ? "undefined" : _typeof(navigator)) === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent;
var userAgent = mockUserAgent || realUserAgent;
// Detect the user agent when the `nodeIntegration` option is set to true
const realUserAgent = typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent;
const userAgent = mockUserAgent || realUserAgent;
if (userAgent && userAgent.indexOf('Electron') >= 0) {
return true;
}
return false;
}
//# sourceMappingURL=is-electron.js.map
import './init';
import { default as Log } from './lib/log';
export { VERSION } from './utils/globals';
// ENVIRONMENT
export { self, window, global, document, process, console } from './env/globals';

@@ -8,10 +11,14 @@ export { default as isBrowser, isBrowserMainThread } from './env/is-browser';

export { default as isElectron } from './env/is-electron';
// ENVIRONMENT'S ASSERT IS 5-15KB, SO WE PROVIDE OUR OWN
export { default as assert } from './utils/assert';
export { default as Stats } from './lib/stats';
export { default as Stat } from './lib/stat';
// LOGGING
export { default as Log } from './lib/log';
export { COLOR } from './utils/color';
export default new Log({
id: 'probe.gl'
});
// DEFAULT EXPORT IS A LOG INSTANCE
export default new Log({ id: 'probe.gl' });
// UTILITIES
export { addColor } from './utils/color';

@@ -22,2 +29,5 @@ export { leftPad, rightPad } from './utils/formatters';

export { default as getHiResTimestamp } from './utils/hi-res-timestamp';
// DEPRECATED (Should be imported directly from @probe.gl/stats)
export { Stats, Stat } from '@probe.gl/stats';
//# sourceMappingURL=index.js.map

@@ -1,6 +0,23 @@

import _typeof from "@babel/runtime/helpers/esm/typeof";
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/* eslint-disable no-console, no-try-catch */
/* global console */
import { VERSION, isBrowser } from '../utils/globals';

@@ -11,5 +28,10 @@ import LocalStorage from '../utils/local-storage';

import { autobind } from '../utils/autobind';
import _assert from '../utils/assert';
import assert from '../utils/assert';
import getHiResTimestamp from '../utils/hi-res-timestamp';
var originalConsole = {
/* eslint-disable no-console */
/* global console, Image */
// Instrumentation in other packages may override console methods, so preserve them here
const originalConsole = {
debug: isBrowser ? console.debug || console.log : console.log,

@@ -21,5 +43,6 @@ log: console.log,

};
var DEFAULT_SETTINGS = {
enabled: false,
priority: 0
const DEFAULT_SETTINGS = {
enabled: true,
level: 0
};

@@ -29,21 +52,46 @@

var cache = {};
const cache = {};
const ONCE = { once: true };
/*
function throttle(tag, timeout) {
const prevTime = cache[tag];
const time = Date.now();
if (!prevTime || (time - prevTime > timeout)) {
cache[tag] = time;
return true;
}
return false;
}
// Assertions don't generate standard exceptions and don't print nicely
function checkForAssertionErrors(args) {
const isAssertion =
args &&
args.length > 0 &&
typeof args[0] === 'object' &&
args[0] !== null &&
args[0].name === 'AssertionError';
if (isAssertion) {
args = Array.prototype.slice.call(args);
args.unshift(`assert(${args[0].message})`);
}
return args;
}
*/
function getTableHeader(table) {
for (var key in table) {
for (var title in table[key]) {
for (const key in table) {
for (const title in table[key]) {
return title || 'untitled';
}
}
return 'empty';
}
var Log = function () {
function Log() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
id = _ref.id;
// A console wrapper
_classCallCheck(this, Log);
export default class Log {
constructor({ id } = {}) {
this.id = id;

@@ -53,6 +101,9 @@ this.VERSION = VERSION;

this._deltaTs = getHiResTimestamp();
this.LOG_THROTTLE_TIMEOUT = 0;
this._storage = new LocalStorage("__probe-".concat(this.id, "__"), DEFAULT_SETTINGS);
// TODO - fix support from throttling groups
this.LOG_THROTTLE_TIMEOUT = 0; // Time before throttled messages are logged again
this._storage = new LocalStorage(`__probe-${this.id}__`, DEFAULT_SETTINGS);
this.userData = {};
this.timeStamp("".concat(this.id, " started"));
this.timeStamp(`${this.id} started`);
autobind(this);

@@ -62,530 +113,356 @@ Object.seal(this);

_createClass(Log, [{
key: "isEnabled",
value: function isEnabled() {
return this._storage.config.enabled;
}
}, {
key: "getPriority",
value: function getPriority() {
return this._storage.config.priority;
}
}, {
key: "getLevel",
value: function getLevel() {
return this._storage.config.priority;
}
}, {
key: "getTotal",
value: function getTotal() {
return Number((getHiResTimestamp() - this._startTs).toPrecision(10));
}
}, {
key: "getDelta",
value: function getDelta() {
return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10));
}
}, {
key: "enable",
value: function enable() {
var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
set level(newLevel) {
this.setLevel(newLevel);
}
this._storage.updateConfiguration({
enabled: enabled
});
get level() {
return this.getLevel();
}
return this;
}
}, {
key: "setLevel",
value: function setLevel(level) {
this._storage.updateConfiguration({
priority: level
});
isEnabled() {
return this._storage.config.enabled;
}
return this;
}
}, {
key: "assert",
value: function assert(condition, message) {
_assert(condition, message);
}
}, {
key: "warn",
value: function warn(message) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
getLevel() {
return this._storage.config.level;
}
return this._getLogFunction({
message: message,
args: args,
method: originalConsole.warn,
once: true
});
}
}, {
key: "error",
value: function error(message) {
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
// @return {Number} milliseconds, with fractions
getTotal() {
return Number((getHiResTimestamp() - this._startTs).toPrecision(10));
}
return this._getLogFunction({
message: message,
args: args,
method: originalConsole.error
});
}
}, {
key: "deprecated",
value: function deprecated(oldUsage, newUsage) {
return this.warn("`".concat(oldUsage, "` is deprecated and will be removed in a later version. Use `").concat(newUsage, "` instead"));
}
}, {
key: "removed",
value: function removed(oldUsage, newUsage) {
return this.error("`".concat(oldUsage, "` has been removed. Use `").concat(newUsage, "` instead"));
}
}, {
key: "probe",
value: function probe(priority, message) {
for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
args[_key3 - 2] = arguments[_key3];
}
// @return {Number} milliseconds, with fractions
getDelta() {
return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10));
}
return this._getLogFunction({
priority: priority,
message: message,
args: args,
method: originalConsole.log,
time: true,
once: true
});
}
}, {
key: "log",
value: function log(priority, message) {
for (var _len4 = arguments.length, args = new Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) {
args[_key4 - 2] = arguments[_key4];
}
// Deprecated
set priority(newPriority) {
this.level = newPriority;
}
return this._getLogFunction({
priority: priority,
message: message,
args: args,
method: originalConsole.debug
});
}
}, {
key: "info",
value: function info(priority, message) {
for (var _len5 = arguments.length, args = new Array(_len5 > 2 ? _len5 - 2 : 0), _key5 = 2; _key5 < _len5; _key5++) {
args[_key5 - 2] = arguments[_key5];
}
get priority() {
return this.level;
}
return this._getLogFunction({
priority: priority,
message: message,
args: args,
method: console.info
});
}
}, {
key: "once",
value: function once(priority, message) {
for (var _len6 = arguments.length, args = new Array(_len6 > 2 ? _len6 - 2 : 0), _key6 = 2; _key6 < _len6; _key6++) {
args[_key6 - 2] = arguments[_key6];
}
getPriority() {
return this.level;
}
return this._getLogFunction({
priority: priority,
message: message,
args: args,
method: originalConsole.debug || originalConsole.info,
once: true
});
}
}, {
key: "table",
value: function table(priority, _table, columns) {
if (_table) {
var tag = getTableHeader(_table);
return this._getLogFunction({
priority: priority,
message: _table,
args: columns && [columns],
tag: tag,
method: console.table || noop
});
}
// Configure
return noop;
}
}, {
key: "image",
value: function image(_ref2) {
var priority = _ref2.priority,
_image = _ref2.image,
_ref2$message = _ref2.message,
message = _ref2$message === void 0 ? '' : _ref2$message,
_ref2$scale = _ref2.scale,
scale = _ref2$scale === void 0 ? 1 : _ref2$scale;
enable(enabled = true) {
this._storage.updateConfiguration({ enabled });
return this;
}
if (priority > this.getPriority()) {
return noop;
}
setLevel(level) {
this._storage.updateConfiguration({ level });
return this;
}
return isBrowser ? this._logImageInBrowser({
image: _image,
message: message,
scale: scale
}) : this._logImageInNode({
image: _image,
message: message,
scale: scale
});
}
}, {
key: "settings",
value: function settings() {
if (console.table) {
console.table(this._storage.config);
} else {
console.log(this._storage.config);
}
}
}, {
key: "get",
value: function get(setting) {
return this._storage.config[setting];
}
}, {
key: "set",
value: function set(setting, value) {
this._storage.updateConfiguration(_defineProperty({}, setting, value));
}
}, {
key: "_logImageInNode",
value: function _logImageInNode(_ref3) {
var image = _ref3.image,
_ref3$message = _ref3.message,
message = _ref3$message === void 0 ? '' : _ref3$message,
_ref3$scale = _ref3.scale,
scale = _ref3$scale === void 0 ? 1 : _ref3$scale;
var asciify = null;
// Unconditional logging
try {
asciify = module.require('asciify-image');
} catch (error) {}
assert(condition, message) {
assert(condition, message);
}
if (asciify) {
return function () {
return asciify(image, {
fit: 'box',
width: "".concat(Math.round(80 * scale), "%")
}).then(function (data) {
return console.log(data);
});
};
}
// Warn, but only once, no console flooding
warn(message) {
return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
}
return noop;
}
}, {
key: "_logImageInBrowser",
value: function _logImageInBrowser(_ref4) {
var image = _ref4.image,
_ref4$message = _ref4.message,
message = _ref4$message === void 0 ? '' : _ref4$message,
_ref4$scale = _ref4.scale,
scale = _ref4$scale === void 0 ? 1 : _ref4$scale;
// Print an error
error(message) {
return this._getLogFunction(0, message, originalConsole.error, arguments);
}
if (typeof image === 'string') {
var img = new Image();
deprecated(oldUsage, newUsage) {
return this.warn(`\`${oldUsage}\` is deprecated and will be removed \
in a later version. Use \`${newUsage}\` instead`);
}
img.onload = function () {
var _console;
removed(oldUsage, newUsage) {
return this.error(`\`${oldUsage}\` has been removed. Use \`${newUsage}\` instead`);
}
var args = formatImage(img, message, scale);
// Conditional logging
(_console = console).log.apply(_console, _toConsumableArray(args));
};
// Log to a group
probe(logLevel, message) {
return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {
time: true,
once: true
});
}
img.src = image;
return noop;
}
// Log a debug message
log(logLevel, message) {
return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
}
var element = image.nodeName || '';
// Log a normal message
info(logLevel, message) {
return this._getLogFunction(logLevel, message, console.info, arguments);
}
if (element.toLowerCase() === 'img') {
var _console2;
// Log a normal message, but only once, no console flooding
once(logLevel, message) {
return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);
}
(_console2 = console).log.apply(_console2, _toConsumableArray(formatImage(image, message, scale)));
// Logs an object as a table
table(logLevel, table, columns) {
if (table) {
return this._getLogFunction(logLevel, table, console.table || noop, columns && [columns], {
tag: getTableHeader(table)
});
}
return noop;
}
return noop;
}
// logs an image under Chrome
image({ logLevel, priority, image, message = '', scale = 1 }) {
if (!this._shouldLog(logLevel || priority)) {
return noop;
}
return isBrowser ? logImageInBrowser({ image, message, scale }) : logImageInNode({ image, message, scale });
}
if (element.toLowerCase() === 'canvas') {
var _img = new Image();
// Logs the current settings as a table
settings() {
if (console.table) {
console.table(this._storage.config);
} else {
console.log(this._storage.config);
}
}
_img.onload = function () {
var _console3;
// logs the current status of the setting
get(setting) {
return this._storage.config[setting];
}
return (_console3 = console).log.apply(_console3, _toConsumableArray(formatImage(_img, message, scale)));
};
// update the status of the setting
set(setting, value) {
this._storage.updateConfiguration({ [setting]: value });
}
_img.src = image.toDataURL();
return noop;
}
time(logLevel, message) {
return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);
}
return noop;
}
}, {
key: "time",
value: function time(priority, message) {
return this._getLogFunction({
priority: priority,
message: message,
method: console.time ? console.time : console.info
});
}
}, {
key: "timeEnd",
value: function timeEnd(priority, message) {
return this._getLogFunction({
priority: priority,
message: message,
method: console.timeEnd ? console.timeEnd : console.info
});
}
}, {
key: "timeStamp",
value: function timeStamp(priority, message) {
return this._getLogFunction({
priority: priority,
message: message,
method: console.timeStamp || noop
});
}
}, {
key: "group",
value: function group(priority, message) {
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
collapsed: false
};
opts = this._normalizeArguments({
priority: priority,
message: message,
opts: opts
});
var _opts = opts,
collapsed = _opts.collapsed;
return this._getLogFunction({
priority: priority,
message: message,
opts: opts,
method: (collapsed ? console.groupCollapsed : console.group) || console.info
});
}
}, {
key: "groupCollapsed",
value: function groupCollapsed(priority, message) {
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
return this.group(priority, message, Object.assign({}, opts, {
collapsed: true
}));
}
}, {
key: "groupEnd",
value: function groupEnd(priority) {
return this._getLogFunction({
priority: priority,
message: '',
method: console.groupEnd || noop
});
}
}, {
key: "withGroup",
value: function withGroup(priority, message, func) {
var opts = this._normalizeArguments({
priority: priority,
message: message
});
timeEnd(logLevel, message) {
return this._getLogFunction(logLevel, message, console.timeEnd ? console.timeEnd : console.info);
}
this.group(opts);
timeStamp(logLevel, message) {
return this._getLogFunction(logLevel, message, console.timeStamp || noop);
}
try {
func();
} finally {
this.groupEnd(opts.message);
}
}
}, {
key: "trace",
value: function trace() {
if (console.trace) {
console.trace();
}
}
}, {
key: "_shouldLog",
value: function _shouldLog(priority) {
priority = this._normalizePriority(priority);
return priority === 0 || this.isEnabled() && this.getPriority() >= priority;
}
}, {
key: "_getElapsedTime",
value: function _getElapsedTime() {
var total = this.getTotal();
var delta = this.getDelta();
this._deltaTs = getHiResTimestamp();
return {
total: total,
delta: delta
};
}
}, {
key: "_getLogFunction",
value: function _getLogFunction(opts) {
if (this._shouldLog(opts.priority)) {
var _opts2 = opts,
method = _opts2.method;
opts = this._parseArguments(opts);
group(logLevel, message, opts = { collapsed: false }) {
opts = normalizeArguments({ logLevel, message, opts });
const { collapsed } = opts;
opts.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
_assert(method);
return this._getLogFunction(opts);
}
var _opts3 = opts,
message = _opts3.message;
var tag = opts.tag || opts.message;
groupCollapsed(logLevel, message, opts = {}) {
return this.group(logLevel, message, Object.assign({}, opts, { collapsed: true }));
}
if (opts.once) {
if (!cache[tag]) {
cache[tag] = getHiResTimestamp();
} else {
return noop;
}
}
groupEnd(logLevel) {
return this._getLogFunction(logLevel, '', console.groupEnd || noop);
}
message = this._decorateMessage(message, opts);
return method.bind.apply(method, [console, message].concat(_toConsumableArray(opts.args)));
}
// EXPERIMENTAL
return noop;
withGroup(logLevel, message, func) {
this.group(logLevel, message)();
try {
func();
} finally {
this.groupEnd(logLevel)();
}
}, {
key: "_parseArguments",
value: function _parseArguments(options) {
var normOpts = this._normalizeArguments(options);
}
var _this$_getElapsedTime = this._getElapsedTime(),
delta = _this$_getElapsedTime.delta,
total = _this$_getElapsedTime.total;
return Object.assign(options, normOpts, {
delta: delta,
total: total
});
trace() {
if (console.trace) {
console.trace();
}
}, {
key: "_normalizePriority",
value: function _normalizePriority(priority) {
var resolvedPriority;
}
switch (_typeof(priority)) {
case 'number':
resolvedPriority = priority;
break;
// PRIVATE METHODS
case 'object':
resolvedPriority = priority.priority || 0;
break;
_shouldLog(logLevel) {
return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
}
default:
resolvedPriority = 0;
_getLogFunction(logLevel, message, method, args = [], opts) {
if (this._shouldLog(logLevel)) {
// normalized opts + timings
opts = normalizeArguments({ logLevel, message, args, opts });
method = method || opts.method;
assert(method);
opts.total = this.getTotal();
opts.delta = this.getDelta();
// reset delta timer
this._deltaTs = getHiResTimestamp();
const tag = opts.tag || opts.message;
if (opts.once) {
if (!cache[tag]) {
cache[tag] = getHiResTimestamp();
} else {
return noop;
}
}
_assert(Number.isFinite(resolvedPriority) && resolvedPriority >= 0);
// TODO - Make throttling work with groups
// if (opts.nothrottle || !throttle(tag, this.LOG_THROTTLE_TIMEOUT)) {
// return noop;
// }
return resolvedPriority;
message = decorateMessage(this.id, opts.message, opts);
// Bind console function so that it can be called after being returned
return method.bind(console, message, ...opts.args);
}
}, {
key: "_normalizeArguments",
value: function _normalizeArguments(_ref5) {
var priority = _ref5.priority,
message = _ref5.message,
_ref5$args = _ref5.args,
args = _ref5$args === void 0 ? [] : _ref5$args,
opts = _ref5.opts;
var newOpts = {
priority: this._normalizePriority(priority),
message: message,
args: args
};
return noop;
}
}
switch (_typeof(priority)) {
case 'string':
case 'function':
if (message !== undefined) {
args.unshift(message);
}
Log.VERSION = VERSION;
Object.assign(newOpts, {
message: priority
});
break;
// Get logLevel from first argument:
// - log(logLevel, message, args) => logLevel
// - log(message, args) => 0
// - log({logLevel, ...}, message, args) => logLevel
// - log({logLevel, message, args}) => logLevel
function normalizeLogLevel(logLevel) {
if (!logLevel) {
return 0;
}
let resolvedLevel;
case 'object':
Object.assign(newOpts, priority);
break;
switch (typeof logLevel) {
case 'number':
resolvedLevel = logLevel;
break;
default:
}
case 'object':
// Backward compatibility
// TODO - deprecate `priority`
resolvedLevel = logLevel.logLevel || logLevel.priority || 0;
break;
if (typeof newOpts.message === 'function') {
newOpts.message = this._shouldLog(newOpts.priority) ? newOpts.message() : '';
}
default:
return 0;
}
// 'log level must be a number'
assert(Number.isFinite(resolvedLevel) && resolvedLevel >= 0);
_assert(typeof newOpts.message === 'string' || _typeof(newOpts.message) === 'object');
return resolvedLevel;
}
return Object.assign(newOpts, opts);
}
}, {
key: "_decorateMessage",
value: function _decorateMessage(message, opts) {
if (typeof message === 'string') {
var time = '';
// "Normalizes" the various argument patterns into an object with known types
// - log(logLevel, message, args) => {logLevel, message, args}
// - log(message, args) => {logLevel: 0, message, args}
// - log({logLevel, ...}, message, args) => {logLevel, message, args}
// - log({logLevel, message, args}) => {logLevel, message, args}
export function normalizeArguments(opts) {
const { logLevel, message } = opts;
opts.logLevel = normalizeLogLevel(logLevel);
// We use `arguments` instead of rest parameters (...args) because IE
// does not support the syntax. Rest parameters is transpiled to code with
// perf impact. Doing it here instead avoids constructing args when logging is
// disabled.
// TODO - remove when/if IE support is dropped
const args = opts.args ? Array.from(opts.args) : [];
/* eslint-disable no-empty */
// args should only contain arguments that appear after `message`
while (args.length && args.shift() !== message) {}
/* eslint-enable no-empty */
opts.args = args;
if (opts.time) {
var _this$_getElapsedTime2 = this._getElapsedTime(),
total = _this$_getElapsedTime2.total;
switch (typeof logLevel) {
case 'string':
case 'function':
if (message !== undefined) {
args.unshift(message);
}
opts.message = logLevel;
break;
time = leftPad(formatTime(total));
}
case 'object':
Object.assign(opts, logLevel);
break;
message = opts.time ? "".concat(this.id, ": ").concat(time, " ").concat(message) : "".concat(this.id, ": ").concat(message);
message = addColor(message, opts.color, opts.background);
}
default:
}
return message;
}
}, {
key: "priority",
set: function set(newPriority) {
this._storage.updateConfiguration({
priority: newPriority
});
// Resolve functions into strings by calling them
if (typeof opts.message === 'function') {
opts.message = opts.message();
}
const messageType = typeof opts.message;
// 'log message must be a string' or object
assert(messageType === 'string' || messageType === 'object');
return this;
},
get: function get() {
return this._storage.config.priority;
}
}]);
// original opts + normalized opts + opts arg + fixed up message
return Object.assign(opts, opts.opts);
}
return Log;
}();
function decorateMessage(id, message, opts) {
if (typeof message === 'string') {
const time = opts.time ? leftPad(formatTime(opts.total)) : '';
message = opts.time ? `${id}: ${time} ${message}` : `${id}: ${message}`;
message = addColor(message, opts.color, opts.background);
}
return message;
}
export { Log as default };
Log.VERSION = VERSION;
// Use the asciify module to log an image under node.js
function logImageInNode({ image, message = '', scale = 1 }) {
// Note: Runtime load of the "asciify-image" module, avoids including in browser bundles
let asciify = null;
try {
asciify = module.require('asciify-image');
} catch (error) {
// asciify not installed, silently ignore
}
if (asciify) {
return () => asciify(image, { fit: 'box', width: `${Math.round(80 * scale)}%` }).then(data => console.log(data));
}
return noop;
}
function logImageInBrowser({ image, message = '', scale = 1 }) {
if (typeof image === 'string') {
const img = new Image();
img.onload = () => {
const args = formatImage(img, message, scale);
console.log(...args);
};
img.src = image;
return noop;
}
const element = image.nodeName || '';
if (element.toLowerCase() === 'img') {
console.log(...formatImage(image, message, scale));
return noop;
}
if (element.toLowerCase() === 'canvas') {
const img = new Image();
img.onload = () => console.log(...formatImage(img, message, scale));
img.src = image.toDataURL();
return noop;
}
return noop;
}
//# sourceMappingURL=log.js.map

@@ -1,40 +0,36 @@

export function autobind(obj) {
var predefined = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['constructor'];
var proto = Object.getPrototypeOf(obj);
var propNames = Object.getOwnPropertyNames(proto);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
try {
var _loop = function _loop() {
var key = _step.value;
if (typeof obj[key] === 'function') {
if (!predefined.find(function (name) {
return key === name;
})) {
obj[key] = obj[key].bind(obj);
}
/**
* Binds the "this" argument of all functions on a class instance to the instance
* @param {Object} obj - class instance (typically a react component)
*/
export function autobind(obj, predefined = ['constructor']) {
const proto = Object.getPrototypeOf(obj);
const propNames = Object.getOwnPropertyNames(proto);
for (const key of propNames) {
if (typeof obj[key] === 'function') {
if (!predefined.find(name => key === name)) {
obj[key] = obj[key].bind(obj);
}
};
for (var _iterator = propNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
_loop();
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
_iterator["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
//# sourceMappingURL=autobind.js.map
import { isBrowser } from './globals';
export var COLOR = {
export const COLOR = {
BLACK: 30,

@@ -11,2 +12,3 @@ RED: 31,

WHITE: 37,
BRIGHT_BLACK: 90,

@@ -30,13 +32,12 @@ BRIGHT_RED: 91,

color = getColor(color);
string = "\x1B[".concat(color, "m").concat(string, "\x1B[39m");
string = `\u001b[${color}m${string}\u001b[39m`;
}
if (background) {
// background colors values are +10
color = getColor(background);
string = "\x1B[".concat(background + 10, "m").concat(string, "\x1B[49m");
string = `\u001b[${background + 10}m${string}\u001b[49m`;
}
}
return string;
}
//# sourceMappingURL=color.js.map

@@ -0,79 +1,66 @@

// TODO: Currently unused, keeping in case we want it later for log formatting
export function formatTime(ms) {
var formatted;
let formatted;
if (ms < 10) {
formatted = "".concat(ms.toFixed(2), "ms");
formatted = `${ms.toFixed(2)}ms`;
} else if (ms < 100) {
formatted = "".concat(ms.toFixed(1), "ms");
formatted = `${ms.toFixed(1)}ms`;
} else if (ms < 1000) {
formatted = "".concat(ms.toFixed(0), "ms");
formatted = `${ms.toFixed(0)}ms`;
} else {
formatted = "".concat((ms / 1000).toFixed(2), "s");
formatted = `${(ms / 1000).toFixed(2)}s`;
}
return formatted;
}
export function leftPad(string) {
var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 8;
var padLength = Math.max(length - string.length, 0);
return "".concat(' '.repeat(padLength)).concat(string);
export function leftPad(string, length = 8) {
const padLength = Math.max(length - string.length, 0);
return `${' '.repeat(padLength)}${string}`;
}
export function rightPad(string) {
var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 8;
var padLength = Math.max(length - string.length, 0);
return "".concat(string).concat(' '.repeat(padLength));
export function rightPad(string, length = 8) {
const padLength = Math.max(length - string.length, 0);
return `${string}${' '.repeat(padLength)}`;
}
export function formatValue(v) {
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var EPSILON = 1e-16;
var _opts$isInteger = opts.isInteger,
isInteger = _opts$isInteger === void 0 ? false : _opts$isInteger;
export function formatValue(v, opts = {}) {
const EPSILON = 1e-16;
const { isInteger = false } = opts;
if (Array.isArray(v) || ArrayBuffer.isView(v)) {
return formatArrayValue(v, opts);
}
if (!Number.isFinite(v)) {
return String(v);
}
if (Math.abs(v) < EPSILON) {
return isInteger ? '0' : '0.';
}
if (isInteger) {
return v.toFixed(0);
}
if (Math.abs(v) > 100 && Math.abs(v) < 10000) {
return v.toFixed(0);
}
var string = v.toPrecision(2);
var decimal = string.indexOf('.0');
const string = v.toPrecision(2);
const decimal = string.indexOf('.0');
return decimal === string.length - 2 ? string.slice(0, -1) : string;
}
// Helper to formatValue
function formatArrayValue(v, opts) {
var _opts$maxElts = opts.maxElts,
maxElts = _opts$maxElts === void 0 ? 16 : _opts$maxElts,
_opts$size = opts.size,
size = _opts$size === void 0 ? 1 : _opts$size;
var string = '[';
for (var i = 0; i < v.length && i < maxElts; ++i) {
const { maxElts = 16, size = 1 } = opts;
let string = '[';
for (let i = 0; i < v.length && i < maxElts; ++i) {
if (i > 0) {
string += ",".concat(i % size === 0 ? ' ' : '');
string += `,${i % size === 0 ? ' ' : ''}`;
}
string += formatValue(v[i], opts);
}
var terminator = v.length > maxElts ? '...' : ']';
return "".concat(string).concat(terminator);
const terminator = v.length > maxElts ? '...' : ']';
return `${string}${terminator}`;
}
export function formatImage(image, message, scale) {
var maxWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 600;
var imageUrl = image.src.replace(/\(/g, '%28').replace(/\)/g, '%29');
// Inspired by https://github.com/hughsk/console-image (MIT license)
export function formatImage(image, message, scale, maxWidth = 600) {
const imageUrl = image.src.replace(/\(/g, '%28').replace(/\)/g, '%29');

@@ -84,7 +71,9 @@ if (image.width > maxWidth) {

var width = image.width * scale;
var height = image.height * scale;
var style = ['font-size:1px;', "padding:".concat(Math.floor(height / 2), "px ").concat(Math.floor(width / 2), "px;"), "line-height:".concat(height, "px;"), "background:url(".concat(imageUrl, ");"), "background-size:".concat(width, "px ").concat(height, "px;"), 'color:transparent;'].join('');
return ["".concat(message, " %c+"), style];
const width = image.width * scale;
const height = image.height * scale;
const style = ['font-size:1px;', `padding:${Math.floor(height / 2)}px ${Math.floor(width / 2)}px;`, `line-height:${height}px;`, `background:url(${imageUrl});`, `background-size:${width}px ${height}px;`, 'color:transparent;'].join('');
return [`${message} %c+`, style];
}
//# sourceMappingURL=formatters.js.map
import checkIfBrowser from '../env/is-browser';
export { self, window, global, document, process, console } from '../env/globals';
export var VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'untranspiled source';
export var isBrowser = checkIfBrowser();
// Extract injected version from package.json (injected by babel plugin)
/* global __VERSION__ */
export const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'untranspiled source';
export const isBrowser = checkIfBrowser();
//# sourceMappingURL=globals.js.map

@@ -0,9 +1,33 @@

// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/**
* Common environment setup
*/
import { window, process, isBrowser } from './globals';
export default function getHiResTimestamp() {
var timestamp;
let timestamp;
// Get best timer available.
if (isBrowser && window.performance) {
timestamp = window.performance.now();
} else if (process.hrtime) {
var timeParts = process.hrtime();
const timeParts = process.hrtime();
timestamp = timeParts[0] * 1000 + timeParts[1] / 1e6;

@@ -10,0 +34,0 @@ } else {

@@ -1,8 +0,26 @@

import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/* global window */
function getStorage(type) {
try {
var storage = window[type];
var x = '__storage_test__';
const storage = window[type];
const x = '__storage_test__';
storage.setItem(x, x);

@@ -16,8 +34,5 @@ storage.removeItem(x);

var LocalStorage = function () {
function LocalStorage(id, defaultSettings) {
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'sessionStorage';
_classCallCheck(this, LocalStorage);
// Store keys in local storage via simple interface
export default class LocalStorage {
constructor(id, defaultSettings, type = 'sessionStorage') {
this.storage = getStorage(type);

@@ -27,48 +42,34 @@ this.id = id;

Object.assign(this.config, defaultSettings);
this._loadConfiguration();
}
_createClass(LocalStorage, [{
key: "getConfiguration",
value: function getConfiguration() {
return this.config;
}
}, {
key: "setConfiguration",
value: function setConfiguration(configuration) {
this.config = {};
return this.updateConfiguration(configuration);
}
}, {
key: "updateConfiguration",
value: function updateConfiguration(configuration) {
Object.assign(this.config, configuration);
getConfiguration() {
return this.config;
}
if (this.storage) {
var serialized = JSON.stringify(this.config);
this.storage.setItem(this.id, serialized);
}
setConfiguration(configuration) {
this.config = {};
return this.updateConfiguration(configuration);
}
return this;
updateConfiguration(configuration) {
Object.assign(this.config, configuration);
if (this.storage) {
const serialized = JSON.stringify(this.config);
this.storage.setItem(this.id, serialized);
}
}, {
key: "_loadConfiguration",
value: function _loadConfiguration() {
var configuration = {};
return this;
}
if (this.storage) {
var serializedConfiguration = this.storage.getItem(this.id);
configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {};
}
Object.assign(this.config, configuration);
return this;
// Get config from persistent store, if available
_loadConfiguration() {
let configuration = {};
if (this.storage) {
const serializedConfiguration = this.storage.getItem(this.id);
configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {};
}
}]);
return LocalStorage;
}();
export { LocalStorage as default };
Object.assign(this.config, configuration);
return this;
}
}
//# sourceMappingURL=local-storage.js.map

@@ -5,3 +5,3 @@ {

"license": "MIT",
"version": "3.1.1",
"version": "3.2.0-beta.1",
"keywords": [

@@ -36,3 +36,3 @@ "javascript",

},
"gitHead": "41925fa4c6d9728c375ad2aaf555940b3d5dc144"
"gitHead": "6b456f5045a655dabda2327b6172e44281f6c321"
}

@@ -15,6 +15,2 @@ import './init';

// STATS (PERFORMANCE PROFILING)
export {default as Stats} from './lib/stats';
export {default as Stat} from './lib/stat';
// LOGGING

@@ -33,1 +29,4 @@ export {default as Log} from './lib/log';

export {default as getHiResTimestamp} from './utils/hi-res-timestamp';
// DEPRECATED (Should be imported directly from @probe.gl/stats)
export {Stats, Stat} from '@probe.gl/stats';

@@ -44,4 +44,4 @@ // Copyright (c) 2017 Uber Technologies, Inc.

const DEFAULT_SETTINGS = {
enabled: false,
priority: 0
enabled: true,
level: 0
};

@@ -52,2 +52,3 @@

const cache = {};
const ONCE = {once: true};

@@ -110,9 +111,8 @@ /*

set priority(newPriority) {
this._storage.updateConfiguration({priority: newPriority});
return this;
set level(newLevel) {
this.setLevel(newLevel);
}
get priority() {
return this._storage.config.priority;
get level() {
return this.getLevel();
}

@@ -124,8 +124,4 @@

getPriority() {
return this._storage.config.priority;
}
getLevel() {
return this._storage.config.priority;
return this._storage.config.level;
}

@@ -143,2 +139,15 @@

// Deprecated
set priority(newPriority) {
this.level = newPriority;
}
get priority() {
return this.level;
}
getPriority() {
return this.level;
}
// Configure

@@ -152,3 +161,3 @@

setLevel(level) {
this._storage.updateConfiguration({priority: level});
this._storage.updateConfiguration({level});
return this;

@@ -164,14 +173,9 @@ }

// Warn, but only once, no console flooding
warn(message, ...args) {
return this._getLogFunction({
message,
args,
method: originalConsole.warn,
once: true
});
warn(message) {
return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
}
// Print an error
error(message, ...args) {
return this._getLogFunction({message, args, method: originalConsole.error});
error(message) {
return this._getLogFunction(0, message, originalConsole.error, arguments);
}

@@ -191,8 +195,4 @@

// Log to a group
probe(priority, message, ...args) {
return this._getLogFunction({
priority,
message,
args,
method: originalConsole.log,
probe(logLevel, message) {
return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {
time: true,

@@ -204,42 +204,27 @@ once: true

// Log a debug message
log(priority, message, ...args) {
return this._getLogFunction({
priority,
message,
args,
method: originalConsole.debug
});
log(logLevel, message) {
return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
}
// Log a normal message
info(priority, message, ...args) {
return this._getLogFunction({
priority,
message,
args,
method: console.info
});
info(logLevel, message) {
return this._getLogFunction(logLevel, message, console.info, arguments);
}
// Log a normal message, but only once, no console flooding
once(priority, message, ...args) {
return this._getLogFunction({
priority,
once(logLevel, message) {
return this._getLogFunction(
logLevel,
message,
args,
method: originalConsole.debug || originalConsole.info,
once: true
});
originalConsole.debug || originalConsole.info,
arguments,
ONCE
);
}
// Logs an object as a table
table(priority, table, columns) {
table(logLevel, table, columns) {
if (table) {
const tag = getTableHeader(table);
return this._getLogFunction({
priority,
message: table,
args: columns && [columns],
tag,
method: console.table || noop
return this._getLogFunction(logLevel, table, console.table || noop, columns && [columns], {
tag: getTableHeader(table)
});

@@ -251,9 +236,9 @@ }

// logs an image under Chrome
image({priority, image, message = '', scale = 1}) {
if (priority > this.getPriority()) {
image({logLevel, priority, image, message = '', scale = 1}) {
if (!this._shouldLog(logLevel || priority)) {
return noop;
}
return isBrowser
? this._logImageInBrowser({image, message, scale})
: this._logImageInNode({image, message, scale});
? logImageInBrowser({image, message, scale})
: logImageInNode({image, message, scale});
}

@@ -280,89 +265,32 @@

// Use the asciify module to log an image under node.js
_logImageInNode({image, message = '', scale = 1}) {
// Note: Runtime load of the "asciify-image" module, avoids including in browser bundles
let asciify = null;
try {
asciify = module.require('asciify-image');
} catch (error) {
// asciify not installed, silently ignore
}
if (asciify) {
return () =>
asciify(image, {fit: 'box', width: `${Math.round(80 * scale)}%`}).then(data =>
console.log(data)
);
}
return noop;
time(logLevel, message) {
return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);
}
_logImageInBrowser({image, message = '', scale = 1}) {
if (typeof image === 'string') {
const img = new Image();
img.onload = () => {
const args = formatImage(img, message, scale);
console.log(...args);
};
img.src = image;
return noop;
}
const element = image.nodeName || '';
if (element.toLowerCase() === 'img') {
console.log(...formatImage(image, message, scale));
return noop;
}
if (element.toLowerCase() === 'canvas') {
const img = new Image();
img.onload = () => console.log(...formatImage(img, message, scale));
img.src = image.toDataURL();
return noop;
}
return noop;
}
time(priority, message) {
return this._getLogFunction({
priority,
timeEnd(logLevel, message) {
return this._getLogFunction(
logLevel,
message,
method: console.time ? console.time : console.info
});
console.timeEnd ? console.timeEnd : console.info
);
}
timeEnd(priority, message) {
return this._getLogFunction({
priority,
message,
method: console.timeEnd ? console.timeEnd : console.info
});
timeStamp(logLevel, message) {
return this._getLogFunction(logLevel, message, console.timeStamp || noop);
}
timeStamp(priority, message) {
return this._getLogFunction({
priority,
message,
method: console.timeStamp || noop
});
}
group(logLevel, message, opts = {collapsed: false}) {
opts = normalizeArguments({logLevel, message, opts});
const {collapsed} = opts;
opts.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
group(priority, message, opts = {collapsed: false}) {
opts = this._normalizeArguments({priority, message, opts});
const {collapsed} = opts;
return this._getLogFunction({
priority,
message,
opts,
method: (collapsed ? console.groupCollapsed : console.group) || console.info
});
return this._getLogFunction(opts);
}
groupCollapsed(priority, message, opts = {}) {
return this.group(priority, message, Object.assign({}, opts, {collapsed: true}));
groupCollapsed(logLevel, message, opts = {}) {
return this.group(logLevel, message, Object.assign({}, opts, {collapsed: true}));
}
groupEnd(priority) {
return this._getLogFunction({
priority,
message: '',
method: console.groupEnd || noop
});
groupEnd(logLevel) {
return this._getLogFunction(logLevel, '', console.groupEnd || noop);
}

@@ -372,14 +300,9 @@

withGroup(priority, message, func) {
const opts = this._normalizeArguments({
priority,
message
});
withGroup(logLevel, message, func) {
this.group(logLevel, message)();
this.group(opts);
try {
func();
} finally {
this.groupEnd(opts.message);
this.groupEnd(logLevel)();
}

@@ -396,24 +319,18 @@ }

_shouldLog(priority) {
priority = this._normalizePriority(priority);
return priority === 0 || (this.isEnabled() && this.getPriority() >= priority);
_shouldLog(logLevel) {
return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
}
_getElapsedTime() {
const total = this.getTotal();
const delta = this.getDelta();
// reset delta timer
this._deltaTs = getHiResTimestamp();
return {total, delta};
}
_getLogFunction(logLevel, message, method, args = [], opts) {
if (this._shouldLog(logLevel)) {
// normalized opts + timings
opts = normalizeArguments({logLevel, message, args, opts});
method = method || opts.method;
assert(method);
_getLogFunction(opts) {
if (this._shouldLog(opts.priority)) {
const {method} = opts;
opts.total = this.getTotal();
opts.delta = this.getDelta();
// reset delta timer
this._deltaTs = getHiResTimestamp();
opts = this._parseArguments(opts);
assert(method);
let {message} = opts;
const tag = opts.tag || opts.message;

@@ -434,3 +351,3 @@

message = this._decorateMessage(message, opts);
message = decorateMessage(this.id, opts.message, opts);

@@ -440,97 +357,136 @@ // Bind console function so that it can be called after being returned

}
return noop;
}
}
_parseArguments(options) {
const normOpts = this._normalizeArguments(options);
Log.VERSION = VERSION;
const {delta, total} = this._getElapsedTime();
// normalized opts + timings
return Object.assign(options, normOpts, {
delta,
total
});
// Get logLevel from first argument:
// - log(logLevel, message, args) => logLevel
// - log(message, args) => 0
// - log({logLevel, ...}, message, args) => logLevel
// - log({logLevel, message, args}) => logLevel
function normalizeLogLevel(logLevel) {
if (!logLevel) {
return 0;
}
let resolvedLevel;
// Get priority from first argument:
// - log(priority, message, args) => priority
// - log(message, args) => 0
// - log({priority, ...}, message, args) => priority
// - log({priority, message, args}) => priority
_normalizePriority(priority) {
let resolvedPriority;
switch (typeof logLevel) {
case 'number':
resolvedLevel = logLevel;
break;
switch (typeof priority) {
case 'number':
resolvedPriority = priority;
break;
case 'object':
// Backward compatibility
// TODO - deprecate `priority`
resolvedLevel = logLevel.logLevel || logLevel.priority || 0;
break;
case 'object':
resolvedPriority = priority.priority || 0;
break;
default:
return 0;
}
// 'log level must be a number'
assert(Number.isFinite(resolvedLevel) && resolvedLevel >= 0);
default:
resolvedPriority = 0;
}
// 'log priority must be a number'
assert(Number.isFinite(resolvedPriority) && resolvedPriority >= 0);
return resolvedLevel;
}
return resolvedPriority;
}
// "Normalizes" the various argument patterns into an object with known types
// - log(logLevel, message, args) => {logLevel, message, args}
// - log(message, args) => {logLevel: 0, message, args}
// - log({logLevel, ...}, message, args) => {logLevel, message, args}
// - log({logLevel, message, args}) => {logLevel, message, args}
export function normalizeArguments(opts) {
const {logLevel, message} = opts;
opts.logLevel = normalizeLogLevel(logLevel);
// We use `arguments` instead of rest parameters (...args) because IE
// does not support the syntax. Rest parameters is transpiled to code with
// perf impact. Doing it here instead avoids constructing args when logging is
// disabled.
// TODO - remove when/if IE support is dropped
const args = opts.args ? Array.from(opts.args) : [];
/* eslint-disable no-empty */
// args should only contain arguments that appear after `message`
while (args.length && args.shift() !== message) {}
/* eslint-enable no-empty */
opts.args = args;
// "Normalizes" the various argument patterns into an object with known types
// - log(priority, message, args) => {priority, message, args}
// - log(message, args) => {priority: 0, message, args}
// - log({priority, ...}, message, args) => {priority, message, args}
// - log({priority, message, args}) => {priority, message, args}
_normalizeArguments({priority, message, args = [], opts}) {
const newOpts = {
priority: this._normalizePriority(priority),
message,
args
};
switch (typeof logLevel) {
case 'string':
case 'function':
if (message !== undefined) {
args.unshift(message);
}
opts.message = logLevel;
break;
switch (typeof priority) {
case 'string':
case 'function':
if (message !== undefined) {
args.unshift(message);
}
Object.assign(newOpts, {message: priority});
break;
case 'object':
Object.assign(opts, logLevel);
break;
case 'object':
Object.assign(newOpts, priority);
break;
default:
}
default:
}
// Resolve functions into strings by calling them
if (typeof opts.message === 'function') {
opts.message = opts.message();
}
const messageType = typeof opts.message;
// 'log message must be a string' or object
assert(messageType === 'string' || messageType === 'object');
// Resolve functions into strings by calling them
if (typeof newOpts.message === 'function') {
newOpts.message = this._shouldLog(newOpts.priority) ? newOpts.message() : '';
}
// 'log message must be a string' or object
assert(typeof newOpts.message === 'string' || typeof newOpts.message === 'object');
// original opts + normalized opts + opts arg + fixed up message
return Object.assign(opts, opts.opts);
}
// original opts + normalized opts + opts arg + fixed up message
return Object.assign(newOpts, opts);
function decorateMessage(id, message, opts) {
if (typeof message === 'string') {
const time = opts.time ? leftPad(formatTime(opts.total)) : '';
message = opts.time ? `${id}: ${time} ${message}` : `${id}: ${message}`;
message = addColor(message, opts.color, opts.background);
}
return message;
}
_decorateMessage(message, opts) {
if (typeof message === 'string') {
let time = '';
if (opts.time) {
const {total} = this._getElapsedTime();
time = leftPad(formatTime(total));
}
message = opts.time ? `${this.id}: ${time} ${message}` : `${this.id}: ${message}`;
message = addColor(message, opts.color, opts.background);
}
return message;
// Use the asciify module to log an image under node.js
function logImageInNode({image, message = '', scale = 1}) {
// Note: Runtime load of the "asciify-image" module, avoids including in browser bundles
let asciify = null;
try {
asciify = module.require('asciify-image');
} catch (error) {
// asciify not installed, silently ignore
}
if (asciify) {
return () =>
asciify(image, {fit: 'box', width: `${Math.round(80 * scale)}%`}).then(data =>
console.log(data)
);
}
return noop;
}
Log.VERSION = VERSION;
function logImageInBrowser({image, message = '', scale = 1}) {
if (typeof image === 'string') {
const img = new Image();
img.onload = () => {
const args = formatImage(img, message, scale);
console.log(...args);
};
img.src = image;
return noop;
}
const element = image.nodeName || '';
if (element.toLowerCase() === 'img') {
console.log(...formatImage(image, message, scale));
return noop;
}
if (element.toLowerCase() === 'canvas') {
const img = new Image();
img.onload = () => console.log(...formatImage(img, message, scale));
img.src = image.toDataURL();
return noop;
}
return noop;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc