combineURLs.js 380 B

1234567891011121314
  1. 'use strict';
  2. /**
  3. * Creates a new URL by combining the specified URLs
  4. *
  5. * @param {string} baseURL The base URL
  6. * @param {string} relativeURL The relative URL
  7. * @returns {string} The combined URL
  8. */
  9. module.exports = function combineURLs(baseURL, relativeURL) {
  10. return relativeURL
  11. ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
  12. : baseURL;
  13. };