Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / debug / src / common.js
index 2f82b8dc7d886526e3faf1c5494516d4eafc9565..392a8e005a063a6ed99295cbd1859bef2f60bb11 100644 (file)
@@ -12,16 +12,12 @@ function setup(env) {
        createDebug.enable = enable;
        createDebug.enabled = enabled;
        createDebug.humanize = require('ms');
+       createDebug.destroy = destroy;
 
        Object.keys(env).forEach(key => {
                createDebug[key] = env[key];
        });
 
-       /**
-       * Active `debug` instances.
-       */
-       createDebug.instances = [];
-
        /**
        * The currently active debug mode names, and names to skip.
        */
@@ -63,6 +59,7 @@ function setup(env) {
        */
        function createDebug(namespace) {
                let prevTime;
+               let enableOverride = null;
 
                function debug(...args) {
                        // Disabled?
@@ -92,7 +89,7 @@ function setup(env) {
                        args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
                                // If we encounter an escaped % then don't increase the array index
                                if (match === '%%') {
-                                       return match;
+                                       return '%';
                                }
                                index++;
                                const formatter = createDebug.formatters[format];
@@ -115,33 +112,28 @@ function setup(env) {
                }
 
                debug.namespace = namespace;
-               debug.enabled = createDebug.enabled(namespace);
                debug.useColors = createDebug.useColors();
-               debug.color = selectColor(namespace);
-               debug.destroy = destroy;
+               debug.color = createDebug.selectColor(namespace);
                debug.extend = extend;
-               // Debug.formatArgs = formatArgs;
-               // debug.rawLog = rawLog;
+               debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
+
+               Object.defineProperty(debug, 'enabled', {
+                       enumerable: true,
+                       configurable: false,
+                       get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride,
+                       set: v => {
+                               enableOverride = v;
+                       }
+               });
 
-               // env-specific initialization logic for debug instances
+               // Env-specific initialization logic for debug instances
                if (typeof createDebug.init === 'function') {
                        createDebug.init(debug);
                }
 
-               createDebug.instances.push(debug);
-
                return debug;
        }
 
-       function destroy() {
-               const index = createDebug.instances.indexOf(this);
-               if (index !== -1) {
-                       createDebug.instances.splice(index, 1);
-                       return true;
-               }
-               return false;
-       }
-
        function extend(namespace, delimiter) {
                const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
                newDebug.log = this.log;
@@ -179,11 +171,6 @@ function setup(env) {
                                createDebug.names.push(new RegExp('^' + namespaces + '$'));
                        }
                }
-
-               for (i = 0; i < createDebug.instances.length; i++) {
-                       const instance = createDebug.instances[i];
-                       instance.enabled = createDebug.enabled(instance.namespace);
-               }
        }
 
        /**
@@ -258,6 +245,14 @@ function setup(env) {
                return val;
        }
 
+       /**
+       * XXX DO NOT USE. This is a temporary stub function.
+       * XXX It WILL be removed in the next major release.
+       */
+       function destroy() {
+               console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
+       }
+
        createDebug.enable(createDebug.load());
 
        return createDebug;