bluenode 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,291 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ var util = require('util');
23
+
24
+ function EventEmitter() {
25
+ EventEmitter.init.call(this);
26
+ }
27
+ module.exports = EventEmitter;
28
+
29
+ // Backwards-compat with node 0.10.x
30
+ EventEmitter.EventEmitter = EventEmitter;
31
+
32
+ EventEmitter.prototype._events = undefined;
33
+ EventEmitter.prototype._maxListeners = undefined;
34
+
35
+ // By default EventEmitters will print a warning if more than 10 listeners are
36
+ // added to it. This is a useful default which helps finding memory leaks.
37
+ EventEmitter.defaultMaxListeners = 10;
38
+
39
+ EventEmitter.init = function() {
40
+ if (!this._events || this._events === Object.getPrototypeOf(this)._events)
41
+ this._events = {};
42
+
43
+ this._maxListeners = this._maxListeners || undefined;
44
+ };
45
+
46
+ // Obviously not all Emitters should be limited to 10. This function allows
47
+ // that to be increased. Set to zero for unlimited.
48
+ EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
49
+ if (!util.isNumber(n) || n < 0 || isNaN(n))
50
+ throw TypeError('n must be a positive number');
51
+ this._maxListeners = n;
52
+ return this;
53
+ };
54
+
55
+ EventEmitter.prototype.emit = function emit(type) {
56
+ var er, handler, len, args, i, listeners;
57
+
58
+ if (!this._events)
59
+ this._events = {};
60
+
61
+ // If there is no 'error' event listener then throw.
62
+ if (type === 'error' && !this._events.error) {
63
+ er = arguments[1];
64
+ if (er instanceof Error) {
65
+ throw er; // Unhandled 'error' event
66
+ } else {
67
+ throw Error('Uncaught, unspecified "error" event.');
68
+ }
69
+ return false;
70
+ }
71
+
72
+ handler = this._events[type];
73
+
74
+ if (util.isUndefined(handler))
75
+ return false;
76
+
77
+ if (util.isFunction(handler)) {
78
+ switch (arguments.length) {
79
+ // fast cases
80
+ case 1:
81
+ handler.call(this);
82
+ break;
83
+ case 2:
84
+ handler.call(this, arguments[1]);
85
+ break;
86
+ case 3:
87
+ handler.call(this, arguments[1], arguments[2]);
88
+ break;
89
+ // slower
90
+ default:
91
+ len = arguments.length;
92
+ args = new Array(len - 1);
93
+ for (i = 1; i < len; i++)
94
+ args[i - 1] = arguments[i];
95
+ handler.apply(this, args);
96
+ }
97
+ } else if (util.isObject(handler)) {
98
+ len = arguments.length;
99
+ args = new Array(len - 1);
100
+ for (i = 1; i < len; i++)
101
+ args[i - 1] = arguments[i];
102
+
103
+ listeners = handler.slice();
104
+ len = listeners.length;
105
+ for (i = 0; i < len; i++)
106
+ listeners[i].apply(this, args);
107
+ }
108
+
109
+ return true;
110
+ };
111
+
112
+ EventEmitter.prototype.addListener = function addListener(type, listener) {
113
+ var m;
114
+
115
+ if (!util.isFunction(listener))
116
+ throw TypeError('listener must be a function');
117
+
118
+ if (!this._events)
119
+ this._events = {};
120
+
121
+ // To avoid recursion in the case that type === "newListener"! Before
122
+ // adding it to the listeners, first emit "newListener".
123
+ if (this._events.newListener)
124
+ this.emit('newListener', type,
125
+ util.isFunction(listener.listener) ?
126
+ listener.listener : listener);
127
+
128
+ if (!this._events[type])
129
+ // Optimize the case of one listener. Don't need the extra array object.
130
+ this._events[type] = listener;
131
+ else if (util.isObject(this._events[type]))
132
+ // If we've already got an array, just append.
133
+ this._events[type].push(listener);
134
+ else
135
+ // Adding the second element, need to change to array.
136
+ this._events[type] = [this._events[type], listener];
137
+
138
+ // Check for listener leak
139
+ if (util.isObject(this._events[type]) && !this._events[type].warned) {
140
+ var m;
141
+ if (!util.isUndefined(this._maxListeners)) {
142
+ m = this._maxListeners;
143
+ } else {
144
+ m = EventEmitter.defaultMaxListeners;
145
+ }
146
+
147
+ if (m && m > 0 && this._events[type].length > m) {
148
+ this._events[type].warned = true;
149
+ console.error('(node) warning: possible EventEmitter memory ' +
150
+ 'leak detected. %d %s listeners added. ' +
151
+ 'Use emitter.setMaxListeners() to increase limit.',
152
+ this._events[type].length, type);
153
+ console.trace();
154
+ }
155
+ }
156
+
157
+ return this;
158
+ };
159
+
160
+ EventEmitter.prototype.on = EventEmitter.prototype.addListener;
161
+
162
+ EventEmitter.prototype.once = function once(type, listener) {
163
+ if (!util.isFunction(listener))
164
+ throw TypeError('listener must be a function');
165
+
166
+ var fired = false;
167
+
168
+ function g() {
169
+ this.removeListener(type, g);
170
+
171
+ if (!fired) {
172
+ fired = true;
173
+ listener.apply(this, arguments);
174
+ }
175
+ }
176
+
177
+ g.listener = listener;
178
+ this.on(type, g);
179
+
180
+ return this;
181
+ };
182
+
183
+ // emits a 'removeListener' event iff the listener was removed
184
+ EventEmitter.prototype.removeListener =
185
+ function removeListener(type, listener) {
186
+ var list, position, length, i;
187
+
188
+ if (!util.isFunction(listener))
189
+ throw TypeError('listener must be a function');
190
+
191
+ if (!this._events || !this._events[type])
192
+ return this;
193
+
194
+ list = this._events[type];
195
+ length = list.length;
196
+ position = -1;
197
+
198
+ if (list === listener ||
199
+ (util.isFunction(list.listener) && list.listener === listener)) {
200
+ delete this._events[type];
201
+ if (this._events.removeListener)
202
+ this.emit('removeListener', type, listener);
203
+
204
+ } else if (util.isObject(list)) {
205
+ for (i = length; i-- > 0;) {
206
+ if (list[i] === listener ||
207
+ (list[i].listener && list[i].listener === listener)) {
208
+ position = i;
209
+ break;
210
+ }
211
+ }
212
+
213
+ if (position < 0)
214
+ return this;
215
+
216
+ if (list.length === 1) {
217
+ list.length = 0;
218
+ delete this._events[type];
219
+ } else {
220
+ list.splice(position, 1);
221
+ }
222
+
223
+ if (this._events.removeListener)
224
+ this.emit('removeListener', type, listener);
225
+ }
226
+
227
+ return this;
228
+ };
229
+
230
+ EventEmitter.prototype.removeAllListeners =
231
+ function removeAllListeners(type) {
232
+ var key, listeners;
233
+
234
+ if (!this._events)
235
+ return this;
236
+
237
+ // not listening for removeListener, no need to emit
238
+ if (!this._events.removeListener) {
239
+ if (arguments.length === 0)
240
+ this._events = {};
241
+ else if (this._events[type])
242
+ delete this._events[type];
243
+ return this;
244
+ }
245
+
246
+ // emit removeListener for all listeners on all events
247
+ if (arguments.length === 0) {
248
+ for (key in this._events) {
249
+ if (key === 'removeListener') continue;
250
+ this.removeAllListeners(key);
251
+ }
252
+ this.removeAllListeners('removeListener');
253
+ this._events = {};
254
+ return this;
255
+ }
256
+
257
+ listeners = this._events[type];
258
+
259
+ if (util.isFunction(listeners)) {
260
+ this.removeListener(type, listeners);
261
+ } else if (Array.isArray(listeners)) {
262
+ // LIFO order
263
+ while (listeners.length)
264
+ this.removeListener(type, listeners[listeners.length - 1]);
265
+ }
266
+ delete this._events[type];
267
+
268
+ return this;
269
+ };
270
+
271
+ EventEmitter.prototype.listeners = function listeners(type) {
272
+ var ret;
273
+ if (!this._events || !this._events[type])
274
+ ret = [];
275
+ else if (util.isFunction(this._events[type]))
276
+ ret = [this._events[type]];
277
+ else
278
+ ret = this._events[type].slice();
279
+ return ret;
280
+ };
281
+
282
+ EventEmitter.listenerCount = function(emitter, type) {
283
+ var ret;
284
+ if (!emitter._events || !emitter._events[type])
285
+ ret = 0;
286
+ else if (util.isFunction(emitter._events[type]))
287
+ ret = 1;
288
+ else
289
+ ret = emitter._events[type].length;
290
+ return ret;
291
+ };
@@ -0,0 +1 @@
1
+ module.exports = {};
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ join: function() {}
3
+ };
@@ -0,0 +1 @@
1
+ module.exports = function() {};
@@ -0,0 +1,654 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ var formatRegExp = /%[sdj%]/g;
23
+ exports.format = function(f) {
24
+ if (!isString(f)) {
25
+ var objects = [];
26
+ for (var i = 0; i < arguments.length; i++) {
27
+ objects.push(inspect(arguments[i]));
28
+ }
29
+ return objects.join(' ');
30
+ }
31
+
32
+ var i = 1;
33
+ var args = arguments;
34
+ var len = args.length;
35
+ var str = String(f).replace(formatRegExp, function(x) {
36
+ if (x === '%%') return '%';
37
+ if (i >= len) return x;
38
+ switch (x) {
39
+ case '%s': return String(args[i++]);
40
+ case '%d': return Number(args[i++]);
41
+ case '%j':
42
+ try {
43
+ return JSON.stringify(args[i++]);
44
+ } catch (_) {
45
+ return '[Circular]';
46
+ }
47
+ default:
48
+ return x;
49
+ }
50
+ });
51
+ for (var x = args[i]; i < len; x = args[++i]) {
52
+ if (isNull(x) || !isObject(x)) {
53
+ str += ' ' + x;
54
+ } else {
55
+ str += ' ' + inspect(x);
56
+ }
57
+ }
58
+ return str;
59
+ };
60
+
61
+
62
+ // Mark that a method should not be used.
63
+ // Returns a modified function which warns once by default.
64
+ // If --no-deprecation is set, then it is a no-op.
65
+ exports.deprecate = function(fn, msg) {
66
+ // Allow for deprecating things in the process of starting up.
67
+ if (isUndefined(global.process)) {
68
+ return function() {
69
+ return exports.deprecate(fn, msg).apply(this, arguments);
70
+ };
71
+ }
72
+
73
+ if (process.noDeprecation === true) {
74
+ return fn;
75
+ }
76
+
77
+ var warned = false;
78
+ function deprecated() {
79
+ if (!warned) {
80
+ if (process.throwDeprecation) {
81
+ throw new Error(msg);
82
+ } else if (process.traceDeprecation) {
83
+ console.trace(msg);
84
+ } else {
85
+ console.error(msg);
86
+ }
87
+ warned = true;
88
+ }
89
+ return fn.apply(this, arguments);
90
+ }
91
+
92
+ return deprecated;
93
+ };
94
+
95
+
96
+ var debugs = {};
97
+ var debugEnviron;
98
+ exports.debuglog = function(set) {
99
+ if (isUndefined(debugEnviron))
100
+ debugEnviron = process.env.NODE_DEBUG || '';
101
+ set = set.toUpperCase();
102
+ if (!debugs[set]) {
103
+ if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
104
+ var pid = process.pid;
105
+ debugs[set] = function() {
106
+ var msg = exports.format.apply(exports, arguments);
107
+ console.error('%s %d: %s', set, pid, msg);
108
+ };
109
+ } else {
110
+ debugs[set] = function() {};
111
+ }
112
+ }
113
+ return debugs[set];
114
+ };
115
+
116
+
117
+ /**
118
+ * Echos the value of a value. Trys to print the value out
119
+ * in the best way possible given the different types.
120
+ *
121
+ * @param {Object} obj The object to print out.
122
+ * @param {Object} opts Optional options object that alters the output.
123
+ */
124
+ /* legacy: obj, showHidden, depth, colors*/
125
+ function inspect(obj, opts) {
126
+ // default options
127
+ var ctx = {
128
+ seen: [],
129
+ stylize: stylizeNoColor
130
+ };
131
+ // legacy...
132
+ if (arguments.length >= 3) ctx.depth = arguments[2];
133
+ if (arguments.length >= 4) ctx.colors = arguments[3];
134
+ if (isBoolean(opts)) {
135
+ // legacy...
136
+ ctx.showHidden = opts;
137
+ } else if (opts) {
138
+ // got an "options" object
139
+ exports._extend(ctx, opts);
140
+ }
141
+ // set default options
142
+ if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
143
+ if (isUndefined(ctx.depth)) ctx.depth = 2;
144
+ if (isUndefined(ctx.colors)) ctx.colors = false;
145
+ if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
146
+ if (ctx.colors) ctx.stylize = stylizeWithColor;
147
+ return formatValue(ctx, obj, ctx.depth);
148
+ }
149
+ exports.inspect = inspect;
150
+
151
+
152
+ // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
153
+ inspect.colors = {
154
+ 'bold' : [1, 22],
155
+ 'italic' : [3, 23],
156
+ 'underline' : [4, 24],
157
+ 'inverse' : [7, 27],
158
+ 'white' : [37, 39],
159
+ 'grey' : [90, 39],
160
+ 'black' : [30, 39],
161
+ 'blue' : [34, 39],
162
+ 'cyan' : [36, 39],
163
+ 'green' : [32, 39],
164
+ 'magenta' : [35, 39],
165
+ 'red' : [31, 39],
166
+ 'yellow' : [33, 39]
167
+ };
168
+
169
+ // Don't use 'blue' not visible on cmd.exe
170
+ inspect.styles = {
171
+ 'special': 'cyan',
172
+ 'number': 'yellow',
173
+ 'boolean': 'yellow',
174
+ 'undefined': 'grey',
175
+ 'null': 'bold',
176
+ 'string': 'green',
177
+ 'date': 'magenta',
178
+ // "name": intentionally not styling
179
+ 'regexp': 'red'
180
+ };
181
+
182
+
183
+ function stylizeWithColor(str, styleType) {
184
+ var style = inspect.styles[styleType];
185
+
186
+ if (style) {
187
+ return '\u001b[' + inspect.colors[style][0] + 'm' + str +
188
+ '\u001b[' + inspect.colors[style][1] + 'm';
189
+ } else {
190
+ return str;
191
+ }
192
+ }
193
+
194
+
195
+ function stylizeNoColor(str, styleType) {
196
+ return str;
197
+ }
198
+
199
+
200
+ function arrayToHash(array) {
201
+ var hash = {};
202
+
203
+ array.forEach(function(val, idx) {
204
+ hash[val] = true;
205
+ });
206
+
207
+ return hash;
208
+ }
209
+
210
+
211
+ function formatValue(ctx, value, recurseTimes) {
212
+ // Provide a hook for user-specified inspect functions.
213
+ // Check that value is an object with an inspect function on it
214
+ if (ctx.customInspect &&
215
+ value &&
216
+ isFunction(value.inspect) &&
217
+ // Filter out the util module, it's inspect function is special
218
+ value.inspect !== exports.inspect &&
219
+ // Also filter out any prototype objects using the circular check.
220
+ !(value.constructor && value.constructor.prototype === value)) {
221
+ var ret = value.inspect(recurseTimes, ctx);
222
+ if (!isString(ret)) {
223
+ ret = formatValue(ctx, ret, recurseTimes);
224
+ }
225
+ return ret;
226
+ }
227
+
228
+ // Primitive types cannot have properties
229
+ var primitive = formatPrimitive(ctx, value);
230
+ if (primitive) {
231
+ return primitive;
232
+ }
233
+
234
+ // Look up the keys of the object.
235
+ var keys = Object.keys(value);
236
+ var visibleKeys = arrayToHash(keys);
237
+
238
+ if (ctx.showHidden) {
239
+ keys = Object.getOwnPropertyNames(value);
240
+ }
241
+
242
+ // This could be a boxed primitive (new String(), etc.), check valueOf()
243
+ // NOTE: Avoid calling `valueOf` on `Date` instance because it will return
244
+ // a number which, when object has some additional user-stored `keys`,
245
+ // will be printed out.
246
+ var formatted;
247
+ var raw = value;
248
+ try {
249
+ // the .valueOf() call can fail for a multitude of reasons
250
+ if (!isDate(value))
251
+ raw = value.valueOf();
252
+ } catch (e) {
253
+ // ignore...
254
+ }
255
+
256
+ if (isString(raw)) {
257
+ // for boxed Strings, we have to remove the 0-n indexed entries,
258
+ // since they just noisey up the output and are redundant
259
+ keys = keys.filter(function(key) {
260
+ return !(key >= 0 && key < raw.length);
261
+ });
262
+ }
263
+
264
+ // Some type of object without properties can be shortcutted.
265
+ if (keys.length === 0) {
266
+ if (isFunction(value)) {
267
+ var name = value.name ? ': ' + value.name : '';
268
+ return ctx.stylize('[Function' + name + ']', 'special');
269
+ }
270
+ if (isRegExp(value)) {
271
+ return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
272
+ }
273
+ if (isDate(value)) {
274
+ return ctx.stylize(Date.prototype.toString.call(value), 'date');
275
+ }
276
+ if (isError(value)) {
277
+ return formatError(value);
278
+ }
279
+ // now check the `raw` value to handle boxed primitives
280
+ if (isString(raw)) {
281
+ formatted = formatPrimitiveNoColor(ctx, raw);
282
+ return ctx.stylize('[String: ' + formatted + ']', 'string');
283
+ }
284
+ if (isNumber(raw)) {
285
+ formatted = formatPrimitiveNoColor(ctx, raw);
286
+ return ctx.stylize('[Number: ' + formatted + ']', 'number');
287
+ }
288
+ if (isBoolean(raw)) {
289
+ formatted = formatPrimitiveNoColor(ctx, raw);
290
+ return ctx.stylize('[Boolean: ' + formatted + ']', 'boolean');
291
+ }
292
+ }
293
+
294
+ var base = '', array = false, braces = ['{', '}'];
295
+
296
+ // Make Array say that they are Array
297
+ if (isArray(value)) {
298
+ array = true;
299
+ braces = ['[', ']'];
300
+ }
301
+
302
+ // Make functions say that they are functions
303
+ if (isFunction(value)) {
304
+ var n = value.name ? ': ' + value.name : '';
305
+ base = ' [Function' + n + ']';
306
+ }
307
+
308
+ // Make RegExps say that they are RegExps
309
+ if (isRegExp(value)) {
310
+ base = ' ' + RegExp.prototype.toString.call(value);
311
+ }
312
+
313
+ // Make dates with properties first say the date
314
+ if (isDate(value)) {
315
+ base = ' ' + Date.prototype.toUTCString.call(value);
316
+ }
317
+
318
+ // Make error with message first say the error
319
+ if (isError(value)) {
320
+ base = ' ' + formatError(value);
321
+ }
322
+
323
+ // Make boxed primitive Strings look like such
324
+ if (isString(raw)) {
325
+ formatted = formatPrimitiveNoColor(ctx, raw);
326
+ base = ' ' + '[String: ' + formatted + ']';
327
+ }
328
+
329
+ // Make boxed primitive Numbers look like such
330
+ if (isNumber(raw)) {
331
+ formatted = formatPrimitiveNoColor(ctx, raw);
332
+ base = ' ' + '[Number: ' + formatted + ']';
333
+ }
334
+
335
+ // Make boxed primitive Booleans look like such
336
+ if (isBoolean(raw)) {
337
+ formatted = formatPrimitiveNoColor(ctx, raw);
338
+ base = ' ' + '[Boolean: ' + formatted + ']';
339
+ }
340
+
341
+ if (keys.length === 0 && (!array || value.length === 0)) {
342
+ return braces[0] + base + braces[1];
343
+ }
344
+
345
+ if (recurseTimes < 0) {
346
+ if (isRegExp(value)) {
347
+ return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
348
+ } else {
349
+ return ctx.stylize('[Object]', 'special');
350
+ }
351
+ }
352
+
353
+ ctx.seen.push(value);
354
+
355
+ var output;
356
+ if (array) {
357
+ output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
358
+ } else {
359
+ output = keys.map(function(key) {
360
+ return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
361
+ });
362
+ }
363
+
364
+ ctx.seen.pop();
365
+
366
+ return reduceToSingleString(output, base, braces);
367
+ }
368
+
369
+
370
+ function formatPrimitive(ctx, value) {
371
+ if (isUndefined(value))
372
+ return ctx.stylize('undefined', 'undefined');
373
+ if (isString(value)) {
374
+ var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
375
+ .replace(/'/g, "\\'")
376
+ .replace(/\\"/g, '"') + '\'';
377
+ return ctx.stylize(simple, 'string');
378
+ }
379
+ if (isNumber(value)) {
380
+ // Format -0 as '-0'. Strict equality won't distinguish 0 from -0,
381
+ // so instead we use the fact that 1 / -0 < 0 whereas 1 / 0 > 0 .
382
+ if (value === 0 && 1 / value < 0)
383
+ return ctx.stylize('-0', 'number');
384
+ return ctx.stylize('' + value, 'number');
385
+ }
386
+ if (isBoolean(value))
387
+ return ctx.stylize('' + value, 'boolean');
388
+ // For some reason typeof null is "object", so special case here.
389
+ if (isNull(value))
390
+ return ctx.stylize('null', 'null');
391
+ }
392
+
393
+
394
+ function formatPrimitiveNoColor(ctx, value) {
395
+ var stylize = ctx.stylize;
396
+ ctx.stylize = stylizeNoColor;
397
+ var str = formatPrimitive(ctx, value);
398
+ ctx.stylize = stylize;
399
+ return str;
400
+ }
401
+
402
+
403
+ function formatError(value) {
404
+ return '[' + Error.prototype.toString.call(value) + ']';
405
+ }
406
+
407
+
408
+ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
409
+ var output = [];
410
+ for (var i = 0, l = value.length; i < l; ++i) {
411
+ if (hasOwnProperty(value, String(i))) {
412
+ output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
413
+ String(i), true));
414
+ } else {
415
+ output.push('');
416
+ }
417
+ }
418
+ keys.forEach(function(key) {
419
+ if (!key.match(/^\d+$/)) {
420
+ output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
421
+ key, true));
422
+ }
423
+ });
424
+ return output;
425
+ }
426
+
427
+
428
+ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
429
+ var name, str, desc;
430
+ desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
431
+ if (desc.get) {
432
+ if (desc.set) {
433
+ str = ctx.stylize('[Getter/Setter]', 'special');
434
+ } else {
435
+ str = ctx.stylize('[Getter]', 'special');
436
+ }
437
+ } else {
438
+ if (desc.set) {
439
+ str = ctx.stylize('[Setter]', 'special');
440
+ }
441
+ }
442
+ if (!hasOwnProperty(visibleKeys, key)) {
443
+ name = '[' + key + ']';
444
+ }
445
+ if (!str) {
446
+ if (ctx.seen.indexOf(desc.value) < 0) {
447
+ if (isNull(recurseTimes)) {
448
+ str = formatValue(ctx, desc.value, null);
449
+ } else {
450
+ str = formatValue(ctx, desc.value, recurseTimes - 1);
451
+ }
452
+ if (str.indexOf('\n') > -1) {
453
+ if (array) {
454
+ str = str.split('\n').map(function(line) {
455
+ return ' ' + line;
456
+ }).join('\n').substr(2);
457
+ } else {
458
+ str = '\n' + str.split('\n').map(function(line) {
459
+ return ' ' + line;
460
+ }).join('\n');
461
+ }
462
+ }
463
+ } else {
464
+ str = ctx.stylize('[Circular]', 'special');
465
+ }
466
+ }
467
+ if (isUndefined(name)) {
468
+ if (array && key.match(/^\d+$/)) {
469
+ return str;
470
+ }
471
+ name = JSON.stringify('' + key);
472
+ if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
473
+ name = name.substr(1, name.length - 2);
474
+ name = ctx.stylize(name, 'name');
475
+ } else {
476
+ name = name.replace(/'/g, "\\'")
477
+ .replace(/\\"/g, '"')
478
+ .replace(/(^"|"$)/g, "'")
479
+ .replace(/\\\\/g, '\\');
480
+ name = ctx.stylize(name, 'string');
481
+ }
482
+ }
483
+
484
+ return name + ': ' + str;
485
+ }
486
+
487
+
488
+ function reduceToSingleString(output, base, braces) {
489
+ var length = output.reduce(function(prev, cur) {
490
+ return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
491
+ }, 0);
492
+
493
+ if (length > 60) {
494
+ return braces[0] +
495
+ (base === '' ? '' : base + '\n ') +
496
+ ' ' +
497
+ output.join(',\n ') +
498
+ ' ' +
499
+ braces[1];
500
+ }
501
+
502
+ return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
503
+ }
504
+
505
+
506
+ // NOTE: These type checking functions intentionally don't use `instanceof`
507
+ // because it is fragile and can be easily faked with `Object.create()`.
508
+ var isArray = exports.isArray = Array.isArray;
509
+
510
+ function isBoolean(arg) {
511
+ return typeof arg === 'boolean';
512
+ }
513
+ exports.isBoolean = isBoolean;
514
+
515
+ function isNull(arg) {
516
+ return arg === null;
517
+ }
518
+ exports.isNull = isNull;
519
+
520
+ function isNullOrUndefined(arg) {
521
+ return arg == null;
522
+ }
523
+ exports.isNullOrUndefined = isNullOrUndefined;
524
+
525
+ function isNumber(arg) {
526
+ return typeof arg === 'number';
527
+ }
528
+ exports.isNumber = isNumber;
529
+
530
+ function isString(arg) {
531
+ return typeof arg === 'string';
532
+ }
533
+ exports.isString = isString;
534
+
535
+ function isSymbol(arg) {
536
+ return typeof arg === 'symbol';
537
+ }
538
+ exports.isSymbol = isSymbol;
539
+
540
+ function isUndefined(arg) {
541
+ return arg === void 0;
542
+ }
543
+ exports.isUndefined = isUndefined;
544
+
545
+ function isRegExp(re) {
546
+ return isObject(re) && objectToString(re) === '[object RegExp]';
547
+ }
548
+ exports.isRegExp = isRegExp;
549
+
550
+ function isObject(arg) {
551
+ return typeof arg === 'object' && arg !== null;
552
+ }
553
+ exports.isObject = isObject;
554
+
555
+ function isDate(d) {
556
+ return isObject(d) && objectToString(d) === '[object Date]';
557
+ }
558
+ exports.isDate = isDate;
559
+
560
+ function isError(e) {
561
+ return isObject(e) &&
562
+ (objectToString(e) === '[object Error]' || e instanceof Error);
563
+ }
564
+ exports.isError = isError;
565
+
566
+ function isFunction(arg) {
567
+ return typeof arg === 'function';
568
+ }
569
+ exports.isFunction = isFunction;
570
+
571
+ function isPrimitive(arg) {
572
+ return arg === null ||
573
+ typeof arg === 'boolean' ||
574
+ typeof arg === 'number' ||
575
+ typeof arg === 'string' ||
576
+ typeof arg === 'symbol' || // ES6 symbol
577
+ typeof arg === 'undefined';
578
+ }
579
+ exports.isPrimitive = isPrimitive;
580
+
581
+ function isBuffer(arg) {
582
+ return arg instanceof Buffer;
583
+ }
584
+ exports.isBuffer = isBuffer;
585
+
586
+ function objectToString(o) {
587
+ return Object.prototype.toString.call(o);
588
+ }
589
+
590
+
591
+ function pad(n) {
592
+ return n < 10 ? '0' + n.toString(10) : n.toString(10);
593
+ }
594
+
595
+
596
+ var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
597
+ 'Oct', 'Nov', 'Dec'];
598
+
599
+ // 26 Feb 16:19:34
600
+ function timestamp() {
601
+ var d = new Date();
602
+ var time = [pad(d.getHours()),
603
+ pad(d.getMinutes()),
604
+ pad(d.getSeconds())].join(':');
605
+ return [d.getDate(), months[d.getMonth()], time].join(' ');
606
+ }
607
+
608
+
609
+ // log is just a thin wrapper to console.log that prepends a timestamp
610
+ exports.log = function() {
611
+ console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
612
+ };
613
+
614
+
615
+ /**
616
+ * Inherit the prototype methods from one constructor into another.
617
+ *
618
+ * The Function.prototype.inherits from lang.js rewritten as a standalone
619
+ * function (not on Function.prototype). NOTE: If this file is to be loaded
620
+ * during bootstrapping this function needs to be rewritten using some native
621
+ * functions as prototype setup using normal JavaScript does not work as
622
+ * expected during bootstrapping (see mirror.js in r114903).
623
+ *
624
+ * @param {function} ctor Constructor function which needs to inherit the
625
+ * prototype.
626
+ * @param {function} superCtor Constructor function to inherit prototype from.
627
+ */
628
+ exports.inherits = function(ctor, superCtor) {
629
+ ctor.super_ = superCtor;
630
+ ctor.prototype = Object.create(superCtor.prototype, {
631
+ constructor: {
632
+ value: ctor,
633
+ enumerable: false,
634
+ writable: true,
635
+ configurable: true
636
+ }
637
+ });
638
+ };
639
+
640
+ exports._extend = function(origin, add) {
641
+ // Don't do anything if add isn't an object
642
+ if (!add || !isObject(add)) return origin;
643
+
644
+ var keys = Object.keys(add);
645
+ var i = keys.length;
646
+ while (i--) {
647
+ origin[keys[i]] = add[keys[i]];
648
+ }
649
+ return origin;
650
+ };
651
+
652
+ function hasOwnProperty(obj, prop) {
653
+ return Object.prototype.hasOwnProperty.call(obj, prop);
654
+ }