Created
September 13, 2023 22:40
-
-
Save LuisPaGarcia/ace32ddfe27397cc87dcb24f8b80478f to your computer and use it in GitHub Desktop.
path to slug
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
function replaceSlashesWithDashes(path) { | |
// Remove the leading and trailing slashes if they exist | |
const trimmedPath = path.replace(/^\/|\/$/g, ''); | |
// Replace all remaining slashes with dashes | |
return trimmedPath.replace(/\//g, '-'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment