From 267c7ec1ab511617030c7cf3bea33df2e40abd9e Mon Sep 17 00:00:00 2001 From: Vitaly Tomilov Date: Sat, 14 Jul 2018 22:53:38 +0100 Subject: [PATCH] refactoring --- README.md | 20 +++++++++++--------- package.json | 6 +++--- src/index.js | 13 ++++--------- test/main.js | 3 ++- test/main.ts | 3 ++- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 325af7b..7094ea5 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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¶m2=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 @@ -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: @@ -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** @@ -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` diff --git a/package.json b/package.json index 535cd0b..9961076 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/index.js b/src/index.js index 3f26dfb..9b95982 100644 --- a/src/index.js +++ b/src/index.js @@ -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) { @@ -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); diff --git a/test/main.js b/test/main.js index 5bf56ba..87a3431 100644 --- a/test/main.js +++ b/test/main.js @@ -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('')); diff --git a/test/main.ts b/test/main.ts index 06549f6..177fde4 100644 --- a/test/main.ts +++ b/test/main.ts @@ -24,7 +24,8 @@ var cs = a.build(); a.setDefaults({}); a.setDefaults({ - user: '' + user: '', + password: '' }); cs = a.build();