arnaucube
arnaucube/socketioMEANseedPublic Self-hosted repository
socketioMEANseed/server/node_modules/socket.io-client/node_modules/debug/debug.js
server/node_modules/socket.io-client/node_modules/debug/debug.jsRaw
  1
  2/**
  3 * This is the common logic for both the Node.js and web browser
  4 * implementations of `debug()`.
  5 *
  6 * Expose `debug()` as the module.
  7 */
  8
  9exports = module.exports = debug.debug = debug;
 10exports.coerce = coerce;
 11exports.disable = disable;
 12exports.enable = enable;
 13exports.enabled = enabled;
 14exports.humanize = require('ms');
 15
 16/**
 17 * The currently active debug mode names, and names to skip.
 18 */
 19
 20exports.names = [];
 21exports.skips = [];
 22
 23/**
 24 * Map of special "%n" handling functions, for the debug "format" argument.
 25 *
 26 * Valid key names are a single, lowercased letter, i.e. "n".
 27 */
 28
 29exports.formatters = {};
 30
 31/**
 32 * Previously assigned color.
 33 */
 34
 35var prevColor = 0;
 36
 37/**
 38 * Previous log timestamp.
 39 */
 40
 41var prevTime;
 42
 43/**
 44 * Select a color.
 45 *
 46 * @return {Number}
 47 * @api private
 48 */
 49
 50function selectColor() {
 51  return exports.colors[prevColor++ % exports.colors.length];
 52}
 53
 54/**
 55 * Create a debugger with the given `namespace`.
 56 *
 57 * @param {String} namespace
 58 * @return {Function}
 59 * @api public
 60 */
 61
 62function debug(namespace) {
 63
 64  // define the `disabled` version
 65  function disabled() {
 66  }
 67  disabled.enabled = false;
 68
 69  // define the `enabled` version
 70  function enabled() {
 71
 72    var self = enabled;
 73
 74    // set `diff` timestamp
 75    var curr = +new Date();
 76    var ms = curr - (prevTime || curr);
 77    self.diff = ms;
 78    self.prev = prevTime;
 79    self.curr = curr;
 80    prevTime = curr;
 81
 82    // add the `color` if not set
 83    if (null == self.useColors) self.useColors = exports.useColors();
 84    if (null == self.color && self.useColors) self.color = selectColor();
 85
 86    var args = new Array(arguments.length);
 87    for (var i = 0; i < args.length; i++) {
 88      args[i] = arguments[i];
 89    }
 90
 91    args[0] = exports.coerce(args[0]);
 92
 93    if ('string' !== typeof args[0]) {
 94      // anything else let's inspect with %o
 95      args = ['%o'].concat(args);
 96    }
 97
 98    // apply any `formatters` transformations
 99    var index = 0;
100    args[0] = args[0].replace(/%([a-z%])/g, function(match, format) {
101      // if we encounter an escaped % then don't increase the array index
102      if (match === '%%') return match;
103      index++;
104      var formatter = exports.formatters[format];
105      if ('function' === typeof formatter) {
106        var val = args[index];
107        match = formatter.call(self, val);
108
109        // now we need to remove `args[index]` since it's inlined in the `format`
110        args.splice(index, 1);
111        index--;
112      }
113      return match;
114    });
115
116    // apply env-specific formatting
117    args = exports.formatArgs.apply(self, args);
118
119    var logFn = enabled.log || exports.log || console.log.bind(console);
120    logFn.apply(self, args);
121  }
122  enabled.enabled = true;
123
124  var fn = exports.enabled(namespace) ? enabled : disabled;
125
126  fn.namespace = namespace;
127
128  return fn;
129}
130
131/**
132 * Enables a debug mode by namespaces. This can include modes
133 * separated by a colon and wildcards.
134 *
135 * @param {String} namespaces
136 * @api public
137 */
138
139function enable(namespaces) {
140  exports.save(namespaces);
141
142  var split = (namespaces || '').split(/[\s,]+/);
143  var len = split.length;
144
145  for (var i = 0; i < len; i++) {
146    if (!split[i]) continue; // ignore empty strings
147    namespaces = split[i].replace(/[\\^$+?.()|[\]{}]/g, '\\$&').replace(/\*/g, '.*?');
148    if (namespaces[0] === '-') {
149      exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
150    } else {
151      exports.names.push(new RegExp('^' + namespaces + '$'));
152    }
153  }
154}
155
156/**
157 * Disable debug output.
158 *
159 * @api public
160 */
161
162function disable() {
163  exports.enable('');
164}
165
166/**
167 * Returns true if the given mode name is enabled, false otherwise.
168 *
169 * @param {String} name
170 * @return {Boolean}
171 * @api public
172 */
173
174function enabled(name) {
175  var i, len;
176  for (i = 0, len = exports.skips.length; i < len; i++) {
177    if (exports.skips[i].test(name)) {
178      return false;
179    }
180  }
181  for (i = 0, len = exports.names.length; i < len; i++) {
182    if (exports.names[i].test(name)) {
183      return true;
184    }
185  }
186  return false;
187}
188
189/**
190 * Coerce `val`.
191 *
192 * @param {Mixed} val
193 * @return {Mixed}
194 * @api private
195 */
196
197function coerce(val) {
198  if (val instanceof Error) return val.stack || val.message;
199  return val;
200}