buildFullPath.js 691 B

1234567891011121314151617181920
  1. 'use strict'
  2. import isAbsoluteURL from '../helpers/isAbsoluteURL'
  3. import combineURLs from '../helpers/combineURLs'
  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. * @returns {string} The combined full path
  12. */
  13. export default function buildFullPath(baseURL, requestedURL) {
  14. if (baseURL && !isAbsoluteURL(requestedURL)) {
  15. return combineURLs(baseURL, requestedURL)
  16. }
  17. return requestedURL
  18. }