Comparing version 3.0.0 to 4.0.0
@@ -7,9 +7,5 @@ (function (name, context, definition) { | ||
function startsWith(str, searchString) { | ||
return str.substr(0, searchString.length) === searchString; | ||
} | ||
function normalize (strArray) { | ||
var resultArray = []; | ||
function normalize (strArray, options) { | ||
var resultArray = []; | ||
// If the first part is a plain protocol, we combine it with the next part. | ||
@@ -27,11 +23,12 @@ if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) { | ||
} | ||
for (var i = 0; i < strArray.length; i++) { | ||
var component = strArray[i]; | ||
if (typeof component !== 'string') { | ||
component = component && component.toString() || ''; | ||
throw new TypeError('Url must be a string. Received ' + component); | ||
} | ||
if (component === '') { continue; } | ||
if (i > 0) { | ||
@@ -48,5 +45,5 @@ // Removing the starting slashes for each component but the first. | ||
} | ||
resultArray.push(component); | ||
} | ||
@@ -68,14 +65,13 @@ | ||
return function () { | ||
var input = arguments; | ||
var options = {}; | ||
var input; | ||
if (typeof arguments[0] === 'object') { | ||
// new syntax with array and options | ||
input = arguments[0]; | ||
options = arguments[1] || {}; | ||
} else { | ||
input = [].slice.call(arguments); | ||
} | ||
return normalize([].slice.call(input), options); | ||
return normalize(input); | ||
}; | ||
}); |
{ | ||
"name": "url-join", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "Join urls and normalize as in path.join.", | ||
@@ -23,2 +23,2 @@ "main": "lib/url-join.js", | ||
} | ||
} | ||
} |
var urljoin = require('../lib/url-join'); | ||
var assert = require('assert'); | ||
@@ -101,5 +102,11 @@ describe('url join', function () { | ||
it('should merge a simple path with a number correctly', function() { | ||
urljoin('http://blabla.com/', 1) | ||
.should.eql('http://blabla.com/1'); | ||
it('should fail with segments that are not string', function() { | ||
assert.throws(() => urljoin('http://blabla.com/', 1), | ||
/Url must be a string. Received 1/); | ||
assert.throws(() => urljoin('http://blabla.com/', undefined, 'test'), | ||
/Url must be a string. Received undefined/); | ||
assert.throws(() => urljoin('http://blabla.com/', null, 'test'), | ||
/Url must be a string. Received null/); | ||
assert.throws(() => urljoin('http://blabla.com/', { foo: 123 }, 'test'), | ||
/Url must be a string. Received \[object Object\]/); | ||
}); | ||
@@ -132,2 +139,9 @@ | ||
}); | ||
it('should skip empty strings', function() { | ||
urljoin('http://foobar.com', '', 'test') | ||
.should.eql('http://foobar.com/test'); | ||
urljoin('', 'http://foobar.com', '', 'test') | ||
.should.eql('http://foobar.com/test'); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10694
199