buildFullPath.js 695 B

123456789101112131415161718192021
  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) {
  15. if (baseURL && !isAbsoluteURL(requestedURL)) {
  16. return combineURLs(baseURL, requestedURL);
  17. }
  18. return requestedURL;
  19. }