From 990b36463503c5fb38e720d7ee6a55d02bd2c7e8 Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Mon, 6 Nov 2017 10:24:16 +0100 Subject: [PATCH] add getDbUrl fund --- src/utils/dbUtils.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/utils/dbUtils.js b/src/utils/dbUtils.js index 2b68313..54e2b9a 100644 --- a/src/utils/dbUtils.js +++ b/src/utils/dbUtils.js @@ -14,6 +14,14 @@ export function getLegalDBName(input) { .replace(/(%..)/g, esc => `(${esc.substr(1)})`); } +export function getDbUrl(db) { + if (db.user) { + return `${db.protocol}${encodeURIComponent(db.user)}:${encodeURIComponent(db.password)}@${db.host}`; + } else { + return `${db.protocol}${db.host}`; + } +}; + const dbs = {}; export function getDb(dbUrl) { if (!dbs[dbUrl]) dbs[dbUrl] = new PouchDB(dbUrl);