buildFullPath.js 783 B

12345678910111213141516171819202122
  1. 'use strict';
  2. import isAbsoluteURL from '../helpers/isAbsoluteURL.js';
  3. import combineURLs from '../helpers/combineURLs.js';
  4. /**
  5. * Creates a new URL by combining the baseURL with the requestedURL,
  6. * only when the requestedURL is not already an absolute URL.
  7. * If the requestURL is absolute, this function returns the requestedURL untouched.
  8. *
  9. * @param {string} baseURL The base URL
  10. * @param {string} requestedURL Absolute or relative URL to combine
  11. *
  12. * @returns {string} The combined full path
  13. */
  14. export default function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
  15. let isRelativeUrl = !isAbsoluteURL(requestedURL);
  16. if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) {
  17. return combineURLs(baseURL, requestedURL);
  18. }
  19. return requestedURL;
  20. }