path.js (598B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 /* 8 * Join all the arguments together and normalize the resulting URI. 9 * The initial path must be an full URI with a protocol (i.e. http://). 10 */ 11 exports.joinURI = (initialPath, ...paths) => { 12 let url = URL.parse(initialPath); 13 if (!url) { 14 return null; 15 } 16 17 for (const path of paths) { 18 if (path) { 19 url = new URL(path, url); 20 } 21 } 22 23 return url.href; 24 };