arnaucube
arnaucube/commonroutesAppPublic Self-hosted repository
commonroutesApp/www/lib/angular-simple-logger/dist/browser.js
www/lib/angular-simple-logger/dist/browser.jsRaw
  1(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2angular.module('nemLogging', []);
  3
  4angular.module('nemLogging').provider('nemDebug', function (){
  5  var ourDebug = null;
  6  ourDebug = require('debug');
  7
  8  this.$get =  function(){
  9    //avail as service
 10    return ourDebug;
 11  };
 12
 13  //avail at provider, config time
 14  this.debug = ourDebug;
 15
 16  return this;
 17});
 18var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
 19  slice = [].slice;
 20
 21angular.module('nemLogging').provider('nemSimpleLogger', [
 22  'nemDebugProvider', function(nemDebugProvider) {
 23    var LEVELS, Logger, _debugCache, _fns, _isValidLogObject, _maybeExecLevel, _wrapDebug, i, key, len, nemDebug, val;
 24    nemDebug = nemDebugProvider.debug;
 25    _debugCache = {};
 26    _fns = ['debug', 'info', 'warn', 'error', 'log'];
 27    LEVELS = {};
 28    for (key = i = 0, len = _fns.length; i < len; key = ++i) {
 29      val = _fns[key];
 30      LEVELS[val] = key;
 31    }
 32    _maybeExecLevel = function(level, current, fn) {
 33      if (level >= current) {
 34        return fn();
 35      }
 36    };
 37    _isValidLogObject = function(logObject) {
 38      var isValid, j, len1;
 39      isValid = false;
 40      if (!logObject) {
 41        return isValid;
 42      }
 43      for (j = 0, len1 = _fns.length; j < len1; j++) {
 44        val = _fns[j];
 45        isValid = (logObject[val] != null) && typeof logObject[val] === 'function';
 46        if (!isValid) {
 47          break;
 48        }
 49      }
 50      return isValid;
 51    };
 52
 53    /*
 54      Overide logeObject.debug with a nemDebug instance
 55      see: https://github.com/visionmedia/debug/blob/master/Readme.md
 56     */
 57    _wrapDebug = function(namespace, logObject) {
 58      var debugInstance, j, len1, newLogger;
 59      if (_debugCache[namespace] == null) {
 60        _debugCache[namespace] = nemDebug(namespace);
 61      }
 62      debugInstance = _debugCache[namespace];
 63      newLogger = {};
 64      for (j = 0, len1 = _fns.length; j < len1; j++) {
 65        val = _fns[j];
 66        newLogger[val] = val === 'debug' ? debugInstance : logObject[val];
 67      }
 68      return newLogger;
 69    };
 70    Logger = (function() {
 71      function Logger($log1) {
 72        var fn1, j, len1, level, logFns;
 73        this.$log = $log1;
 74        this.spawn = bind(this.spawn, this);
 75        if (!this.$log) {
 76          throw 'internalLogger undefined';
 77        }
 78        if (!_isValidLogObject(this.$log)) {
 79          throw '@$log is invalid';
 80        }
 81        this.doLog = true;
 82        logFns = {};
 83        fn1 = (function(_this) {
 84          return function(level) {
 85            logFns[level] = function() {
 86              var args;
 87              args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
 88              if (_this.doLog) {
 89                return _maybeExecLevel(LEVELS[level], _this.currentLevel, function() {
 90                  var ref;
 91                  return (ref = _this.$log)[level].apply(ref, args);
 92                });
 93              }
 94            };
 95            return _this[level] = logFns[level];
 96          };
 97        })(this);
 98        for (j = 0, len1 = _fns.length; j < len1; j++) {
 99          level = _fns[j];
100          fn1(level);
101        }
102        this.LEVELS = LEVELS;
103        this.currentLevel = LEVELS.error;
104      }
105
106      Logger.prototype.spawn = function(newInternalLogger) {
107        if (typeof newInternalLogger === 'string') {
108          if (!_isValidLogObject(this.$log)) {
109            throw '@$log is invalid';
110          }
111          if (!nemDebug) {
112            throw 'nemDebug is undefined this is probably the light version of this library sep debug logggers is not supported!';
113          }
114          return _wrapDebug(newInternalLogger, this.$log);
115        }
116        return new Logger(newInternalLogger || this.$log);
117      };
118
119      return Logger;
120
121    })();
122    this.decorator = [
123      '$log', function($delegate) {
124        var log;
125        log = new Logger($delegate);
126        log.currentLevel = LEVELS.debug;
127        return log;
128      }
129    ];
130    this.$get = [
131      '$log', function($log) {
132        return new Logger($log);
133      }
134    ];
135    return this;
136  }
137]);
138
139},{"debug":2}],2:[function(require,module,exports){
140
141/**
142 * This is the web browser implementation of `debug()`.
143 *
144 * Expose `debug()` as the module.
145 */
146
147exports = module.exports = require('./debug');
148exports.log = log;
149exports.formatArgs = formatArgs;
150exports.save = save;
151exports.load = load;
152exports.useColors = useColors;
153exports.storage = 'undefined' != typeof chrome
154               && 'undefined' != typeof chrome.storage
155                  ? chrome.storage.local
156                  : localstorage();
157
158/**
159 * Colors.
160 */
161
162exports.colors = [
163  'lightseagreen',
164  'forestgreen',
165  'goldenrod',
166  'dodgerblue',
167  'darkorchid',
168  'crimson'
169];
170
171/**
172 * Currently only WebKit-based Web Inspectors, Firefox >= v31,
173 * and the Firebug extension (any Firefox version) are known
174 * to support "%c" CSS customizations.
175 *
176 * TODO: add a `localStorage` variable to explicitly enable/disable colors
177 */
178
179function useColors() {
180  // is webkit? http://stackoverflow.com/a/16459606/376773
181  return ('WebkitAppearance' in document.documentElement.style) ||
182    // is firebug? http://stackoverflow.com/a/398120/376773
183    (window.console && (console.firebug || (console.exception && console.table))) ||
184    // is firefox >= v31?
185    // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
186    (navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31);
187}
188
189/**
190 * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
191 */
192
193exports.formatters.j = function(v) {
194  return JSON.stringify(v);
195};
196
197
198/**
199 * Colorize log arguments if enabled.
200 *
201 * @api public
202 */
203
204function formatArgs() {
205  var args = arguments;
206  var useColors = this.useColors;
207
208  args[0] = (useColors ? '%c' : '')
209    + this.namespace
210    + (useColors ? ' %c' : ' ')
211    + args[0]
212    + (useColors ? '%c ' : ' ')
213    + '+' + exports.humanize(this.diff);
214
215  if (!useColors) return args;
216
217  var c = 'color: ' + this.color;
218  args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1));
219
220  // the final "%c" is somewhat tricky, because there could be other
221  // arguments passed either before or after the %c, so we need to
222  // figure out the correct index to insert the CSS into
223  var index = 0;
224  var lastC = 0;
225  args[0].replace(/%[a-z%]/g, function(match) {
226    if ('%%' === match) return;
227    index++;
228    if ('%c' === match) {
229      // we only are interested in the *last* %c
230      // (the user may have provided their own)
231      lastC = index;
232    }
233  });
234
235  args.splice(lastC, 0, c);
236  return args;
237}
238
239/**
240 * Invokes `console.log()` when available.
241 * No-op when `console.log` is not a "function".
242 *
243 * @api public
244 */
245
246function log() {
247  // this hackery is required for IE8/9, where
248  // the `console.log` function doesn't have 'apply'
249  return 'object' === typeof console
250    && console.log
251    && Function.prototype.apply.call(console.log, console, arguments);
252}
253
254/**
255 * Save `namespaces`.
256 *
257 * @param {String} namespaces
258 * @api private
259 */
260
261function save(namespaces) {
262  try {
263    if (null == namespaces) {
264      exports.storage.removeItem('debug');
265    } else {
266      exports.storage.debug = namespaces;
267    }
268  } catch(e) {}
269}
270
271/**
272 * Load `namespaces`.
273 *
274 * @return {String} returns the previously persisted debug modes
275 * @api private
276 */
277
278function load() {
279  var r;
280  try {
281    r = exports.storage.debug;
282  } catch(e) {}
283  return r;
284}
285
286/**
287 * Enable namespaces listed in `localStorage.debug` initially.
288 */
289
290exports.enable(load());
291
292/**
293 * Localstorage attempts to return the localstorage.
294 *
295 * This is necessary because safari throws
296 * when a user disables cookies/localstorage
297 * and you attempt to access it.
298 *
299 * @return {LocalStorage}
300 * @api private
301 */
302
303function localstorage(){
304  try {
305    return window.localStorage;
306  } catch (e) {}
307}
308
309},{"./debug":3}],3:[function(require,module,exports){
310
311/**
312 * This is the common logic for both the Node.js and web browser
313 * implementations of `debug()`.
314 *
315 * Expose `debug()` as the module.
316 */
317
318exports = module.exports = debug;
319exports.coerce = coerce;
320exports.disable = disable;
321exports.enable = enable;
322exports.enabled = enabled;
323exports.humanize = require('ms');
324
325/**
326 * The currently active debug mode names, and names to skip.
327 */
328
329exports.names = [];
330exports.skips = [];
331
332/**
333 * Map of special "%n" handling functions, for the debug "format" argument.
334 *
335 * Valid key names are a single, lowercased letter, i.e. "n".
336 */
337
338exports.formatters = {};
339
340/**
341 * Previously assigned color.
342 */
343
344var prevColor = 0;
345
346/**
347 * Previous log timestamp.
348 */
349
350var prevTime;
351
352/**
353 * Select a color.
354 *
355 * @return {Number}
356 * @api private
357 */
358
359function selectColor() {
360  return exports.colors[prevColor++ % exports.colors.length];
361}
362
363/**
364 * Create a debugger with the given `namespace`.
365 *
366 * @param {String} namespace
367 * @return {Function}
368 * @api public
369 */
370
371function debug(namespace) {
372
373  // define the `disabled` version
374  function disabled() {
375  }
376  disabled.enabled = false;
377
378  // define the `enabled` version
379  function enabled() {
380
381    var self = enabled;
382
383    // set `diff` timestamp
384    var curr = +new Date();
385    var ms = curr - (prevTime || curr);
386    self.diff = ms;
387    self.prev = prevTime;
388    self.curr = curr;
389    prevTime = curr;
390
391    // add the `color` if not set
392    if (null == self.useColors) self.useColors = exports.useColors();
393    if (null == self.color && self.useColors) self.color = selectColor();
394
395    var args = Array.prototype.slice.call(arguments);
396
397    args[0] = exports.coerce(args[0]);
398
399    if ('string' !== typeof args[0]) {
400      // anything else let's inspect with %o
401      args = ['%o'].concat(args);
402    }
403
404    // apply any `formatters` transformations
405    var index = 0;
406    args[0] = args[0].replace(/%([a-z%])/g, function(match, format) {
407      // if we encounter an escaped % then don't increase the array index
408      if (match === '%%') return match;
409      index++;
410      var formatter = exports.formatters[format];
411      if ('function' === typeof formatter) {
412        var val = args[index];
413        match = formatter.call(self, val);
414
415        // now we need to remove `args[index]` since it's inlined in the `format`
416        args.splice(index, 1);
417        index--;
418      }
419      return match;
420    });
421
422    if ('function' === typeof exports.formatArgs) {
423      args = exports.formatArgs.apply(self, args);
424    }
425    var logFn = enabled.log || exports.log || console.log.bind(console);
426    logFn.apply(self, args);
427  }
428  enabled.enabled = true;
429
430  var fn = exports.enabled(namespace) ? enabled : disabled;
431
432  fn.namespace = namespace;
433
434  return fn;
435}
436
437/**
438 * Enables a debug mode by namespaces. This can include modes
439 * separated by a colon and wildcards.
440 *
441 * @param {String} namespaces
442 * @api public
443 */
444
445function enable(namespaces) {
446  exports.save(namespaces);
447
448  var split = (namespaces || '').split(/[\s,]+/);
449  var len = split.length;
450
451  for (var i = 0; i < len; i++) {
452    if (!split[i]) continue; // ignore empty strings
453    namespaces = split[i].replace(/\*/g, '.*?');
454    if (namespaces[0] === '-') {
455      exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
456    } else {
457      exports.names.push(new RegExp('^' + namespaces + '$'));
458    }
459  }
460}
461
462/**
463 * Disable debug output.
464 *
465 * @api public
466 */
467
468function disable() {
469  exports.enable('');
470}
471
472/**
473 * Returns true if the given mode name is enabled, false otherwise.
474 *
475 * @param {String} name
476 * @return {Boolean}
477 * @api public
478 */
479
480function enabled(name) {
481  var i, len;
482  for (i = 0, len = exports.skips.length; i < len; i++) {
483    if (exports.skips[i].test(name)) {
484      return false;
485    }
486  }
487  for (i = 0, len = exports.names.length; i < len; i++) {
488    if (exports.names[i].test(name)) {
489      return true;
490    }
491  }
492  return false;
493}
494
495/**
496 * Coerce `val`.
497 *
498 * @param {Mixed} val
499 * @return {Mixed}
500 * @api private
501 */
502
503function coerce(val) {
504  if (val instanceof Error) return val.stack || val.message;
505  return val;
506}
507
508},{"ms":4}],4:[function(require,module,exports){
509/**
510 * Helpers.
511 */
512
513var s = 1000;
514var m = s * 60;
515var h = m * 60;
516var d = h * 24;
517var y = d * 365.25;
518
519/**
520 * Parse or format the given `val`.
521 *
522 * Options:
523 *
524 *  - `long` verbose formatting [false]
525 *
526 * @param {String|Number} val
527 * @param {Object} options
528 * @return {String|Number}
529 * @api public
530 */
531
532module.exports = function(val, options){
533  options = options || {};
534  if ('string' == typeof val) return parse(val);
535  return options.long
536    ? long(val)
537    : short(val);
538};
539
540/**
541 * Parse the given `str` and return milliseconds.
542 *
543 * @param {String} str
544 * @return {Number}
545 * @api private
546 */
547
548function parse(str) {
549  str = '' + str;
550  if (str.length > 10000) return;
551  var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
552  if (!match) return;
553  var n = parseFloat(match[1]);
554  var type = (match[2] || 'ms').toLowerCase();
555  switch (type) {
556    case 'years':
557    case 'year':
558    case 'yrs':
559    case 'yr':
560    case 'y':
561      return n * y;
562    case 'days':
563    case 'day':
564    case 'd':
565      return n * d;
566    case 'hours':
567    case 'hour':
568    case 'hrs':
569    case 'hr':
570    case 'h':
571      return n * h;
572    case 'minutes':
573    case 'minute':
574    case 'mins':
575    case 'min':
576    case 'm':
577      return n * m;
578    case 'seconds':
579    case 'second':
580    case 'secs':
581    case 'sec':
582    case 's':
583      return n * s;
584    case 'milliseconds':
585    case 'millisecond':
586    case 'msecs':
587    case 'msec':
588    case 'ms':
589      return n;
590  }
591}
592
593/**
594 * Short format for `ms`.
595 *
596 * @param {Number} ms
597 * @return {String}
598 * @api private
599 */
600
601function short(ms) {
602  if (ms >= d) return Math.round(ms / d) + 'd';
603  if (ms >= h) return Math.round(ms / h) + 'h';
604  if (ms >= m) return Math.round(ms / m) + 'm';
605  if (ms >= s) return Math.round(ms / s) + 's';
606  return ms + 'ms';
607}
608
609/**
610 * Long format for `ms`.
611 *
612 * @param {Number} ms
613 * @return {String}
614 * @api private
615 */
616
617function long(ms) {
618  return plural(ms, d, 'day')
619    || plural(ms, h, 'hour')
620    || plural(ms, m, 'minute')
621    || plural(ms, s, 'second')
622    || ms + ' ms';
623}
624
625/**
626 * Pluralization helper.
627 */
628
629function plural(ms, n, name) {
630  if (ms < n) return;
631  if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name;
632  return Math.ceil(ms / n) + ' ' + name + 's';
633}
634
635},{}]},{},[1]);