Skip to content

Commit

Permalink
improving typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Aug 14, 2017
1 parent 2423718 commit f4340bd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 42 deletions.
33 changes: 4 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,40 +106,15 @@ If it is specified, the parser will call method `setDefaults` automatically (see
The object returned by the parser contains all the properties as specified in the connection string,
plus two methods: `setDefaults` and `build` (see below).

#### Method `setDefaults`
#### Method `setDefaults(defaults) => ConnectionString`

```
setDefaults(defaults) => void
```

The method takes an object with default values and sets those for all the properties that were not
specified within the connection string.
The method takes an object with default values, sets those for all the properties that were not
specified within the connection string, and returns the same object (itself).

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
```
#### Method `build() => string`

Constructs and returns the connection string from all the current properties.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "connection-string",
"version": "0.4.0",
"version": "0.4.1",
"description": "Advanced URL Connection String Parser.",
"main": "src/index.js",
"typings": "src/index.d.ts",
Expand Down
18 changes: 9 additions & 9 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ interface IConnectionString {
hostname?: string
port?: number
segments?: string[]
params?: { [name: string]: any }
params?: { [name: string]: string }
}

export class ConnectionString implements IConnectionString {
constructor(cd: string, defaults?: IConnectionString)

protocol: string;
user: string;
password: string;
host: string;
hostname: string;
port: number;
segments: string[];
params: { [name: string]: any };
protocol?: string;
user?: string;
password?: string;
host?: string;
hostname?: string;
port?: number;
segments?: string[];
params?: { [name: string]: string };

build(): string;

Expand Down
6 changes: 3 additions & 3 deletions test/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ if ('protocol' in a) {
}

var segment1: string = a.segments[0];
var param1: number = a.params['first'];
var param1: string = a.params['first'];

a.params['first'] = 123;
a.params['first'] = 'hello';

a.params = {
first: 123,
first: '123',
second: 'hello!'
};

Expand Down

0 comments on commit f4340bd

Please sign in to comment.