UNPKG

ololog

Version:

Logging. Colors. Terminals & browsers. Show call locations. Pretty prints objects, Errors, anything!

1,502 lines (1,202 loc) 651 kB
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ (function (process){ "use strict"; /* ------------------------------------------------------------------------ */ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); function _defineEnumerableProperties(obj, descs) { for (var key in descs) { var desc = descs[key]; desc.configurable = desc.enumerable = true; if ("value" in desc) desc.writable = true; Object.defineProperty(obj, key, desc); } return obj; } function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); } var O = Object, StackTracey = require('stacktracey'), ansi = require('ansicolor'), bullet = require('string.bullet'), pipez = require('pipez'); /* ------------------------------------------------------------------------ */ var _stringify = require('string.ify').configure({ formatter: function formatter(x, stringify) { if (x instanceof Error && !(typeof Symbol !== 'undefined' && x[Symbol.for('String.ify')])) { if (stringify.state.depth > 0) return '<Error: ' + x.message + '>'; // prevents unwanted pretty printing for Errors that are properties of complex objects var indent = ' ', why = stringify.limit((x.message || '').replace(/\r|\n/g, '').trim(), stringify.state.maxErrorMessageLength || 120), stack = new StackTracey(x).withSources().asTable(), stackIndented = stack.split('\n').map(function (x) { return indent + x; }).join('\n'), isAssertion = 'actual' in x && 'expected' in x, type = x.constructor.name || 'Error'; if (isAssertion) { var str = stringify.configure({ maxStringLength: Number.MAX_VALUE, maxDepth: 8 }); var actual = bullet(indent + 'actual: ', str(x.actual)), expected = bullet(indent + 'expected: ', str(x.expected)); if (actual.split('\n').length > 1 || expected.split('\n').length > 1) // if multiline actual/expected, need extra whitespace inbetween actual += '\n'; return '[' + type + '] ' + why + '\n\n' + ansi.red(actual) + '\n' + ansi.green(expected) + '\n\n' + stackIndented + '\n'; } else { return '[' + type + '] ' + why + '\n\n' + stackIndented + '\n'; } } } }); /* ------------------------------------------------------------------------ */ var _require = require('printable-characters'), isBlank = _require.isBlank, blank = _require.blank, changeLastNonemptyLine = function changeLastNonemptyLine(lines, fn) { for (var i = lines.length - 1; i >= 0; i--) { if (i === 0 || !isBlank(lines[i])) { lines[i] = fn(lines[i]); break; } } return lines; }; /* ------------------------------------------------------------------------ */ var log = pipez({ /* ------------------------------------------------------------------------ */ stringify: function stringify(args, cfg) { var print = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : cfg.print || _stringify.configure(cfg); return args.map(function (arg) { return typeof arg === 'string' ? arg : print(arg); }); }, trim: function trim(tokens, _ref) { var _ref$max = _ref.max, max = _ref$max === undefined ? undefined : _ref$max; return !max ? tokens : tokens.map(function (t) { return _stringify.limit(t, max); }); }, lines: function lines(tokens, _ref2) { var _ref2$linebreak = _ref2.linebreak, linebreak = _ref2$linebreak === undefined ? '\n' : _ref2$linebreak; var lines = [[]]; var leftPad = []; var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = tokens[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var t = _step.value; var _t$split = t.split(linebreak), _t$split2 = _toArray(_t$split), first = _t$split2[0], rest = _t$split2.slice(1); lines[lines.length - 1].push(first); lines = [].concat(_toConsumableArray(lines), _toConsumableArray(rest.map(function (t) { return t ? [].concat(leftPad, [t]) : []; }))); var pad = blank(!rest.length ? t : rest[rest.length - 1]); if (pad) { leftPad.push(pad); } } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } return lines; }, concat: function concat(lines, _ref3) { var _ref3$separator = _ref3.separator, separator = _ref3$separator === undefined ? ' ' : _ref3$separator; return lines.map(function (tokens) { return tokens.join(separator); }); }, indent: function indent(lines, _ref4) { var _ref4$level = _ref4.level, level = _ref4$level === undefined ? 0 : _ref4$level, _ref4$pattern = _ref4.pattern, pattern = _ref4$pattern === undefined ? '\t' : _ref4$pattern; return lines.map(function (line) { return pattern.repeat(level) + line; }); }, tag: function tag(lines, _ref5) { var _ref5$level = _ref5.level, level = _ref5$level === undefined ? '' : _ref5$level, _ref5$levelColor = _ref5.levelColor, levelColor = _ref5$levelColor === undefined ? { 'info': ansi.cyan, 'warn': ansi.yellow, 'debug': ansi.blue, 'error': ansi.bright.red } : _ref5$levelColor; return bullet((levelColor[level] || function (s) { return s; })(level.toUpperCase().padStart(6) + '\t'), lines); }, time: function time(lines, _ref6) { var _ref6$when = _ref6.when, when = _ref6$when === undefined ? new Date() : _ref6$when, _ref6$format = _ref6.format, format = _ref6$format === undefined ? 'locale' : _ref6$format, _ref6$locale = _ref6.locale, locale = _ref6$locale === undefined ? [] : _ref6$locale, _ref6$options = _ref6.options, options = _ref6$options === undefined ? {} : _ref6$options, _ref6$print = _ref6.print, print = _ref6$print === undefined ? function (when) { return ansi.darkGray(format === 'iso' ? when.toISOString() : format === 'locale' ? when.toLocaleString(locale, options) : format === 'utc' ? when.toUTCString() : when.toString()) + '\t'; } : _ref6$print; return bullet(print(when), lines); }, locate: function locate(lines, _ref7) { var _ref7$shift = _ref7.shift, shift = _ref7$shift === undefined ? 0 : _ref7$shift, _ref7$where = _ref7.where, where = _ref7$where === undefined ? new StackTracey().clean().at(1 + shift) : _ref7$where, _ref7$join = _ref7.join, join = _ref7$join === undefined ? function (a, sep, b) { return a && b ? a + sep + b : a || b; } : _ref7$join, _ref7$print = _ref7.print, print = _ref7$print === undefined ? function (_ref8) { var calleeShort = _ref8.calleeShort, _ref8$fileName = _ref8.fileName, fileName = _ref8$fileName === undefined ? [] : _ref8$fileName, _ref8$line = _ref8.line, line = _ref8$line === undefined ? [] : _ref8$line; return ansi.darkGray('(' + join(calleeShort, ' @ ', join(fileName, ':', line)) + ')'); } : _ref7$print; return changeLastNonemptyLine(lines, function (line) { return join(line, ' ', print(where)); }); }, join: function join(lines, _ref9) { var _ref9$linebreak = _ref9.linebreak, linebreak = _ref9$linebreak === undefined ? '\n' : _ref9$linebreak; return lines.join(linebreak); }, render: function render(text, _ref10) { var _ref10$engine = _ref10.engine, engine = _ref10$engine === undefined ? typeof window !== 'undefined' && window.window === window && window.navigator ? navigator.userAgent.indexOf('Chrome') >= 0 ? 'chrome' : 'generic' : 'ansi' : _ref10$engine, _ref10$engines = _ref10.engines, engines = _ref10$engines === undefined ? {/* configurable */} : _ref10$engines, _ref10$consoleMethod = _ref10.consoleMethod, consoleMethod = _ref10$consoleMethod === undefined ? 'log' : _ref10$consoleMethod, _ref10$defaults = _ref10.defaults, defaults = _ref10$defaults === undefined ? { ansi: function ansi(s) { return console[consoleMethod](s); }, chrome: function chrome(s) { var _console; return (_console = console)[consoleMethod].apply(_console, _toConsumableArray(ansi.parse(s).asChromeConsoleLogArguments)); }, generic: function generic(s) { return console[consoleMethod](ansi.strip(s)); } } : _ref10$defaults; return text && O.assign(defaults, engines)[engine](text), text; }, returnValue: function returnValue(__, _ref11) { var _ref11$initialArgumen = _slicedToArray(_ref11.initialArguments, 1), firstArgument = _ref11$initialArgumen[0]; return firstArgument; } /* ------------------------------------------------------------------------ */ }).configure({ time: false, // disables some steps (until enabled back explicitly) tag: false /* ------------------------------------------------------------------------ */ }).methods({ get noop() { return pipez({ returnValue: function returnValue(args) { return args[0]; } }).methods(this.methods_); }, get null() { return this.noop; }, // LEGACY, DEPRECATED (left here for backward compatibility) indent: function indent(level) { return this.configure({ indent: { level: level } }); }, get error() { return this.configure({ tag: { level: 'error' }, render: { consoleMethod: 'error' } }); }, get warn() { return this.configure({ tag: { level: 'warn' }, render: { consoleMethod: 'warn' } }); }, get info() { return this.configure({ tag: { level: 'info' }, render: { consoleMethod: 'info' } }); }, get debug() { return this.configure({ tag: { level: 'debug' }, render: { consoleMethod: 'debug' } }); }, maxArrayLength: function maxArrayLength(n) { return this.configure({ stringify: { maxArrayLength: n } }); }, maxObjectLength: function maxObjectLength(n) { return this.configure({ stringify: { maxObjectLength: n } }); }, maxDepth: function maxDepth(n) { return this.configure({ stringify: { maxDepth: n } }); }, maxLength: function maxLength(n) { return this.configure({ stringify: { maxLength: n } }); }, get unlimited() { return this.configure({ stringify: { maxStringLength: Number.MAX_VALUE, maxObjectLength: Number.MAX_VALUE, maxArrayLength: Number.MAX_VALUE, maxDepth: Number.MAX_VALUE, maxErrorMessageLength: Number.MAX_VALUE } }); }, get noPretty() { return this.configure({ stringify: { pretty: false } }); }, get noFancy() { return this.configure({ stringify: { fancy: false } }); }, get noRightAlignKeys() { return this.configure({ stringify: { rightAlignKeys: false } }); }, get noLocate() { return this.configure({ locate: false }); }, precision: function precision(n) { return this.configure({ stringify: { precision: n } }); }, get serialize() { return this.before('render'); }, get deserialize() { return this.from('render'); }, newline: function newline() { return this.from('join')(['']); }, handleNodeErrors: function handleNodeErrors() { var _this = this; process.on('uncaughtException', function (e) { _this.bright.red.error.noLocate(e);process.exit(1); }); process.on('unhandledRejection', function (e) { _this.bright.red.error.noLocate(e);process.exit(1); }); return this; } }); /* ------------------------------------------------------------------------ */ ansi.names.forEach(function (color) { var _log$methods, _mutatorMap; log.methods((_log$methods = {}, _mutatorMap = {}, _mutatorMap[color] = _mutatorMap[color] || {}, _mutatorMap[color].get = function () { return this.configure({ 'concat+': function concat(lines) { return lines.map(ansi[color]); } }); }, _defineEnumerableProperties(_log$methods, _mutatorMap), _log$methods)); }); /* ------------------------------------------------------------------------ */ module.exports = log; /* ------------------------------------------------------------------------ */ }).call(this,require('_process')) },{"_process":13,"ansicolor":2,"pipez":11,"printable-characters":12,"stacktracey":26,"string.bullet":27,"string.ify":28}],2:[function(require,module,exports){ "use strict"; /* ------------------------------------------------------------------------ */ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var O = Object; /* See https://misc.flogisoft.com/bash/tip_colors_and_formatting ------------------------------------------------------------------------ */ var colorCodes = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'lightGray', '', 'default'], colorCodesLight = ['darkGray', 'lightRed', 'lightGreen', 'lightYellow', 'lightBlue', 'lightMagenta', 'lightCyan', 'white', ''], styleCodes = ['', 'bright', 'dim', 'italic', 'underline', '', '', 'inverse'], asBright = { 'red': 'lightRed', 'green': 'lightGreen', 'yellow': 'lightYellow', 'blue': 'lightBlue', 'magenta': 'lightMagenta', 'cyan': 'lightCyan', 'black': 'darkGray', 'lightGray': 'white' }, types = { 0: 'style', 2: 'unstyle', 3: 'color', 9: 'colorLight', 4: 'bgColor', 10: 'bgColorLight' }, subtypes = { color: colorCodes, colorLight: colorCodesLight, bgColor: colorCodes, bgColorLight: colorCodesLight, style: styleCodes, unstyle: styleCodes /* ------------------------------------------------------------------------ */ };var clean = function clean(obj) { for (var k in obj) { if (!obj[k]) { delete obj[k]; } } return O.keys(obj).length === 0 ? undefined : obj; }; /* ------------------------------------------------------------------------ */ var Color = function () { function Color(background, name, brightness) { _classCallCheck(this, Color); this.background = background; this.name = name; this.brightness = brightness; } _createClass(Color, [{ key: 'defaultBrightness', value: function defaultBrightness(value) { return new Color(this.background, this.name, this.brightness || value); } }, { key: 'css', value: function css(inverted) { var color = inverted ? this.inverse : this; var rgbName = color.brightness === Code.bright && asBright[color.name] || color.name; var prop = color.background ? 'background:' : 'color:', rgb = Colors.rgb[rgbName], alpha = this.brightness === Code.dim ? 0.5 : 1; return rgb ? prop + 'rgba(' + [].concat(_toConsumableArray(rgb), [alpha]).join(',') + ');' : !color.background && alpha < 1 ? 'color:rgba(0,0,0,0.5);' : ''; // Chrome does not support 'opacity' property... } }, { key: 'inverse', get: function get() { return new Color(!this.background, this.name || (this.background ? 'black' : 'white'), this.brightness); } }, { key: 'clean', get: function get() { return clean({ name: this.name === 'default' ? '' : this.name, bright: this.brightness === Code.bright, dim: this.brightness === Code.dim }); } }]); return Color; }(); /* ------------------------------------------------------------------------ */ var Code = function () { function Code(n) { _classCallCheck(this, Code); if (n !== undefined) { this.value = Number(n); } } _createClass(Code, [{ key: 'type', get: function get() { return types[Math.floor(this.value / 10)]; } }, { key: 'subtype', get: function get() { return subtypes[this.type][this.value % 10]; } }, { key: 'str', get: function get() { return this.value ? '\x1B[' + this.value + 'm' : ''; } }, { key: 'isBrightness', get: function get() { return this.value === Code.noBrightness || this.value === Code.bright || this.value === Code.dim; } }], [{ key: 'str', value: function str(x) { return new Code(x).str; } }]); return Code; }(); /* ------------------------------------------------------------------------ */ O.assign(Code, { reset: 0, bright: 1, dim: 2, inverse: 7, noBrightness: 22, noItalic: 23, noUnderline: 24, noInverse: 27, noColor: 39, noBgColor: 49 }); /* ------------------------------------------------------------------------ */ var replaceAll = function replaceAll(str, a, b) { return str.split(a).join(b); }; /* ANSI brightness codes do not overlap, e.g. "{bright}{dim}foo" will be rendered bright (not dim). So we fix it by adding brightness canceling before each brightness code, so the former example gets converted to "{noBrightness}{bright}{noBrightness}{dim}foo" – this way it gets rendered as expected. */ var denormalizeBrightness = function denormalizeBrightness(s) { return s.replace(/(\u001b\[(1|2)m)/g, '\x1B[22m$1'); }; var normalizeBrightness = function normalizeBrightness(s) { return s.replace(/\u001b\[22m(\u001b\[(1|2)m)/g, '$1'); }; var wrap = function wrap(x, openCode, closeCode) { var open = Code.str(openCode), close = Code.str(closeCode); return String(x).split('\n').map(function (line) { return denormalizeBrightness(open + replaceAll(normalizeBrightness(line), close, open) + close); }).join('\n'); }; /* ------------------------------------------------------------------------ */ var camel = function camel(a, b) { return a + b.charAt(0).toUpperCase() + b.slice(1); }; var stringWrappingMethods = function () { return [].concat(_toConsumableArray(colorCodes.map(function (k, i) { return !k ? [] : [// color methods [k, 30 + i, Code.noColor], [camel('bg', k), 40 + i, Code.noBgColor]]; })), _toConsumableArray(colorCodesLight.map(function (k, i) { return !k ? [] : [// light color methods [k, 90 + i, Code.noColor], [camel('bg', k), 100 + i, Code.noBgColor]]; })), _toConsumableArray(['', 'BrightRed', 'BrightGreen', 'BrightYellow', 'BrightBlue', 'BrightMagenta', 'BrightCyan'].map(function (k, i) { return !k ? [] : [['bg' + k, 100 + i, Code.noBgColor]]; })), _toConsumableArray(styleCodes.map(function (k, i) { return !k ? [] : [// style methods [k, i, k === 'bright' || k === 'dim' ? Code.noBrightness : 20 + i]]; }))).reduce(function (a, b) { return a.concat(b); }); }(); /* ------------------------------------------------------------------------ */ var assignStringWrappingAPI = function assignStringWrappingAPI(target) { var wrapBefore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : target; return stringWrappingMethods.reduce(function (memo, _ref) { var _ref2 = _slicedToArray(_ref, 3), k = _ref2[0], open = _ref2[1], close = _ref2[2]; return O.defineProperty(memo, k, { get: function get() { return assignStringWrappingAPI(function (str) { return wrapBefore(wrap(str, open, close)); }); } }); }, target); }; /* ------------------------------------------------------------------------ */ var TEXT = 0, BRACKET = 1, CODE = 2; function rawParse(s) { var state = TEXT, buffer = '', text = '', code = '', codes = []; var spans = []; for (var i = 0, n = s.length; i < n; i++) { var c = s[i]; buffer += c; switch (state) { case TEXT: if (c === '\x1B') { state = BRACKET;buffer = c; } else { text += c; } break; case BRACKET: if (c === '[') { state = CODE;code = '';codes = []; } else { state = TEXT;text += buffer; } break; case CODE: if (c >= '0' && c <= '9') { code += c; } else if (c === ';') { codes.push(new Code(code));code = ''; } else if (c === 'm' && code.length) { codes.push(new Code(code)); var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = codes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var _code = _step.value; spans.push({ text: text, code: _code });text = ''; } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } state = TEXT; } else { state = TEXT;text += buffer; } } } if (state !== TEXT) text += buffer; if (text) spans.push({ text: text, code: new Code() }); return spans; } /* ------------------------------------------------------------------------ */ /** * Represents an ANSI-escaped string. */ var Colors = function () { /** * @param {string} s a string containing ANSI escape codes. */ function Colors(s) { _classCallCheck(this, Colors); this.spans = s ? rawParse(s) : []; } _createClass(Colors, [{ key: Symbol.iterator, /** * @example * const spans = [...ansi.parse ('\u001b[7m\u001b[7mfoo\u001b[7mbar\u001b[27m')] */ value: function value() { return this.spans[Symbol.iterator](); } /** * @desc This allows an alternative import style, see https://github.com/xpl/ansicolor/issues/7#issuecomment-578923578 * @example * import { ansicolor, ParsedSpan } from 'ansicolor' */ }, { key: 'str', get: function get() { return this.spans.reduce(function (str, p) { return str + p.text + p.code.str; }, ''); } }, { key: 'parsed', get: function get() { var color = void 0, bgColor = void 0, brightness = void 0, styles = void 0; function reset() { color = new Color(), bgColor = new Color(true /* background */), brightness = undefined, styles = new Set(); } reset(); return O.assign(new Colors(), { spans: this.spans.map(function (span) { var c = span.code; var inverted = styles.has('inverse'), underline = styles.has('underline') ? 'text-decoration: underline;' : '', italic = styles.has('italic') ? 'font-style: italic;' : '', bold = brightness === Code.bright ? 'font-weight: bold;' : ''; var foreColor = color.defaultBrightness(brightness); var styledSpan = O.assign({ css: bold + italic + underline + foreColor.css(inverted) + bgColor.css(inverted) }, clean({ bold: !!bold, color: foreColor.clean, bgColor: bgColor.clean }), span); var _iteratorNormalCompletion2 = true; var _didIteratorError2 = false; var _iteratorError2 = undefined; try { for (var _iterator2 = styles[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { var k = _step2.value; styledSpan[k] = true; } } catch (err) { _didIteratorError2 = true; _iteratorError2 = err; } finally { try { if (!_iteratorNormalCompletion2 && _iterator2.return) { _iterator2.return(); } } finally { if (_didIteratorError2) { throw _iteratorError2; } } } if (c.isBrightness) { brightness = c.value; } else if (span.code.value !== undefined) { if (span.code.value === Code.reset) { reset(); } else { switch (span.code.type) { case 'color': case 'colorLight': color = new Color(false, c.subtype);break; case 'bgColor': case 'bgColorLight': bgColor = new Color(true, c.subtype);break; case 'style': styles.add(c.subtype);break; case 'unstyle': styles.delete(c.subtype);break; } } } return styledSpan; }).filter(function (s) { return s.text.length > 0; }) }); } /* Outputs with Chrome DevTools-compatible format */ }, { key: 'asChromeConsoleLogArguments', get: function get() { var spans = this.parsed.spans; return [spans.map(function (s) { return '%c' + s.text; }).join('')].concat(_toConsumableArray(spans.map(function (s) { return s.css; }))); } }, { key: 'browserConsoleArguments', get: function get() /* LEGACY, DEPRECATED */{ return this.asChromeConsoleLogArguments; } /** * @desc installs String prototype extensions * @example * require ('ansicolor').nice * console.log ('foo'.bright.red) */ }], [{ key: 'parse', /** * @desc parses a string containing ANSI escape codes * @return {Colors} parsed representation. */ value: function parse(s) { return new Colors(s).parsed; } /** * @desc strips ANSI codes from a string * @param {string} s a string containing ANSI escape codes. * @return {string} clean string. */ }, { key: 'strip', value: function strip(s) { return s.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-nqry=><]/g, ''); // hope V8 caches the regexp } }, { key: 'nice', get: function get() { Colors.names.forEach(function (k) { if (!(k in String.prototype)) { O.defineProperty(String.prototype, k, { get: function get() { return Colors[k](this); } }); } }); return Colors; } }, { key: 'ansicolor', get: function get() { return Colors; } }]); return Colors; }(); /* ------------------------------------------------------------------------ */ assignStringWrappingAPI(Colors, function (str) { return str; }); /* ------------------------------------------------------------------------ */ Colors.names = stringWrappingMethods.map(function (_ref3) { var _ref4 = _slicedToArray(_ref3, 1), k = _ref4[0]; return k; }); /* ------------------------------------------------------------------------ */ Colors.rgb = { black: [0, 0, 0], darkGray: [100, 100, 100], lightGray: [200, 200, 200], white: [255, 255, 255], red: [204, 0, 0], lightRed: [255, 51, 0], green: [0, 204, 0], lightGreen: [51, 204, 51], yellow: [204, 102, 0], lightYellow: [255, 153, 51], blue: [0, 0, 255], lightBlue: [26, 140, 255], magenta: [204, 0, 204], lightMagenta: [255, 0, 255], cyan: [0, 153, 255], lightCyan: [0, 204, 255] /* ------------------------------------------------------------------------ */ };module.exports = Colors; /* ------------------------------------------------------------------------ */ },{}],3:[function(require,module,exports){ "use strict"; function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } const O = Object; var _require = require('printable-characters'); const first = _require.first, strlen = _require.strlen, limit = (s, n) => first(s, n - 1) + '…'; const asColumns = (rows, cfg_) => { const zip = (arrs, f) => arrs.reduce((a, b) => b.map((b, i) => [].concat(_toConsumableArray(a[i] || []), [b])), []).map(args => f.apply(undefined, _toConsumableArray(args))), /* Convert cell data to string (converting multiline text to singleline) */ cells = rows.map(r => r.map(c => c.replace(/\n/g, '\\n'))), /* Compute column widths (per row) and max widths (per column) */ cellWidths = cells.map(r => r.map(strlen)), maxWidths = zip(cellWidths, Math.max), /* Default config */ cfg = O.assign({ delimiter: ' ', minColumnWidths: maxWidths.map(x => 0), maxTotalWidth: 0 }, cfg_), delimiterLength = strlen(cfg.delimiter), /* Project desired column widths, taking maxTotalWidth and minColumnWidths in account. */ totalWidth = maxWidths.reduce((a, b) => a + b, 0), relativeWidths = maxWidths.map(w => w / totalWidth), maxTotalWidth = cfg.maxTotalWidth - delimiterLength * (maxWidths.length - 1), excessWidth = Math.max(0, totalWidth - maxTotalWidth), computedWidths = zip([cfg.minColumnWidths, maxWidths, relativeWidths], (min, max, relative) => Math.max(min, Math.floor(max - excessWidth * relative))), /* This is how many symbols we should pad or cut (per column). */ restCellWidths = cellWidths.map(widths => zip([computedWidths, widths], (a, b) => a - b)); /* Perform final composition. */ return zip([cells, restCellWidths], (a, b) => zip([a, b], (str, w) => w >= 0 ? cfg.right ? ' '.repeat(w) + str : str + ' '.repeat(w) : limit(str, strlen(str) + w)).join(cfg.delimiter)); }; const asTable = cfg => O.assign(arr => { var _ref; /* Print arrays */ if (arr[0] && Array.isArray(arr[0])) { return asColumns(arr.map(r => r.map((c, i) => c === undefined ? '' : cfg.print(c, i))), cfg).join('\n'); } /* Print objects */ const colNames = [].concat(_toConsumableArray(new Set((_ref = []).concat.apply(_ref, _toConsumableArray(arr.map(O.keys)))))), columns = [colNames.map(cfg.title)].concat(_toConsumableArray(arr.map(o => colNames.map(key => o[key] === undefined ? '' : cfg.print(o[key], key))))), lines = asColumns(columns, cfg); return (cfg.dash ? [lines[0], cfg.dash.repeat(strlen(lines[0]))].concat(_toConsumableArray(lines.slice(1))) : lines).join('\n'); }, cfg, { configure: newConfig => asTable(O.assign({}, cfg, newConfig)) }); module.exports = asTable({ maxTotalWidth: Number.MAX_SAFE_INTEGER, print: String, title: String, dash: '-', right: false }); },{"printable-characters":12}],4:[function(require,module,exports){ 'use strict' exports.byteLength = byteLength exports.toByteArray = toByteArray exports.fromByteArray = fromByteArray var lookup = [] var revLookup = [] var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' for (var i = 0, len = code.length; i < len; ++i) { lookup[i] = code[i] revLookup[code.charCodeAt(i)] = i } // Support decoding URL-safe base64 strings, as Node.js does. // See: https://en.wikipedia.org/wiki/Base64#URL_applications revLookup['-'.charCodeAt(0)] = 62 revLookup['_'.charCodeAt(0)] = 63 function getLens (b64) { var len = b64.length if (len % 4 > 0) { throw new Error('Invalid string. Length must be a multiple of 4') } // Trim off extra bytes after placeholder bytes are found // See: https://github.com/beatgammit/base64-js/issues/42 var validLen = b64.indexOf('=') if (validLen === -1) validLen = len var placeHoldersLen = validLen === len ? 0 : 4 - (validLen % 4) return [validLen, placeHoldersLen] } // base64 is 4/3 + up to two characters of the original data function byteLength (b64) { var lens = getLens(b64) var validLen = lens[0] var placeHoldersLen = lens[1] return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen } function _byteLength (b64, validLen, placeHoldersLen) { return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen } function toByteArray (b64) { var tmp var lens = getLens(b64) var validLen = lens[0] var placeHoldersLen = lens[1] var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)) var curByte = 0 // if there are placeholders, only get up to the last complete 4 chars var len = placeHoldersLen > 0 ? validLen - 4 : validLen var i for (i = 0; i < len; i += 4) { tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] arr[curByte++] = (tmp >> 16) & 0xFF arr[curByte++] = (tmp >> 8) & 0xFF arr[curByte++] = tmp & 0xFF } if (placeHoldersLen === 2) { tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) arr[curByte++] = tmp & 0xFF } if (placeHoldersLen === 1) { tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) arr[curByte++] = (tmp >> 8) & 0xFF arr[curByte++] = tmp & 0xFF } return arr } function tripletToBase64 (num) { return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] } function encodeChunk (uint8, start, end) { var tmp var output = [] for (var i = start; i < end; i += 3) { tmp = ((uint8[i] << 16) & 0xFF0000) + ((uint8[i + 1] << 8) & 0xFF00) + (uint8[i + 2] & 0xFF) output.push(tripletToBase64(tmp)) } return output.join('') } function fromByteArray (uint8) { var tmp var len = uint8.length var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes var parts = [] var maxChunkLength = 16383 // must be multiple of 3 // go through the array every three bytes, we'll deal with trailing stuff later for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { parts.push(encodeChunk( uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength) )) } // pad the end with zeros, but make sure to not forget the extra bytes if (extraBytes === 1) { tmp = uint8[len - 1] parts.push( lookup[tmp >> 2] + lookup[(tmp << 4) & 0x3F] + '==' ) } else if (extraBytes === 2) { tmp = (uint8[len - 2] << 8) + uint8[len - 1] parts.push( lookup[tmp >> 10] + lookup[(tmp >> 4) & 0x3F] + lookup[(tmp << 2) & 0x3F] + '=' ) } return parts.join('') } },{}],5:[function(require,module,exports){ (function (Buffer){ /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh <https://feross.org> * @license MIT */ /* eslint-disable no-proto */ 'use strict' var base64 = require('base64-js') var ieee754 = require('ieee754') exports.Buffer = Buffer exports.SlowBuffer = SlowBuffer exports.INSPECT_MAX_BYTES = 50 var K_MAX_LENGTH = 0x7fffffff exports.kMaxLength = K_MAX_LENGTH /** * If `Buffer.TYPED_ARRAY_SUPPORT`: * === true Use Uint8Array implementation (fastest) * === false Print warning and recommend using `buffer` v4.x which has an Object * implementation (most compatible, even IE6) * * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, * Opera 11.6+, iOS 4.2+. * * We report that the browser does not support typed arrays if the are not subclassable * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support * for __proto__ and has a buggy typed array implementation. */ Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && typeof console.error === 'function') { console.error( 'This browser lacks typed array (Uint8Array) support which is required by ' + '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' ) } function typedArraySupport () { // Can typed array instances can be augmented? try { var arr = new Uint8Array(1) arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } } return arr.foo() === 42 } catch (e) { return false } } Object.defineProperty(Buffer.prototype, 'parent', { enumerable: true, get: function () { if (!Buffer.isBuffer(this)) return undefined return this.buffer } }) Object.defineProperty(Buffer.prototype, 'offset', { enumerable: true, get: function () { if (!Buffer.isBuffer(this)) return undefined return this.byteOffset } }) function createBuffer (length) { if (length > K_MAX_LENGTH) { throw new RangeError('The value "' + length + '" is invalid for option "size"') } // Return an augmented `Uint8Array` instance var buf = new Uint8Array(length) buf.__proto__ = Buffer.prototype return buf } /** * The Buffer constructor returns instances of `Uint8Array` that have their * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of * `Uint8Array`, so the returned instances will have all the node `Buffer` methods * and the `Uint8Array` methods. Square bracket notation works as expected -- it * returns a single octet. * * The `Uint8Array` prototype remains unmodified. */ function Buffer (arg, encodingOrOffset, length) { // Common case. if (typeof arg === 'number') { if (typeof encodingOrOffset === 'string') { throw new TypeError( 'The "string" argument must be of type string. Received type number' ) } return allocUnsafe(arg) } return from(arg, encodingOrOffset, length) } // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 if (typeof Symbol !== 'undefined' && Symbol.species != null && Buffer[Symbol.species] === Buffer) { Object.defineProperty(Buffer, Symbol.species, { value: null, configurable: true, enumerable: false, writable: false }) } Buffer.poolSize = 8192 // not used by this implementation function from (value, encodingOrOffset, length) { if (typeof value === 'string') { return fromString(value, encodingOrOffset) } if (ArrayBuffer.isView(value)) { return fromArrayLike(value) } if (value == null) { throw TypeError( 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + (typeof value) ) } if (isInstance(value, ArrayBuffer) || (value && isInstance(value.buffer, ArrayBuffer))) { return fromArrayBuffer(value, encodingOrOffset, length) } if (typeof value === 'number') { throw new TypeError( 'The "value" argument must not be of type number. Received type number' ) } var valueOf = value.valueOf && value.valueOf() if (valueOf != null && valueOf !== value) { return Buffer.from(valueOf, encodingOrOffset, length) } var b = fromObject(value) if (b) return b if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === 'function') { return Buffer.from( value[Symbol.toPrimitive]('string'), encodingOrOffset, length ) } throw new TypeError( 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + (typeof value) ) } /** * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError * if value is a number. * Buffer.from(str[, encoding]) * Buffer.from(array) * Buffer.from(buffer) * Buffer.from(arrayBuffer[, byteOffset[, length]]) **/ Buffer.from = function (value, encodingOrOffset, length) { return from(value, encodingOrOffset, length) } // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: // https://github.com/feross/buffer/pull/148 Buffer.prototype.__proto__ = Uint8Array.prototype Buffer.__proto__ = Uint8Array function assertSize (size) { if (typeof size !== 'number') { throw new TypeError('"size" argument must be of type number') } else if (size < 0) { throw new RangeError('The value "' + size + '" is invalid for option "size"') } } function alloc (size, fill, encoding) { assertSize(size) if (size <= 0) { return createBuffer(size) } if (fill !== undefined) { // Only pay attention to encoding if it's a string. This // prevents accidentally sending in a number that would // be interpretted as a start offset. return typeof encoding === 'string' ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill) } return createBuffer(size) } /** * Creates a new filled Buffer instance. * alloc(size[, fill[, encoding]]) **/ Buffer.alloc = function (size, fill, encoding) { return alloc(size, fill, encoding) } function allocUnsafe (size) { assertSize(size) return createBuffer(size < 0 ? 0 : checked(size) | 0) } /** * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. * */ Buffer.allocUnsafe = function (size) { return allocUnsafe(size) } /** * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. */ Buffer.allocUnsafeSlow = function (size) { return allocUnsafe(size) } function fromString (string, encoding) { if (typeof encoding !== 'string' || encoding === '') { encoding = 'utf8' } if (!Buffer.isEncoding(encoding)) { throw new TypeError('Unknown encoding: ' + encoding) } var length = byteLength(string, encoding) | 0 var buf = createBuffer(length) var actual = buf.write(string, encoding) if (actual !== length) { // Writing a hex string, for example, that contains invalid characters will // cause everything after the first invalid character to be ignored. (e.g. // 'abxxcd' will be treated as 'ab') buf = buf.slice(0, actual) } return buf } function fromArrayLike (array) { var length = array.length < 0 ? 0 : checked(array.length) | 0 var buf = createBuffer(length) for (var i = 0; i < length; i += 1) { buf[i] = array[i] & 255 } return buf } function fromArrayBuffer (array, byteOffset, length) { if (byteOffset < 0 || array.byteLength < byteOffset) { throw new RangeError('"offset" is outside of buffer bounds') } if (array.byteLength < byteOffset + (length || 0)) { throw new RangeError('"length" is outside of buffer bounds') } var buf if (byteOffset === undefined && length === undefined) { buf = new Uint8Array(array) } else if (length === undefined) { buf = new Uint8Array(array, byteOffset) } else { buf = new Uint8Array(array, byteOffset, length) } // Return an augmented `Uint8Array` instance buf.__proto__ = Buffer.prototype return buf } function fromObject (obj) { if (Buffer.isBuffer(obj)) { var len = checked(obj.length) | 0 var buf = createBuffer(len) if (buf.length === 0) { return buf } obj.copy(buf, 0, 0, len) return buf } if (obj.length !== undefined) { if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { return createBuffer(0) } return fromArrayLike(obj) } if (obj.type === 'Buffer' && Array.isArray(obj.data)) { return fromArrayLike(obj.data) } } function checked (length) { // Note: cannot use `length < K_MAX_LENGTH` here because that fails when // length is NaN (which is otherwise