mirror of
https://github.com/Kong/insomnia.git
synced 2026-09-18 02:56:36 -04:00
22 lines
526 B
TypeScript
22 lines
526 B
TypeScript
/**
|
|
* Set a default protocol for a URL
|
|
* @param url URL to set protocol on
|
|
* @param [defaultProto='http:'] default protocol
|
|
*/
|
|
export const setDefaultProtocol = (url: string, defaultProto?: string) => {
|
|
const trimmedUrl = url.trim();
|
|
defaultProto = defaultProto || 'http:';
|
|
|
|
// If no url, don't bother returning anything
|
|
if (!trimmedUrl) {
|
|
return '';
|
|
}
|
|
|
|
// Default the proto if it doesn't exist
|
|
if (!trimmedUrl.includes('://')) {
|
|
return `${defaultProto}//${trimmedUrl}`;
|
|
}
|
|
|
|
return trimmedUrl;
|
|
};
|