2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-02 16:04:10 +03:00

Add combineURLs helper

This commit is contained in:
Nick Uraltsev
2015-11-21 17:41:02 -08:00
parent 4bbde9ae6c
commit e253b0ef3e
2 changed files with 27 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
'use strict';
/**
* Creates a new URL by combining the specified URLs
*
* @param {string} baseURL The base URL
* @param {string} relativeURL The relative URL
* @returns {string} The combined URL
*/
module.exports = function combineURLs(baseURL, relativeURL) {
return baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '');
};
+15
View File
@@ -0,0 +1,15 @@
var combineURLs = require('../../../lib/helpers/combineURLs');
describe('helpers::combineURLs', function () {
it('should combine URLs', function () {
expect(combineURLs('https://api.github.com', '/users')).toBe('https://api.github.com/users');
});
it('should remove duplicate slashes', function () {
expect(combineURLs('https://api.github.com/', '/users')).toBe('https://api.github.com/users');
});
it('should insert missing slash', function () {
expect(combineURLs('https://api.github.com', 'users')).toBe('https://api.github.com/users');
});
});