comunicationLeap/node_modules/socket.io-adapter/node_modules/debug/node.js
node_modules/socket.io-adapter/node_modules/debug/node.jsRaw
1
2/**
3 * Module dependencies.
4 */
5
6var tty = require('tty');
7var util = require('util');
8
9/**
10 * This is the Node.js implementation of `debug()`.
11 *
12 * Expose `debug()` as the module.
13 */
14
15exports = module.exports = require('./debug');
16exports.log = log;
17exports.formatArgs = formatArgs;
18exports.save = save;
19exports.load = load;
20exports.useColors = useColors;
21
22/**
23 * Colors.
24 */
25
26exports.colors = [6, 2, 3, 4, 5, 1];
27
28/**
29 * Is stdout a TTY? Colored output is enabled when `true`.
30 */
31
32function useColors() {
33 var debugColors = (process.env.DEBUG_COLORS || '').trim().toLowerCase();
34 if (0 === debugColors.length) {
35 return tty.isatty(1);
36 } else {
37 return '0' !== debugColors
38 && 'no' !== debugColors
39 && 'false' !== debugColors
40 && 'disabled' !== debugColors;
41 }
42}
43
44/**
45 * Map %o to `util.inspect()`, since Node doesn't do that out of the box.
46 */
47
48var inspect = (4 === util.inspect.length ?
49 // node <= 0.8.x
50 function (v, colors) {
51 return util.inspect(v, void 0, void 0, colors);
52 } :
53 // node > 0.8.x
54 function (v, colors) {
55 return util.inspect(v, { colors: colors });
56 }
57);
58
59exports.formatters.o = function(v) {
60 return inspect(v, this.useColors)
61 .replace(/\s*\n\s*/g, ' ');
62};
63
64/**
65 * Adds ANSI color escape codes if enabled.
66 *
67 * @api public
68 */
69
70function formatArgs() {
71 var args = arguments;
72 var useColors = this.useColors;
73 var name = this.namespace;
74
75 if (useColors) {
76 var c = this.color;
77
78 args[0] = ' \u001b[9' + c + 'm' + name + ' '
79 + '\u001b[0m'
80 + args[0] + '\u001b[3' + c + 'm'
81 + ' +' + exports.humanize(this.diff) + '\u001b[0m';
82 } else {
83 args[0] = new Date().toUTCString()
84 + ' ' + name + ' ' + args[0];
85 }
86 return args;
87}
88
89/**
90 * Invokes `console.log()` with the specified arguments.
91 */
92
93function log() {
94 return console.log.apply(console, arguments);
95}
96
97/**
98 * Save `namespaces`.
99 *
100 * @param {String} namespaces
101 * @api private
102 */
103
104function save(namespaces) {
105 if (null == namespaces) {
106 // If you set a process.env field to null or undefined, it gets cast to the
107 // string 'null' or 'undefined'. Just delete instead.
108 delete process.env.DEBUG;
109 } else {
110 process.env.DEBUG = namespaces;
111 }
112}
113
114/**
115 * Load `namespaces`.
116 *
117 * @return {String} returns the previously persisted debug modes
118 * @api private
119 */
120
121function load() {
122 return process.env.DEBUG;
123}
124
125/**
126 * Enable namespaces listed in `process.env.DEBUG` initially.
127 */
128
129exports.enable(load());