@zohodesk/client_build_tool
Version:
A CLI tool to build web applications and client libraries
44 lines (34 loc) • 914 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.serverPathConcat = serverPathConcat;
exports.urlConcat = urlConcat;
/* eslint-disable no-use-before-define */
/**
*
* @param {String} url
* @param {String} path
*/
function serverPathConcat(url, path) {
const slashRemovedUrl = removeLastSlash(url);
const slashRemovedPath = removeFrontSlash(path);
if (slashRemovedUrl === '') {
return `${path}/`;
}
return `${[slashRemovedUrl, slashRemovedPath].filter(a => a).join('/')}/`;
}
function urlConcat(url, path) {
const slashRemovedUrl = removeLastSlash(url);
const slashRemovedPath = removeFrontSlash(path);
if (slashRemovedUrl === '') {
return path;
}
return `${slashRemovedUrl}/${slashRemovedPath}`;
}
function removeLastSlash(url) {
return url.replace(/\/+$/, '');
}
function removeFrontSlash(url) {
return url.replace(/^\/+/, '');
}