diff --git a/README.md b/README.md index 396e8d0..c9105f6 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/package.json b/package.json index 099bc3f..f1194e5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.d.ts b/src/index.d.ts index dda9b68..30d3ce0 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -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; diff --git a/test/main.ts b/test/main.ts index 550f8da..7d8f327 100644 --- a/test/main.ts +++ b/test/main.ts @@ -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!' };