arnaucube
arnaucube/socketioMEANseedPublic Self-hosted repository
socketioMEANseed/server/node_modules/debug/browser.js
server/node_modules/debug/browser.jsRaw
  1
  2/**
  3 * This is the web browser implementation of `debug()`.
  4 *
  5 * Expose `debug()` as the module.
  6 */
  7
  8exports = module.exports = require('./debug');
  9exports.log = log;
 10exports.formatArgs = formatArgs;
 11exports.save = save;
 12exports.load = load;
 13exports.useColors = useColors;
 14
 15/**
 16 * Use chrome.storage.local if we are in an app
 17 */
 18
 19var storage;
 20
 21if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined')
 22  storage = chrome.storage.local;
 23else
 24  storage = localstorage();
 25
 26/**
 27 * Colors.
 28 */
 29
 30exports.colors = [
 31  'lightseagreen',
 32  'forestgreen',
 33  'goldenrod',
 34  'dodgerblue',
 35  'darkorchid',
 36  'crimson'
 37];
 38
 39/**
 40 * Currently only WebKit-based Web Inspectors, Firefox >= v31,
 41 * and the Firebug extension (any Firefox version) are known
 42 * to support "%c" CSS customizations.
 43 *
 44 * TODO: add a `localStorage` variable to explicitly enable/disable colors
 45 */
 46
 47function useColors() {
 48  // is webkit? http://stackoverflow.com/a/16459606/376773
 49  return ('WebkitAppearance' in document.documentElement.style) ||
 50    // is firebug? http://stackoverflow.com/a/398120/376773
 51    (window.console && (console.firebug || (console.exception && console.table))) ||
 52    // is firefox >= v31?
 53    // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
 54    (navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31);
 55}
 56
 57/**
 58 * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
 59 */
 60
 61exports.formatters.j = function(v) {
 62  return JSON.stringify(v);
 63};
 64
 65
 66/**
 67 * Colorize log arguments if enabled.
 68 *
 69 * @api public
 70 */
 71
 72function formatArgs() {
 73  var args = arguments;
 74  var useColors = this.useColors;
 75
 76  args[0] = (useColors ? '%c' : '')
 77    + this.namespace
 78    + (useColors ? ' %c' : ' ')
 79    + args[0]
 80    + (useColors ? '%c ' : ' ')
 81    + '+' + exports.humanize(this.diff);
 82
 83  if (!useColors) return args;
 84
 85  var c = 'color: ' + this.color;
 86  args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1));
 87
 88  // the final "%c" is somewhat tricky, because there could be other
 89  // arguments passed either before or after the %c, so we need to
 90  // figure out the correct index to insert the CSS into
 91  var index = 0;
 92  var lastC = 0;
 93  args[0].replace(/%[a-z%]/g, function(match) {
 94    if ('%%' === match) return;
 95    index++;
 96    if ('%c' === match) {
 97      // we only are interested in the *last* %c
 98      // (the user may have provided their own)
 99      lastC = index;
100    }
101  });
102
103  args.splice(lastC, 0, c);
104  return args;
105}
106
107/**
108 * Invokes `console.log()` when available.
109 * No-op when `console.log` is not a "function".
110 *
111 * @api public
112 */
113
114function log() {
115  // this hackery is required for IE8/9, where
116  // the `console.log` function doesn't have 'apply'
117  return 'object' === typeof console
118    && console.log
119    && Function.prototype.apply.call(console.log, console, arguments);
120}
121
122/**
123 * Save `namespaces`.
124 *
125 * @param {String} namespaces
126 * @api private
127 */
128
129function save(namespaces) {
130  try {
131    if (null == namespaces) {
132      storage.removeItem('debug');
133    } else {
134      storage.debug = namespaces;
135    }
136  } catch(e) {}
137}
138
139/**
140 * Load `namespaces`.
141 *
142 * @return {String} returns the previously persisted debug modes
143 * @api private
144 */
145
146function load() {
147  var r;
148  try {
149    r = storage.debug;
150  } catch(e) {}
151  return r;
152}
153
154/**
155 * Enable namespaces listed in `localStorage.debug` initially.
156 */
157
158exports.enable(load());
159
160/**
161 * Localstorage attempts to return the localstorage.
162 *
163 * This is necessary because safari throws
164 * when a user disables cookies/localstorage
165 * and you attempt to access it.
166 *
167 * @return {LocalStorage}
168 * @api private
169 */
170
171function localstorage(){
172  try {
173    return window.localStorage;
174  } catch (e) {}
175}