Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Jul 14, 2018
1 parent 3a69480 commit 267c7ec
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Unlike the standard URL parser, this one supports the following:

* Multiple hosts - for connecting to multiple servers
* Fully optional syntax for every element in the connection string
* Configuration of defaults for any parameter that's missing
* Configuration of defaults for any missing parameter
* Construction of a connection string from all parameters
* Friendlier access to the URL's segments and parameters
* TypeScript declarations are deployed with the library
Expand All @@ -50,11 +50,11 @@ Unlike the standard URL parser, this one supports the following:
* `username@` => `{user: 'username'}`
* `:pass123@` => `{password: 'pass123'}`
* `/seg1/seg2` => `{segments: ['seg1', 'seg2']}`
* `?param1=1&param2=2` => `{params: {param1: '1', param2: '2'}}`
* `?p1=1&p2=2` => `{params: {p1: '1', p2: '2'}}`

For a complete list of short-syntax examples see the [Optional Format].
For more short-syntax examples see [Optional Format].

All browsers and Node.js versions are supported.
All browsers are supported, plus Node.js v4.0 and newer.

## Installing

Expand All @@ -71,8 +71,9 @@ const parse = require('connection-string');

const obj1 = parse('my-server:12345');

// with a default:
const obj2 = parse('my-server:12345', {user: 'admin'});
// with a default value:
parse('my-server:12345', {user: 'admin'});
//=> {user: 'admin', hosts: [{name: 'my-server', port: 12345}]}
```

or as a class:
Expand All @@ -82,8 +83,9 @@ const ConnectionString = require('connection-string');

const obj1 = new ConnectionString('my-server:12345');

// with a default:
// with a default value:
const obj2 = new ConnectionString('my-server:12345', {user: 'admin'});
//=> {user: 'admin', hosts: [{name: 'my-server', port: 12345}]}
```

* **Browsers**
Expand Down Expand Up @@ -116,11 +118,11 @@ plus two methods: `setDefaults` and `build` (see below).

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

The method takes an object with default values, 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, 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.
passing the `defaults` object into the parser/constructor.

#### Method `build() => string`

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "connection-string",
"version": "0.6.0",
"version": "0.6.1",
"description": "Advanced URL Connection String Parser.",
"main": "src/index.js",
"typings": "src/index.d.ts",
Expand Down Expand Up @@ -34,8 +34,8 @@
},
"license": "MIT",
"engines": {
"node": ">=0.10",
"npm": ">=1.4"
"node": ">=4.0",
"npm": ">=2.14.2"
},
"devDependencies": {
"coveralls": "3.0.2",
Expand Down
13 changes: 4 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
}

function isText(txt) {
return txt && typeof txt === 'string' && /\S/.test(txt);
return typeof txt === 'string' && /\S/.test(txt);
}

function trim(txt) {
Expand All @@ -250,21 +250,16 @@
return (typeof str1 === 'string' && typeof str2 === 'string') && str1.toUpperCase() === str2.toUpperCase();
}

/* istanbul ignore next */
Number.isInteger = Number.isInteger || function (value) {
return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
};

Object.defineProperty(ConnectionString.prototype, 'build', {value: build});
Object.defineProperty(ConnectionString.prototype, 'setDefaults', {value: setDefaults});

ConnectionString.ConnectionString = ConnectionString;
ConnectionString.ConnectionString = ConnectionString; // to make it more TypeScript-friendly

/* istanbul ignore else */
if (typeof module === 'object' && module && typeof module.exports === 'object') {
module.exports = ConnectionString;
module.exports = ConnectionString; // inside Node.js
}
else {
window.ConnectionString = ConnectionString;
window.ConnectionString = ConnectionString; // inside a browser
}
})(this);
3 changes: 2 additions & 1 deletion test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ a.params = {
var cs = a.build();
a.setDefaults({});
a.setDefaults({
user: ''
user: '',
password: ''
});
cs = a.build();
var qq = a.setDefaults(new src_1.ConnectionString(''));
3 changes: 2 additions & 1 deletion test/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var cs = a.build();
a.setDefaults({});

a.setDefaults({
user: ''
user: '',
password: ''
});

cs = a.build();
Expand Down

0 comments on commit 267c7ec

Please sign in to comment.