FriendsOfFlarum / socialprofile

Add custom social media pages to your user profile
MIT License
13 stars 8 forks source link

Refactor and improve URL-related tasks #17

Closed davwheat closed 3 years ago

davwheat commented 3 years ago

This PR adds two new helpers to refactor the URL validation and favicon URL generation logic out of the main js files.

Both helpers are documented with JSDoc, and extractBaseUrl.js has a few examples, too, to prevent confusion.

extractBaseUrl.js

This function takes a URL input and returns the base URL (what would be supplied as an Origin header when navigating). If the URL is invalid, it returns null.

isValidUrl.js

It basically does what the name says. If the URL is valid, it returns true, otherwise false. The URL API isn't supported in IE, but that shouldn't be a real issue: people using IE should expect many, many issues on modern sites.