UNPKG

10.3 kBSource Map (JSON)View Raw
1{
2 "version": 3,
3 "sources": ["../src/common.ts"],
4 "sourcesContent": ["// from https://github.com/visionmedia/debug/blob/master/src/common.js\n/**\n * This is the common logic for both the Node.js and web browser\n * implementations of `debug()`.\n */\n\nexport function setup(env) {\n /**\n * Create a debugger with the given `namespace`.\n *\n * @param {String} namespace\n * @return {Function}\n * @api public\n */\n const createDebug: any = (namespace, logger) => {\n let prevTime\n let enableOverride = null\n let namespacesCache\n let enabledCache\n\n const debug: any = (...args) => {\n // Disabled?\n\n const self = debug\n\n // Set `diff` timestamp\n const curr = Number(new Date())\n const ms = curr - (prevTime || curr)\n self.diff = ms\n self.prev = prevTime\n self.curr = curr\n prevTime = curr\n\n args[0] = createDebug.coerce(args[0])\n\n if (typeof args[0] !== 'string') {\n // Anything else let's inspect with %O\n args.unshift('%O')\n }\n\n // Apply any `formatters` transformations\n let index = 0\n args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {\n // If we encounter an escaped % then don't increase the array index\n if (match === '%%') {\n return '%'\n }\n index++\n const formatter = createDebug.formatters[format]\n if (typeof formatter === 'function') {\n const val = args[index]\n match = formatter.call(self, val)\n\n // Now we need to remove `args[index]` since it's inlined in the `format`\n args.splice(index, 1)\n index--\n }\n return match\n })\n\n // Apply env-specific formatting (colors, etc.)\n createDebug.formatArgs.call(self, args)\n\n if (logger && typeof logger === 'function') {\n logger.apply(self, args)\n }\n\n if (debug.enabled) {\n const logFn = self.log || createDebug.log\n logFn.apply(self, args)\n }\n }\n\n debug.namespace = namespace\n debug.useColors = createDebug.useColors()\n debug.color = createDebug.selectColor(namespace)\n debug.extend = extend\n debug.destroy = createDebug.destroy // XXX Temporary. Will be removed in the next major release.\n\n Object.defineProperty(debug, 'enabled', {\n enumerable: true,\n configurable: false,\n get: () => {\n if (enableOverride !== null) {\n return enableOverride\n }\n if (namespacesCache !== createDebug.namespaces) {\n namespacesCache = createDebug.namespaces\n enabledCache = createDebug.enabled(namespace)\n }\n\n return enabledCache\n },\n set: (v) => {\n enableOverride = v\n },\n })\n\n // Env-specific initialization logic for debug instances\n if (typeof createDebug.init === 'function') {\n createDebug.init(debug)\n }\n\n return debug\n }\n\n createDebug.debug = createDebug\n createDebug.default = createDebug\n createDebug.coerce = coerce\n createDebug.disable = disable\n createDebug.enable = enable\n createDebug.enabled = enabled\n createDebug.humanize = require('ms')\n createDebug.destroy = destroy\n\n Object.keys(env).forEach((key) => {\n createDebug[key] = env[key]\n })\n\n /**\n * The currently active debug mode names, and names to skip.\n */\n\n createDebug.names = []\n createDebug.skips = []\n\n /**\n * Map of special \"%n\" handling functions, for the debug \"format\" argument.\n *\n * Valid key names are a single, lower or upper-case letter, i.e. \"n\" and \"N\".\n */\n createDebug.formatters = {}\n\n /**\n * Selects a color for a debug namespace\n * @param {String} namespace The namespace string for the for the debug instance to be colored\n * @return {Number|String} An ANSI color code for the given namespace\n * @api private\n */\n function selectColor(namespace) {\n let hash = 0\n\n for (let i = 0; i < namespace.length; i++) {\n hash = (hash << 5) - hash + namespace.charCodeAt(i)\n hash |= 0 // Convert to 32bit integer\n }\n\n return createDebug.colors[Math.abs(hash) % createDebug.colors.length]\n }\n createDebug.selectColor = selectColor\n\n function extend(this, namespace, delimiter) {\n const newDebug = createDebug(\n this.namespace +\n (typeof delimiter === 'undefined' ? ':' : delimiter) +\n namespace,\n )\n newDebug.log = this.log\n return newDebug\n }\n\n /**\n * Enables a debug mode by namespaces. This can include modes\n * separated by a colon and wildcards.\n *\n * @param {String} namespaces\n * @api public\n */\n function enable(namespaces) {\n createDebug.save(namespaces)\n createDebug.namespaces = namespaces\n\n createDebug.names = []\n createDebug.skips = []\n\n let i\n const split = (typeof namespaces === 'string' ? namespaces : '').split(\n /[\\s,]+/,\n )\n const len = split.length\n\n for (i = 0; i < len; i++) {\n if (!split[i]) {\n // ignore empty strings\n continue\n }\n\n namespaces = split[i].replace(/\\*/g, '.*?')\n\n if (namespaces[0] === '-') {\n createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'))\n } else {\n createDebug.names.push(new RegExp('^' + namespaces + '$'))\n }\n }\n }\n\n /**\n * Disable debug output.\n *\n * @return {String} namespaces\n * @api public\n */\n function disable() {\n const namespaces = [\n ...createDebug.names.map(toNamespace),\n ...createDebug.skips.map(toNamespace).map((namespace) => '-' + namespace),\n ].join(',')\n createDebug.enable('')\n return namespaces\n }\n\n /**\n * Returns true if the given mode name is enabled, false otherwise.\n *\n * @param {String} name\n * @return {Boolean}\n * @api public\n */\n function enabled(name) {\n if (name[name.length - 1] === '*') {\n return true\n }\n\n let i\n let len\n\n for (i = 0, len = createDebug.skips.length; i < len; i++) {\n if (createDebug.skips[i].test(name)) {\n return false\n }\n }\n\n for (i = 0, len = createDebug.names.length; i < len; i++) {\n if (createDebug.names[i].test(name)) {\n return true\n }\n }\n\n return false\n }\n\n /**\n * Convert regexp to namespace\n *\n * @param {RegExp} regxep\n * @return {String} namespace\n * @api private\n */\n function toNamespace(regexp) {\n return regexp\n .toString()\n .substring(2, regexp.toString().length - 2)\n .replace(/\\.\\*\\?$/, '*')\n }\n\n /**\n * Coerce `val`.\n *\n * @param {Mixed} val\n * @return {Mixed}\n * @api private\n */\n function coerce(val) {\n if (val instanceof Error) {\n return val.stack || val.message\n }\n return val\n }\n\n /**\n * XXX DO NOT USE. This is a temporary stub function.\n * XXX It WILL be removed in the next major release.\n */\n function destroy() {\n console.warn(\n 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.',\n )\n }\n\n createDebug.enable(createDebug.load())\n\n return createDebug\n}\n"],
5 "mappings": ";;;;;;;AAAA;AAAA;AAAA;AAMO,eAAe,KAAK;AAQzB,QAAM,cAAmB,CAAC,WAAW,WAAW;AAC9C,QAAI;AACJ,QAAI,iBAAiB;AACrB,QAAI;AACJ,QAAI;AAEJ,UAAM,QAAa,IAAI,SAAS;AAG9B,YAAM,OAAO;AAGb,YAAM,OAAO,OAAO,IAAI;AACxB,YAAM,KAAK,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