Skip to content

Commit

Permalink
improving segments+params
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed May 24, 2018
1 parent 65a3ff7 commit f1da7c6
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,30 @@
if (!this.password && isText(defaults.password)) {
this.password = trim(defaults.password);
}
// TODO: This needs more test coverage:
if (!this.segments && Array.isArray(defaults.segments)) {
this.segments = defaults.segments;
var s = defaults.segments.filter(isText);
if (s.length) {
this.segments = s;
}
}
// TODO: Default for parameters should allow merging logic.
if (!this.params && defaults.params && typeof defaults.params === 'object') {
this.params = defaults.params;
// TODO: This needs more test coverage:
if (defaults.params && typeof defaults.params === 'object') {
var keys = Object.keys(defaults.params);
if (keys.length) {
if (this.params) {
for (var a in defaults.params) {
if (!(a in this.params)) {
this.params[a] = defaults.params[a];
}
}
} else {
this.params = {};
for (var b in defaults.params) {
this.params[b] = defaults.params[b];
}
}
}
}
if (this.port || this.hostname) {
this.host = (this.hostname || '') + (this.port >= 0 ? (':' + this.port) : '');
Expand Down

0 comments on commit f1da7c6

Please sign in to comment.