Display post counts within link for categories and archive

Recently I had to add the count of posts in each category or archive on the sidebar. I knew exactly what I have to do, search wp_list_categories in the WordPress Code Reference. I copied the code and modified it to look the way I want just to realize that the count number is not inside the link.


Looking online on how to do this, I found what I was searching for on GitHub. You can add the code in functions.php and the post count will be placed inside the link.