inspired by https://github.com/request/request/blob/33cd9e297a00c5540e55778a24a706effc35434c/request.js#L169
163382
function getProxyUri(uri) {

	if (uri.protocol === 'https:' && env.httpsProxy || uri.protocol === 'http:' && env.httpProxy) {

		if (env.noProxy) {
			var canonicalHost = uri.host.replace(/^\.*/, '.');
			var port = uri.port || (uri.protocol === 'https:' ? '443' : '80');

			var patterns = env.noProxy.split(',');
			for (var i = patterns.length - 1; i >= 0; i--) {
				var pattern = patterns[i].trim().toLowerCase();

				// don't use a proxy at all
				if (pattern === '*') {
					return null;
				}

				// Remove leading * and make sure to have exact one leading dot (.)
				pattern = pattern.replace(/^[\*]+/, '').replace(/^\.*/, '.');

				// add port if no specified
				if (pattern.indexOf(':') === -1) {
					pattern += ':' + port;
				}

				// if host ends with pattern, no proxy should be used
				if (canonicalHost.indexOf(pattern) === canonicalHost.length - pattern.length) {
					return null;
				}
			}
		}

		if (uri.protocol === 'https:' && env.httpsProxy) {
			return env.httpsProxy;
		} else if (uri.protocol === 'http:' && env.httpProxy) {
			return env.httpProxy;
		}
	}

	return null;
}
1298941
function compressPubKey (pubKey) {
  const x = pubKey.substring(2, 66)
  const y = pubKey.substring(66, 130)
  const even = parseInt(y.substring(62, 64), 16) % 2 === 0
  const prefix = even ? '02' : '03'

  return prefix + x
}
1067321
function base64ToBlob(base64Image, contentType) {
  // http://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript

  // Remove leading 'data:image/jpeg;base64,' or 'data:image/png;base64,'
  base64Image = base64Image.split(',')[1];

  let byteCharacters = atob(base64Image);

  // http://stackoverflow.com/questions/6259515/javascript-elegant-way-to-split-string-into-segments-n-characters-long
  let byteArrays = byteCharacters.match(/[\s\S]{1,512}/g).map( slice => {

    let byteNumbers = slice.split('').map( x => x.charCodeAt(0) );

    return new Uint8Array(byteNumbers);
  });

  let blob = new Blob(byteArrays, { type: contentType || 'image/jpg' /* or 'image/png' */ });

  return blob;
}
153362
function dataURItoBlob(dataURI) {
    // convert base64 to raw binary data held in a string
    var byteString = atob(dataURI.split(',')[1]),
        // separate out the mime component
        mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0],
        // write the bytes of the string to an ArrayBuffer
        arrayBuffer = new ArrayBuffer(byteString.length),
        _ia = new Uint8Array(arrayBuffer),
        i, dataView, blob;

    for (i = 0; i < byteString.length; i++) {
        _ia[i] = byteString.charCodeAt(i);
    }

    dataView = new DataView(arrayBuffer);
    blob = new Blob([dataView], { type: mimeString });

    return blob;
}
406433
function getFileUrl (repo, path, sha, line) {
  var url = "https://github.com/" + repo + "/blob/";

  if (sha) {
    url += sha + "/";
  }

  url += path;

  if (line) {
    url += "#L" + line;
  }

  return url;
}
514813
function request2response ( request ) {

    let headers = {},
        headersKeys = [],
        headersEntries = [];

    request.getAllResponseHeaders ().replace ( /^(.*?):\s*([\s\S]*?)$/gm, ( match, key, value ) => {
      key = key.toLowerCase ();
      headersKeys.push ( key );
      headersEntries.push ([ key, value ]);
      let prevValue = headers[key];
      headers[key] = prevValue ? `${prevValue},${value}` : value;
    });

    return {
      request,
      ok: ( request.status / 200 | 0 ) === 1, // 200-299
      status: request.status,
      statusText: request.statusText,
      url: request.responseURL,
      clone: () => fetch.request2response ( request ),
      text: () => Promise.resolve ( request.responseText ),
      json: () => Promise.resolve ( JSON.parse ( request.responseText ) ),
      blob: () => Promise.resolve ( new Blob ([ request.response ]) ),
      headers: {
        keys: () => headersKeys,
        entries: () => headersEntries,
        get: key => headers[key.toLowerCase ()],
        has: key => key.toLowerCase () in headers
      }
    };

  }
507009
function createPkgConfigPathObj(path) {
  var lastWildcard = path.lastIndexOf('*');
  var length = Math.max(lastWildcard + 1, path.lastIndexOf('/'));
  return {
    length: length,
    regEx: new RegExp('^(' + path.substr(0, length).replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '[^\\/]+') + ')(\\/|$)'),
    wildcard: lastWildcard != -1
  };
}
1317666
function getUri() {
  const startPos = pos;
  const uriExcluding = {};
  let uri;
  let token;
  let l;
  let raw;

  pos += 2;

  uriExcluding[TokenType.Space] = 1;
  uriExcluding[TokenType.Tab] = 1;
  uriExcluding[TokenType.Newline] = 1;
  uriExcluding[TokenType.LeftParenthesis] = 1;
  uriExcluding[TokenType.RightParenthesis] = 1;

  if (checkUri1(pos)) {
    uri = []
        .concat(getSC())
        .concat([getString()])
        .concat(getSC());
  } else {
    uri = getSC();
    l = checkExcluding(uriExcluding, pos);
    token = tokens[pos];
    raw = newNode(NodeType.RawType, joinValues(pos, pos + l), token.ln,
        token.col);

    uri.push(raw);

    pos += l + 1;

    uri = uri.concat(getSC());
  }

  token = tokens[startPos];
  const line = token.ln;
  const column = token.col;
  const end = getLastPosition(uri, line, column, 1);
  pos++;

  return newNode(NodeType.UriType, uri, line, column, end);
}
995290
function parse_BLOB(blob) {
	var size = blob.read_shift(4);
	var bytes = blob.slice(blob.l,blob.l+size);
	blob.l += size;
	if((size & 3) > 0) blob.l += (4 - (size & 3)) & 3;
	return bytes;
}
956209
function parse_ColRelU(blob, length) {
	var c = blob.read_shift(length == 1 ? 1 : 2);
	return [c & 0x3FFF, (c >> 14) & 1, (c >> 15) & 1];
}
150954
function Multipart() {

		// Internal body
		var body = [];
		var boundary = (Math.random() * 1e10).toString(32);
		var counter = 0;
		var lineBreak = '\r\n';
		var delim = lineBreak + '--' + boundary;
		var ready = function() {};

		var dataUri = /^data\:([^;,]+(\;charset=[^;,]+)?)(\;base64)?,/i;

		// Add file
		function addFile(item) {
			var fr = new FileReader();
			fr.onload = function(e) {
				addContent(btoa(e.target.result), item.type + lineBreak + 'Content-Transfer-Encoding: base64');
			};

			fr.readAsBinaryString(item);
		}

		// Add content
		function addContent(content, type) {
			body.push(lineBreak + 'Content-Type: ' + type + lineBreak + lineBreak + content);
			counter--;
			ready();
		}

		// Add new things to the object
		this.append = function(content, type) {

			// Does the content have an array
			if (typeof (content) === 'string' || !('length' in Object(content))) {
				// Converti to multiples
				content = [content];
			}

			for (var i = 0; i < content.length; i++) {

				counter++;

				var item = content[i];

				// Is this a file?
				// Files can be either Blobs or File types
				if (
					(typeof (File) !== 'undefined' && item instanceof File) ||
					(typeof (Blob) !== 'undefined' && item instanceof Blob)
				) {
					// Read the file in
					addFile(item);
				}

				// Data-URI?
				// Data:[<mime type>][;charset=<charset>][;base64],<encoded data>
				// /^data\:([^;,]+(\;charset=[^;,]+)?)(\;base64)?,/i
				else if (typeof (item) === 'string' && item.match(dataUri)) {
					var m = item.match(dataUri);
					addContent(item.replace(dataUri, ''), m[1] + lineBreak + 'Content-Transfer-Encoding: base64');
				}

				// Regular string
				else {
					addContent(item, type);
				}
			}
		};

		this.onready = function(fn) {
			ready = function() {
				if (counter === 0) {
					// Trigger ready
					body.unshift('');
					body.push('--');
					fn(body.join(delim), boundary);
					body = [];
				}
			};

			ready();
		};
	}
571126
function jsonEncoded(gw, callback){
  var buffer = '';
  var readlength = 0;
  var $error = false;
  gw.req.on('data', function (chunk) {
    if (readlength > gw.content.length){$error = true;}
    if (!$error) {
      readlength += chunk.length;
      buffer += chunk.toString('ascii');
    }
  });
  gw.req.on('end', function () {
    if ($error) {
      gw.error(400);
    } else {
      try {
        var params = JSON.parse(buffer);
        gw.content.params = params;
        for(var i=0,k=Object.keys(params),l=k.length;i<l;i++){
          gw.params[k[i]]=params[k[i]];
        }
        callback();
      } catch (error) {
        gw.error(400);
      }
    }
  });
}
570018
function parseBase64Stream(req) {
  var passthrough = false;
  var accumulation = '';
  var stream = req.pipe(through(function(chunk, enc, callback) {
    if (!passthrough) {
      accumulation += chunk;
      var test = ';base64,';
      var index = accumulation.indexOf(test);
      if (index > -1) {
        passthrough = true;
        chunk = accumulation.substr(index + test.length);
      }
    }
    if (passthrough) {
      this.push(chunk);
    }
    callback();
  }))
    .pipe(base64.decode());
  return stream;
}
1289039
function getUri() {
  const startPos = pos;
  const type = NodeType.UriType;
  const token = tokens[startPos];
  const line = token.ln;
  const column = token.col;
  let content = [];
  let end;

  const uriType = tokens[startPos].uriType;

  // Skip `url` and `(`.
  pos += 2;

  if (uriType === 1) content = content.concat(getUri1());
  else if (uriType === 2) content = content.concat(getUri2());
  else end = getLastPosition(content, line, column, 4);

  if (!end) end = getLastPosition(content, line, column, 1);

  // Skip `)`.
  pos++;

  return newNode(type, content, line, column, end);
}
735280
function parse_dictionary(blob,CodePage) {
	var cnt = blob.read_shift(4);
	var dict = ({});
	for(var j = 0; j != cnt; ++j) {
		var pid = blob.read_shift(4);
		var len = blob.read_shift(4);
		dict[pid] = blob.read_shift(len, (CodePage === 0x4B0 ?'utf16le':'utf8')).replace(chr0,'').replace(chr1,'!');
	}
	if(blob.l & 3) blob.l = (blob.l>>2+1)<<2;
	return dict;
}
1296755
function(org) {
        var url = decodeURIComponent(org.toString());
        urlOutput.empty().attr('href', url);

        url = url.replace(/.*?\/users\//g, '/users/');
        url = url.replace(/Token=(.{10}).*/g, 'Token=$1...');

        var parts = url.split('?'), param;
        var params = parts[1].replace(/t\[\]=maxSize.*?&/g, '').split('&');

        // Base url
        $('<div />').text(parts[0]).appendTo(urlOutput);
        for (var i = 0, prefix; i < params.length; i++) {
            prefix = i > 0 ? '&' : '?';

            parts = params[i].split(/t\[\]=/);
            param = prefix + parts[0];
            if (parts.length > 1) {
                var args = [], trans = parts[1].split(':');
                param = prefix + 't[]=<span class="transformation">' + trans[0] + '</span>';

                if (trans.length > 1) {
                    var items = trans[1].split(',');

                    for (var t = 0; t < items.length; t++) {
                        var c = items[t].split('='), x = '';
                        x += '<span class="param">' + c[0] + '</span>=';
                        x += '<span class="value">' + c[1] + '</span>';
                        args.push(x);
                    }

                    param += ':' + args.join(',');
                }
            }

            param = param.replace(/(.*?=)/, '<strong>$1</strong>');
            $('<div />').html(param).appendTo(urlOutput);
        }
    }
1017044
function(body, error, code, errorTraceId, errorUserTitle, errorUserMessage) {
            _$jscmd("utils.js", "line", 104);
            //TODO: support errorTraceId
            //TODO: errorUserTitle and errorUserMessage should be change from strings to ints (==code) to support localization
            var response = {};
            //set code
            if (_$jscmd("utils.js", "cond", "107_7_26", !__isNullOrUndefined(code))) {
                _$jscmd("utils.js", "line", 108);
                response.code = code;
            } else {
                if (_$jscmd("utils.js", "cond", "111_8_26", !__isNullOrUndefined(body))) response.code = 0; else //if (!__isNullOrUndefined(error))
                response.code = 1e3;
            }
            //set body
            if (_$jscmd("utils.js", "cond", "118_7_26", !__isNullOrUndefined(body))) response.body = body;
            //set error
            if (_$jscmd("utils.js", "cond", "122_7_27", !__isNullOrUndefined(error))) {
                _$jscmd("utils.js", "line", 123);
                response.error = error;
                //set errorTraceId
                if (_$jscmd("utils.js", "cond", "126_8_34", !__isNullOrUndefined(errorTraceId))) response.errorTraceId = errorTraceId;
                //set errorUserTitle
                if (_$jscmd("utils.js", "cond", "130_8_36", !__isNullOrUndefined(errorUserTitle))) response.errorUserTitle = errorUserTitle; else {
                    _$jscmd("utils.js", "line", 134);
                    //TODO: this is not the real implementation
                    response.errorUserTitle = "Bolt Error " + response.code.toString();
                }
                //set errorUserMessage
                if (_$jscmd("utils.js", "cond", "138_8_38", !__isNullOrUndefined(errorUserMessage))) response.errorUserMessage = errorUserMessage; else {
                    _$jscmd("utils.js", "line", 142);
                    //TODO: this is not the real implementation
                    response.errorUserMessage = errors[response.code];
                }
            }
            _$jscmd("utils.js", "line", 146);
            return JSON.stringify(response);
        }