package/package.json000644 0000002031 3560116604 011542 0ustar00000000 000000 { "name": "pg-connection-string", "version": "2.1.0", "description": "Functions for dealing with a PostgresSQL connection string", "main": "./index.js", "types": "./index.d.ts", "scripts": { "test": "istanbul cover _mocha && npm run check-coverage", "check-coverage": "istanbul check-coverage --statements 100 --branches 100 --lines 100 --functions 100", "coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls" }, "repository": { "type": "git", "url": "https://github.com/iceddev/pg-connection-string" }, "keywords": [ "pg", "connection", "string", "parse" ], "author": "Blaine Bublitz (http://iceddev.com/)", "license": "MIT", "bugs": { "url": "https://github.com/iceddev/pg-connection-string/issues" }, "homepage": "https://github.com/iceddev/pg-connection-string", "dependencies": {}, "devDependencies": { "chai": "^4.1.1", "istanbul": "^0.4.5", "mocha": "^3.5.0" }, "files": [ "index.js", "index.d.ts" ] } package/index.d.ts000644 0000000542 3560116604 011162 0ustar00000000 000000 export function parse(connectionString: string): ConnectionOptions; export interface ConnectionOptions { host: string | null; password?: string; user?: string; port?: string | null; database: string | null | undefined; client_encoding?: string; ssl?: boolean | string; application_name?: string; fallback_application_name?: string; } package/index.js000644 0000003734 3560116604 010734 0ustar00000000 000000 'use strict'; var url = require('url'); var fs = require('fs'); //Parse method copied from https://github.com/brianc/node-postgres //Copyright (c) 2010-2014 Brian Carlson (brian.m.carlson@gmail.com) //MIT License //parses a connection string function parse(str) { //unix socket if(str.charAt(0) === '/') { var config = str.split(' '); return { host: config[0], database: config[1] }; } // url parse expects spaces encoded as %20 var result = url.parse(/ |%[^a-f0-9]|%[a-f0-9][^a-f0-9]/i.test(str) ? encodeURI(str).replace(/\%25(\d\d)/g, "%$1") : str, true); var config = result.query; for (var k in config) { if (Array.isArray(config[k])) { config[k] = config[k][config[k].length-1]; } } var auth = (result.auth || ':').split(':'); config.user = auth[0]; config.password = auth.splice(1).join(':'); config.port = result.port; if(result.protocol == 'socket:') { config.host = decodeURI(result.pathname); config.database = result.query.db; config.client_encoding = result.query.encoding; return config; } config.host = result.hostname; // result.pathname is not always guaranteed to have a '/' prefix (e.g. relative urls) // only strip the slash if it is present. var pathname = result.pathname; if (pathname && pathname.charAt(0) === '/') { pathname = result.pathname.slice(1) || null; } config.database = pathname && decodeURI(pathname); if (config.ssl === 'true' || config.ssl === '1') { config.ssl = true; } if (config.ssl === '0') { config.ssl = false; } if (config.sslcert || config.sslkey || config.sslrootcert) { config.ssl = {}; } if (config.sslcert) { config.ssl.cert = fs.readFileSync(config.sslcert).toString(); } if (config.sslkey) { config.ssl.key = fs.readFileSync(config.sslkey).toString(); } if (config.sslrootcert) { config.ssl.ca = fs.readFileSync(config.sslrootcert).toString(); } return config; } module.exports = parse; parse.parse = parse; package/LICENSE000644 0000002072 3560116604 010266 0ustar00000000 000000 The MIT License (MIT) Copyright (c) 2014 Iced Development Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.package/README.md000644 0000001516 3560116604 010542 0ustar00000000 000000 pg-connection-string ==================== [![NPM](https://nodei.co/npm/pg-connection-string.png?compact=true)](https://nodei.co/npm/pg-connection-string/) [![Build Status](https://travis-ci.org/iceddev/pg-connection-string.svg?branch=master)](https://travis-ci.org/iceddev/pg-connection-string) [![Coverage Status](https://coveralls.io/repos/iceddev/pg-connection-string/badge.svg?branch=master)](https://coveralls.io/r/iceddev/pg-connection-string?branch=master) Functions for dealing with a PostgresSQL connection string `parse` method taken from [node-postgres](https://github.com/brianc/node-postgres.git) Copyright (c) 2010-2014 Brian Carlson (brian.m.carlson@gmail.com) MIT License ## Usage ```js var parse = require('pg-connection-string').parse; var config = parse('postgres://someuser:somepassword@somehost:381/somedatabase') ```