Skip to content

Commit

Permalink
docs + package updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Aug 14, 2017
1 parent 77348f0 commit 134156c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -104,41 +104,51 @@ 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`

```
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
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 134156c

Please sign in to comment.