rc-js-util
Version:
A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.
34 lines • 881 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.pathJoin = void 0;
/**
* @public
* Joins two strings `start` and `end` with a `separator`.
*
* @returns The joined path.
*
* @remarks
* See {@link pathJoin}.
*/
function pathJoin(start, end, separator = "/") {
const startEndsWithSeparator = start[start.length - 1] === separator;
const endStartsWithSeparator = end[0] === separator;
if (startEndsWithSeparator) {
if (endStartsWithSeparator) {
return start.concat(end.substring(1));
}
else {
return start.concat(end);
}
}
else {
if (endStartsWithSeparator) {
return start.concat(end);
}
else {
return `${start}${separator}${end}`;
}
}
}
exports.pathJoin = pathJoin;
//# sourceMappingURL=path-join.js.map