diff --git a/README.md b/README.md index 680ae8e..d0e6b7c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ connection-string ================= -URL Connection String Parser, with fully optional syntax. +Advanced URL Connection String Parser, with fully optional syntax. [![Build Status](https://travis-ci.org/vitaly-t/connection-string.svg?branch=master)](https://travis-ci.org/vitaly-t/connection-string) [![Coverage Status](https://coveralls.io/repos/vitaly-t/connection-string/badge.svg?branch=master)](https://coveralls.io/r/vitaly-t/connection-string?branch=master) @@ -104,7 +104,7 @@ Both the root function and class `ConnectionString` take a second optional param If it is specified, the parser will call method `setDefauts` automatically (see below). The object returned by the parser contains all the properties as specified in the connection string, -plus two methods: `setDefauilts` and `build` (see below). +plus two methods: `setDefaults` and `build` (see below). #### Method `setDefaults` @@ -112,33 +112,43 @@ plus two methods: `setDefauilts` and `build` (see below). setDefaults(defaults) => void ``` -The method takes an object that default values and sets those for all the properties that were not +The method takes an object with default values and sets those for all the properties that were not specified within the connection string. You can make use of this method either explicitly, after constructing the class, or implicitly, by passing `defaults` into the parser/constructor. +Example: + +```js +var a = new ConnectionString('abc://localhost', { + // defaults: + port: 123, + user: 'guest' +}); +// a => { +// protocol: 'abc', +// host: 'localhost', +// hostname: 'localhost', +// port: 123, +// user: 'guest' +// } +``` + #### Method `build` ``` build() => string ``` -Builds and returns the connection string from all the current properties. +Constructs and returns the connection string from all the current properties. Example: ```js var a = new ConnectionString('abc://localhost'); - -a.build(); //=> 'abc://localhost' - -// using defaults: -a.build({ - hostname: '127.0.0.1', - port: 12345, - user: 'tester' -}); //=> 'abc://tester@localhost:12345' +a.setDefaults({user: 'guest', port: 123}); +a.build(); //=> 'abc://guest:@localhost:123' ``` [WiKi Pages]:https://github.com/vitaly-t/connection-string/wiki diff --git a/package.json b/package.json index b6ef81f..099bc3f 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { "name": "connection-string", - "version": "0.3.1", - "description": "URL Connection String Parser.", + "version": "0.4.0", + "description": "Advanced URL Connection String Parser.", "main": "src/index.js", "typings": "src/index.d.ts", "scripts": { "test": "jasmine-node test", "coverage": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test", "travis": "npm run lint && istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test --captureExceptions && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", - "lint": "./node_modules/.bin/eslint ./lib ./test" + "lint": "./node_modules/.bin/eslint ./src ./test/*Spec.js" }, "files": [ "src" @@ -38,9 +38,9 @@ "npm": ">=1.4" }, "devDependencies": { - "coveralls": "2.11", - "eslint": "^4.2.0", - "istanbul": "0.4", - "jasmine-node": "1.14" + "coveralls": "~2.11.16", + "eslint": "~4.4.1", + "istanbul": "~0.4.5", + "jasmine-node": "~1.14.5" } } diff --git a/src/index.js b/src/index.js index 4edbc97..2c77759 100644 --- a/src/index.js +++ b/src/index.js @@ -172,7 +172,7 @@ this.params = defaults.params; } if (this.port || this.hostname) { - this.host = (this.hostname || '') + (this.port >= 0 ? (':' + parseInt(this.port)) : ''); + this.host = (this.hostname || '') + (this.port >= 0 ? (':' + this.port) : ''); } return this; }