UNPKG

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.

30 lines 755 B
/** * @public * Joins two strings `start` and `end` with a `separator`. * * @returns The joined path. * * @remarks * See {@link pathJoin}. */ export 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}`; } } } //# sourceMappingURL=path-join.js.map