Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / node_modules / debug / src / node.js
1 "use strict";
2
3 /**
4  * Module dependencies.
5  */
6 var tty = require('tty');
7
8 var util = require('util');
9 /**
10  * This is the Node.js implementation of `debug()`.
11  */
12
13
14 exports.init = init;
15 exports.log = log;
16 exports.formatArgs = formatArgs;
17 exports.save = save;
18 exports.load = load;
19 exports.useColors = useColors;
20 /**
21  * Colors.
22  */
23
24 exports.colors = [6, 2, 3, 4, 5, 1];
25
26 try {
27   // Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
28   // eslint-disable-next-line import/no-extraneous-dependencies
29   var supportsColor = require('supports-color');
30
31   if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
32     exports.colors = [20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 62, 63, 68, 69, 74, 75, 76, 77, 78, 79, 80, 81, 92, 93, 98, 99, 112, 113, 128, 129, 134, 135, 148, 149, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 178, 179, 184, 185, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 214, 215, 220, 221];
33   }
34 } catch (error) {} // Swallow - we only care if `supports-color` is available; it doesn't have to be.
35
36 /**
37  * Build up the default `inspectOpts` object from the environment variables.
38  *
39  *   $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
40  */
41
42
43 exports.inspectOpts = Object.keys(process.env).filter(function (key) {
44   return /^debug_/i.test(key);
45 }).reduce(function (obj, key) {
46   // Camel-case
47   var prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, function (_, k) {
48     return k.toUpperCase();
49   }); // Coerce string value into JS value
50
51   var val = process.env[key];
52
53   if (/^(yes|on|true|enabled)$/i.test(val)) {
54     val = true;
55   } else if (/^(no|off|false|disabled)$/i.test(val)) {
56     val = false;
57   } else if (val === 'null') {
58     val = null;
59   } else {
60     val = Number(val);
61   }
62
63   obj[prop] = val;
64   return obj;
65 }, {});
66 /**
67  * Is stdout a TTY? Colored output is enabled when `true`.
68  */
69
70 function useColors() {
71   return 'colors' in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(process.stderr.fd);
72 }
73 /**
74  * Adds ANSI color escape codes if enabled.
75  *
76  * @api public
77  */
78
79
80 function formatArgs(args) {
81   var name = this.namespace,
82       useColors = this.useColors;
83
84   if (useColors) {
85     var c = this.color;
86     var colorCode = "\x1B[3" + (c < 8 ? c : '8;5;' + c);
87     var prefix = "  ".concat(colorCode, ";1m").concat(name, " \x1B[0m");
88     args[0] = prefix + args[0].split('\n').join('\n' + prefix);
89     args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + "\x1B[0m");
90   } else {
91     args[0] = getDate() + name + ' ' + args[0];
92   }
93 }
94
95 function getDate() {
96   if (exports.inspectOpts.hideDate) {
97     return '';
98   }
99
100   return new Date().toISOString() + ' ';
101 }
102 /**
103  * Invokes `util.format()` with the specified arguments and writes to stderr.
104  */
105
106
107 function log() {
108   return process.stderr.write(util.format.apply(util, arguments) + '\n');
109 }
110 /**
111  * Save `namespaces`.
112  *
113  * @param {String} namespaces
114  * @api private
115  */
116
117
118 function save(namespaces) {
119   if (namespaces) {
120     process.env.DEBUG = namespaces;
121   } else {
122     // If you set a process.env field to null or undefined, it gets cast to the
123     // string 'null' or 'undefined'. Just delete instead.
124     delete process.env.DEBUG;
125   }
126 }
127 /**
128  * Load `namespaces`.
129  *
130  * @return {String} returns the previously persisted debug modes
131  * @api private
132  */
133
134
135 function load() {
136   return process.env.DEBUG;
137 }
138 /**
139  * Init logic for `debug` instances.
140  *
141  * Create a new `inspectOpts` object in case `useColors` is set
142  * differently for a particular `debug` instance.
143  */
144
145
146 function init(debug) {
147   debug.inspectOpts = {};
148   var keys = Object.keys(exports.inspectOpts);
149
150   for (var i = 0; i < keys.length; i++) {
151     debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
152   }
153 }
154
155 module.exports = require('./common')(exports);
156 var formatters = module.exports.formatters;
157 /**
158  * Map %o to `util.inspect()`, all on a single line.
159  */
160
161 formatters.o = function (v) {
162   this.inspectOpts.colors = this.useColors;
163   return util.inspect(v, this.inspectOpts)
164     .split('\n')
165     .map(function (str) { return str.trim(); })
166     .join(' ');
167 };
168 /**
169  * Map %O to `util.inspect()`, allowing multiple lines if needed.
170  */
171
172
173 formatters.O = function (v) {
174   this.inspectOpts.colors = this.useColors;
175   return util.inspect(v, this.inspectOpts);
176 };
177