@ixo/supamoto-bot-sdk
Version:
An SDK to easily interact with Supamoto bot db
19 lines (17 loc) • 743 B
JavaScript
export function cleanUrlString(url) {
// Remove line breakers such as \n and any other whitespace characters
let cleanedUrl = url.replace(/[\n\r\s]/g, '');
// Regular expression to match duplicate slashes except for the first one after "https://" or "http://"
const regex = /(https?:\/\/|[^:])\/\//g;
// Replace duplicate slashes with a single slash, excluding the first one after "https://" or "http://"
cleanedUrl = cleanedUrl.replace(regex, (match, p1) => {
// If match starts with http: or https:, keep it as it is.
if (p1 === 'http://' || p1 === 'https://') {
return match;
} else {
// Otherwise, replace the extra slashes with a single slash
return p1 + '/';
}
});
return cleanedUrl;
}