Skip to content

Instantly share code, notes, and snippets.

@vibs2006
Last active June 14, 2023 12:38
Show Gist options
  • Save vibs2006/dc4f89170d16a7f4f2b1a0d5d7b353c9 to your computer and use it in GitHub Desktop.
Save vibs2006/dc4f89170d16a7f4f2b1a0d5d7b353c9 to your computer and use it in GitHub Desktop.
Javascript Helper Methods
  1. Path.Combine
//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