2014-12-09 23:00:00 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Join all the arguments together and normalize the resulting URI.
|
|
|
|
* The initial path must be an full URI with a protocol (i.e. http://).
|
|
|
|
*/
|
|
|
|
exports.joinURI = (initialPath, ...paths) => {
|
2016-03-04 15:06:48 +03:00
|
|
|
let url;
|
2014-12-09 23:00:00 +03:00
|
|
|
|
|
|
|
try {
|
2016-03-04 15:06:48 +03:00
|
|
|
url = new URL(initialPath);
|
2016-12-02 20:32:04 +03:00
|
|
|
} catch (e) {
|
|
|
|
return null;
|
2014-12-09 23:00:00 +03:00
|
|
|
}
|
|
|
|
|
2018-06-01 13:36:09 +03:00
|
|
|
for (const path of paths) {
|
2015-09-01 21:25:13 +03:00
|
|
|
if (path) {
|
2016-03-04 15:06:48 +03:00
|
|
|
url = new URL(path, url);
|
2014-12-09 23:00:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 15:06:48 +03:00
|
|
|
return url.href;
|
2016-05-17 21:25:54 +03:00
|
|
|
};
|