UNPKG

41 kBJavaScriptView Raw
1(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.bla = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2exports.endianness = function () { return 'LE' };
3
4exports.hostname = function () {
5 if (typeof location !== 'undefined') {
6 return location.hostname
7 }
8 else return '';
9};
10
11exports.loadavg = function () { return [] };
12
13exports.uptime = function () { return 0 };
14
15exports.freemem = function () {
16 return Number.MAX_VALUE;
17};
18
19exports.totalmem = function () {
20 return Number.MAX_VALUE;
21};
22
23exports.cpus = function () { return [] };
24
25exports.type = function () { return 'Browser' };
26
27exports.release = function () {
28 if (typeof navigator !== 'undefined') {
29 return navigator.appVersion;
30 }
31 return '';
32};
33
34exports.networkInterfaces
35= exports.getNetworkInterfaces
36= function () { return {} };
37
38exports.arch = function () { return 'javascript' };
39
40exports.platform = function () { return 'browser' };
41
42exports.tmpdir = exports.tmpDir = function () {
43 return '/tmp';
44};
45
46exports.EOL = '\n';
47
48exports.homedir = function () {
49 return '/'
50};
51
52},{}],2:[function(require,module,exports){
53// shim for using process in browser
54var process = module.exports = {};
55
56// cached from whatever global is present so that test runners that stub it
57// don't break things. But we need to wrap it in a try catch in case it is
58// wrapped in strict mode code which doesn't define any globals. It's inside a
59// function because try/catches deoptimize in certain engines.
60
61var cachedSetTimeout;
62var cachedClearTimeout;
63
64function defaultSetTimout() {
65 throw new Error('setTimeout has not been defined');
66}
67function defaultClearTimeout () {
68 throw new Error('clearTimeout has not been defined');
69}
70(function () {
71 try {
72 if (typeof setTimeout === 'function') {
73 cachedSetTimeout = setTimeout;
74 } else {
75 cachedSetTimeout = defaultSetTimout;
76 }
77 } catch (e) {
78 cachedSetTimeout = defaultSetTimout;
79 }
80 try {
81 if (typeof clearTimeout === 'function') {
82 cachedClearTimeout = clearTimeout;
83 } else {
84 cachedClearTimeout = defaultClearTimeout;
85 }
86 } catch (e) {
87 cachedClearTimeout = defaultClearTimeout;
88 }
89} ())
90function runTimeout(fun) {
91 if (cachedSetTimeout === setTimeout) {
92 //normal enviroments in sane situations
93 return setTimeout(fun, 0);
94 }
95 // if setTimeout wasn't available but was latter defined
96 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
97 cachedSetTimeout = setTimeout;
98 return setTimeout(fun, 0);
99 }
100 try {
101 // when when somebody has screwed with setTimeout but no I.E. maddness
102 return cachedSetTimeout(fun, 0);
103 } catch(e){
104 try {
105 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
106 return cachedSetTimeout.call(null, fun, 0);
107 } catch(e){
108 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
109 return cachedSetTimeout.call(this, fun, 0);
110 }
111 }
112
113
114}
115function runClearTimeout(marker) {
116 if (cachedClearTimeout === clearTimeout) {
117 //normal enviroments in sane situations
118 return clearTimeout(marker);
119 }
120 // if clearTimeout wasn't available but was latter defined
121 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
122 cachedClearTimeout = clearTimeout;
123 return clearTimeout(marker);
124 }
125 try {
126 // when when somebody has screwed with setTimeout but no I.E. maddness
127 return cachedClearTimeout(marker);
128 } catch (e){
129 try {
130 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
131 return cachedClearTimeout.call(null, marker);
132 } catch (e){
133 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
134 // Some versions of I.E. have different rules for clearTimeout vs setTimeout
135 return cachedClearTimeout.call(this, marker);
136 }
137 }
138
139
140
141}
142var queue = [];
143var draining = false;
144var currentQueue;
145var queueIndex = -1;
146
147function cleanUpNextTick() {
148 if (!draining || !currentQueue) {
149 return;
150 }
151 draining = false;
152 if (currentQueue.length) {
153 queue = currentQueue.concat(queue);
154 } else {
155 queueIndex = -1;
156 }
157 if (queue.length) {
158 drainQueue();
159 }
160}
161
162function drainQueue() {
163 if (draining) {
164 return;
165 }
166 var timeout = runTimeout(cleanUpNextTick);
167 draining = true;
168
169 var len = queue.length;
170 while(len) {
171 currentQueue = queue;
172 queue = [];
173 while (++queueIndex < len) {
174 if (currentQueue) {
175 currentQueue[queueIndex].run();
176 }
177 }
178 queueIndex = -1;
179 len = queue.length;
180 }
181 currentQueue = null;
182 draining = false;
183 runClearTimeout(timeout);
184}
185
186process.nextTick = function (fun) {
187 var args = new Array(arguments.length - 1);
188 if (arguments.length > 1) {
189 for (var i = 1; i < arguments.length; i++) {
190 args[i - 1] = arguments[i];
191 }
192 }
193 queue.push(new Item(fun, args));
194 if (queue.length === 1 && !draining) {
195 runTimeout(drainQueue);
196 }
197};
198
199// v8 likes predictible objects
200function Item(fun, array) {
201 this.fun = fun;
202 this.array = array;
203}
204Item.prototype.run = function () {
205 this.fun.apply(null, this.array);
206};
207process.title = 'browser';
208process.browser = true;
209process.env = {};
210process.argv = [];
211process.version = ''; // empty string to avoid regexp issues
212process.versions = {};
213
214function noop() {}
215
216process.on = noop;
217process.addListener = noop;
218process.once = noop;
219process.off = noop;
220process.removeListener = noop;
221process.removeAllListeners = noop;
222process.emit = noop;
223process.prependListener = noop;
224process.prependOnceListener = noop;
225
226process.listeners = function (name) { return [] }
227
228process.binding = function (name) {
229 throw new Error('process.binding is not supported');
230};
231
232process.cwd = function () { return '/' };
233process.chdir = function (dir) {
234 throw new Error('process.chdir is not supported');
235};
236process.umask = function() { return 0; };
237
238},{}],3:[function(require,module,exports){
239if (typeof Object.create === 'function') {
240 // implementation from standard node.js 'util' module
241 module.exports = function inherits(ctor, superCtor) {
242 ctor.super_ = superCtor
243 ctor.prototype = Object.create(superCtor.prototype, {
244 constructor: {
245 value: ctor,
246 enumerable: false,
247 writable: true,
248 configurable: true
249 }
250 });
251 };
252} else {
253 // old school shim for old browsers
254 module.exports = function inherits(ctor, superCtor) {
255 ctor.super_ = superCtor
256 var TempCtor = function () {}
257 TempCtor.prototype = superCtor.prototype
258 ctor.prototype = new TempCtor()
259 ctor.prototype.constructor = ctor
260 }
261}
262
263},{}],4:[function(require,module,exports){
264module.exports = function isBuffer(arg) {
265 return arg && typeof arg === 'object'
266 && typeof arg.copy === 'function'
267 && typeof arg.fill === 'function'
268 && typeof arg.readUInt8 === 'function';
269}
270},{}],5:[function(require,module,exports){
271(function (process,global){
272// Copyright Joyent, Inc. and other Node contributors.
273//
274// Permission is hereby granted, free of charge, to any person obtaining a
275// copy of this software and associated documentation files (the
276// "Software"), to deal in the Software without restriction, including
277// without limitation the rights to use, copy, modify, merge, publish,
278// distribute, sublicense, and/or sell copies of the Software, and to permit
279// persons to whom the Software is furnished to do so, subject to the
280// following conditions:
281//
282// The above copyright notice and this permission notice shall be included
283// in all copies or substantial portions of the Software.
284//
285// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
286// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
287// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
288// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
289// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
290// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
291// USE OR OTHER DEALINGS IN THE SOFTWARE.
292
293var formatRegExp = /%[sdj%]/g;
294exports.format = function(f) {
295 if (!isString(f)) {
296 var objects = [];
297 for (var i = 0; i < arguments.length; i++) {
298 objects.push(inspect(arguments[i]));
299 }
300 return objects.join(' ');
301 }
302
303 var i = 1;
304 var args = arguments;
305 var len = args.length;
306 var str = String(f).replace(formatRegExp, function(x) {
307 if (x === '%%') return '%';
308 if (i >= len) return x;
309 switch (x) {
310 case '%s': return String(args[i++]);
311 case '%d': return Number(args[i++]);
312 case '%j':
313 try {
314 return JSON.stringify(args[i++]);
315 } catch (_) {
316 return '[Circular]';
317 }
318 default:
319 return x;
320 }
321 });
322 for (var x = args[i]; i < len; x = args[++i]) {
323 if (isNull(x) || !isObject(x)) {
324 str += ' ' + x;
325 } else {
326 str += ' ' + inspect(x);
327 }
328 }
329 return str;
330};
331
332
333// Mark that a method should not be used.
334// Returns a modified function which warns once by default.
335// If --no-deprecation is set, then it is a no-op.
336exports.deprecate = function(fn, msg) {
337 // Allow for deprecating things in the process of starting up.
338 if (isUndefined(global.process)) {
339 return function() {
340 return exports.deprecate(fn, msg).apply(this, arguments);
341 };
342 }
343
344 if (process.noDeprecation === true) {
345 return fn;
346 }
347
348 var warned = false;
349 function deprecated() {
350 if (!warned) {
351 if (process.throwDeprecation) {
352 throw new Error(msg);
353 } else if (process.traceDeprecation) {
354 console.trace(msg);
355 } else {
356 console.error(msg);
357 }
358 warned = true;
359 }
360 return fn.apply(this, arguments);
361 }
362
363 return deprecated;
364};
365
366
367var debugs = {};
368var debugEnviron;
369exports.debuglog = function(set) {
370 if (isUndefined(debugEnviron))
371 debugEnviron = process.env.NODE_DEBUG || '';
372 set = set.toUpperCase();
373 if (!debugs[set]) {
374 if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
375 var pid = process.pid;
376 debugs[set] = function() {
377 var msg = exports.format.apply(exports, arguments);
378 console.error('%s %d: %s', set, pid, msg);
379 };
380 } else {
381 debugs[set] = function() {};
382 }
383 }
384 return debugs[set];
385};
386
387
388/**
389 * Echos the value of a value. Trys to print the value out
390 * in the best way possible given the different types.
391 *
392 * @param {Object} obj The object to print out.
393 * @param {Object} opts Optional options object that alters the output.
394 */
395/* legacy: obj, showHidden, depth, colors*/
396function inspect(obj, opts) {
397 // default options
398 var ctx = {
399 seen: [],
400 stylize: stylizeNoColor
401 };
402 // legacy...
403 if (arguments.length >= 3) ctx.depth = arguments[2];
404 if (arguments.length >= 4) ctx.colors = arguments[3];
405 if (isBoolean(opts)) {
406 // legacy...
407 ctx.showHidden = opts;
408 } else if (opts) {
409 // got an "options" object
410 exports._extend(ctx, opts);
411 }
412 // set default options
413 if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
414 if (isUndefined(ctx.depth)) ctx.depth = 2;
415 if (isUndefined(ctx.colors)) ctx.colors = false;
416 if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
417 if (ctx.colors) ctx.stylize = stylizeWithColor;
418 return formatValue(ctx, obj, ctx.depth);
419}
420exports.inspect = inspect;
421
422
423// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
424inspect.colors = {
425 'bold' : [1, 22],
426 'italic' : [3, 23],
427 'underline' : [4, 24],
428 'inverse' : [7, 27],
429 'white' : [37, 39],
430 'grey' : [90, 39],
431 'black' : [30, 39],
432 'blue' : [34, 39],
433 'cyan' : [36, 39],
434 'green' : [32, 39],
435 'magenta' : [35, 39],
436 'red' : [31, 39],
437 'yellow' : [33, 39]
438};
439
440// Don't use 'blue' not visible on cmd.exe
441inspect.styles = {
442 'special': 'cyan',
443 'number': 'yellow',
444 'boolean': 'yellow',
445 'undefined': 'grey',
446 'null': 'bold',
447 'string': 'green',
448 'date': 'magenta',
449 // "name": intentionally not styling
450 'regexp': 'red'
451};
452
453
454function stylizeWithColor(str, styleType) {
455 var style = inspect.styles[styleType];
456
457 if (style) {
458 return '\u001b[' + inspect.colors[style][0] + 'm' + str +
459 '\u001b[' + inspect.colors[style][1] + 'm';
460 } else {
461 return str;
462 }
463}
464
465
466function stylizeNoColor(str, styleType) {
467 return str;
468}
469
470
471function arrayToHash(array) {
472 var hash = {};
473
474 array.forEach(function(val, idx) {
475 hash[val] = true;
476 });
477
478 return hash;
479}
480
481
482function formatValue(ctx, value, recurseTimes) {
483 // Provide a hook for user-specified inspect functions.
484 // Check that value is an object with an inspect function on it
485 if (ctx.customInspect &&
486 value &&
487 isFunction(value.inspect) &&
488 // Filter out the util module, it's inspect function is special
489 value.inspect !== exports.inspect &&
490 // Also filter out any prototype objects using the circular check.
491 !(value.constructor && value.constructor.prototype === value)) {
492 var ret = value.inspect(recurseTimes, ctx);
493 if (!isString(ret)) {
494 ret = formatValue(ctx, ret, recurseTimes);
495 }
496 return ret;
497 }
498
499 // Primitive types cannot have properties
500 var primitive = formatPrimitive(ctx, value);
501 if (primitive) {
502 return primitive;
503 }
504
505 // Look up the keys of the object.
506 var keys = Object.keys(value);
507 var visibleKeys = arrayToHash(keys);
508
509 if (ctx.showHidden) {
510 keys = Object.getOwnPropertyNames(value);
511 }
512
513 // IE doesn't make error fields non-enumerable
514 // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
515 if (isError(value)
516 && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
517 return formatError(value);
518 }
519
520 // Some type of object without properties can be shortcutted.
521 if (keys.length === 0) {
522 if (isFunction(value)) {
523 var name = value.name ? ': ' + value.name : '';
524 return ctx.stylize('[Function' + name + ']', 'special');
525 }
526 if (isRegExp(value)) {
527 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
528 }
529 if (isDate(value)) {
530 return ctx.stylize(Date.prototype.toString.call(value), 'date');
531 }
532 if (isError(value)) {
533 return formatError(value);
534 }
535 }
536
537 var base = '', array = false, braces = ['{', '}'];
538
539 // Make Array say that they are Array
540 if (isArray(value)) {
541 array = true;
542 braces = ['[', ']'];
543 }
544
545 // Make functions say that they are functions
546 if (isFunction(value)) {
547 var n = value.name ? ': ' + value.name : '';
548 base = ' [Function' + n + ']';
549 }
550
551 // Make RegExps say that they are RegExps
552 if (isRegExp(value)) {
553 base = ' ' + RegExp.prototype.toString.call(value);
554 }
555
556 // Make dates with properties first say the date
557 if (isDate(value)) {
558 base = ' ' + Date.prototype.toUTCString.call(value);
559 }
560
561 // Make error with message first say the error
562 if (isError(value)) {
563 base = ' ' + formatError(value);
564 }
565
566 if (keys.length === 0 && (!array || value.length == 0)) {
567 return braces[0] + base + braces[1];
568 }
569
570 if (recurseTimes < 0) {
571 if (isRegExp(value)) {
572 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
573 } else {
574 return ctx.stylize('[Object]', 'special');
575 }
576 }
577
578 ctx.seen.push(value);
579
580 var output;
581 if (array) {
582 output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
583 } else {
584 output = keys.map(function(key) {
585 return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
586 });
587 }
588
589 ctx.seen.pop();
590
591 return reduceToSingleString(output, base, braces);
592}
593
594
595function formatPrimitive(ctx, value) {
596 if (isUndefined(value))
597 return ctx.stylize('undefined', 'undefined');
598 if (isString(value)) {
599 var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
600 .replace(/'/g, "\\'")
601 .replace(/\\"/g, '"') + '\'';
602 return ctx.stylize(simple, 'string');
603 }
604 if (isNumber(value))
605 return ctx.stylize('' + value, 'number');
606 if (isBoolean(value))
607 return ctx.stylize('' + value, 'boolean');
608 // For some reason typeof null is "object", so special case here.
609 if (isNull(value))
610 return ctx.stylize('null', 'null');
611}
612
613
614function formatError(value) {
615 return '[' + Error.prototype.toString.call(value) + ']';
616}
617
618
619function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
620 var output = [];
621 for (var i = 0, l = value.length; i < l; ++i) {
622 if (hasOwnProperty(value, String(i))) {
623 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
624 String(i), true));
625 } else {
626 output.push('');
627 }
628 }
629 keys.forEach(function(key) {
630 if (!key.match(/^\d+$/)) {
631 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
632 key, true));
633 }
634 });
635 return output;
636}
637
638
639function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
640 var name, str, desc;
641 desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
642 if (desc.get) {
643 if (desc.set) {
644 str = ctx.stylize('[Getter/Setter]', 'special');
645 } else {
646 str = ctx.stylize('[Getter]', 'special');
647 }
648 } else {
649 if (desc.set) {
650 str = ctx.stylize('[Setter]', 'special');
651 }
652 }
653 if (!hasOwnProperty(visibleKeys, key)) {
654 name = '[' + key + ']';
655 }
656 if (!str) {
657 if (ctx.seen.indexOf(desc.value) < 0) {
658 if (isNull(recurseTimes)) {
659 str = formatValue(ctx, desc.value, null);
660 } else {
661 str = formatValue(ctx, desc.value, recurseTimes - 1);
662 }
663 if (str.indexOf('\n') > -1) {
664 if (array) {
665 str = str.split('\n').map(function(line) {
666 return ' ' + line;
667 }).join('\n').substr(2);
668 } else {
669 str = '\n' + str.split('\n').map(function(line) {
670 return ' ' + line;
671 }).join('\n');
672 }
673 }
674 } else {
675 str = ctx.stylize('[Circular]', 'special');
676 }
677 }
678 if (isUndefined(name)) {
679 if (array && key.match(/^\d+$/)) {
680 return str;
681 }
682 name = JSON.stringify('' + key);
683 if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
684 name = name.substr(1, name.length - 2);
685 name = ctx.stylize(name, 'name');
686 } else {
687 name = name.replace(/'/g, "\\'")
688 .replace(/\\"/g, '"')
689 .replace(/(^"|"$)/g, "'");
690 name = ctx.stylize(name, 'string');
691 }
692 }
693
694 return name + ': ' + str;
695}
696
697
698function reduceToSingleString(output, base, braces) {
699 var numLinesEst = 0;
700 var length = output.reduce(function(prev, cur) {
701 numLinesEst++;
702 if (cur.indexOf('\n') >= 0) numLinesEst++;
703 return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
704 }, 0);
705
706 if (length > 60) {
707 return braces[0] +
708 (base === '' ? '' : base + '\n ') +
709 ' ' +
710 output.join(',\n ') +
711 ' ' +
712 braces[1];
713 }
714
715 return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
716}
717
718
719// NOTE: These type checking functions intentionally don't use `instanceof`
720// because it is fragile and can be easily faked with `Object.create()`.
721function isArray(ar) {
722 return Array.isArray(ar);
723}
724exports.isArray = isArray;
725
726function isBoolean(arg) {
727 return typeof arg === 'boolean';
728}
729exports.isBoolean = isBoolean;
730
731function isNull(arg) {
732 return arg === null;
733}
734exports.isNull = isNull;
735
736function isNullOrUndefined(arg) {
737 return arg == null;
738}
739exports.isNullOrUndefined = isNullOrUndefined;
740
741function isNumber(arg) {
742 return typeof arg === 'number';
743}
744exports.isNumber = isNumber;
745
746function isString(arg) {
747 return typeof arg === 'string';
748}
749exports.isString = isString;
750
751function isSymbol(arg) {
752 return typeof arg === 'symbol';
753}
754exports.isSymbol = isSymbol;
755
756function isUndefined(arg) {
757 return arg === void 0;
758}
759exports.isUndefined = isUndefined;
760
761function isRegExp(re) {
762 return isObject(re) && objectToString(re) === '[object RegExp]';
763}
764exports.isRegExp = isRegExp;
765
766function isObject(arg) {
767 return typeof arg === 'object' && arg !== null;
768}
769exports.isObject = isObject;
770
771function isDate(d) {
772 return isObject(d) && objectToString(d) === '[object Date]';
773}
774exports.isDate = isDate;
775
776function isError(e) {
777 return isObject(e) &&
778 (objectToString(e) === '[object Error]' || e instanceof Error);
779}
780exports.isError = isError;
781
782function isFunction(arg) {
783 return typeof arg === 'function';
784}
785exports.isFunction = isFunction;
786
787function isPrimitive(arg) {
788 return arg === null ||
789 typeof arg === 'boolean' ||
790 typeof arg === 'number' ||
791 typeof arg === 'string' ||
792 typeof arg === 'symbol' || // ES6 symbol
793 typeof arg === 'undefined';
794}
795exports.isPrimitive = isPrimitive;
796
797exports.isBuffer = require('./support/isBuffer');
798
799function objectToString(o) {
800 return Object.prototype.toString.call(o);
801}
802
803
804function pad(n) {
805 return n < 10 ? '0' + n.toString(10) : n.toString(10);
806}
807
808
809var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
810 'Oct', 'Nov', 'Dec'];
811
812// 26 Feb 16:19:34
813function timestamp() {
814 var d = new Date();
815 var time = [pad(d.getHours()),
816 pad(d.getMinutes()),
817 pad(d.getSeconds())].join(':');
818 return [d.getDate(), months[d.getMonth()], time].join(' ');
819}
820
821
822// log is just a thin wrapper to console.log that prepends a timestamp
823exports.log = function() {
824 console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
825};
826
827
828/**
829 * Inherit the prototype methods from one constructor into another.
830 *
831 * The Function.prototype.inherits from lang.js rewritten as a standalone
832 * function (not on Function.prototype). NOTE: If this file is to be loaded
833 * during bootstrapping this function needs to be rewritten using some native
834 * functions as prototype setup using normal JavaScript does not work as
835 * expected during bootstrapping (see mirror.js in r114903).
836 *
837 * @param {function} ctor Constructor function which needs to inherit the
838 * prototype.
839 * @param {function} superCtor Constructor function to inherit prototype from.
840 */
841exports.inherits = require('inherits');
842
843exports._extend = function(origin, add) {
844 // Don't do anything if add isn't an object
845 if (!add || !isObject(add)) return origin;
846
847 var keys = Object.keys(add);
848 var i = keys.length;
849 while (i--) {
850 origin[keys[i]] = add[keys[i]];
851 }
852 return origin;
853};
854
855function hasOwnProperty(obj, prop) {
856 return Object.prototype.hasOwnProperty.call(obj, prop);
857}
858
859}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
860},{"./support/isBuffer":4,"_process":2,"inherits":3}],6:[function(require,module,exports){
861"use strict";
862Object.defineProperty(exports, "__esModule", { value: true });
863var main_1 = require("./main");
864Object.defineProperty(exports, "ConnectionString", { enumerable: true, get: function () { return main_1.ConnectionString; } });
865var types_1 = require("./types");
866Object.defineProperty(exports, "HostType", { enumerable: true, get: function () { return types_1.HostType; } });
867
868},{"./main":7,"./types":9}],7:[function(require,module,exports){
869(function (process){
870"use strict";
871Object.defineProperty(exports, "__esModule", { value: true });
872exports.ConnectionString = void 0;
873var util_1 = require("util");
874var os_1 = require("os");
875var types_1 = require("./types");
876var static_1 = require("./static");
877var errInvalidDefaults = "Invalid \"defaults\" parameter: ";
878var ConnectionString = /** @class */ (function () {
879 /**
880 * Constructor.
881 *
882 * @param cs - connection string (can be empty).
883 *
884 * @param defaults - optional defaults, which can also be set
885 * explicitly, via method setDefaults.
886 */
887 function ConnectionString(cs, defaults) {
888 var _this = this;
889 if (!(this instanceof ConnectionString)) {
890 throw new TypeError("Class constructor ConnectionString cannot be invoked without 'new'");
891 }
892 if (typeof cs !== 'string') {
893 throw new TypeError("Invalid connection string: " + JSON.stringify(cs));
894 }
895 if (typeof (defaults !== null && defaults !== void 0 ? defaults : {}) !== 'object') {
896 throw new TypeError(errInvalidDefaults + JSON.stringify(defaults));
897 }
898 cs = cs.trim();
899 static_1.validateUrl(cs); // will throw, if failed
900 // Extracting the protocol:
901 var m = cs.match(/^[\w-_.+!*'()$%:]*:\/\//);
902 if (m) {
903 var protocol = m[0].replace(/:\/\//, '');
904 if (protocol) {
905 this.protocol = static_1.decode(protocol);
906 }
907 cs = cs.substr(m[0].length);
908 }
909 // Extracting user + password:
910 m = cs.match(/^([\w-_.+!*'()$%]*):?([\w-_.+!*'()$%]*)@/);
911 if (m) {
912 if (m[1]) {
913 this.user = static_1.decode(m[1]);
914 }
915 if (m[2]) {
916 this.password = static_1.decode(m[2]);
917 }
918 cs = cs.substr(m[0].length);
919 }
920 // Extracting hosts details:
921 // (if it starts with `/`, it is the first path segment, i.e. no hosts specified)
922 if (cs[0] !== '/') {
923 var endOfHosts = cs.search(/[\/?]/);
924 var hosts = (endOfHosts === -1 ? cs : cs.substr(0, endOfHosts)).split(',');
925 hosts.forEach(function (h) {
926 var host = static_1.parseHost(h);
927 if (host) {
928 if (!_this.hosts) {
929 _this.hosts = [];
930 }
931 _this.hosts.push(host);
932 }
933 });
934 if (endOfHosts >= 0) {
935 cs = cs.substr(endOfHosts);
936 }
937 }
938 // Extracting the path:
939 m = cs.match(/\/([\w-_.+!*'()$%]+)/g);
940 if (m) {
941 this.path = m.map(function (s) { return static_1.decode(s.substr(1)); });
942 }
943 // Extracting parameters:
944 var idx = cs.indexOf('?');
945 if (idx !== -1) {
946 cs = cs.substr(idx + 1);
947 m = cs.match(/([\w-_.+!*'()$%]+)=([\w-_.+!*'()$%]+)/g);
948 if (m) {
949 var params_1 = {};
950 m.forEach(function (s) {
951 var a = s.split('=');
952 var prop = static_1.decode(a[0]);
953 if (prop in params_1) {
954 throw new Error("Parameter \"" + prop + "\" repeated.");
955 }
956 params_1[prop] = static_1.decode(a[1]);
957 });
958 this.params = params_1;
959 }
960 }
961 if (defaults) {
962 this.setDefaults(defaults);
963 }
964 }
965 Object.defineProperty(ConnectionString.prototype, "hostname", {
966 /**
967 * Safe read-accessor to the first host's name.
968 */
969 get: function () {
970 var _a;
971 return (_a = this.hosts) === null || _a === void 0 ? void 0 : _a[0].name;
972 },
973 enumerable: false,
974 configurable: true
975 });
976 Object.defineProperty(ConnectionString.prototype, "port", {
977 /**
978 * Safe read-accessor to the first host's port.
979 */
980 get: function () {
981 var _a;
982 return (_a = this.hosts) === null || _a === void 0 ? void 0 : _a[0].port;
983 },
984 enumerable: false,
985 configurable: true
986 });
987 Object.defineProperty(ConnectionString.prototype, "type", {
988 /**
989 * Safe read-accessor to the first host's type.
990 */
991 get: function () {
992 var _a;
993 return (_a = this.hosts) === null || _a === void 0 ? void 0 : _a[0].type;
994 },
995 enumerable: false,
996 configurable: true
997 });
998 /**
999 * Parses a host name into an object, which then can be passed into `setDefaults`.
1000 *
1001 * It returns `null` only when no valid host recognized.
1002 */
1003 ConnectionString.parseHost = function (host) {
1004 return static_1.parseHost(host, true);
1005 };
1006 /**
1007 * Converts this object into a valid connection string.
1008 */
1009 ConnectionString.prototype.toString = function (options) {
1010 var s = '';
1011 var opts = options || {};
1012 if (this.protocol) {
1013 s += static_1.encode(this.protocol, opts).replace(/%3A/g, ':') + '://';
1014 }
1015 if (this.user || this.password) {
1016 if (this.user) {
1017 s += static_1.encode(this.user, opts);
1018 }
1019 if (this.password) {
1020 s += ':';
1021 var h = opts.passwordHash;
1022 if (h) {
1023 var code = (typeof h === 'string' && h[0]) || '#';
1024 s += code.repeat(this.password.length);
1025 }
1026 else {
1027 s += static_1.encode(this.password, opts);
1028 }
1029 }
1030 s += '@';
1031 }
1032 if (Array.isArray(this.hosts)) {
1033 s += this.hosts.map(function (h) { return static_1.fullHostName(h, options); }).join();
1034 }
1035 if (Array.isArray(this.path)) {
1036 this.path.forEach(function (seg) {
1037 s += '/' + static_1.encode(seg, opts);
1038 });
1039 }
1040 if (this.params && typeof this.params === 'object') {
1041 var params = [];
1042 for (var a in this.params) {
1043 var value = this.params[a];
1044 if (typeof value !== 'string') {
1045 value = JSON.stringify(value);
1046 }
1047 value = static_1.encode(value, opts);
1048 if (opts.plusForSpace) {
1049 value = value.replace(/%20/g, '+');
1050 }
1051 params.push(static_1.encode(a, opts) + "=" + value);
1052 }
1053 if (params.length) {
1054 s += "?" + params.join('&');
1055 }
1056 }
1057 return s;
1058 };
1059 /**
1060 * Applies default parameters, and returns itself.
1061 */
1062 ConnectionString.prototype.setDefaults = function (defaults) {
1063 if (!defaults || typeof defaults !== 'object') {
1064 throw new TypeError(errInvalidDefaults + JSON.stringify(defaults));
1065 }
1066 if (!('protocol' in this) && static_1.hasText(defaults.protocol)) {
1067 this.protocol = defaults.protocol.trim();
1068 }
1069 // Missing default `hosts` are merged with the existing ones:
1070 if (Array.isArray(defaults.hosts)) {
1071 var hosts_1 = Array.isArray(this.hosts) ? this.hosts : [];
1072 var dhHosts = defaults.hosts.filter(function (d) { return d && typeof d === 'object'; });
1073 dhHosts.forEach(function (dh) {
1074 var dhName = static_1.hasText(dh.name) ? dh.name.trim() : undefined;
1075 var h = { name: dhName, port: dh.port, type: dh.type };
1076 var found = false;
1077 for (var i = 0; i < hosts_1.length; i++) {
1078 var thisHost = static_1.fullHostName(hosts_1[i]), defHost = static_1.fullHostName(h);
1079 if (thisHost.toLowerCase() === defHost.toLowerCase()) {
1080 found = true;
1081 break;
1082 }
1083 }
1084 if (!found) {
1085 var obj_1 = {};
1086 if (h.name) {
1087 if (h.type && h.type in types_1.HostType) {
1088 obj_1.name = h.name;
1089 obj_1.type = h.type;
1090 }
1091 else {
1092 var t = static_1.parseHost(h.name, true);
1093 if (t) {
1094 obj_1.name = t.name;
1095 obj_1.type = t.type;
1096 }
1097 }
1098 }
1099 var p = h.port;
1100 if (typeof p === 'number' && p > 0 && p < 65536) {
1101 obj_1.port = p;
1102 }
1103 if (obj_1.name || obj_1.port) {
1104 Object.defineProperty(obj_1, 'toString', {
1105 value: function (options) { return static_1.fullHostName(obj_1, options); }
1106 });
1107 hosts_1.push(obj_1);
1108 }
1109 }
1110 });
1111 if (hosts_1.length) {
1112 this.hosts = hosts_1;
1113 }
1114 }
1115 if (!('user' in this) && static_1.hasText(defaults.user)) {
1116 this.user = defaults.user.trim();
1117 }
1118 if (!('password' in this) && static_1.hasText(defaults.password)) {
1119 this.password = defaults.password.trim();
1120 }
1121 // Since the order of `path` segments is usually important, we set default
1122 // `path` segments as they are, but only when they are missing completely:
1123 if (!('path' in this) && Array.isArray(defaults.path)) {
1124 var s = defaults.path.filter(static_1.hasText);
1125 if (s.length) {
1126 this.path = s;
1127 }
1128 }
1129 // Missing default `params` are merged with the existing ones:
1130 if (defaults.params && typeof defaults.params === 'object') {
1131 var keys = Object.keys(defaults.params);
1132 if (keys.length) {
1133 if (this.params && typeof (this.params) === 'object') {
1134 for (var a in defaults.params) {
1135 if (!(a in this.params)) {
1136 this.params[a] = defaults.params[a];
1137 }
1138 }
1139 }
1140 else {
1141 this.params = {};
1142 for (var b in defaults.params) {
1143 this.params[b] = defaults.params[b];
1144 }
1145 }
1146 }
1147 }
1148 return this;
1149 };
1150 return ConnectionString;
1151}());
1152exports.ConnectionString = ConnectionString;
1153(function () {
1154 // hiding prototype members, to keep the type signature clean:
1155 ['setDefaults', 'toString', 'hostname', 'port', 'type'].forEach(function (prop) {
1156 var desc = Object.getOwnPropertyDescriptor(ConnectionString.prototype, prop);
1157 desc.enumerable = false;
1158 Object.defineProperty(ConnectionString.prototype, prop, desc);
1159 });
1160 var inspecting = false;
1161 // istanbul ignore else
1162 console.log('INSPECT:', util_1.inspect.custom);
1163 if (util_1.inspect.custom) {
1164 Object.defineProperty(ConnectionString.prototype, util_1.inspect.custom, {
1165 value: function () {
1166 if (inspecting) {
1167 return this;
1168 }
1169 inspecting = true;
1170 var options = { colors: process.stdout.isTTY };
1171 var src = util_1.inspect(this, options);
1172 var _a = this, hostname = _a.hostname, port = _a.port, type = _a.type;
1173 var vp = util_1.inspect({ hostname: hostname, port: port, type: type }, options);
1174 inspecting = false;
1175 return "" + src + os_1.EOL + "Virtual Properties: " + vp;
1176 }
1177 });
1178 }
1179})();
1180
1181}).call(this,require('_process'))
1182},{"./static":8,"./types":9,"_process":2,"os":1,"util":5}],8:[function(require,module,exports){
1183"use strict";
1184Object.defineProperty(exports, "__esModule", { value: true });
1185exports.parseHost = exports.validateUrl = exports.hasText = exports.decode = exports.encode = exports.fullHostName = void 0;
1186var types_1 = require("./types");
1187function fullHostName(obj, options) {
1188 var a = '';
1189 if (obj.name) {
1190 var skipEncoding = obj.type === types_1.HostType.IPv4 || obj.type === types_1.HostType.IPv6;
1191 a = skipEncoding ? obj.name : encode(obj.name, options !== null && options !== void 0 ? options : {});
1192 }
1193 if (obj.port) {
1194 a += ':' + obj.port;
1195 }
1196 return a;
1197}
1198exports.fullHostName = fullHostName;
1199function encode(text, options) {
1200 text = encodeURIComponent(text);
1201 if (options.plusForSpace) {
1202 text = text.replace(/%20/g, '+');
1203 }
1204 return options.encodeDollar ? text : text.replace(/%24/g, '$');
1205}
1206exports.encode = encode;
1207function decode(text) {
1208 return decodeURIComponent(text.replace(/\+/g, '%20'));
1209}
1210exports.decode = decode;
1211function hasText(txt) {
1212 return typeof txt === 'string' && /\S/.test(txt);
1213}
1214exports.hasText = hasText;
1215function validateUrl(url) {
1216 var idx = url.search(/[^A-Za-z0-9-._:/?[\]@!$&'()*+,;=%]/);
1217 if (idx >= 0) {
1218 var s = JSON.stringify(url[idx]).replace(/^"|"$/g, "'");
1219 throw new Error("Invalid URL character " + s + " at position " + idx);
1220 }
1221}
1222exports.validateUrl = validateUrl;
1223function parseHost(host, direct) {
1224 if (direct) {
1225 if (typeof host !== 'string') {
1226 throw new TypeError("Invalid \"host\" parameter: " + JSON.stringify(host));
1227 }
1228 host = host.trim();
1229 }
1230 var m, isIPv6;
1231 if (host[0] === '[') {
1232 // This is IPv6, with [::] being the shortest possible
1233 m = host.match(/((\[[0-9a-z:%]{2,45}])(?::(-?[0-9a-z]+))?)/i);
1234 isIPv6 = true;
1235 }
1236 else {
1237 // It is either IPv4 or domain/socket
1238 if (direct) {
1239 // Allowed directly: ForwardSlash + Space
1240 m = host.match(/(([a-z0-9.$/\- ]*)(?::(-?[0-9a-z]+))?)/i);
1241 }
1242 else {
1243 // Allow when indirectly: + and %
1244 m = host.match(/(([a-z0-9.+$%\-]*)(?::(-?[0-9a-z]+))?)/i);
1245 }
1246 }
1247 if (m) {
1248 var h_1 = {};
1249 if (m[2]) {
1250 if (isIPv6) {
1251 h_1.name = m[2];
1252 h_1.type = types_1.HostType.IPv6;
1253 }
1254 else {
1255 if (m[2].match(/([0-9]{1,3}\.){3}[0-9]{1,3}/)) {
1256 h_1.name = m[2];
1257 h_1.type = types_1.HostType.IPv4;
1258 }
1259 else {
1260 h_1.name = direct ? m[2] : decode(m[2]);
1261 h_1.type = h_1.name.match(/\/|.*\.sock$/i) ? types_1.HostType.socket : types_1.HostType.domain;
1262 }
1263 }
1264 }
1265 if (m[3]) {
1266 var p = m[3], port = parseInt(p);
1267 if (port > 0 && port < 65536 && port.toString() === p) {
1268 h_1.port = port;
1269 }
1270 else {
1271 throw new Error("Invalid port: " + JSON.stringify(p) + ". Valid port range is: [1...65535]");
1272 }
1273 }
1274 if (h_1.name || h_1.port) {
1275 Object.defineProperty(h_1, 'toString', {
1276 value: function (options) { return fullHostName(h_1, options); }
1277 });
1278 return h_1;
1279 }
1280 }
1281 return null;
1282}
1283exports.parseHost = parseHost;
1284
1285},{"./types":9}],9:[function(require,module,exports){
1286"use strict";
1287Object.defineProperty(exports, "__esModule", { value: true });
1288exports.HostType = void 0;
1289var HostType;
1290(function (HostType) {
1291 HostType["domain"] = "domain";
1292 HostType["socket"] = "socket";
1293 HostType["IPv4"] = "IPv4";
1294 HostType["IPv6"] = "IPv6";
1295})(HostType = exports.HostType || (exports.HostType = {}));
1296
1297},{}]},{},[6])(6)
1298});