Replace Repeated Characters with JavaScript

URLs can be tricky to work with because they can be more complicated than the traditional URL format you type in.  I was again reminded of this when I was parsing Webpack URLs when I saw this beauty:


I parsed the URL with new URL("....") but saw that the pathname included every leading slash:


Since I wanted to display a sane pathname, I wanted to figure out how to remove/replace repeated characters with JavaScript.  It was actually easier than I thought it would be:

const prettyPath = urlObj.

Check Full Content Here […] is Available for Purchase. Learn more by clicking the button here:

Get More Info