- Path.Combine
Last active
June 14, 2023 12:38
-
-
Save vibs2006/dc4f89170d16a7f4f2b1a0d5d7b353c9 to your computer and use it in GitHub Desktop.
Javascript Helper Methods
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
//Path.Combine Equivalent in Javascript | |
function pathJoin(parts, sep){ | |
const separator = sep || '/'; | |
parts = parts.map((part, index)=>{ | |
if (index) { | |
part = part.replace(new RegExp('^' + separator), ''); | |
} | |
if (index !== parts.length - 1) { | |
part = part.replace(new RegExp(separator + '$'), ''); | |
} | |
return part; | |
}) | |
return parts.join(separator); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment