@opengis/fastify-table
Version:
core-plugins
13 lines • 526 B
JavaScript
export default function getDBParams(str) {
if (typeof str !== 'string') return str;
if (str.includes('/')) {
const arr = str.match(/(([A-z_0-9]+):([A-z0-9_]+)@)?([a-z0-9._]+):([0-9]+)(\/([a-z0-9_]+))?/) || [];
const [, , user, password, host, port, , db] = arr;
return { name: str, user, password, host, port, db };
}
if (str.includes(':')) {
const [db, port] = str.split(':') || [];
return { name: str, port, db };
}
return { name: str, db: str };
}