Skip to content

Instantly share code, notes, and snippets.

@LuisPaGarcia
Created September 13, 2023 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuisPaGarcia/ace32ddfe27397cc87dcb24f8b80478f to your computer and use it in GitHub Desktop.
Save LuisPaGarcia/ace32ddfe27397cc87dcb24f8b80478f to your computer and use it in GitHub Desktop.
path to slug
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