buildFullPath.js 695 B

1234567891011121314151617181920
  1. 'use strict';
  2. var isAbsoluteURL = require('../helpers/isAbsoluteURL');
  3. var combineURLs = require('../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. module.exports = function buildFullPath(baseURL, requestedURL) {
  14. if (baseURL && !isAbsoluteURL(requestedURL)) {
  15. return combineURLs(baseURL, requestedURL);
  16. }
  17. return requestedURL;
  18. };