iridium
Version:
A custom lightweight ORM for MongoDB designed for power-users
41 lines • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
function BuildUrl(config) {
let url = "mongodb://";
if (config.username) {
url += config.username;
if (config.password)
url += ":" + config.password;
url += "@";
}
url += buildHostList(config);
if (config.database)
url += "/" + config.database;
return url;
}
exports.BuildUrl = BuildUrl;
function buildHostList(config) {
let hosts = [];
if (config.host) {
if (config.port)
hosts.push(`${config.host}:${config.port}`);
else
hosts.push(config.host);
}
if (config.hosts) {
config.hosts.forEach(host => {
if (host.port)
hosts.push(`${host.address}:${host.port}`);
else if (config && config.port)
hosts.push(`${host.address}:${config.port}`);
else
hosts.push(host.address);
});
}
if (hosts.length)
return lodash_1.uniq(hosts).join(",");
else
return "localhost";
}
//# sourceMappingURL=UrlBuilder.js.map