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