DEV Community

Discussion on: String Manipulation of URLs is an Anti-Pattern.

Collapse
 
manchicken profile image
Mike Stemle • Edited

There are two reasons I used the third-party library:

  1. Most folks that I have encountered do use a library.
  2. Even if the encoding function does work in that use case, the anti-pattern remains.

I was trying to keep this article short, but I could have also gone in to how so many times folks will try to do stuff like:

some_url = `${first_url}${(source_url.indexOf('?') > -1) ? '&' : '?'}${param_list.join('&')}`
Enter fullscreen mode Exit fullscreen mode

Those are all really bad practices. The only real solution is to use URL libraries which treat a URL as the packed value that it is.