Created
October 13, 2022 12:53
-
-
Save adroste/b11466500364d765f67ca2148d2d6a78 to your computer and use it in GitHub Desktop.
Properly joins paths, also works for URLs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const pathJoin = (base, ...parts) => { | |
const trimSepRight = /\/+$/g; | |
const trimSepLeftRight = /^\/+|\/+$/g; | |
const partsTrimmed = parts.map(p => p.replace(trimSepLeftRight, '')); | |
return [base.replace(trimSepRight, '')].concat(partsTrimmed).join('/'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for Typescript: