function getConnectionString(connection) {
  let url;
  try {
    // if connection.host contains a valid url e.g. 'https://crate.io:4200'
    url = new URL(connection.host);
    // if connection.host doesn't contain protocol e.g. 'crate.io:4200'
    if (!['http:', 'https:'].includes(url.protocol)) {
      let protocol = connection.ssl ? 'https:' : 'http:';
      url = new URL(protocol + connection.host);
    }
  } catch (error) {
    // if connection.host contains only hostname e.g. 'crate.io'
    let protocol = connection.ssl ? 'https:' : 'http:';
    url = new URL(protocol + connection.host);
  }
  if (connection.port) {
    url.port = connection.port;
  }
  if (connection.username) {
    url.username = connection.username;
    if (connection.password) {
      url.password = connection.password;
    }
  }
  return url.href;
}
Get connection string with options
@param {*} connection